Skip to content

Commit

Permalink
Move adding custom keybindings from platform to (duh) keybinder. Bril…
Browse files Browse the repository at this point in the history
…liant suggestion, @JustPerfection!
  • Loading branch information
dsheeler committed Aug 21, 2024
1 parent bd27bb2 commit efbcebd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
42 changes: 41 additions & 1 deletion src/keybinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,19 +34,55 @@ 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;

this._startAppSwitcherBind = startAppSwitcherBind;

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);
Expand All @@ -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) {
Expand Down
38 changes: 1 addition & 37 deletions src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit efbcebd

Please sign in to comment.