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 @@ -9,8 +9,8 @@ from .codes import codes, types
logging.basicConfig(format='%(message)s')
log = logging.getLogger('remouse')
wacom_width = 15725
wacom_height = 20967
wacom_max_y = 15725
wacom_max_x = 20967
def get_monitor(region, monitor_num, orientation):
""" Get info of where we want to map the tablet to
@ -23,8 +23,17 @@ def get_monitor(region, monitor_num, orientation): @@ -23,8 +23,17 @@ def get_monitor(region, monitor_num, orientation):
Returns:
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:
x, y, width, height = get_region(orientation)
monitor = Monitor(
@ -34,7 +43,9 @@ def get_monitor(region, monitor_num, orientation): @@ -34,7 +43,9 @@ def get_monitor(region, monitor_num, orientation):
else:
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):
""" Show tkwindow to user to select mouse bounds
@ -100,21 +111,21 @@ def get_region(orientation): @@ -100,21 +111,21 @@ def get_region(orientation):
# 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):
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':
y = wacom_height - y
elif orientation == 'right':
x, y = wacom_height - y, wacom_width - x
wacom_width, wacom_height = wacom_height, wacom_width
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
x, y = y, wacom_max_x - x
wacom_max_x, wacom_max_y = wacom_max_y, wacom_max_x
ratio_width, ratio_height = monitor_width / wacom_max_x, monitor_height / wacom_max_y
if mode == 'fill':
scaling_x = max(ratio_width, ratio_height)
@ -129,8 +140,8 @@ def remap(x, y, wacom_width, wacom_height, monitor_width, @@ -129,8 +140,8 @@ def remap(x, y, wacom_width, wacom_height, monitor_width,
raise NotImplementedError
return (
scaling_x * (x - (wacom_width - monitor_width / scaling_x) / 2),
scaling_y * (y - (wacom_height - monitor_height / scaling_y) / 2)
scaling_x * (x - (wacom_max_x - monitor_width / scaling_x) / 2),
scaling_y * (y - (wacom_max_y - monitor_height / scaling_y) / 2)
)
# log evdev event to console

26
remarkable_mouse/evdev.py

@ -8,7 +8,7 @@ from socket import timeout as TimeoutError @@ -8,7 +8,7 @@ from socket import timeout as TimeoutError
import libevdev
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')
log = logging.getLogger('remouse')
@ -91,7 +91,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode) @@ -91,7 +91,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
local_device = create_local_device()
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 = []
@ -111,28 +111,28 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode) @@ -111,28 +111,28 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
# intercept EV_ABS events and modify coordinates
if types[e_type] == 'EV_ABS':
# handle x direction
if codes[e_type][e_code] == 'ABS_Y':
if codes[e_type][e_code] == 'ABS_X':
x = e_value
# handle y direction
if codes[e_type][e_code] == 'ABS_X':
if codes[e_type][e_code] == 'ABS_Y':
y = e_value
mapped_x, mapped_y = remap(
x, y,
wacom_width, wacom_height,
monitor.width, monitor.height,
wacom_max_x, wacom_max_y,
wacom_max_x * (monitor.width / tot_width), wacom_max_y * (monitor.height / tot_height),
mode, orientation
)
# FIXME - something wrong with remapping
# handle x direction
# if codes[e_type][e_code] == 'ABS_Y':
# e_value = int(mapped_x)
mapped_x += wacom_max_x * (monitor.x / tot_width)
mapped_y += wacom_max_y * (monitor.y / tot_height)
# # handle y direction
# if codes[e_type][e_code] == 'ABS_X':
# e_value = int(mapped_y)
# reinsert modified values into evdev event
if codes[e_type][e_code] == 'ABS_X':
e_value = int(mapped_x)
if codes[e_type][e_code] == 'ABS_Y':
e_value = int(mapped_y)
# pass events directly to libevdev
e_bit = libevdev.evbit(e_type, e_code)

44
remarkable_mouse/notes.md

@ -0,0 +1,44 @@ @@ -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 @@ -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 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')
log = logging.getLogger('remouse')
@ -31,7 +31,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode) @@ -31,7 +31,7 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
mouse = Controller()
monitor = get_monitor(region, monitor_num, orientation)
monitor, _ = get_monitor(region, monitor_num, orientation)
log.debug('Chose monitor: {}'.format(monitor))
x = y = 0
@ -46,11 +46,11 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode) @@ -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)
# handle x direction
if codes[e_type][e_code] == 'ABS_Y':
if codes[e_type][e_code] == 'ABS_X':
x = e_value
# handle y direction
if codes[e_type][e_code] == 'ABS_X':
if codes[e_type][e_code] == 'ABS_Y':
y = e_value
# handle draw
@ -63,9 +63,9 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode) @@ -63,9 +63,9 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
if codes[e_type][e_code] == 'SYN_REPORT':
mapped_x, mapped_y = remap(
x, y,
wacom_width, wacom_height,
wacom_max_x, wacom_max_y,
monitor.width, monitor.height,
mode, orientation
mode, orientation,
)
mouse.move(
monitor.x + mapped_x - mouse.position[0],

Loading…
Cancel
Save