From 869ea8436d9cf9d5748e6c089cc0b0b58358e75f Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Sat, 26 Sep 2026 22:23:04 +0100 Subject: Align GNOME shortcuts with the Sway setup --- dot_local/lib/dotfiles/canonical_desktop.py | 70 ++++++++++++++++++++-- .../workspace-cycle@dotfiles/extension.js | 35 +++++++++++ .../workspace-cycle@dotfiles/metadata.json | 8 +++ ...me.shell.extensions.workspace-cycle.gschema.xml | 13 ++++ 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/extension.js create mode 100644 dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/metadata.json create mode 100644 dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/schemas/org.gnome.shell.extensions.workspace-cycle.gschema.xml (limited to 'dot_local') diff --git a/dot_local/lib/dotfiles/canonical_desktop.py b/dot_local/lib/dotfiles/canonical_desktop.py index 96e4e4e..b184ad0 100644 --- a/dot_local/lib/dotfiles/canonical_desktop.py +++ b/dot_local/lib/dotfiles/canonical_desktop.py @@ -4,12 +4,14 @@ import importlib import json import os import shlex +import subprocess import sys from pathlib import Path HOME = Path.home() STATE = HOME / ".local/state/dotfiles/gnome-settings.json" EXTENSIONS = [ + "workspace-cycle@dotfiles", "external-display@dotfiles", "o-tiling@oliwebd.github.com", "copyous@boerdereinar.dev", @@ -98,6 +100,7 @@ def shortcuts(saved: dict) -> None: saved, ) shell = shlex.quote(str(HOME / ".nix-profile/bin/zsh")) + scratch = shlex.quote('nvim "$XDG_RUNTIME_DIR/scratch-$(date +%s).txt"') actions = { "terminal": ("Return", "/snap/bin/ghostty"), "files": ("Return", f"/snap/bin/ghostty -e {shell} -lc yazi"), @@ -106,6 +109,11 @@ def shortcuts(saved: dict) -> None: "dictate": ("i", f"{shell} -lc dictate"), "ocr": ("o", f"{shell} -lc ocr"), "record": ("r", f"{shell} -lc 'record toggle'"), + "calculator": ("c", f"/snap/bin/ghostty -e {shell} -lc ipython"), + "scratch-editor": ( + "t", + f"/snap/bin/ghostty -e {shell} -lc {scratch}", + ), "clipboard": ( "p", "gdbus call --session --dest org.gnome.Shell.Extensions.Copyous --object-path /org/gnome/Shell/Extensions/Copyous --method org.gnome.Shell.Extensions.Copyous.Show", @@ -156,6 +164,7 @@ def apply_settings(saved: dict) -> None: write_key( "org.gnome.desktop.wm.keybindings", "toggle-fullscreen", ["f"], saved ) + desktop_bindings(saved) tiling(saved) shortcuts(saved) workspaces(saved) @@ -163,6 +172,41 @@ def apply_settings(saved: dict) -> None: extensions(saved) +def desktop_bindings(saved: dict) -> None: + for key, bindings in { + "switch-applications": ["Tab"], + "switch-applications-backward": ["Tab"], + "switch-input-source": [], + "switch-input-source-backward": [], + "cycle-windows": ["bracketright", "Escape"], + "cycle-windows-backward": ["bracketleft", "Escape"], + }.items(): + write_key("org.gnome.desktop.wm.keybindings", key, bindings, saved) + for key, bindings in { + "screensaver": ["s"], + "volume-up": ["k"], + "volume-down": ["j"], + "volume-mute": ["m"], + "mic-mute": ["m"], + "play": ["space"], + "next": ["l"], + "previous": ["h"], + "logout": ["e", "Delete"], + }.items(): + write_key("org.gnome.settings-daemon.plugins.media-keys", key, bindings, saved) + for key, bindings in { + "toggle-message-tray": ["n"], + "show-screenshot-ui": ["Print"], + "screenshot": ["Print"], + "screen-brightness-up": ["XF86MonBrightnessUp", "bracketright"], + "screen-brightness-down": [ + "XF86MonBrightnessDown", + "bracketleft", + ], + }.items(): + write_key("org.gnome.shell.keybindings", key, bindings, saved) + + def tiling(saved: dict) -> None: schema = "org.gnome.shell.extensions.o-tiling" for key, value in { @@ -174,22 +218,25 @@ def tiling(saved: dict) -> None: "panel-transparency": False, "mouse-cursor-follows-active-window": False, "toggle-floating": ["space"], + "toggle-stacking-global": ["s"], + "tile-orientation": ["e"], + "tile-enter": ["r"], }.items(): write_key(schema, key, value, saved) for key in [ - "tile-enter", "toggle-tiling", - "tile-orientation", "pop-workspace-up", "pop-workspace-down", ]: write_key(schema, key, [], saved) for direction, letter in zip(["left", "down", "up", "right"], "hjkl"): - binding = "Right" if direction == "right" else f"{letter}" - write_key(schema, f"focus-{direction}", [binding], saved) + write_key(schema, f"focus-{direction}", [f"{letter}"], saved) write_key( schema, f"tile-move-{direction}-global", [f"{letter}"], saved ) + write_key(schema, f"tile-resize-{direction}", [letter], saved) + write_key(schema, f"tile-move-{direction}", [f"{letter}"], saved) + write_key(schema, f"tile-swap-{direction}", [], saved) def panel(saved: dict) -> None: @@ -221,6 +268,11 @@ def panel(saved: dict) -> None: def workspaces(saved: dict) -> None: write_key("org.gnome.mutter", "dynamic-workspaces", True, saved) + for key, binding in [ + ("next-workspace", "Tab"), + ("previous-workspace", "Tab"), + ]: + write_key("org.gnome.shell.extensions.workspace-cycle", key, [binding], saved) for number in range(1, 11): key = str(number % 10) for action, modifier in [("switch", ""), ("move", "")]: @@ -266,6 +318,16 @@ def main() -> None: raise SystemExit("Run this command from the GNOME desktop session.") saved = json.loads(STATE.read_text()) if STATE.exists() else {} if sys.argv[1:] == ["settings"]: + subprocess.run( + [ + "/usr/bin/glib-compile-schemas", + str( + HOME + / ".local/share/gnome-shell/extensions/workspace-cycle@dotfiles/schemas" + ), + ], + check=True, + ) apply_settings(saved) elif sys.argv[1:] == ["restore"]: restore(saved) diff --git a/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/extension.js b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/extension.js new file mode 100644 index 0000000..dc6e3c9 --- /dev/null +++ b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/extension.js @@ -0,0 +1,35 @@ +import Meta from "gi://Meta"; +import Shell from "gi://Shell"; +import { Extension } from "resource:///org/gnome/shell/extensions/extension.js"; +import * as Main from "resource:///org/gnome/shell/ui/main.js"; + +export default class WorkspaceCycle extends Extension { + enable() { + const settings = this.getSettings(); + for (const [name, step] of [ + ["next-workspace", 1], + ["previous-workspace", -1], + ]) { + Main.wm.addKeybinding( + name, + settings, + Meta.KeyBindingFlags.NONE, + Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW, + () => this.cycle(step), + ); + } + } + + cycle(step) { + const manager = global.workspace_manager; + const count = manager.n_workspaces; + if (count < 2) return; + const index = (manager.get_active_workspace_index() + step + count) % count; + manager.get_workspace_by_index(index).activate(global.get_current_time()); + } + + disable() { + Main.wm.removeKeybinding("next-workspace"); + Main.wm.removeKeybinding("previous-workspace"); + } +} diff --git a/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/metadata.json b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/metadata.json new file mode 100644 index 0000000..8f8eafd --- /dev/null +++ b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/metadata.json @@ -0,0 +1,8 @@ +{ + "uuid": "workspace-cycle@dotfiles", + "name": "Workspace Cycle", + "description": "Cycle through workspaces in both directions.", + "shell-version": ["50"], + "settings-schema": "org.gnome.shell.extensions.workspace-cycle", + "version": 1 +} diff --git a/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/schemas/org.gnome.shell.extensions.workspace-cycle.gschema.xml b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/schemas/org.gnome.shell.extensions.workspace-cycle.gschema.xml new file mode 100644 index 0000000..25a993f --- /dev/null +++ b/dot_local/share/gnome-shell/extensions/workspace-cycle@dotfiles/schemas/org.gnome.shell.extensions.workspace-cycle.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + Next workspace, with wraparound + + + [] + Previous workspace, with wraparound + + + -- cgit v1.3.1