Browse Source

finally working remapping for evdev

master
evan 2 years ago
parent
commit
3bcdb8f989
  1. 45
      remarkable_mouse/common.py
  2. 26
      remarkable_mouse/evdev.py
  3. 44
      remarkable_mouse/notes.md
  4. 12
      remarkable_mouse/pynput.py

45
remarkable_mouse/common.py

@ -9,8 +9,8 @@ from .codes import codes, types
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
log = logging.getLogger('remouse') log = logging.getLogger('remouse')
wacom_width = 15725 wacom_max_y = 15725
wacom_height = 20967 wacom_max_x = 20967
def get_monitor(region, monitor_num, orientation): def get_monitor(region, monitor_num, orientation):
""" Get info of where we want to map the tablet to """ Get info of where we want to map the tablet to
@ -23,8 +23,17 @@ def get_monitor(region, monitor_num, orientation):
Returns: Returns:
screeninfo.Monitor screeninfo.Monitor
(width, height): total size of all screens put together
""" """
# compute size of box encompassing all screens
max_x, max_y = 0, 0
for m in get_monitors():
x = m.x + m.width
y = m.y + m.height
max_x = max(x, max_x)
max_y = max(y, max_y)
if region: if region:
x, y, width, height = get_region(orientation) x, y, width, height = get_region(orientation)
monitor = Monitor( monitor = Monitor(
@ -34,7 +43,9 @@ def get_monitor(region, monitor_num, orientation):
else: else:
monitor = get_monitors()[monitor_num] monitor = get_monitors()[monitor_num]
return monitor log.debug(f"Chose monitor: {monitor}")
log.debug(f"Screen size: ({max_x}, {max_y})")
return monitor, (max_x, max_y)
def get_region(orientation): def get_region(orientation):
""" Show tkwindow to user to select mouse bounds """ Show tkwindow to user to select mouse bounds
@ -100,21 +111,21 @@ def get_region(orientation):
# remap wacom coordinates to screen coordinates # remap wacom coordinates to screen coordinates
def remap(x, y, wacom_width, wacom_height, monitor_width, def remap(x, y, wacom_max_x, wacom_max_y, monitor_width,
monitor_height, mode, orientation): monitor_height, mode, orientation):
if orientation == 'right':
x, y = wacom_max_x - x, wacom_max_y - y
if orientation == 'left':
pass
if orientation == 'top':
x, y = wacom_max_y - y, x
wacom_max_x, wacom_max_y = wacom_max_y, wacom_max_x
if orientation == 'bottom': if orientation == 'bottom':
y = wacom_height - y x, y = y, wacom_max_x - x
elif orientation == 'right': wacom_max_x, wacom_max_y = wacom_max_y, wacom_max_x
x, y = wacom_height - y, wacom_width - x
wacom_width, wacom_height = wacom_height, wacom_width ratio_width, ratio_height = monitor_width / wacom_max_x, monitor_height / wacom_max_y
elif orientation == 'left':
x, y = y, x
wacom_width, wacom_height = wacom_height, wacom_width
elif orientation == 'top':
x = wacom_width - x
ratio_width, ratio_height = monitor_width / wacom_width, monitor_height / wacom_height
if mode == 'fill': if mode == 'fill':
scaling_x = max(ratio_width, ratio_height) scaling_x = max(ratio_width, ratio_height)
@ -129,8 +140,8 @@ def remap(x, y, wacom_width, wacom_height, monitor_width,
raise NotImplementedError raise NotImplementedError
return ( return (
scaling_x * (x - (wacom_width - monitor_width / scaling_x) / 2), scaling_x * (x - (wacom_max_x - monitor_width / scaling_x) / 2),
scaling_y * (y - (wacom_height - monitor_height / scaling_y) / 2) scaling_y * (y - (wacom_max_y - monitor_height / scaling_y) / 2)
) )
# log evdev event to console # log evdev event to console

26
remarkable_mouse/evdev.py

@ -8,7 +8,7 @@ from socket import timeout as TimeoutError
import libevdev import libevdev
from .codes import codes, types from .codes import codes, types
from .common import get_monitor, remap, wacom_width, wacom_height, log_event from .common import get_monitor, remap, wacom_max_x, wacom_max_y, log_event
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
log = logging.getLogger('remouse') log = logging.getLogger('remouse')
@ -91,7 +91,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
local_device = create_local_device() local_device = create_local_device()
log.debug("Created virtual input device '{}'".format(local_device.devnode)) log.debug("Created virtual input device '{}'".format(local_device.devnode))
monitor = get_monitor(region, monitor_num, orientation) monitor, (tot_width, tot_height) = get_monitor(region, monitor_num, orientation)
pending_events = [] pending_events = []
@ -111,28 +111,28 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
# intercept EV_ABS events and modify coordinates # intercept EV_ABS events and modify coordinates
if types[e_type] == 'EV_ABS': if types[e_type] == 'EV_ABS':
# handle x direction # handle x direction
if codes[e_type][e_code] == 'ABS_Y': if codes[e_type][e_code] == 'ABS_X':
x = e_value x = e_value
# handle y direction # handle y direction
if codes[e_type][e_code] == 'ABS_X': if codes[e_type][e_code] == 'ABS_Y':
y = e_value y = e_value
mapped_x, mapped_y = remap( mapped_x, mapped_y = remap(
x, y, x, y,
wacom_width, wacom_height, wacom_max_x, wacom_max_y,
monitor.width, monitor.height, wacom_max_x * (monitor.width / tot_width), wacom_max_y * (monitor.height / tot_height),
mode, orientation mode, orientation
) )
# FIXME - something wrong with remapping mapped_x += wacom_max_x * (monitor.x / tot_width)
# handle x direction mapped_y += wacom_max_y * (monitor.y / tot_height)
# if codes[e_type][e_code] == 'ABS_Y':
# e_value = int(mapped_x)
# # handle y direction # reinsert modified values into evdev event
# if codes[e_type][e_code] == 'ABS_X': if codes[e_type][e_code] == 'ABS_X':
# e_value = int(mapped_y) e_value = int(mapped_x)
if codes[e_type][e_code] == 'ABS_Y':
e_value = int(mapped_y)
# pass events directly to libevdev # pass events directly to libevdev
e_bit = libevdev.evbit(e_type, e_code) e_bit = libevdev.evbit(e_type, e_code)

44
remarkable_mouse/notes.md

@ -0,0 +1,44 @@
# Coordinate Notes
```
Coordinate Systems
------------------
reMarkable (pen)
+---------+
| X |
| | |
| | |
| +--- Y |
| |
|---------|
|o o o|
+---------+
pynput output
+--------------+
| +----- X |
| | |
| | |
| Y |
+--------------+
|
-------
evdev output
+--------------+
| +----- X |
| | |
| | |
| Y |
+--------------+
|
-------
```

12
remarkable_mouse/pynput.py

@ -4,7 +4,7 @@ from screeninfo import get_monitors
# from .codes import EV_SYN, EV_ABS, ABS_X, ABS_Y, BTN_TOUCH # from .codes import EV_SYN, EV_ABS, ABS_X, ABS_Y, BTN_TOUCH
from .codes import codes from .codes import codes
from .common import get_monitor, remap, wacom_width, wacom_height, log_event from .common import get_monitor, remap, wacom_max_x, wacom_max_y, log_event
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
log = logging.getLogger('remouse') log = logging.getLogger('remouse')
@ -31,7 +31,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
mouse = Controller() mouse = Controller()
monitor = get_monitor(region, monitor_num, orientation) monitor, _ = get_monitor(region, monitor_num, orientation)
log.debug('Chose monitor: {}'.format(monitor)) log.debug('Chose monitor: {}'.format(monitor))
x = y = 0 x = y = 0
@ -46,11 +46,11 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
e_time, e_millis, e_type, e_code, e_value = struct.unpack('2IHHi', data) e_time, e_millis, e_type, e_code, e_value = struct.unpack('2IHHi', data)
# handle x direction # handle x direction
if codes[e_type][e_code] == 'ABS_Y': if codes[e_type][e_code] == 'ABS_X':
x = e_value x = e_value
# handle y direction # handle y direction
if codes[e_type][e_code] == 'ABS_X': if codes[e_type][e_code] == 'ABS_Y':
y = e_value y = e_value
# handle draw # handle draw
@ -63,9 +63,9 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
if codes[e_type][e_code] == 'SYN_REPORT': if codes[e_type][e_code] == 'SYN_REPORT':
mapped_x, mapped_y = remap( mapped_x, mapped_y = remap(
x, y, x, y,
wacom_width, wacom_height, wacom_max_x, wacom_max_y,
monitor.width, monitor.height, monitor.width, monitor.height,
mode, orientation mode, orientation,
) )
mouse.move( mouse.move(
monitor.x + mapped_x - mouse.position[0], monitor.x + mapped_x - mouse.position[0],

Loading…
Cancel
Save