land.nix: change workspace management and keybinds to maps

This commit is contained in:
Charlie Root 2024-08-28 12:46:27 +02:00
commit 8144b3931d

View file

@ -14,8 +14,8 @@
(inputs'.split-monitor-workspaces.packages) (inputs'.split-monitor-workspaces.packages)
split-monitor-workspaces split-monitor-workspaces
; ;
inherit (lib) flatten mkIf mkDefault mapAttrsToList; inherit (lib) imap0 flatten optionalString mkIf mkDefault mapAttrsToList;
inherit (builtins) toString; inherit (builtins) map genList attrNames toString;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.hyprland = { programs.hyprland = {
@ -83,55 +83,33 @@ in {
) )
monitors; monitors;
workspace = flatten () # INFO: This is a custom function to map all of my monitors to workspaces.
# Since I use split-monitor-workspaces, I map 10 workspaces to each monitor
# Workspace config # and set the first one to be the default one.
workspace = [ # To be able to use this for a varying amount of monitors we do some nasty trickery:
"1,monitor:eDP-1, default:true" workspace =
"2,monitor:eDP-1" # We're creating several lists of workspace assignments, one for each monitor,
"3,monitor:eDP-1" # and have to merge them into one big list.
"4,monitor:eDP-1" (flatten
"5,monitor:eDP-1" # We then use imap0 insted of map because imap0 starts indexing at zero as oppsed to one with map.
"6,monitor:eDP-1" (imap0 (monitorIndex: monitorName: (
"7,monitor:eDP-1" map (
"8,monitor:eDP-1" i: let
"9,monitor:eDP-1" # we define our own modulo operation for this,
"10,monitor:eDP-1" # since only the first workspace on each monitor is the default workspace.
mod = a: b: a - (b * (a / b));
# "1,monitor:HDMI-A-1, default:true" workspace = toString i;
# "2,monitor:HDMI-A-1" isDefault = (mod i 10) == 1; # 11, 21, 31, ...
# "3,monitor:HDMI-A-1" in "${workspace}, monitor:${monitorName}${optionalString isDefault ", default:true"}"
# "4,monitor:HDMI-A-1" )
# "5,monitor:HDMI-A-1" # we generate a list of 10 elements for each monitor. We have to add 1 each time since genList starts indexing at 0.
# "6,monitor:HDMI-A-1" # also, we add the monitorIndex * 10 to get 10 workspaces for each individual monitor.
# "7,monitor:HDMI-A-1" (genList (i: i + 1 + (10 * monitorIndex)) 10)
# "8,monitor:HDMI-A-1" ))
# "9,monitor:HDMI-A-1" # our attrSet of different monitors
# "10,monitor:HDMI-A-1" (attrNames monitors)))
# # These are my two special workspaces
# "11, monitor:HDMI-A-2, default:true" ++ [
# "12, monitor:HDMI-A-2"
# "13, monitor:HDMI-A-2"
# "14, monitor:HDMI-A-2"
# "15, monitor:HDMI-A-2"
# "16, monitor:HDMI-A-2"
# "17, monitor:HDMI-A-2"
# "18, monitor:HDMI-A-2"
# "19, monitor:HDMI-A-2"
# "20, monitor:HDMI-A-2"
#
# "21, monitor:DP-2, default:true"
# "22, monitor:DP-2"
# "23, monitor:DP-2"
# "24, monitor:DP-2"
# "25, monitor:DP-2"
# "26, monitor:DP-2"
# "27, monitor:DP-2"
# "28, monitor:DP-2"
# "29, monitor:DP-2"
# "30, monitor:DP-2"
#
# scratchpads
"special:nixos, decorate:false" "special:nixos, decorate:false"
"special:keepassxc, decorate:false" "special:keepassxc, decorate:false"
]; ];
@ -141,7 +119,6 @@ in {
kb_variant = ",colemak_dh_wide"; kb_variant = ",colemak_dh_wide";
kb_options = "grp:rctrl_rshift_toggle"; kb_options = "grp:rctrl_rshift_toggle";
sensitivity = 0.0;
follow_mouse = true; follow_mouse = true;
repeat_rate = 50; repeat_rate = 50;
@ -226,58 +203,31 @@ in {
]; ];
# Keybinds # Keybinds
bind = [ bind =
# workspaces
# split-workspace is because of the split-workspace plugin
map (
i: let
mod = a: b: a - (b * (a / b));
key = toString (mod i 10);
workspace = toString i;
in "$mainMod, ${key}, split-workspace, ${workspace}"
) (genList (i: i + 1) 10)
# split-movetoworkspacesilent
++ map (
i: let
mod = a: b: a - (b * (a / b));
key = toString (mod i 10);
workspace = toString i;
in "$mainMod SHIFT, ${key}, split-movetoworkspacesilent, ${workspace}"
) (genList (i: i + 1) 10)
++ [
"$mainMod, RETURN, exec, ${pkgs.foot}/bin/foot" "$mainMod, RETURN, exec, ${pkgs.foot}/bin/foot"
"$mainMod, Q, killactive" "$mainMod, Q, killactive"
"$mainMod, F, fullscreen, 0" "$mainMod, F, fullscreen, 0"
"$mainMod, D, exec, ${pkgs.procps}/bin/pkill fuzzel || ${pkgs.fuzzel}/bin/fuzzel" "$mainMod, D, exec, ${pkgs.procps}/bin/pkill fuzzel || ${pkgs.fuzzel}/bin/fuzzel"
"$mainMod, SPACE, togglefloating, active" "$mainMod, SPACE, togglefloating, active"
# workspaces
# split-workspace is because of the split-workspace plugin
"$mainMod, 1, workspace, 1"
"$mainMod, 2, workspace, 2"
"$mainMod, 3, workspace, 3"
"$mainMod, 4, workspace, 4"
"$mainMod, 5, workspace, 5"
"$mainMod, 6, workspace, 6"
"$mainMod, 7, workspace, 7"
"$mainMod, 8, workspace, 8"
"$mainMod, 9, workspace, 9"
"$mainMod, 0, workspace, 10"
"$mainMod SHIFT, 1, movetoworkspacesilent, 1"
"$mainMod SHIFT, 2, movetoworkspacesilent, 2"
"$mainMod SHIFT, 3, movetoworkspacesilent, 3"
"$mainMod SHIFT, 4, movetoworkspacesilent, 4"
"$mainMod SHIFT, 5, movetoworkspacesilent, 5"
"$mainMod SHIFT, 6, movetoworkspacesilent, 6"
"$mainMod SHIFT, 7, movetoworkspacesilent, 7"
"$mainMod SHIFT, 8, movetoworkspacesilent, 8"
"$mainMod SHIFT, 9, movetoworkspacesilent, 9"
"$mainMod SHIFT, 0, movetoworkspacesilent, 10"
# split-workspace is because of the split-workspace plugin
# "$mainMod, 1, split-workspace, 1"
# "$mainMod, 2, split-workspace, 2"
# "$mainMod, 3, split-workspace, 3"
# "$mainMod, 4, split-workspace, 4"
# "$mainMod, 5, split-workspace, 5"
# "$mainMod, 6, split-workspace, 6"
# "$mainMod, 7, split-workspace, 7"
# "$mainMod, 8, split-workspace, 8"
# "$mainMod, 9, split-workspace, 9"
# "$mainMod, 0, split-workspace, 10"
# "$mainMod SHIFT, 1, split-movetoworkspacesilent, 1"
# "$mainMod SHIFT, 2, split-movetoworkspacesilent, 2"
# "$mainMod SHIFT, 3, split-movetoworkspacesilent, 3"
# "$mainMod SHIFT, 4, split-movetoworkspacesilent, 4"
# "$mainMod SHIFT, 5, split-movetoworkspacesilent, 5"
# "$mainMod SHIFT, 6, split-movetoworkspacesilent, 6"
# "$mainMod SHIFT, 7, split-movetoworkspacesilent, 7"
# "$mainMod SHIFT, 8, split-movetoworkspacesilent, 8"
# "$mainMod SHIFT, 9, split-movetoworkspacesilent, 9"
# "$mainMod SHIFT, 0, split-movetoworkspacesilent, 10"
#
# Move Windows # Move Windows
"$mainMod SHIFT, H, movewindow, l" "$mainMod SHIFT, H, movewindow, l"
"$mainMod SHIFT, J, movewindow, d" "$mainMod SHIFT, J, movewindow, d"
@ -329,10 +279,15 @@ in {
bindle = let bindle = let
volume_up = "${pkgs.pamixer}/bin/pamixer -ui 5"; volume_up = "${pkgs.pamixer}/bin/pamixer -ui 5";
volume_down = "${pkgs.pamixer}/bin/pamixer -ud 5"; volume_down = "${pkgs.pamixer}/bin/pamixer -ud 5";
brightness_up = "${pkgs.brighnessctl}/bin/brighnessctl set +5%";
brightness_down = "${pkgs.brighnessctl}/bin/brighnessctl set 5%-";
in [ in [
", XF86AudioRaiseVolume, exec, ${volume_up}" ", XF86AudioRaiseVolume, exec, ${volume_up}"
", XF86AudioLowerVolume, exec, ${volume_down}" ", XF86AudioLowerVolume, exec, ${volume_down}"
", XF86MonBrighnessUp, exec, ${brightness_up}"
", XF86MonBrighnessDown, exec, ${brightness_down}"
]; ];
# Mouse settings # Mouse settings
bindm = [ bindm = [
"$mainMod, mouse:272, movewindow" "$mainMod, mouse:272, movewindow"