From 554001c0ed0f46153f39f84cbd32a308b1f133ba Mon Sep 17 00:00:00 2001 From: Carlos Soriano Date: Wed, 11 Jun 2014 15:27:40 +0200 Subject: [PATCH] appDisplay: Move focus to popup only when necessary Unlike for the main app view, where we only move the key focus once the users starts navigating, the key focus is moved immediately when opening a folder popup. This is unexpected, so make app folders consistent with the main view. As arrow keys will not work while the container itself has key focus, we handle those explicitly by translating them to TAB_FORWARD and TAB_BACKWARD respectively. https://bugzilla.gnome.org/show_bug.cgi?id=731477 --- js/ui/appDisplay.js | 47 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index b580ba38e..a707c67fc 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -1253,6 +1253,51 @@ const AppFolderPopup = new Lang.Class({ })); this._grabHelper = new GrabHelper.GrabHelper(this.actor); this._grabHelper.addActor(Main.layoutManager.overviewGroup); + this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPress)); + }, + + _onKeyPress: function(actor, event) { + if (global.stage.get_key_focus() != actor) + return Clutter.EVENT_PROPAGATE; + + // Since we need to only grab focus on one item child when the user + // actually press a key we don't use navigate_focus when opening + // the popup. + // Instead of that, grab the focus on the AppFolderPopup actor + // and actually moves the focus to a child only when the user + // actually press a key. + // It should work with just grab_key_focus on the AppFolderPopup + // actor, but since the arrow keys are not wrapping_around the focus + // is not grabbed by a child when the widget that has the current focus + // is the same that is requesting focus, so to make it works with arrow + // keys we need to connect to the key-press-event and navigate_focus + // when that happens using TAB_FORWARD or TAB_BACKWARD instead of arrow + // keys + + // Use TAB_FORWARD for down key and right key + // and TAB_BACKWARD for up key and left key on ltr + // languages + let direction; + let isLtr = Clutter.get_default_text_direction() == Clutter.TextDirection.LTR; + switch (event.get_key_symbol()) { + case Clutter.Down: + direction = Gtk.DirectionType.TAB_FORWARD; + break; + case Clutter.Right: + direction = isLtr ? Gtk.DirectionType.TAB_FORWARD : + Gtk.DirectionType.TAB_BACKWARD; + break; + case Clutter.Up: + direction = Gtk.DirectionType.TAB_BACKWARD; + break; + case Clutter.Left: + direction = isLtr ? Gtk.DirectionType.TAB_BACKWARD : + Gtk.DirectionType.TAB_FORWARD; + break; + default: + return Clutter.EVENT_PROPAGATE; + } + return actor.navigate_focus(null, direction, false); }, toggle: function() { @@ -1278,8 +1323,6 @@ const AppFolderPopup = new Lang.Class({ this._boxPointer.show(BoxPointer.PopupAnimation.FADE | BoxPointer.PopupAnimation.SLIDE); - this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false); - this.emit('open-state-changed', true); },