From bcb13396cd517d0537f249e119b012e6657b902a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=B6=8A=E7=BE=BD=E6=AF=9B?= <97326386+Icather@users.noreply.github.com> Date: Mon, 15 Jun 2026 16:49:15 +0800 Subject: [PATCH] fix(computer_use): use single-batch SendInput for switch_desktop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two-batch SendInput (press → sleep → release) crashes the embedded gateway (Dashboard Chat tab) because its single-channel event loop cannot handle multi-batch keyboard injection without disrupting the PTY pipeline. The full system gateway is unaffected because its multi-client dispatch loop handles concurrent channels. Switch to single-batch SendInput matching _press_combo semantics (hold modifiers → tap arrow → release). This works in both embedded and full gateway modes. --- tools/computer_use/windows_backend.py | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/computer_use/windows_backend.py b/tools/computer_use/windows_backend.py index 2211993dccb1..62db4bb4c10c 100644 --- a/tools/computer_use/windows_backend.py +++ b/tools/computer_use/windows_backend.py @@ -296,12 +296,11 @@ def _press_combo(vks: List[int]) -> None: def _switch_desktop_via_keybd(direction: str, overlay_client) -> bool: - """Switch virtual desktop, keeping the overlay alive across the transition. + """Switch virtual desktop via Ctrl+Win+Left/Right SendInput. - Any SendInput-based virtual-desktop switch kills the full-screen tkinter - overlay subprocess because the display-context change tears down its X11 - connection. Workaround: stop the overlay → switch → restart it on the - new desktop. + The overlay subprocess (full-screen tkinter window) is killed by any + virtual-desktop transition, so we stop it before switching and restart + it on the new desktop. """ VK_CONTROL = 0x11 VK_LWIN = 0x5B @@ -310,24 +309,20 @@ def _switch_desktop_via_keybd(direction: str, overlay_client) -> bool: vk_dir = VK_LEFT if direction == "left" else VK_RIGHT - press = [_key_event(VK_CONTROL, True), - _key_event(VK_LWIN, True), - _key_event(vk_dir, True)] - release = [_key_event(vk_dir, False), - _key_event(VK_LWIN, False), - _key_event(VK_CONTROL, False)] + # Single-batch SendInput matching _press_combo semantics: + # hold modifiers → tap arrow → release, so the system input thread + # sees the same event order as a physical keyboard. + seq = [_key_event(VK_CONTROL, True), + _key_event(VK_LWIN, True), + _key_event(vk_dir, True), + _key_event(vk_dir, False), + _key_event(VK_LWIN, False), + _key_event(VK_CONTROL, False)] try: - # 1. Gracefully stop the overlay before switching overlay_client.stop() - - # 2. Switch virtual desktop - _send_inputs(press) - time.sleep(0.08) - _send_inputs(release) - - # 3. Restart overlay on the new desktop - overlay_client._dead = False # we killed it on purpose, not a crash + _send_inputs(seq) + overlay_client._dead = False overlay_client.start() return True except Exception: