# Read `man 5 sway` for a complete reference.

### Variables
# Super 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
# Your preferred application launcher
# Note: it's recommended that you pass the final command to sway
#set $menu dmenu_path | dmenu | xargs swaymsg exec
set $menu bemenu-run
set $menu2 wofi | xargs -d '\n' swaymsg exec
set $brad-menu $HOME/bin/brad-menu
set $mpv-clipboard wl-paste | xargs -d '\n' mpv --force-window=immediate --osd-level=3 --save-position-on-quit | xargs swaymsg exec
set $mpv-clipboard-primary wl-paste -p | xargs -d '\n' mpv --force-window=immediate --osd-level=3 --save-position-on-quit | xargs swaymsg exec
set $mpv-stream-clipboard wl-paste | xargs -d '\n' mpv --pause=no --cache-secs=10 --demuxer-readahead-secs=10 --untimed --force-window=immediate --osd-level=3 --save-position-on-quit | xargs swaymsg exec
set $mpv-stream-clipboard-primary wl-paste -p | xargs -d '\n' mpv --pause=no --cache-secs=10 --demuxer-readahead-secs=10 --untimed --force-window=immediate --osd-level=3 --save-position-on-quit | xargs swaymsg exec
set $xdg-clipboard wl-paste | xargs -d '\n' xdg-open | xargs swaymsg exec
set $xdg-clipboard-primary wl-paste -p | xargs -d '\n' xdg-open | xargs swaymsg exec

# hide titlebars
#default_border none
default_border pixel 1
#new_window normal
#for_window [class="^.*"] border pixel 1
for_window [app_id="term-temp"] floating enable, border pixel 3
for_window [app_id="term-scratch"] floating enable, border pixel 3
#for_window [app_id="picker"] floating enable, border pixel 3, resize set 1200 800, move down 500
for_window [app_id="picker"] border pixel 3, resize set 1200 800
for_window [app_id="imv"] floating enable, border pixel 3, resize set 500 700, move position 100 ppt 100 ppt, move left 520, move up 750
no_focus [app_id="imv"]

#font
font pango:monospace 9

# autostart programs
exec --no-startup-id mpdscribble
exec --no-startup-id mako
exec --no-startup-id xrdb ~/.Xresources
exec sh -c 'dbus-launch --autolaunch=$(dbus-uuidgen --get) mako'
#exec --no-startup-id emacs
exec --no-startup-id "sh -c 'sleep 10; exec foot --app-id=term-local'"
exec --no-startup-id "sh -c 'sleep 15; exec foot --app-id=term-masaki'"
exec --no-startup-id "sh -c 'sleep 10; exec foot --app-id=term-editor'"

# gnome-keyring
exec eval $(gnome-keyring-daemon --start)
exec export SSH_AUTH_SOCK

set $laptop 'Chimei Innolux Corporation 0x14D4 0x00000000'
set $landscape 'Hewlett Packard HP ZR24w CNT037144C'
set $portrait 'Hewlett Packard HP ZR24w CNT03512JN'
bindswitch --reload --locked lid:on output $laptop disable
bindswitch --reload --locked lid:off output $laptop enable

### Output configuration
output $landscape bg $HOME/pictures/wallpaper/1529004448340.jpg fill
output $portrait bg $HOME/pictures/wallpaper/portrait/DYabJ0FV4AACG69.jpg fill

# random wallpaper
#set $wallpapers_path $HOME/pictures/wallpaper
#output * bg `find $wallpapers_path -type f | shuf -n 1` fill

# set $portrait as left monitor and rotate it anticlockwise
output $portrait pos 0 1200 transform 270
#
# broken
#exec swaymsg move workspace 1 to output $landscape
#exec swaymsg move workspace 2 to output $portrait
#exec swaymsg focus output $landscape

### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
#          timeout 300 'swaylock -f -c 000000' \
#          timeout 600 'swaymsg "output * dpms off"' \
#               resume 'swaymsg "output * dpms on"' \
#          before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.

### Input configuration

# mouse
input type:pointer accel_profile flat

# keyboards

# universal settings
input type:keyboard repeat_delay 280
input type:keyboard repeat_rate 40

# Pinky4
input "21582:28724:tamanishi_Pinky4_Keyboard" {
	xkb_layout us
	xkb_options compose:caps
}

# ThinkPad keyboard
input "1:1:AT_Translated_Set_2_keyboard" {
	xkb_layout us
	xkb_variant workman
	xkb_options compose:caps
}

# workman and qwerty, swappable, internal keyboard
#input "1:1:AT_Translated_Set_2_keyboard" {
#xkb_layout us,us
#xkb_variant workman,
#xkb_options compose:caps
#}


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

    # kill focused window
    bindsym $mod+Shift+q kill

    # start your launcher
    bindsym $mod+d exec $menu
    bindsym $mod+Shift+d exec $menu2
    bindsym $mod+q exec $brad-menu

    # focus-menu
    bindsym ctrl+$mod+f exec $HOME/bin/focus-menu

    # open clipboard contents in mpv
    bindsym $mod+p exec $mpv-clipboard
    bindsym $mod+Shift+p exec $mpv-clipboard-primary
    bindsym $mod+Mod1+p exec $mpv-stream-clipboard
    bindsym $mod+Mod1+Shift+p exec $mpv-stream-clipboard-primary

    # open clipboard contents with xdg-open
    bindsym $mod+Mod1+o exec $xdg-clipboard
    bindsym $mod+Mod1+Shift+o exec $xdg-clipboard-primary

    # mouse button for dragging.
    floating_modifier $mod normal

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

    # exit sway (logs you out of your Wayland session)
    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'

    # lock screen
    bindsym $mod+Shift+x exec swaylock -f -c 000000

    # emoji
    bindsym $mod+z exec ~/bin/emoji

    # clip-menu
    bindsym $mod+c exec ~/bin/bemenuclip

### Scrot
    # screenshot selected area
    bindsym $mod+x exec grim -g "$(slurp)" ~/scrot/$(date +'%Y-%m-%d-%H%M%S_grim.png')
    # screenshot all outputs
    bindsym Print exec grim ~/scrot/$(date +'%Y-%m-%d-%H%M%S_grim_desktop.png')
    # screenshot focused output
    bindsym ctrl+Print exec grim -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') ~/scrot/$(date +'%Y-%m-%d-%H%M%S_grim.png')
    # screenshot focused window
    bindsym Mod1+Print exec ~/bin/windowscrot
    # screenshot selected area after a few seconds
    bindsym Shift+Print exec ~/bin/geoscrot

### Focus
    # focus anki
    bindsym ctrl+$mod+a [class="Anki"] focus

    # focus browser (qutebrowser)
    bindsym ctrl+$mod+b [app_id="org.qutebrowser.qutebrowser"] focus ; [class="qutebrowser"] focus ; [app_id="icecat"] focus

    # focus browser (chromium)
    bindsym ctrl+Shift+$mod+b [app_id="chromium-browser"] focus

    # focus chat (nheko)
    bindsym ctrl+$mod+c [title="nheko"] focus

    # focus da file manager (pcmanfm-qt)
    #bindsym ctrl+$mod+d [class="Deluge"] focus
    bindsym ctrl+$mod+d [app_id="pcmanfm-qt"] focus ; [class="pcmanfm-qt"] focus

    # focus emacs
    bindsym ctrl+$mod+e [class="Emacs"] focus ; [app_id="term-editor"] focus

    # focus gajim
    bindsym ctrl+$mod+g [app_id="org.gajim.Gajim"] focus

    # focus safe (keepassxc)
    bindsym ctrl+$mod+s [class="KeePassXC"] focus ; [app_id="org.keepassxc.KeePassXC"] focus

    # focus local terminal
    bindsym ctrl+$mod+l [app_id="term-local"] focus

    # focus masaki terminal
    bindsym ctrl+$mod+m [app_id="term-masaki"] focus

    # focus obs (obs)
    bindsym ctrl+$mod+o [class="obs"] focus

    # focus video (mpv)
    bindsym ctrl+$mod+v [app_id="mpv"] focus

    # focus xmpp (dino)
    bindsym ctrl+$mod+x [app_id="dino"] focus

#
# 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
    # or use $mod+[up|down|left|right]
    bindsym $mod+Left focus left
    bindsym $mod+Down focus down
    bindsym $mod+Up focus up
    bindsym $mod+Right focus right
    bindsym ctrl+$mod+j focus output right
    bindsym ctrl+$mod+k focus output left

    # _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
    # ditto, with arrow keys
    bindsym $mod+Shift+Left move left
    bindsym $mod+Shift+Down move down
    bindsym $mod+Shift+Up move up
    bindsym $mod+Shift+Right move right
#
# Workspaces:
#
    # switch to workspace
    bindsym $mod+1 workspace 1
    bindsym $mod+2 workspace 2
    bindsym $mod+3 workspace 3
    bindsym $mod+4 workspace 4
    bindsym $mod+5 workspace 5
    bindsym $mod+6 workspace 6
    bindsym $mod+7 workspace 7
    bindsym $mod+8 workspace 8
    bindsym $mod+9 workspace 9
    bindsym $mod+0 workspace 10
    bindsym ctrl+$mod+n workspace next_on_output
    bindsym ctrl+$mod+p workspace prev_on_output 
    # move focused container to workspace
    bindsym $mod+Shift+1 move container to workspace 1
    bindsym $mod+Shift+2 move container to workspace 2
    bindsym $mod+Shift+3 move container to workspace 3
    bindsym $mod+Shift+4 move container to workspace 4
    bindsym $mod+Shift+5 move container to workspace 5
    bindsym $mod+Shift+6 move container to workspace 6
    bindsym $mod+Shift+7 move container to workspace 7
    bindsym $mod+Shift+8 move container to workspace 8
    bindsym $mod+Shift+9 move container to workspace 9
    bindsym $mod+Shift+0 move container to workspace 10
    # move workspaces between monitors
    bindsym $mod+o move workspace to output left

    # Note: workspaces can have any name you want, not just numbers.
    # We just use 1-10 as the default.
#
# 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+s 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

    # 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
    bindsym $mod+Shift+a focus child
    
    assign [class="Firefox"] 2
    assign [class="Nightly"] 2
    assign [class="IceCat"] 2
    assign [class="Navigator"] 2
    assign [class="qutebrowser"] 2
    assign [class="Deluge"] 3
    assign [app_id="icecat"] 2
    assign [app_id="mpv"] 1
    assign [app_id="term-masaki"] 2
    assign [app_id="term-local"] 1
    assign [app_id="term-editor"] 1

#
# Scratchpad:
#
    # Sway has a "scratchpad", which is a bag of holding for windows.
    # You can send windows there and get them back later.

    # Move the currently focused window to the scratchpad
    bindsym $mod+Shift+minus 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+minus scratchpad show

# colors
# class                 border  backgr. text    indicator child_border
client.focused          #222222 #000000 #ffffff #6c7172   #7fffd4
client.focused_inactive #222222 #000000 #E1E1E1 #6c7172   #222222
client.unfocused        #222222 #000000 #888888 #292d2e   #222222
client.urgent           #2f343a #900000 #ffffff #900000   #900000
client.placeholder      #000000 #000000 #ffffff #000000   #0c0c0c

#
# Resizing containers:
#
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"

    bindsym $mod+i mode "j: japanese; k: korean; v: vietnamese; esc: english"

    mode "j: japanese; k: korean; v: vietnamese; esc: english" {
        bindsym j exec ibus engine anthy; mode "default"
        bindsym k exec ibus engine hangul; mode "default"
        bindsym v exec ibus engine Unikey; mode "default"
        bindsym Return exec ibus engine xkb:us::eng; mode "default"
        bindsym Escape exec ibus engine xkb:us::eng; mode "default"
    }

#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.

bar {
    swaybar_command waybar
}

#bar {
#    position top
#
#    # When the status_command prints a new line to stdout, swaybar updates.
#    # The default just shows the current date and time.
#    status_command while date +'%A %Y-%m-%d %H:%M:%S'; do sleep 1; done
#
#    colors {
#        background #000000
#      	separator  #000000
#        statusline #ffffff
#
#      	focused_workspace  #ffffff #ffffff #000000
#      	active_workspace   #000000 #000000 #ffffff
#        inactive_workspace #000000 #000000 #ffffff
#	urgent_workspace   #000000 #e60000 #ffffff
#    }
#}