···11+{ config, lib, pkgs, ... }: let
22+33+ term = "/run/current-system/sw/bin/alacritty";
44+55+in {
66+ imports = [
77+ ../lib/wayland.nix
88+ ];
99+ programs.sway = {
1010+ enable = true;
1111+ wrapperFeatures.gtk = true;
1212+ };
1313+1414+ environment.etc."sway/config".text = ''
1515+ # Default config for sway
1616+ #
1717+ # Copy this to ~/.config/sway/config and edit it to your liking.
1818+ #
1919+ # Read `man 5 sway` for a complete reference.
2020+2121+ ### Variables
2222+ #
2323+ # Logo key. Use Mod1 for Alt.
2424+ set $mod Mod4
2525+ # Home row direction keys, like vim
2626+ set $left h
2727+ set $down j
2828+ set $up k
2929+ set $right l
3030+ # Your preferred terminal emulator
3131+ set $term ${term}
3232+ # Your preferred application launcher
3333+ # Note: pass the final command to swaymsg so that the resulting window can be opened
3434+ # on the original workspace that the command was run on.
3535+ set $menu ${pkgs.dmenu}/bin/dmenu_path | fzfmenu | xargs swaymsg exec --
3636+3737+ ### Output configuration
3838+ #
3939+ # Default wallpaper (more resolutions are available in @datadir@/backgrounds/sway/)
4040+ # output * bg @datadir@/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
4141+ #
4242+ # Example configuration:
4343+ #
4444+ # output HDMI-A-1 resolution 1920x1080 position 1920,0
4545+ #
4646+ # You can get the names of your outputs by running: swaymsg -t get_outputs
4747+4848+ ### Idle configuration
4949+ #
5050+ # Example configuration:
5151+ #
5252+ # exec swayidle -w \
5353+ # timeout 300 'swaylock -f -c 000000' \
5454+ # timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
5555+ # before-sleep 'swaylock -f -c 000000'
5656+ #
5757+ # This will lock your screen after 300 seconds of inactivity, then turn off
5858+ # your displays after another 300 seconds, and turn your screens back on when
5959+ # resumed. It will also lock your screen before your computer goes to sleep.
6060+6161+ ### Input configuration
6262+ #
6363+ # Example configuration:
6464+ #
6565+ # input "2:14:SynPS/2_Synaptics_TouchPad" {
6666+ # dwt enabled
6767+ # tap enabled
6868+ # natural_scroll enabled
6969+ # middle_emulation enabled
7070+ # }
7171+ #
7272+ # You can get the names of your inputs by running: swaymsg -t get_inputs
7373+ # Read `man 5 sway-input` for more information about this section.
7474+7575+ ### Key bindings
7676+ #
7777+ # Basics:
7878+ #
7979+ # Start a terminal
8080+ bindsym $mod+Shift+Return exec $term
8181+8282+ # Kill focused window
8383+ bindsym $mod+Shift+c kill
8484+8585+ # Start your launcher
8686+ bindsym $mod+d exec $menu
8787+8888+ # Drag floating windows by holding down $mod and left mouse button.
8989+ # Resize them with right mouse button + $mod.
9090+ # Despite the name, also works for non-floating windows.
9191+ # Change normal to inverse to use left mouse button for resizing and right
9292+ # mouse button for dragging.
9393+ floating_modifier $mod normal
9494+9595+ # Reload the configuration file
9696+ bindsym $mod+Shift+r reload
9797+9898+ # Exit sway (logs you out of your Wayland session)
9999+ 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'
100100+ #
101101+ # Moving around:
102102+ #
103103+ # Move your focus around
104104+ bindsym $mod+Left focus left
105105+ bindsym $mod+Down focus down
106106+ bindsym $mod+Up focus up
107107+ bindsym $mod+Right focus right
108108+109109+ # Move the focused window with the same, but add Shift
110110+ bindsym $mod+Shift+Left move left
111111+ bindsym $mod+Shift+Down move down
112112+ bindsym $mod+Shift+Up move up
113113+ bindsym $mod+Shift+Right move right
114114+ # Layout stuff:
115115+ #
116116+ # You can "split" the current object of your focus with
117117+ # $mod+b or $mod+v, for horizontal and vertical splits
118118+ # respectively.
119119+ bindsym $mod+b splith
120120+ bindsym $mod+v splitv
121121+122122+ # Switch the current container between different layout styles
123123+ bindsym $mod+s layout stacking
124124+ bindsym $mod+w layout tabbed
125125+ bindsym $mod+e layout toggle split
126126+127127+ # Make the current focus fullscreen
128128+ bindsym $mod+f fullscreen
129129+130130+ # Toggle the current focus between tiling and floating mode
131131+ bindsym $mod+Shift+space floating toggle
132132+133133+ # Swap focus between the tiling area and the floating area
134134+ bindsym $mod+space focus mode_toggle
135135+136136+ # Move focus to the parent container
137137+ bindsym $mod+Shift+a focus parent
138138+ #
139139+ # Scratchpad:
140140+ #
141141+ # Sway has a "scratchpad", which is a bag of holding for windows.
142142+ # You can send windows there and get them back later.
143143+144144+ # Move the currently focused window to the scratchpad
145145+ bindsym $mod+Shift+minus move scratchpad
146146+147147+ # Show the next scratchpad window or hide the focused scratchpad window.
148148+ # If there are multiple scratchpad windows, this command cycles through them.
149149+ bindsym $mod+minus scratchpad show
150150+ #
151151+ # Resizing containers:
152152+ #
153153+ mode "resize" {
154154+ # left will shrink the containers width
155155+ # right will grow the containers width
156156+ # up will shrink the containers height
157157+ # down will grow the containers height
158158+ bindsym $left resize shrink width 10px
159159+ bindsym $down resize grow height 10px
160160+ bindsym $up resize shrink height 10px
161161+ bindsym $right resize grow width 10px
162162+163163+ # Ditto, with arrow keys
164164+ bindsym Left resize shrink width 10px
165165+ bindsym Down resize grow height 10px
166166+ bindsym Up resize shrink height 10px
167167+ bindsym Right resize grow width 10px
168168+169169+ # Return to default mode
170170+ bindsym Return mode "default"
171171+ bindsym Escape mode "default"
172172+ }
173173+ bindsym $mod+r mode "resize"
174174+175175+ #
176176+ # Status Bar:
177177+ #
178178+ # Read `man 5 sway-bar` for more information about this section.
179179+ bar {
180180+ position top
181181+182182+ # When the status_command prints a new line to stdout, swaybar updates.
183183+ # The default just shows the current date and time.
184184+ status_command while date +'%Y-%m-%d %H:%M:%S'; do sleep 1; done
185185+186186+ colors {
187187+ statusline #ffffff
188188+ background #323232
189189+ inactive_workspace #32323200 #32323200 #5c5c5c
190190+ }
191191+ }
192192+193193+ default_border pixel 1
194194+ default_floating_border none
195195+ smart_borders on
196196+197197+ bindsym $mod+q exec ${pkgs.writers.writeDash "goto_workspace" ''
198198+ set -efux
199199+ unset TERM # we want fzfmenu to start a new terminal
200200+ CURRENT_OUTPUT=$(swaymsg -r -t get_outputs | jq '.[] | select(.focused == true).name')
201201+ FZFMENU_FZF_DEFAULT_OPTS="--select-1"
202202+ WS=$(swaymsg -r -t get_workspaces |
203203+ jq -r '.[].name' |
204204+ fzfmenu -p 'Workspace name: '
205205+ )
206206+ if [ -n "$WS" ]; then
207207+ swaymsg workspace "$WS"
208208+ swaymsg move workspace to output "$CURRENT_OUTPUT"
209209+ fi
210210+ ''}
211211+212212+ bindsym $mod+Shift+q exec ${pkgs.writers.writeDash "moveto_workspace" ''
213213+ set -efux
214214+ unset TERM # we want fzfmenu to start a new terminal
215215+ FZFMENU_FZF_DEFAULT_OPTS="--select-1"
216216+ WS=$(swaymsg -r -t get_workspaces |
217217+ jq -r '.[].name' |
218218+ fzfmenu -p 'Workspace name: '
219219+ )
220220+ if [ -n "$WS" ]; then
221221+ swaymsg move container to workspace "$WS"
222222+ fi
223223+ ''}
224224+225225+ bindsym $mod+x exec ${./starter} floating enable -- ${pkgs.alacritty}/bin/alacritty --config-file /var/theme/config/alacritty.yaml
226226+ bindsym $mod+y exec /run/current-system/sw/bin/switch-theme toggle
227227+228228+ for_window [title="fzfmenu"] floating enable
229229+ bindsym $mod+Tab focus next
230230+ bindsym $mod+Escape workspace back_and_forth
231231+232232+ bindsym $mod+p exec ${pkgs.writers.writeDash "passmenu" ''
233233+ set -efux
234234+ unset TERM # we want fzfmenu to start a new terminal
235235+ (cd $HOME/.password-store; find -type f -name '*.gpg') |
236236+ sed -e 's/\.gpg$//' |
237237+ fzfmenu -p 'Password: ' |
238238+ xargs -I{} pass show {} |
239239+ tr -d '\n' |
240240+ ${pkgs.wtype}/bin/wtype -s 1 -
241241+ ''}
242242+ bindsym $mod+Shift+p exec ${pkgs.writers.writeDash "otpmenu" ''
243243+ unset TERM
244244+ ${pkgs.otpmenu}/bin/otpmenu
245245+ ''}
246246+247247+ # screenlock
248248+ bindsym $mod+F11 exec ${pkgs.swaylock}/bin/swaylock -f -c 000000
249249+250250+ # media buttons
251251+ bindsym XF86AudioMute exec ${pkgs.pulseaudio.out}/bin/pactl -- set-sink-mute @DEFAULT_SINK@ toggle
252252+ bindsym XF86AudioRaiseVolume exec ${pkgs.pulseaudio.out}/bin/pactl -- set-sink-volume @DEFAULT_SINK@ +4%
253253+ bindsym XF86AudioLowerVolume exec ${pkgs.pulseaudio.out}/bin/pactl -- set-sink-volume @DEFAULT_SINK@ -4%
254254+ bindsym XF86MonBrightnessDown exec ${pkgs.acpilight}/bin/xbacklight -time 0 -dec 1
255255+ bindsym XF86MonBrightnessUp exec ${pkgs.acpilight}/bin/xbacklight -time 0 -inc 1
256256+257257+ # background programs
258258+ exec ydotoold
259259+ exec_always pkill kanshi; exec ${pkgs.kanshi}/bin/kanshi
260260+261261+ # theme and env specific stuff
262262+ exec_always ${pkgs.writers.writeDash "dbus-sway-environment" ''
263263+ set -efux
264264+ dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
265265+ systemctl --user stop xdg-desktop-portal xdg-desktop-portal-wlr
266266+ systemctl --user start xdg-desktop-portal xdg-desktop-portal-wlr
267267+ ''}
268268+269269+ exec_always ${let
270270+ schema = pkgs.gsettings-desktop-schemas;
271271+ datadir = "${schema}/share/gsettings-schemas/${schema.name}";
272272+ in pkgs.writers.writeDash "gsettings" ''
273273+ set -efux
274274+ export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}:$XDG_DATA_DIRS
275275+ gnome_schema=org.gnome.desktop.interface
276276+ gsettings set $gnome_schema gtk-theme 'Dracula'
277277+ ''}
278278+279279+ # keyboard
280280+ input type:keyboard {
281281+ xkb_layout us
282282+ xkb_variant altgr-intl
283283+ xkb_options caps:hyper
284284+ }
285285+286286+ # flameshot
287287+ for_window [app_id="flameshot"] border pixel 0, floating enable, fullscreen disable, move absolute position 0 0
288288+ exec ${pkgs.flameshot}/bin/flameshot
289289+ '';
290290+291291+}