This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
forked from wertarbyte/autorandr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautorandr-update-display
executable file
·94 lines (78 loc) · 1.89 KB
/
autorandr-update-display
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
DATE=$(date +%Y%m%d-%H%M%S)
set -e
AUTORANDR="/usr/local/bin/autorandr"
XRANDR="/usr/bin/xrandr"
XBACKLIGHT="/usr/bin/xbacklight"
find_user() {
local D="$1"
#local user=$(who | grep 'tty' | awk -vD="$D" '$0 ~ "\\(:"D"\\)$" {print $1}') ## Works better for GNOME
#local user=$(who | awk -vD="$D m" '$2 ~ ":"D || $0 ~ "\\(:"D"\\)$" {print $1}' |head -n 1) ## Works better for KDE
local user=$(who | awk -vD="$D" '$2 ~ ":"D || $0 ~ "\\(:"D"\\)$" {print $1}' |head -n 1) ## Works better for KDE and Ubuntu
if [[ ! $user ]]; then
echo "No user found!" >&2
who >&2
exit 10
fi
echo $user
}
run_as_x_user() {
local user="$1"; shift
local cmd="$@"
case "$user" in
"")
;;
# Run as root:
"(unknown)")
eval ${cmd}
;;
*)
/bin/su -c "$cmd" "$user"
;;
esac
}
switch_external_off() {
local user="$1"
run_as_x_user $user $XRANDR --output DP1 --off --output DP2 --off --output DP3 --off
}
update_backlight() {
local user="$1"
case $(detect_autorandr $user) in
docked*)
run_as_x_user $user $XBACKLIGHT -set 100%
;;
mobile*)
run_as_x_user $user $XBACKLIGHT -set 40%
;;
*)
echo "Unrecognised autorandr session" >&2
;;
esac
}
detect_autorandr() {
local user="$1"
run_as_x_user $user $AUTORANDR |awk '/detected/ {print $1}'
}
############################
update_backlight=""
while [[ "$1" ]]; do
case "$1" in
-backlight)
update_backlight=1
shift
;;
*)
echo "'$1' arg not recognised" >&2
exit 1
;;
esac
done
############################
for X in /tmp/.X11-unix/X*; do
D="${X##/tmp/.X11-unix/X}"
user=$(find_user $D)
export DISPLAY=":$D"
#switch_external_off $user
run_as_x_user $user $AUTORANDR -c
[[ $update_backlight ]] && update_backlight $user
done