From 9960e874c4439ba3a9b795b4ff59243890a3fbdc Mon Sep 17 00:00:00 2001 From: OlivierChiasson Date: Mon, 13 Jul 2026 12:02:06 -0300 Subject: [PATCH] Refactor DMS IPC bindings for Niri and Hyprland - Updated `binds.nix` files for both Niri and Hyprland to utilize a centralized `dmsIpcBinds` structure, improving maintainability and consistency across keybindings. - Introduced `dmsIpcBinds` in `default.nix` for both modules to streamline the command definitions for DMS IPC calls. - Enhanced `dms` module to define shared IPC commands, ensuring uniform command formatting for different compositors. --- modules/desktop/hyprland/binds.nix | 22 ++++++++++------------ modules/desktop/hyprland/default.nix | 5 ++++- modules/desktop/niri/binds.nix | 22 +++++++++++----------- modules/desktop/niri/default.nix | 5 ++++- modules/desktop/shells/dms/default.nix | 21 +++++++++++++++++++++ 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/modules/desktop/hyprland/binds.nix b/modules/desktop/hyprland/binds.nix index 1eba0a9..d25c382 100644 --- a/modules/desktop/hyprland/binds.nix +++ b/modules/desktop/hyprland/binds.nix @@ -1,6 +1,6 @@ { ... }: { flake.lib.hyprlandBinds = - { lib, dmsEnabled ? false }: + { lib, dmsEnabled ? false, dmsIpcBinds }: let workspaceBinds = (builtins.map (i: "Super, ${toString i}, workspace, ${toString i}") (builtins.genList (n: n + 1) 9)) @@ -28,17 +28,15 @@ "Super, Equal, splitratio, 0.1" "AltSuper, Space, togglefloating" "Super, P, pin" - ] - ++ lib.optionals dmsEnabled [ - "Super, Space, exec, dms ipc call spotlight toggle" - "Super, I, exec, dms ipc call settings focusOrToggle" - "Super, N, exec, dms ipc call notepad toggle" - "ShiftSuper, N, exec, dms ipc call notifications toggle" - "Super, M, exec, dms ipc call processlist focusOrToggle" - "Super, L, exec, dms ipc call lock lock" - "ShiftSuper, V, exec, dms ipc call clipboard toggle" - ] - ++ [ + ] ++ lib.optionals dmsEnabled [ + "Super, Space, exec, ${dmsIpcBinds.spotlight}" + "Super, I, exec, ${dmsIpcBinds.settingsFocus}" + "Super, N, exec, ${dmsIpcBinds.notepad}" + "ShiftSuper, N, exec, ${dmsIpcBinds.notifications}" + "Super, M, exec, ${dmsIpcBinds.processlistFocus}" + "Super, L, exec, ${dmsIpcBinds.lock}" + "ShiftSuper, V, exec, ${dmsIpcBinds.clipboard}" + ] ++ [ "Super, Tab, cyclenext" "Super, Tab, bringactivetotop" "Super, left, movefocus, l" diff --git a/modules/desktop/hyprland/default.nix b/modules/desktop/hyprland/default.nix index 12b1d92..1057430 100644 --- a/modules/desktop/hyprland/default.nix +++ b/modules/desktop/hyprland/default.nix @@ -101,7 +101,10 @@ "sleep 1 && hyprctl reload" ]; } - (self.lib.hyprlandBinds { inherit lib dmsEnabled; }) + (self.lib.hyprlandBinds { + inherit lib dmsEnabled; + dmsIpcBinds = self.lib.dmsIpcBinds; + }) { decoration = { rounding = 10; diff --git a/modules/desktop/niri/binds.nix b/modules/desktop/niri/binds.nix index 66d79cc..5caa60c 100644 --- a/modules/desktop/niri/binds.nix +++ b/modules/desktop/niri/binds.nix @@ -1,6 +1,6 @@ { ... }: { flake.lib.niriBinds = - { pkgs, dmsEnabled ? false }: + { pkgs, dmsEnabled ? false, dmsIpcBinds }: let lib = pkgs.lib; in @@ -12,16 +12,16 @@ "Mod+E"."spawn-sh" = "nemo"; } // lib.optionalAttrs dmsEnabled { - "Mod+Space"."spawn-sh" = "dms ipc call spotlight toggle"; - "Mod+V"."spawn-sh" = "dms ipc call clipboard toggle"; - "Mod+N"."spawn-sh" = "dms ipc call notepad toggle"; - "Mod+Shift+N"."spawn-sh" = "dms ipc call notifications toggle"; - "Mod+M"."spawn-sh" = "dms ipc call processlist toggle"; - "Mod+B"."spawn-sh" = ''dms ipc call bar toggle name "Main Bar"; dms ipc call bar toggle name "Bar 2"''; - "Mod+Shift+B"."spawn-sh" = ''dms ipc call bar toggle name "Bar 2"''; - "Mod+A"."spawn-sh" = "dms ipc call ephemera toggle"; - "Mod+numbersign"."spawn-sh" = "dms ipc call wallpaperCarousel toggle"; - "Mod+L"."spawn-sh" = "dms ipc call lock lock"; + "Mod+Space"."spawn-sh" = dmsIpcBinds.spotlight; + "Mod+V"."spawn-sh" = dmsIpcBinds.clipboard; + "Mod+N"."spawn-sh" = dmsIpcBinds.notepad; + "Mod+Shift+N"."spawn-sh" = dmsIpcBinds.notifications; + "Mod+M"."spawn-sh" = dmsIpcBinds.processlist; + "Mod+B"."spawn-sh" = dmsIpcBinds.barToggle; + "Mod+Shift+B"."spawn-sh" = dmsIpcBinds.barToggleBar2; + "Mod+A"."spawn-sh" = dmsIpcBinds.ephemera; + "Mod+numbersign"."spawn-sh" = dmsIpcBinds.wallpaperCarousel; + "Mod+L"."spawn-sh" = dmsIpcBinds.lock; } // { "Mod+Q"."close-window" = _: { }; diff --git a/modules/desktop/niri/default.nix b/modules/desktop/niri/default.nix index ebcd9b8..fa14791 100644 --- a/modules/desktop/niri/default.nix +++ b/modules/desktop/niri/default.nix @@ -21,7 +21,10 @@ niriBaseSettings = pkgs: dmsEnabled: self.lib.niriBaseSettings pkgs // { - binds = self.lib.niriBinds { inherit pkgs dmsEnabled; }; + binds = self.lib.niriBinds { + inherit pkgs dmsEnabled; + dmsIpcBinds = self.lib.dmsIpcBinds; + }; }; mergeNiriSettings = diff --git a/modules/desktop/shells/dms/default.nix b/modules/desktop/shells/dms/default.nix index d4f3bfc..636752c 100644 --- a/modules/desktop/shells/dms/default.nix +++ b/modules/desktop/shells/dms/default.nix @@ -46,4 +46,25 @@ }; flake.homeManagerModules.desktopShellDms = import ./_private/hm.nix; + + # DMS IPC commands shared between Niri and Hyprland keybind tables. + # Defines flake.lib.dmsIpcBinds so each compositor formats the same + # command string in its native shape — Niri attrs vs Hyprland string-list. + # Adding a new DMS keybind requires editing this file plus the + # per-compositor bind layout, not the command string. + flake.lib.dmsIpcBinds = { + spotlight = "dms ipc call spotlight toggle"; + clipboard = "dms ipc call clipboard toggle"; + notepad = "dms ipc call notepad toggle"; + notifications = "dms ipc call notifications toggle"; + processlist = "dms ipc call processlist toggle"; + # Hyprland prefers focusOrToggle (window-aware); niri subscribes to toggle. + processlistFocus = "dms ipc call processlist focusOrToggle"; + settingsFocus = "dms ipc call settings focusOrToggle"; + barToggle = ''dms ipc call bar toggle name "Main Bar"; dms ipc call bar toggle name "Bar 2"''; + barToggleBar2 = ''dms ipc call bar toggle name "Bar 2"''; + ephemera = "dms ipc call ephemera toggle"; + wallpaperCarousel = "dms ipc call wallpaperCarousel toggle"; + lock = "dms ipc call lock lock"; + }; }