set $notify ~/projects/sisyphus/scripts/notify.sh

bindsym {

    # Focus
    $flag+$up    focus up
    $flag+$right focus right
    $flag+$down  focus down
    $flag+$left  focus left

    $flag+Up     focus up
    $flag+Right  focus right
    $flag+Down   focus down
    $flag+Left   focus left

    $flag+p      focus parent
    $flag+space  focus mode_toggle

    # Move windows
    $flag+Shift+$up     move up
    $flag+Shift+$right  move right
    $flag+Shift+$down   move down
    $flag+Shift+$left   move left

    $flag+Shift+Up      move up
    $flag+Shift+Right   move right
    $flag+Shift+Down    move down
    $flag+Shift+Left    move left

    $flag+Next          move scratchpad
    $flag+KP_Next       move scratchpad
    $flag+Prior         scratchpad show
    $flag+KP_Prior      scratchpad show

    # Layouts
    $flag+z       layout toggle split
    $flag+x       layout tabbed
    $flag+c       split h
    $flag+v       split v

    $flag+f       floating enable,  border normal 1
    $flag+Shift+f floating disable, border pixel 1

    $flag+s       sticky toggle
    $flag+F11     fullscreen

    $alt+Next     border pixel 1      # Show window title
    $alt+KP_Next  border pixel 1
    $alt+Prior    border normal 1     # Hide window title
    $alt+KP_Prior border normal 1
}

# Workspaces
set {
    $ws1  "1:1"
    $ws2  "2:2"
    $ws3  "3:3"
    $ws4  "4:4"
    $ws5  "5:5"
    $ws6  "6:6"
    $ws7  "7:7"
    $ws8  "8:8"
    $ws9  "9:9"
    $ws10 "10:10"
    $ws11 "11:Soc"
    $ws12 "12:Ent"
}

bindsym {
    # Focus a specific workspace
    $flag+1              workspace $ws1
    $flag+2              workspace $ws2
    $flag+3              workspace $ws3
    $flag+4              workspace $ws4
    $flag+5              workspace $ws5
    $flag+6              workspace $ws6
    $flag+7              workspace $ws7
    $flag+8              workspace $ws8
    $flag+9              workspace $ws9
    $flag+0              workspace $ws10
    $flag+minus          workspace $ws11
    $flag+equal          workspace $ws12

    # Move window to a specific workspace
    $flag+Shift+1        move container to workspace $ws1,  workspace $ws1
    $flag+Shift+2        move container to workspace $ws2,  workspace $ws2
    $flag+Shift+3        move container to workspace $ws3,  workspace $ws3
    $flag+Shift+4        move container to workspace $ws4,  workspace $ws4
    $flag+Shift+5        move container to workspace $ws5,  workspace $ws5
    $flag+Shift+6        move container to workspace $ws6,  workspace $ws6
    $flag+Shift+7        move container to workspace $ws7,  workspace $ws7
    $flag+Shift+8        move container to workspace $ws8,  workspace $ws8
    $flag+Shift+9        move container to workspace $ws9,  workspace $ws9
    $flag+Shift+0        move container to workspace $ws10, workspace $ws10
    $flag+Shift+minus    move container to workspace $ws11, workspace $ws11
    $flag+Shift+equal    move container to workspace $ws12, workspace $ws12

    # Go through workspaces in order
    $flag+Control+$left  workspace prev_on_output
    $flag+Control+$right workspace next_on_output

    $flag+Control+Left   workspace prev_on_output
    $flag+Control+Right  workspace next_on_output

    $flag+Control+Shift+$left  move container to workspace prev_on_output, workspace prev_on_output
    $flag+Control+Shift+$right move container to workspace next_on_output, workspace next_on_output

    $flag+Control+Shift+Left   move container to workspace prev_on_output, workspace prev_on_output
    $flag+Control+Shift+Right  move container to workspace next_on_output, workspace next_on_output

    # Also GNOME-like keybinds
    $flag+$alt+$left     workspace prev_on_output
    $flag+$alt+$right    workspace next_on_output

    $flag+$alt+Left      workspace prev_on_output
    $flag+$alt+Right     workspace next_on_output

    $flag+$alt+Shift+$left     move container to workspace prev_on_output, workspace prev_on_output
    $flag+$alt+Shift+$right    move container to workspace next_on_output, workspace next_on_output

    $flag+$alt+Shift+Left      move container to workspace prev_on_output, workspace prev_on_output
    $flag+$alt+Shift+Right     move container to workspace next_on_output, workspace next_on_output

    # Use your mouse to scroll between workspaces
    --whole-window $flag+$scrollUp      workspace prev_on_output
    --whole-window $flag+$scrollDown    workspace next_on_output
}

bindgesture {
    swipe:3:right workspace prev_on_output
    swipe:3:left  workspace next_on_output
}

# Outputs
bindsym {
    # Use "left" and "up" at the same time to mimic "previous"
    # Use "right" and "down" at the same time to mimic "next"
    # Though this does not work when using multiple screens, it's an intermediary solution until Sway supports "output next/previous"
    $flag+Control+$up         focus output left,  focus output up
    $flag+Control+$down       focus output right, focus output down

    $flag+Control+Up          focus output left,  focus output up
    $flag+Control+Down        focus output right, focus output down

    $flag+$alt+$up            focus output left,  focus output up
    $flag+$alt+$down          focus output right, focus output down

    $flag+$alt+Up             focus output left,  focus output up
    $flag+$alt+Down           focus output right, focus output down

    $flag+Control+Shift+$up   move container to output left,  focus output left \
                              move container to output up,    focus output up
    $flag+Control+Shift+$down move container to output right, focus output right \
                              move container to output down,  focus output down

    $flag+Control+Shift+Up    move container to output left,  focus output left \
                              move container to output up,    focus output up
    $flag+Control+Shift+Down  move container to output right, focus output right \
                              move container to output down,  focus output down

    $flag+$alt+Shift+$up      move container to output left,  focus output left \
                              move container to output up,    focus output up
    $flag+$alt+Shift+$down    move container to output right, focus output right \
                              move container to output down,  focus output down

    $flag+$alt+Shift+Up       move container to output left,  focus output left \
                              move container to output up,    focus output up
    $flag+$alt+Shift+Down     move container to output right, focus output right \
                              move container to output down,  focus output down
}

# System
bindsym --locked {
    # Brightness
    XF86MonBrightnessDown       exec brightnessctl -e s 5%- && $notify -b
    XF86MonBrightnessUp         exec brightnessctl -e s +5% && $notify -b

    # Audio
    XF86AudioRaiseVolume        exec wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 2%+ && $notify -v
    XF86AudioLowerVolume        exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 2%- && $notify -v
    XF86AudioMute               exec wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && $notify -v
    XF86AudioMicMute            exec wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle

    # Media
    XF86AudioPlay               exec playerctl play-pause
    XF86AudioPrev               exec playerctl previous
    XF86AudioNext               exec playerctl next

    Shift+XF86AudioMute         exec playerctl play-pause
    Shift+XF86AudioLowerVolume  exec playerctl previous
    Shift+XF86AudioRaiseVolume  exec playerctl next

    # Other special keys
    XF86Calculator              exec qalculate-gtk
}

bindgesture hold:3              exec playerctl play-pause

# Shortcuts
bindsym {
    # Reload sway
    $alt+Shift+r reload
    # Dialog to exit sway
    $alt+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'
    
    # Kill focused window
    $flag+q        kill
    # Start a terminal
    $flag+Return   exec $term
    Control+$alt+t exec $term

    $alt+space     exec $menu
    $alt+Tab       focus prev
    $flag+Tab      exec $window_switcher

    --whole-window $alt+$scrollUp   focus prev
    --whole-window $alt+$scrollDown focus next

    # Lock the screen
    $flag+Delete   exec $lock
    
    # File explorer
    $flag+e        exec $term -e vifm
}

bindgesture {
    # Also show the bar, hide when finished
    swipe:3:up    bar hidden_state show, exec "$window_switcher; swaymsg bar hidden_state hide"
    swipe:4:up    exec "$menu; swaymsg bar hidden_state hide"

    # Cancel and hide bar
    swipe:down    exec pkill rofi, bar hidden_state hide
}
