refactor: sway: split config template into own file

This commit is contained in:
Colin 2023-09-04 23:49:15 +00:00
parent 5c3bb2293c
commit 7f5811db9a
3 changed files with 210 additions and 191 deletions

View File

@ -132,7 +132,7 @@ in
];
sane.user.fs = lib.mkIf cfg.installConfigs {
".config/sway/config".symlink.text =
".config/sway/config".symlink.target =
import ./sway-config.nix { inherit pkgs; };
".config/waybar/config".symlink.target =

View File

@ -0,0 +1,174 @@
# xwayland enable|disable|force
# - enable: lazily launch xwayland on first client connection
# - disable: never launch xwayland
# - force: launch xwayland immediately on boot
# XWayland exposes a X11 server that translates the protocol to a wayland backend, allowing legacy x11-only GUI apps.
# XWayland uses about 35MB RSS even when idle
xwayland @xwayland@
set $mod @mod@
set $term @terminal_cmd@
set $menu @launcher_cmd@
set $emoji_picker @emoji_cmd@
set $locker @lock_cmd@
set $snippets_picker @snip_cmd@
set $screenshot @screenshot_cmd@
set $brightness_up @brightness_up_cmd@
set $brightness_down @brightness_down_cmd@
set $volume_up @vol_up_cmd@
set $volume_down @vol_down_cmd@
set $mute @mute_cmd@
### default font
font pango:monospace 8
### pixel boundary between windows
default_border pixel 3
default_floating_border pixel 2
hide_edge_borders smart
#### focus_wrapping: behavior when trying to focus past the edge of a container
#### no => preserve last focus. helpful mostly when `focus_follows_mouse yes`
focus_wrapping no
focus_follows_mouse yes
#### workspace_layout default => workspaces use splits by default (as opposed to e.g. tabbed)
workspace_layout default
### default colors (#border #background #text #indicator #childBorder)
client.focused #4c7899 #285577 #ffffff #2e9ef4 #285577
client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a
client.unfocused #333333 #222222 #888888 #292d2e #222222
client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff
### key bindings
floating_modifier $mod
## media keys
bindsym XF86AudioRaiseVolume exec $volume_up
bindsym XF86AudioLowerVolume exec $volume_down
bindsym $mod+Page_Up exec $volume_up
bindsym $mod+Page_Down exec $volume_down
bindsym XF86AudioMute exec $mute
bindsym XF86MonBrightnessUp exec $brightness_up
bindsym XF86MonBrightnessDown exec $brightness_down
## special functions
bindsym $mod+Print exec $screenshot
bindsym $mod+l exec $locker
bindsym $mod+s exec $snippets_picker
bindsym $mod+slash exec $emoji_picker
bindsym $mod+d exec $menu
bindsym $mod+Return exec $term
bindsym $mod+Shift+q kill
bindsym $mod+Shift+e 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'
bindsym $mod+Shift+c reload
## layout
bindsym $mod+b splith
bindsym $mod+v splitv
bindsym $mod+f fullscreen toggle
bindsym $mod+a focus parent
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
bindsym $mod+Shift+space floating toggle
bindsym $mod+space focus mode_toggle
bindsym $mod+r mode resize
## movement
bindsym $mod+Up focus up
bindsym $mod+Down focus down
bindsym $mod+Left focus left
bindsym $mod+Right focus right
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Right move right
## workspaces
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
## "scratchpad" = ??
bindsym $mod+Shift+minus move scratchpad
bindsym $mod+minus scratchpad show
### defaults
mode "resize" {
bindsym Down resize grow height 10 px
bindsym Escape mode default
bindsym Left resize shrink width 10 px
bindsym Return mode default
bindsym Right resize grow width 10 px
bindsym Up resize shrink height 10 px
bindsym h resize shrink width 10 px
bindsym j resize grow height 10 px
bindsym k resize shrink height 10 px
bindsym l resize grow width 10 px
}
### lightly modified bars
bar {
mode dock
hidden_state hide
position top
status_command @status@
swaybar_command @waybar@
workspace_buttons yes
strip_workspace_numbers no
tray_output primary
colors {
background #000000
statusline #ffffff
separator #666666
# #border #background #text
focused_workspace #4c7899 #285577 #ffffff
active_workspace #333333 #5f676a #ffffff
inactive_workspace #333333 #222222 #888888
urgent_workspace #2f343a #900000 #ffffff
binding_mode #2f343a #900000 #ffffff
}
}
### displays
## DESKTOP
output "Samsung Electric Company S22C300 0x00007F35" {
pos 0,0
res 1920x1080
}
output "Goldstar Company Ltd LG ULTRAWIDE 0x00004E94" {
pos 1920,0
res 3440x1440
}
## LAPTOP
# sh/en TV
output "Pioneer Electronic Corporation VSX-524 0x00000101" {
pos 0,0
res 1920x1080
}
# internal display
output "Unknown 0x0637 0x00000000" {
pos 1920,0
res 1920x1080
}
# XXX: needed for xdg-desktop-portal-* to work.
# this is how we expose these env vars to user dbus services:
# - DISPLAY
# - WAYLAND_DISPLAY
# - SWAYSOCK
# - XDG_CURRENT_DESKTOP
# for more, see: <repo:nixos/nixpkgs:nixos/modules/programs/wayland/sway.nix>
include /etc/sway/config.d/*

View File

@ -3,200 +3,45 @@ let
fuzzel = "${pkgs.fuzzel}/bin/fuzzel";
sed = "${pkgs.gnused}/bin/sed";
wtype = "${pkgs.wtype}/bin/wtype";
launcher-cmd = fuzzel;
terminal-cmd = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec";
lock-cmd = "${pkgs.swaylock}/bin/swaylock --indicator-idle-visible --indicator-radius 100 --indicator-thickness 30";
vol-up-cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume +5";
vol-down-cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume -5";
mute-cmd = "${pkgs.pulsemixer}/bin/pulsemixer --toggle-mute";
brightness-up-cmd = "${pkgs.brightnessctl}/bin/brightnessctl set +2%";
brightness-down-cmd = "${pkgs.brightnessctl}/bin/brightnessctl set 2%-";
screenshot-cmd = "${pkgs.sway-contrib.grimshot}/bin/grimshot copy area";
launcher_cmd = fuzzel;
terminal_cmd = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec";
lock_cmd = "${pkgs.swaylock}/bin/swaylock --indicator-idle-visible --indicator-radius 100 --indicator-thickness 30";
vol_up_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume +5";
vol_down_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume -5";
mute_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --toggle-mute";
brightness_up_cmd = "${pkgs.brightnessctl}/bin/brightnessctl set +2%";
brightness_down_cmd = "${pkgs.brightnessctl}/bin/brightnessctl set 2%-";
screenshot_cmd = "${pkgs.sway-contrib.grimshot}/bin/grimshot copy area";
# "bookmarking"/snippets inspired by Luke Smith:
# - <https://www.youtube.com/watch?v=d_11QaTlf1I>
snip-file = ../snippets.txt;
list-snips = "cat ${snip-file} ~/.config/sane-sway/snippets.txt";
strip-comments = "${sed} 's/ #.*$//'";
snip-cmd = "${wtype} $(${list-snips} | ${fuzzel} -d -i -w 60 | ${strip-comments})";
# TODO: snip_cmd is complex enough it should be its own package and not embedded -- pipes and all -- into the sway config
snip_file = ../snippets.txt;
list_snips = "cat ${snip_file} ~/.config/sane-sway/snippets.txt";
strip_comments = "${sed} 's/ #.*$//'";
snip_cmd = "${wtype} $(${list_snips} | ${fuzzel} -d -i -w 60 | ${strip_comments})";
# TODO: splatmoji release > 1.2.0 should allow `-s none` to disable skin tones
emoji-cmd = "${pkgs.splatmoji}/bin/splatmoji -s medium-light type";
emoji_cmd = "${pkgs.splatmoji}/bin/splatmoji -s medium-light type";
# mod = "Mod1"; # Alt
mod = "Mod4"; # Super (Logo key)
xwayland = "disable";
in ''
# xwayland enable|disable|force
# - enable: lazily launch xwayland on first client connection
# - disable: never launch xwayland
# - force: launch xwayland immediately on boot
# XWayland exposes a X11 server that translates the protocol to a wayland backend, allowing legacy x11-only GUI apps.
# XWayland uses about 35MB RSS even when idle
xwayland ${xwayland}
set $mod ${mod}
set $term ${terminal-cmd}
set $menu ${launcher-cmd}
set $emoji_picker ${emoji-cmd}
set $locker ${lock-cmd}
set $snippets_picker ${snip-cmd}
set $screenshot ${screenshot-cmd}
set $brightness_up ${brightness-up-cmd}
set $brightness_down ${brightness-down-cmd}
set $volume_up ${vol-up-cmd}
set $volume_down ${vol-down-cmd}
set $mute ${mute-cmd}
### default font
font pango:monospace 8
### pixel boundary between windows
default_border pixel 3
default_floating_border pixel 2
hide_edge_borders smart
#### focus_wrapping: behavior when trying to focus past the edge of a container
#### no => preserve last focus. helpful mostly when `focus_follows_mouse yes`
focus_wrapping no
focus_follows_mouse yes
#### workspace_layout default => workspaces use splits by default (as opposed to e.g. tabbed)
workspace_layout default
### default colors (#border #background #text #indicator #childBorder)
client.focused #4c7899 #285577 #ffffff #2e9ef4 #285577
client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a
client.unfocused #333333 #222222 #888888 #292d2e #222222
client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff
### key bindings
floating_modifier $mod
## media keys
bindsym XF86AudioRaiseVolume exec $volume_up
bindsym XF86AudioLowerVolume exec $volume_down
bindsym $mod+Page_Up exec $volume_up
bindsym $mod+Page_Down exec $volume_down
bindsym XF86AudioMute exec $mute
bindsym XF86MonBrightnessUp exec $brightness_up
bindsym XF86MonBrightnessDown exec $brightness_down
## special functions
bindsym $mod+Print exec $screenshot
bindsym $mod+l exec $locker
bindsym $mod+s exec $snippets_picker
bindsym $mod+slash exec $emoji_picker
bindsym $mod+d exec $menu
bindsym $mod+Return exec $term
bindsym $mod+Shift+q kill
bindsym $mod+Shift+e 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'
bindsym $mod+Shift+c reload
## layout
bindsym $mod+b splith
bindsym $mod+v splitv
bindsym $mod+f fullscreen toggle
bindsym $mod+a focus parent
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
bindsym $mod+Shift+space floating toggle
bindsym $mod+space focus mode_toggle
bindsym $mod+r mode resize
## movement
bindsym $mod+Up focus up
bindsym $mod+Down focus down
bindsym $mod+Left focus left
bindsym $mod+Right focus right
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Right move right
## workspaces
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
## "scratchpad" = ??
bindsym $mod+Shift+minus move scratchpad
bindsym $mod+minus scratchpad show
### defaults
mode "resize" {
bindsym Down resize grow height 10 px
bindsym Escape mode default
bindsym Left resize shrink width 10 px
bindsym Return mode default
bindsym Right resize grow width 10 px
bindsym Up resize shrink height 10 px
bindsym h resize shrink width 10 px
bindsym j resize grow height 10 px
bindsym k resize shrink height 10 px
bindsym l resize grow width 10 px
}
### lightly modified bars
bar {
mode dock
hidden_state hide
position top
status_command ${pkgs.i3status}/bin/i3status
swaybar_command ${pkgs.waybar}/bin/waybar
workspace_buttons yes
strip_workspace_numbers no
tray_output primary
colors {
background #000000
statusline #ffffff
separator #666666
# #border #background #text
focused_workspace #4c7899 #285577 #ffffff
active_workspace #333333 #5f676a #ffffff
inactive_workspace #333333 #222222 #888888
urgent_workspace #2f343a #900000 #ffffff
binding_mode #2f343a #900000 #ffffff
}
}
### displays
## DESKTOP
output "Samsung Electric Company S22C300 0x00007F35" {
pos 0,0
res 1920x1080
}
output "Goldstar Company Ltd LG ULTRAWIDE 0x00004E94" {
pos 1920,0
res 3440x1440
}
## LAPTOP
# sh/en TV
output "Pioneer Electronic Corporation VSX-524 0x00000101" {
pos 0,0
res 1920x1080
}
# internal display
output "Unknown 0x0637 0x00000000" {
pos 1920,0
res 1920x1080
}
# XXX: needed for xdg-desktop-portal-* to work.
# this is how we expose these env vars to user dbus services:
# - DISPLAY
# - WAYLAND_DISPLAY
# - SWAYSOCK
# - XDG_CURRENT_DESKTOP
# for more, see: <repo:nixos/nixpkgs:nixos/modules/programs/wayland/sway.nix>
include /etc/sway/config.d/*
''
in pkgs.substituteAll {
src = ./sway-config;
inherit
brightness_down_cmd
brightness_up_cmd
emoji_cmd
launcher_cmd
lock_cmd
mod
mute_cmd
screenshot_cmd
snip_cmd
terminal_cmd
vol_down_cmd
vol_up_cmd
xwayland
;
status = "${pkgs.i3status}/bin/i3status";
waybar = "${pkgs.waybar}/bin/waybar";
}