|
|
|
|
@ -12,19 +12,24 @@ import paramiko
|
|
|
|
|
from screeninfo import get_monitors
|
|
|
|
|
from pynput.mouse import Button, Controller
|
|
|
|
|
|
|
|
|
|
# EVTYPE_SYNC = 0
|
|
|
|
|
# EVTYPE_KEY = 1
|
|
|
|
|
EVTYPE_ABS = 3
|
|
|
|
|
|
|
|
|
|
# WACOM_EVCODE_DISTANCE = 25
|
|
|
|
|
# WACOM_EVCODE_XTILT = 26
|
|
|
|
|
# WACOM_EVCODE_YTILT = 27
|
|
|
|
|
EVCODE_STYLUS_PRESSURE = 24
|
|
|
|
|
EVCODE_STYLUS_XPOS = 0
|
|
|
|
|
EVCODE_STYLUS_YPOS = 1
|
|
|
|
|
|
|
|
|
|
wacom_width = 15725
|
|
|
|
|
wacom_height = 20951
|
|
|
|
|
# evtype_sync = 0
|
|
|
|
|
# evtype_key = 1
|
|
|
|
|
e_type_abs = 3
|
|
|
|
|
|
|
|
|
|
# evcode_stylus_distance = 25
|
|
|
|
|
# evcode_stylus_xtilt = 26
|
|
|
|
|
# evcode_stylus_ytilt = 27
|
|
|
|
|
e_code_stylus_xpos = 1
|
|
|
|
|
e_code_stylus_ypos = 0
|
|
|
|
|
e_code_stylus_pressure = 24
|
|
|
|
|
# evcode_finger_xpos = 53
|
|
|
|
|
# evcode_finger_ypos = 54
|
|
|
|
|
# evcode_finger_pressure = 58
|
|
|
|
|
|
|
|
|
|
stylus_width = 15725
|
|
|
|
|
stylus_height = 20951
|
|
|
|
|
# finger_width = 767
|
|
|
|
|
# finger_height = 1023
|
|
|
|
|
|
|
|
|
|
mouse = Controller()
|
|
|
|
|
logging.basicConfig(format='%(message)s')
|
|
|
|
|
@ -32,23 +37,23 @@ log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# remap wacom coordinates in various orientations
|
|
|
|
|
def fit(x, y, wacom_width, wacom_height, monitor, orientation):
|
|
|
|
|
def fit(x, y, stylus_width, stylus_height, monitor, orientation):
|
|
|
|
|
|
|
|
|
|
if orientation == 'vertical':
|
|
|
|
|
y = wacom_height - y
|
|
|
|
|
y = stylus_height - y
|
|
|
|
|
elif orientation == 'right':
|
|
|
|
|
x, y = y, x
|
|
|
|
|
wacom_width, wacom_height = wacom_height, wacom_width
|
|
|
|
|
stylus_width, stylus_height = stylus_height, stylus_width
|
|
|
|
|
elif orientation == 'left':
|
|
|
|
|
x, y = wacom_height - y, wacom_width - x
|
|
|
|
|
wacom_width, wacom_height = wacom_height, wacom_width
|
|
|
|
|
x, y = stylus_height - y, stylus_width - x
|
|
|
|
|
stylus_width, stylus_height = stylus_height, stylus_width
|
|
|
|
|
|
|
|
|
|
ratio_width, ratio_height = monitor.width / wacom_width, monitor.height / wacom_height
|
|
|
|
|
ratio_width, ratio_height = monitor.width / stylus_width, monitor.height / stylus_height
|
|
|
|
|
scaling = ratio_width if ratio_width > ratio_height else ratio_height
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
scaling * (x - (wacom_width - monitor.width / scaling) / 2),
|
|
|
|
|
scaling * (y - (wacom_height - monitor.height / scaling) / 2)
|
|
|
|
|
scaling * (x - (stylus_width - monitor.width / scaling) / 2),
|
|
|
|
|
scaling * (y - (stylus_height - monitor.height / scaling) / 2)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -103,22 +108,22 @@ def read_tablet(args):
|
|
|
|
|
while True:
|
|
|
|
|
_, _, e_type, e_code, e_value = struct.unpack('2IHHi', stdout.read(16))
|
|
|
|
|
|
|
|
|
|
if e_type == EVTYPE_ABS:
|
|
|
|
|
if e_type == e_type_abs:
|
|
|
|
|
|
|
|
|
|
# handle x direction
|
|
|
|
|
if e_code == WACOM_EVCODE_YPOS:
|
|
|
|
|
if e_code == e_code_stylus_xpos:
|
|
|
|
|
log.debug(f'{e_value}')
|
|
|
|
|
x = e_value
|
|
|
|
|
new_x = True
|
|
|
|
|
|
|
|
|
|
# handle y direction
|
|
|
|
|
if e_code == WACOM_EVCODE_XPOS:
|
|
|
|
|
if e_code == e_code_stylus_ypos:
|
|
|
|
|
log.debug(f'\t{e_value}')
|
|
|
|
|
y = e_value
|
|
|
|
|
new_y = True
|
|
|
|
|
|
|
|
|
|
# handle draw
|
|
|
|
|
if e_code == WACOM_EVCODE_PRESSURE:
|
|
|
|
|
if e_code == e_code_stylus_pressure:
|
|
|
|
|
log.debug(f'\t\t{e_value}')
|
|
|
|
|
if e_value > args.threshold:
|
|
|
|
|
mouse.press(Button.left)
|
|
|
|
|
@ -127,10 +132,10 @@ def read_tablet(args):
|
|
|
|
|
|
|
|
|
|
# only move when x and y are updated for smoother mouse
|
|
|
|
|
if new_x and new_y:
|
|
|
|
|
x, y = fit(x, y, wacom_width, wacom_height, monitor, args.orientation)
|
|
|
|
|
mapped_x, mapped_y = fit(x, y, stylus_width, stylus_height, monitor, args.orientation)
|
|
|
|
|
mouse.move(
|
|
|
|
|
monitor.x + x - mouse.position[0],
|
|
|
|
|
monitor.y + y - mouse.position[1]
|
|
|
|
|
monitor.x + mapped_x - mouse.position[0],
|
|
|
|
|
monitor.y + mapped_y - mouse.position[1]
|
|
|
|
|
)
|
|
|
|
|
new_x = new_y = False
|
|
|
|
|
|
|
|
|
|
|