summaryrefslogtreecommitdiff
path: root/dockd.sh
blob: 6c5831e639dc1457fee097e941660f2269ec7fec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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-3 --off --output DP-2 --auto --primary
	nvidia-settings --assign CurrentMetaMode="DP-2:nvidia-auto-select +0+0 { ForceCompositionPipeline = On }"
	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-3 --auto --primary --output DP-2 --off
	nvidia-settings --assign CurrentMetaMode="DP-3:nvidia-auto-select +0+0 { ForceCompositionPipeline = On }"
	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
}

[ "$1" = "dock" ] && dock && return 0
[ "$1" = "undock" ] && undock && return 0

while sleep 5
do
	xrandr=$(xrandr)
	case "$xrandr" in 
		*"DP-2 disconnected primary"*)
			# if DP-2 is disconnected and primary then undock
			undock
			;;
		*"DP-2 connected ("*)
			# if DP-2 is connected but isn't primary then dock
			dock
			;;
	esac
done