]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - contrib/pm-utils/40autorandr
264ba5f671b15baf06e8059cbfe5bb216cfbc4ae
[deb_pkgs/autorandr.git] / contrib / pm-utils / 40autorandr
1 #!/bin/sh
2 #
3 # 40autorandr: Change autorandr profile on thaw/resume
4 exec > /var/log/autorandr.log 2>&1
5
6 AUTORANDR="autorandr -c --default default"
7
8 detect_display()
9 {
10         # Wait for the system to recognize the changed state, see bug #30
11         # Note the ampersand below, this runs asynchroneously.
12         sleep 5
13
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`"
19
20                         if [ -z "$user" ];      then
21                                 # Try xinit as a fallback, see bug #39
22                                 user="`w -h | awk -vD="$D" '$7 ~ "xinit" && $0 ~ ":"D"(.[0-9])?" {print $1}' | head -n1`"
23                         fi
24                 else
25                         user="`who --all | awk -vD="$D" '$3 ~ ":"D"(.[0-9])?$" {print $1}' | head -1`"
26                 fi
27
28                 if [ x"$user" != x"" ]; then
29                         logger "autorandr: Changing display configuration for user '$user'"
30                         export DISPLAY=":$D"
31                         /bin/su -c "${AUTORANDR}" "$user"
32                 fi
33         done
34 }
35
36 case "$1" in
37         thaw|resume)
38                 detect_display &
39                 ;;
40 esac