Bind mouse to a concrete monitor in a dual screen setup with two independent pointers
Scenario is, bind my Wacom Bamboo to my second monitor and my mouse to the first monitor. The binding for Wacom Bamboo works perfect with the settings for the tablet. But how can I bind my mouse to the other monitor?
My current steps:
Bind the Wacom Bamboo to my second monitor
Configure two independent pointers
With plugged Wacom Bamboo and my mouse,
xinput --listshows~ xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=8 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=9 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=13 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=14 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen stylus id=10 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen eraser id=11 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen cursor id=15 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pad pad id=16 [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)] ↳ Power Button id=7 [slave keyboard (3)] ↳ Razer Razer BlackWidow Ultimate id=12 [slave keyboard (3)]Create a new device with
xinput create-master Bamboo~ xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=8 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=9 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=13 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=14 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen stylus id=10 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen eraser id=11 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pen cursor id=15 [slave pointer (2)] ⎜ ↳ Wacom Bamboo Pad pad id=16 [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)] ↳ Power Button id=7 [slave keyboard (3)] ↳ Razer Razer BlackWidow Ultimate id=12 [slave keyboard (3)] ⎡ Bamboo pointer id=17 [master pointer (18)] ⎜ ↳ Bamboo XTEST pointer id=19 [slave pointer (17)] ⎣ Bamboo keyboard id=18 [master keyboard (17)] ↳ Bamboo XTEST keyboard id=20 [slave keyboard (18)]Re-attach the Wacom Bamboo ids
xinput reattach 10 "Bamboo pointer" xinput reattach 11 "Bamboo pointer" xinput reattach 15 "Bamboo pointer" xinput reattach 16 "Bamboo pointer"~ xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=8 [slave pointer (2)] ⎜ ↳ Logitech G9x Laser Mouse id=9 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=13 [slave pointer (2)] ⎜ ↳ Razer Razer BlackWidow Ultimate id=14 [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)] ↳ Power Button id=7 [slave keyboard (3)] ↳ Razer Razer BlackWidow Ultimate id=12 [slave keyboard (3)] ⎡ Bamboo pointer id=17 [master pointer (18)] ⎜ ↳ Wacom Bamboo Pen stylus id=10 [slave pointer (17)] ⎜ ↳ Wacom Bamboo Pen eraser id=11 [slave pointer (17)] ⎜ ↳ Wacom Bamboo Pen cursor id=15 [slave pointer (17)] ⎜ ↳ Wacom Bamboo Pad pad id=16 [slave pointer (17)] ⎜ ↳ Bamboo XTEST pointer id=19 [slave pointer (17)] ⎣ Bamboo keyboard id=18 [master keyboard (17)] ↳ Bamboo XTEST keyboard id=20 [slave keyboard (18)]
1 Answer
About the answer
The answer below might need some additional editing. To create two separate mice, I followed the steps, mentioned in your question. It did work, but my "normal" mouse had some issues afterwards. Left-click did not work in some situations.
Since you do not mention the side- effect in your question, I assume it has to do with hardware- specific conflicting functionality of both mice I connected.
The good news is that xdotool apparently only "sees" the coordinates of the "main" mouse, which makes it possible to lock up the cursor in one of the screens.
Two scripts
Below two scripts:
- A script to lock up the pointer in either which one of the two screens.
- A script to automate step 2, as described in your question: Configure two independent pointers
1. Script to lock the cursor into one screen, in a dual monitor setup
#!/usr/bin/env python3
import subprocess
import time
import sys
# --- set the loop time below
t = 0.2
# ---
# screen argument should be either left or right
screen = sys.argv[1]
def get(command): return subprocess.check_output(command).decode("utf-8")
def condition(x_pos): if screen == "right": return x_pos < limit else: return x_pos > limit
def get_pos(): return [int(s.split(":")[-1]) for s in get( ["xdotool", "getmouselocation"] ).split()if any(["x" in s, "y" in s])]
limit = sorted([int(s.split("+")[1]) for s in get( "xrandr" ).split() if s.count("+") == 2])[-1]
limit = limit-3 if screen == "left" else limit+3
while True: pos = get_pos(); x_pos = pos[0] if condition(x_pos) == True: x = limit; y = pos[1] subprocess.Popen(["xdotool", "mousemove", str(x), str(y)]) else: pass time.sleep(t)to use
The script uses
xdotool:sudo apt-get install xdotoolCopy the script into an empty file, save it as
lock_cursor.pyRun it with the screen (
leftorright) as argument, by either:python3 /path/to/lock_cursor.py leftor
python3 /path/to/lock_cursor.py right
2. Script to automate the setup of two independent mice
This might be a tricky one, since I don't own a Wacom Bamboo, and I could not do a "final test" in a live situation. With my ordinary second mouse, it worked fine however (be it with different id- strings).
If it also works fine in your situation, both script could be merged to run in one call; the script below only takes action if the double- mice setup was not yet performed.
#!/usr/bin/env python3
import subprocess
import os
import sys
new_master = "Bamboo"
id_string = "Wacom Bamboo"
def get(command): return subprocess.check_output(command).decode("utf-8")
def execute(command): subprocess.call(["/bin/bash", "-c", command])
def find_ids(xinp_data, id_string): return [l.split("=")[1].split()[0] for l in xinp_data.splitlines() if id_string in l]
xinput_data = get(["xinput", "list"])
if not "Bamboo pointer" in xinput_data: ids = find_ids(xinput_data,id_string) if not ids: print("Wacom Bamboo seems not to be connected") else: pass execute("xinput create-master "+new_master) for n in ids: execute("xinput reattach "+n+' "Bamboo pointer"')To use
Simply copy the script into an empty file, save it as setup_bamboo.py, run it by the command:
python3 /path/to/setup_bamboo.pyNotes
I could not find another way to lock the mouse to one screen but to use
xdotool. The (first) script therefore locks up the mouse with the help ofxdotool. Since it runs in a periodic loop, the mouse position is corrected if it trespasses the screen's limit. The consequence is that, although effectively it works fine, you will still notice a cosmetic difference with a "hard" fence.I spent some time trying to reduce the effect, "smartly" increasing the loop speed whenever the mouse is near the screen's limit, or even making it dependent on the direction the mouse moves into. In the end however I came to the conclusion that the gained improvement is minimal, and simplicity of coding should be preferred.