From 8fddaf2a3ba974fe5ada034754d8644a799369d8 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 5 Apr 2025 23:29:55 +0200 Subject: [PATCH] ags keybinds: allow multiple binds, make modifiers case-insensitive --- .../.configuration/default_options.jsonc | 6 +++-- .config/ags/modules/.widgetutils/keybind.js | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.config/ags/modules/.configuration/default_options.jsonc b/.config/ags/modules/.configuration/default_options.jsonc index c1c7e1e0..ed895dc9 100644 --- a/.config/ags/modules/.configuration/default_options.jsonc +++ b/.config/ags/modules/.configuration/default_options.jsonc @@ -200,9 +200,11 @@ ] }, "keybinds": { - // Format: Mod1+Mod2+key. CaSe SeNsItIvE! + // Format: "Modifier_1+...+Modifier_n+key". The key is CaSe SeNsItIvE! // Modifiers: Shift Ctrl Alt Hyper Meta - // See https://docs.gtk.org/gdk3/index.html#constants for the other keys (they are listed as KEY_key) + // See https://docs.gtk.org/gdk3/index.html#constants for keys (listed as KEY_key) + // You can assign multiple keybinds for the same action. Just split them with a comma + // Example: "Ctrl+Page_Down, ctrl+Tab" "overview": { "altMoveLeft": "Ctrl+B", "altMoveRight": "Ctrl+F", diff --git a/.config/ags/modules/.widgetutils/keybind.js b/.config/ags/modules/.widgetutils/keybind.js index 40ed9ac7..188ebc92 100644 --- a/.config/ags/modules/.widgetutils/keybind.js +++ b/.config/ags/modules/.widgetutils/keybind.js @@ -1,20 +1,20 @@ const { Gdk } = imports.gi; const MODS = { - 'Shift': Gdk.ModifierType.SHIFT_MASK, - 'Ctrl': Gdk.ModifierType.CONTROL_MASK, - 'Alt': Gdk.ModifierType.ALT_MASK, - 'Hyper': Gdk.ModifierType.HYPER_MASK, - 'Meta': Gdk.ModifierType.META_MASK + 'shift': Gdk.ModifierType.SHIFT_MASK, + 'ctrl': Gdk.ModifierType.CONTROL_MASK, + 'alt': Gdk.ModifierType.ALT_MASK, + 'hyper': Gdk.ModifierType.HYPER_MASK, + 'meta': Gdk.ModifierType.META_MASK } -export const checkKeybind = (event, keybind) => { +const checkSingleKeybind = (event, keybind) => { const pressedModMask = event.get_state()[1]; const pressedKey = event.get_keyval()[1]; const keys = keybind.split('+'); for (let i = 0; i < keys.length; i++) { - if (keys[i] in MODS) { - if (!(pressedModMask & MODS[keys[i]])) { + if (keys[i].toLowerCase() in MODS) { + if (!(pressedModMask & MODS[keys[i].toLowerCase()])) { return false; } } else if (pressedKey !== Gdk[`KEY_${keys[i]}`] && pressedKey !== Gdk[`KEY_${keys[i].toLowerCase()}`]) { @@ -23,3 +23,12 @@ export const checkKeybind = (event, keybind) => { } return true; } + +export const checkKeybind = (event, keybind) => { + const keybinds = keybind.replace(' ', '').split(','); + for (let i = 0; i < keybinds.length; i++) { + if (checkSingleKeybind(event, keybinds[i])) { + return true; + } + } +}