-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add extended mouse forwarding #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f1271f6
Forward extra mouse buttons
s117 8d9a5fe
Forward mouse pan using the extended report format
s117 102c15b
feat: finalize extended mouse forwarding
quaxalber 5844755
fix: avoid empty mouse interrupt packets
quaxalber a194cd0
docs: explain mouse report length padding
quaxalber 29bbfe7
docs: clarify mouse report length workaround
quaxalber 5382d8c
refactor: share extended mouse button constants
quaxalber dc927f5
refactor: remove redundant mouse button type cache
quaxalber ccc095a
fix: address extended mouse review findings
quaxalber 1a34b36
refactor: remove unused mouse relay wrapper
quaxalber 0f3e2e6
style: keep AC Pan HID item grouped
quaxalber b40a8d6
fix: handle Windows raw mouse buttons
quaxalber 2da9114
fix: dedupe high-res horizontal wheel events
quaxalber 39b0e72
feat: support high-resolution vertical wheel
quaxalber 90a6c9a
test: add fast mouse loopback harness
quaxalber d167337
docs: require PR head install for Pi validation
quaxalber 5ae5995
docs: clarify rsynced Pi validation installs
quaxalber 6e39e52
docs: defer rsync validation workflow
quaxalber aa6212d
fix: keep fast mouse harness steps distinct
quaxalber fbabb40
feat: advertise high-resolution mouse scrolling
quaxalber 985b467
test: limit default mouse button presses
quaxalber b8113f6
docs: mark intrusive loopback scenario opt-in
quaxalber fdb0275
fix: handle combined chunked mouse reports
quaxalber 014c70e
test: log mouse gadget movement reports
quaxalber a11a4b7
test: log normalized mouse rel inputs
quaxalber f578110
fix: address mouse harness review findings
quaxalber f23258c
fix: preserve raw input mouse packet ordering
quaxalber 97c8ff8
fix: align hi-res mouse contracts
quaxalber 6b75854
fix: accept compact unnumbered mouse pan reports
quaxalber f404b35
fix: keep mouse harness reports canonical
quaxalber eac464c
fix: validate mouse button state on motion reports
quaxalber 93a670d
fix: document mouse descriptor bounds in windows capture
quaxalber 84d00d5
test: harden harness review tests
quaxalber ff3b104
style: indent HID descriptor hierarchy
quaxalber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from __future__ import annotations | ||
|
|
||
|
|
||
| def _clamp_hid_i8(value: int) -> int: | ||
| return min(127, max(-127, value)) | ||
|
|
||
|
|
||
| def _clamp_hid_i16(value: int) -> int: | ||
| return min(32767, max(-32767, value)) | ||
|
|
||
|
|
||
| class ExtendedMouse: | ||
| """Small mouse report writer with horizontal pan support.""" | ||
|
|
||
| LEFT = LEFT_BUTTON = 0x01 | ||
| RIGHT = RIGHT_BUTTON = 0x02 | ||
| MIDDLE = MIDDLE_BUTTON = 0x04 | ||
| SIDE = SIDE_BUTTON = 0x08 | ||
| EXTRA = EXTRA_BUTTON = 0x10 | ||
| FORWARD = FORWARD_BUTTON = 0x20 | ||
| BACK = BACK_BUTTON = 0x40 | ||
| TASK = TASK_BUTTON = 0x80 | ||
|
|
||
| def __init__(self, devices) -> None: | ||
| from adafruit_hid import find_device | ||
|
|
||
| self._mouse_device = find_device(devices, usage_page=0x1, usage=0x02) | ||
| if not self._mouse_device: | ||
| raise ValueError("Could not find matching mouse HID device.") | ||
| self.report = bytearray(7) | ||
| self._pan_remainder = 0.0 | ||
|
|
||
| def __str__(self): | ||
| return str(self._mouse_device) | ||
|
|
||
| def press(self, buttons: int) -> None: | ||
| self.report[0] |= buttons | ||
| self._send_no_move() | ||
|
|
||
| def release(self, buttons: int) -> None: | ||
| self.report[0] &= ~buttons | ||
| self._send_no_move() | ||
|
|
||
| def release_all(self) -> None: | ||
| self.report[0] = 0 | ||
| self._send_no_move() | ||
|
|
||
| def move(self, x: int = 0, y: int = 0, wheel: int = 0, pan: float = 0) -> None: | ||
| pan_total = self._pan_remainder + pan | ||
| pan = int(pan_total) | ||
| self._pan_remainder = pan_total - pan | ||
| while x != 0 or y != 0 or wheel != 0 or pan != 0: | ||
| partial_x = _clamp_hid_i16(x) | ||
| partial_y = _clamp_hid_i16(y) | ||
| partial_wheel = _clamp_hid_i8(wheel) | ||
| partial_pan = _clamp_hid_i8(pan) | ||
| self.report[1:3] = partial_x.to_bytes(2, "little", signed=True) | ||
| self.report[3:5] = partial_y.to_bytes(2, "little", signed=True) | ||
| self.report[5] = partial_wheel & 0xFF | ||
| self.report[6] = partial_pan & 0xFF | ||
| self._mouse_device.send_report(self.report) | ||
| x -= partial_x | ||
| y -= partial_y | ||
| wheel -= partial_wheel | ||
| pan -= partial_pan | ||
|
|
||
| def _send_no_move(self) -> None: | ||
| self.report[1:7] = b"\x00" * 6 | ||
| self._mouse_device.send_report(self.report) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.