diff options
Diffstat (limited to 'dockd.sh')
-rwxr-xr-x | dockd.sh | 65 |
1 files changed, 44 insertions, 21 deletions
@@ -1,7 +1,14 @@ #!/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() { - echo Docking... + notify-send Docking... xrandr \ --output DP-0 --off \ --output DP-1 --off \ @@ -9,18 +16,21 @@ dock() { --output DP-3 --off \ --output DP-4 --off \ --output VGA-0 --off - killall xautolock - xautolock \ - -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...'" + themer.sh -r sysctl hw.snd.default_unit=1 - echo Docked + 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() { - echo Undocking... + notify-send Undocking... xrandr \ --output DP-0 --off \ --output DP-1 --off \ @@ -28,6 +38,9 @@ undock() { --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 \ @@ -35,20 +48,30 @@ undock() { -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...'" - sysctl hw.snd.default_unit=4 - echo Undocked + -notifier "notify-send -t=10000 '10 seconds to lock...'" & + notify-send Undocked } -while : -do - is_lid_open=$(sysctl -n dev.acpi_lid.0.state) +contains() { + string="$1" + sub="$2" + [ "${string#*$sub}" != "$string" ] && return 0 || return 1 +} - if [ "$is_lid_open" != "$was_lid_open" ] - then - was_lid_open=$is_lid_open - [ "$is_lid_open" = "0" ] && dock || undock - fi +# start assuming undocked +undock - sleep 10 +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 + |