You are not logged in.
Hey everyone!
I am using an x200 tablet at the moment and I wanted to get autorotate to work including the digitizer but I coulnd't find something that satisfied me. So with the help of the internet I made this small script. It works on my tablet and checks every second if the laptop is in tablet and rotates per xrandr and xsetwacom.
I put the file in /bin/ and run it with my .xinitrc as autorotate &
Well here is the most important thing:
#!/bin/bash
# Working autorotate on thinkpad x200 tablet
rstate="0"
while [ true ]
do
react=`grep 0 -c /sys/devices/platform/thinkpad_acpi/hotkey_tablet_mode`
if (( ($react == "1") && ($rstate=="1") )); then
/usr/bin/xrandr -o normal
xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate none
xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate none
xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate none
rstate="0"
fi
if (( ($react != "1") && (rstate == "0") )); then
/usr/bin/xrandr -o right
xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate cw
xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate cw
xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate cw
rstate="1"
fi
sleep 1
done
Last edited by Erhan (2012-12-05 15:03:54)
Offline
This could be greatly simplified with inotify which would have the added benefit of removing the potential 2 second delay.
At the very least you could replace the useless cat and variable with the following:
if [[ $(grep -q 0 /sys/devices/restofpath) ]]; then
Last edited by Trilby (2012-12-05 14:37:51)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you very much. I optimized the code a little more now and it doesn't consume as much resources as before.
I just wonder if using grep is less resource hungry then cat.
What do you think?
Offline
The way you have implemented it, I suspect it is more resource hungry. I wasn't suggesting using grep to extract the number from the file, just as a conditional test of whether the file stores a 0 or not.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I have two if statements, would that mean that i would have to grep two times as a conditional test instead of using the output once?
My idea was that it reacts on the fact if the lid is open or in tablet mode. Moreover I want it to check if it is ALREADY in tablet mode so that it doesn't run xrandr and xsetwacom when there is no need to it.
Last edited by Erhan (2012-12-05 16:08:16)
Offline
Sorry, I think I have provided more confusion than assistance. These are really trivial issues when it is still looping continuously when it could use inotify instead. Try something like the following:
#!/bin/bash
# depends: inotify-tools
file="/sys/devices/platform/thinkpad_acpi/hotkey_tablet_mode"
while inotifywait -qq -e modify $file; do
if [[ "$(cat $file)" == "0" ]]; then
xrandr -o normal
xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate none
xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate none
xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate none
else
xrandr -o right
xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate cw
xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate cw
xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate cw
fi
done
Last edited by Trilby (2012-12-05 16:45:07)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you very much for your answer.
-e modify doesn't seem to react to the modifications. I can cat and proof that the file was modified but inotifywait stays quiet. I tried it with -e access and it reacted to cat at least. I'm trying to find out now why "modify" doesn't react to the modification.
But I like your idea because it would just go to the if statements if the file was changed. So less resources would be used this way.
Only drawback is the extra dependency but that's okay.
Last edited by Erhan (2012-12-05 17:25:46)
Offline
This thread is a little old, but this might help somebody else. You cannot use inotifywait in this case because the file you want to watch is never modified. Its content is basically generated when you read it, which, if you use inotifywait, you never do.
An alternative is to listen for acpi events. That's what I did in this script: https://github.com/slosd/bin/blob/maste … ate-screen
Instead of inotifywait I use acpi_listen:
acpi_listen | while read event; do
if [[
$event == "ibm/hotkey HKEY 00000080 00005009" # tablet
|| $event == "ibm/hotkey HKEY 00000080 0000500a" # laptop
]]; then
autorotate "$rotation"
fi
done
Last edited by slosd (2013-04-07 20:07:56)
Offline