Edited file the file with
sudo nano /usr/share/X11/xorg.conf.d/10-evdev.conf
Changed MatchIsTouchscreen from "on" to "off"
Section "InputClass"
Identifier "evdev touchscreen catchall"
MatchIsTouchscreen "off"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
"ELAN touchscreen" is disabled and no longer detected in xinput list.
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.
Best Answer
Try finding your touchscreen XID with
xinput --list
, then add the following command to your startup applications:xinput disable [touchscreen XID]
(for example, if the XID is 9, then the command would bexinput disable 9
).