4

I'm using Kubuntu 16.04 (xenial) on a laptop with an ELAN Touchscreen together with a DELL 750-AAHC active stylus. One of the buttons on the stylus behaves as a mouse middle-button, and I want it to be a right button instead.

I can achieve this by doing

$ xinput set-button-map "ELAN Touchscreen Pen" 1 3 2

(i.e., mapping the function of button 3, which must correspond to the right button, to physical button 2).

This does what I want, but the change is not permanent.

I added the command in ~/.xsessionrc (according to the answer on this post), so it's run automatically when I reboot, but the button mapping "randomly" reverts to default on its own: it's working as expected for a while, and suddenly I discover that it doesn't, so I get

$ xinput get-button-map "ELAN Touchscreen Pen"
1 2 3 4 5

and I have to remap it manually.

I tried a few "suspect" things to see what might be responsible for reverting, but I couldn't figure it out. It's not caused by

  • suspending the laptop or turning off the screen
  • rotating the screen (this was suspect because xinput is used on rotation to transform the input matrix.)
  • toggling touchscreen, touchpad or stylus input on/off (also with xinput).

IMPORTANT UPDATE:

I've discovered that this problem is not specific to the stylus: I disabled the finger-touch capability of the screen ("ELAN Touchscreen") earlier for some reason by doing:

$ xinput disable "ELAN Touchscreen"

and I just discovered that it came back on its own (and the stylus right-click had again reverted). So it seems like all xinput changes revert to default for this unknown reason.

UPDATE 2

I found some suspicious entries in /var/log/syslog when this happened again. The timestamps were during a time I had not actually been using the laptop for some time, so energy-saving features were probably activated (I have "dim screen" at 9 mins and "switch off" at 10 mins; I will experiment with energy saving and update accordingly).

The pattern bellow is actually repeated many times, with only a few seconds difference between each block.

usb 1-8: USB disconnect, device number 18
usb 1-8: new full-speed USB device number 19 using xhci_hcd
usb 1-8: New USB device found, idVendor=04f3, idProduct=2073
usb 1-8: New USB device strings: Mfr=4, Product=14, SerialNumber=0
usb 1-8: Product: Touchscreen
usb 1-8: Manufacturer: ELAN
input: ELAN Touchscreen Pen as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EE/input/input7548
input: ELAN Touchscreen as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EE/input/input7549
input: ELAN Touchscreen Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EE/input/input7552
hid-multitouch 0003:04F3:2073.04EE: input,hiddev0,hidraw0: USB HID v1.10 Keyboard [ELAN Touchscreen] on usb-0000:00:14.0-8/input0

In each block, almost everything is the same except a few numbers that increase. Here's the next block for comparison:

usb 1-8: USB disconnect, device number 19
usb 1-8: new full-speed USB device number 20 using xhci_hcd
usb 1-8: New USB device found, idVendor=04f3, idProduct=2073
usb 1-8: New USB device strings: Mfr=4, Product=14, SerialNumber=0
usb 1-8: Product: Touchscreen
usb 1-8: Manufacturer: ELAN
input: ELAN Touchscreen Pen as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EF/input/input7554
input: ELAN Touchscreen as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EF/input/input7555
input: ELAN Touchscreen Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/0003:04F3:2073.04EF/input/input7558
hid-mul itouch 0003:04F3:2073.04EF: input,hiddev0,hidraw0: USB HID v1.10 Keyboard [ELAN Touchscreen] on usb-0000:00:14.0-8/input0

The device numbers wrap around at 128.

System:

  • KDE Plasma 5.5.5
  • Qt 5.5.1
  • Kernel 4.13.0-32-generic #35~16.04.1-Ubuntu 64-bit
  • xinput version 1.6.2

    XI version on server: 2.3

  • X.Org X Server 1.19.5

    Release Date: 2017-10-12

    X Protocol Version 11, Revision 0

  • No idea what keeps messing with your xinput but as a workaround, how about putting it in a script and running it every minute through cron? do "crontab -e", scroll to the bottom to add a new line and add: "* * * * * /path/to/script.sh" – canofcolliders Feb 16 '18 at 4:06
  • Thanks. I've never dealt with cron, but maybe it's about time. I'll look into it as a possible workaround if all else fails. – Ratler Feb 17 '18 at 3:22
  • The xinput command can be put in the xserver startup configuration file. I am not sure exactly which file it needs to be in because the different X implementations fight each other to which config files have the final say. – stumblebee Feb 17 '18 at 6:43
  • @stumblebee, I guess that's what ~/.xsessionrc does in my case, but as I've mentioned in the post, the change reverts during the session for unknown reasons. – Ratler Feb 17 '18 at 20:58
  • 1
    It looks this may be due to the stylus powering off after a certain period of inactivity. This would be the equivalent of unplugging the device and plugging it back it. – stumblebee Feb 18 '18 at 1:25
1

This appears to be a bug (the fact that the touchscreen device randomly disconnects and reconnects as a new device, which has the side-effect of resetting all settings to default).

As a workaround, you can create your own udev rule (file name based on these suggestions by Daniel Drake) that will run a script that re-applies the xinput changes whenever the touchscreen reconnects:

sudo nano /etc/udev/rules.d/10-custom-elan.rules

and add this line which contains "idVendor" and "idProduct" information (from your syslog). The absolute path to "elan.sh" must be used.

ATTRS{idVendor}=="04f3", ATTRS{idProduct}=="2073", RUN+="/home/username/elan.sh"

(which roughly translates to ""when a device that matches the specified attributes is found, run the designated script").

Then create the actual script to run xinput:

nano /home/username/elan.sh 

with the following lines:

#!/usr/bin/env bash

#These lines allow the script to be called by udev rules
export DISPLAY=":0"
export XAUTHORITY="/home/username/.Xauthority"

#Command to remap buttons
xinput set-button-map "ELAN Touchscreen Pen" 1 3 2 4 5

And of course make it executable:

chmod +x /home/username/elan.sh

Without the export lines, the script works when called by you (the active user) directly, but it doesn't work when called by udev (the root user). Details can be found in this and this answer, but here's a brief summary:

To launch a graphical program on a user's desktop, you need two things: the address (what display the user's desktop is on) and authorisation. When a user logs in, the login manager authorises a connection to the X server by generating a cookie, adding it to the server and passing it to the user by writing it to $HOME/.Xauthority. The root user should, then, be able to connect by knowing the display used by the user and by having access to the Xauthority cookie. This is what the export lines achieve.

Note: the fact that the display number is hardcoded might cause a problem under some circumstances, but in this usage scenario (single user of a personal laptop) it will probably be OK.

  • @Ratler Thanks for the edit and additional information. – stumblebee Mar 29 '18 at 4:21
  • 1
    This was almost there, so I added some points (mainly the 'export' statements in the script) to make it the complete solution that (finally!) worked for me. Thanks for your help! – Ratler Mar 29 '18 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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