Add setting to cycle taskbar windows on mouse scroll

This commit is contained in:
Charles Gagnon
2019-08-25 16:53:57 -04:00
parent 71b4ceb4fe
commit 906f2f2aaf
5 changed files with 50 additions and 40 deletions

View File

@@ -6591,6 +6591,7 @@
<items>
<item id="NOTHING" translatable="yes">Do nothing</item>
<item id="SWITCH_WORKSPACE" translatable="yes">Switch workspace</item>
<item id="CYCLE_WINDOWS" translatable="yes">Cycle windows</item>
</items>
</object>
<packing>

View File

@@ -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) {

View File

@@ -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);
}
}
},

View File

@@ -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) {

View File

@@ -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