From a42dcee6ecae73dba077d33744874418bea7fc27 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 5 Feb 2014 17:25:43 +0100 Subject: [PATCH] WindowList: allow switching windows with mouse scroll This is something that gnome-panel supported, and apparently some users would like to have it back, so restore this feature on our window list too. https://bugzilla.gnome.org/show_bug.cgi?id=723693 --- extensions/window-list/extension.js | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js index a0f9a9f4..714142c0 100644 --- a/extensions/window-list/extension.js +++ b/extensions/window-list/extension.js @@ -219,6 +219,17 @@ const WindowButton = new Lang.Class({ this._updateStyle(); }, + get active() { + return this.actor.has_style_class_name('focused'); + }, + + activate: function() { + if (this.active) + return; + + this._onClicked(this.actor, 1); + }, + _onClicked: function(actor, button) { if (this._contextMenu.isOpen) { this._contextMenu.close(); @@ -485,6 +496,17 @@ const AppButton = new Lang.Class({ }, + get active() { + return this.actor.has_style_class_name('focused'); + }, + + activate: function() { + if (this.active) + return; + + this._onClicked(this.actor, 1); + }, + _onClicked: function(actor, button) { let menuWasOpen = this._menu.isOpen; if (menuWasOpen) @@ -724,6 +746,7 @@ const WindowList = new Lang.Class({ let layout = new Clutter.BoxLayout({ homogeneous: true }); this._windowList = new St.Widget({ style_class: 'window-list', + reactive: true, layout_manager: layout, x_align: Clutter.ActorAlign.START, x_expand: true, @@ -750,6 +773,7 @@ const WindowList = new Lang.Class({ Lang.bind(this, this._populateWindowList)); } })); + this._windowList.connect('scroll-event', Lang.bind(this, this._onScrollEvent)); let indicatorsBox = new St.BoxLayout({ x_align: Clutter.ActorAlign.END }); box.add(indicatorsBox); @@ -833,6 +857,31 @@ const WindowList = new Lang.Class({ this._groupingModeChanged(); }, + _onScrollEvent: function(actor, event) { + let direction = event.get_scroll_direction(); + let diff = 0; + if (direction == Clutter.ScrollDirection.DOWN) + diff = 1; + else if (direction == Clutter.ScrollDirection.UP) + diff = -1; + else + return; + + let children = this._windowList.get_children().map(function(actor) { + return actor._delegate; + }); + let active = 0; + for (let i = 0; i < children.length; i++) { + if (children[i].active) { + active = i; + break; + } + } + + active = Math.max(0, Math.min(active + diff, children.length-1)); + children[active].activate(); + }, + _groupingModeChanged: function() { this._groupingMode = this._settings.get_enum('grouping-mode'); this._grouped = this._groupingMode == GroupingMode.ALWAYS;