Skip to content

One keyboard and mouse for a Mac and a Windows PC over the local network, in either direction.

Beamer 1.5.4

Toby Kalkman53183bcd56bc
diff --git a/VERSION b/VERSION
index 8af85be..94fe62c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.5.3
+1.5.4
diff --git a/core/tests/test_shortcut_cycle.py b/core/tests/test_shortcut_cycle.py
index 42132af..4a17a21 100644
--- a/core/tests/test_shortcut_cycle.py
+++ b/core/tests/test_shortcut_cycle.py
@@ -62,5 +62,63 @@ class ShortcutCycleTests(unittest.TestCase):
self.assertEqual(settings_sync.read(data, set())[2], {"shortcut_goes_to": "ticked"})
+# A synced layout: a Windows PC, a Linux machine and the Mac in a row, a fourth machine up to the
+# right and switched off. With Linux home the cycle from the Mac is the fourth, the PC, then home.
+RIG, FEDORA, MAC, FAR = "rig", "fedora", "mac", "far"
+SYNCED = {RIG: (-960, -50, 160, 100), FEDORA: (-800, -50, 160, 100),
+ MAC: (-640, -50, 160, 100), FAR: (-198, -119, 160, 100)}
+
+
+class WayHomeTests(unittest.TestCase):
+ """An offline machine in the cycle never costs a press or keeps input from home, and a machine
+ that refused a moment ago (the owner holds it back, so a take there does nothing) is passed
+ over, never chosen: choosing it left input on the Mac with "<machine> isn't connected" on
+ every press."""
+
+ def presses_home(self, home, mode, start, held):
+ peers = [peer(ident) for ident in SYNCED if ident != home]
+ order = ways.shortcut_order(peers, home, SYNCED, mode)
+ ready = lambda ident: ident != FAR
+ on, pressed = start, 0
+ while on is not None:
+ target, _skipped = ways.next_target({"shortcut_goes_to": mode}, order, on, ready,
+ held=lambda ident: ident in held)
+ self.assertNotIn(target, {FAR} | set(held), (home, mode, on))
+ self.assertNotEqual(target, on, (home, mode, on))
+ on, pressed = target, pressed + 1
+ self.assertLessEqual(pressed, len(order), (home, mode, start))
+ return pressed
+
+ def test_every_press_moves_on_and_ends_home_for_each_home(self):
+ for home in (FEDORA, MAC, RIG):
+ for mode in ("ticked", "next"):
+ for start in [ident for ident in SYNCED if ident not in (home, FAR)]:
+ for held in ((), tuple(ident for ident in SYNCED if ident not in (home, start, FAR))):
+ with self.subTest(home=home, mode=mode, start=start, held=held):
+ self.presses_home(home, mode, start, held)
+
+ def test_fedora_home_from_the_mac_with_the_rig_held_back_goes_home_in_one_press(self):
+ peers = [peer(RIG), peer(MAC), peer(FAR)]
+ order = ways.shortcut_order(peers, FEDORA, SYNCED, "ticked")
+ self.assertEqual(order, [MAC, FAR, RIG, None])
+ target, skipped = ways.next_target({"shortcut_goes_to": "ticked"}, order, MAC,
+ lambda ident: ident != FAR, held=lambda ident: ident == RIG)
+ self.assertEqual((target, skipped), (None, [FAR]))
+
+ def test_a_held_back_machine_is_not_named_as_not_connected(self):
+ target, skipped = ways.next_target({}, [A, B, None], None, lambda _ident: True,
+ held=lambda ident: ident == A)
+ self.assertEqual((target, skipped), (B, []))
+
+ def test_hold_passes_over_a_held_back_last_machine(self):
+ self.assertEqual(ways.hold_target({"shortcut_goes_to": "last"}, [A, B, None], A,
+ lambda _ident: True, held=lambda ident: ident == A), (B, []))
+
+ def test_nothing_to_name_when_every_machine_is_held_back(self):
+ held = lambda _ident: True
+ self.assertEqual(ways.next_target({}, [A, B, None], None, lambda _ident: False, held=held), (None, []))
+ self.assertEqual(ways.hold_target({}, [A, B, None], None, lambda _ident: False, held=held), (None, []))
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/core/ways.py b/core/ways.py
index 2584941..1faf9f0 100644
--- a/core/ways.py
+++ b/core/ways.py
@@ -1537,8 +1537,12 @@ def shortcut_order(peers: list, machine_id: str, positions: dict, mode: str = "n
return reading + [None]
-def next_target(settings: dict, order: list, current: Optional[str], ready: Callable[[Optional[str]], bool]):
- """Next ready peer or home, and the peer ids skipped because they are not ready."""
+def next_target(settings: dict, order: list, current: Optional[str], ready: Callable[[Optional[str]], bool],
+ held: Optional[Callable[[str], bool]] = None):
+ """Next ready peer or home, and the peer ids skipped because they are not ready. A peer `held`
+ back after refusing a moment ago is passed over unnamed: the owner ignores a move there, so
+ choosing it would leave input where it is (14-10-2026)."""
+ held = held or (lambda _ident: False)
peers = [ident for ident in order if ident is not None]
if current is None:
start = 0
@@ -1547,17 +1551,21 @@ def next_target(settings: dict, order: list, current: Optional[str], ready: Call
candidates = peers[start:]
skipped = []
for ident in candidates:
+ if held(ident):
+ continue
if ready(ident):
return ident, skipped
skipped.append(ident)
- if current is None and peers:
- return peers[0], skipped
+ if current is None:
+ return next((ident for ident in peers if not held(ident)), None), skipped
return None, skipped
-def hold_target(settings: dict, order: list, last: Optional[str], ready: Callable[[str], bool]):
- """The Hold-style destination and any preceding peers that were not ready."""
- peers = [ident for ident in order if ident is not None]
+def hold_target(settings: dict, order: list, last: Optional[str], ready: Callable[[str], bool],
+ held: Optional[Callable[[str], bool]] = None):
+ """The Hold-style destination and any preceding peers that were not ready; `held` as next_target."""
+ held = held or (lambda _ident: False)
+ peers = [ident for ident in order if ident is not None and not held(ident)]
candidates = peers
if settings.get("shortcut_goes_to", "last") == "last" and last in peers:
candidates = [last] + [ident for ident in peers if ident != last]
diff --git a/flatpak/uk.co.kalkman.beamer.metainfo.xml b/flatpak/uk.co.kalkman.beamer.metainfo.xml
index f90b272..e54d81c 100644
--- a/flatpak/uk.co.kalkman.beamer.metainfo.xml
+++ b/flatpak/uk.co.kalkman.beamer.metainfo.xml
@@ -43,6 +43,9 @@
</screenshots>
<content_rating type="oars-1.1"/>
<releases>
+ <release version="1.5.4" date="2026-10-14">
+ <description><p>Fixes the shortcut leaving input stranded when it picked a machine that had just turned it away.</p></description>
+ </release>
<release version="1.5.3" date="2026-10-13">
<description><p>Adds pointer hiding on idle screens, idle takeover, per-screen crossing with contact-span matching, and Mac and Qt refresh improvements.</p></description>
</release>
diff --git a/mac_app/bridge.py b/mac_app/bridge.py
index bf76477..f568e3d 100644
--- a/mac_app/bridge.py
+++ b/mac_app/bridge.py
@@ -825,6 +825,10 @@ class KVMController:
link = self._peers_up.get(peer) if peer else None
return link is not None and link.live() and self._accepts.get(peer, False)
+ def _held_back(self, peer):
+ with self._owner_lock:
+ return self.owner.held_back(peer)
+
def _crossing_ready(self, peer):
"""Whether a zone to `peer` has a wall now: its link is up, this Mac sends to it, and it is not
held back after a refusal, as Windows' zones are, since a push that cannot take it must not pin
@@ -885,7 +889,8 @@ class KVMController:
def _cycle_target(self):
order = self._shortcut_cycle()
target, skipped = ways.next_target(self.cfg.crossing, order,
- protocol.peer_id_text(self.owner.on) if self.owner.on else None, self._ready)
+ protocol.peer_id_text(self.owner.on) if self.owner.on else None, self._ready,
+ held=self._held_back)
self._announce_shortcut_skips(skipped)
return target
@@ -2010,10 +2015,15 @@ class KVMController:
if result.is_repeat:
return None
if result.is_down:
+ order = self._shortcut_cycle()
target, skipped = ways.hold_target(
- self.cfg.crossing, self._shortcut_cycle(), self._last_peer, self._ready)
+ self.cfg.crossing, order, self._last_peer, self._ready, held=self._held_back)
self._announce_shortcut_skips(skipped)
- self.set_redirecting(True, peer=target, reason="hold")
+ # None from a cycle with machines in it means every one refused a moment ago: a peer
+ # of None would fall back to the shortcut's machine, which may be outside the cycle.
+ # An empty cycle (one machine, no layout) still goes to the shortcut's machine.
+ if target is not None or not any(ident is not None for ident in order):
+ self.set_redirecting(True, peer=target, reason="hold")
else:
self.set_redirecting(False)
return None
diff --git a/mac_app/tests/test_shortcut_home_chain.py b/mac_app/tests/test_shortcut_home_chain.py
index 3724cd0..fc754cb 100644
--- a/mac_app/tests/test_shortcut_home_chain.py
+++ b/mac_app/tests/test_shortcut_home_chain.py
@@ -102,6 +102,16 @@ class DoubleTapChainTests(Chain):
self.assertEqual(c.owner.on, protocol.id_text(OTHER_ID))
self.assertEqual(c._cycle_target(), protocol.id_text(FEDORA_ID))
+ def test_next_target_passes_over_a_machine_that_just_refused_and_comes_home(self):
+ # The owner ignores a move to a machine it holds back, so choosing it left input where it was.
+ self._use_next_cycle()
+ c = self.controller
+ self.assertTrue(c.set_redirecting(True, peer=protocol.id_text(OTHER_ID)))
+ self.acg.arrives(c, protocol.accept_msg(c.owner.route))
+ c.owner._hold_back(protocol.id_text(FEDORA_ID), "refused")
+
+ self.assertIsNone(c._cycle_target())
+
def test_next_target_after_a_peer_requested_move(self):
self._use_next_cycle()
c = self.controller
@@ -238,6 +248,21 @@ class HoldChainTests(Chain):
self.assertIsNone(self.controller.owner.on)
+class HoldWithEveryCycleMachineHeldBack(Chain):
+ style = "hold"
+
+ def test_hold_with_every_cycle_machine_held_back_moves_nothing(self):
+ # hold_target names nobody, and a peer of None would fall back to a machine outside the cycle.
+ c = self.controller
+ c.cfg.crossing["shortcut_goes_to"] = "ticked"
+ c._shortcut_cycle = lambda: [protocol.id_text(OTHER_ID), None]
+ c.owner._hold_back(protocol.id_text(OTHER_ID), "refused")
+ self.tap(FakeQuartz.kCGEventFlagsChanged, self.key(True))
+ settle(c)
+ self.assertIsNone(c.owner.on)
+ self.assertFalse(c.redirecting)
+
+
class ArrivalHomeGrace(Chain):
"""The same chain ending as rc14's did at 19:50:51: a switch home at the Mac's bottom edge."""
diff --git a/win_app/sender.py b/win_app/sender.py
index 6970ee5..417d42c 100644
--- a/win_app/sender.py
+++ b/win_app/sender.py
@@ -298,10 +298,18 @@ class LinkSender:
def _cycle_target(self):
target, skipped = ways.next_target({"shortcut_goes_to": self._setting("shortcut_goes_to", "last")},
self._cycle_order(), protocol.peer_id_text(self.owner) if self.owner else None,
- self._cycle_ready)
+ self._cycle_ready, held=self._held_back)
self._announce_shortcut_skips(skipped)
return protocol.read_id(target) if target is not None else None
+ def _held_back(self, ident):
+ peer = protocol.read_id(ident)
+ owner = self._owner
+ if peer is None or owner is None:
+ return False
+ with self._lock:
+ return owner.held_back(peer)
+
def _cycle_ready(self, ident):
peer = protocol.read_id(ident)
return peer is not None and self.links.up(peer) and self._accepts.get(peer) is True
@@ -324,7 +332,7 @@ class LinkSender:
target, skipped = ways.hold_target(
{"shortcut_goes_to": self._setting("shortcut_goes_to", "last")},
self._cycle_order(), self._last_on,
- self._cycle_ready)
+ self._cycle_ready, held=self._held_back)
self._announce_shortcut_skips(skipped)
target = protocol.read_id(target) if target else None
self.set_redirecting(target is not None, peer=target)
diff --git a/win_app/tests/test_pc_three_machines.py b/win_app/tests/test_pc_three_machines.py
index 6935e68..bd2b6c1 100644
--- a/win_app/tests/test_pc_three_machines.py
+++ b/win_app/tests/test_pc_three_machines.py
@@ -81,6 +81,15 @@ class ShortcutMachineTests(unittest.TestCase):
rig.sender.toggle_shortcut()
self.assertIsNone(rig.sender.owner)
+ def test_next_shortcut_passes_over_a_machine_that_just_refused_and_comes_home(self):
+ # The owner ignores a move to a machine it holds back, so choosing it left input where it was.
+ rig = self.rig(up=(B, C), shortcut_goes_to="next")
+ rig.sender.toggle_shortcut()
+ self.assertEqual(rig.sender.owner, C)
+ rig.sender._owner._hold_back(B, "refused")
+ rig.sender.toggle_shortcut()
+ self.assertIsNone(rig.sender.owner)
+
def test_a_machine_that_does_not_accept_input_is_passed_over(self):
rig = self.rig(up=(C,))
rig.bring_up(B, accepts=False)