Auto-magic Rotation HOW TO: for Intrepid, Jaunty, Karmic, and Lucid brought to us courtesy of Red_Lion post #576 in the "Re: Info and help for HP TX2500 Series" thread.
Red_Lion supplied the "hp-wmi.c" source code and his custom Makefile. The makefile was for 2.6.30 (in Jaunty) but works fine in 2.6.27 (Intrepid). Actually as far as I can tell the "hp-wmi.c" source code is the same from 2.6.27 to 2.6.30. If you want to verify this or get the source code directly use the links below.
The following assumes you have your video set up for rotation. See Appendix 1 in the Rotation HOW TO on the first page, first post of this thread.
First check to see if you already have HP-WMI installed:
If it is there, and it should be in Jaunty, Karmic, and Lucid, no need to compile it (thank you Red_Lion for pointing this out).
modprobe -l | grep hp-wmi
Next check 'lsmod' in a terminal:
In Intrepid you should see wmi. You should also see hp-wmi after you compile and install it, and then add it to the 'modules' file in "/etc/" as described below. In Jaunty, Karmic, and Lucid you should see only hp-wmi. If you don't you'll need to add it to 'modules' as below. The difference is due to the Ubuntu kernel team adding wmi to the kernel starting with Jaunty. So it's now wmi.h in "linux-headers" rather than wmi.ko in "linux-images".
For Intrepid download the hp_wmi.tar.gz onto your desktop. Extract it. In a terminal enter:
The "hp-wmi.ko" will be installed in "/lib/modules/`uname -r`/extra/".
sudo make install
To make hp-wmi active (i.e. present in lsmod) add "hp-wmi" (without the quotes) to the end of the "modules" file using:
Save and close.
gksudo gedit /etc/modules
Using Text Editor (gedit) open and place in an empty file the following script:
Note: In Lucid there has been a change to the device naming convention (actually true in Jaunty and Karmic also, but you can ignore it if using one of the modified wacom.fdi's). To get your devices to rotate enter 'xinput --list' in a terminal. Find the device names that correspond to stylus, eraser (if you have one), and touch. Then substitute the longer more descriptive device names (with the quotes) in for stylus, eraser, and touch in the script's xsetwacom commands. You can also use the ID numbers. There is a bug using the Lucid default wacom.ko (from linuxwacom version 0.8.4-4(?)). Stylus and touch are called the same, namely "Wacom ISDv4 93", for TX2500 & TX2000's. So for at least touch use the ID number. If you've compiled and installed linuxwacom 0.8.5-12 or 0.8.6-2 (or up) wacom.ko this bug was fixed.
# From Red_Lion post #576: http://ubuntuforums.org/showthread.php?t=845911&page=58
while true; do
if [[ -e /sys/devices/platform/hp-wmi/dock ]]; then
if [[ $new != $old ]]; then
# -Close and restart Cairo Dock so it resizes on rotation.
# killall -9 cairo-dock &
# sleep 2s
if [[ $new == "0" ]]; then
echo "Rotate to landscape, hide cellwriter."
xrandr -o normal
xsetwacom set stylus rotate NONE
xsetwacom set eraser rotate NONE
xsetwacom set touch rotate NONE
# cellwriter --hide-window
elif [[ $new == "4" ]]; then
echo "Rotate to portrait, show cellwriter."
xrandr -o right
xsetwacom set stylus rotate CW
xsetwacom set eraser rotate CW
xsetwacom set touch rotate CW
# cellwriter --show-window
# cairo-dock -o &
Save it in "/home/yourusername/" as ".automagic_rotation.sh" (without the quotes), or whatever you want to name it. Close Text Editor. Back in the terminal:
Then in Intrepid go to System->Preferences->Sessions and click on Add and for the command enter "/home/yourusername/.automagic_rotation.sh" (without the quotes). And title it “Auto-magic Rotation” or whatever you like. Remember ".automagic_rotation.sh" will be a hidden file and to view it you'll have to check Show Hidden Files in View.
chmod +x ~/.automagic_rotation.sh
In Jaunty, Karmic, & Lucid go to System->Preferences->Startup Applications and click on Add and for the command enter "/home/yourusername/.automagic_rotation.sh" (without the quotes). And title it “Auto-magic Rotation” or whatever you like.
As you can see from the commented out lines Red_Lion likes to have CellWriter show itself when in portrait/tablet orientation. I have Cairo Dock which needs to be restarted on rotation so that it correctly resizes. I left the lines in to demonstrate what you can do. For example you could integrate the Compiz_off_Rotation script into it if you have ATI video but want Compiz in landscape as I do in post #284.
Reboot. You should now have auto-magic rotation when you rotate your screen on the swivel hinge!
If you have used, or are planning on using, the patch Matthew Garrett (HP-WMI module maintainer) supplied to MisteR2 first you need to change 'dock' to 'tablet' on the "trigger line" according to Ayuthia. The patch separates out the swivel hinge signal from the "dock event" and calls it 'tablet'. This is obviously more technically correct and probably necessary for those of you with docks. Otherwise docking may trigger rotation. The patch, called "hp-wmi.diff", is attached to MisteR2's post #106 in this thread. The patch is included in the HP-WMI for kernel 2.6.31. So in Karmic you will also need to make these changes.
So in the script change:
Which is how MisteR2 has the line in his "rotate_screen_inotify_v2.sh" script in post #206 in this thread.
Additionally the '4' needs to be changed to a '1' in the 'elif' portrait rotation line (per Ayuthia). So:
elif [[ $new == "1" ]]; then
Note: In Karmic cak3 has another take on automatic rotation. He wrote a little bash "daemon" and uses Tom Jaeger's WacomRotate daemon (method 3). See post #374.
Appendix 1: hp-wmi.c source code blobs in the kernel git trees
kernel 2.6.27: http://git.kernel.org/?p=linux/kerne...712ccd2da1b220
kernel 2.6.30: http://git.kernel.org/?p=linux/kerne...712ccd2da1b220
Appendix 2: Explanation of WMI
For those who are curious about the WMI BIOS interface here is a brief explanation:
This driver adds support for the ACPI-WMI (Windows Management Instrumentation) mapper device (PNP0C14) found on some systems.
NOTE: You will need another driver or userspace application on top of this to actually use anything defined in the ACPI-WMI mapper. ACPI-WMI is a proprietary extension to ACPI to expose parts of the ACPI firmware to userspace - this is done through various vendor defined methods and data blocks in a PNP0C14 device, which are then made available for userspace to call.
The implementation of this in Linux currently only exposes this to other kernel space drivers.
This driver is a required dependency to build the firmware specific drivers needed on many machines, including Acer and HP laptops. [i.e. HP-WMI]
It is safe to enable this driver even if your DSDT doesn't define any ACPI-WMI devices.