3 # 40autorandr: Change autorandr profile on thaw/resume
4 exec > /var/log/autorandr.log 2>&1
6 AUTORANDR="autorandr -c --default default"
10 # Wait for the system to recognize the changed state, see bug #30
11 # Note the ampersand below, this runs asynchroneously.
14 for X in /tmp/.X11-unix/X*; do
15 D="${X##/tmp/.X11-unix/X}"
16 # Prefer w to who, see bug #39
17 if [ -x "`which w`" ]; then
18 user="`w -h | awk -vD="$D" '$2 ~ ":"D"(.[0-9])?$" || $3 ~ ":"D"(.[0-9])?$" {print $1}' | head -n1`"
20 if [ -z "$user" ]; then
21 # This fallback checks if there is exactly one user (except
22 # root) logged in an interactive session and assumes the
23 # session belongs to him. See bug #39.
24 user="`w -hu | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`"
27 user="`who --all | awk -vD="$D" '$3 ~ ":"D"(.[0-9])?$" {print $1}' | head -1`"
29 if [ -z "$user" ]; then
30 # Same fallback as above; see bug #39.
31 user="`who -u | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`"
35 if [ x"$user" != x"" ]; then
36 logger "autorandr: Changing display configuration for display :$D, user '$user'"
38 /bin/su -c "${AUTORANDR}" "$user"