One codebase builds the Mac app and the iPhone and iPad app. Almost all of it lives in a Swift package; the app targets only create the model and show the package's scenes.
Apps/
macOS/, iOS/ @main, Info.plist, entitlements
Shared/ Assets, App Intents
iOSUITests/ Interface tests that drive the app with touches
Packages/OpenScreensKit/
Sources/
OpenScreensCore/ Everything that is not interface
OpenScreensUI/ SwiftUI, the session controller, the two canvases
RFBTestServer/ A small screen-sharing server for tests and demos
DemoServer/ `openscreens-demo-server`, which runs it
Tests/
Packages/RDP/ The Remote Desktop client
Vendor/rootshell-vnc/ The protocol engine
The engine (Vendor/rootshell-vnc) speaks RFB and Apple's Screen Sharing
extensions: authentication, the adaptive codecs of Standard mode, the HEVC
stream of High Performance mode, sound, the clipboard. It is
rootshellVNC, vendored because
OpenScreens draws the picture in its own views and needs a few things the
package keeps to itself. The first commit under that directory is an
upstream release untouched, and a later release is taken in as one commit
named for it. Every local change is its own commit, prefixed engine:, so
git log -- Vendor/rootshell-vnc is the list of differences.
OpenScreensCore has no interface and no engine session in it, which is what makes it testable:
| Folder | What is in it |
|---|---|
Models |
Computer, ConnectionSettings and friends. Every enum decodes leniently, so a library written by a newer version still loads. |
Store |
LibraryDocument (the file format and the merge), LibraryStore, preferences, and the keychain. |
Sync |
CloudSyncEngine, which mirrors the library to iCloud key-value storage. |
Discovery, Tailscale |
Finding computers: Bonjour through dns_sd, and the tailnet through Tailscale's API or local app. |
SSH |
Client, tunnel, SFTP, private keys, known hosts. Built on SwiftNIO SSH. |
Input |
Keysyms, key codes, and HardwareKeyboard, which decides what a key press means to the remote computer. |
Geometry |
Viewport: fit, fill, zoom, pan, and mapping a point in the view to a point of the picture. DisplayArrangement: where two displays go in the picture, and which remote pixel a point of it stands for. SessionChromeLayout: where the picture and the controls go on a touch screen, from what the screen keeps content clear of. |
Network |
Address parsing, links, Wake-on-LAN. |
OpenScreensUI is the app:
AppModelowns the library, preferences, credentials, discovery, sync and the open sessions. There is one, shared by every window and by App Intents.RemoteSessionsits between the interface and the engine for one connection. It decides when to ask for a password or show a host key, turns settings into an engine configuration, and is the only way input reaches the remote computer — which is what makes "observe only" absolute.RemoteCanvasis two views with one job, anNSViewand aUIView. Each hosts the engine's video layers directly and turns its platform's events into calls on the session. Nothing about gestures or key events leaks above them.FileBrowseris one SSH connection to a computer for its files: it signs in the way a tunnel would, lists folders over SFTP and runs transfers one at a time. It is independent of any screen-sharing session.FileTransferOverlayis the other way files move, with a Mac: a drag onto the canvas is passed on as a drag on the Mac's own screen, and the engine copies what is dropped. The overlay shows where to drag files for copying them back, and each copy as it goes.
The Remote Desktop client (Packages/RDP) is OpenScreens' own, and
nothing in it is tied to Apple's systems: it builds and is tested on Linux
too. Given a byte stream, it negotiates, starts TLS on it, signs in with
CredSSP and NTLMv2, joins the MCS channels, exchanges capabilities and
keeps the desktop as a framebuffer, decoding the planar and interleaved
bitmaps Windows sends. It turns key and pointer events into RDP's input,
and carries the clipboard and display-control channels.
It reaches the app through the engine. A TransportSession can run a
ForeignSessionDriver in place of its own RFB handshake and message loop,
and RDPSessionDriver in Core is one: what changed in the RDP client's
framebuffer goes up as raw framebuffer rectangles, the pointer as the
cached alpha cursors a Mac sends, the clipboard as text. So VNCSession,
the canvases, Picture in Picture, the statistics and reconnecting work the
same over either protocol, and RemoteSession only chooses the driver,
for a computer whose remoteProtocol is RDP.
A few things Windows does shape the client. Its self-signed certificate may only encrypt a key, not sign one, which BoringSSL holds a server to: such a server is reached with RSA key transport, tried when the modern suites are refused for it, and remembered. Unicode keys that arrive together get one another's character, so they are kept 30 ms apart from the keys around them. And a server that is going to end a session says why first; the client passes that on, and the engine does not reconnect to a session someone ended on purpose.
- The library opens a
RemoteSessionfor aComputerthroughSessionManager, which reuses one that is already open. start()looks for credentials and either asks or connects. With an SSH tunnel it builds a transport provider fromSSHTunnelFactory; the engine then makes its connection through that instead of dialling itself.- The canvas reports its size, and for a desktop that follows the window the
engine asks the Mac for a virtual display of that size — or two, each half
of it. A view smaller than a Mac's screen gets a desktop of its shape,
scaled up to a minimum the computer's settings choose: 720 points across
by default, 1024 for more space. A Mac does not say when it will not make
a display that small, so once the resize has settled the session checks
what it was given.
A computer that is not a Mac is asked another way, and only where its
server has said it lets a client resize its desktop: for one of
StandardDesktop's choosing, at one pixel to a point, since such a desktop is not drawn at twice its size. - Pointer events are mapped through
Viewportto the picture and throughDisplayArrangementto remote pixels. Key events go throughHardwareKeyboard. - Ending the session releases every key and button that is down first, so nothing is left stuck on the other side.
A VNC server is signed in to the way it asks. The engine chooses among what the server offers: RSA-AES, which RealVNC and wayvnc speak, where it encrypts the whole session; VeNCrypt with TLS; an encrypted sign-in before a plain one; and a VNC password.
A server that encrypts its connections does it with a certificate or a key
that nobody has signed. The engine hands either to RemoteSession, which
makes a ServerIdentity of it and asks a KnownHostsStore of its own, as
it does for the SSH server of a tunnel: unknown is the user's to judge, on
record goes through, and anything else for the same computer is shown as a
change. The answer travels back to the engine before a password is sent.
The Mac app updates itself. Sparkle does the
part that must not be got wrong: it reads the feed of releases, downloads
one, checks the signatures, puts the app in place and opens it again. None
of what the user sees is Sparkle's. SparkleUpdater hands each step to an
UpdateModel, and the notice above the library, the sheet with the release
notes and the pane in Settings are drawn from that. UpdateModel knows
nothing of Sparkle, which is what lets its rules be tested: what the user
asked about is shown at once, and what was found in the background waits
beside a session instead of in front of it.
On iPhone and iPad updates are the App Store's and TestFlight's, and the
model has nothing behind it. What both platforms share is what comes after:
the app carries a copy of CHANGELOG.md, and the first launch of a new
version shows what it says about the releases since the one last seen.
scripts/release-mac.sh writes the feed, appcast.xml, signs it and the
disk image with the project's update key, and scripts/publish-mac.sh
attaches it to the release, where installed copies look for it.
A key press becomes a KeyStroke: what the key types on the local layout
with the modifiers held, what it types without Option, and which key a
Command shortcut would call it. The Mac canvas gets those from the keyboard
layout itself and combines dead keys; the iOS canvas gets them from UIKey.
HardwareKeyboard turns strokes into key events, differently for the two
kinds of remote computer:
- A Mac types exactly the character it is asked for, adding or cancelling
Shift and Option to do it. So it is sent the finished character —
Ω, not Option andz— which arrives as the same key press when the layouts match and as the same character when they do not. With Command held it leaves the modifiers alone and is sent the key the shortcut names. - Anything else holds modifiers the usual RFB way. Option is Alt, but is only sent once something needs Alt, and never when it merely typed a symbol that the local layout keeps behind Option.
"Key Positions" sends virtual key codes to a Mac instead and lets its layout decide. apple-screen-sharing-notes.md has the measurements behind these rules.
The library is one JSON document: computers, groups, and a record of what was deleted and when. Two copies are merged item by item — the later edit wins, and a deletion wins over an edit made before it. The merge does not depend on which copy is which or on the order copies arrive in, which is what lets devices converge through a store as simple as iCloud key-value storage. A few rules keep that honest:
- Dates are stored exactly. Rounding them could change what a merge decides after a relaunch.
- A change is always stamped later than what it was made from, even if that came from a clock running ahead.
- Connecting is not an edit. The time of the last connection is settled on its own, so connecting from a device that is behind cannot undo a change made elsewhere.
- A tie is settled by comparing the items' bytes, the same way on both sides.
Passwords, SSH keys and access tokens are never part of the document. They
live in the keychain, behind SecretStorage.
- Unit tests cover Core: the merge is checked against a written-out specification over generated libraries, and the keyboard rules are pinned one by one.
- End-to-end tests run a real
RemoteSessionagainstRFBTestServeron loopback and check what arrived. - SSH tests start a private, unprivileged
sshd. - Interface tests launch the iPhone app pointed at a server the test runs, and drive it with touches and key presses.
- Engine tests are upstream's, plus those for the local changes.
- RDP tests (
swift test --package-path Packages/RDP) check NTLM against [MS-NLMP]'s worked example, the planar codec against tiles a Windows 11 server sent and the interleaved one against bitmaps FreeRDP encoded, both as FreeRDP decodes them, and every PDU the client writes or reads.rdp-probe, in the same package, connects to a real server from the command line, signs in, runs a script of keys and clipboard and saves the picture. - The compatibility lab opens sessions to real VNC servers in a
container and looks inside it at what arrived. It needs Docker and is run
by hand:
scripts/compat-lab.
Debug builds read a few environment variables at launch — open this address,
type this, press these keys, write a report — so a session with a real
computer can be scripted. DebugAutomation.swift documents them.