### sway settings

# logo key. Use Mod1 for Alt.
set $mod Mod4

# home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l

set $term $TERMINAL
set $browser $BROWSER
set $editor $EDITOR
#set $menu dmenu_path | dmenu | xargs swaymsg exec --
set $menu rofi -show combi | xargs swaymsg exec --

# wallpaper
exec change-background


### daemons


# notifications
exec swaync

# display orientation
exec --no-startup-id kanshi

# input method
exec fcitx5

# night light
#exec sleep 3 && gammastep -l LAT:LON

# mpd (music player daemon)
exec mpd

# xresources (nsxiv theme, and other programs)
exec xrdb $HOME/.config/x11/xresources

#  Syncthing (sync daemon)
exec syncthing --no-browser

# polkit
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

# emacs daemon
exec /usr/bin/emacs --daemon

#assign [app_id="librewolf"] 2
#assign [app_id="firefox"] 2
assign [app_id="mumble"] 9
assign [app_id="dino"] 9
assign [app_id="deluge"] 10

#exec_always autotiling
exec systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway


# behavior
focus_follows_mouse no
hide_edge_borders smart
workspace_auto_back_and_forth no
show_marks yes

# looks
font pango: monospace 8
gaps inner 25
#default_border pixel 2
bindsym $mod+Control+y border toggle

set $cl_high #333333
set $cl_indi #333333
set $cl_back #222222
set $cl_fore #d9d8d8
set $cl_urge #FF0000

client.focused      $cl_high $cl_high $cl_fore $cl_indi $cl_high
client.focused_inactive $cl_back $cl_back $cl_fore $cl_back $cl_back
client.unfocused    $cl_back $cl_back $cl_fore $cl_back $cl_back
client.urgent       $cl_urge $cl_urge $cl_fore $cl_urge $cl_urge

### Idle configuration

# timeout
exec idle


### key bindings


# start a terminal
bindsym $mod+Return exec $term

# kill focused window
bindsym $mod+q kill

# start your launcher
bindsym $mod+d exec $menu
bindsym $mod+Shift+d exec dmenu_path | dmenu | xargs swaymsg exec


# drag floating windows by holding down $mod and left mouse button.
# resize them with right mouse button + $mod.
# despite the name, also works for non-floating windows.
# change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal

# reload the configuration file
bindsym $mod+Shift+r reload

# toggle waybar
bindsym $mod+x exec killall -SIGUSR1 waybar

# exit sway (logs you out of your wayland session)
bindsym $mod+Shift+backspace exec prompt "Do you really wont to exit sway? This will end your Wayland session" "swaymsg exit"

# Prompts you options; shutdown, sleep, etc.
bindsym $mod+backspace exec sysact

# move your focus around
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right

# move the focused window with the same, but add Shift
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right

# screenshot
bindsym Print exec grimshot save output $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png
bindsym $mod+Print exec grimshot save active $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png
bindsym $mod+Shift+Print exec grimshot save window $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png
# alternative keybind
bindsym $mod+Control+u exec grimshot save output $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png
bindsym $mod+u exec grimshot save active $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png
bindsym $mod+Shift+u exec grimshot save window $HOME/Pictures/Screenshots/$(date +'%Y-%m-%d_%H.%M.%S_%Z').png


### programs

# sway config
bindsym $mod+F1 exec em ~/.config/sway/config
bindsym $mod+F2 exec em ~/projects/shell/dynobara/packages.txt
bindsym $mod+F3 exec em ~/projects/shell/dynobara/instruction.org

# browser
bindsym $mod+w exec $browser

# agenda
bindsym $mod+c exec emacsclient -c --eval '(org-agenda-list)' || emacs --eval '(org-agenda-list)'

# notebook
bindsym $mod+n exec $term -e $editor ~/notebook/index.org
bindsym $mod+v exec em ~/notebook/refile.org

# newsboat (rss)
bindsym $mod+Shift+n exec $term -e newsboat

# notifications tab
bindsym $mod+t exec swaync-client -t

# file manager
bindsym $mod+r exec $term -e lf

# emacs
bindsym $mod+e exec emacsclient -c || emacs

# mail
#bindsym $mod+e exec $term -e neomutt

# start tasks in dmenu
bindsym $mod+Shift+x exec start-tasks

# bookmarks
bindsym $mod+b exec em ~/notebook/bookmarks.org
bindsym $mod+shift+b exec bookmark
bindsym $mod+Insert exec wtype "$(grep -v '^#' ~/notebook/bookmarks.org | dmenu -l 50 | cut -d' ' -f1)"

# kaomiji?
bindsym $mod+z exec dmenukaomoji

# keepass dmenu
bindsym $mod+shift+Insert exec keepmenu

# download script
bindsym $mod+Control+m exec musdl

# youtube client
bindsym $mod+y exec io.freetubeapp.FreeTube $(wl-paste)

# games
bindsym $mod+g exec taverner

# workspace names
set $wp1 1
set $wp2 2
set $wp3 3
set $wp4 4
set $wp5 5
set $wp6 6
set $wp7 7
set $wp8 8
set $wp9 9
set $wp10 10


# binding workspace to monitors
workspace $wp1 output HDMI-A-1
workspace $wp2 output HDMI-A-1
workspace $wp3 output HDMI-A-1
workspace $wp4 output HDMI-A-1
workspace $wp5 output HDMI-A-1
workspace $wp6 output DVI-D-1
workspace $wp7 output DVI-D-1
workspace $wp8 output DVI-D-1
workspace $wp9 output DVI-D-1
workspace $wp10 output DVI-D-1

# switch to workspace
bindsym $mod+1 workspace $wp1
bindsym $mod+2 workspace $wp2
bindsym $mod+3 workspace $wp3
bindsym $mod+4 workspace $wp4
bindsym $mod+5 workspace $wp5
bindsym $mod+6 workspace $wp6
bindsym $mod+7 workspace $wp7
bindsym $mod+8 workspace $wp8
bindsym $mod+9 workspace $wp9
bindsym $mod+0 workspace $wp10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $wp1
bindsym $mod+Shift+2 move container to workspace $wp2
bindsym $mod+Shift+3 move container to workspace $wp3
bindsym $mod+Shift+4 move container to workspace $wp4
bindsym $mod+Shift+5 move container to workspace $wp5
bindsym $mod+Shift+6 move container to workspace $wp6
bindsym $mod+Shift+7 move container to workspace $wp7
bindsym $mod+Shift+8 move container to workspace $wp8
bindsym $mod+Shift+9 move container to workspace $wp9
bindsym $mod+Shift+0 move container to workspace $wp10

# move focused container to workspace
# with comma/period (</>)
bindsym $mod+comma focus output left
bindsym $mod+period focus output right
bindsym $mod+Shift+comma move window to output left
bindsym $mod+Shift+period move window to output right
bindsym $mod+Alt+comma move workspace to output left
bindsym $mod+Alt+period move workspace to output right
# with directional pad (up/down/left/right)
bindsym $mod+left focus output left
bindsym $mod+right focus output right
bindsym $mod+up focus output up
bindsym $mod+down focus output down
bindsym $mod+Shift+left move window to output left
bindsym $mod+Shift+right move window to output right
bindsym $mod+Shift+up move window to output up
bindsym $mod+Shift+down move window to output down
bindsym $mod+Alt+left move workspace to output left
bindsym $mod+Alt+right move workspace to output right
bindsym $mod+Alt+up move workspace to output up
bindsym $mod+Alt+down move workspace to output down

# splits
# bindsym $mod+b splith
# bindsym $mod+v splitv

# sticky
bindsym $mod+s sticky toggle

# switch the current container between different layout styles
#bindsym $mod+Shift+s layout stacking
bindsym $mod+Shift+w layout tabbed
bindsym $mod+Shift+e layout toggle split

# make the current focus fullscreen
bindsym $mod+f fullscreen

# toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle

# swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle

# move focus to the parent container
bindsym $mod+a focus parent

# move the currently focused window to the scratchpad
bindsym $mod+Shift+grave move scratchpad

# show the next scratchpad window or hide the focused scratchpad window.
# if there are multiple scratchpad windows, this command cycles through them.
bindsym $mod+grave scratchpad show

mode "resize" {
    # left will shrink the containers width
    # right will grow the containers width
    # up will shrink the containers height
    # down will grow the containers height
    bindsym $left resize shrink width 10px
    bindsym $down resize grow height 10px
    bindsym $up resize shrink height 10px
    bindsym $right resize grow width 10px

    # ditto, with arrow keys
    bindsym Left resize shrink width 10px
    bindsym Down resize grow height 10px
    bindsym Up resize shrink height 10px
    bindsym Right resize grow width 10px

    # return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
#bindsym $mod+r mode "resize"



# status bar
#include $HOME/.config/sway/bar
exec_always killall waybar
exec_always sleep 2 && waybar


### special keys


# keyboard brightness
bindsym XF86MonBrightnessDown exec brightnessctl set 10%-
bindsym XF86MonBrightnessUp exec brightnessctl set +10%

# volume
bindsym $mod+minus exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindsym $mod+equal exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
bindsym $mod+Shift+minus exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 15%-
bindsym $mod+Shift+equal exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 15%+
bindsym XF86AudioLowerVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindsym XF86AudioRaiseVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+

# mute
bindsym $mod+Shift+m exec wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindsym XF86AudioMute exec wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindsym XF86AudioMicMute exec wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle

# music controls
bindsym $mod+p exec mpc toggle
bindsym $mod+o exec mpc next
bindsym $mod+i exec mpc prev

# music seeking
bindsym $mod+bracketleft exec mpc seek -10
bindsym $mod+bracketright exec mpc seek +10
bindsym $mod+Shift+bracketleft exec mpc seek -60
bindsym $mod+Shift+bracketright exec mpc seek +60

# audio controller
bindsym $mod+Control+p exec $term -e pulsemixer

# music player
bindsym $mod+m exec $term -e ncmpcpp

#bindsym $mod+Shift+o exec mpc repeat
#bindsym $mod+Shift+i exec mpc seek 0%

bindsym $mod+Shift+s exec ~/.config/sway/scripts/sway-select-window

include /etc/sway/config.d/*
include ~/syncthing/default/config.d/sway/*