From 906f2f2aaf739ebe324c3ad9acac5ec78a0023c2 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Sun, 25 Aug 2019 16:53:57 -0400 Subject: [PATCH] Add setting to cycle taskbar windows on mouse scroll --- Settings.ui | 1 + appIcons.js | 23 +++-------------------- panel.js | 19 ++++++++++++------- taskbar.js | 30 +++++++++++++++++------------- utils.js | 17 +++++++++++++++++ 5 files changed, 50 insertions(+), 40 deletions(-) diff --git a/Settings.ui b/Settings.ui index 17bc903..9d92c57 100644 --- a/Settings.ui +++ b/Settings.ui @@ -6591,6 +6591,7 @@ Do nothing Switch workspace + Cycle windows diff --git a/appIcons.js b/appIcons.js index 667e9cb..647d445 100644 --- a/appIcons.js +++ b/appIcons.js @@ -359,23 +359,9 @@ var taskbarAppIcon = Utils.defineClass({ }); let windows = this.getAppIconInterestingWindows(); - + windows.sort(Taskbar.sortWindowsCompareFunction); - - let windowIndex = windows.indexOf(global.display.focus_window); - let nextWindowIndex = windowIndex < 0 ? - this.window ? windows.indexOf(this.window) : 0 : - windowIndex + (direction == 'up' ? 1 : -1); - - if (nextWindowIndex == windows.length) { - nextWindowIndex = 0; - } else if (nextWindowIndex < 0) { - nextWindowIndex = windows.length - 1; - } - - if (windowIndex != nextWindowIndex) { - Main.activateWindow(windows[nextWindowIndex]); - } + Utils.activateSiblingWindow(windows, direction, this.window); } }, @@ -588,10 +574,7 @@ var taskbarAppIcon = Utils.defineClass({ }, _onSwitchWorkspace: function(windowTracker) { - Mainloop.timeout_add(0, Lang.bind(this, function () { - this._displayProperIndicator(); - return GLib.SOURCE_REMOVE; - })); + this._displayProperIndicator(); }, _displayProperIndicator: function (force) { diff --git a/panel.js b/panel.js index 5805124..2a403be 100644 --- a/panel.js +++ b/panel.js @@ -756,20 +756,25 @@ var dtpPanelWrapper = Utils.defineClass({ }, _onPanelMouseScroll: function(actor, event) { - if (this._dtpSettings.get_string('scroll-panel-action') === 'SWITCH_WORKSPACE') { - let direction = Utils.getMouseScrollDirection(event); - - if (!event.get_source()._dtpIgnoreScroll && direction && !this._scrollPanelDelayTimeoutId) { - this._scrollPanelDelayTimeoutId = Mainloop.timeout_add(this._dtpSettings.get_int('scroll-panel-delay'), () => { - this._scrollPanelDelayTimeoutId = 0; - }); + let scrollAction = this._dtpSettings.get_string('scroll-panel-action'); + let direction = Utils.getMouseScrollDirection(event); + if (!event.get_source()._dtpIgnoreScroll && direction && !this._scrollPanelDelayTimeoutId) { + this._scrollPanelDelayTimeoutId = Mainloop.timeout_add(this._dtpSettings.get_int('scroll-panel-delay'), () => { + this._scrollPanelDelayTimeoutId = 0; + }); + + if (scrollAction === 'SWITCH_WORKSPACE') { let args = [global.display]; //gnome-shell < 3.30 needs an additional "screen" param global.screen ? args.push(global.screen) : 0; Main.wm._showWorkspaceSwitcher.apply(Main.wm, args.concat([0, { get_name: () => 'switch---' + direction }])); + } else if (scrollAction === 'CYCLE_WINDOWS') { + let windows = this.taskbar.getAppInfos().reduce((ws, appInfo) => ws.concat(appInfo.windows), []); + + Utils.activateSiblingWindow(windows, direction); } } }, diff --git a/taskbar.js b/taskbar.js index 0231146..8d7e893 100644 --- a/taskbar.js +++ b/taskbar.js @@ -740,13 +740,7 @@ var taskbar = Utils.defineClass({ getAppStableSequence(appB, this._dtpSettings, this.panelWrapper.monitor); }, - _redisplay: function () { - if (!this._signalsHandler) { - return; - } - - //get the currently displayed appIcons - let currentAppIcons = this._getTaskbarIcons(); + getAppInfos: function() { //get the user's favorite apps let favoriteApps = this._checkIfShowingFavorites() ? AppFavorites.getAppFavorites().getFavorites() : []; @@ -754,16 +748,26 @@ var taskbar = Utils.defineClass({ // When using isolation, we filter out apps that have no windows in // the current workspace (this check is done in AppIcons.getInterestingWindows) let runningApps = this._checkIfShowingRunningApps() ? this._getRunningApps().sort(this.sortAppsCompareFunction.bind(this)) : []; - let expectedAppInfos; + if (!this.isGroupApps && this._dtpSettings.get_boolean('group-apps-use-launchers')) { - expectedAppInfos = this._createAppInfos(favoriteApps, [], true) - .concat(this._createAppInfos(runningApps) - .filter(appInfo => appInfo.windows.length)); + return expectedAppInfos = this._createAppInfos(favoriteApps, [], true) + .concat(this._createAppInfos(runningApps) + .filter(appInfo => appInfo.windows.length)); } else { - expectedAppInfos = this._createAppInfos(favoriteApps.concat(runningApps.filter(app => favoriteApps.indexOf(app) < 0))) - .filter(appInfo => appInfo.windows.length || favoriteApps.indexOf(appInfo.app) >= 0); + return this._createAppInfos(favoriteApps.concat(runningApps.filter(app => favoriteApps.indexOf(app) < 0))) + .filter(appInfo => appInfo.windows.length || favoriteApps.indexOf(appInfo.app) >= 0); } + }, + + _redisplay: function () { + if (!this._signalsHandler) { + return; + } + + //get the currently displayed appIcons + let currentAppIcons = this._getTaskbarIcons(); + let expectedAppInfos = this.getAppInfos(); //remove the appIcons which are not in the expected apps list for (let i = currentAppIcons.length - 1; i > -1; --i) { diff --git a/utils.js b/utils.js index d2d39e4..205ea18 100644 --- a/utils.js +++ b/utils.js @@ -397,6 +397,23 @@ var getMouseScrollDirection = function(event) { return direction; }; +var activateSiblingWindow = function(windows, direction, startWindow) { + let windowIndex = windows.indexOf(global.display.focus_window); + let nextWindowIndex = windowIndex < 0 ? + startWindow ? windows.indexOf(startWindow) : 0 : + windowIndex + (direction == 'up' ? 1 : -1); + + if (nextWindowIndex == windows.length) { + nextWindowIndex = 0; + } else if (nextWindowIndex < 0) { + nextWindowIndex = windows.length - 1; + } + + if (windowIndex != nextWindowIndex) { + Main.activateWindow(windows[nextWindowIndex]); + } +} + /* * This is a copy of the same function in utils.js, but also adjust horizontal scrolling * and perform few further cheks on the current value to avoid changing the values when