Touchscreen and additional external monitor

15,357

Solution 1

There is a specific command for mapping input to a display in xsetwacom called MapToOutput. Here is what you do:

Start by figuring out the name of the display you want to map to. This can be done by running xrandr:

phnomic@phnomic-jobb:~$ xrandr
Screen 0: minimum 320 x 200, current 3200 x 1597, maximum 8192 x 8192
LVDS1 connected 1280x800+1920+797 (normal left inverted right x axis y axis) 286mm x 179mm
   1280x800       60.0*+
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA1 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
   1920x1200      59.9*+
   1920x1080      60.0  
   1600x1200      60.0  
   1680x1050      60.0  
   1280x1024      60.0  
   1440x900       59.9  
   1280x960       60.0  
   1024x768       60.0  
   800x600        60.3  
   640x480        60.0  
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)

In my case I want to use LVDS1.

Next, figure out what your devices are called. This is done using xsetwacom --list:

phnomic@phnomic-jobb:~$ xsetwacom --list
Wacom ISDv4 E6 Pen stylus           id: 20  type: STYLUS    
Wacom ISDv4 E6 Pen eraser           id: 21  type: ERASER    
Wacom ISDv4 E6 Finger touch         id: 22  type: TOUCH     

Finally run the command xsetwacom set "[device name]" MapToOutput [screen name] for all devices that you wish to assign. In my case, this becomes:

phnomic@phnomic-jobb:~$ xsetwacom set "Wacom ISDv4 E6 Pen stylus" MapToOutput LVDS1
phnomic@phnomic-jobb:~$ xsetwacom set "Wacom ISDv4 E6 Pen eraser" MapToOutput LVDS1
phnomic@phnomic-jobb:~$ xsetwacom set "Wacom ISDv4 E6 Finger touch" MapToOutput LVDS1

And then you are all good to use your fancy touch screen regardless of what monitors you connect it to and what orientation you use for your monitors.

If you want to know more, I recommend this sourceforge post.

Solution 2

I had the same problem on my Surface Pro 2 with Ubuntu 12.04 64 bit. I have a dual-monitor setup with a MiniDisplay to HDMI cable, my second monitor isn't touch enabled. What worked for me was to find device names by:

xinput --list

This returned:

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ HOLTEK Wireless USB Device                id=10   [slave  pointer  (2)]
⎜   ↳ Atmel Atmel maXTouch Digitizer            id=13   [slave  pointer  (2)]
⎜   ↳ MICROSOFT SAM                             id=11   [slave  pointer  (2)]
⎜   ↳ MICROSOFT SAM                             id=12   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ HOLTEK Wireless USB Device                id=9    [slave  keyboard (3)]
    ↳ Front LifeCam                             id=14   [slave  keyboard (3)]
    ↳ Rear LifeCam 

"xsetwacom --list" mentioned by @phnomic wouldn't return anything.

We then map devices to screens like @phnomic suggested:

xsetwacom set "Atmel Atmel maXTouch Digitizer" MapToOutput eDP1
xsetwacom set 11 MapToOutput eDP1
xsetwacom set 12 MapToOutput eDP1

note that 11 and 12 are device IDs for the two devices both named "MICROSOFT SAM"

Solution 3

I wrote a simple script that will fix things using udev. First create /etc/udev/rules.d/99-monitor-hotplug.rules

It is just this line:

ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/share/X11/touchscreen.sh"

Now the /usr/share/X11/touchscreen.sh file (mark it +x !!) :

#!/bin/sh
#
# This is designed to be run by hotplug.  See hotplug docs ...
#

# Make sure PATH is sane
export PATH="/bin:/usr/bin"

# Now the rest of the ENV to hook into X
# This should probably be run by Dbus, but I don't know how.
# Instead I see who's running Dbus, and get that user's .Xauthority
# So, its kind of a hack!

export USER=`ps -ef | grep dbus-daemon | grep session | cut -d ' ' -f 1`
export DISPLAY=":0"
export XAUTHORITY=/home/$USER/.Xauthority
export ICON=/usr/share/icons/Humanity/devices/48/monitor.svg

# Find Touchscreen id number -- sets id
export id=`xinput | grep Touch | cut -d '=' -f 2 | cut -f 1`

# Find the primary screen! 
export screen=`xrandr | grep primary | cut -d ' ' -f 1`

# Use xinput to map them
xinput --map-to-output $id $screen

su $USER -c "notify-send -i $ICON \"TouchScreen\"\
 \"Mapping Device $id to your $screen screen\""

The last line just pops up a nice message telling you what it did. When from a terminal, on any user-id, it works great, but won't work from udev! The script itself works fine - its just the notification that fails from udev. Yet nother dbus issue I think. If anyone can fix that - let me know!!

Share:
15,357

Related videos on Youtube

Pavel Polivka
Author by

Pavel Polivka

Updated on September 18, 2022

Comments

  • Pavel Polivka
    Pavel Polivka over 1 year

    Soon I'll commence a PhD study with a strong focus on modelling. I'm lucky enough to have my supervisor offer me a laptop. Since besides making and running models I'll be making minutes of meetings and perhaps giving a lecture from time to time, we were thinking of a touchscreen notebook.

    Due to contracts I'll be stuck with HP or Dell. A nice laptop we've found can be seen at here. The most important aspect here is probably that the graphics chip is an Intel HD Graphics 3000.

    Ideally I'd work with just the touchscreen during meetings and lectures, and would extend the laptop to an external monitor for modelling purposes. In the latter case I'd still use my laptop screen to draw diagrams. There are two points I'm worried about for now:

    1. Will the laptop touchscreen work with Ubuntu 11.10? Although similar questions on AskUbuntu and Googling suggest that it won't be a problem, I'd like to know for sure before buying the laptop. Would be a real waste if I need to switch back to Windows just to use the touchscreen.

    2. And if the touchscreen works, will it still work when I connect an external monitor? I found a similar question (see How do I calibrate a touchscreen on a dual monitor system?) but unfortunately that one has never been answered.

    If you can tell me anything that might help (different set-ups that worked or didn't work, etc.), please let me know.

  • Pavel Polivka
    Pavel Polivka about 12 years
    Your method is quicker and more elegant. The other answer might be useful for other applications, but yours should be the accepted answer. Thanks a lot :)
  • Pavel Polivka
    Pavel Polivka over 10 years
    Thanks for letting us know! Good to hear that xinput does the same job as xsetwacom --list. A small suggestion if I may, consider using "MICROSOFT SAM" instead of IDs 11 and 12. The IDs might change, the name won't.
  • Kat Amsterdam
    Kat Amsterdam almost 4 years
    great script except xinput | grep Touchscreen | cut -f 2 returns ID=11 (in my use case) but the xinput --map-to-output command only accepts 11 without the ID= xinput | cut -d '=' -f 2 | cut -f 1
  • Kat Amsterdam
    Kat Amsterdam almost 4 years
    Ok, I give up. This script doesn't work under Ubuntu 20.04 Unable to connect to X Server No Protocol specified Can't open Display :0
  • Evan Langlois
    Evan Langlois almost 4 years
    This was written years ago and I havent bothered to connect an external monitor in forever. I may look into this if I think about it. However, if it says cant open display ... Is X running? Is it running on :0 ?