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