Skip to content

View and control Linux desktops from the iPhone (851-4486) - #1493

Merged
pondorasti merged 13 commits into
mainfrom
alexandru/851-4486-linux-desktop-step-5-view-and-control
Nov 26, 2026
Merged

pondorasti merged 13 commits into
mainfrom
alexandru/851-4486-linux-desktop-step-5-view-and-control

Conversation

@pondorasti

@pondorasti pondorasti commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes 851-4486
Part of 851-4479

The iPhone can now view and control a Linux machine's desktop, in the same Desktop tab it has for Macs. Before, it said "can only be viewed from a Mac".

What changed

  • The VNC viewing session, frame publishing and input translation (ScreenSharing/VNC) build for iOS. They used nothing Mac-specific; only the #if os(macOS) gates go.
  • RFBWebSocketTransport moves from CodevisorCoreMac to ScreenSharingConnection, so both apps use it. The Mac's wiring is unchanged.
  • The phone's ScreenSharingDesktops gives each machine a VNC transport that opens the server's relay socket. Connecting, failing, retrying, reconnecting and "in use on another device" are the shared connection's, as for a Mac.
  • Keys: the phone has no keyboard layout to read, so it passes a fixed US table (VNCUnitedStatesKeyLayout). Command goes out as Control, as on the Mac.
  • Pointer: the phone connects with serverDrawsPointer, which leaves the cursor-shape and pointer-position encodings out of what the client advertises, so the VNC server paints the pointer into the picture.
  • Size: the phone never asks for a desktop size or scale. It views at the desktop's size and zooms.
  • Scrolling: a two-finger drag arrives as many small movements, and the Mac's rule (at least one wheel click per event) would make a slow drag scroll fastest. The phone uses VNCScrollInput.touch: one click per 20 desktop pixels dragged.
  • Wording: the phone's status and control notices named "the Mac" ("Connecting to Mac…", "The Mac didn't answer…"). They now name the machine, for Macs too.
  • VNCScreenSharingSession.init was 73 lines and baselined in SwiftLint; its receive loop is now a small static function and the baseline entry is gone.

Left out, as decided

Resizing the desktop to the phone, the 2x switch, clipboard sync (Paste from iPhone stays), cursor shapes, and setting up a desktop from the phone.

The "set up a desktop" line for a machine without one is left out. Neither thing it would point to exists yet (codevisor desktop setup is step 2, the Mac app's button is step 4), and a machine without a desktop doesn't offer Open Desktop at all, so the line would need a new dead-end row on every Linux machine. It belongs with step 2 or 4.

Tests

New, and failing without the change (checked by breaking the code: 6 of them fail when the pointer, name, scroll or key table choices are removed):

  • ScreenSharingLinuxDesktopTests: the phone's real pane model against a real RFB server through a fake relay socket. Goes live with no host start and no resize; a tap asks for control under the phone's name and clicks once granted; another device taking control leaves the picture and says who; right-click; drag; slow scroll; typing with Command as Control; every printable key; a refused relay fails with Try Again and Try Again connects; a dropped relay reconnects.
  • VNCUnitedStatesKeyLayoutTests, VNCWheelTests, and a cursor test for serverDrawsPointer.
  • The old test that the phone refuses a Linux desktop is removed with the behaviour. RFBWebSocketTransportTests moves with the transport, and the VNC transport tests (including step 1's remembered-display test) now run ungated.

193 tests in 24 touched suites pass. build:ios and build:macos succeed.

Code review (medium)

Found six things. Fixed, each with a test:

  • Pasted text with Windows line endings pressed Return twice per line break on a Linux desktop. One Return now.
  • A hardware keyboard with a non-US layout typed its US key positions (German Z arrived as y). For a session whose keys are characters, the phone now sends the character iOS reports for the key; chords send the key's own letter with the modifier; arrows, Return and dead keys still go by position. This also makes Caps Lock work on a hardware keyboard.
  • A control grant that arrived after the phone had given up waiting (3 s) left the machine thinking the phone was in control. The phone now hands such a grant back. This was already true for Macs viewed from the phone.
  • The README said the fixed key table handles Caps Lock, which the phone never sent. The dead branch and the claim are gone.

Left:

  • The unused part of a two-finger scroll (under 20 pixels) carries into the next scroll gesture, so a tiny later drag can give one early wheel click. Dropping it at the start of a gesture needs a gesture-start signal in the input messages, which is more than this is worth here.
  • If creating the RFB client object itself fails, the relay socket isn't closed. That only happens if a 1x1 framebuffer can't be allocated, there is no way to make it happen in a test, and it was already so on the Mac.

Hardware keyboards on a Linux desktop (after review at 35a68af)

A hardware keyboard's key codes are positions and its layout may not be US, so for a Linux desktop the phone sends what iOS reports for the key (ScreenSharingHardwareKey, rules in the ScreenSharing README):

  • Shift tapped in the on-screen bar is applied on top of a hardware key (it was dropped). Letters are capitalised; for other keys the layout's shifted symbol can't be known, so the character goes as it is with Shift held.
  • Option alone types the character the layout makes with it only when that is ASCII or a currency sign (German Option-L is @, Option-5 is [, Option-7 is |, Option-E is €; US Option-3 is £), with no Alt. Anything else it composes (US Option-F is ƒ), Option that composes nothing, and Option tapped on screen, is Alt with the key's letter, so Alt shortcuts work from a US keyboard.
  • A dead key sends nothing. Measured on iOS 27.2 with a German hardware layout (key presses injected into the simulator, with and without a text input focused): the dead key reports empty characters and "´" as its unmodified character; the next key reports "é", "´" after Space, or "´x" when the two don't combine. Option and Shift-Option reports were measured once (Shift-Option-7 gave "\" over "7"); Control, Command and Caps Lock reports were not measured.
  • Shortcuts send the key's own character with every held modifier; a character outside the US table's unshifted keys goes as its own keysym, so Shift is neither lost nor invented.
  • The touch scroll's leftover distance is dropped when the next two-finger drag begins (scrollGestureBegan), along with the phone's sub-pixel remainder.

Known limits, listed in the README: an Option combination that iOS reports no character for is treated as a dead key; a shortcut with Shift on a digit or punctuation key sends the US shifted symbol; a pending accent is dropped if the next key is a shortcut or has no character; Space reporting another kind of space arrives as an ordinary space.

The code review ran on this delta six times. Every pass found further layout cases in this logic; the concrete ones are fixed with tests, and what is left is the list above. The last commit (the narrower Option rule) was not reviewed by the skill.

Checked by hand

iOS 27.2 simulator (iPhone 17 Pro) against the dev container's Xfce desktop (CODEVISOR_DEV_CONTAINER_DESKTOP=1), on the code before the rebase onto step 1 (#1485) and again after it:

  • Open Desktop goes live in about 4 s; the pointer is drawn in the picture.
  • Taps click where touched (opened the Applications menu, started a terminal; measured with an event-logging window: press and release at the exact pixel).
  • One-finger drag is a press, moves with the button held, and a release. The press lands about 10 points along the drag from where the finger went down; that is the shared canvas's drag recognition, the same for Macs, and not changed here.
  • Typing: echo "Hi_iPhone-42!" ~ $HOME | tr a-z A-Z arrived intact, the on-screen keys work, and Command with c interrupted sleep 100 (arrived as Control-C).
  • Stop Controlling, then tapping again, takes control back.
  • A second viewer taking control: the phone keeps the picture and shows "Alexandru's MacBook Pro took control."
  • Killing the VNC server: Reconnecting, then "Can't Show This Desktop" with Try Again. Restarting it: the phone reconnected by itself once, and Try Again connected in 1.4 s the other time.

Not checked by hand (this Mac's screen was locked, so the simulator window could not be driven with two fingers, and the later fixes were not run in the simulator against a Linux desktop):

  • Two-finger right-click and two-finger scroll: covered by ScreenSharingLinuxDesktopTests, down to the bytes sent to the VNC server, and by VNCWheelTests.
  • Pinch zoom: the existing canvas code, unchanged, and it never reaches the desktop.
  • The hardware keyboard rules above: covered by ScreenSharingHardwareKeyTests and three model-level tests against a real RFB server. What iOS reports for keys was measured in the simulator on a German layout; the rules were not typed into a Linux desktop by hand. Before these rules, hardware-style keys on a US layout were checked by hand (a, Shift+Z, 9, Shift+!).
  • Pasted Windows line endings and the handed-back control grant: tests only.
  • A real iPhone, an iPad, a physical hardware keyboard, and a non-US on-screen keyboard.

Screenshots

Light Dark
Live live-light live-dark
Connecting connecting-light connecting-dark
Failure failure-light failure-dark

Also: another device took control, typing in a terminal.

🤖 Generated with Claude Code

pondorasti and others added 13 commits November 26, 2026 11:21
The iPhone answered "can only be viewed from a Mac" for a Linux desktop.
The VNC viewing session, frame publishing and input translation now build
for iOS, the WebSocket transport moves to the shared connection package,
and the phone's Desktop pane opens the server's relay like the Mac does.

The phone has no keyboard layout to read, so key codes go through a fixed
US table. It draws no cursor, so it asks the server to paint the pointer
into the picture. It never resizes the desktop. Touch scrolling turns the
wheel by the distance dragged instead of once per movement.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Pasted Windows line endings pressed Return twice. A hardware keyboard
with a non-US layout typed its US positions, so its keys now go as the
characters iOS reports for them. A control grant that arrived after the
phone gave up was kept by the machine; the phone now hands it back.
The fixed key table no longer claims to handle Caps Lock, which the
phone never sent.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…oll's leftover with its gesture

Shift tapped in the on-screen bar was dropped for hardware keys, because
iOS reports the key without it. Option on a non-US layout sent Alt and
the key's letter instead of the character the layout makes (German
Option-L is @). A dead key fell back to its US position and typed a
character nobody pressed; it now sends nothing, and the next key carries
what iOS made of the two. The distance left over from a two-finger
scroll is forgotten after 300 ms without scrolling.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…t on a Linux desktop

The delta review found that Option-Space typed a non-breaking space, an
Option dead key was sent as Alt and the letter, a shortcut on a key iOS
gives no character for was dropped, and Shift tapped on screen guessed a
US shifted symbol for non-letter keys (and turned ß into SS).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…when a drag begins

A shortcut on a character outside the US table's unshifted keys is sent
as its own keysym with every held modifier, so Shift is neither lost
(Command-Shift-§), doubled into two letters (ß), nor invented (French
Command-&). A dead key sends nothing whatever is latched on screen. The
touch scroll's leftover distance is dropped when the next two-finger
drag begins instead of after a pause.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…wn limits

A character key with unprintable characters goes by position instead of
vanishing; only an empty report is a dead key. Caps Lock no longer adds
Shift to a shortcut. On-screen Shift capitalises only characters whose
capital is that same letter (µ stays µ). A new scroll gesture also drops
the phone's own sub-pixel remainder.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… a capital whose small form is two code points

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ey when it reports another space

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… invisible characters are handled

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…lt otherwise

Option alone typed whatever the layout composed, which on a US keyboard
is nearly every letter, so Alt shortcuts from a hardware keyboard were
lost. It now types the composed character only when it is ASCII or a
currency sign (German @ [ | \ and €, US £); any other result is Alt
with the key's own letter again.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@pondorasti
pondorasti merged commit 171d67b into main Nov 26, 2026
11 checks passed
@pondorasti
pondorasti deleted the alexandru/851-4486-linux-desktop-step-5-view-and-control branch November 26, 2026 23:46
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