summaryrefslogblamecommitdiff
path: root/dockd.sh
blob: 2ac4ef6250d479dd326a261feaadc0e1707b9c02 (plain) (tree)
1
2
3
4
5
6
7
8
9
         
       
 





                                                 
        






                                                                                             
                    
                                    


                                                 

 





                                                
          






                                                                                                              


                                               






                                                                                                   

                                                                          

 




                                                                  
 

                         
 











                                                          
    
 
#!/bin/sh
#set -x

# To dock:
# - set DP-2 (external monitor) to primary output
# - restart i3 to get scaling correct via themer
# - set default sound unit to external speakers
# - disable laptop lid close sleep
# - disable auto locking and sleeping
dock() {
	xrandr \
		--output DP-0 --off \
		--output DP-1 --off \
		--output DP-2 --primary --mode 2560x1440 --pos 0x0 --rotate normal --dpi 96 \
		--output DP-3 --off \
		--output DP-4 --off \
		--output VGA-0 --off 
	themer.sh -r
	sysctl hw.snd.default_unit=1
	doas sysctl hw.acpi.lid_switch_state=NONE
	killall xautolock 
	notify-send Docked.
}

# To un-dock: 
# - set DP-3 (internal screen) to primary output
# - restart i3 to get scaling correct via themer
# - set default sound unit to builtin speakers
# - enable laptop lid close sleep
# - enable auto locking and sleeping
undock() {
	xrandr \
		--output DP-0 --off \
		--output DP-1 --off \
		--output DP-2 --off \
		--output DP-3 --primary --mode 1920x1080 --transform none --pos 0x0 --rotate normal --dpi 96 \
		--output DP-4 --off \
		--output VGA-0 --off 
	themer.sh -r
	sysctl hw.snd.default_unit=4
	doas sysctl hw.acpi.lid_switch_state=S3
	killall xautolock
	xautolock \
		-killtime 10 \
		-killer "sleep 0.5; doas acpiconf -s3" \
		-notify 10 \
		-time 10 \
		-locker "i3lock -n -f -c 000000 -i ~/.local/share/wallpapers/lock.png; sleep 0.2" \
		-notifier "notify-send -t=10000 '10 seconds to lock...'" &
	notify-send Undocked
}

contains() {
	string="$1"
	sub="$2"
	[ "${string#*$sub}" != "$string" ] && return 0 || return 1
}

# start assuming undocked
undock

while sleep 5
do
	xrandr=$(xrandr)

	# if DP-2 is disconnected and primary then undock 
	contains "$xrandr" "DP-2 disconnected primary" \
		&& undock \
		&& continue
	# if DP-2 is connected but isn't primary then dock
	contains "$xrandr" "DP-3 connected primary" \
		&& contains "$xrandr" "DP-2 connected" \
		&& dock 
done