diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bef867bb..b62d1cc7 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1703,6 +1703,19 @@ in { one place. See https://github.com/glanceapp/glance for more. ''; } + + { + time = "2024-07-27T20:17:19+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.wlr-which-key'. + + wlr-which-key is a keymap manager for wlroots-based compositors, + inspired by which-key.nvim. + + See https://github.com/MaxVerevkin/wlr-which-key for more. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index dbeebfbf..bcc8f37f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -250,6 +250,7 @@ let ./programs/waybar.nix ./programs/wezterm.nix ./programs/wlogout.nix + ./programs/wlr-which-key.nix ./programs/wofi.nix ./programs/wpaperd.nix ./programs/xmobar.nix diff --git a/modules/programs/wlr-which-key.nix b/modules/programs/wlr-which-key.nix new file mode 100644 index 00000000..4142c793 --- /dev/null +++ b/modules/programs/wlr-which-key.nix @@ -0,0 +1,88 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.wlr-which-key; + yamlFormat = pkgs.formats.yaml { }; +in { + meta.maintainers = with lib.maintainers; [ LilleAila mightyiam minijackson ]; + + options.programs.wlr-which-key = { + enable = lib.mkEnableOption "wlr-which-key configuration"; + + commonSettings = lib.mkOption { + type = lib.types.submodule { freeformType = yamlFormat.type; }; + + default = { }; + example = { + anchor = "center"; + background = "#282828d0"; + border = "#8ec07c"; + color = "#fbf1c7"; + }; + + description = '' + Settings to be applied to every configuration under the `configs` option. + ''; + }; + + configs = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + freeformType = yamlFormat.type; + + options.menu = lib.mkOption { + description = "The various menus to display"; + type = lib.types.attrs; + }; + + config = cfg.commonSettings; + }); + + default = { }; + example.config = { + anchor = "center"; + menu = { + p = { + desc = "Power"; + submenu = { + o = { + cmd = "poweroff"; + desc = "Off"; + }; + r = { + cmd = "reboot"; + desc = "Reboot"; + }; + s = { + cmd = "systemctl suspend"; + desc = "Sleep"; + }; + }; + }; + }; + }; + + description = '' + Various configurations for wlr-which-key. + + Each configuration `configs.''${name}` is installed into + `~/.config/wlr-which-key/''${name}.yaml`. + + This enables you to run: `wlr-which-key ''${name}` + + The default configuration is named 'config'. + + For more information on available options, see: + + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ pkgs.wlr-which-key ]; + + xdg.configFile = lib.mapAttrs' (name: value: + lib.nameValuePair "wlr-which-key/${name}.yaml" { + source = yamlFormat.generate "wlr-which-key-${name}.yaml" value; + }) cfg.configs; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 1c143716..19d2179d 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -157,6 +157,7 @@ in import nmtSrc { ./modules/programs/vscode ./modules/programs/watson ./modules/programs/wezterm + ./modules/programs/wlr-which-key ./modules/programs/yazi ./modules/programs/zellij ./modules/programs/zk diff --git a/tests/modules/programs/wlr-which-key/default.nix b/tests/modules/programs/wlr-which-key/default.nix new file mode 100644 index 00000000..8e0ac421 --- /dev/null +++ b/tests/modules/programs/wlr-which-key/default.nix @@ -0,0 +1 @@ +{ wlr-which-key = ./wlr-which-key.nix; } diff --git a/tests/modules/programs/wlr-which-key/expected-config.yaml b/tests/modules/programs/wlr-which-key/expected-config.yaml new file mode 100644 index 00000000..c12a754a --- /dev/null +++ b/tests/modules/programs/wlr-which-key/expected-config.yaml @@ -0,0 +1,68 @@ +anchor: center +background: '#282828d0' +border: '#8ec07c' +border_width: 2 +color: '#fbf1c7' +corner_r: 10 +font: JetBrainsMono Nerd Font 12 +margin_bottom: 0 +margin_left: 0 +margin_right: 0 +margin_top: 0 +menu: + l: + desc: Laptop Screen + submenu: + s: + desc: Scale + submenu: + '1': + cmd: wlr-randr --output eDP-1 --scale 1 + desc: Set Scale to 1.0 + '2': + cmd: wlr-randr --output eDP-1 --scale 1.1 + desc: Set Scale to 1.1 + '3': + cmd: wlr-randr --output eDP-1 --scale 1.2 + desc: Set Scale to 1.2 + '4': + cmd: wlr-randr --output eDP-1 --scale 1.3 + desc: Set Scale to 1.3 + t: + cmd: toggle-laptop-display.sh + desc: Toggle On/Off + p: + desc: Power + submenu: + o: + cmd: poweroff + desc: 'Off' + r: + cmd: reboot + desc: Reboot + s: + cmd: systemctl suspend + desc: Sleep + t: + desc: Theme + submenu: + d: + cmd: dark-theme on + desc: Dark + l: + cmd: dark-theme off + desc: Light + t: + cmd: dark-theme toggle + desc: Toggle + w: + desc: WiFi + submenu: + c: + cmd: kitty --class nmtui-connect nmtui-connect + desc: Connections + t: + cmd: wifi_toggle.sh + desc: Toggle +padding: 15 +separator: ' ➜ ' diff --git a/tests/modules/programs/wlr-which-key/expected-other.yaml b/tests/modules/programs/wlr-which-key/expected-other.yaml new file mode 100644 index 00000000..ce7d5c28 --- /dev/null +++ b/tests/modules/programs/wlr-which-key/expected-other.yaml @@ -0,0 +1,17 @@ +anchor: center +background: '#282828d0' +border: '#8ec07c' +border_width: 2 +color: '#fbf1c7' +corner_r: 10 +font: JetBrainsMono Nerd Font 12 +margin_bottom: 0 +margin_left: 0 +margin_right: 0 +margin_top: 0 +menu: + a: + cmd: echo aaah + desc: Say aaah +padding: 15 +separator: ' ➜ ' diff --git a/tests/modules/programs/wlr-which-key/wlr-which-key.nix b/tests/modules/programs/wlr-which-key/wlr-which-key.nix new file mode 100644 index 00000000..949b8725 --- /dev/null +++ b/tests/modules/programs/wlr-which-key/wlr-which-key.nix @@ -0,0 +1,123 @@ +{ + programs.wlr-which-key = { + enable = true; + + commonSettings = { + anchor = "center"; + background = "#282828d0"; + border = "#8ec07c"; + border_width = 2; + color = "#fbf1c7"; + corner_r = 10; + font = "JetBrainsMono Nerd Font 12"; + margin_bottom = 0; + margin_left = 0; + margin_right = 0; + margin_top = 0; + padding = 15; + separator = " ➜ "; + }; + + # Example config in the README + configs.config = { + menu = { + l = { + desc = "Laptop Screen"; + submenu = { + s = { + desc = "Scale"; + submenu = { + "1" = { + cmd = "wlr-randr --output eDP-1 --scale 1"; + desc = "Set Scale to 1.0"; + }; + "2" = { + cmd = "wlr-randr --output eDP-1 --scale 1.1"; + desc = "Set Scale to 1.1"; + }; + "3" = { + cmd = "wlr-randr --output eDP-1 --scale 1.2"; + desc = "Set Scale to 1.2"; + }; + "4" = { + cmd = "wlr-randr --output eDP-1 --scale 1.3"; + desc = "Set Scale to 1.3"; + }; + }; + }; + t = { + cmd = "toggle-laptop-display.sh"; + desc = "Toggle On/Off"; + }; + }; + }; + p = { + desc = "Power"; + submenu = { + o = { + cmd = "poweroff"; + desc = "Off"; + }; + r = { + cmd = "reboot"; + desc = "Reboot"; + }; + s = { + cmd = "systemctl suspend"; + desc = "Sleep"; + }; + }; + }; + t = { + desc = "Theme"; + submenu = { + d = { + cmd = "dark-theme on"; + desc = "Dark"; + }; + l = { + cmd = "dark-theme off"; + desc = "Light"; + }; + t = { + cmd = "dark-theme toggle"; + desc = "Toggle"; + }; + }; + }; + w = { + desc = "WiFi"; + submenu = { + c = { + cmd = "kitty --class nmtui-connect nmtui-connect"; + desc = "Connections"; + }; + t = { + cmd = "wifi_toggle.sh"; + desc = "Toggle"; + }; + }; + }; + }; + }; + + configs.other.menu.a = { + cmd = "echo aaah"; + desc = "Say aaah"; + }; + }; + + test.stubs.wlr-which-key = { }; + + nmt.script = '' + assertFileExists home-files/.config/wlr-which-key/config.yaml + assertFileContent home-files/.config/wlr-which-key/config.yaml ${ + ./expected-config.yaml + } + + assertFileExists home-files/.config/wlr-which-key/other.yaml + assertFileContent home-files/.config/wlr-which-key/other.yaml ${ + ./expected-other.yaml + } + ''; +}