Skip to content

View and control a Linux machine's real screen (851-4496) - #1502

Merged
pondorasti merged 8 commits into
mainfrom
alexandru/851-4496-linux-desktop-step-8-view-and-control-a
Nov 27, 2026
Merged

pondorasti merged 8 commits into
mainfrom
alexandru/851-4496-linux-desktop-step-8-view-and-control-a

Conversation

@pondorasti

@pondorasti pondorasti commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Fixes 851-4496

Step 8 of the Linux desktop design (851-4479, section 5, decisions 7 to 9): a Linux machine where the server's account is logged in at the monitor lists two displays, like a Mac with two monitors: Desktop (the virtual one, as before) and Screen (the real one). X11 sessions only in this PR.

What changed

  • The config holds a list. screen-sharing.json gets displays, a list of { id, vnc, service }: desktop and screen. A config in the old form (the desktop's vnc and service at the top) is read as a one-entry list and is not rewritten until setup next changes something. Viewers see vnc:desktop (first, so it stays the default) and vnc:screen.
  • Finding the session (screen-logind.ts, screen-session.ts). Who is at the screen comes from logind: local, seated, active user sessions that are graphical (x11, wayland, mir) or a text login running X (startx); who only where loginctl can't be asked. The display and the session type come from the account's own logind session, and only that session's processes (its session-<Id>.scope) supply the cookie and the bus, so a leftover from the last login can't win.
  • Sharing it (screen-share.ts, screen-helper.ts). No extra service. While the screen is set up the server checks every three seconds: it starts TigerVNC's x0vncserver (X0tigervnc on Debian and Ubuntu) on a private socket with no TCP port when the session appears, and stops it when the session ends or the account is no longer at the screen. Nothing runs at the login screen. The socket is named after the server's data folder, so two servers on one account don't collide. A helper that ignores SIGTERM gets SIGKILL and is forgotten only once it has exited. The same relay and ownership checks as the virtual desktop apply.
  • Only its own account. With someone else at the screen, setup refuses in one sentence and offers the virtual desktop. No root, no crossing accounts.
  • A notification on that screen when a viewer connects, at most one every 30 seconds. Nobody has to approve.
  • Command line. codevisor desktop setup --screen, status lists both, remove --screen. Documented in apps/server/README.md.
  • Relay. Picks the display by id; a viewer can't resize the real screen; a viewer is disconnected with a fitting message when the session ends or the screen is removed.
  • serve-boot.ts was near the 500-line cap, so the Linux desktop start-up wiring moved to desktop/desktop-boot.ts.

What the apps need (checked, not changed)

  • The reply now lists displays that can't be viewed under unavailable, each with its reason. The apps don't show it yet; they still show the reason when nothing can be viewed. Worth adding with 851-4498.

  • Listing and opening a second VNC display needs nothing. The Mac and iPhone apps take the display list from the server, show a picker when there is more than one, and open the socket by display id.

  • One gap, filed as 851-4498: picking another display while a VNC connection is live only takes effect at the next connect. The in-session switch exists only for Mac hosts, and the connection restarts for a display change only when it is already reconnecting. I left the Swift change out: it needs a look in the running app, and this Mac's screen is locked.

Not in this PR

  • wlroots (Sway, Hyprland). Not built. There is no real wlroots login to test against here, and I did not get to trying headless Sway. A Wayland session is detected and refused with a sentence, before anything is installed. Second PR.
  • GNOME and KDE on Wayland (step 9), resizing, the Mac app's setup UI (step 4), the app-side display switch (851-4498).

Proof

An OrbStack Ubuntu 24.04 machine with a real display manager login: LightDM greeter, password typed at the greeter, Xfce session. There is no GPU, so Xvfb stands in for the X server and plays the monitor. The server runs as alice, built from this branch. The viewer is a scripted VNC client that connects through the server's WebSocket relay. Run on the final code.

The VM has no virtual consoles, so logind first refused LightDM's session ("Seat has no VTs but VT number not 0"). A test-only PAM line in the VM reports VT 0, and the login then becomes a real logind session (Seat=seat0, Class=user, Type=x11), as on a workstation. Who is at the screen in this run comes from logind, not who.

The real screen, captured inside the VM with import -window root, after the viewer clicked into alice's terminal and typed a command through the relay. The notification is the one a viewer's arrival shows:

The real screen inside the VM

The same screen as the viewer received it through the relay (display vnc:screen):

The screen as received through the relay

After alice logged out: the login screen, which is not shared.

After logout

The session, as run:

=== 1. Nobody is logged in at the screen. The server runs as alice.
$ codevisor desktop setup
==> Checking this machine
    Ubuntu 24.04.5 LTS, no desktop set up
==> Starting the desktop as alice
==> The desktop is ready. Open it from this machine in Codevisor.
$ codevisor desktop setup --screen
==> Checking this machine
    Ubuntu 24.04.5 LTS, nobody is logged in at this machine's screen
==> Set up. The screen is shared whenever alice is logged in at this machine, and nobody is right now.
$ codevisor desktop status
The desktop is running as alice on display :1.
It starts at boot.
Log: journalctl --user -u codevisor-desktop
The screen is set up to be shared, but alice isn't logged in at it.
displays the apps are offered: [('vnc:desktop', 'Desktop')]
$ cat ~/.codevisor/data/screen-sharing.json
{
  "displays": [
    {
      "id": "desktop",
      "vnc": {
        "socket": "/run/user/1000/codevisor-desktop.sock",
        "display": 1,
        "xauthority": "/run/user/1000/codevisor-desktop.xauth",
        "name": "Desktop",
        "desktop": "xfce",
        "defaultSize": "1440x900"
      },
      "service": "systemd-user"
    },
    {
      "id": "screen",
      "vnc": {
        "socket": "/run/user/1000/codevisor-screen-00fed9c716f4.sock",
        "name": "Screen"
      },
      "service": "server"
    }
  ]
}
=== 2. alice has logged in at the greeter (LightDM, Xfce session on display :0)
c1 1000 alice seat0 tty7 active no -
$ codevisor desktop status
The desktop is running as alice on display :1.
It starts at boot.
Log: journalctl --user -u codevisor-desktop
The screen (X11, display :0) is shared as alice.
helper: X0tigervnc -display :0 -rfbunixpath /run/user/1000/codevisor-screen-00fed9c716f4.sock -rfbunixmode 0600 -rfbport -1 -localhost -SecurityTypes None -AcceptSetDesktopSize=0 
srw------- 1 alice alice 0 Nov 26 19:31 /run/user/1000/codevisor-screen-00fed9c716f4.sock
TCP ports the helper listens on: 0
displays the apps are offered: [('vnc:desktop', 'Desktop'), ('vnc:screen', 'Screen')]
=== 3. A viewer connects to vnc:screen through the server's relay, looks, clicks and types
connected through the relay: "alice@cv-step8" 1440x900
connected through the relay: "alice@cv-step8" 1440x900
=== 3b. A second Codevisor server on the same account (its own data folder, no screen set up) runs beside the first
after 10 s of both servers following the screen:
srw------- codevisor-screen-00fed9c716f4.sock
displays the apps are offered: [('vnc:desktop', 'Desktop'), ('vnc:screen', 'Screen')]
connected through the relay: "alice@cv-step8" 1440x900
=== 4. Another server on the same machine runs as bob, while alice is the one at the screen
$ codevisor desktop setup --screen   (as bob)
==> Checking this machine
alice is logged in at this machine's screen, and Codevisor runs as bob here, so it can't share that screen. Set up a separate desktop instead: codevisor desktop setup
    Ubuntu 24.04.5 LTS, alice is logged in at this machine's screen
exit code 1
config: ls: cannot access '/home/bob/.codevisor/data/screen-sharing.json': No such file or directory
=== 5. alice logs out while a viewer is connected
connected through the relay: "alice@cv-step8" 1440x900
the relay closed 1005 
logind sessions at the screen: 1
helper process 984: gone
socket: ls: cannot access '/run/user/1000/codevisor-screen-*.sock': No such file or directory
$ codevisor desktop status
The desktop is running as alice on display :1.
It starts at boot.
Log: journalctl --user -u codevisor-desktop
The screen is set up to be shared, but alice isn't logged in at it.
displays the apps are offered: [('vnc:desktop', 'Desktop')]
$ codevisor desktop remove --screen
The screen is no longer shared. Nothing on it was closed.
displays left in the config: ['desktop']

Third round, also in the VM: alice logged in, a tmux was started from inside the session (Alt+F2), she logged out (that session stays closing with the tmux in its scope) and logged in again. The screen was shared again from the new session (Id=c4, Display=:0) with two older sessions still closing. This run also showed a tmux with DISPLAY=:0.0 against logind's :0, which the server now treats as the same display.

Also seen in this run: after logout, logind keeps alice's session in closing (processes outliving the logout), and the server correctly says she isn't at the screen. Step 3b runs a second server on the same account beside the first; the first one's socket survives and its viewer still connects.

Package names were checked by installing them in containers, one at a time: Fedora tigervnc-x11-server + libnotify, Arch tigervnc + libnotify, openSUSE Tumbleweed and Leap 15.6 xorg-x11-Xvnc + libnotify-tools all gave both x0vncserver and notify-send. On openSUSE, tigervnc-x11vnc is only an x11vnc-style wrapper; x0vncserver itself is in xorg-x11-Xvnc.

Not proved here: a physical monitor or GPU, several monitors, GDM or SDDM, the startx path, a login on Fedora, Arch or openSUSE, and the Mac and iPhone apps.

Tests

  • screen-sharing-config.test.ts: both config forms, adding and removing an entry, what isn't shared.
  • screen-session.test.ts: which processes count as the account's session, and who is at the screen.
  • screen-share.test.ts: set up, wait, follow login and logout, a moved display, refusals, logind's session type, a helper on the network or unchecked, an account that left the screen, a gone socket, a helper that ignores SIGTERM, a helper that dies right after starting, its own socket, another server's socket left alone, an unreadable config, removal.
  • screen-share-notices.test.ts: the notification, the install (one at a time, failures, sudo only when asked, a fresh program list).
  • screen-packages.test.ts: the openSUSE screen install run in sh against a fake zypper, for its exit codes.
  • vnc-relays.test.ts: the notification fires once the relay reaches the screen's VNC server, not before.
  • vnc-displays.test.ts: two displays listed, relayed each to its own server, no resize of the screen, messages when the screen goes.
  • desktop-screen.test.ts, desktop.test.ts (routes), desktop-manager.test.ts: the command line, the routes, and the desktop keeping the screen's entry.

Review

Third review round (the reviewer's seven), all fixed: the session taken from logind; each display's problem reported on its own (unavailable in the reply, and the old message when nothing can be viewed); computer-use-stream-v1 only for a display other than the real screen; text-console logins don't count, startx does; a failing screen check leaves the desktop routes working; "shared" only while the account is at the screen; the README's socket example. The code-review run on that found more, also fixed: only active sessions count, the who fallback matched by display, :0.0 equals :0, remove --screen stops the helper first, the retry wait doesn't hold back a new login, and the failure names each display when none can be viewed.

Second review round (the reviewer's ten items), all fixed: per-folder socket and only touching what it owns; logind trusted over who; SIGKILL escalation; presence checked while sharing; package names checked in containers; one install at a time; unknown config keys carried over; a clearer message when the first start fails; the notification on connect; fewer checks per status. The code-review skill on that result found five more and three small ones, also fixed: the program list after the command line's own install, logind's session type, zypper's exit codes for the screen install, a config that doesn't parse left alone, the helper found by its own socket, sudo checked only for the screen flow, a back-off for a helper that dies right after starting, and no setup --screen hint on Wayland.

First round:

Ran the code-review skill on the branch before opening this. Ten findings, all fixed in the third commit: the screen's install has its own sudo and progress and runs in the background; Wayland is refused before installing; a helper whose ports can't be checked is stopped; processes left by an ended session and sessions that are ending no longer count as someone logged in; the helper uses the socket recorded at setup; the messages name the right command and the right display.

🤖 Generated with Claude Code

pondorasti and others added 8 commits November 26, 2026 20:47
The server's config holds a list of displays. While the screen is set
up, the server follows its own account's graphical X11 session: it
starts TigerVNC's x0vncserver on a private socket when the session
appears and stops it when the session ends. The relay, the display list
and `codevisor desktop setup/status/remove` know about the second
display.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
- The screen's package step has its own sudo, busy and failure, runs in
  the background like the desktop's, and names its own command to run
  again.
- A Wayland session is refused before anything is installed.
- A helper whose ports can't be checked is stopped, not shared.
- Processes left behind by a session that ended don't count as someone
  logged in: the account must also be among those at the screen.
- Sessions that are ending don't count as someone at the screen.
- The helper listens on the socket recorded at setup.
- Viewers get a message that fits the screen when it goes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
- Each server names its screen socket after its data folder, and only
  removes a socket it recorded or a helper it started. A helper whose
  socket has gone is started again.
- Who is at the screen comes from logind; who is asked only where
  loginctl can't be, so a remote X session doesn't count.
- A helper that ignores SIGTERM gets SIGKILL and is forgotten only once
  it has exited.
- While sharing, the account must still be at the screen.
- One screen install at a time; logind asked once per status; program
  checks reused for 30 seconds.
- Rewriting the config keeps keys it doesn't know.
- setup --screen says a screen that isn't shared yet is set up and will
  be tried again.
- The viewing notification fires once the relay reaches the screen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Found by the code review of the previous commit:
- The program list is kept only when nothing is missing, so an install
  setup --screen ran itself shows at once; sudo is checked only when the
  screen's setup asks.
- logind's session type decides X11 or Wayland.
- The screen's zypper install accepts zypper's "installed, but" exit
  codes, and pacman's messages name the screen's own command.
- A screen-sharing.json that isn't a config is left alone.
- The helper is found by the socket on its own command line.
- A helper that stops right after starting is retried after 30 s.
- desktop status doesn't suggest setup --screen on Wayland.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roblem

Third review round on 851-4496:
- The session is taken from logind: its display, and the processes of
  that session only, so a leftover from the last login can't win. Where
  logind can't be asked, only live displays count, newest first.
- Only graphical logind sessions, or a text login running X (startx),
  count as someone at the screen.
- A display that can't be viewed is reported on its own (`unavailable`
  in the reply); when none can be, the reply fails with the first one's
  reason, the desktop's when it has one.
- computer-use-stream-v1 is listed only for a display other than the
  real screen.
- The desktop routes answer without the screen if looking at it fails.
- The screen is called shared only while the account is at it.
- README: the socket name in the example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seen in a VM: a tmux started from the session carries DISPLAY=:0.0 while
logind reports :0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Only active logind sessions count as at the screen, so a session
  switched to the background doesn't, and an account's active session
  is the one used.
- Where logind can't be asked, the display who records picks the
  processes, with or without XDG_SEAT.
- A helper isn't restarted because :0.0 and :0 differ.
- remove --screen stops the helper first and fails if it can't.
- The retry wait after a failed start doesn't hold back a new login.
- When no display can be viewed, the failure names each one's reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4496-linux-desktop-step-8-view-and-control-a branch from 35c6569 to 90e7d7f Compare November 27, 2026 05:09
@pondorasti
pondorasti merged commit c4856ad into main Nov 27, 2026
@pondorasti
pondorasti deleted the alexandru/851-4496-linux-desktop-step-8-view-and-control-a branch November 27, 2026 05:11
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