[gnome-shell] screenshot-ui: Add keyboard navigation



commit 639a346c1e07c70e64d88660217a3f611ed2171a
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Fri Nov 26 15:29:25 2021 +0300

    screenshot-ui: Add keyboard navigation
    
    Allow switching the screenshot mode by pressing the "s", "c", or "w" key. Also
    implement arrow-key navigation between monitors in the screen screenshot mode
    and between windows in the window screenshot mode.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1954>

 js/ui/screenshot.js | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
---
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index afb3277a27..27e43c6ab4 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -1400,6 +1400,48 @@ class ScreenshotUI extends St.Widget {
             return Clutter.EVENT_STOP;
         }
 
+        if (symbol === Clutter.KEY_s || symbol === Clutter.KEY_S) {
+            this._selectionButton.checked = true;
+            return Clutter.EVENT_STOP;
+        }
+
+        if (symbol === Clutter.KEY_c || symbol === Clutter.KEY_C) {
+            this._screenButton.checked = true;
+            return Clutter.EVENT_STOP;
+        }
+
+        if (this._windowButton.reactive &&
+            (symbol === Clutter.KEY_w || symbol === Clutter.KEY_W)) {
+            this._windowButton.checked = true;
+            return Clutter.EVENT_STOP;
+        }
+
+        if (symbol === Clutter.KEY_Left || symbol === Clutter.KEY_Right ||
+            symbol === Clutter.KEY_Up || symbol === Clutter.KEY_Down) {
+            let direction;
+            if (symbol === Clutter.KEY_Left)
+                direction = St.DirectionType.LEFT;
+            else if (symbol === Clutter.KEY_Right)
+                direction = St.DirectionType.RIGHT;
+            else if (symbol === Clutter.KEY_Up)
+                direction = St.DirectionType.UP;
+            else if (symbol === Clutter.KEY_Down)
+                direction = St.DirectionType.DOWN;
+
+            if (this._windowButton.checked) {
+                const window =
+                    this._windowSelectors.flatMap(selector => selector.windows())
+                        .find(win => win.checked) ?? null;
+                this.navigate_focus(window, direction, false);
+            } else if (this._screenButton.checked) {
+                const screen =
+                    this._screenSelectors.find(selector => selector.checked) ?? null;
+                this.navigate_focus(screen, direction, false);
+            }
+
+            return Clutter.EVENT_STOP;
+        }
+
         return super.vfunc_key_press_event(event);
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]