From 9ff2def4aec352dcd7fced53afea321c6e0c1c41 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 2 Jul 2023 14:37:56 -0600 Subject: [PATCH] move keybinds to sxhkd --- modules/common/applications/kitty.nix | 15 +-- modules/nixos/graphical/default.nix | 28 ++-- modules/nixos/graphical/i3.nix | 140 +------------------- modules/nixos/graphical/keybinds.nix | 100 ++++++++++++++ modules/nixos/graphical/picom.nix | 2 +- modules/nixos/graphical/polybar.nix | 2 +- modules/nixos/graphical/rofi.nix | 20 +-- modules/nixos/graphical/rofi/brightness.nix | 0 modules/nixos/graphical/rofi/power.nix | 0 modules/nixos/graphical/sway.nix | 15 ++- 10 files changed, 147 insertions(+), 175 deletions(-) create mode 100644 modules/nixos/graphical/keybinds.nix mode change 100755 => 100644 modules/nixos/graphical/rofi/brightness.nix mode change 100755 => 100644 modules/nixos/graphical/rofi/power.nix diff --git a/modules/common/applications/kitty.nix b/modules/common/applications/kitty.nix index ff69175..3ad0697 100644 --- a/modules/common/applications/kitty.nix +++ b/modules/common/applications/kitty.nix @@ -11,23 +11,10 @@ config = lib.mkIf (config.gui.enable && config.kitty.enable) { - # Set the Rofi-Systemd terminal for viewing logs - # Using optionalAttrs because only available in NixOS - environment = { } // lib.attrsets.optionalAttrs - (builtins.hasAttr "sessionVariables" config.environment) { - sessionVariables.ROFI_SYSTEMD_TERM = "${pkgs.kitty}/bin/kitty"; - }; + terminal = "${pkgs.kitty}/bin/kitty"; home-manager.users.${config.user} = { - # Set the i3 terminal - xsession.windowManager.i3.config.terminal = - lib.mkIf pkgs.stdenv.isLinux "kitty"; - - # Set the Rofi terminal for running programs - programs.rofi.terminal = - lib.mkIf pkgs.stdenv.isLinux "${pkgs.kitty}/bin/kitty"; - programs.kitty = { enable = true; environment = { }; diff --git a/modules/nixos/graphical/default.nix b/modules/nixos/graphical/default.nix index 018dd77..26fc95d 100644 --- a/modules/nixos/graphical/default.nix +++ b/modules/nixos/graphical/default.nix @@ -12,14 +12,6 @@ options = { - launcherCommand = lib.mkOption { - type = lib.types.str; - description = "Command to use for launching"; - }; - systemdSearch = lib.mkOption { - type = lib.types.str; - description = "Command to use for interacting with systemd"; - }; altTabCommand = lib.mkOption { type = lib.types.str; description = "Command to use for choosing windows"; @@ -36,14 +28,30 @@ type = lib.types.str; description = "Command to use for quick calculations"; }; - toggleBarCommand = lib.mkOption { + launcherCommand = lib.mkOption { type = lib.types.str; - description = "Command to hide and show the status bar."; + description = "Command to use for launching"; + }; + lockScreenCommand = lib.mkOption { + type = lib.types.str; + description = "Command to use to lock the screen"; }; powerCommand = lib.mkOption { type = lib.types.str; description = "Command to use for power options menu"; }; + systemdSearch = lib.mkOption { + type = lib.types.str; + description = "Command to use for interacting with systemd"; + }; + terminal = lib.mkOption { + type = lib.types.str; + description = "Package to use for graphical terminal"; + }; + toggleBarCommand = lib.mkOption { + type = lib.types.str; + description = "Command to hide and show the status bar."; + }; wallpaper = lib.mkOption { type = lib.types.path; description = "Wallpaper background image file"; diff --git a/modules/nixos/graphical/i3.nix b/modules/nixos/graphical/i3.nix index 9d6c533..5f45563 100644 --- a/modules/nixos/graphical/i3.nix +++ b/modules/nixos/graphical/i3.nix @@ -2,8 +2,6 @@ let - lockCmd = - "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; lockUpdate = "${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.wallpaper} --display 1 --span"; @@ -29,12 +27,6 @@ in { ws2 = "2:II"; ws3 = "3:III"; ws4 = "4:IV"; - ws5 = "5:V"; - ws6 = "6:VI"; - ws7 = "7:VII"; - ws8 = "8:VIII"; - ws9 = "9:IX"; - ws10 = "10:X"; in { modifier = modifier; assigns = { @@ -92,118 +84,6 @@ in { followMouse = false; }; keybindings = { - - # Adjust screen brightness - "Shift+F12" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 + 30"; - "Shift+F11" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 - 30"; - "XF86MonBrightnessUp" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 + 30"; - "XF86MonBrightnessDown" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 - 30"; - - # Media player controls - "XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; - "XF86AudioStop" = "exec ${pkgs.playerctl}/bin/playerctl stop"; - "XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl next"; - "XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl previous"; - - # Launchers - "${modifier}+Return" = - "exec --no-startup-id kitty; workspace ${ws2}; layout tabbed"; - "${modifier}+space" = - "exec --no-startup-id ${config.launcherCommand}"; - "${modifier}+Shift+s" = - "exec --no-startup-id ${config.systemdSearch}"; - "${modifier}+Shift+a" = - "exec --no-startup-id ${config.audioSwitchCommand}"; - "Mod1+Tab" = "exec --no-startup-id ${config.altTabCommand}"; - "${modifier}+Shift+period" = - "exec --no-startup-id ${config.powerCommand}"; - "${modifier}+Shift+m" = - "exec --no-startup-id ${config.brightnessCommand}"; - "${modifier}+c" = - "exec --no-startup-id ${config.calculatorCommand}"; - "${modifier}+Shift+c" = "reload"; - "${modifier}+Shift+r" = "restart"; - "${modifier}+Shift+q" = '' - exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'"''; - "${modifier}+Shift+x" = "exec ${lockCmd}"; - "${modifier}+Mod1+h" = - "exec --no-startup-id kitty sh -c '${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; - "${modifier}+Mod1+r" = - "exec --no-startup-id kitty sh -c 'doas nixos-rebuild switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; - - # Window options - "${modifier}+q" = "kill"; - "${modifier}+b" = "exec ${config.toggleBarCommand}"; - "${modifier}+f" = "fullscreen toggle"; - "${modifier}+h" = "focus left"; - "${modifier}+j" = "focus down"; - "${modifier}+k" = "focus up"; - "${modifier}+l" = "focus right"; - "${modifier}+Left" = "focus left"; - "${modifier}+Down" = "focus down"; - "${modifier}+Up" = "focus up"; - "${modifier}+Right" = "focus right"; - "${modifier}+Shift+h" = "move left"; - "${modifier}+Shift+j" = "move down"; - "${modifier}+Shift+k" = "move up"; - "${modifier}+Shift+l" = "move right"; - "${modifier}+Shift+Left" = "move left"; - "${modifier}+Shift+Down" = "move down"; - "${modifier}+Shift+Up" = "move up"; - "${modifier}+Shift+Right" = "move right"; - - # Tiling - "${modifier}+i" = "split h"; - "${modifier}+v" = "split v"; - "${modifier}+s" = "layout stacking"; - "${modifier}+t" = "layout tabbed"; - "${modifier}+e" = "layout toggle split"; - "${modifier}+Shift+space" = "floating toggle"; - "${modifier}+Control+space" = "focus mode_toggle"; - "${modifier}+a" = "focus parent"; - - # Workspaces - "${modifier}+1" = "workspace ${ws1}"; - "${modifier}+2" = "workspace ${ws2}"; - "${modifier}+3" = "workspace ${ws3}"; - "${modifier}+4" = "workspace ${ws4}"; - "${modifier}+5" = "workspace ${ws5}"; - "${modifier}+6" = "workspace ${ws6}"; - "${modifier}+7" = "workspace ${ws7}"; - "${modifier}+8" = "workspace ${ws8}"; - "${modifier}+9" = "workspace ${ws9}"; - "${modifier}+0" = "workspace ${ws10}"; - - # Move windows - "${modifier}+Shift+1" = - "move container to workspace ${ws1}; workspace ${ws1}"; - "${modifier}+Shift+2" = - "move container to workspace ${ws2}; workspace ${ws2}"; - "${modifier}+Shift+3" = - "move container to workspace ${ws3}; workspace ${ws3}"; - "${modifier}+Shift+4" = - "move container to workspace ${ws4}; workspace ${ws4}"; - "${modifier}+Shift+5" = - "move container to workspace ${ws5}; workspace ${ws5}"; - "${modifier}+Shift+6" = - "move container to workspace ${ws6}; workspace ${ws6}"; - "${modifier}+Shift+7" = - "move container to workspace ${ws7}; workspace ${ws7}"; - "${modifier}+Shift+8" = - "move container to workspace ${ws8}; workspace ${ws8}"; - "${modifier}+Shift+9" = - "move container to workspace ${ws9}; workspace ${ws9}"; - "${modifier}+Shift+0" = - "move container to workspace ${ws10}; workspace ${ws10}"; - - # Move screens - "${modifier}+Control+l" = "move workspace to output right"; - "${modifier}+Control+h" = "move workspace to output left"; - # Resizing "${modifier}+r" = ''mode "resize"''; "${modifier}+Control+Shift+h" = @@ -232,6 +112,7 @@ in { notification = false; } ]; + terminal = config.terminal; window = { border = 0; hideEdgeBorders = "smart"; @@ -239,22 +120,13 @@ in { }; workspaceAutoBackAndForth = false; workspaceOutputAssign = [ ]; - # gaps = { - # bottom = 8; - # top = 8; - # left = 8; - # right = 8; - # horizontal = 15; - # vertical = 15; - # inner = 15; - # outer = 0; - # smartBorders = "off"; - # smartGaps = false; - # }; }; extraConfig = ""; }; + lockScreenCommand = + "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; + programs.fish.functions = { update-lock-screen = lib.mkIf config.services.xserver.enable { description = "Update lockscreen with wallpaper"; @@ -278,14 +150,14 @@ in { # Ref: https://github.com/betterlockscreen/betterlockscreen/blob/next/system/betterlockscreen%40.service systemd.services.lock = { enable = config.services.xserver.enable; - description = "Lock the screen on resume from suspend"; + description = "Lock the screen before suspend"; before = [ "sleep.target" "suspend.target" ]; serviceConfig = { User = config.user; Type = "simple"; Environment = "DISPLAY=:0"; TimeoutSec = "infinity"; - ExecStart = lockCmd; + ExecStart = config.lockScreenCommand; ExecStartPost = "${pkgs.coreutils-full}/bin/sleep 1"; }; wantedBy = [ "sleep.target" "suspend.target" ]; diff --git a/modules/nixos/graphical/keybinds.nix b/modules/nixos/graphical/keybinds.nix new file mode 100644 index 0000000..76214b8 --- /dev/null +++ b/modules/nixos/graphical/keybinds.nix @@ -0,0 +1,100 @@ +{ config, pkgs, lib, ... }: + +let + + 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 { + + home-manager.users.${config.user}.programs.sxhkd = { + enable = true; + keybindings = { + + # Adjust screen brightness (TODO: replace with pkgs.light?) + "shift + {F11,F12}" = '' + ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 {- 30,+ 30} && sleep 1; \\ + ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 {- 30,+ 30} + ''; + "XF86MonBrightness{Down,Up}" = keybindings."shift + {F11,F12}"; + + # Media controls + "XF86Audio{Play,Stop,Next,Prev}" = + "${pkgs.playerctl}/bin/playerctl {play-pause,stop,next,previous}"; + + # Window management + "super + q" = ''${pkgs.i3}/bin/i3-msg "kill"''; + "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 + "super + Return" = config.terminal; + "super + space" = config.launcherCommand; + "super + shift + s" = config.systemdSearch; + "super + shift + a" = config.audioSwitchCommand; + "alt + Tab" = config.altTabCommand; + "super + shift + period" = config.powerCommand; + "super + shift + m" = config.brightnessCommand; + "super + c" = config.calculatorCommand; + "super + shift + {c,r}" = ''${pkgs.i3}/bin/i3-msg "{reload,restart}"''; + "super + shift + x" = config.lockScreenCommand; + "super + alt + h" = + "${config.terminal} sh -c '${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; + "super + alt + r" = + "${config.terminal} sh -c 'doas nixos-rebuild switch --flake ${config.dotfilesPath}#${config.networking.hostName} || read'"; + + } // workspaceBindings; + + }; +} diff --git a/modules/nixos/graphical/picom.nix b/modules/nixos/graphical/picom.nix index 102d4d5..e99165f 100644 --- a/modules/nixos/graphical/picom.nix +++ b/modules/nixos/graphical/picom.nix @@ -1,6 +1,6 @@ { config, pkgs, lib, ... }: { - config = lib.mkIf (pkgs.stdenv.isLinux && config.services.xserver.enable) { + config = lib.mkIf config.services.xserver.enable { home-manager.users.${config.user} = { services.picom = { diff --git a/modules/nixos/graphical/polybar.nix b/modules/nixos/graphical/polybar.nix index 385d938..79ddaac 100644 --- a/modules/nixos/graphical/polybar.nix +++ b/modules/nixos/graphical/polybar.nix @@ -1,6 +1,6 @@ { config, pkgs, lib, ... }: { - config = lib.mkIf (pkgs.stdenv.isLinux && config.services.xserver.enable) { + config = lib.mkIf config.services.xserver.enable { toggleBarCommand = "polybar-msg cmd toggle"; diff --git a/modules/nixos/graphical/rofi.nix b/modules/nixos/graphical/rofi.nix index 87911c7..74b581d 100644 --- a/modules/nixos/graphical/rofi.nix +++ b/modules/nixos/graphical/rofi.nix @@ -8,11 +8,10 @@ in { imports = [ ./rofi/power.nix ./rofi/brightness.nix ]; - config = lib.mkIf (pkgs.stdenv.isLinux && config.services.xserver.enable) { + config = lib.mkIf config.services.xserver.enable { # Set the Rofi-Systemd terminal for viewing logs - environment.sessionVariables.ROFI_SYSTEMD_TERM = - lib.mkIf config.kitty.enable "${pkgs.kitty}/bin/kitty"; + environment.sessionVariables.ROFI_SYSTEMD_TERM = config.terminal; home-manager.users.${config.user} = { @@ -24,6 +23,13 @@ in { programs.rofi = { enable = true; cycle = true; + extraConfig = { + show-icons = true; + kb-cancel = "Escape,Super+space"; + modi = "window,run,ssh,emoji,calc,systemd"; + sort = true; + # levenshtein-sort = true; + }; location = "center"; pass = { }; plugins = [ pkgs.rofi-calc pkgs.rofi-emoji pkgs.rofi-systemd ]; @@ -143,15 +149,9 @@ in { }; }; + terminal = config.terminal; xoffset = 0; yoffset = -20; - extraConfig = { - show-icons = true; - kb-cancel = "Escape,Super+space"; - modi = "window,run,ssh,emoji,calc,systemd"; - sort = true; - # levenshtein-sort = true; - }; }; home.file.".local/share/rofi/themes" = { diff --git a/modules/nixos/graphical/rofi/brightness.nix b/modules/nixos/graphical/rofi/brightness.nix old mode 100755 new mode 100644 diff --git a/modules/nixos/graphical/rofi/power.nix b/modules/nixos/graphical/rofi/power.nix old mode 100755 new mode 100644 diff --git a/modules/nixos/graphical/sway.nix b/modules/nixos/graphical/sway.nix index 46463c2..64629f2 100644 --- a/modules/nixos/graphical/sway.nix +++ b/modules/nixos/graphical/sway.nix @@ -1,16 +1,21 @@ -{ config, pkgs, lib, ... }: { +{ config, lib, ... }: { config = lib.mkIf config.gui.enable { - programs.sway.enable = true; + programs.sway = { + enable = true; + package = null; # Use home-manager Sway instead + }; }; home-manager.users.${config.user} = { - wayland.windowManager.sway.enable = true; - wayland.windowManager.sway.config = - config.home-manager.users.${config.user}.xsession.windowManager.i3.config; + wayland.windowManager.sway = { + enable = true; + config = + config.home-manager.users.${config.user}.xsession.windowManager.i3.config; + }; };