diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index 6487cf1..4ee7e6f 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -5,40 +5,39 @@ ... }: # The Hyprland compositor. -let # NOLINT(let_order) +let cfg = config.modules.desktop.session.hyprland; # NOLINT(let_order) + lua = rec { + toLua = lib.generators.toLua { }; + call = + function: args: + lib.generators.mkLuaInline "${function}(${lib.concatMapStringsSep ", " toLua args})"; + bind = key: dispatcher: { + _args = [ + key + dispatcher + ]; + }; + bindWith = key: dispatcher: options: { + _args = [ + key + dispatcher + options + ]; + }; + execBind = key: command: bind key (call "hl.dsp.exec_cmd" [ command ]); + execBindWith = + key: command: options: + bindWith key (call "hl.dsp.exec_cmd" [ command ]) options; + + # Numbered-workspace switch and move for 1..9, the operator's i3 muscle memory. + workspaceBinds = lib.concatMap (n: [ + (bind "SUPER + ${toString n}" (call "hl.dsp.focus" [ { workspace = n; } ])) + (bind "SUPER + SHIFT + ${toString n}" (call "hl.dsp.window.move" [ { workspace = n; } ])) + ]) (lib.range 1 9); + }; + cursor = config.stylix.cursor; - bind = key: dispatcher: { - _args = [ - key - dispatcher - ]; - }; - luaCall = function: args: mkLuaInline "${function}(${lib.concatMapStringsSep ", " toLua args})"; - terminal = "ghostty"; - execBindWith = - key: command: options: - bindWith key (luaCall "hl.dsp.exec_cmd" [ command ]) options; - bindWith = key: dispatcher: options: { - _args = [ - key - dispatcher - options - ]; - }; - - # Numbered-workspace switch and move for 1..9, the operator's i3 muscle memory. - workspaceBinds = lib.concatMap (n: [ - (bind "${mod} + ${toString n}" (luaCall "hl.dsp.focus" [ { workspace = n; } ])) - (bind "${mod} + SHIFT + ${toString n}" (luaCall "hl.dsp.window.move" [ { workspace = n; } ])) - ]) (lib.range 1 9); - - execBind = key: command: bind key (luaCall "hl.dsp.exec_cmd" [ command ]); - - inherit (lib.generators) mkLuaInline; - - mod = "SUPER"; - toLua = lib.generators.toLua { }; user = config.user.name; # Flip the tiling strategy between the two built-in layouts, since neither a @@ -237,23 +236,23 @@ in ]; bind = [ - (execBind "${mod} + Return" terminal) + (lua.execBind "SUPER + Return" "ghostty") # Move focus. - (bind "${mod} + H" (luaCall "hl.dsp.focus" [ { direction = "left"; } ])) - (bind "${mod} + J" (luaCall "hl.dsp.focus" [ { direction = "down"; } ])) - (bind "${mod} + K" (luaCall "hl.dsp.focus" [ { direction = "up"; } ])) - (bind "${mod} + L" (luaCall "hl.dsp.focus" [ { direction = "right"; } ])) + (lua.bind "SUPER + H" (lua.call "hl.dsp.focus" [ { direction = "left"; } ])) + (lua.bind "SUPER + J" (lua.call "hl.dsp.focus" [ { direction = "down"; } ])) + (lua.bind "SUPER + K" (lua.call "hl.dsp.focus" [ { direction = "up"; } ])) + (lua.bind "SUPER + L" (lua.call "hl.dsp.focus" [ { direction = "right"; } ])) # Move the window within the layout. - (bind "${mod} + SHIFT + H" (luaCall "hl.dsp.window.move" [ { direction = "left"; } ])) - (bind "${mod} + SHIFT + J" (luaCall "hl.dsp.window.move" [ { direction = "down"; } ])) - (bind "${mod} + SHIFT + K" (luaCall "hl.dsp.window.move" [ { direction = "up"; } ])) - (bind "${mod} + SHIFT + L" (luaCall "hl.dsp.window.move" [ { direction = "right"; } ])) + (lua.bind "SUPER + SHIFT + H" (lua.call "hl.dsp.window.move" [ { direction = "left"; } ])) + (lua.bind "SUPER + SHIFT + J" (lua.call "hl.dsp.window.move" [ { direction = "down"; } ])) + (lua.bind "SUPER + SHIFT + K" (lua.call "hl.dsp.window.move" [ { direction = "up"; } ])) + (lua.bind "SUPER + SHIFT + L" (lua.call "hl.dsp.window.move" [ { direction = "right"; } ])) # Resize the active window. - (bind "${mod} + ALT + H" ( - luaCall "hl.dsp.window.resize" [ + (lua.bind "SUPER + ALT + H" ( + lua.call "hl.dsp.window.resize" [ { x = -40; y = 0; @@ -261,8 +260,8 @@ in } ] )) - (bind "${mod} + ALT + J" ( - luaCall "hl.dsp.window.resize" [ + (lua.bind "SUPER + ALT + J" ( + lua.call "hl.dsp.window.resize" [ { x = 0; y = 40; @@ -270,8 +269,8 @@ in } ] )) - (bind "${mod} + ALT + K" ( - luaCall "hl.dsp.window.resize" [ + (lua.bind "SUPER + ALT + K" ( + lua.call "hl.dsp.window.resize" [ { x = 0; y = -40; @@ -279,8 +278,8 @@ in } ] )) - (bind "${mod} + ALT + L" ( - luaCall "hl.dsp.window.resize" [ + (lua.bind "SUPER + ALT + L" ( + lua.call "hl.dsp.window.resize" [ { x = 40; y = 0; @@ -289,41 +288,43 @@ in ] )) - (bind "${mod} + Space" (luaCall "hl.dsp.window.float" [ { action = "toggle"; } ])) - (bind "${mod} + F" (luaCall "hl.dsp.window.fullscreen" [ ])) + (lua.bind "SUPER + Space" (lua.call "hl.dsp.window.float" [ { action = "toggle"; } ])) + (lua.bind "SUPER + F" (lua.call "hl.dsp.window.fullscreen" [ ])) # togglesplit is a dwindle layout message, reached through layout. - (bind "${mod} + T" (luaCall "hl.dsp.layout" [ "togglesplit" ])) - (execBind "${mod} + SHIFT + T" "${toggleLayout}") - (bind "${mod} + SHIFT + Q" (luaCall "hl.dsp.window.close" [ ])) - (bind "${mod} + CTRL + Q" (luaCall "hl.dsp.window.kill" [ ])) + (lua.bind "SUPER + T" (lua.call "hl.dsp.layout" [ "togglesplit" ])) + (lua.execBind "SUPER + SHIFT + T" "${toggleLayout}") + (lua.bind "SUPER + SHIFT + Q" (lua.call "hl.dsp.window.close" [ ])) + (lua.bind "SUPER + CTRL + Q" (lua.call "hl.dsp.window.kill" [ ])) # Volume and brightness keys repeat while held, each raising a popup # through the OSD client. # Volume is capped at 100 percent. # The client floors brightness so a full hold cannot black the screen out. - (execBindWith "XF86AudioRaiseVolume" + (lua.execBindWith "XF86AudioRaiseVolume" "${pkgs.swayosd}/bin/swayosd-client --output-volume raise --max-volume 100" { repeating = true; } ) - (execBindWith "XF86AudioLowerVolume" "${pkgs.swayosd}/bin/swayosd-client --output-volume lower" { + (lua.execBindWith "XF86AudioLowerVolume" "${pkgs.swayosd}/bin/swayosd-client --output-volume lower" + { + repeating = true; + } + ) + (lua.execBindWith "XF86MonBrightnessUp" "${pkgs.swayosd}/bin/swayosd-client --brightness raise" { repeating = true; }) - (execBindWith "XF86MonBrightnessUp" "${pkgs.swayosd}/bin/swayosd-client --brightness raise" { - repeating = true; - }) - (execBindWith "XF86MonBrightnessDown" "${pkgs.swayosd}/bin/swayosd-client --brightness lower" { + (lua.execBindWith "XF86MonBrightnessDown" "${pkgs.swayosd}/bin/swayosd-client --brightness lower" { repeating = true; }) # Mute and media transport still fire while the session is locked. - (execBindWith "XF86AudioMute" "${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle" { + (lua.execBindWith "XF86AudioMute" "${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle" { locked = true; }) - (execBindWith "XF86AudioPlay" "${pkgs.playerctl}/bin/playerctl play-pause" { locked = true; }) - (execBindWith "XF86AudioNext" "${pkgs.playerctl}/bin/playerctl next" { locked = true; }) - (execBindWith "XF86AudioPrev" "${pkgs.playerctl}/bin/playerctl previous" { locked = true; }) + (lua.execBindWith "XF86AudioPlay" "${pkgs.playerctl}/bin/playerctl play-pause" { locked = true; }) + (lua.execBindWith "XF86AudioNext" "${pkgs.playerctl}/bin/playerctl next" { locked = true; }) + (lua.execBindWith "XF86AudioPrev" "${pkgs.playerctl}/bin/playerctl previous" { locked = true; }) ] - ++ workspaceBinds; + ++ lua.workspaceBinds; }; }; };