diff --git a/user/sway.nix b/user/sway.nix index c8d7df1..c47edb4 100644 --- a/user/sway.nix +++ b/user/sway.nix @@ -99,30 +99,28 @@ in { mod = "Mod4"; menu = "${pkgs.bmenu}/bin/bmenu run"; terminal = "alacritty"; - workspace_binds = { - "${mod}+1" = "workspace number 1"; - "${mod}+2" = "workspace number 2"; - "${mod}+3" = "workspace number 3"; - "${mod}+4" = "workspace number 4"; - "${mod}+5" = "workspace number 5"; - "${mod}+6" = "workspace number 6"; - "${mod}+7" = "workspace number 7"; - "${mod}+8" = "workspace number 8"; - "${mod}+9" = "workspace number 9"; - "${mod}+0" = "workspace number 10"; - "${mod}+Shift+1" = "move container to workspace number 1"; - "${mod}+Shift+2" = "move container to workspace number 2"; - "${mod}+Shift+3" = "move container to workspace number 3"; - "${mod}+Shift+4" = "move container to workspace number 4"; - "${mod}+Shift+5" = "move container to workspace number 5"; - "${mod}+Shift+6" = "move container to workspace number 6"; - "${mod}+Shift+7" = "move container to workspace number 7"; - "${mod}+Shift+8" = "move container to workspace number 8"; - "${mod}+Shift+9" = "move container to workspace number 9"; - "${mod}+Shift+0" = "move container to workspace number 10"; - }; + + # Utility funcion + # Input: [{v1=1;} {v2=2;}] + # Output: {v1=1;v2=2;} + mergeAttrsSet = lib.foldAttrs (n: _: n) { }; + + # mod+1 to swich to workspace 1 + # mod+shift+1 to move to workspace 1 + workspace_binds = let + workspaceBinds = map makeWorkspaceBinds (lib.range 1 10); + makeWorkspaceBinds = (i: + let + key = toString (lib.mod i 10); + workspaceNumber = toString i; + in { + "${mod}+${key}" = "workspace number ${workspaceNumber}"; + "${mod}+Shift+${key}" = + "move container to workspace number ${workspaceNumber}"; + }); + in mergeAttrsSet workspaceBinds; + prev_next_binds = let - join_dict_arr = builtins.foldl' (a: v: a // v) { }; maybe_window = key: if (lib.strings.hasInfix "button" key) then "--whole-window" @@ -130,11 +128,18 @@ in { ""; prev_binds = map (key: { "${maybe_window key} ${mod}+${key}" = "workspace prev_on_output"; - }) [ key.tabL "bracketleft" "Prior" "button9" "button4" ]; + }) [ + key.tabL + "bracketleft" + "Prior" + "button9" + "button4" + "Shift+Tab" + ]; next_binds = map (key: { "${maybe_window key} ${mod}+${key}" = "workspace next_on_output"; - }) [ key.tabR "bracketright" "Next" "button8" "button5" ]; - in join_dict_arr (prev_binds ++ next_binds); + }) [ key.tabR "bracketright" "Next" "button8" "button5" "Tab" ]; + in mergeAttrsSet (prev_binds ++ next_binds); movement_binds = { "${mod}+${key.left}" = "focus left"; "${mod}+${key.down}" = "focus down"; @@ -203,6 +208,8 @@ in { "${mod}+m" = "mode audio"; "${mod}+b" = "splith"; "${mod}+v" = "splitv"; + "${mod}+t" = "layout toggle split tabbed stacking"; + "${mod}+r" = "layout toggle split"; "${mod}+f" = "fullscreen toggle"; "${mod}+a" = "focus parent"; # "${mod}+s" = "layout stacking"; @@ -215,12 +222,8 @@ in { "${mod}+Shift+c" = "reload"; # "${mod}+Shift+e" = # "exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'"; - "${mod}+r" = "mode resize"; } // workspace_binds // prev_next_binds // movement_binds // audio_binds - // system_binds - # // map (key: "$mod+${key} workspace prev_on_output") [ key.tabL "bracketleft" "Prior" "button9" "button4" ] - # // map (key: "$mod+${key} workspace next_on_output") [ key.tabL "bracketleft" "Prior" "button9" "button4" ] - ; + // system_binds; terminal = pkgs.alacritty.executable; }; };