From 6ea3da93db7514c1af9f4f080ab458a7525d50c1 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:36:07 -0400 Subject: [PATCH] partial success of i3 and sxhkd --- modules/common/shell/starship.nix | 2 +- modules/nixos/graphical/default.nix | 1 + modules/nixos/graphical/i3.nix | 49 +++++++----------- modules/nixos/graphical/keybinds.nix | 77 +++++++++++++++------------- 4 files changed, 62 insertions(+), 67 deletions(-) diff --git a/modules/common/shell/starship.nix b/modules/common/shell/starship.nix index 0b34535..26ef550 100644 --- a/modules/common/shell/starship.nix +++ b/modules/common/shell/starship.nix @@ -13,7 +13,7 @@ "$cmd_duration" "$character" ]; - right_format = "$nix_shell"; + # right_format = "$nix_shell"; character = { success_symbol = "[❯](bold green)"; error_symbol = "[❯](bold red)"; diff --git a/modules/nixos/graphical/default.nix b/modules/nixos/graphical/default.nix index 3a3ad05..ab22529 100644 --- a/modules/nixos/graphical/default.nix +++ b/modules/nixos/graphical/default.nix @@ -5,6 +5,7 @@ ./fonts.nix ./gtk.nix ./i3.nix + ./keybinds.nix ./picom.nix ./polybar.nix ./rofi.nix diff --git a/modules/nixos/graphical/i3.nix b/modules/nixos/graphical/i3.nix index 95d92d5..c232052 100644 --- a/modules/nixos/graphical/i3.nix +++ b/modules/nixos/graphical/i3.nix @@ -15,7 +15,7 @@ let "7" = "7:VII"; "8" = "8:VIII"; "9" = "9:IX"; - "0" = "10:X"; + "10" = "10:X"; }; in { @@ -124,30 +124,18 @@ in { extraConfig = ""; }; - programs.sxhkd.keybindings = let + services.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 + {_,shift +}{h,j,k,l}" = + ''${i3-msg} "{focus,move} {left,down,up,right}"''; + "super + {_,shift +}{Left,Down,Up,Right}" = + ''${i3-msg} "{focus,move} {left,down,up,right}"''; "super + q" = ''${i3-msg} "kill"''; "super + f" = ''${i3-msg} "fullscreen toggle"''; @@ -166,21 +154,17 @@ in { # Restart and reload "super + shift + {c,r}" = ''${i3-msg} "{reload,restart}"''; - } + "super + {1-9,0}" = ''${i3-msg} "workspace {1-9,10}"''; + "super + shift + {1-9,0}" = '' + WORKSPACE={1-9,10}; + ${i3-msg} "move container to workspace $WORKSPACE; workspace $WORKSPACE"''; - # Bind super + workspace -> switch to workspace - // (bindAll (num: "super + ${num}") - (num: ''${i3-msg} "workspace ${lookup num}"'')) + "super + r : {h,j,k,l}" = + ''${i3-msg} "resize {shrink,grow} width 10px or 10 ppt"''; + "super + r : {j,k}" = + ''${i3-msg} "resize {shrink,grow} height 10px or 10 ppt"''; - # 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 = - "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; + }; programs.fish.functions = { update-lock-screen = lib.mkIf config.services.xserver.enable { @@ -202,6 +186,9 @@ in { }; + lockScreenCommand = + "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; + # Ref: https://github.com/betterlockscreen/betterlockscreen/blob/next/system/betterlockscreen%40.service systemd.services.lock = { enable = config.services.xserver.enable; diff --git a/modules/nixos/graphical/keybinds.nix b/modules/nixos/graphical/keybinds.nix index 969e362..f7c6d24 100644 --- a/modules/nixos/graphical/keybinds.nix +++ b/modules/nixos/graphical/keybinds.nix @@ -1,45 +1,52 @@ -{ config, pkgs, ... }: +{ config, pkgs, ... }: { -let + home-manager.users.${config.user} = { + services.sxhkd = { + enable = true; + keybindings = { - binds = config.home-manager.users.${config.user}.programs.sxhkd.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}" = '' + ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 {- 30,+ 30} && sleep 1; \\ + ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 {- 30,+ 30} + ''; -in { + # Media controls + "XF86Audio{Play,Stop,Next,Prev}" = + "${pkgs.playerctl}/bin/playerctl {play-pause,stop,next,previous}"; - home-manager.users.${config.user}.programs.sxhkd = { - enable = true; - keybindings = { + # Toggle bar + "super + b" = config.toggleBarCommand; - # 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}" = binds."shift + {F11,F12}"; - - # Media controls - "XF86Audio{Play,Stop,Next,Prev}" = - "${pkgs.playerctl}/bin/playerctl {play-pause,stop,next,previous}"; - - # Toggle bar - "super + b" = config.toggleBarCommand; - - # 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 + 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'"; + # 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 + 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'"; + }; }; + xsession.windowManager.i3.config.startup = [{ + + command = "pkill sxhkd; sxhkd"; + always = true; + notification = false; + }]; + }; + }