Hi,
ich bräuchte ein wenig Hilfe ein Bash Script zu debuggen und anzupassen. Es geht um ein Script, das auf ein ACPI Event hin, die Video Modes durch-"toggle"-t. Also von INTERNAL_ONLY nach MIRROR nach EXTERNAL_ONLY nach BOTH und das Ganze mittels xrandr. Das Script stammt aus dem ThinkWiki hat aber einige Probleme so wie ich das sehe:
Erstmal braucht aber nur folgender Teil ein wenig Hilfe:
Und zwar ist das Problem, dass INTERNAL_STATE=(normal ist statt leer zu sein. Der Output von xrandr der ein leeres INTERNAL_STATE bringen sollte sieht so aus:
Ist das Ding verbunden sollte eher sowas hier da stehen:
Hab leider wenig Plan von diesem grep/sed-Kram :S
cu
serow
ich bräuchte ein wenig Hilfe ein Bash Script zu debuggen und anzupassen. Es geht um ein Script, das auf ein ACPI Event hin, die Video Modes durch-"toggle"-t. Also von INTERNAL_ONLY nach MIRROR nach EXTERNAL_ONLY nach BOTH und das Ganze mittels xrandr. Das Script stammt aus dem ThinkWiki hat aber einige Probleme so wie ich das sehe:
Code:
#!/bin/bash
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
EXTERNAL_OUTPUT="VGA"
INTERNAL_OUTPUT="LVDS"
EXTERNAL_LOCATION="left"
# Figure out which user and X11 display to work on
# TODO there has to be a better way to do this?
X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $1}')
export DISPLAY=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $3}')
# Switch to X user if necessary
if [ "$X_USER" != "$USER" ]; then
SU="su $X_USER -c"
else
SU="sh -c"
fi
case "$EXTERNAL_LOCATION" in
left|LEFT)
EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"
;;
right|RIGHT)
EXTERNAL_LOCATION="--right-of $INTERNAL_OUTPUT"
;;
top|TOP|above|ABOVE)
EXTERNAL_LOCATION="--above $INTERNAL_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
EXTERNAL_LOCATION="--below $INTERNAL_OUTPUT"
;;
*)
EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"
;;
esac
# Figure out current state
INTERNAL_STATE=$($SU xrandr | grep ^$INTERNAL_OUTPUT | grep " con" | sed "s/.*connected//" | sed "s/ //" | sed "s/ .*//g")
EXTERNAL_STATE=$($SU xrandr | grep ^$EXTERNAL_OUTPUT | grep " con" | sed "s/.*connected//" | sed "s/ //" | sed "s/ .*//g")
echo "INTERNAL_STATE=$INTERNAL_STATE"
echo "EXTERNAL_STATE=$EXTERNAL_STATE"
if [ -z "$INTERNAL_STATE" ]; then
STATE="external"
elif [ -z "$EXTERNAL_STATE" ]; then
STATE="internal"
else
INTERNAL_STATE=$(echo $INTERNAL_STATE | sed "s/[0-9]*x[0-9]*//")
EXTERNAL_STATE=$(echo $EXTERNAL_STATE | sed "s/[0-9]*x[0-9]*//")
if [ "$INTERNAL_STATE" = "$EXTERNAL_STATE" ]; then
STATE="mirror"
else
STATE="both"
fi
fi
function screen_external(){
$SU "xrandr --output $INTERNAL_OUTPUT --off"
$SU "xrandr --output $EXTERNAL_OUTPUT --mode 1024x768"
}
function screen_internal(){
$SU "xrandr --output $INTERNAL_OUTPUT --auto"
$SU "xrandr --output $EXTERNAL_OUTPUT --off"
}
function screen_mirror(){
$SU "xrandr --output $INTERNAL_OUTPUT --auto"
$SU "xrandr --output $EXTERNAL_OUTPUT --mode 1024x768 --same-as $INTERNAL_OUTPUT"
}
function screen_both(){
$SU "xrandr --output $INTERNAL_OUTPUT --auto"
$SU "xrandr --output $EXTERNAL_OUTPUT --mode 1024x768 $EXTERNAL_LOCATION"
}
function screen_toggle(){
case "$STATE" in
internal)
echo "Switching to Mirror"
screen_mirror
;;
mirror)
echo "Switching to External Only"
screen_external
;;
external)
echo "Switching to Both"
screen_both
;;
both)
echo "Switching to Internal Only"
screen_internal
;;
*)
echo "Switching to Internal as State could not be determined"
screen_internal
;;
esac
}
# What should we do?
DO="$1"
if [ -z "$DO" ]; then
if [ $(basename $0) = "thinkpad-fn-f7" ]; then
DO="toggle"
fi
fi
case "$DO" in
toggle)
echo "TOGGLE"
screen_toggle
;;
internal)
echo "INTERNAL"
screen_internal
;;
external)
echo "EXTERNAL"
screen_external
;;
mirror)
echo "MIRROR"
screen_mirror
;;
both)
echo "BOTH"
screen_both
;;
status)
echo "Current Fn-F7 state is: $STATE"
echo
echo "Attached monitors:"
$SU xrandr | grep "\Wconnected" | sed "s/^/ /"
;;
*)
echo "usage: $0 <command>" >&2
echo >&2
echo " commands:" >&2
echo " status" >&2
echo " internal" >&2
echo " external" >&2
echo " mirror" >&2
echo " both" >&2
echo " toggle" >&2
echo >&2
;;
esac
Erstmal braucht aber nur folgender Teil ein wenig Hilfe:
Code:
# Figure out current state
INTERNAL_STATE=$($SU xrandr | grep ^$INTERNAL_OUTPUT | grep " con" | sed "s/.*connected//" | sed "s/ //" | sed "s/ .*//g")
EXTERNAL_STATE=$($SU xrandr | grep ^$EXTERNAL_OUTPUT | grep " con" | sed "s/.*connected//" | sed "s/ //" | sed "s/ .*//g")
echo "INTERNAL_STATE=$INTERNAL_STATE"
echo "EXTERNAL_STATE=$EXTERNAL_STATE"
Und zwar ist das Problem, dass INTERNAL_STATE=(normal ist statt leer zu sein. Der Output von xrandr der ein leeres INTERNAL_STATE bringen sollte sieht so aus:
LVDS connected (normal left inverted right x axis y axis etc etc)
Ist das Ding verbunden sollte eher sowas hier da stehen:
LVDS connected 1024x768+1024+0 (normal left inverted right x axis y axis etc etc)
Hab leider wenig Plan von diesem grep/sed-Kram :S
cu
serow