move keybinds between i3 and keybinds file

This commit is contained in:
Noah Masur 2023-08-06 23:19:52 -04:00
parent f16ef49792
commit 97c94e6b6a
2 changed files with 85 additions and 85 deletions

View File

@ -5,6 +5,19 @@ let
lockUpdate = lockUpdate =
"${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.wallpaper} --display 1 --span"; "${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.wallpaper} --display 1 --span";
workspaces = {
"1" = "1:I";
"2" = "2:II";
"3" = "3:III";
"4" = "4:IV";
"5" = "5:V";
"6" = "6:VI";
"7" = "7:VII";
"8" = "8:VIII";
"9" = "9:IX";
"0" = "10:X";
};
in { in {
config = lib.mkIf pkgs.stdenv.isLinux { config = lib.mkIf pkgs.stdenv.isLinux {
@ -21,23 +34,18 @@ in {
home-manager.users.${config.user} = { home-manager.users.${config.user} = {
xsession.windowManager.i3 = { xsession.windowManager.i3 = {
enable = config.services.xserver.enable; enable = config.services.xserver.enable;
config = let config = let modifier = "Mod4"; # Super key
modifier = "Mod4"; # Super key
ws1 = "1:I";
ws2 = "2:II";
ws3 = "3:III";
ws4 = "4:IV";
in { in {
modifier = modifier; modifier = modifier;
assigns = { assigns = {
"${ws1}" = [{ class = "Firefox"; }]; "${workspaces."1"}" = [{ class = "Firefox"; }];
"${ws2}" = [ "${workspaces."2"}" = [
{ class = "kitty"; } { class = "kitty"; }
{ class = "aerc"; } { class = "aerc"; }
{ class = "obsidian"; } { class = "obsidian"; }
]; ];
"${ws3}" = [{ class = "discord"; }]; "${workspaces."3"}" = [{ class = "discord"; }];
"${ws4}" = [{ class = "Steam"; }]; "${workspaces."4"}" = [{ class = "Steam"; }];
}; };
bars = [{ command = "echo"; }]; # Disable i3bar bars = [{ command = "echo"; }]; # Disable i3bar
colors = let colors = let
@ -83,17 +91,7 @@ in {
newWindow = "urgent"; newWindow = "urgent";
followMouse = false; followMouse = false;
}; };
keybindings = { keybindings = { };
# Resizing
"${modifier}+r" = ''mode "resize"'';
"${modifier}+Control+Shift+h" =
"resize shrink width 10 px or 10 ppt";
"${modifier}+Control+Shift+j" =
"resize grow height 10 px or 10 ppt";
"${modifier}+Control+Shift+k" =
"resize shrink height 10 px or 10 ppt";
"${modifier}+Control+Shift+l" = "resize grow width 10 px or 10 ppt";
};
modes = { }; modes = { };
startup = [ startup = [
{ {
@ -102,13 +100,15 @@ in {
notification = false; notification = false;
} }
{ {
command = command = "i3-msg workspace ${
"i3-msg workspace ${ws2}, move workspace to output right"; workspaces."1"
}, move workspace to output right";
notification = false; notification = false;
} }
{ {
command = command = "i3-msg workspace ${
"i3-msg workspace ${ws1}, move workspace to output left"; workspaces."2"
}, move workspace to output left";
notification = false; notification = false;
} }
]; ];
@ -124,6 +124,61 @@ in {
extraConfig = ""; extraConfig = "";
}; };
programs.sxhkd.keybindings = let
# Shortcuts
binds =
config.home-manager.users.${config.user}.programs.sxhkd.keybindings;
i3-msg = "${pkgs.i3}/bin/i3-msg";
# Create an attrset of keybinds to actions for every workspace by number
bindAll = let workspaceNums = builtins.attrNames workspaces;
in keybindFunction: actionFunction:
# 1 -> "keybind + 1" -> "some action on ws 1"
lib.genAttrs (map keybindFunction workspaceNums) actionFunction;
# Look up the name of the workspace based on its number
lookup = num: builtins.getAttr num workspaces;
in {
# Window navigation
"super + {h,j,k,l}" = ''${i3-msg} "focus {left,down,up,right}"'';
"super + {Left,Down,Up,Right}" = binds."super + {h,j,k,l}";
"super + shift + {h,j,k,l}" = ''${i3-msg} "move {left,down,up,right}"'';
"super + shift + {Left,Down,Up,Right}" =
binds."super + shift + {h,j,k,l}";
"super + q" = ''${i3-msg} "kill"'';
"super + f" = ''${i3-msg} "fullscreen toggle"'';
# Screen management
"super + control + l" = ''${i3-msg} "move workspace to output right"'';
"super + control + h" = ''${i3-msg} "move workspace to output left"'';
# Window layouts and tiling
"super + {i,v}" = ''${i3-msg} "split {h,v}"'';
"super + {s,t,e}" =
''${i3-msg} "layout {stacking,tabbed,toggle split}"'';
"super + shift + space" = ''${i3-msg} "floating toggle"'';
"super + control + space" = ''${i3-msg} "focus mode_toggle"'';
"super + a" = ''${i3-msg} "focus parent"'';
# Restart and reload
"super + shift + {c,r}" = ''${i3-msg} "{reload,restart}"'';
}
# Bind super + workspace -> switch to workspace
// (bindAll (num: "super + ${num}")
(num: ''${i3-msg} "workspace ${lookup num}"''))
# Bind super + shift + workspace -> move to workspace
// (bindAll (num: "super + shift + ${num}") (num:
''
${i3-msg} "move container to workspace ${lookup num}; workspace ${
lookup num
}"''));
lockScreenCommand = lockScreenCommand =
"${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span";

View File

@ -1,39 +1,8 @@
{ config, pkgs, lib, ... }: { config, pkgs, ... }:
let let
keybindings = binds = config.home-manager.users.${config.user}.programs.sxhkd.keybindings;
config.home-manager.users.${config.user}.programs.sxhkd.keybindings;
workspaceBindings = let
workspaces = {
"1" = "1:I";
"2" = "2:II";
"3" = "3:III";
"4" = "4:IV";
"5" = "5:V";
"6" = "6:VI";
"7" = "7:VII";
"8" = "8:VIII";
"9" = "9:IX";
"0" = "10:X";
};
# Create an attrset of keybinds to actions for every workspace by number
bindAll = keybindFunction: actionFunction:
(lib.genAttrs (map keybindFunction (builtins.attrNames workspaces))
actionFunction);
# Look up the name of the workspace based on its number
lookup = num: builtins.getAttr num workspaces;
in (bindAll (num: "super + ${num}")
(num: ''${pkgs.i3}/bin/i3-msg "workspace ${lookup num}"''))
// (bindAll (num: "super + shift + ${num}") (num:
''
${pkgs.i3}/bin/i3-msg "move container to workspace ${
lookup num
}; workspace ${lookup num}"''));
in { in {
@ -46,37 +15,14 @@ in {
${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 {- 30,+ 30} && sleep 1; \\ ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 {- 30,+ 30} && sleep 1; \\
${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 {- 30,+ 30} ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 {- 30,+ 30}
''; '';
"XF86MonBrightness{Down,Up}" = keybindings."shift + {F11,F12}"; "XF86MonBrightness{Down,Up}" = binds."shift + {F11,F12}";
# Media controls # Media controls
"XF86Audio{Play,Stop,Next,Prev}" = "XF86Audio{Play,Stop,Next,Prev}" =
"${pkgs.playerctl}/bin/playerctl {play-pause,stop,next,previous}"; "${pkgs.playerctl}/bin/playerctl {play-pause,stop,next,previous}";
# Window management # Toggle bar
"super + q" = ''${pkgs.i3}/bin/i3-msg "kill"'';
"super + b" = config.toggleBarCommand; "super + b" = config.toggleBarCommand;
"super + f" = ''${pkgs.i3}/bin/i3-msg "fullscreen toggle"'';
"super + {h,j,k,l}" =
''${pkgs.i3}/bin/i3-msg "focus {left,down,up,right}"'';
"super + {Left,Down,Up,Right}" = keybindings."super + {h,j,k,l}";
"super + shift + {h,j,k,l}" =
''${pkgs.i3}/bin/i3-msg "move {left,down,up,right}"'';
"super + shift + {Left,Down,Up,Right}" =
keybindings."super + shift + {h,j,k,l}";
# Screen management
"super + control + l" =
''${pkgs.i3}/bin/i3-msg "move workspace to output right"'';
"super + control + h" =
''${pkgs.i3}/bin/i3-msg "move workspace to output left"'';
# Window layouts and tiling
"super + {i,v}" = ''${pkgs.i3}/bin/i3-msg "split {h,v}"'';
"super + {s,t,e}" =
''${pkgs.i3}/bin/i3-msg "layout {stacking,tabbed,toggle split}"'';
"super + shift + space" = ''${pkgs.i3}/bin/i3-msg "floating toggle"'';
"super + control + space" = ''${pkgs.i3}/bin/i3-msg "focus mode_toggle"'';
"super + a" = ''${pkgs.i3}/bin/i3-msg "focus parent"'';
# Launchers # Launchers
"super + Return" = config.terminal; "super + Return" = config.terminal;
@ -87,14 +33,13 @@ in {
"super + shift + period" = config.powerCommand; "super + shift + period" = config.powerCommand;
"super + shift + m" = config.brightnessCommand; "super + shift + m" = config.brightnessCommand;
"super + c" = config.calculatorCommand; "super + c" = config.calculatorCommand;
"super + shift + {c,r}" = ''${pkgs.i3}/bin/i3-msg "{reload,restart}"'';
"super + shift + x" = config.lockScreenCommand; "super + shift + x" = config.lockScreenCommand;
"super + alt + h" = "super + alt + h" =
"${config.terminal} sh -c '${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; "${config.terminal} sh -c '${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'";
"super + alt + r" = "super + alt + r" =
"${config.terminal} sh -c 'doas nixos-rebuild switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; "${config.terminal} sh -c 'doas nixos-rebuild switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'";
} // workspaceBindings; };
}; };
} }