From 639a346c1e07c70e64d88660217a3f611ed2171a Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 26 Nov 2021 15:29:25 +0300 Subject: [PATCH] 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: --- js/ui/screenshot.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index afb3277a2..27e43c6ab 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); } });