From 6d87114290f5076b62f65037c719d1f9c46cbb2c Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 20 Feb 2023 14:21:04 +0100 Subject: Add i3 shortcuts for enabling/disabling displayport as well as turning its brightness on/off --- yoga/bin/toggle-dp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 yoga/bin/toggle-dp (limited to 'yoga/bin/toggle-dp') diff --git a/yoga/bin/toggle-dp b/yoga/bin/toggle-dp new file mode 100755 index 0000000..9d80383 --- /dev/null +++ b/yoga/bin/toggle-dp @@ -0,0 +1,32 @@ +#!/bin/bash +set -ex + +EXTERNAL="$(xrandr | grep 'DisplayPort.* connected' | cut -d' ' -f1)" + +map_wacom () { + xsetwacom set 'Wacom Intuos S Pen stylus' MapToOutput $1 2>/dev/null || true +} + +if [ -z "$EXTERNAL" ]; then + # No external display; only use laptop screen + xrandr --output eDP --primary --auto --output $EXTERNAL --off + map_wacom eDP +else + # External display; check if it is currently used + set +e + xrandr --listactivemonitors | grep $EXTERNAL >/dev/null + RESULT=$? + set -e + if [ $RESULT -eq 0 ]; then + # External display in use; disable + xrandr --output eDP --primary --auto --output $EXTERNAL --off + map_wacom eDP + else + # External display not in use; enable + xrandr --output eDP --auto --below $EXTERNAL --primary --output $EXTERNAL --auto + map_wacom $EXTERNAL + fi +fi + +# Reset background +setbg -- cgit v1.2.3