aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2023-02-20 14:21:04 +0100
committerCamil Staps2023-02-20 14:21:04 +0100
commit6d87114290f5076b62f65037c719d1f9c46cbb2c (patch)
tree24a96aa4186a2e33d4a11f85640adb83d24231c9
parentMake dmenu case insensitive for running programs (diff)
Add i3 shortcuts for enabling/disabling displayport as well as turning its brightness on/off
-rw-r--r--i3/.i3/config2
-rwxr-xr-xyoga/bin/toggle-dp32
-rwxr-xr-xyoga/bin/toggle-dp-brightness11
3 files changed, 45 insertions, 0 deletions
diff --git a/i3/.i3/config b/i3/.i3/config
index 79427eb..74c8d49 100644
--- a/i3/.i3/config
+++ b/i3/.i3/config
@@ -38,6 +38,8 @@ bindsym XF86MonBrightnessUp exec bash -c 'echo "$(($(cat /sys/class/backlight/am
bindsym XF86MonBrightnessDown exec bash -c 'echo "$(($(cat /sys/class/backlight/amdgpu_bl0/brightness)-10))" > /sys/class/backlight/amdgpu_bl0/brightness'
bindsym $mod+XF86MonBrightnessUp exec bash -c 'echo 255 > /sys/class/backlight/amdgpu_bl0/brightness'
bindsym $mod+XF86MonBrightnessDown exec bash -c 'echo 1 > /sys/class/backlight/amdgpu_bl0/brightness'
+bindsym $mod+F7 exec toggle-dp
+bindsym $mod+Shift+F7 exec toggle-dp-brightness
# change focus
bindsym $mod+j focus left
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
diff --git a/yoga/bin/toggle-dp-brightness b/yoga/bin/toggle-dp-brightness
new file mode 100755
index 0000000..e92eaff
--- /dev/null
+++ b/yoga/bin/toggle-dp-brightness
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -e
+EXTERNAL="$(xrandr | grep 'DisplayPort.* connected' | cut -d' ' -f1)"
+[ -z "$EXTERNAL" ] && exit 1
+
+BRIGHTNESS="$(xrandr --verbose | grep -A5 "$EXTERNAL" | grep Brightness | cut -d':' -f2)"
+if [ "$BRIGHTNESS" == " 1.0" ]; then
+ xrandr --output $EXTERNAL --brightness 0
+else
+ xrandr --output $EXTERNAL --brightness 1
+fi