Skip to content

Instantly share code, notes, and snippets.

@callemo
Created August 1, 2023 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callemo/9c1f60387ad58aaf28126e4ffd5180f8 to your computer and use it in GitHub Desktop.
Save callemo/9c1f60387ad58aaf28126e4ffd5180f8 to your computer and use it in GitHub Desktop.
Dock and undock your OpenBSD laptop
#!/bin/sh
# dock: switches between external and internal displays.
prefix="${0##*/}:"
log() { echo "$prefix" "$@" >&2; }
fatal() { log "$@"; exit 1; }
int='eDP-1'
mode='1920x1080'
[ "$(uname)" = OpenBSD ] || fatal 'not running in OpenBSD'
ext="$(xrandr | awk '$2 == "connected" && $1 != "'$int'" { print $1 }')"
[ -n "$ext" ] || fatal 'not connected to an external display'
case "$0" in
*undock)
log "undocking from external $ext"
xrandr --output "$int" --auto --output "$ext" --off
xinput set-prop /dev/wsmouse 'Device Accel Constant Deceleration' 1
;;
*)
log "docking to external $ext"
xrandr --output "$ext" --mode "$mode" --output "$int" --off
xinput set-prop /dev/wsmouse 'Device Accel Constant Deceleration' 3
xinput set-button-map /dev/wsmouse 1 2 3 5 4 7 6
;;
esac
pgrep cwm && pkill -HUP cwm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment