X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=contrib%2Fpm-utils%2F40autorandr;h=8a66f3971f84d408e322e8ef0c692e0f892c8d43;hb=adb35ed8a70b28eb5e42be778a5d323e6d41b532;hp=80cda11bba44f0d2a0053f387322bbc0ebcf827b;hpb=737ca561f4d3dadacbbf5f561c58e7efceb0541e;p=deb_pkgs%2Fautorandr.git diff --git a/contrib/pm-utils/40autorandr b/contrib/pm-utils/40autorandr index 80cda11..8a66f39 100755 --- a/contrib/pm-utils/40autorandr +++ b/contrib/pm-utils/40autorandr @@ -16,12 +16,24 @@ detect_display() # Prefer w to who, see bug #39 if [ -x "`which w`" ]; then user="`w -h | awk -vD="$D" '$2 ~ ":"D"(.[0-9])?$" || $3 ~ ":"D"(.[0-9])?$" {print $1}' | head -n1`" + + if [ -z "$user" ]; then + # This fallback checks if there is exactly one user (except + # root) logged in an interactive session and assumes the + # session belongs to him. See bug #39. + user="`w -hu | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`" + fi else user="`who --all | awk -vD="$D" '$3 ~ ":"D"(.[0-9])?$" {print $1}' | head -1`" + + if [ -z "$user" ]; then + # Same fallback as above; see bug #39. + user="`who -u | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`" + fi fi if [ x"$user" != x"" ]; then - logger "autorandr: Changing display configuration for user '$user'" + logger "autorandr: Changing display configuration for display :$D, user '$user'" export DISPLAY=":$D" /bin/su -c "${AUTORANDR}" "$user" fi