urirun-uinput 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: urirun-uinput
3
+ Version: 0.1.1
4
+ Summary: Linux uinput keyboard/mouse input surface primitive for urirun โ€” synthesize key/click/move events via /dev/uinput ioctls. Pure stdlib, no urirun dependency.
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # urirun-uinput
12
+
13
+
14
+ ## AI Cost Tracking
15
+
16
+ ![PyPI](https://img.shields.io/badge/pypi-costs-blue) ![Version](https://img.shields.io/badge/version-0.1.1-blue) ![Python](https://img.shields.io/badge/python-3.9+-blue) ![License](https://img.shields.io/badge/license-Apache--2.0-green)
17
+ ![AI Cost](https://img.shields.io/badge/AI%20Cost-$0.01-orange) ![Human Time](https://img.shields.io/badge/Human%20Time-4.6h-blue) ![Model](https://img.shields.io/badge/Model-openrouter%2Fqwen%2Fqwen3--coder--next-lightgrey)
18
+
19
+ - ๐Ÿค– **LLM usage:** $0.0132 (2 commits)
20
+ - ๐Ÿ‘ค **Human dev:** ~$459 (4.6h @ $100/h, 30min dedup)
21
+
22
+ Generated on 2026-07-05 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/qwen/qwen3-coder-next)
23
+
24
+ ---
25
+
26
+
27
+
28
+ The **Linux uinput keyboard/mouse input surface primitive** for urirun, extracted from
29
+ `urirun.connectors.inputs.uinput` as a standalone, dependency-free package.
30
+
31
+ It synthesizes real keyboard and pointer events by writing to `/dev/uinput` via ioctls โ€” the
32
+ input half of a desktop surface (the capture half is the KVM connector / mutter backend). Pure
33
+ stdlib (`fcntl`, `os`, `struct`, `time`) โ€” **no `urirun` dependency** โ€” so any connector can adopt
34
+ it without pulling in the backend.
35
+
36
+ ## Why it's its own package
37
+
38
+ `extraction_audit.py --preset E` reports the connectors toolkit (which this belongs to) GREEN, and
39
+ uinput itself pulls only stdlib. It is consumed by URI, swappable, and reusable across connectors โ€”
40
+ the same lift case as `urirun-cdp`. The KVM connector injects its own resolvers and adopts it.
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install -e . # editable, from this repo
46
+ ```
47
+
48
+ ## Back-compat
49
+
50
+ The old import path still works via a re-export shim in the urirun package:
51
+
52
+ ```python
53
+ from urirun.connectors.inputs import uinput # โ†’ urirun_uinput.uinput (sys.modules shim)
54
+ ```
55
+
56
+ So existing code and the `test_kernel_adoption` contract test (which guards the symbols the KVM
57
+ connector relies on) keep working unchanged. That contract test skips gracefully when this package
58
+ isn't installed, matching how the connector packages are tested in their own CI rather than urirun's.
59
+
60
+ ## Tests
61
+
62
+ ```bash
63
+ PYTHONPATH=../urirun/adapters/python python -m pytest tests/ -q
64
+ ```
65
+
66
+ The surface's own tests live here (`tests/test_uinput.py`); they exercise the event-encoding
67
+ primitives without a real `/dev/uinput` device.
68
+
69
+ ## License
70
+
71
+ Licensed under Apache-2.0.
@@ -0,0 +1,61 @@
1
+ # urirun-uinput
2
+
3
+
4
+ ## AI Cost Tracking
5
+
6
+ ![PyPI](https://img.shields.io/badge/pypi-costs-blue) ![Version](https://img.shields.io/badge/version-0.1.1-blue) ![Python](https://img.shields.io/badge/python-3.9+-blue) ![License](https://img.shields.io/badge/license-Apache--2.0-green)
7
+ ![AI Cost](https://img.shields.io/badge/AI%20Cost-$0.01-orange) ![Human Time](https://img.shields.io/badge/Human%20Time-4.6h-blue) ![Model](https://img.shields.io/badge/Model-openrouter%2Fqwen%2Fqwen3--coder--next-lightgrey)
8
+
9
+ - ๐Ÿค– **LLM usage:** $0.0132 (2 commits)
10
+ - ๐Ÿ‘ค **Human dev:** ~$459 (4.6h @ $100/h, 30min dedup)
11
+
12
+ Generated on 2026-07-05 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/qwen/qwen3-coder-next)
13
+
14
+ ---
15
+
16
+
17
+
18
+ The **Linux uinput keyboard/mouse input surface primitive** for urirun, extracted from
19
+ `urirun.connectors.inputs.uinput` as a standalone, dependency-free package.
20
+
21
+ It synthesizes real keyboard and pointer events by writing to `/dev/uinput` via ioctls โ€” the
22
+ input half of a desktop surface (the capture half is the KVM connector / mutter backend). Pure
23
+ stdlib (`fcntl`, `os`, `struct`, `time`) โ€” **no `urirun` dependency** โ€” so any connector can adopt
24
+ it without pulling in the backend.
25
+
26
+ ## Why it's its own package
27
+
28
+ `extraction_audit.py --preset E` reports the connectors toolkit (which this belongs to) GREEN, and
29
+ uinput itself pulls only stdlib. It is consumed by URI, swappable, and reusable across connectors โ€”
30
+ the same lift case as `urirun-cdp`. The KVM connector injects its own resolvers and adopts it.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install -e . # editable, from this repo
36
+ ```
37
+
38
+ ## Back-compat
39
+
40
+ The old import path still works via a re-export shim in the urirun package:
41
+
42
+ ```python
43
+ from urirun.connectors.inputs import uinput # โ†’ urirun_uinput.uinput (sys.modules shim)
44
+ ```
45
+
46
+ So existing code and the `test_kernel_adoption` contract test (which guards the symbols the KVM
47
+ connector relies on) keep working unchanged. That contract test skips gracefully when this package
48
+ isn't installed, matching how the connector packages are tested in their own CI rather than urirun's.
49
+
50
+ ## Tests
51
+
52
+ ```bash
53
+ PYTHONPATH=../urirun/adapters/python python -m pytest tests/ -q
54
+ ```
55
+
56
+ The surface's own tests live here (`tests/test_uinput.py`); they exercise the event-encoding
57
+ primitives without a real `/dev/uinput` device.
58
+
59
+ ## License
60
+
61
+ Licensed under Apache-2.0.
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "urirun-uinput"
7
+ version = "0.1.1"
8
+ description = "Linux uinput keyboard/mouse input surface primitive for urirun โ€” synthesize key/click/move events via /dev/uinput ioctls. Pure stdlib, no urirun dependency."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.9"
12
+ dependencies = []
13
+
14
+ [tool.setuptools.packages.find]
15
+ where = ["src"]
16
+
17
+ [tool.pfix]
18
+ # Self-healing Python configuration
19
+ model = "openrouter/qwen/qwen3-coder-next"
20
+ auto_apply = true
21
+ auto_install_deps = true
22
+ auto_restart = false
23
+ max_retries = 3
24
+ create_backups = false
25
+ git_auto_commit = false
26
+
27
+ [tool.pfix.runtime_todo]
28
+ enabled = true
29
+ todo_file = "TODO.md"
30
+ min_severity = "low"
31
+ deduplicate = true
32
+
33
+ [tool.costs]
34
+ # AI Cost tracking configuration
35
+ badge = true
36
+ update_readme = true
37
+ readme_path = "README.md"
38
+ default_model = "openrouter/qwen/qwen3-coder-next"
39
+ analysis_mode = "byok"
40
+ full_history = true
41
+ max_commits = 500
42
+
43
+ # Cost thresholds for badge colors (USD)
44
+ badge_color_thresholds = { low = 1.0, medium = 5.0, high = 10.0, critical = 50.0 }
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ """urirun-uinput โ€” the uinput keyboard/mouse surface primitive, extracted as a standalone (stdlib-only) package."""
2
+ from .uinput import * # noqa: F401,F403
@@ -0,0 +1,148 @@
1
+ # Author: Tom Sapletta ยท https://tom.sapletta.com
2
+ # Part of the ifURI solution.
3
+ #
4
+ # GENERIC pixel-accurate absolute pointer via a raw Linux /dev/uinput device โ€” the
5
+ # connector-agnostic core extracted from urirun-connector-kvm/backends.py.
6
+ #
7
+ # An ABSOLUTE (tablet-style) device bypasses pointer acceleration and maps [0,65535] linearly
8
+ # onto the desktop, so a click at fraction (x/sw, y/sh) of a screenshot lands at THAT pixel โ€”
9
+ # the fix for the Wayland hot-corner / capture-spaceโ‰ action-space bug (ydotool's mousemove -a
10
+ # mis-mapped raw pixels and trips the GNOME hot-corner). stdlib only; needs r/w on /dev/uinput.
11
+ #
12
+ # Connector-agnostic: the SCREEN SIZE (the space coords live in) and the optional CALIBRATION
13
+ # transform are supplied by the caller / injected via configure() โ€” this module never reads a
14
+ # connector's screen/calib env. Linux-only; on other OSes uinput_available() is False.
15
+ from __future__ import annotations
16
+
17
+ import fcntl as _fcntl
18
+ import os
19
+ import struct as _struct
20
+ import time
21
+ from typing import Callable
22
+
23
+ try:
24
+ from urirun.connectors.backend_registry import BackendError
25
+ except Exception: # pragma: no cover - allow flat use without the registry
26
+ class BackendError(RuntimeError): # type: ignore
27
+ pass
28
+
29
+ ABS_RANGE = 65535
30
+
31
+ _UI = ord("U")
32
+ def _ui_io(nr: int) -> int: return (0 << 30) | (_UI << 8) | nr
33
+ def _ui_iow(nr: int, sz: int) -> int: return (1 << 30) | (sz << 16) | (_UI << 8) | nr
34
+ _UI_DEV_CREATE, _UI_DEV_DESTROY = _ui_io(1), _ui_io(2)
35
+ _UI_SET_EVBIT, _UI_SET_KEYBIT, _UI_SET_ABSBIT = _ui_iow(100, 4), _ui_iow(101, 4), _ui_iow(103, 4)
36
+ _EV_SYN, _EV_KEY, _EV_ABS = 0, 1, 3
37
+ _ABS_X, _ABS_Y = 0, 1
38
+ _BTN_CODE = {"left": 0x110, "right": 0x111, "middle": 0x112}
39
+ _BTN_TOUCH = 0x14A
40
+
41
+ _CFG: dict[str, Callable] = {
42
+ "screen_size": lambda: (0, 0), # connector injects its capture-surface size resolver
43
+ "calib": lambda: None, # connector injects its calibration (ax,bx,ay,by) | None
44
+ }
45
+
46
+
47
+ def configure(*, screen_size: Callable[[], tuple] | None = None,
48
+ calib: Callable[[], tuple | None] | None = None) -> None:
49
+ """A connector wires its screen-size resolver (used when a caller omits sw/sh) and an optional
50
+ calibration provider here โ€” so the generic never reads kvm's URIRUN_KVM_SCREEN / _CALIB env."""
51
+ if screen_size is not None:
52
+ _CFG["screen_size"] = screen_size
53
+ if calib is not None:
54
+ _CFG["calib"] = calib
55
+
56
+
57
+ def calib_from_env(var: str = "URIRUN_ABS_CALIB") -> tuple | None:
58
+ """Parse ``ax,bx,ay,by`` from an env var into a calibration tuple, or None if unset/invalid.
59
+ Encodes ``landing_pixel = a*commanded + b`` per axis (fit by a host calibration pass)."""
60
+ try:
61
+ ax, bx, ay, by = (float(v) for v in os.environ.get(var, "").split(","))
62
+ return ax, bx, ay, by
63
+ except (ValueError, TypeError):
64
+ return None
65
+
66
+
67
+ def uinput_available() -> bool:
68
+ return os.path.exists("/dev/uinput") and os.access("/dev/uinput", os.W_OK)
69
+
70
+
71
+ def compute_abs(px: float, py: float, sw: int, sh: int, calib: tuple | None = None) -> tuple[int, int]:
72
+ """Map pixel (px,py) on a swร—sh surface to the uinput [0,ABS_RANGE] range. If ``calib`` is
73
+ given it INVERTS ``landing=a*commanded+b`` first, so the cursor LANDS at (px,py) on a
74
+ fractional-HiDPI / multi-region display. The pure-math heart of the coordinate fix."""
75
+ if calib:
76
+ ca_x, cb_x, ca_y, cb_y = calib
77
+ if ca_x:
78
+ px = (px - cb_x) / ca_x
79
+ if ca_y:
80
+ py = (py - cb_y) / ca_y
81
+ px = max(0.0, min(float(sw), px))
82
+ py = max(0.0, min(float(sh), py))
83
+ ax = max(0, min(ABS_RANGE, int(px / sw * ABS_RANGE) if sw else int(px)))
84
+ ay = max(0, min(ABS_RANGE, int(py / sh * ABS_RANGE) if sh else int(py)))
85
+ return ax, ay
86
+
87
+
88
+ def _create_abs() -> int:
89
+ fd = os.open("/dev/uinput", os.O_WRONLY | os.O_NONBLOCK)
90
+ for ev in (_EV_KEY, _EV_ABS, _EV_SYN):
91
+ _fcntl.ioctl(fd, _UI_SET_EVBIT, ev)
92
+ for b in (0x110, 0x111, 0x112, _BTN_TOUCH):
93
+ _fcntl.ioctl(fd, _UI_SET_KEYBIT, b)
94
+ _fcntl.ioctl(fd, _UI_SET_ABSBIT, _ABS_X)
95
+ _fcntl.ioctl(fd, _UI_SET_ABSBIT, _ABS_Y)
96
+ absmax = [0] * 64
97
+ absmax[_ABS_X] = absmax[_ABS_Y] = ABS_RANGE
98
+ dev = _struct.pack("<80s4HI", b"urirun-abs-pointer", 0x03, 0x1234, 0x5678, 1, 0)
99
+ dev += _struct.pack("<64i", *absmax) + _struct.pack("<192i", *([0] * 192))
100
+ os.write(fd, dev)
101
+ _fcntl.ioctl(fd, _UI_DEV_CREATE)
102
+ return fd
103
+
104
+
105
+ def _emit_clicks(ev: Callable, fd: int, button: str, clicks: int) -> None:
106
+ """Emit ``clicks`` press/release pairs on the open uinput ``fd`` โ€” N presses on ONE device
107
+ is a real double/triple-click."""
108
+ bc = _BTN_CODE.get(button, 0x110)
109
+ for _i in range(max(1, int(clicks))):
110
+ ev(fd, _EV_KEY, bc, 1); ev(fd, _EV_KEY, _BTN_TOUCH, 1); ev(fd, _EV_SYN, 0, 0)
111
+ time.sleep(0.06)
112
+ ev(fd, _EV_KEY, bc, 0); ev(fd, _EV_KEY, _BTN_TOUCH, 0); ev(fd, _EV_SYN, 0, 0)
113
+ time.sleep(0.06)
114
+
115
+
116
+ def abs_click(x: int, y: int, sw: int = 0, sh: int = 0, *, button: str = "left",
117
+ do_click: bool = True, settle: float = 0.9, clicks: int = 1,
118
+ calib: tuple | None = None) -> dict:
119
+ """Position (and optionally click) at pixel (x,y) via a fresh raw absolute uinput device.
120
+ ``sw``/``sh`` default to the injected screen-size resolver; ``calib`` to the injected one.
121
+ Coordinate-exact: what a screenshot shows at (x,y) is where the click lands."""
122
+ if not uinput_available():
123
+ raise BackendError("no write access to /dev/uinput (add user to 'input' group or a udev rule)")
124
+ if not sw or not sh:
125
+ dsw, dsh = _CFG["screen_size"]()
126
+ sw, sh = sw or dsw, sh or dsh
127
+ if calib is None:
128
+ calib = _CFG["calib"]()
129
+ ax, ay = compute_abs(float(x), float(y), sw, sh, calib)
130
+
131
+ def ev(fd: int, t: int, c: int, v: int) -> None:
132
+ os.write(fd, _struct.pack("llHHi", 0, 0, t, c, v))
133
+ fd = _create_abs()
134
+ try:
135
+ time.sleep(float(settle)) # compositor discovers + maps the new device
136
+ ev(fd, _EV_ABS, _ABS_X, ax); ev(fd, _EV_ABS, _ABS_Y, ay); ev(fd, _EV_SYN, 0, 0)
137
+ time.sleep(0.25)
138
+ if do_click:
139
+ _emit_clicks(ev, fd, button, clicks)
140
+ time.sleep(0.2)
141
+ return {"via": "uinput-absolute", "abs": [ax, ay], "pixel": [x, y],
142
+ "clicked": bool(do_click), "clicks": int(clicks) if do_click else 0}
143
+ finally:
144
+ try:
145
+ _fcntl.ioctl(fd, _UI_DEV_DESTROY)
146
+ except Exception: # noqa: BLE001
147
+ pass
148
+ os.close(fd)
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: urirun-uinput
3
+ Version: 0.1.1
4
+ Summary: Linux uinput keyboard/mouse input surface primitive for urirun โ€” synthesize key/click/move events via /dev/uinput ioctls. Pure stdlib, no urirun dependency.
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # urirun-uinput
12
+
13
+
14
+ ## AI Cost Tracking
15
+
16
+ ![PyPI](https://img.shields.io/badge/pypi-costs-blue) ![Version](https://img.shields.io/badge/version-0.1.1-blue) ![Python](https://img.shields.io/badge/python-3.9+-blue) ![License](https://img.shields.io/badge/license-Apache--2.0-green)
17
+ ![AI Cost](https://img.shields.io/badge/AI%20Cost-$0.01-orange) ![Human Time](https://img.shields.io/badge/Human%20Time-4.6h-blue) ![Model](https://img.shields.io/badge/Model-openrouter%2Fqwen%2Fqwen3--coder--next-lightgrey)
18
+
19
+ - ๐Ÿค– **LLM usage:** $0.0132 (2 commits)
20
+ - ๐Ÿ‘ค **Human dev:** ~$459 (4.6h @ $100/h, 30min dedup)
21
+
22
+ Generated on 2026-07-05 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/qwen/qwen3-coder-next)
23
+
24
+ ---
25
+
26
+
27
+
28
+ The **Linux uinput keyboard/mouse input surface primitive** for urirun, extracted from
29
+ `urirun.connectors.inputs.uinput` as a standalone, dependency-free package.
30
+
31
+ It synthesizes real keyboard and pointer events by writing to `/dev/uinput` via ioctls โ€” the
32
+ input half of a desktop surface (the capture half is the KVM connector / mutter backend). Pure
33
+ stdlib (`fcntl`, `os`, `struct`, `time`) โ€” **no `urirun` dependency** โ€” so any connector can adopt
34
+ it without pulling in the backend.
35
+
36
+ ## Why it's its own package
37
+
38
+ `extraction_audit.py --preset E` reports the connectors toolkit (which this belongs to) GREEN, and
39
+ uinput itself pulls only stdlib. It is consumed by URI, swappable, and reusable across connectors โ€”
40
+ the same lift case as `urirun-cdp`. The KVM connector injects its own resolvers and adopts it.
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install -e . # editable, from this repo
46
+ ```
47
+
48
+ ## Back-compat
49
+
50
+ The old import path still works via a re-export shim in the urirun package:
51
+
52
+ ```python
53
+ from urirun.connectors.inputs import uinput # โ†’ urirun_uinput.uinput (sys.modules shim)
54
+ ```
55
+
56
+ So existing code and the `test_kernel_adoption` contract test (which guards the symbols the KVM
57
+ connector relies on) keep working unchanged. That contract test skips gracefully when this package
58
+ isn't installed, matching how the connector packages are tested in their own CI rather than urirun's.
59
+
60
+ ## Tests
61
+
62
+ ```bash
63
+ PYTHONPATH=../urirun/adapters/python python -m pytest tests/ -q
64
+ ```
65
+
66
+ The surface's own tests live here (`tests/test_uinput.py`); they exercise the event-encoding
67
+ primitives without a real `/dev/uinput` device.
68
+
69
+ ## License
70
+
71
+ Licensed under Apache-2.0.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/urirun_uinput/__init__.py
5
+ src/urirun_uinput/uinput.py
6
+ src/urirun_uinput.egg-info/PKG-INFO
7
+ src/urirun_uinput.egg-info/SOURCES.txt
8
+ src/urirun_uinput.egg-info/dependency_links.txt
9
+ src/urirun_uinput.egg-info/top_level.txt
10
+ tests/test_uinput.py
@@ -0,0 +1 @@
1
+ urirun_uinput
@@ -0,0 +1,69 @@
1
+ # Author: Tom Sapletta ยท https://tom.sapletta.com
2
+ # The generic absolute-uinput pointer (urirun.connectors.inputs.uinput). The coordinate math is
3
+ # the heart of the Wayland hot-corner fix: a raw pixel must be SCALED into the [0,65535] ABS
4
+ # range, else the cursor lands near (0,0) and trips Activities. Tested without /dev/uinput.
5
+ from __future__ import annotations
6
+
7
+ import struct
8
+
9
+ import pytest
10
+
11
+ from urirun_uinput import uinput as U
12
+
13
+
14
+ def test_compute_abs_scales_pixel_into_abs_range():
15
+ # the bug it fixes: raw pixel 720 must NOT stay 720 (โ‰ˆ11px once mapped) โ€” it must become the
16
+ # ABS midpoint so the click lands at the screen centre, not the hot-corner.
17
+ assert U.compute_abs(0, 0, 1440, 900) == (0, 0)
18
+ assert U.compute_abs(1440, 900, 1440, 900) == (U.ABS_RANGE, U.ABS_RANGE)
19
+ ax, ay = U.compute_abs(720, 450, 1440, 900)
20
+ assert abs(ax - U.ABS_RANGE // 2) <= 1 and abs(ay - U.ABS_RANGE // 2) <= 1 # centre
21
+ assert ax != 720, "raw pixel must be scaled, not passed through (the hot-corner bug)"
22
+
23
+
24
+ def test_compute_abs_inverts_calibration():
25
+ # landing = 1.0*commanded + 100 (a 100px offset). To LAND at pixel 600 we must COMMAND 500.
26
+ calib = (1.0, 100.0, 1.0, 0.0)
27
+ ax, _ = U.compute_abs(600, 0, 1000, 1000, calib)
28
+ assert ax == int(500 / 1000 * U.ABS_RANGE) # commanded 500, then scaled
29
+
30
+
31
+ def test_compute_abs_zero_screen_passes_through():
32
+ # unknown screen size -> treat coords as already absolute (no division by zero)
33
+ assert U.compute_abs(123, 456, 0, 0) == (123, 456)
34
+
35
+
36
+ def test_calib_from_env(monkeypatch):
37
+ monkeypatch.setenv("URIRUN_ABS_CALIB", "1.1,2.2,3.3,4.4")
38
+ assert U.calib_from_env() == (1.1, 2.2, 3.3, 4.4)
39
+ monkeypatch.setenv("URIRUN_ABS_CALIB", "garbage")
40
+ assert U.calib_from_env() is None
41
+
42
+
43
+ def test_abs_click_raises_cleanly_without_uinput(monkeypatch):
44
+ monkeypatch.setattr(U, "uinput_available", lambda: False)
45
+ with pytest.raises(U.BackendError) as ei:
46
+ U.abs_click(10, 10, 1000, 1000)
47
+ assert "/dev/uinput" in str(ei.value)
48
+
49
+
50
+ def test_configure_injects_screen_size_resolver(monkeypatch):
51
+ seen = {}
52
+ monkeypatch.setattr(U, "uinput_available", lambda: True)
53
+ monkeypatch.setattr(U, "_create_abs", lambda: 7)
54
+ monkeypatch.setattr(U._fcntl, "ioctl", lambda *a: 0)
55
+ monkeypatch.setattr(U.os, "close", lambda fd: None)
56
+ monkeypatch.setattr(U.time, "sleep", lambda s: None)
57
+
58
+ def fake_write(fd, data):
59
+ t, c, v = struct.unpack("llHHi", data)[2:]
60
+ if t == U._EV_ABS:
61
+ seen[c] = v
62
+ monkeypatch.setattr(U.os, "write", fake_write)
63
+ try:
64
+ U.configure(screen_size=lambda: (1000, 1000)) # injected, used because sw/sh omitted
65
+ r = U.abs_click(500, 500, do_click=False, settle=0) # no sw/sh -> resolver gives 1000ร—1000
66
+ assert r["abs"] == [U.ABS_RANGE // 2, U.ABS_RANGE // 2] # centre, via injected size
67
+ assert seen[U._ABS_X] == U.ABS_RANGE // 2 # the ABS_X event carried it
68
+ finally:
69
+ U.configure(screen_size=lambda: (0, 0))