Evidlo / remarkable_mouse

use your reMarkable as a graphics tablet
GNU General Public License v3.0
514 stars 49 forks source link

Send events to a virtual input device #9

Closed matteodelabre closed 4 years ago

matteodelabre commented 5 years ago

Instead of sending mouse move and click events to the system’s main device, create a separate virtual input device that registers itself as a Wacom tablet. Most importantly, this enables pressure and tilt sensitivity which is picked up by programs such as GIMP or Krita.

Proper system support requires the xf86-input-wacom driver to be installed. It is available on Ubuntu and Debian inside the xserver-xorg-input-wacom package and on Arch Linux inside the xf86-input-wacom package. Following installation of that driver, the X server needs to be restarted.

Because this uses the libevdev library that is only supported on Linux, this commit breaks compatibility with Windows and (probably) macOS. Furthermore, because creating virtual input devices is restricted to root, the script must now be run with sudo. Failing to do so will most likely trigger a permission error.

CLI changes

xinput --set-prop "reMarkable tablet stylus" "Wacom Rotation" <orientation>

where <orientation> is one of 0 (for “right” orientation), 1 (for “portrait” orientation), 2 (for “left” orientation) or 3 (for “reversed portrait” orientation).

xinput --map-to-output "reMarkable tablet stylus" <output>

where <output> is the name of an output currently connected to the device, as listed by xrandr (e.g. LVDS1).

xinput --set-prop "reMarkable tablet stylus" "Wacom Pressure Threshold" 1000

where 1000 can be replaced by an arbitrary pressure threshold. On my machine, the default seems to be 26. The pressure profile (mapping the actual pressure put on the stylus to the pressure actually received by the drawing programs) can also be adjusted using the following prop:

xinput --set-prop "reMarkable tablet stylus" "Wacom Pressurecurve" 50 0 100 50

Dependencies changes

Replaced dependency pynput with libevdev (which requires that libevdev is present on the system). Dropped dependency screeninfo because assigning the input to a monitor is no longer done through this program.

Evidlo commented 5 years ago

I'm a bit concerned that this will break OSX support.

@bordaigorl Do you think you could test this?

As for dropping --orientation, --monitor and --threshold, perhaps these xinput command could be subprocessed?

bordaigorl commented 5 years ago

Well, unfortunately libevdev is not compatible with MacOs since it wraps linux kernel functionality. It would be really cool if there was something similar for OSX

Evidlo commented 5 years ago

I have added an --evdev flag to enable the virtual device and still maintain OSX support on the combined branch. Let me know what you think.

matteodelabre commented 5 years ago

This looks good to me. I’ve left some comments on the branch. Here’s a short comparison of the two modes:

out1440

Thank you for your work on this!

Evidlo commented 4 years ago

I'd like to use this GIF on the README if that's OK.

matteodelabre commented 4 years ago

Of course, no problem!