From efbcebd12aac239cb82d87a605273a2c0f1224df Mon Sep 17 00:00:00 2001 From: Daniel Sheeler Date: Wed, 21 Aug 2024 13:23:48 -0500 Subject: [PATCH] Move adding custom keybindings from platform to (duh) keybinder. Brilliant suggestion, @JustPerfection! --- src/extension.js | 2 +- src/keybinder.js | 42 +++++++++++++++++++++++++++++++++++++++++- src/platform.js | 38 +------------------------------------- src/switcher.js | 8 ++++---- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/extension.js b/src/extension.js index 0cbde1f..b6823c2 100644 --- a/src/extension.js +++ b/src/extension.js @@ -47,7 +47,7 @@ export default class CoverflowAltTabExtension extends Extension { this.logger.log("Creating New Manager"); this.manager = new Manager.Manager( new Platform.PlatformGnomeShell(this.getSettings(), this.logger), - new Keybinder.Keybinder330Api(), + new Keybinder.Keybinder330Api(this.getSettings()), this.logger ); this.logger.log("Creating New Manager DONE"); diff --git a/src/keybinder.js b/src/keybinder.js index 3524cd3..5d62450 100644 --- a/src/keybinder.js +++ b/src/keybinder.js @@ -23,6 +23,7 @@ */ import Shell from 'gi://Shell'; +import Meta from 'gi://Meta'; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import {__ABSTRACT_METHOD__} from './lib.js' @@ -33,12 +34,45 @@ class AbstractKeybinder { } export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder { - constructor(...args) { + constructor(settings, ...args) { super(...args); + this._settings = settings; this._startAppSwitcherBind = null; + this._keybindingActions = new Map(); } + getAction(actionName) { + return this._keybindingActions.get(actionName); + } + + addKeybinding(actionName) { + let action = Main.wm.addKeybinding( + actionName, + this._settings, + Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, + Shell.ActionMode.NORMAL, + () => {} + ); + this._keybindingActions.set(actionName, action) + + action = Main.wm.addKeybinding( + actionName + "-backward", + this._settings, + Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, + Shell.ActionMode.NORMAL, + () => {} + ) + this._keybindingActions.set(actionName + "-backward", action) + } + + removeKeybinding(actionName) { + Main.wm.removeKeybinding(actionName); + this._keybindingActions.delete(actionName); + Main.wm.removeKeybinding(actionName + "-backward"); + this._keybindingActions.delete(actionName + "-backward"); + } + enable(startAppSwitcherBind, platform) { let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode; @@ -46,6 +80,9 @@ export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder { platform.addSettingsChangedCallback(this._onSettingsChanged.bind(this)); + this.addKeybinding("coverflow-switch-windows"); + this.addKeybinding("coverflow-switch-applications"); + Main.wm.setCustomKeybindingHandler('switch-group', mode.NORMAL, startAppSwitcherBind); Main.wm.setCustomKeybindingHandler('switch-group-backward', mode.NORMAL, startAppSwitcherBind); Main.wm.setCustomKeybindingHandler("coverflow-switch-windows", mode.NORMAL, this._startAppSwitcherBind); @@ -62,6 +99,9 @@ export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder { Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm)); Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm)); Main.wm.setCustomKeybindingHandler('switch-group-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm)); + + this.removeKeybinding("coverflow-switch-windows"); + this.removeKeybinding("coverflow-switch-applications"); } _onSettingsChanged(settings, key=null) { diff --git a/src/platform.js b/src/platform.js index df9874a..c70145d 100644 --- a/src/platform.js +++ b/src/platform.js @@ -173,7 +173,6 @@ export class PlatformGnomeShell extends AbstractPlatform { this._backgroundColor = null; this._settings_changed_callbacks = null; this._themeContext = null; - this._keybindingActions = new Map(); this._logger = logger; } @@ -264,15 +263,11 @@ export class PlatformGnomeShell extends AbstractPlatform { } this._settings = this._loadSettings(); - this.addKeybinding("coverflow-switch-windows"); - this.addKeybinding("coverflow-switch-applications"); + } disable() { - this.removeKeybinding("coverflow-switch-windows"); - this.removeKeybinding("coverflow-switch-applications"); - this.showPanels(0); if (this._connections) { for (let connection of this._connections) { @@ -292,37 +287,6 @@ export class PlatformGnomeShell extends AbstractPlatform { } - getAction(actionName) { - return this._keybindingActions.get(actionName); - } - - addKeybinding(actionName) { - let action = Main.wm.addKeybinding( - actionName, - this._extensionSettings, - Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, - Shell.ActionMode.NORMAL, - () => {} - ); - this._keybindingActions.set(actionName, action) - - action = Main.wm.addKeybinding( - actionName + "-backward", - this._extensionSettings, - Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, - Shell.ActionMode.NORMAL, - () => {} - ) - this._keybindingActions.set(actionName + "-backward", action) - } - - removeKeybinding(actionName) { - Main.wm.removeKeybinding(actionName); - this._keybindingActions.delete(actionName); - Main.wm.removeKeybinding(actionName + "-backward"); - this._keybindingActions.delete(actionName + "-backward"); - } - getWidgetClass() { return St.Widget; } diff --git a/src/switcher.js b/src/switcher.js index b70849c..13e2f40 100644 --- a/src/switcher.js +++ b/src/switcher.js @@ -755,8 +755,8 @@ export class Switcher { case Meta.KeyBindingAction.SWITCH_APPLICATIONS: case Meta.KeyBindingAction.SWITCH_GROUP: case Meta.KeyBindingAction.SWITCH_WINDOWS: - case this._manager.platform.getAction("coverflow-switch-windows"): - case this._manager.platform.getAction("coverflow-switch-applications"): + case this._manager.keybinder.getAction("coverflow-switch-windows"): + case this._manager.keybinder.getAction("coverflow-switch-applications"): // shift -> backwards if (event_state & Clutter.ModifierType.SHIFT_MASK) { @@ -769,8 +769,8 @@ export class Switcher { case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD: case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD: case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD: - case this._manager.platform.getAction("coverflow-switch-windows-backward"): - case this._manager.platform.getAction("coverflow-switch-applications-backward"): + case this._manager.keybinder.getAction("coverflow-switch-windows-backward"): + case this._manager.keybinder.getAction("coverflow-switch-applications-backward"): this._previous(); return true;