Skip to content

Commit 059d341

Browse files
committed
add touchpad support
1 parent 133d5a7 commit 059d341

File tree

9 files changed

+64
-16
lines changed

9 files changed

+64
-16
lines changed

src/hhd/contrib/dev.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def B(b: str):
1313
def RV(type: int, code: int):
1414
if (type, code) not in cache:
1515
v = ecodes.bytype[type][code]
16-
if isinstance(v, list):
16+
if isinstance(v, list) or isinstance(v, tuple):
1717
v = v[0]
1818
cache[(type, code)] = v
1919
else:

src/hhd/controller/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class TouchpadCorrection(NamedTuple):
325325
"left",
326326
"right",
327327
"center",
328+
"legos",
328329
"disabled",
329330
]
330331

@@ -354,7 +355,7 @@ def correct_touchpad(
354355
y_mult=new_height,
355356
y_ofs=(height - new_height),
356357
)
357-
case "right":
358+
case "right" | "legos":
358359
if ratio > 2:
359360
new_width = width / ratio
360361
return TouchpadCorrection(
@@ -474,6 +475,8 @@ def correct_touchpad(
474475
)
475476
case "stretch" | "disabled":
476477
return TouchpadCorrection(x_mult=width, y_mult=height)
478+
# case "legos":
479+
# return TouchpadCorrection(x_mult=800, y_mult=800, x_ofs=1055, y_ofs=140)
477480

478481
logger.error(f"Touchpad correction method '{method}' not found.")
479482
return TouchpadCorrection(x_mult=width, y_mult=height)

src/hhd/controller/physical/evdev.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,12 @@ def open(self) -> Sequence[int]:
282282
if cap_id not in dev_cap:
283283
matches = False
284284
break
285+
if cap_id != B("EV_ABS"):
286+
dev_caps = dev_cap[cap_id]
287+
else:
288+
dev_caps = [c[0] for c in dev_cap[cap_id]] # type: ignore
285289
for cap in caps:
286-
if cap not in dev_cap[cap_id]:
290+
if cap not in dev_caps:
287291
matches = False
288292
break
289293
if not matches:

src/hhd/device/legion_go/slim/base.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
GOS_INTERFACE_AXIS_MAP,
1818
GOS_INTERFACE_BTN_ESSENTIALS,
1919
GOS_INTERFACE_BTN_MAP,
20+
GOS_TOUCHPAD_BUTTON_MAP,
21+
GOS_TOUCHPAD_AXIS_MAP,
2022
)
2123
from .hid import LegionHidraw, LegionHidrawTs, rgb_callback
2224

25+
2326
FIND_DELAY = 0.1
2427
ERROR_DELAY = 0.5
2528
LONGER_ERROR_DELAY = 3
@@ -224,12 +227,13 @@ def controller_loop_xinput(
224227
debug = DEBUG_MODE
225228

226229
# Output
227-
230+
touchpad_enable = conf.get("touchpad", "disabled")
228231
d_producers, d_outs, d_params = get_outputs(
229232
conf["xinput"],
230233
None,
231234
conf["imu"].to(bool),
232235
emit=emit,
236+
touchpad_enable=touchpad_enable, # type: ignore
233237
rgb_modes={
234238
"disabled": [],
235239
"solid": ["color"],
@@ -263,6 +267,20 @@ def controller_loop_xinput(
263267
)
264268
)
265269

270+
uses_touch = d_params.get("uses_touch", False)
271+
d_touch = GenericGamepadEvdev(
272+
vid=[GOS_VID],
273+
pid=list(GOS_PIDS),
274+
capabilities={
275+
EC("EV_KEY"): [EC("BTN_LEFT")],
276+
EC("EV_ABS"): [EC("ABS_MT_POSITION_Y")],
277+
},
278+
btn_map=GOS_TOUCHPAD_BUTTON_MAP,
279+
axis_map=GOS_TOUCHPAD_AXIS_MAP,
280+
aspect_ratio=1,
281+
required=True,
282+
)
283+
266284
freq = conf.get("freq", None)
267285
os = conf.get("mapping.mode", None)
268286
d_cfg = LegionHidraw(
@@ -279,6 +297,7 @@ def controller_loop_xinput(
279297
os=os,
280298
turbo=conf.get("mapping.windows.turbo", None) if os == "windows" else None,
281299
freq=freq,
300+
touchpad="absolute" if uses_touch else "relative",
282301
)
283302

284303
# Mute keyboard shortcuts, mute
@@ -322,6 +341,8 @@ def prepare(m):
322341
try:
323342
prepare(d_xinput)
324343
prepare(d_shortcuts)
344+
if uses_touch:
345+
prepare(d_touch)
325346
prepare(d_cfg)
326347
prepare(d_raw)
327348
for d in d_producers:

src/hhd/device/legion_go/slim/const.py

+14
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@
5858
"gyro_z": AM(22 << 3, "i16", scale=0.0005325, order="little"),
5959
"gyro_y": AM(24 << 3, "i16", scale=-0.0005325, order="little"),
6060
}
61+
62+
GOS_TOUCHPAD_BUTTON_MAP: dict[int, Button] = to_map(
63+
{
64+
"touchpad_touch": [B("BTN_TOOL_FINGER")], # also BTN_TOUCH
65+
"touchpad_left": [B("BTN_LEFT")],
66+
}
67+
)
68+
69+
GOS_TOUCHPAD_AXIS_MAP: dict[int, Axis] = to_map(
70+
{
71+
"touchpad_x": [B("ABS_X")], # also ABS_MT_POSITION_X
72+
"touchpad_y": [B("ABS_Y")], # also ABS_MT_POSITION_Y
73+
}
74+
)

src/hhd/device/legion_go/slim/controller.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ children:
5757
hint: >-
5858
SteamOS style mapping.
5959
60-
# touchpad:
61-
# type: multiple
62-
# title: Touchpad Emulation
63-
# default: disabled
64-
# tags: [ non-essential, ordinal ]
65-
# hint: >-
66-
# Passthrough the touchpad to the controller (Dualsense only).
67-
# options:
68-
# disabled: Disabled
69-
# gamemode: Gamemode
70-
# always: Always
60+
touchpad:
61+
type: multiple
62+
title: Touchpad Emulation
63+
default: disabled
64+
tags: [ non-essential, ordinal ]
65+
hint: >-
66+
Passthrough the touchpad to the controller (Dualsense only).
67+
options:
68+
disabled: Disabled
69+
gamemode: Gamemode
70+
always: Always
7171

7272
freq:
7373
type: multiple

src/hhd/device/legion_go/slim/hid.py

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def open(self):
283283
cmds.extend(config_device(self.os, self.turbo, self.touchpad, self.freq)) # type: ignore
284284

285285
for r in cmds:
286+
# logger.info(f"Sending command: {r.hex()}")
286287
self.dev.write(r)
287288

288289
return out

src/hhd/plugins/outputs.py

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_outputs(
3838
rgb_modes: Mapping[RgbMode, Sequence[RgbSettings]] | None = None,
3939
rgb_zones: RgbZones = "mono",
4040
controller_disabled: bool = False,
41+
touchpad_enable: Literal["disabled", "gamemode", "always"] | None = None,
4142
) -> tuple[Sequence[Producer], Sequence[Consumer], Mapping[str, Any]]:
4243
producers = []
4344
consumers = []
@@ -50,6 +51,10 @@ def get_outputs(
5051
correction = touch_conf["controller.correction"].to(TouchpadCorrectionType)
5152
if touchpad in ("emulation", "controller"):
5253
desktop_disable = touch_conf[touchpad]["desktop_disable"].to(bool)
54+
elif touchpad_enable:
55+
touchpad = "disabled" if touchpad_enable == "disabled" else "controller"
56+
correction = "legos" # todo: make generic
57+
desktop_disable = touchpad_enable == "gamemode"
5358
else:
5459
touchpad = "controller"
5560
correction = "stretch"

sync.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fi
55

66
HOST=$1
77
RSYNC="rsync -rv --exclude .git --exclude venv --exclude __pycache__'"
8-
USER=${USER:-bazzite}
8+
USER=${2:-bazzite}
99

1010
# python -m venv --system-site-packages ~/hhd-dev/hhd/venv
1111
# ~/hhd-dev/hhd/venv/bin/pip install -e ~/hhd-dev/adjustor

0 commit comments

Comments
 (0)