diff --git a/hm/desktop/i3.nix b/hm/desktop/i3.nix index de153d7..69bffe8 100644 --- a/hm/desktop/i3.nix +++ b/hm/desktop/i3.nix @@ -10,11 +10,31 @@ let '' }"; + # CARDINALS + cardinals = [ + { vi = "h"; arrow = "Left"; container = "left"; workspace = "prev_on_output"; output = "left"; } + { vi = "l"; arrow = "Right"; container = "right"; workspace = "next_on_output"; output = "right"; } + { vi = "j"; arrow = "Down"; container = "up"; workspace = "prev"; output = "below"; } + { vi = "k"; arrow = "Up"; container = "down"; workspace = "next"; output = "above"; } + ]; + forEachCardinal = f: map (c: f c) cardinals; + + # WORKSPACES + workspaces_keys = lib.strings.stringToCharacters "1234567890"; + workspaces = map + (i: { + id = i; + name = builtins.toString (i + 1); + key = builtins.elemAt workspaces_keys i; + }) + (lib.lists.range 0 ((builtins.length workspaces_keys) - 1)); + forEachWorkspace = f: map (w: f w) workspaces; + # MISC mod = config.xsession.windowManager.i3.config.modifier; - fonts = config.stylix.fonts; rofi = "exec --no-startup-id ${config.programs.rofi.package}/bin/rofi"; modes = config.frogeye.desktop.i3.bindmodes; + x11_screens = config.frogeye.desktop.x11_screens; in { config = lib.mkIf config.xsession.windowManager.i3.enable { @@ -22,7 +42,7 @@ in xsession.windowManager.i3.config = { modifier = "Mod4"; fonts = { - names = [ fonts.sansSerif.name ]; + names = [ config.stylix.fonts.sansSerif.name ]; }; terminal = "alacritty"; colors = let ignore = "#ff00ff"; in @@ -47,9 +67,6 @@ in button2 = "kill"; # Rofi "${mod}+i" = "exec --no-startup-id ${pkgs.rofimoji}/bin/rofimoji"; - "${mod}+plus" = "${rofi} -modi ssh -show ssh"; - "${mod}+รน" = "${rofi} -modi ssh -show ssh -ssh-command '{terminal} -e {ssh-client} {host} -t \"sudo -s -E\"'"; - # TODO In which keyboard layout? "${mod}+Tab" = "${rofi} -modi window -show window"; # start program launcher "${mod}+d" = "${rofi} -modi run -show run"; @@ -69,16 +86,6 @@ in ${pkgs.libgnomekbd}/bin/gkbd-keyboard-display -l $layout '' }"; - # change focus - "${mod}+h" = "focus left; ${focus}"; - "${mod}+j" = "focus down; ${focus}"; - "${mod}+k" = "focus up; ${focus}"; - "${mod}+l" = "focus right; ${focus}"; - # move focused window - "${mod}+Shift+h" = "move left; ${focus}"; - "${mod}+Shift+j" = "move down; ${focus}"; - "${mod}+Shift+k" = "move up; ${focus}"; - "${mod}+Shift+l" = "move right; ${focus}"; # workspace back and forth (with/without active container) "${mod}+b" = "workspace back_and_forth; ${focus}"; "${mod}+Shift+b" = "move container to workspace back_and_forth; workspace back_and_forth; ${focus}"; @@ -94,60 +101,30 @@ in "${mod}+space" = "focus mode_toggle; ${focus}"; "${mod}+a" = "focus parent; ${focus}"; "${mod}+q" = "focus child; ${focus}"; - # Switch to workspace - "${mod}+1" = "workspace 1; ${focus}"; - "${mod}+2" = "workspace 2; ${focus}"; - "${mod}+3" = "workspace 3; ${focus}"; - "${mod}+4" = "workspace 4; ${focus}"; - "${mod}+5" = "workspace 5; ${focus}"; - "${mod}+6" = "workspace 6; ${focus}"; - "${mod}+7" = "workspace 7; ${focus}"; - "${mod}+8" = "workspace 8; ${focus}"; - "${mod}+9" = "workspace 9; ${focus}"; - "${mod}+0" = "workspace 10; ${focus}"; - # TODO Prevent repetitions, see workspace assignation for example - #navigate workspaces next / previous - "${mod}+Ctrl+h" = "workspace prev_on_output; ${focus}"; - "${mod}+Ctrl+l" = "workspace next_on_output; ${focus}"; - "${mod}+Ctrl+j" = "workspace prev; ${focus}"; - "${mod}+Ctrl+k" = "workspace next; ${focus}"; - # Move to workspace next / previous with focused container - "${mod}+Ctrl+Shift+h" = "move container to workspace prev_on_output; workspace prev_on_output; ${focus}"; - "${mod}+Ctrl+Shift+l" = "move container to workspace next_on_output; workspace next_on_output; ${focus}"; - "${mod}+Ctrl+Shift+j" = "move container to workspace prev; workspace prev; ${focus}"; - "${mod}+Ctrl+Shift+k" = "move container to workspace next; workspace next; ${focus}"; - # move focused container to workspace - "${mod}+ctrl+1" = "move container to workspace 1; ${focus}"; - "${mod}+ctrl+2" = "move container to workspace 2; ${focus}"; - "${mod}+ctrl+3" = "move container to workspace 3; ${focus}"; - "${mod}+ctrl+4" = "move container to workspace 4; ${focus}"; - "${mod}+ctrl+5" = "move container to workspace 5; ${focus}"; - "${mod}+ctrl+6" = "move container to workspace 6; ${focus}"; - "${mod}+ctrl+7" = "move container to workspace 7; ${focus}"; - "${mod}+ctrl+8" = "move container to workspace 8; ${focus}"; - "${mod}+ctrl+9" = "move container to workspace 9; ${focus}"; - "${mod}+ctrl+0" = "move container to workspace 10; ${focus}"; - # move to workspace with focused container - "${mod}+shift+1" = "move container to workspace 1; workspace 1; ${focus}"; - "${mod}+shift+2" = "move container to workspace 2; workspace 2; ${focus}"; - "${mod}+shift+3" = "move container to workspace 3; workspace 3; ${focus}"; - "${mod}+shift+4" = "move container to workspace 4; workspace 4; ${focus}"; - "${mod}+shift+5" = "move container to workspace 5; workspace 5; ${focus}"; - "${mod}+shift+6" = "move container to workspace 6; workspace 6; ${focus}"; - "${mod}+shift+7" = "move container to workspace 7; workspace 7; ${focus}"; - "${mod}+shift+8" = "move container to workspace 8; workspace 8; ${focus}"; - "${mod}+shift+9" = "move container to workspace 9; workspace 9; ${focus}"; - "${mod}+shift+0" = "move container to workspace 10; workspace 10; ${focus}"; - # move workspaces to screen (arrow keys) - "${mod}+ctrl+shift+Right" = "move workspace to output right; ${focus}"; - "${mod}+ctrl+shift+Left" = "move workspace to output left; ${focus}"; - "${mod}+Ctrl+Shift+Up" = "move workspace to output above; ${focus}"; - "${mod}+Ctrl+Shift+Down" = "move workspace to output below; ${focus}"; # i3 control "${mod}+Shift+c" = "reload"; "${mod}+Shift+r" = "restart"; "${mod}+Shift+e" = "exit"; - } // lib.mapAttrs' (k: v: lib.nameValuePair v.enter "mode ${v.name}") modes; + } // lib.mapAttrs' (k: v: lib.nameValuePair v.enter "mode ${v.name}") modes + // lib.attrsets.mergeAttrsList (forEachCardinal (c: { + # change focus + "${mod}+${c.vi}" = "focus ${c.container}; ${focus}"; + # move focused window + "${mod}+Shift+${c.vi}" = "move ${c.container}; ${focus}"; + #navigate workspaces next / previous + "${mod}+Ctrl+${c.vi}" = "workspace ${c.workspace}; ${focus}"; + # Move to workspace next / previous with focused container + "${mod}+Ctrl+Shift+${c.vi}" = "move container to workspace ${c.workspace}; workspace ${c.workspace}; ${focus}"; + # move workspaces to screen (arrow keys) + "${mod}+Ctrl+Shift+${c.arrow}" = "move workspace to output ${c.output}; ${focus}"; + })) // lib.attrsets.mergeAttrsList (forEachWorkspace (w: { + # Switch to workspace + "${mod}+${w.key}" = "workspace ${w.name}; ${focus}"; + # move focused container to workspace + "${mod}+ctrl+${w.key}" = "move container to workspace ${w.name}; ${focus}"; + # move to workspace with focused container + "${mod}+shift+${w.key}" = "move container to workspace ${w.name}; workspace ${w.name}; ${focus}"; + })); modes = lib.mapAttrs' (k: v: lib.nameValuePair v.name (v.bindings // lib.optionalAttrs v.return_bindings { "Return" = "mode default"; @@ -183,12 +160,7 @@ in workspaceLayout = "tabbed"; focus.mouseWarping = true; # i3 only supports warping to workspace, hence ${focus} workspaceOutputAssign = - let - x11_screens = config.frogeye.desktop.x11_screens; - workspaces = map (i: { name = toString i; key = toString (lib.mod i 10); }) (lib.lists.range 1 10); - forEachWorkspace = f: map (w: f { w = w; workspace = ((builtins.elemAt workspaces w)); }) (lib.lists.range 0 ((builtins.length workspaces) - 1)); - in - forEachWorkspace ({ w, workspace }: { output = builtins.elemAt x11_screens (lib.mod w (builtins.length x11_screens)); workspace = workspace.name; }); + forEachWorkspace (w: { output = builtins.elemAt x11_screens (lib.mod w.id (builtins.length x11_screens)); workspace = w.name; }); }; frogeye.desktop.i3.bindmodes = { "Resize" = {