# Default config for sway
# vim: ft=i3
#
# Read `man 5 sway` for a complete reference.
#

### Variables
#
# 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
# Your preferred terminal emulator
set $term foot
set $term_cmd foot -T float
set $background $HOME/Pictures/wallpaper/bavarian_forest_5k_bw.jpg
set $brightness_cmd $HOME/.config/sway/bin/sway_brightness
set $output_cmd $HOME/.local/bin/swayout
set $volume_cmd $HOME/.config/sway/bin/sway_volume
set $media_cmd /usr/bin/playerctl
set $idle_cmd $HOME/.config/sway/bin/start_swayidle.sh
set $waybar_cmd $HOME/.config/sway/bin/start_waybar.sh
set $move_cmd $HOME/.config/sway/bin/sway_move
set $font Cascadia Code PL Regular 10
set $notify_cmd dunstify -r 123

# Your preferred application launcher
set $menu wofi --show drun --prompt applications
set $search_cmd $HOME/.config/sway/bin/sway_search
set $exit_cmd $HOME/.config/sway/bin/sway_exit

#
# Host Specific
#
include $HOME/.config/sway/hosts.d/$(hostname).conf

#
# General Options
#
focus_wrapping no
# nextcloud workaround
mouse_warping container
# floating_maximum_size 1600 x 900
font pango:$font
hide_edge_borders --i3 smart
smart_gaps on
default_border pixel 4
#
# Gaps
#
gaps inner 5
gaps outer 0
gaps left 0
gaps right 0


### Output configuration
# You can get the names of your outputs by running: swaymsg -t get_outputs
output * bg $background fill


### Input configuration
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
input type:keyboard {
  xkb_layout "eu"
}

### Key bindings
#
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
bindsym $mod+Shift+Return exec $term_cmd

# Kill focused window
bindsym $mod+Shift+q kill
bindsym --release button3 kill

# Start your launcher
bindsym $mod+r exec $menu
bindsym $mod+Shift+r exec $search_cmd

# 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

# Show exit menu
bindsym $mod+Shift+e exec $exit_cmd

# Moving around:
#
# 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
#
# Resize
#
bindsym $mod+Ctrl+$left resize shrink width 50px
bindsym $mod+Ctrl+$down resize grow height 50px
bindsym $mod+Ctrl+$up resize shrink height 50px
bindsym $mod+Ctrl+$right resize grow width 50px
#
# Workspaces:
#
# Switch to workspace
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+0 workspace number 10
bindsym $mod+Escape workspace back_and_forth
# Move focused container to workspace
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
bindsym $mod+Shift+0 move container to workspace number 10
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Urgent
#
bindsym $mod+u [urgent=latest] focus
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv

# Switch the current container between different layout styles
bindsym $mod+q layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+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
# Toggle border/titlebar
bindsym $mod+Control+b border 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+i focus parent
# Move focus to the child
bindsym $mod+Shift+i focus child

#
## Volume
#
bindsym XF86AudioRaiseVolume exec $volume_cmd increase
bindsym XF86AudioLowerVolume exec $volume_cmd decrease
bindsym XF86AudioMute exec $volume_cmd mute
bindsym XF86MonBrightnessUp exec $brightness_cmd increase
bindsym XF86MonBrightnessDown exec $brightness_cmd decrease
#
## Media
#
bindsym XF86AudioPlay exec $media_cmd play-pause
#
#
## Screenshot
#
# copy selection to clipboard
bindsym Print exec grim -g "$(slurp)" - | wl-copy
# copy selection to swappy
bindsym Shift+Print exec grim -g "$(slurp)" - | swappy -f -
# save selection
bindsym $mod+Print exec grim -g "$(slurp)" \
    $(xdg-user-dir PICTURES)/screenshot_$(date +'%Y%m%d_%H%M%S').png
#
## Output
#
bindsym $mod+p exec "$term_cmd $output_cmd"

#
# Gaps
#
gaps inner 5
gaps outer 0
gaps left 0
gaps right 0

#
# Scratchpad:
#
# Move the currently focused window to the scratchpad
bindsym $mod+Shift+s move scratchpad
bindsym $mod+Ctrl+s scratchpad show
bindsym $mod+a [con_mark="a" tiling=True] focus; [con_mark="a" floating=True] focus output $$main; \
    [con_mark="a" floating=True] scratchpad show;
bindsym $mod+s [con_mark="s" tiling=True] focus; [con_mark="s" floating=True] focus output $$main; \
    [con_mark="s" floating=True] scratchpad show;
bindsym $mod+d [con_mark="d" tiling=True] focus; [con_mark="d" floating=True] focus output $$main; \
    [con_mark="d" floating=True] scratchpad show;
bindsym $mod+z [con_mark="z" tiling=True] focus; [con_mark="z" floating=True] focus output $$main; \
    [con_mark="z" floating=True] scratchpad show;
bindsym $mod+x [con_mark="x" tiling=True] focus; [con_mark="x" floating=True] focus output $$main; \
    [con_mark="x" floating=True] scratchpad show;
bindsym $mod+c [con_mark="c" tiling=True] focus; [con_mark="c" floating=True] focus output $$main; \
    [con_mark="c" floating=True] scratchpad show;
bindsym $mod+Shift+u exec notify-send $$main

#
# Notifications
#
bindsym $mod+comma exec dunstctl close
bindsym $mod+Shift+comma exec dunstctl close-all
bindsym $mod+period exec dunstctl history-pop
bindsym $mod+Shift+period exec dunstctl set-paused toggle

#
# Modes
#
mode "move" {
    bindsym $left move left 25px
    bindsym $down move down 25px
    bindsym $up move up 25px
    bindsym $right move right 25px
    # move more
    bindsym Shift+$left move left 100px
    bindsym Shift+$down move down 100px
    bindsym Shift+$up move up 100px
    bindsym Shift+$right move right 100px
    # edges
    bindsym q [floating=True] exec $move_cmd top-left
    bindsym w [floating=True] exec $move_cmd top-center
    bindsym e [floating=True] exec $move_cmd top-right
    bindsym a [floating=True] exec $move_cmd center-left
    bindsym s [floating=True] exec $move_cmd center-center
    bindsym d [floating=True] exec $move_cmd center-right
    bindsym z [floating=True] exec $move_cmd bottom-left
    bindsym x [floating=True] exec $move_cmd bottom-center
    bindsym c [floating=True] exec $move_cmd bottom-right
    # resize presets
    bindsym 1 resize set width 25ppt; [floating=True] resize set width  600px height  360px
    bindsym 2 resize set width 30ppt; [floating=True] resize set width  700px height  420px
    bindsym 3 resize set width 35ppt; [floating=True] resize set width  800px height  480px
    bindsym 4 resize set width 40ppt; [floating=True] resize set width  900px height  540px
    bindsym 5 resize set width 45ppt; [floating=True] resize set width 1000px height  600px
    bindsym 6 resize set width 50ppt; [floating=True] resize set width 1100px height  660px
    bindsym 7 resize set width 55ppt; [floating=True] resize set width 1200px height  720px
    bindsym 8 resize set width 60ppt; [floating=True] resize set width 1300px height  780px
    bindsym 9 resize set width 70ppt; [floating=True] resize set width 1400px height  840px
    bindsym 0 resize set width 80ppt; [floating=True] resize set width 1500px height  900px
    # focus
    bindsym $mod+h focus left
    bindsym $mod+j focus down
    bindsym $mod+k focus up
    bindsym $mod+l focus right
    # Return to default mode
    bindsym Return exec $notify_cmd "mode: default"; mode "default"
    bindsym Escape exec $notify_cmd "mode: default"; mode "default"
}
mode "mark" {
    bindsym a exec $notify_cmd "mode: mark a"; mark a
    bindsym s exec $notify_cmd "mode: mark s"; mark s
    bindsym d exec $notify_cmd "mode: mark d"; mark d
    bindsym z exec $notify_cmd "mode: mark z"; mark z
    bindsym x exec $notify_cmd "mode: mark x"; mark x
    bindsym c exec $notify_cmd "mode: mark c"; mark c
    bindsym Return exec $notify_cmd "mode: default"; mode "default"
    bindsym Escape exec $notify_cmd "mode: default"; mode "default"
}
# Move the focused workspace to another monitor
mode "move-workspace" {
    bindsym h move workspace to output left
    bindsym j move workspace to output down
    bindsym k move workspace to output up
    bindsym l move workspace to output right
    bindsym $mod+h focus left
    bindsym $mod+j focus down
    bindsym $mod+k focus up
    bindsym $mod+l focus right
    bindsym Return exec $notify_cmd "mode: default"; mode "default"
    bindsym Escape exec $notify_cmd "mode: default"; mode "default"
}
bindsym $mod+m exec $notify_cmd "mode: move"; mode "move"
bindsym $mod+Shift+a exec $notify_cmd "mode: mark";  mode "mark"
bindsym $mod+o exec $notify_cmd "mode: move-workspace"; mode "move-workspace"

#
# Window Rules:
#
for_window [title="nmtui"] floating enable
for_window [app_id="nm-connection-editor"] floating enable
for_window [title="float*"] floating enable
for_window [app_id="pavucontrol"] floating enable
for_window [app_id="com.nextcloud.desktopclient.nextcloud"] floating enable
for_window [app_id="imv"] floating enable
for_window [app_id="nm-openconnect-auth-dialog"] floating enable
for_window [app_id=".*"] title_format '<span font_weight="bold">%title</span> <span>(%app_id)</span>'
for_window [class=".*"] title_format '<span font_weight="bold">%title</span> <span>(%class:%instance)</span>'
# different dashes!
for_window [app_id="firefox" title="Firefox — Sharing Indicator"] floating enable
for_window [app_id="firefox" title="Firefox - Sharing Indicator"] floating enable
for_window [app_id="firefox" title="Picture-in-Picture"] floating enable
for_window [title="bluetoothctl"] floating enable
for_window [title="fzf"] floating enable
# mark rules
for_window [class="Plexamp" window_type="normal"] mark s
for_window [class="Ferdium" window_type="normal" window_role="browser-window"] mark z
for_window [class="Signal" window_type="normal" window_role="browser-window"] mark x
for_window [class="Microsoft Teams - Preview" window_type="normal"] mark c
# matlab workaround
no_focus [class="MATLAB R2021a" instance="sun-awt-X11-XDialogPeer"]

#
# Status Bar:
#
exec_always $waybar_cmd
exec_always $idle_cmd

#
# Autostart
#
exec "bash -c 'sleep 10; nextcloud --background'"
exec --no-startup-id dunst
exec --no-startup-id nm-applet --indicator
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
exec --no-startup-id $swayidle_cmd

include /etc/sway/config.d/*
