Platform backends (platform package)
The platform package is the toolkit's window, input, clipboard, cursors and desktop services, behind one neutral
API (no system types in the public signatures). Each system has a backend chosen at build time by file suffix
(*_win32.fm for Windows, *_linux.fm for Linux), and the pure, shared logic (clipboard conversions, HTML-format
headers, drag helpers, dialog filters, the chrome hit test, cursor shapes) lives in files with no suffix.
A program written against this API — the toolkit's ui and render, and an application such as Wren — does not name
Win32 or Wayland. It opens a window, polls events, draws, and asks for services, the same on every system.
| Backend | Window / input | Clipboard | Dialogs | Cursors | DPI | Decorations |
|---|---|---|---|---|---|---|
Windows (*_win32.fm) | Win32 messages | OLE + CF_* | IFileDialog | IDC_* / drawn | per-monitor v2 | DWM + integrated title |
Linux Wayland (window_wl_linux.fm) | xdg-shell + wl_seat (xkbcommon) | wl_data_device | portal / zenity / kdialog | wp_cursor_shape_v1, else libwayland-cursor | wp_fractional_scale_v1 with wp_viewporter, else the wl_output integer scale | zxdg-decoration, or the app's integrated title |
Linux X11 (window_x11_linux.fm) | XCB + xkbcommon | CLIPBOARD selection | portal / zenity / kdialog | libxcb-cursor, else the server's cursor font; custom images through RENDER | Xft.dpi | Motif hints |
The neutral types (what a backend fills, what the app reads)
Window=Native_Window(per-backend state, onerawptrper backend so the struct carries no system types) + the fields every backend fills:size(physical pixels),dpi_scale(dpi/96),focused,active,events,chrome,user,on_frame.Event(Event_Kind:Key_Press/Release,Text,Mouse_*,Scroll,Close,Activate,Pointer_*,Drop_*,Accessibility,Hotkey,Notification_*,Clipboard_Data), withposin client pixels,deltain wheel notches (+yscrolls content down),scroll_source(Scroll_Source:.Wheelor.Finger, fingers on a touchpad) andscroll_end(the fingers left it) (wheel.md),mods,buttons,stamp,pointer,injected.Key,Mouse_Button,Modifier,Cursor(named after the CSS keywords),Display_Info(refresh rate for pacing),Chrome_Regions(the integrated title bar's regions, hit-tested byhit_test_chrome),Placement(outer rect + maximized).
What a backend must provide
A new backend implements this set (the Win32 and Linux backends both do). Procedures that cannot apply to a system are no-ops with a sane return, never an error.
Lifecycle — open_window, open_window_offscreen, show_window, destroy_window, set_title, set_size,
is_closed, cancel_close (the app answered a Close by staying open), is_offscreen, gdi_presents / set_gdi_presents (Windows: whether open_window and open_overlay keep a GDI redirection surface for Vulkan instead of setting WS_EX_NOREDIRECTIONBITMAP for DirectComposition; render.backend_choose sets it before the first window opens).
can_hide_windows(): whether a window can exist unseen, made and never shown (Windows); on Wayland and X11 it cannot, and a
program that needs an unseen window opens an offscreen one.
hide_window(w) takes a shown window off the screen and show_window(w) brings it back, its size, title and interface
kept: a program that lives in the notification area hides its window instead of closing it, and shows it again in a few
milliseconds (no new device, fonts or state). A window with a renderer goes through the host (host.host_hide,
host.host_show), which releases the renderer's surface first. Draw no frame of a hidden window (on Linux a frame would
wait for a screen the window is not on); its wait still ends on a wake, a post and the tray. wait_deadline_set(ms, call,
user) gives the thread's waits one deadline: every wait_event on that thread sleeps no longer, and the first wait that
ends past it calls call(user) once, between frames (wait_deadline_clear(user) takes it back): how the host rests the
renderer of a program whose windows are all hidden. Wayland: the toplevel role
and the surface go, and show_window makes new ones and waits for their first configure, so the compositor places and
focuses it as a new window. (The role alone is not enough: the last frames' content updates may wait in the surface's
queue behind a FIFO barrier of wp_fifo_v1 that an unmapped surface never clears, and every later commit with them.)
X11: unmapped (withdrawn). Windows: SW_HIDE.
A window opened and not yet shown is hidden too, and gets no frame either. Wayland: it is a surface with no role (the
renderer makes its surface on it); its toplevel is made at the first show_window, so a window never shown is in no
task bar (ShojiWM lists every toplevel, even one with no picture yet). set_maximized and set_fullscreen asked before
that show are asked by the new toplevel; minimize is asked once its first configure came. Window.shown_again counts the shows after a hide: the host makes the
renderer's surface again at the next frame (render.surface_remake).
raise_window(w) brings a shown window to the front with the keyboard focus. X11: _NET_ACTIVE_WINDOW. Wayland:
xdg_activation_v1, a token with the seat's last input serial the connection saw (0 when it saw none), spent on the
window's surface; the compositor decides. A compositor that does not focus a new window by itself (ShojiWM's Windows 7
configuration) gives the focus this way: call it after show_window when the user asked for the window. A second start of the
program brings the first one's window up with the token its launcher gave it: activation_token_from_env() in the second
(Wayland's XDG_ACTIVATION_TOKEN, X11's DESKTOP_STARTUP_ID, taken out of the environment), handed to the first, which
calls raise_window_token(w, token) (Windows: raise_window). Windows: raise_window restores a minimized window, then
SetForegroundWindow, which the system grants when the process may take the foreground: the second start allowed the first
(AllowSetForegroundWindow in instance), and a copy started by setup.launch was allowed by the one it replaces.
Identity — set_app_id(id), once before the first window: on Linux, the windows' Wayland app_id and X11 WM_CLASS.
The desktop finds the program's <id>.desktop by it, for the icon and the name in a task bar. Without a call, the id is
the executable's file name. On Windows it does nothing. There, every window of the program (main, secondary, overlay) takes
the executable's icon (resource 1, at the sizes of the taskbar and of the title: hIcon and hIconSm of the window
class), and the process declares the AppUserModelID of its build (-define:GT_AUMID, project_aumid of trame:toolbox)
before the first window, unless the program declared one already (desktop.set_process_identity, notify_set_app). app_user_model_id(publisher, name) is
the rule both derive the id with: each in PascalCase of ASCII letters and digits, joined by a dot (Froment Software,
opencode native: FromentSoftware.OpencodeNative).
State — minimize, toggle_maximize, set_fullscreen, request_close, is_maximized, is_minimized,
is_fullscreen, is_window_visible, is_window_occluded, set_integrated_title / is_integrated_title, system_title_available, set_chrome_regions, show_system_menu,
set_caption_menu_app, system_menu_available,
needs_top_border, needs_frame_outline, resize_border, set_backdrop, set_square_corners, set_border_color, set_dark_title,
set_offscreen_dpi, set_offscreen_active.
On Windows, is_window_occluded detects hidden, minimized, DWM-cloaked, and z-order-covered windows via
SetWinEventHook and an opaque rectangle-union walk (Occlusion_Rect, occlusion_rect_covered,
occlusion_rect_empty, occlusion_rect_contains, occlusion_rect_intersects, occlusion_rect_inset,
occlusion_hook_register, occlusion_hook_unregister), pausing animations in trame:host while covered and waking
immediately when uncovered. AltGr on European Windows keyboard layouts is filtered (AltGr_State, AltGr_Key,
Key_Mod_State, altgr_reset, altgr_step, altgr_filter_mods) so Right Alt does not report Ctrl+Alt.
Where it is — window_output_name(w): the monitor the window is on, by the name trame:capture gives outputs
("DP-2", "\\.\DISPLAY1"). Wayland says it with wl_surface.enter, after the window's first picture; two monitors of the
same size are told apart by it, where a window's size cannot. "" before then, and on X11.
An offscreen window's machine (virtual.fm) — virtual_screen_set, virtual_screen: the screen monitor_size and display_info answer for it; its input comes through inject_event, its cursor is w.cursor, its clipboard the process's store: nothing of the machine it runs on is read or written.
Loop — poll_events (re-entrancy safe; drops what the last call returned, keeps what came since), wait_event,
wait_handle (waits on a handle while taking input; render.wait_frame_slot uses it for the frame-latency object), take_paint_request, take_wake, pump_stats, wake,
wake_handle / wake_signal (a thread-safe wake handle for offscreen windows), inject_event.
Placement — outer_rect, client_origin, move_window, get_placement, set_placement. positions_known(w):
whether the system gives this window its place and the pointer's on the screen (Windows, X11, offscreen: yes; Wayland:
no), asked at run time.
move_to_active_monitor(w, follow) puts a window on the monitor the user works on, at the same place of its work area
(rect_on_work, rect_on_work_dpi for mixed-DPI monitors): with .Pointer (the default) the monitor under the pointer, with .Focus the one of the window in front
(the pointer's when there is none; active_monitor_parse reads "pointer" or "focus"): a program called up by a shortcut or a
notification area icon calls it before it shows its window. Windows; elsewhere the system places what it shows.
Display — display_info, display_invalidate, display_live_hz, monitor_size (the window's monitor in pixels,
for a screen-sized fixed surface). display_info is the rate of the monitor the window is on, read again when it moves
to another one or its mode changes (its serial changes, and render.pace_frame replans): Windows the window's monitor,
X11 the RandR monitor under the window's middle, Wayland the outputs the surface entered (wl_surface.enter), the
highest rate when it is on several, the first output's before it is on any. A frame after a rest takes one refresh of
that rate as its dt (host) when the renderer measures none (a server without the answers below).
Vblank timing (vblank.fm) — vblank_timing(handles) says what the display server said of a window's pictures
(Vblank_Timing): the vblank the last one shown reached the screen at (on std:temporal's tick clock), the output's
refresh counter there, the period (the server's, else measured), the lead (how long before a vblank a present must be
made to be shown at it, learned), and the pictures shown and discarded. The renderer calls vblank_ask just before each
present and reads the answers at the next one: render.measured_refresh_hz, render.vblank_grid,
render.present_totals (shown, missed) and the start just in time (pacing.md) take the server's numbers.
Wayland with wp_presentation; X11 with the Present extension (PresentCompleteNotify, selected on each window), when
the Vulkan driver presents with it: a software one (lavapipe) draws with PutImage, and nothing comes. Zeros without them.
Windows reads its compositor itself (the procedures answer nothing there). A discarded picture is not a missed refresh:
a window that presents faster than the screen has some by design. vblank_presented, vblank_discarded and
vblank_lead_learn are the pure updates, for a test. The answers end no wait of the loop. Design:
src/md/infrastructure/vblank.md.
Cursors — set_cursor, set_cursor_custom, cursor_info, cursor_source, cursor_scheme, cursor_size_px,
cursor_render, shown_cursor, cursor_handle_of, custom_cursor_create / _release / _valid / _stats /
_info, cursors_destroy.
Text clipboard — get_clipboard, set_clipboard. Rich clipboard (clipboard.fm) —
clipboard_request (a read that does not wait: a Clipboard_Data event answers it), clipboard_set / _get_image /
_get_html / _get_files / _formats / _sequence / _watch / _changed.
Dialogs and shell — open_file_dialog, save_file_dialog, pick_folder_dialog, known_folder_path, open_url,
open_path, reveal_in_folder. file_roots() (a system call: off the interface's thread) is where the file system starts:
the drives on Windows, / elsewhere (the file browser's places). launch_detached(args) (Linux) starts a program and does not wait for it, its output
nowhere: xdg-open, an application of "Open with" (desktop.open_with).
System — user_dir, session_runtime_dir, system_font_path, os_animations_enabled, app_icon_rgba.
A program's folders (user_dir.fm) — user_dir(kind, program) is where a program keeps what it keeps, one folder of its own
per kind, the same call on every system (program ""; the folder every program's is in). Nothing is made: the program makes it
when it writes there. program is its vendor's folder, then its own: APP_FOLDER :: "FromentSoftware" +
platform.USER_DIR_SEPARATOR + "Papier" (src/md/features/folders.md). user_dirs_move(from, to) moves a program's
folders once from an older name ("papier") to it: call it at start, before anything reads them and before any window;
it returns how many folders moved and the first that could not. kinds (USER_DIRS_MOVED: every kind but Runtime)
leaves a kind where it is: an older install in the data folder, which its menu entry names, stays with {.Config, .State,
.Cache}.
User_Dir | Linux | Windows | macOS |
|---|---|---|---|
.Config (its settings) | $XDG_CONFIG_HOME/<program> (~/.config) | %APPDATA%\<program> | ~/Library/Application Support/<program> |
.Data (what it made and keeps) | $XDG_DATA_HOME/<program> (~/.local/share) | %LOCALAPPDATA%\<program> | ~/Library/Application Support/<program> |
.State (logs, crash reports, what it remembers between runs) | $XDG_STATE_HOME/<program> (~/.local/state) | %LOCALAPPDATA%\<program>\state | ~/Library/Application Support/<program>/state (logs: ~/Library/Logs/<program>) |
.Cache (what it can make again) | $XDG_CACHE_HOME/<program> (~/.cache) | %LOCALAPPDATA%\<program>\cache | ~/Library/Caches/<program> |
.Runtime (sockets, pipes, what lasts a session) | the session's (session_runtime_dir)/<program>, else <$TMPDIR or /tmp>/runtime-<uid>/<program> | the system's temporary folder (GetTempPath2W, else GetTempPathW)\<program> | $TMPDIR/<program> (macOS makes it the user's) |
A variable counts only when it is an absolute path, as the XDG specification says, on Windows too (%APPDATA%, %LOCALAPPDATA%):
a test or a portable copy points them elsewhere. Without them, Windows' known folders (SHGetKnownFolderPath).
The runtime folder is never one that another user can enter or make first. On Linux without a session's runtime folder,
user_dir(.Runtime, ...) makes runtime-<uid> in the temporary folder, closed to the others (fsx.private_dir). It gives
"" when another user made that name first, or when the name is a link. A program's folder in it needs no check of its own:
fsx.make_dirs is enough. user_dir can ask the system (a stat, a mkdir; on Windows, a known folder): call it from a
task. The decisions are in src/md/features/folders.md.
session_runtime_dir() returns (dir, ok): the session's own runtime folder, the one its services (gvfs, the portals,
D-Bus) use. On Linux it is $XDG_RUNTIME_DIR when that is absolute, else /run/user/<uid> when that is a folder of this
user closed to the others. ok is false when the session has none (Windows, a Linux session without a login manager).
A program that looks for gvfs's mounts reads <dir>/gvfs only when ok is true.
Network interfaces (net_interfaces.fm) — interface_addresses() lists every IPv4 and IPv6 address of every
interface, IPv4 first (Interface_Address: the interface's name, the family, the address and the netmask in network
order, up, loopback); interface_addresses_destroy frees the list. std:net's IP4_Address is addr[:4], its
IP6_Address is transmute([8]u16be)addr. Linux: the C library's getifaddrs. Elsewhere: an empty list for now.
Devices — input_devices, touch_max_points.
Hotkeys (hotkey.fm) — hotkey_register(w, id, hk), hotkey_unregister: a combination the system gives the
window wherever the keyboard is, as a Hotkey event whose hotkey is the id. hotkey_parse("Ctrl+Shift+V") and
hotkey_text read and write their text (Ctrl, Shift, Alt, Win, then a letter, a digit, F1 to F12, a named key, or a
single character for a key Key does not name: Hotkey.char, the key that types it on the user's layout, "Ctrl+Shift+ù").
That text is English, for a file. key_english(key) gives a key's name in English whatever the language in use
(Page Up, Enter, Num +): key_text's words before their translation, which a file a person also reads keeps
(ui.binding_store_text). key_text (key_text.fm) gives the text a person reads, in the language in use, of a
Key, a Hotkey or keys written in English ("Maj+Impr. écran" in French): commands.md.
ui.hotkey_field records one from the keys pressed (a click, then the keys): a key Key does not name comes as a
Key_Press with its character (Event.char).
Windows: RegisterHotKey (false when another program holds the combination). Linux: none (false): the compositor binds
shortcuts to commands. send_hotkey(w, hk) is the other way: it presses hk for whatever window has the keyboard (another
program's: a clipboard history pastes with Ctrl+V into the program it was called from). Windows: SendInput. Wayland: a
virtual keyboard of the seat (zwp_virtual_keyboard_v1, with a keymap that has the key alone; false when the compositor
has none); the window's thread calls it. X11: false.
send_wheel(w, notches) turns the mouse wheel for whatever window is under the pointer (a scrolling capture of another
program's window). Positive notches turn it down, towards the user: the content moves up, as to read further (a window
of the toolkit gets a Scroll with delta.y = +1 per notch). Each notch goes alone, as a real wheel sends it: programs
read one wheel message as one step. Windows: SendInput (MOUSEEVENTF_WHEEL, WHEEL_DELTA per notch). X11: XTEST
(buttons 4 and 5; false without libxcb-xtest or the extension), from the window's thread. Wayland: false: no protocol
lets a client drive the seat's pointer, only the RemoteDesktop portal (libei), which asks the person each session.
0 notches sends nothing: the answer says whether the wheel can be turned there.
Taskbar button (taskbar.fm): Taskbar button.
Drag and drop (dragdrop.fm), tray (tray.fm), accessibility (a11y.fm): optional; a backend that
has none keeps the shared stubs (neither Windows nor Linux), which answer "not supported".
Taskbar button
A window says three things on its button in the task bar or the dock (taskbar.fm; the reasons:
src/md/features/taskbar.md). Each call sets one part and answers whether it changed: a call
with the values the button shows already asks nothing of the system, so a program calls it where its state changes, or
at each build. Nothing waits: Windows' calls are messages to Explorer, Linux's is a D-Bus signal.
taskbar_progress(w, state, fraction = 0):Taskbar_Progress.None,.Normal,.Paused,.Erroror.Indeterminate;fraction(0 to 1, kept in thousandths) counts for the three with a bar.taskbar_badge(w, count, words = "", accent = TASKBAR_BADGE_RED): a count (0 takes it away).wordsis what a screen reader says of it ("3 sessions are waiting for you"; "": the toolkit's "3 waiting", translated).accent(0xRRGGBB) is the disc where the toolkit draws it.ui.taskbar_badge(w, count, words)gives the theme's accent: the badge takes a new theme at the next call.taskbar_attention(w, on, flashes = 0): asks the person to look at the window. It ends when the window becomes active; a window that is active already gets no attention (false).flashes(Windows): that many flashes, then the button stays lit; 0 flashes until the window is active.taskbar_state(w): what the button shows (Taskbar_State).taskbar_badge_pixels(count, size, accent)is the count's picture (RGBA, straight alpha),launcher_entry_body(uri, state)the Linux signal's body andwayland_attention_marks(current_desktop)whether Wayland's token is asked: pure, for a test.taskbar_offscreen_entry(w, on): an offscreen window's calls go to the bus (Linux), for a test.
platform.taskbar_progress(app.window, running > 0 ? .Indeterminate : .None)
ui.taskbar_badge(app.window, waiting, fmt.tprintf(i18n.tr(waiting, "%d session is waiting for you", "%d sessions are waiting for you"), waiting))
if asked { platform.taskbar_attention(app.window, true) }| Windows | Linux, Wayland | Linux, X11 | macOS | |
|---|---|---|---|---|
| Progress | ITaskbarList3: green, paused yellow, error red, indeterminate | the Unity launcher entry's progress: paused and error as normal, indeterminate not shown | as Wayland | none yet |
| Count | an overlay icon the toolkit draws (a disc in the accent, the number), its words spoken | the entry's count, drawn by the dock | as Wayland | none yet |
| Attention | FlashWindowEx | on KDE, GNOME and sway an xdg_activation_v1 token with no serial (the compositor marks the window), and the entry's urgent | UrgencyHint and _NET_WM_STATE_DEMANDS_ATTENTION, and urgent | none yet |
- Windows asks the taskbar only once Explorer sent the window
TaskbarButtonCreated(at its first show), and again with the whole state when Explorer restarts. A hidden window has no button; it gets the state when it is shown.taskbar_inject_button_created,taskbar_button_knownandtaskbar_overlay_shownare for tests. - Linux's entry is the program's, not a window's: it names
application://<app id>.desktop(set_app_id), and the window that changed last decides it. Its end clears the entry. KDE Plasma, Dash to Dock, Dash to Panel, Plank, Latte and ShojiWM's task bar read it; GNOME's own dash does not. An offscreen window sends nothing, so a program's tests do not reach the developer's dock;taskbar_offscreen_entry(w, true)sends it, for a test on a bus of its own. - Wayland asks the token only when
XDG_CURRENT_DESKTOPnames KDE, GNOME or sway, whose compositors mark the window: another compositor can grant it and take the focus. The attention cannot be taken back: the compositor ends it when the window is focused. A notification (notify) is the program's choice, not this API's.
The desktop's background
platform.set_wallpaper(path) -> Wallpaper_Result gives a picture (absolute path; a PNG or a JPEG) to the system as
the desktop's background: .Set, .Cancelled (the person said no), .Unsupported (no way on this system or
desktop: the program says so, or greys its menu item), .Failed (the file could not be read, or the system refused
it). It blocks until the system answers, and a portal may ask the person: call it on a worker. ui.wallpaper_set(path,
done, user) does that on the chores and calls done(user, result) at a later build.
| System | How |
|---|---|
| Windows | SystemParametersInfoW(SPI_SETDESKWALLPAPER), written to the profile and broadcast |
| Linux | the desktop portal's org.freedesktop.portal.Wallpaper.SetWallpaperFile (the picture's descriptor, no preview, the background only), which GNOME's and KDE's portals answer; no portal or no Wallpaper interface: .Unsupported |
| others | .Unsupported |
Differences the app should know
- A pipe whose reader is gone. On Linux and macOS a write to it raises SIGPIPE, which ends the process.
sigpipe_ignore()makes it an error of that write instead, and keeps a handler the program set itself. The Wayland backend calls it; a program that writes to a pipe or a socket of its own calls it too. Windows has no SIGPIPE: the procedure does nothing there. - Threads. A window's procedures run on the thread that opened it. Windows' messages are the thread's; on Linux each thread that opens windows has its own connection to the display server (its events, its seat's focus and serials) and its own session bus, so several apps of a process each run on a thread of their own. The process's resources (the clipboard store, the virtual screen of the offscreen windows, the window class) are locked or atomic (getting-started.md, "Where state lives").
- Window position. X11 and Windows report and set the outer rectangle. Wayland does not let a client know or set
its absolute position (the compositor places windows):
client_originis{0,0},move_windowis a no-op. Save and restore the size and the maximized state (both work everywhere), not the position, on Wayland. - The session's windows.
toplevels(w)lists the windows of the session, other programs' too (their app id, title, focus, minimized), andtoplevel_activate(w, id)brings one to the front: where the compositor offers wlr-foreign-toplevel-management (sway, Hyprland, niri, labwc, river, ShojiWM). Elsewhere (GNOME, KDE, X11, Windows) the list is empty: a program hides what needs it. - A window not shown. Wayland's compositor tells when it shows a window's picture (
wl_surface.frame), and a present in Fifo waits for that word about the last one: a window it does not show (covered whole, minimized, on another workspace) never gets it.frame_shown_ask(w), just before a picture is presented, asks for it;frame_shown_pending(w)says it has not come;frame_shown_forget(w)drops it when no picture was presented after all.hostpresents no picture while it is pending (the input is still read and built). The word asks for a repaint only when a picture waits for it (frame_shown_held(w)):hostsays so when it holds a picture, and when the loop finds a frame due (an animation) while the word is pending, so an animation goes on at each refresh with no input; a window at rest is not drawn again at each refresh. False and nothing elsewhere. A compositor may also keep the word for a window it shows (ShojiWM, counting a window on the wrong output, sent it once a second, and a Fifo barrier held the commit for good): on Wayland the renderer presents in a mailbox when the driver offers one (render.present_may_blockfalse), and thenhostwaits for the word at mostFRAME_SHOWN_PATIENCE_MS(250 ms) when it has a picture to show, and not at all after the user's input.frame_shown_waited_ms(w)says how long it has waited. - Decorations. Windows and KDE (zxdg-decoration) draw a server title bar; GNOME draws none — set an integrated
title bar (
set_integrated_title) and draw it yourself (the toolkit'sui.window_buttonsalready does, the same frame as Windows). X11 asks the window manager for no decorations through Motif hints when integrated.system_title_available(w)says whether the system can draw the title bar (Windows, X11, a Wayland compositor with zxdg-decoration): where it can, a program offers the choice (a preference "the system's title bar") and switches at any time withset_integrated_title;ui.window_buttonsdraws nothing while the title bar is the system's. - An integrated title bar's frame on Linux (
frame_linux.fm). Windows moves, resizes and maximizes a window from its hit test; Wayland and X11 leave that to the client. A left press on the caption becomes the compositor's move (xdg_toplevel.move, X11_NET_WM_MOVERESIZE), on a band along any of the four sides its resize, a double click on the caption maximizes or restores, a right click there opens the compositor's window menu (Wayland), and the pointer over a band shows the resize cursor. The app gets anEvent.Frame_Pressinstead of the press. On Wayland the bands are outside the window: a ring of 8 px around it, an empty subsurface that takes the pointer there only, and the window's geometry (set_window_geometry) its surface alone, so the compositor places and tiles the window without it. The whole window is the app's: a scrollbar along its edge is grabbed on its whole width. Only a free window has the ring (not maximized, full screen, tiled, nor framed by the compositor); X11, and a compositor withoutwl_subcompositororwp_viewporter, keep the bands inside the window. Where the window has no frame of the system's,needs_frame_outlineis true anduidraws a 1-pixel outline in the theme's border colour: not when the compositor chose server-side decorations, when it tiles the window (thetiled_*states: sway, Hyprland and niri draw their own border), when the X11 window manager reports_NET_FRAME_EXTENTS, nor when the window is maximized or full screen. Windows always has the system's. The app's menu of the title bar. A right click on the caption of an integrated title bar opens the system's window menu: Windows' (Restore, Move, Size...), the Wayland compositor's (
xdg_toplevel.show_window_menu). X11 has none: the click is the app's there.set_caption_menu_app(w, true)gives that click to the app on every system: aMouse_Pressand aMouse_Releaseof.Rightat that point (Windows:WM_NCRBUTTONDOWNoverHTCAPTIONis taken and captured, and theWM_CONTEXTMENUof its release is not given toDefWindowProc).ui.caption_right_clicked()says that such a click came on an empty part of the title bar this frame, and where; the app opens its own menu there.show_system_menu(w, pos)still opens the system's, from an item of that menu;system_menu_available(w)says whether there is one to open (Windows, Wayland; not X11 nor an offscreen window). Callset_caption_menu_apponce per window; the left button, the double click and the resize bands stay the system's.Formulaplatform.set_caption_menu_app(w, true) // in the build, after the title bar: if at, ok := ui.caption_right_clicked(); ok { ui.menu_open("caption_menu", at) }- DPI. Windows is per-monitor (physical pixels,
dpi_scale= dpi/96). Wayland iswp_fractional_scale_v1withwp_viewporter: the buffer has the scaled size, the surface the logical one; without them thewl_outputinteger scale. A window that the compositor has given no fractional scale yet takes the scale of the output it most likely appears on (its mode over its logical size): the one the compositor named, else the one of the program's window under the pointer or with the keyboard, else the last scale the compositor gave a window, else the output of most of its windows, else the first output's (src/md/infrastructure/wayland-scale.md). The first show waits for the first configure, and applies what came with it. X11 readsXft.dpi. - Translucency.
set_backdropis the Windows acrylic effect; on Linux a window is translucent when it was opened with an alpha surface (render.inittransparent), which the compositor blends — there is no extra effect to turn on, soset_backdropreports whether the window is translucent at all. - The clipboard change signal is cheap on Windows (a sequence number). On Linux it comes from
wl_data_deviceor XFIXES; an X server without XFIXES only tells a program when it loses the clipboard. - Libraries load at run time (
dlopen): a binary built for Linux starts on a machine missing libwayland-client or libxcb and prints which library is absent (it does not fail to link). The window backends needed: libwayland-client + libxkbcommon (Wayland), libxcb + libxkbcommon (X11; libxkbcommon-x11 refines the keymap).
Rendering on Linux
render draws with Vulkan on Linux; there is no Direct3D. The surface comes from the window's native handles:
- Wayland:
VK_KHR_wayland_surfaceon thewl_displayandwl_surface. - X11 (XCB):
VK_KHR_xcb_surfaceon the XCB connection and window.
A machine with no driver for its graphics card (an old card, some virtual machines) draws with lavapipe, Mesa's software Vulkan. See rendering.md and src/md/infrastructure/no-graphics.md.
Before its device, the renderer shows its first frame drawn on the CPU (render's CPU stage, rendering.md):
platform.show_pixels(w, bgra, size, opaque) puts premultiplied B, G, R, A pixels on the window until the renderer
presents its own (Wayland: a wl_shm buffer attached to the surface and committed, which maps the window; X11:
PutImage in strips under the largest request, on a mapped window). It returns false when nothing could be shown: a
surface whose role was not configured yet, a window not mapped, an offscreen window. platform.can_show_pixels(w)
says whether the window's system can, and platform.drop_pixels(w) releases what was kept once the renderer has
presented (on Wayland the buffer stays attached until then). On Windows the picture is a layered popup the window owns,
over its client area (UpdateLayeredWindow), for a translucent window as for an opaque one: it follows the window when it
moves, shows and hides with it, and lets input through.
The platform package exposes these handles for the renderer through native_surface_handles(w); render.init takes a neutral handle instead of a win.HWND so the same call opens the renderer on
every system. The present mode (Vsync: FIFO, a mailbox on Wayland; Tearing: IMMEDIATE, where the surface offers it), resize, DPI
and capture (src/render/capture.fm) are the Vulkan backend's (vk_window.fm), whatever the window's system.
Linux desktop services
Beyond the window, input and plain-text clipboard, the Linux backend now carries the full desktop services, behind the
same neutral API as Windows. Most ride a small D-Bus client (the dbus package — see docs/dbus.md), whose socket is
folded into the window loop's poll(2) so the bus is drained on the UI thread each pump. Every service degrades to a
sane fallback (or a no-op) when its desktop piece is absent, so a bare session still runs.
Rich clipboard (cross-process)
The clipboard owner is complete on both backends. Wayland (clipboard_wl_linux.fm): a full wl_data_source
offers every flavour the store holds (text, HTML, text/uri-list, image/png through the toolkit's codec: png.md), its send callback writes the bytes to the
fd the compositor hands over, cancelled releases it, and set_selection uses the last input serial; reading a
flavour another client owns dups a pipe, calls wl_data_offer.receive, and reads it. There is no primary
(middle-click) selection on Wayland (on X11 a copy owns PRIMARY too). X11 (clipboard_x11_linux.fm): SelectionRequest serves TARGETS,
TIMESTAMP, MULTIPLE and the MIME targets, with INCR for a payload too large for one property (a pasted image);
reading follows an INCR hand-off. clipboard_set / clipboard_get_image / _get_html / _get_files read a foreign
owner over the selection transport, in the best type it offers (an image as PNG, JPEG or BMP; files as text/uri-list or
GNOME's list: clipboard.md).
Drag and drop
dragdrop_linux.fm keeps the window's Dnd_State and the API; the transports are Wayland wl_data_device
(dragdrop_wl_linux.fm: enter / motion / drop, the offered MIME types, set_actions, and a wl_data_source for the
source side) and X11 XDND v5 (dragdrop_x11_linux.fm: XdndAware, the Enter / Position / Status / Drop / Leave
/ Finished client messages, the data read over XdndSelection). The public API is the Win32 one: drop_target_enable,
drop_data, drop_set_effect, drag_start, drop_inject, drag_script.
Tray icon and notifications
tray_linux.fm implements the StatusNotifierItem specification over D-Bus: it exports an item object, serves its
properties (icon as an ARGB pixmap, title, tooltip, menu), registers with the StatusNotifierWatcher, and turns the
host's Activate / SecondaryActivate / ContextMenu into Tray_Events. The menu is a com.canonical.dbusmenu tree
(dbusmenu_linux.fm: GetLayout, Event). tray_notify shows its notification through notify_linux.fm;
the results become Notify_* events of the icon. Same public API as tray_win32.fm.
notify_linux.fm shows system notifications through org.freedesktop.Notifications: Notify with the
desktop-entry, urgency and image-data hints; ActionInvoked, NotificationClosed and ActivationToken become
Notification_* events of the window (notifications.md).
notify_windows.fm shows toast notifications through the Windows Runtime. Every WinRT call of the notifications
runs on one notification thread of the process (multithreaded apartment), which owns the notifiers and the toasts. The
window's thread gives it jobs and gives the ids. The answer of notify_async and the toasts' Activated, Dismissed
and Failed events come back in one queue: NOTIFY_MESSAGE to the window, and done and the Notification_* events
are made on the window's thread.
Dialogs, shell and live theme
portal_linux.fm adds the XDG portals: org.freedesktop.portal.FileChooser (OpenFile / SaveFile / a folder,
filters, multiple, suggested name; the result arrives on a Response signal), org.freedesktop.portal.OpenURI
(open_url, except file: URIs which OpenURI forbids; open_path and reveal_in_folder use xdg-open), and org.freedesktop.portal.Settings for live light / dark — dark_mode_preferred
reads org.freedesktop.appearance color-scheme and watch_color_scheme(cb) fires cb on the SettingChanged signal.
dialogs_linux.fm tries the portal first, then zenity / kdialog; theme_linux.fm falls back to the GTK settings.
Accessibility, IME, and the smaller services
- Accessibility (
a11y_linux.fm): a minimal AT-SPI 2 bridge over D-Bus (the a11y bus address fromorg.a11y.Bus.GetAddress), exposing the window's tree (roles, names, states, bounds) and theActioninterface's Invoke / Focus from the toolkit's neutralA11y_Update. Nothing is built while no assistive technology connects. - IME (
ime.fm+ime_wl_linux.fm): Waylandzwp_text_input_v3commits text as.Textevents (the same path as a typed key) and exposes the preedit throughime_preedit;ime_set_cursor_rectplaces the candidate window. What the protocol sends is pending until itsdone:Ime_Compose(ime.fm, pure:tests/ime) keeps it and makes the events (Backspace presses for the text replaced,.Textfor the text committed) and the preedit;ime_cursor_rect_logicalturns the caret's rectangle into the compositor's units. On X11, text comes from the key and the modifiers through libxkbcommon as.Text: no input method, and no dead keys or Compose sequences (Known gaps). - Smaller services (
services_linux.fm):idle_inhibit/idle_uninhibitkeep the screen awake throughorg.freedesktop.ScreenSaver. - Recent documents (
recent_files.fm):add_recent_file(path, mime = "")adds a file to the system's recent documents. Linux appends it to the freedesktoprecently-used.xbel, with its MIME type ("": guessed from the extension). Windows callsSHAddToRecentDocs(SHARD_PATHW): the file goes to the user's Recent folder and to the jump list of the program that the type's ProgID names (trame:desktop's Documents part writes that ProgID with the program's AppUserModelID). Other systems: nothing. It writes a file or calls the shell: call it from a worker, never from the interface's thread (base.blockingsays so in a debug build). - Cursors (
cursors_wl_linux.fm): Wayland names a shape to the compositor throughwp_cursor_shape_v1, so the pointer matches the user's theme with no pixel upload. - Pens (
tablet_wl_linux.fm,tablet_tool.fm): Wayland's tablet protocol (zwp_tablet_manager_v2, version 1) gives a tablet's pens asPointer_*events with their pressure, tilt and eraser, and their emulatedMouse_*(dragdrop.md, "Fingers and pens"). A seat with no tablet announces no tool.
Known gaps
- AT-SPI is a minimal bridge (root tree, names, DoAction) that answers calls but does not register with the
desktop: a screen reader such as Orca does not find the window yet. The full surface (registration, Text ranges,
Collection, per-node objects at their own paths) is what AccessKit's
accesskit_unixadapter would give. - Input: no dead keys or Compose sequences on X11, no touch on Wayland. X11 has no pen: the toolkit does not use XInput 2, so a pen there is the mouse the X server makes of it, with no pressure.