home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

sway.nix (10238B)


      1 { config, nixosConfig, lib, pkgs, ... }:
      2 
      3 let
      4   emacs-in-folder = pkgs.writeScript "emacs-in-folder" ''
      5     #!/usr/bin/env bash
      6     fd . -d 3 --type d ~/src | ${pkgs.wofi}/bin/wofi -dmenu | xargs -I {} zsh -i -c "cd {}; emacs ."
      7   '';
      8   fontConf = {
      9     names = [ "JetBrains Mono" ];
     10     size = 12.0;
     11   };
     12 in
     13 {
     14   wayland.windowManager.sway = {
     15     enable = true;
     16     wrapperFeatures.gtk = true;
     17     systemd.enable = true;
     18     extraSessionCommands = ''
     19       export SDL_VIDEODRIVER=wayland
     20       export QT_QPA_PLATFORM=wayland
     21       export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
     22       export _JAVA_AWT_WM_NONREPARTENTING=1
     23       export MOZ_ENABLE_WAYLAND=1
     24     '';
     25     checkConfig = false;
     26     config = {
     27       gaps = {
     28         inner = 2;
     29         outer = 2;
     30       };
     31       colors = {
     32 	  focused = {
     33 	    border = "#BD93F9";
     34 	    background = "#282A36";
     35 	    text = "#ffffff";
     36 	    indicator = "#8BE9FD";
     37 	    childBorder = "#BD93F9";
     38 	  };
     39 	  focusedInactive = {
     40 	    border = "#BD93F9";
     41 	    background = "#282A36";
     42 	    text = "#F8F8F2";
     43 	    indicator = "#44475A";
     44 	    childBorder = "#44475A";
     45 	  };
     46 	  unfocused = {
     47 	    border = "#44475A";
     48 	    background = "#282A36";
     49 	    text = "#BFBFBF";
     50 	    indicator = "#282A36";
     51 	    childBorder = "#282A36";
     52 	  };
     53       };
     54       modifier = "Mod4";
     55       terminal = "${pkgs.kitty}/bin/kitty";
     56       menu = "${pkgs.wofi}/bin/wofi -G --show drun -modi 'drun,run,window,ssh'";
     57       bindkeysToCode = true;
     58       input = {
     59         "type:keyboard" = {
     60           xkb_layout = "fr";
     61           xkb_variant = "bepo";
     62           xkb_options = "grp:menu_toggle,grp_led:caps,compose:caps";
     63         };
     64       };
     65       output = {
     66         "*" = {
     67           bg = "~/desktop/pictures/lockscreen fill";
     68         };
     69       };
     70       fonts = fontConf;
     71       bars = [];
     72       keybindings =
     73         let
     74           mod = config.wayland.windowManager.sway.config.modifier;
     75           inherit (config.wayland.windowManager.sway.config) left down up right menu terminal;
     76         in
     77         {
     78           "${mod}+Return" = "exec ${terminal}";
     79 
     80           "${mod}+Shift+Return" = "exec emacsclient -c";
     81           "${mod}+Control+Return" = "exec emacs";
     82           "${mod}+Control+Shift+Return" = "exec ${emacs-in-folder}";
     83 
     84           "${mod}+Left" = "focus left";
     85           "${mod}+Down" = "focus down";
     86           "${mod}+Up" = "focus up";
     87           "${mod}+Right" = "focus right";
     88 
     89           "${mod}+Shift+Left" = "move left";
     90           "${mod}+Shift+Down" = "move down";
     91           "${mod}+Shift+Up" = "move up";
     92           "${mod}+Shift+Right" = "move right";
     93 
     94           "${mod}+Control+Left" = "workspace prev_on_output";
     95           "${mod}+Control+Down" = "workspace prev";
     96           "${mod}+Control+Up" = "workspace next";
     97           "${mod}+Control+Right" = "workspace next_on_output";
     98 
     99           "${mod}+Shift+Control+Left" = "move workspace to output left";
    100           "${mod}+Shift+Control+Down" = "move workspace to output down";
    101           "${mod}+Shift+Control+Up" = "move workspace to output up";
    102           "${mod}+Shift+Control+Right" = "move workspace to output right";
    103 
    104           "${mod}+Shift+space" = "floating toggle";
    105           "${mod}+space" = "focus mode_toggle";
    106 
    107           "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 10%+";
    108           "XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 10%-";
    109           "Shift+XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 1%+";
    110           "Shift+XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 1%-";
    111         };
    112       window.commands = [
    113         {
    114           command = "inhibit_idle fullscreen";
    115           criteria.app_id = "firefox";
    116         }
    117         {
    118           command = "inhibit_idle fullscreen";
    119           criteria.app_id = "mpv";
    120         }
    121         {
    122           # spotify doesn't set its WM_CLASS until it has mapped, so the assign is not reliable
    123           command = "move to workspace 10";
    124           criteria.class = "Spotify";
    125         }
    126         {
    127           command = "move to scratchpad, scratchpad show";
    128           criteria = {
    129             app_id = "metask";
    130           };
    131         }
    132         {
    133           command = "move to scratchpad, scratchpad show";
    134           criteria = {
    135             app_id = "emacs";
    136             title = "^_emacs scratchpad_$";
    137           };
    138         }
    139         {
    140           criteria = { title = "Save File"; };
    141           command = "floating enable, resize set width 600px height 800px";
    142         }
    143         {
    144           criteria = { class = "pavucontrol"; };
    145           command = "floating enable";
    146         }
    147         {
    148           criteria = { title = "(Sharing Indicator)"; };
    149           command = "inhibit_idle visible, floating enable";
    150         }
    151         {
    152           # browser zoom|meet|bluejeans
    153           criteria = { title = "(Blue Jeans)|(Meet)|(Zoom Meeting)"; };
    154           command = "inhibit_idle visible";
    155         }
    156         # for_window [app_id="^chrome-.*"] shortcuts_inhibitor disable
    157         {
    158           criteria = { app_id = "^chrome-.*"; };
    159           command = "shortcuts_inhibitor disable";
    160         }
    161       ];
    162       startup = [
    163         { command = "dbus-update-activation-environment --systemd WAYLAND_DISPLAY DISPLAY DBUS_SESSION_BUS_ADDRESS SWAYSOCK XDG_SESSION_TYPE XDG_SESSION_DESKTOP XDG _CURRENT_DESKTOP"; } #workaround
    164         # { command = "${pkgs.networkmanagerapplet}/bin/nm-applet --indicator"; }
    165         { command = "systemctl --user restart kanshi"; always = true; }
    166 	{ command = "${pkgs.pa-notify}/bin/pa-notify"; always = true;}
    167       ];
    168     };
    169     extraConfig =
    170       let
    171         mod = config.wayland.windowManager.sway.config.modifier;
    172         inherit (config.wayland.windowManager.sway.config) left down up right menu terminal;
    173       in
    174       ''
    175         bindcode ${mod}+33 exec "${menu}"
    176         bindcode ${mod}+Control+33 exec "${pkgs.wofi-emoji}/bin/wofi-emoji -G"
    177         bindcode ${mod}+Shift+24 kill
    178         bindcode ${mod}+38 focus parent
    179         bindcode ${mod}+39 layout stacking
    180         bindcode ${mod}+25 layout tabbed
    181         bindcode ${mod}+26 layout toggle split
    182         bindcode ${mod}+Shift+54 reload
    183         bindcode ${mod}+Shift+26 exec "swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'"
    184         bindcode ${mod}+32 mode resize
    185         bindcode ${mod}+Shift+32 exec "${pkgs.swaylock}/bin/swaylock -i $HOME/desktop/pictures/lockscreen"
    186 
    187 	bindcode ${mod}+24 exec notify-send --icon=battery --category=info --urgency=critical "$(acpi)"
    188         # bindcode ${mod}+58 exec
    189 	bindcode ${mod}+28 exec notify-send --icon=clock --category=info --urgency=critical "$(date +"%I:%M")"
    190 	bindcode ${mod}+Shift+28 exec notify-send --icon=clock --category=info --urgency=critical "$(date)" 
    191 
    192         # switch to workspace
    193         bindcode ${mod}+10 workspace number 1
    194         bindcode ${mod}+11 workspace number 2
    195         bindcode ${mod}+12 workspace number 3
    196         bindcode ${mod}+13 workspace number 4
    197         bindcode ${mod}+14 workspace number 5
    198         bindcode ${mod}+15 workspace number 6
    199         bindcode ${mod}+16 workspace number 7
    200         bindcode ${mod}+17 workspace number 8
    201         bindcode ${mod}+18 workspace number 9
    202         bindcode ${mod}+19 workspace number 10
    203 
    204         # move focused container to workspace
    205         bindcode ${mod}+Shift+10 move container to workspace number 1
    206         bindcode ${mod}+Shift+11 move container to workspace number 2
    207         bindcode ${mod}+Shift+12 move container to workspace number 3
    208         bindcode ${mod}+Shift+13 move container to workspace number 4
    209         bindcode ${mod}+Shift+14 move container to workspace number 5
    210         bindcode ${mod}+Shift+15 move container to workspace number 6
    211         bindcode ${mod}+Shift+16 move container to workspace number 7
    212         bindcode ${mod}+Shift+17 move container to workspace number 8
    213         bindcode ${mod}+Shift+18 move container to workspace number 9
    214         bindcode ${mod}+Shift+19 move container to workspace number 10
    215 
    216         bindcode ${mod}+Control+39 split h
    217         bindcode ${mod}+41 fullscreen toggle
    218 
    219         bindsym XF86AudioRaiseVolume exec ${pkgs.pamixer}/bin/pamixer -ui 5 && ${pkgs.pamixer}/bin/pamixer --get-volume > $SWAYSOCK.wob
    220         bindsym XF86AudioLowerVolume exec ${pkgs.pamixer}/bin/pamixer -ud 5 && ${pkgs.pamixer}/bin/pamixer --get-volume > $SWAYSOCK.wob
    221         bindsym XF86AudioMute exec ${pkgs.pamixer}/bin/pamixer --toggle-mute && ( ${pkgs.pamixer}/bin/pamixer --get-mute && echo 0 > $SWAYSOCK.wob ) || ${pkgs.pamixer}/bin/pamixer --get-volume > $SWAYSOCK.wob
    222 
    223         bindsym XF86AudioPlay exec "playerctl play-pause"
    224         bindsym XF86Messenger exec "playerctl play-pause"
    225         bindsym XF86AudioNext exec "playerctl next"
    226         bindsym XF86Go exec "playerctl next"
    227         bindsym XF86AudioPrev exec "playerctl previous"
    228         bindsym Cancel exec "playerctl previous"
    229 
    230         bindcode ${mod}+49 exec swaymsg [app_id="metask"] scratchpad show || exec ${pkgs.kitty}/bin/kitty --title metask --class metask
    231         bindsym --whole-window button8 exec sswaymsg [app_id="metask"] scratchpad show || exec ${pkgs.kitty}/bin/kitty --title metask --class metask
    232         bindcode ${mod}+Shift+49 exec swaymsg '[app_id="emacs" title="^_emacs scratchpad_$"]' scratchpad show || exec ${config.programs.emacs.package}/bin/emacsclient -c -F "((name . \"_emacs scratchpad_\"))"
    233         bindsym --whole-window button9 exec swaymsg '[app_id="emacs" title="^_emacs scratchpad_$"]' scratchpad show || exec ${config.programs.emacs.package}/bin/emacsclient -c -F "((name . \"_emacs scratchpad_\"))"
    234 
    235         # Mouse
    236         # Disabled as it doesn't play well with thinkpad's trackpoint :D
    237         # bindsym --whole-window button6 workspace next_on_output
    238         # bindsym --whole-window button7 workspace prev_on_output
    239 
    240         bindsym ${mod}+F10 exec ${pkgs.my.scripts}/bin/shot %d
    241         bindsym ${mod}+Shift+F10 exec ${pkgs.my.scripts}/bin/shotf %d
    242 
    243         bindsym ${mod}+F9 exec ${pkgs.mako}/bin/makoctl mode -s do-not-disturb
    244         bindsym ${mod}+Shift+F9 exec ${pkgs.mako}/bin/makoctl mode -s default
    245       '';
    246   };
    247   home.packages = with pkgs; [
    248     swaybg
    249   ];
    250 
    251 }
    252