]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - contrib/pm-utils/40autorandr
80cda11bba44f0d2a0053f387322bbc0ebcf827b
[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                 else
20                         user="`who --all | awk -vD="$D" '$3 ~ ":"D"(.[0-9])?$" {print $1}' | head -1`"
21                 fi
22
23                 if [ x"$user" != x"" ]; then
24                         logger "autorandr: Changing display configuration for user '$user'"
25                         export DISPLAY=":$D"
26                         /bin/su -c "${AUTORANDR}" "$user"
27                 fi
28         done
29 }
30
31 case "$1" in
32         thaw|resume)
33                 detect_display &
34                 ;;
35 esac