Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I made a script to rotate my Wacom Bamboo tablet 180 degrees. It works fine when I execute it as myself (user) or root, but when started from udev (i.e. when plugging the tablet into a usb port) it won't work.

Udev rules:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="056a", ATTRS{idProduct}=="00d1", ATTRS{manufacturer}=="Wacom Co.,Ltd.", RUN+="/usr/local/bin/red-wacom-bamboo.sh"

Wacom script /usr/local/bin/red-wacom-bamboo.sh:

#!/usr/bin/env bash

exec > /tmp/red-wacom.log
exec 2>&1

# I had to do this otherwise xsetwacom would say:
# "Failed to open Display ."
# Is there a way to do this without using my username?
export XAUTHORITY=/home/redsandro/.Xauthority
export DISPLAY=:0

/usr/bin/xsetwacom set "Wacom Bamboo 2FG 4x5 Pen stylus" Rotate half
/usr/bin/xsetwacom set "Wacom Bamboo 2FG 4x5 Finger touch" Rotate half

Result in /tmp/red-wacom.log:

Cannot find device 'Wacom Bamboo 2FG 4x5 Pen stylus'.
Cannot find device 'Wacom Bamboo 2FG 4x5 Finger touch'.

(Note that the error in the log means the udev rule itself is not the problem.)

I tried setting a sleep in the script, maybe it needs a few ms. But that doesn't help.

  • Why doesn't this script work when called directly from udev?
    • How do I fix this?
  • Can I call a script from udev as a specific user? (e.g. sync /home to external backup drive - /home/ is only visible to it's user)
share|improve this question

2 Answers 2

up vote 2 down vote accepted

There is a fairly easy workaround, you can add something like this to your xorg.conf (or a file in xorg.conf.d, as I've done):

anthony@Watt:/etc/X11/xorg.conf.d$ cat 55-local-wacom.conf 
Section "InputClass"
       Identifier "Wacom Left Handed"
       MatchDriver "wacom"
       Option "Rotate" "half"
EndSection

Check the wacom(4) manpage for details of all the options you can set.

(In theory, you can use MatchProduct to individually configure the touchpad, pen, eraser, etc., but when I tried that a while back, it caused Xorg to segfault. Same if I tried to float them. But you're not doing any of that... and maybe the bug is fixed now.)

share|improve this answer
    
Wow, after so many googling I never came across this. I upvoted your answer. I will try it out when I am at work. Any specific reason for 55? I always use the idea that "numberless entries are processed last, so it's best to skip numbers for custom entries." –  Redsandro Feb 24 '13 at 17:33
    
@Redsandro /usr/share/X11/xorg.conf.d/50-wacom.conf is 50 on my system, so I picked 55 to come after it. Not sure that even matters. –  derobert Feb 25 '13 at 13:30

When you plug in the device:

  1. Linux detects the device and creates a device entry based on udev rules.
  2. The X server detects the device.

You cannot run xsetwacom before stage 2. Your script is failing because you're running it at stage 1, when X doesn't know the device yet.

You can set some settings with gnome-settings-daemon. I believe it gets its notification of the new device through D-Bus, but I don't know what the D-Bus event looks like. Try spying on the bus with dbus-monitor.

share|improve this answer
    
I upvoted your answer for the details, but I am not sure this is correct for the following reason: I tried using sleep with a bunch of seconds. When plugging in, the tablet works after less than a second, so by the time the commands get executed, the device is already detected and in use by X. But still it doesn't work? –  Redsandro Feb 24 '13 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.