summaryrefslogtreecommitdiff
path: root/.local/bin/amdgpu-toggle-tearfree-x11
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/amdgpu-toggle-tearfree-x11')
-rwxr-xr-x.local/bin/amdgpu-toggle-tearfree-x1141
1 files changed, 41 insertions, 0 deletions
diff --git a/.local/bin/amdgpu-toggle-tearfree-x11 b/.local/bin/amdgpu-toggle-tearfree-x11
new file mode 100755
index 0000000..c7b1ebc
--- /dev/null
+++ b/.local/bin/amdgpu-toggle-tearfree-x11
@@ -0,0 +1,41 @@
1#!/bin/sh
2
3# requires: xrandr, awk
4
5err() {
6 printf "%s\n" "$*" >&2
7 exit 1
8}
9
10for cmd in xrandr awk; do
11 command -v "$cmd" >/dev/null 2>&1 || err "required command not found: $cmd"
12done
13
14# collect all connected outputs
15outputs=$(xrandr --query | awk '/ connected/ { print $1 }')
16
17[ -n "$outputs" ] || err "no connected outputs found."
18
19# sample TearFree state from the first connected output
20first_output=$(printf '%s\n' "$outputs" | awk 'NR==1')
21current_state=$(xrandr --props | awk -v out="$first_output" '
22 $1 == out { found=1 }
23 found && /TearFree:/ { print $2; exit }
24')
25
26case "$current_state" in
27 on) new_state="off" ;;
28 *) new_state="on" ;;
29esac
30
31# single xrandr invocation, avoids monitor reconfiguration for the most part
32xrandr_args=""
33for output in $outputs; do
34 xrandr_args="$xrandr_args --output $output --set TearFree $new_state"
35done
36
37# shellcheck disable=SC2086
38xrandr $xrandr_args || err "failed to set TearFree $new_state on all outputs"
39
40notify-send "AMDGPU (X11)" "TearFree $new_state" -t 3072 \
41 || printf "TearFree toggled to '%s' on all connected outputs.\n" "$new_state"