Skip to content

fix: EIS device lifecycle, keyboard burst, screen auto-detect (port from 01SW) - #15

Merged
VibeProgramm merged 44 commits into
mainfrom
fix/01sw-port
Sep 8, 2026
Merged

VibeProgramm merged 44 commits into
mainfrom
fix/01sw-port

Conversation

@VibeProgramm

Copy link
Copy Markdown
Owner

Summary

Port of three quality fixes from 01SW/kwin-mcp (independent fork of the same upstream; their code validated against KWin 6.7 EIS quirks we also observe), re-implemented on our codebase (official MCP SDK 2.x, async tools, lazy libei, ToolError contract):

  1. EIS device lifecycle + reconnect — KWin pauses/re-adds its EIS devices around input bursts (observed right after session start and after modifier presses); injection silently dropped before. Now: central _handle_event dispatcher (RESUMED/PAUSED/ADDED/REMOVED/SEAT_REMOVED/DISCONNECT), _ensure_devices_ready before every injection (wait emulating → reconnect via fresh connectToEIS on stall), _connection_dead unified error path (DISCONNECT event, ei_dispatch() < 0), device-slot replace-semantics that don't steal handles from live devices, idempotent RESUMED, partial-handshake teardown, active-touch cleanup on reconnect. Adopted from 01SW with our hardening (text-device included in all lifecycle paths, ToolError contract, teardown).
  2. keyboard_burst — all combo key events in a single EIS frame (KWin pauses devices when a combo spans multiple frames); press/release phases are separate frames.
  3. Screen auto-detect — session_start(screen_width=0) = match the visible/logical desktop: kscreen-doctor (ANSI-stripped, Output-block parsing, enabled-only, priority-1 preferred) → xrandr (primary beats Screen current regardless of line order) → 1920×1080 fallback. Explicit sizes keep priority (non-breaking for callers passing sizes; BREAKING for default-relying clients, marked in CHANGELOG).

Plus: serverInfo.version from package metadata (was empty), KWIN_MCP_DEBUG_EI=1 debug logging via stdlib logging (documented in README), CHANGELOG entries with attribution.

Verification loop

fixer → verifier → fixer → verifier (all 16 findings from two review rounds closed):

  • Verifier R1: request-changes (ANSI parsing dead on real KDE, touch UAF on reconnect, dispatch error path, slot stealing) → Fixer R2 closed all →
  • Verifier R2: OK, can PR — all 16 closures confirmed in code + tests; no regressions; fd count stable across 6 reconnects; happy-path latency unchanged (1–2 ms).
  • Unit: 107 tests (was 92; +15 regression tests incl. real-ANSI kscreen fixture, reconnect+active-touch safety, disconnect→reconnect, primary-beats-current). ruff/ty/build green.
  • Live probe: serverInfo.version='0.8.2', 30 tools, session_start(0,0) → screenshot 1746×982 = actual desktop (auto-detect works, was dead before), session_start(800,600) → 800×600, combo storm recovers via reconnect and delivers.

Known follow-ups (non-blocking, separate issues)

  • W1: each modifier-combo after first pays ~5s stall-timeout before reconnect (KWin pauses without RESUMED); injection delivered, but latency is poor — candidates: shorter first-wait, or burst modifiers in mouse_click (they still go single keyboard_key).
  • W2: touch_move/up fetch the touch pointer before _ensure_devices_ready — narrow race vs reconnect; swap to ensure-first.
  • Window-anchor feature from 01SW (KWin script anchoring windows at origin for absolute AT-SPI coords) — intentionally not ported; our geometry-translation approach covers live sessions; candidate for evaluation later.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant