One keyboard and mouse for a Mac and a Windows PC over the local network, in either direction.
Beamer 1.3.1
Toby Kalkman289aba1952df
diff --git a/VERSION b/VERSIONindex f0bb29e..3a3cd8c 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-1.3.0+1.3.1diff --git a/assets/social-preview.png b/assets/social-preview.pngnew file mode 100644index 0000000..1048d75Binary files /dev/null and b/assets/social-preview.png differdiff --git a/mac_app/bridge.py b/mac_app/bridge.pyindex 4ea3170..80b537b 100644--- a/mac_app/bridge.py+++ b/mac_app/bridge.py@@ -15,6 +15,7 @@ import Quartzimport clipboard_macimport crossing+import desktop_macfrom input_injector_mac import INJECTED_MARKimport gesturesimport ignored@@ -48,6 +49,7 @@ SSH_FALLBACK_HOST = "127.0.0.1"SSH_FALLBACK_PORT = 24822PING_INTERVAL_SECONDS = 1.0DESKTOP_BOUNDS_MAX_AGE_SECONDS = 1.0+CROSSING_RETRY_SECONDS = 30.0ROUND_TRIP_SAMPLES = 8ROUND_TRIP_MAX_AGE_SECONDS = 5.0# A receiver that accepts the TCP connection but never sends a preamble is, in practice, one@@ -128,6 +130,7 @@ NX_DEVICE_MODIFIER_BITS = {0x3D: 0x0040,0x3E: 0x2000,}+CAPS_LOCK_KEY_CODE = 0x39# Command, Option and Control, left and right. Shift and caps lock are# excluded on purpose -- see _unicode_character.CHORD_MODIFIER_KEY_CODES = frozenset({0x36, 0x37, 0x3A, 0x3B, 0x3D, 0x3E})@@ -541,6 +544,7 @@ class KVMController:self.notch_range = Noneself.on_crossing = Noneself._crossing_failed = False+ self._crossing_failed_at = 0.0self._bounds_cache = Noneself._bounds_at = 0.0# Both hold the pointer methods off while the shortcut keeps working. Paused is the@@ -959,6 +963,16 @@ class KVMController:result = self.translator.key_result(event_type, event, self.trigger_code, self.cfg.key_map)if result.is_trigger:return self._handle_trigger(result, event)+ # And this Mac's own pointer, which can push through the edge to take it back+ # across; the PC's events carry the injected mark and never reach the edge. Its+ # clicks go the same way, since a click is what resets a push.+ if (+ event_type not in (self.quartz.kCGEventKeyDown, self.quartz.kCGEventKeyUp, self.quartz.kCGEventFlagsChanged)+ and event_type != media_keys.NX_SYSDEFINED_EVENT_TYPE+ and not self.gesture_translator.wants(event_type)+ and not self._was_injected(event)+ ):+ return self._handle_local_mouse(event_type, event)return eventif self.gesture_translator.wants(event_type):return self._handle_gesture_event(event_type, event)@@ -984,7 +998,14 @@ class KVMController:return self._handle_trigger(result, event)if self.redirecting:keycode = self.quartz.CGEventGetIntegerValueField(event, self.quartz.kCGKeyboardEventKeycode)- if self.ignore_gate.keeps(ignored.key(keycode), result.is_down):+ entry = ignored.key(keycode)+ kept = self.ignore_gate.keeps(entry, result.is_down)+ if keycode == CAPS_LOCK_KEY_CODE:+ # One event per toggle, always read as down and sent as a press and its+ # release, so it is a whole press to the gate too: a lone down would pin+ # its route until input came home, whatever the list said by then.+ self.ignore_gate.keeps(entry, False)+ if kept:return eventmessages = result.messageselse:@@ -994,6 +1015,10 @@ class KVMController:if button is not None and self.ignore_gate.keeps(ignored.button(button[0]), button[1]):return eventmessages = self.translator.mouse_messages(event_type, event)+ if button is not None and not messages:+ # A button the wire has no name for stays on this Mac, as one does on the PC,+ # rather than being swallowed and reaching neither.+ return eventif not self.redirecting:return eventfor message in messages:@@ -1031,10 +1056,14 @@ class KVMController:warped back to where the push began, which is the resistance; atbreakthrough input moves to Windows. Everything else passes through.Fails open twice over: the caller's handler already returns the event- on any exception, and a failure here also switches crossing off until- the next settings save, so one broken geometry call cannot log an- exception per mouse move."""- if self._crossing_failed or not self.crossing.armed:+ on any exception, and a failure here also switches crossing off for+ CROSSING_RETRY_SECONDS or until the next settings save, so one broken+ geometry call cannot log an exception per mouse move -- and a passing+ one cannot leave the edge dead until someone thinks to save a setting."""+ if self._crossing_failed and self.clock() - self._crossing_failed_at < CROSSING_RETRY_SECONDS:+ return event+ self._crossing_failed = False+ if not self.crossing.armed:return eventif self.crossing_paused or self.full_screen_app is not None or not self.cfg.send_to_windows:return event@@ -1061,10 +1090,21 @@ class KVMController:)except Exception:self._crossing_failed = True+ self._crossing_failed_at = self.clock()self.crossing.reset()- self.logger.exception("crossing failed; edge switching is off until settings are saved again")+ self.logger.exception("crossing failed; edge switching is off for %.0fs", CROSSING_RETRY_SECONDS)return eventif step.crossed:+ if self.receiving:+ # The PC is driving this Mac and this Mac's own pointer pushed through: the PC's+ # input goes home first, over its own link, and this Mac's follows it across. The+ # PC's focus home clears receiving here too, later, and finds it already clear.+ # The Mac half of the PC's own push back (27-09-2026).+ send_home = self.send_peer_home+ if send_home is None or not send_home():+ self.logger.warning("cannot cross: Windows is driving this Mac and cannot be reached")+ return event+ self.receiving = Falseif self.set_redirecting(True, edge=step.edge, offset=step.offset):self._notify_crossing("cross", step)return None@@ -1086,12 +1126,9 @@ class KVMController:def _default_desktop_bounds(self):quartz = self.quartz- error, displays, count = quartz.CGGetActiveDisplayList(16, None, None)- if error != 0 or not count:- raise RuntimeError(f"CGGetActiveDisplayList failed: {error}")left = top = float("inf")right = bottom = float("-inf")- for display in list(displays)[:count]:+ for display in desktop_mac.display_ids(quartz):rect = quartz.CGDisplayBounds(display)left = min(left, rect.origin.x)top = min(top, rect.origin.y)diff --git a/mac_app/build_dmg.sh b/mac_app/build_dmg.shindex 7c68bcc..7bc49d9 100755--- a/mac_app/build_dmg.sh+++ b/mac_app/build_dmg.sh@@ -82,6 +82,35 @@ for archive in "$APP"/Contents/Resources/lib/python3*.zip; dozip -q -d "$archive" '*.dSYM/*' || [ $? -eq 12 ]done+# The packages py2app copies whole (rumps, cryptography, cffi, setuptools) arrive with the+# __pycache__ pip compiled at install time, whose code objects name the venv's path on this Mac, and+# py2app writes the building python's path into Info.plist. 1.3.0 shipped both (27-09-2026). The+# caches go, inside the zip too, where zipimport never reads a __pycache__ anyway; the loose packages+# are compiled again under a relative name, since the app never writes bytecode into its own bundle.+find "$APP" -name __pycache__ -type d -prune -exec rm -rf {} ++for archive in "$APP"/Contents/Resources/lib/python3*.zip; do+ zip -q -d "$archive" '*/__pycache__/*' || [ $? -eq 12 ]+done+for packages in "$APP"/Contents/Resources/lib/python3.*/; do+ .venv/bin/python3 -m compileall -q -d "lib/$(basename "$packages")" "$packages" >/dev/null+done+/usr/libexec/PlistBuddy -c 'Delete :PythonInfoDict:PythonExecutable' "$APP/Contents/Info.plist"+# Anything still naming this Mac's home folder, in a file or inside the zipped stdlib, stops the build.+.venv/bin/python3 - "$APP" "$HOME" <<'EOF'+import pathlib, sys, zipfile+app, home = pathlib.Path(sys.argv[1]), sys.argv[2].encode()+found = []+for path in app.rglob("*"):+ if path.is_file() and not path.is_symlink():+ if home in path.read_bytes():+ found.append(str(path.relative_to(app)))+ if path.suffix == ".zip":+ with zipfile.ZipFile(path) as archive:+ found += [f"{path.name}:{name}" for name in archive.namelist() if home in archive.read(name)]+if found:+ sys.exit(f"{len(found)} files in the app name {home.decode()}, first {found[:5]}")+EOF+# Every build runs under the hardened runtime, so a local build breaks the way a notarised one would.# Only a release takes a secure timestamp: notarisation requires it, and it needs Apple's server.if [ "$RELEASE" -eq 1 ]; then TIMESTAMP="--timestamp"; else TIMESTAMP="--timestamp=none"; fidiff --git a/mac_app/desktop_mac.py b/mac_app/desktop_mac.pyindex db51e11..c09fbda 100644--- a/mac_app/desktop_mac.py+++ b/mac_app/desktop_mac.py@@ -29,13 +29,25 @@ def _require():return Quartz+def display_ids(quartz=None) -> list:+ """The displays that make up the desktop: the active list, unless it is empty. It is empty+ while the displays sleep, and a sleeping display is still where it was, so the online list+ stands in (27-09-2026: with the Mac's display asleep, the PC's pointer arriving and this Mac's+ own push both failed on the empty list, and each turned its crossing off)."""+ quartz = quartz or _require()+ error, ids, count = quartz.CGGetActiveDisplayList(MAX_DISPLAYS, None, None)+ if error == 0 and count:+ return list(ids)[:count]+ error, ids, count = quartz.CGGetOnlineDisplayList(MAX_DISPLAYS, None, None)+ if error != 0 or not count:+ raise RuntimeError(f"no display to measure: CGGetOnlineDisplayList returned {error}")+ return list(ids)[:count]++def monitors() -> List[Rect]:quartz = _require()- error, display_ids, _count = quartz.CGGetActiveDisplayList(MAX_DISPLAYS, None, None)- if error:- raise RuntimeError(f"CGGetActiveDisplayList failed with error {error}")found: List[Rect] = []- for display_id in display_ids:+ for display_id in display_ids(quartz):bounds = quartz.CGDisplayBounds(display_id)found.append(Rect(diff --git a/mac_app/ignored_titles.py b/mac_app/ignored_titles.pyindex 859c586..fb97acd 100644--- a/mac_app/ignored_titles.py+++ b/mac_app/ignored_titles.py@@ -4,7 +4,7 @@ out of the AppKit recorder in widgets.py so both are testable without it.import ignoredimport media_keys-from bridge import WIRE_OTHER_BUTTONS+from bridge import NX_DEVICE_MODIFIER_BITS, WIRE_OTHER_BUTTONSfrom key_codes import PRINTABLE_KEY_FALLBACKS, SPECIAL_KEY_NAMES, key_titleBUTTON_TITLES = {@@ -41,6 +41,26 @@ def entry_title(entry):return entry+# Shift, Control, Option and Command, left and right, to the flag their family sets: the same+# numbers in NSEvent's modifierFlags and CoreGraphics' event flags.+FAMILY_FLAGS = {0x38: 1 << 17, 0x3C: 1 << 17, 0x3B: 1 << 18, 0x3E: 1 << 18, 0x3A: 1 << 19, 0x3D: 1 << 19, 0x37: 1 << 20, 0x36: 1 << 20}+++def is_modifier_release(keycode, flags):+ """Whether a FlagsChanged event is a modifier going up, which the recorder listens past: a+ modifier already held when recording starts would otherwise be recorded on its release. Read+ the way the event tap reads it: the key's own device bit where the event carries any, else its+ family's bit, which is also what a release with nothing else held carries -- none."""+ keycode, flags = int(keycode), int(flags)+ family = FAMILY_FLAGS.get(keycode)+ if family is None:+ return False+ # The device bits are distinct, so their sum is their union.+ if flags & sum(NX_DEVICE_MODIFIER_BITS.values()):+ return not flags & NX_DEVICE_MODIFIER_BITS[keycode]+ return not flags & family++def recorded_entry(kind, value, trigger_code):"""The ignored_inputs entry one captured press becomes, or None. `kind` is "key" (a keycodefrom a KeyDown or FlagsChanged event), "right" (the right mouse button, `value` unused),diff --git a/mac_app/tests/test_bridge.py b/mac_app/tests/test_bridge.pyindex e867692..26e184f 100644--- a/mac_app/tests/test_bridge.py+++ b/mac_app/tests/test_bridge.py@@ -16,6 +16,7 @@ from bridge import (ACK_TIMEOUT_SECONDS,AUTH_FAILED_STATUS,CONNECT_TIMEOUT_SECONDS,+ CROSSING_RETRY_SECONDS,OLD_RECEIVER_STATUS,PING_INTERVAL_SECONDS,ROUND_TRIP_MAX_AGE_SECONDS,@@ -1801,6 +1802,52 @@ class CrossingWiringTests(unittest.TestCase):self.assertEqual(kinds[-1], "cross")self.assertEqual(kinds.count("tick"), 3)+ def test_this_macs_own_push_while_windows_drives_sends_the_pc_home_and_crosses(self):+ # The Mac half of 2f45c00: this Mac's trackpad could not push back while the PC drove it.+ sent_home = []+ self.controller.receiving = True+ self.controller.send_peer_home = lambda: sent_home.append(True) or True+ _event, returned = self._push(10)+ self.assertIsNone(returned)+ self.assertEqual(sent_home, [True])+ self.assertFalse(self.controller.receiving)+ self.assertTrue(self.controller.redirecting)+ focus = [m for m in self._sent() if m["type"] == protocol.MSG_FOCUS]+ self.assertEqual(focus[0]["data"]["target"], "windows")++ def test_the_pcs_own_moves_never_push_while_it_drives(self):+ sent_home = []+ self.controller.receiving = True+ self.controller.send_peer_home = lambda: sent_home.append(True) or True+ for _ in range(10):+ event = {+ "location": (1727.0, 558.0),+ FakeQuartz.kCGMouseEventDeltaX: 30,+ FakeQuartz.kCGMouseEventDeltaY: 0,+ FakeQuartz.kCGEventSourceUserData: INJECTED_MARK,+ }+ self.assertIs(self.controller._event_tap_callback(None, FakeQuartz.kCGEventMouseMoved, event, None), event)+ self.assertEqual(sent_home, [])+ self.assertTrue(self.controller.receiving)+ self.assertEqual(FakeQuartz.warp_calls, [])++ def test_a_click_resets_this_macs_push_while_windows_drives(self):+ self.controller.receiving = True+ self.controller.send_peer_home = lambda: True+ self._push(3)+ self.assertGreater(self.controller.crossing.pressure, 0)+ event = {"location": (1727.0, 558.0)}+ self.assertIs(self.controller._event_tap_callback(None, FakeQuartz.kCGEventLeftMouseDown, event, None), event)+ self.assertEqual(self.controller.crossing.pressure, 0)++ def test_no_crossing_while_windows_drives_and_cannot_be_reached(self):+ self.controller.receiving = True+ self.controller.send_peer_home = lambda: False+ event, returned = self._push(10)+ self.assertIs(returned, event)+ self.assertTrue(self.controller.receiving)+ self.assertFalse(self.controller.redirecting)+def test_no_crossing_while_disconnected(self):self.controller.sock = Noneevent, returned = self._push(10)@@ -1839,6 +1886,18 @@ class CrossingWiringTests(unittest.TestCase):self.controller.update_config(crossing_config())self.assertFalse(self.controller._crossing_failed)+ def test_a_passing_failure_in_the_crossing_path_heals_by_itself(self):+ self.controller.desktop_bounds = lambda: (_ for _ in ()).throw(RuntimeError("no displays"))+ self.controller._bounds_cache = None+ self._move(1727.0, 558.0, 30)+ self.assertTrue(self.controller._crossing_failed)+ self.controller.desktop_bounds = lambda: self.BOUNDS+ self.controller._bounds_cache = None+ self.clock.value += CROSSING_RETRY_SECONDS+ _event, returned = self._push(10)+ self.assertIsNone(returned)+ self.assertTrue(self.controller.redirecting)+def test_applying_settings_keeps_the_link(self):sock = self.controller.sockself.controller.apply_settings(crossing_config(resistance_px=40, methods=["shortcut", "notch"]))@@ -1917,6 +1976,28 @@ class CrossingWiringTests(unittest.TestCase):controller = KVMController(crossing_config(), logger=quiet_logger(), quartz=DisplayQuartz, clock=self.clock)self.assertEqual(controller._default_desktop_bounds(), (0.0, -300.0, 3648.0, 1117.0))+ def test_a_sleeping_display_still_bounds_the_desktop(self):+ # 27-09-2026: the active list is empty while the display sleeps; the first push after+ # waking raised and turned crossing off until settings were next saved.+ class SleepingQuartz(FakeQuartz):+ @staticmethod+ def CGGetActiveDisplayList(limit, displays, count):+ return 0, (), 0++ @staticmethod+ def CGGetOnlineDisplayList(limit, displays, count):+ return 0, [1], 1++ @staticmethod+ def CGDisplayBounds(display):+ return types.SimpleNamespace(+ origin=types.SimpleNamespace(x=0.0, y=0.0),+ size=types.SimpleNamespace(width=1728.0, height=1117.0),+ )++ controller = KVMController(crossing_config(), logger=quiet_logger(), quartz=SleepingQuartz, clock=self.clock)+ self.assertEqual(controller._default_desktop_bounds(), (0.0, 0.0, 1728.0, 1117.0))+def test_paused_crossing_leaves_the_edge_alone_while_the_shortcut_still_switches(self):self.controller.crossing_paused = Trueevent, returned = self._push(10)diff --git a/mac_app/tests/test_ignored_inputs.py b/mac_app/tests/test_ignored_inputs.pyindex 8c465fb..a2b90f9 100644--- a/mac_app/tests/test_ignored_inputs.py+++ b/mac_app/tests/test_ignored_inputs.py@@ -74,6 +74,26 @@ class TapTests(unittest.TestCase):(protocol.MSG_MOUSEUP, {"button": "forward"}),])+ def test_a_button_with_no_wire_name_stays_on_this_mac(self):+ # Button 6 was swallowed while redirecting: sent nowhere, and kept from this Mac too.+ self.configure([])+ down, up = other_button(5), other_button(5)+ self.assertIs(self.tap(FakeQuartz.kCGEventOtherMouseDown, down), down)+ self.assertIs(self.tap(FakeQuartz.kCGEventOtherMouseUp, up), up)+ self.assertEqual(self.sent(), [])++ def test_caps_lock_listed_mid_session_stays_here_from_its_next_toggle(self):+ # Each toggle is one FlagsChanged the translator reads as down; the first went across and+ # pinned its route until input came home.+ self.configure([])+ toggle_on = {FakeQuartz.kCGKeyboardEventKeycode: 0x39, "flags": FakeQuartz.kCGEventFlagMaskAlphaShift}+ self.assertIsNone(self.tap(FakeQuartz.kCGEventFlagsChanged, toggle_on))+ self.assertEqual(len(self.sent()), 2)+ self.configure([ignored.key(0x39)])+ toggle_off = {FakeQuartz.kCGKeyboardEventKeycode: 0x39, "flags": 0}+ self.assertIs(self.tap(FakeQuartz.kCGEventFlagsChanged, toggle_off), toggle_off)+ self.assertEqual(self.sent(), [])+def test_an_ignored_button_stays_on_this_mac(self):down, up = other_button(3), other_button(3)self.assertIs(self.tap(FakeQuartz.kCGEventOtherMouseDown, down), down)diff --git a/mac_app/tests/test_ignored_titles.py b/mac_app/tests/test_ignored_titles.pyindex e5d6431..6349d6f 100644--- a/mac_app/tests/test_ignored_titles.py+++ b/mac_app/tests/test_ignored_titles.py@@ -61,6 +61,17 @@ class RecordedEntryTests(unittest.TestCase):def test_other_mouse_numbers_a_button_the_wire_has_no_name_for(self):self.assertEqual(ignored_titles.recorded_entry("other", 5, self.TRIGGER), ignored.button("6"))+ def test_a_modifier_already_held_is_not_recorded_on_its_release(self):+ # Left Shift is keycode 0x38, device bit 0x2; Right Shift 0x3C, device bit 0x4.+ self.assertTrue(ignored_titles.is_modifier_release(0x38, 0x100))+ self.assertTrue(ignored_titles.is_modifier_release(0x38, 0x20000 | 0x4))+ self.assertFalse(ignored_titles.is_modifier_release(0x38, 0x20000 | 0x2))+ self.assertFalse(ignored_titles.is_modifier_release(0x38, 0x20000))++ def test_caps_lock_and_ordinary_keys_are_always_presses(self):+ self.assertFalse(ignored_titles.is_modifier_release(0x39, 0))+ self.assertFalse(ignored_titles.is_modifier_release(0x00, 0))+def _media_data1(self, nx_key, down):state = 0x0A if down else 0x0Breturn (nx_key << 16) | (state << 8)diff --git a/mac_app/widgets.py b/mac_app/widgets.pyindex 9246ecd..d07ab59 100644--- a/mac_app/widgets.py+++ b/mac_app/widgets.py@@ -16,7 +16,7 @@ import objcimport media_keysimport theme-from ignored_titles import recorded_entry+from ignored_titles import is_modifier_release, recorded_entryfrom key_codes import KEY_NAME_TO_CODE, SPECIAL_KEY_NAMES, key_title@@ -1096,6 +1096,8 @@ class IgnoredRecorder:elif event_type == AppKit.NSEventTypeOtherMouseDown:entry = recorded_entry("other", int(event.buttonNumber()), self.trigger_code)else:+ if event_type == AppKit.NSEventTypeFlagsChanged and is_modifier_release(event.keyCode(), event.modifierFlags()):+ return evententry = recorded_entry("key", int(event.keyCode()), self.trigger_code)self._stop()if self.on_recorded is not None:@@ -1279,7 +1281,9 @@ class Sidebar:footer.setAccessibilityLabel_(footer_label or footer_text)footer_label_view = Label(footer_text, theme.TYPE["small"], ink="ink_3", wrap=True)footer.addSubview_(footer_label_view.view)- pin(footer_label_view.view, footer, (8, 16, 8, 14))+ # A slim right inset, with nothing beside the text: the address is 144pt of a 180pt+ # sidebar and wrapped onto a third line at the default window width at 14.+ pin(footer_label_view.view, footer, (8, 16, 8, 4))self.view.addSubview_(footer)AppKit.NSLayoutConstraint.activateConstraints_([footer.leadingAnchor().constraintEqualToAnchor_(self.view.leadingAnchor()),diff --git a/win_app/capture_win.py b/win_app/capture_win.pyindex 94a1231..c62fe83 100644--- a/win_app/capture_win.py+++ b/win_app/capture_win.py@@ -156,19 +156,21 @@ VK_CONTROL_LEFT, VK_CONTROL_RIGHT = 0xA2, 0xA3VK_MENU_LEFT, VK_MENU_RIGHT = 0xA4, 0xA5_RIGHT_SHIFT_SCAN = 0x36_EXTENDED_SCAN = 0x100+_EXTENDED_PREFIX = 0xE000def hook_vk(vk: int, scan: int) -> int:"""The virtual key the low-level hook reports for a key a window saw as `vk` and `scan`. A- window is told only Shift, Ctrl or Alt; the hook always knows which side. `scan` carries the- extended-key bit at 0x100, which is how Qt reports it, and is what marks the right Ctrl and- the right Alt."""+ window is told only Shift, Ctrl or Alt; the hook always knows which side. An extended key is+ what marks the right Ctrl and the right Alt: Qt 6 reports one with an 0xE0 prefix (0xE01D is+ the right Ctrl, proved on the rig 27-09-2026), and the extended bit at 0x100 is read too."""+ extended = bool(scan & _EXTENDED_SCAN) or scan & 0xFF00 == _EXTENDED_PREFIXif vk == 0x10:return VK_SHIFT_RIGHT if scan & 0xFF == _RIGHT_SHIFT_SCAN else VK_SHIFT_LEFTif vk == 0x11:- return VK_CONTROL_RIGHT if scan & _EXTENDED_SCAN else VK_CONTROL_LEFT+ return VK_CONTROL_RIGHT if extended else VK_CONTROL_LEFTif vk == 0x12:- return VK_MENU_RIGHT if scan & _EXTENDED_SCAN else VK_MENU_LEFT+ return VK_MENU_RIGHT if extended else VK_MENU_LEFTreturn vk# Windows virtual keys to the wire's key names, which are Mac-shaped: thediff --git a/win_app/kvm_bridge_win.py b/win_app/kvm_bridge_win.pyindex e2f917e..760a2ec 100644--- a/win_app/kvm_bridge_win.py+++ b/win_app/kvm_bridge_win.py@@ -654,8 +654,14 @@ class WindowsApplication(QWidget):self._set_ignored([candidate for candidate in self._config.ignored_inputs if candidate != entry])def _set_ignored(self, entries: list) -> None:+ previous = self._config.ignored_inputsself._config.ignored_inputs = entries- self._persist()+ if not self._persist():+ # A list the file refuses, past ignored.MAX_ENTRIES, or a disk that would not take it:+ # the running app keeps what is saved, so the list shown is the one the next start uses.+ self._config.ignored_inputs = previous+ self._show_ignored(list(previous), "That could not be saved, so the list is unchanged.")+ returnself.sender.update_config(self._config)self._show_ignored(entries)diff --git a/win_app/tests/test_ignored_inputs.py b/win_app/tests/test_ignored_inputs.pyindex 95b8e1b..ba80c68 100644--- a/win_app/tests/test_ignored_inputs.py+++ b/win_app/tests/test_ignored_inputs.py@@ -138,6 +138,9 @@ class CaptureTests(unittest.TestCase):self.assertEqual(capture_win.hook_vk(0x11, 0x11D), 0xA3)self.assertEqual(capture_win.hook_vk(0x12, 0x38), 0xA4)self.assertEqual(capture_win.hook_vk(0x12, 0x138), 0xA5)+ # How Qt 6 reports them on the rig: the extended prefix, not the bit.+ self.assertEqual(capture_win.hook_vk(0x11, 0xE01D), 0xA3)+ self.assertEqual(capture_win.hook_vk(0x12, 0xE038), 0xA5)self.assertEqual(capture_win.hook_vk(0x10, 0x2A), 0xA0)self.assertEqual(capture_win.hook_vk(0x10, 0x36), 0xA1)self.assertEqual(capture_win.hook_vk(VK_A, 0x1E), VK_A)diff --git a/win_app/tests/test_ignored_page.py b/win_app/tests/test_ignored_page.pynew file mode 100644index 0000000..012a09a--- /dev/null+++ b/win_app/tests/test_ignored_page.py@@ -0,0 +1,92 @@+"""The Keyboard page's Stays on this PC list, as far as it can be reached without building the+window: what it does when the list cannot be saved."""++import types+import unittest++import app_config+import ignored++try:+ import kvm_bridge_win+except ImportError: # PySide6 is only in the Windows venv+ kvm_bridge_win = None++[email protected](kvm_bridge_win is None, "needs PySide6")+class SetIgnoredTests(unittest.TestCase):+ def window(self, saves):+ shown, updates = [], []+ window = types.SimpleNamespace(+ _config=app_config.default_config(),+ _persist=lambda: saves,+ sender=types.SimpleNamespace(update_config=updates.append),+ _show_ignored=lambda entries, refused="": shown.append((entries, refused)),+ )+ window._config.ignored_inputs = [ignored.button("back")]+ return window, shown, updates++ def test_a_list_that_saves_is_applied(self):+ window, shown, updates = self.window(saves=True)+ entries = [ignored.button("back"), ignored.key(0xAF)]+ kvm_bridge_win.WindowsApplication._set_ignored(window, entries)+ self.assertEqual(window._config.ignored_inputs, entries)+ self.assertEqual(len(updates), 1)+ self.assertEqual(shown, [(entries, "")])++ def test_a_list_that_cannot_be_saved_changes_nothing(self):+ # A 65th entry was applied live and shown as added, then lost at the next start.+ window, shown, updates = self.window(saves=False)+ kvm_bridge_win.WindowsApplication._set_ignored(window, [ignored.button("back"), ignored.key(0xAF)])+ self.assertEqual(window._config.ignored_inputs, [ignored.button("back")])+ self.assertEqual(updates, [])+ self.assertEqual(shown[-1][0], [ignored.button("back")])+ self.assertTrue(shown[-1][1])++[email protected](kvm_bridge_win is None, "needs PySide6")+class RecorderTests(unittest.TestCase):+ def setUp(self):+ import os++ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")+ from PySide6.QtWidgets import QApplication++ import capture_win+ import widgets++ self.app = QApplication.instance() or QApplication([])+ self.recorded = []+ self.recorder = widgets.InputRecorder("Add", lambda kind, value: self.recorded.append((kind, value)), capture_win.hook_vk)+ self.recorder._toggle()++ def tearDown(self):+ self.recorder.cancel()++ def key(self, press, vk, scan):+ from PySide6.QtCore import QEvent, Qt+ from PySide6.QtGui import QKeyEvent++ kind = QEvent.Type.KeyPress if press else QEvent.Type.KeyRelease+ event = QKeyEvent(kind, 0, Qt.KeyboardModifier.NoModifier, scan, vk, 0)+ self.recorder.eventFilter(self.recorder, event)++ def test_right_ctrl_is_recorded_as_right_ctrl(self):+ # Qt 6 on the rig: nativeVirtualKey 0x11, nativeScanCode 0xE01D.+ self.key(True, 0x11, 0xE01D)+ self.assertEqual(self.recorded, [("key", 0xA3)])++ def test_altgr_is_recorded_as_right_alt_not_its_made_up_left_ctrl(self):+ self.key(True, 0x11, 0x1D)+ self.key(True, 0x12, 0xE038)+ self.assertEqual(self.recorded, [("key", 0xA5)])++ def test_left_ctrl_on_its_own_is_recorded_when_let_go(self):+ self.key(True, 0x11, 0x1D)+ self.assertEqual(self.recorded, [])+ self.key(False, 0x11, 0x1D)+ self.assertEqual(self.recorded, [("key", 0xA2)])+++if __name__ == "__main__":+ unittest.main()diff --git a/win_app/widgets.py b/win_app/widgets.pyindex f999a80..ab437ac 100644--- a/win_app/widgets.py+++ b/win_app/widgets.py@@ -22,6 +22,8 @@ from PySide6.QtWidgets import (import themeimport tokens+LEFT_CTRL_VK = 0xA2+def label(text: str, role: str, wrap: bool = False) -> QLabel:item = QLabel(text)@@ -326,6 +328,7 @@ class InputRecorder(QPushButton):self.on_record = on_recordself.hook_vk = hook_vkself.armed = False+ self.left_ctrl_held = Falseself.setProperty("vernier", "keycap")self.setCursor(Qt.CursorShape.PointingHandCursor)self.setAccessibleName(title)@@ -343,6 +346,7 @@ class InputRecorder(QPushButton):self.clicked.connect(self._toggle)def cancel(self) -> None:+ self.left_ctrl_held = Falseif not self.armed:returnself.armed = False@@ -371,10 +375,19 @@ class InputRecorder(QPushButton):vk = self.hook_vk(event.nativeVirtualKey(), event.nativeScanCode())if not vk:return True+ if vk == LEFT_CTRL_VK:+ # AltGr arrives as a Left Ctrl Windows makes up, then the Right Alt pressed, so a+ # Left Ctrl waits: let go, it is what was pressed; followed by another key, that+ # key is (proved on the rig 27-09-2026, where AltGr recorded as Left Ctrl).+ self.left_ctrl_held = True+ return Trueself.cancel()self.on_record("key", vk)return Trueif kind == QEvent.Type.KeyRelease:+ if self.left_ctrl_held and self.hook_vk(event.nativeVirtualKey(), event.nativeScanCode()) == LEFT_CTRL_VK:+ self.cancel()+ self.on_record("key", LEFT_CTRL_VK)return Trueif kind == QEvent.Type.MouseButtonPress:name = self.BUTTONS.get(event.button())