You are not logged in.

#1 2010-08-23 17:02:38

delcypher
Member
Registered: 2010-04-17
Posts: 42

Problem using xrandr with acpid with bash script on Asus EeePC 1005HA

Hi I've been trying to setup some of my "action keys" using acpid (e.g. touchpad enable toggle, volume control) on my netbook and I've managed to setup up all the keys I want except for one.

I want one of my keys to run a script that toggles the external display on or off (VGA1).

the switch on action is done using the following command

xrandr --output VGA1 --mode 1280x768

the switch off action is done using the following command

xrandr --output VGA1 --off

If I run these commands myself everything works fine.

The external toggle screen code is as follows.

#!/bin/bash
#Script to switch external display on/off

export DISPLAY=':0'
#Get line number of where LVDS1 description starts
LINE_NO=$(xrandr --query | grep -En LVDS1 | grep -Eo '^[0-9]+')
echo '####' >> /home/dan/errorlog
xrandr --query  1>> /home/dan/errorlog
echo '###' >> /home/dan/errorlog
ACTIVE=$(xrandr --query | head --lines=${LINE_NO} | grep -Ec '[0-9]+\.[0-9]+\*')
echo "is active?$ACTIVE" >> /home/dan/errorlog
if [ "$ACTIVE" -eq 0 ]; then
    #activate external display
    echo "Activating external display..." 1>> /home/dan/errorlog
    xrandr --verbose --output VGA1 --mode 1280x768 1>> /home/dan/errorlog 2>> /home/dan/errorlog
elif [ "$ACTIVE" -eq 1 ]; then
    #disable external display
    echo "Disabling external display..." 1>> /home/dan/errorlog
    xrandr --verbose --output VGA1 --off 1>> /home/dan/errorlog 2>> /home/dan/errorlog
else
    echo "Cannot determine if the external display is active. Doing nothing!" 1>> /home/dan/errorlog

fi

The script uses

xrandr --query

to determine if VGA1 is active. A * symbol is placed next to a mode if it is active. However it seems that when I press my key and acpid runs the above script the active mode is not always correctly reported (note that if I run the script manually myself it always seems to work).

Here is the output of errorlog (with # annotations by me)

#FIRST KEYPRESS, SWITCHES ON EXTERNAL DISPLAY AS EXPECTED AS NO ACTIVE MODE ON VGA1

####
Screen 0: minimum 320 x 200, current 1024 x 600, maximum 4096 x 4096
VGA1 connected (normal left inverted right x axis y axis)
   1024x768       60.0 +   75.1     70.1  
   1280x768       59.9  
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?0
Activating external display...
screen 0: 1280x768 320x192 mm 101.60dpi
crtc 0:     1280x768   59.9 +0+0 "VGA1"

#SECOND KEYPRESS, SWITCHES OFF EXTERNAL DISPLAY AS MODE 1280X768 IS ACTIVE

####
Screen 0: minimum 320 x 200, current 1280 x 768, maximum 4096 x 4096
VGA1 connected 1280x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768       60.0 +   75.1     70.1  
   1280x768       59.9* 
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?1
Disabling external display...
crtc 0: disable
screen 0: 1024x600 256x150 mm 101.60dpi

#THIRD KEYPRESS, SHOULD SWITCH EXTERNAL DISPLAY ON BUT IT DOESN'T BECAUSE MODE 1024X768 IS REPORTED AS BEING ACTIVE EVEN THOUGH IT ISN'T

####
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 4096 x 4096
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768       60.0*+   75.1     70.1  
   1280x768       59.9  
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?1
Disabling external display...
crtc 0: disable
screen 0: 1024x600 256x150 mm 101.60dpi

#FOURTH KEYPRESS, 1024X768 REPORTED AS ACTIVE MODE AGAIN EVEN THOUGH THE DISPLAY IS INACTIVE

####
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 4096 x 4096
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768       60.0*+   75.1     70.1  
   1280x768       59.9  
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?1
Disabling external display...
crtc 0: disable
screen 0: 1024x600 256x150 mm 101.60dpi

#FIFTH KEYPRESS, 1024X768 INCORRECTLY REPORTED AGAIN!

####
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 4096 x 4096
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768       60.0*+   75.1     70.1  
   1280x768       59.9  
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?1
Disabling external display...
crtc 0: disable
screen 0: 1024x600 256x150 mm 101.60dpi

#xrandr --query, is manually ran first, then key is pressed! NOW SWITCHES DISPLAY ON BECAUSE NO ACTIVE MODES ARE SHOWN

####
Screen 0: minimum 320 x 200, current 1024 x 600, maximum 4096 x 4096
VGA1 connected (normal left inverted right x axis y axis)
   1024x768       60.0 +   75.1     70.1  
   1280x768       59.9  
   832x624        74.6  
   800x600        85.1     72.2     75.0     60.3     56.2  
   640x480        85.0     72.8     75.0     66.7     60.0  
   720x400        70.1  
LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+   65.0  
   800x600        60.3     56.2  
   640x480        59.9  
###
is active?0
Activating external display...
screen 0: 1280x768 320x192 mm 101.60dpi
crtc 0:     1280x768   59.9 +0+0 "VGA1"
####

As noted above I can enable the display but when I try to disable it the next time the script is executed by acpid VGA1 is misreported as having an active mode repeatedly (If I wait long enough after pressing a key the script sometimes works) so the script doesn't reactivate the display. If I manually run

xrandr --query

manually myself the script suddenly works if I try and run it again.

Does anyone have any idea what's going on!?

Thanks.

Offline

Board footer

Powered by FluxBB