Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions autorandr
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fi

setup_fp_xrandr_edid() {
$XRANDR -q --verbose | awk '
/^[^ ]+ (dis)?connected / { DEV=$1; }
/^[^ ]+ (dis)?connected / || /^[^ ]+ unknown connection / { DEV=$1; }
$1 ~ /^[a-f0-9]+$/ { ID[DEV] = ID[DEV] $1 }
END { for (X in ID) { print X " " ID[X]; } }'
}
Expand Down Expand Up @@ -164,6 +164,13 @@ config_equal() {
}

load_cfg_xrandr() {
# Disable all displays first. There is a bug in xrandr where trying to enable a different display
# when two displays are already attached gives the error "cannot find crtc for output" even
# when --off was passed to disable existing displays. If --off is called first as a separate
# command the crtcs are freed up for use.
# https://bugs.freedesktop.org/show_bug.cgi?id=22539
# https://bugs.freedesktop.org/show_bug.cgi?id=29929
$XRANDR | grep -P '(^[^ ]+) (dis)?connected' | sed -r 's/(^[^ ]+).*/--output \1 --off/' | xargs $XRANDR
sed 's!^!--!' "$1" | xargs $XRANDR
}

Expand Down Expand Up @@ -250,14 +257,19 @@ if [ -n "$LOAD_PROFILE" ]; then
exit $?
fi

LOADED=0
for SETUP_FILE in $PROFILES/*/setup; do
if ! [ -e $SETUP_FILE ]; then
break
fi
PROFILE="$(basename $(dirname "$SETUP_FILE"))"
echo -n "$PROFILE"

if blocked "$PROFILE"; then
if [ "$LOADED" -eq 1 ]; then
# profile already loaded, skip the rest
echo ""
continue
elif blocked "$PROFILE"; then
echo " (blocked)"
continue
fi
Expand All @@ -268,15 +280,19 @@ for SETUP_FILE in $PROFILES/*/setup; do
if [ "$CHANGE_PROFILE" -eq 1 ]; then
if [ "$FORCE_LOAD" -eq 1 ] || ! config_equal "$PROFILE"; then
load "$PROFILE"
LOADED=1
fi
fi
# found the profile, exit with success
exit 0
else
echo ""
fi
done

# found the profile, exit with success
if [ "$LOADED" -eq 1 ]; then
exit 0
fi

# we did not find the profile, load default
if [ -n "$DEFAULT_PROFILE" ]; then
echo "No suitable profile detected, falling back to $DEFAULT_PROFILE"
Expand Down
1 change: 1 addition & 0 deletions pm-utils/40auto-disper
19 changes: 16 additions & 3 deletions pm-utils/40autorandr
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@
#
# 40autorandr: Change autorandr profile on thaw/resume

AUTORANDR="autorandr -c"
# detect if we are being called as 40auto-disper or 40autorandr
FORM=${0##*40}
case $FORM in
auto-disper)
AUTORANDR="auto-disper -c"
;;
*)
AUTORANDR="autorandr -c"
;;
esac
echo "$AUTORANDR"

detect_display()
{
for X in /tmp/.X11-unix/X*; do
D="${X##/tmp/.X11-unix/X}"
user=$(who | awk -vD="$D" '$5 ~ "\\(:"D"\\)$" {print $1}')
user=$(who | awk -vD="$D" '$5 ~ "\\(:"D"\\)$" {print $1; exit}')
echo "Checking $X -- $D - $user"
if [ x"$user" != x"" ]; then
echo "AUTORANDR $D - $user"
export DISPLAY=":$D"
/bin/su -c "${AUTORANDR}" "$user"
fi
done
echo "Done"
}

case "$1" in
thaw|resume)
detect_display
detect_display
;;
esac