---
title: "Desktop windows"
url: https://recursiveai.org/oneplatform/docs/desktop-windows/
description: "How windows behave as desktop-app windows on Linux, and on macOS where the section says so."
version: "1.0.0"
source: https://github.com/recursive-ai-oss/oneplatform-csharp/blob/37f5a73c449624ea8671f8612d61000e2d57aa5e/docs/desktop-windows.md
---

# Desktop windows

How windows behave as desktop-app windows on Linux, and on macOS where the section says so.

## Ordinary windows

`PlatformApp.CreateWindow(WindowOptions)` makes a decorated, movable, resizable window.

| Option | Wayland | X11 |
|---|---|---|
| `Title` | `xdg_toplevel.set_title` | `_NET_WM_NAME` and `WM_NAME` |
| `AppId` | `xdg_toplevel.set_app_id`, which the compositor matches to the app's `.desktop` file | `WM_CLASS` (instance and class) |
| `MinWidth`..`MaxHeight`, `Window.SetSizeLimits` | `set_min_size`, `set_max_size` (a client-side title bar is added to the heights) | `WM_NORMAL_HINTS` |
| `Parent` (dialog) | `xdg_toplevel.set_parent` | `WM_TRANSIENT_FOR` and the dialog window type |
| `Decorations` | see below | `Auto` and `ClientSide`: the window manager; `None`: `_MOTIF_WM_HINTS` |

`Window.Role` tells ordinary windows, dialogs, overlays and popups apart; `Window.Parent` names the parent.

### Frames on Wayland

`DecorationPreference.Auto` asks the compositor for server-side decorations (`zxdg_decoration_manager_v1`, bound at version 1) and follows its answer. If the compositor does not offer the protocol, or answers `client_side`, the platform layer draws a frame: a title bar (title, minimize, maximize/restore, close) and an invisible 8-pixel resize border, built from four `wl_subsurface`s around the window's own surface, so the content, CPU or GPU drawn, is untouched. The frame needs `wl_subcompositor`; without it `Window.Decoration` is `DecorationKind.None`.

The frame hands moves and resizes to the compositor (`xdg_toplevel.move` and `resize` with the serial of the click), opens the window menu on a right click (`show_window_menu`), maximizes on a double click, and sets resize cursors through `wp_cursor_shape_v1`. Closing sends `PlatformEventKind.WindowCloseRequested`; the program decides.

`DecorationPreference.ClientSide` forces the client-side frame. `PlatformOptions.UseServerDecorations = false` does not bind the decoration protocol at all, which is how the no-manager path is exercised. `Window.Decoration` reports who draws the frame now.

The size a program sees (`Window.Width`, `Height`, `WindowResized`) is always the content area, below the title bar.

## Overlays

`WindowOptions.Overlay` makes a keep-on-top window (`OverlayOptions`: layer, anchors, margins, exclusive zone, keyboard behaviour).

- Wayland: a `zwlr_layer_shell_v1` surface, bound at version 4. Layer `Overlay` or `Top`; the compositor answers with the final size. If the compositor lacks the protocol, `CreateWindow` throws `OverlayUnavailableException` ("zwlr_layer_shell_v1 not offered by the compositor ..."); with `OverlayOptions.FallbackToToplevel` it makes an ordinary window instead (`Role` is `Toplevel`).
- X11: a window of type `_NET_WM_WINDOW_TYPE_DOCK` with `_NET_WM_STATE_ABOVE`, `SKIP_TASKBAR` and `SKIP_PAGER`, placed from the anchors and margins on the screen. Anchoring to opposite edges stretches it. A positive exclusive zone along one edge sets `_NET_WM_STRUT_PARTIAL`. The keyboard setting is ignored.

Overlays have no frame (`Decoration` is `None`).

## Popups

`PlatformApp.CreatePopup(parent, PopupOptions)` makes a menu, drop-down or tooltip attached to a rectangle of the parent (in the parent's pixels).

- Wayland: an `xdg_popup` with an `xdg_positioner` (anchor rectangle, anchor, gravity, offset, constraint adjustment). A popup may also belong to another popup or to an overlay (`zwlr_layer_surface_v1.get_popup`). With `Grab` the popup needs a recent click or key press in the app; `popup_done` ends it. Clicks inside the app's own windows are the app's input; a click outside them dismisses the popup.
- X11: an override-redirect window placed by `PopupPlacement` (the same arithmetic as the positioner, constrained to the screen) with an owner-events pointer grab; a press that no window of the app receives dismisses it. Keyboard input stays with the parent window.

Dismissal posts `PlatformEventKind.PopupDismissed` with the popup's window id, then closes the popup. `Window.PositionInParent` is where the system put the popup, relative to the parent's content area, in pixels.

## macOS (Cocoa)

- Ordinary windows are titled `NSWindow`s: the system draws the frame (`Decoration` is `ServerSide`; `Auto` and `ClientSide` are the same here, `None` is borderless). `Resizable = false` drops the resize control. `MinWidth`..`MaxHeight` and `SetSizeLimits` set `contentMinSize` and `contentMaxSize` (pixels divided by the scale). `AppId` has no AppKit counterpart.
- A dialog (`Parent`) is a child window (`addChildWindow:ordered:`): above its parent, moving and minimizing with it.
- An overlay is a borderless window at a window level: `Overlay` is `NSStatusWindowLevel`, `Top` is `NSFloatingWindowLevel`. It is on every Space, shown beside full-screen windows, not movable, and placed from the anchors and margins on the main screen without AppKit moving it clear of the menu bar. With `Keyboard = None` it never becomes the key window. `ExclusiveZone` is ignored. `CreateWindow` never throws `OverlayUnavailableException` on macOS.
- A popup is a borderless child window at `NSPopUpMenuWindowLevel`, placed by `PopupPlacement` inside the parent screen's visible area, and never takes the keyboard. AppKit has no pointer grab, so with `Grab` the loop watches the global mouse buttons (about 60 times a second, only while such a popup is open): a press that lands outside every window of the app posts `PopupDismissed` and closes the popup. A press in one of the app's own windows is the app's input.
- `StartMove`, `StartResize` and `ShowWindowMenu` do nothing: the system frame does its own moves. `FillSolid` sets the window layer's background colour, which shows wherever nothing has been presented.
- `Activate` of a popup throws `ActivationUnavailableException`.

## Showing CPU pixels

`Window.CanPresentPixels` says whether a window can show an image drawn by the CPU, for a program with no usable graphics device (or one that asks for CPU drawing). `Window.PresentPixels(bgra, width, height)` takes the window's client area as 4 bytes per pixel in blue, green, red, unused order, top row first, and the unused byte is ignored: the picture is opaque.

| Backend | `CanPresentPixels` |
|---|---|
| Win32 | true (`SetDIBitsToDevice`; redrawn on `WM_PAINT`) |
| Wayland toplevel, layer-shell and popup windows | true, when the compositor offers `wl_shm` (always, by the core protocol) |
| X11, Cocoa, Android, iOS, browser | false; `PresentPixels` throws `NotSupportedException` |

On Wayland the image is copied into one of a few reusable `wl_shm` buffers (XRGB8888), attached, damaged and committed; nothing is allocated per picture. A buffer the compositor still holds (until its `release` event) is never drawn into, so a window cycles through two or three buffers, and a fourth is made only if the compositor keeps all of them. A picture of a new size drops the old-size buffers as they are released. The surface is sized to the picture: its logical size is the pixel size divided by the window's scale (through `wp_viewport` where offered, `wl_surface.set_buffer_scale` otherwise), so pass the window's pixel size (`Window.Width` and `Window.Height`, which follow `WindowResized`) for a window that fills exactly. A picture presented before the first configure is kept and appears with it. The compositor keeps showing the last committed buffer, so nothing is drawn on a timer or frame callback: call `PresentPixels` when the picture changes, and an idle window costs no CPU. A popup's picture is committed after its first configure, like a window's, and its position and dismissal (`popup_done`) are unchanged. A configure or a scale change recommits the last picture without copying it again; the program is told about the new size through `WindowResized` and presents a picture of that size.

## Window icons

A desktop normally takes a window's icon from the application's installed launcher entry (on Linux a `.desktop` file named by the app id, with an icon in the icon theme). An application that runs without being installed, such as an AppImage launched directly, has none, and the system shows a placeholder. `Window.SetIcon(images, name)` gives the window its own icon: pass one or more `IconImage` pictures (straight RGBA, top row first); a single square picture also supplies the smaller standard sizes (16, 22, 24, 32, 48, 64, 128 and 256 pixels that are below it).

| Backend | `SetIcon` |
|---|---|
| Wayland toplevels | yes, through `xdg_toplevel_icon_manager_v1` (staging protocol; KWin 6.6 offers it) with one `wl_shm` buffer per square picture and the themed `name` when given; applied with the toplevel's next commit |
| Wayland, a compositor without that protocol; popups and overlays | returns false: the icon comes from the installed launcher entry |
| X11 | yes, `_NET_WM_ICON` |
| Win32, Cocoa | returns false for now |

The same pictures go to the tray icon: `TrayIcon.CreateAsync(connection, id, title, images)` publishes them as the StatusNotifierItem `IconPixmap` (each size as width, height and ARGB bytes in network byte order) and `SetIcon(images)` changes them and emits `NewIcon`. With no themed name the item's `IconName` is empty, so the host has only the pictures to draw; with a name it may prefer the themed icon, and a host that cannot resolve the name may draw nothing, so give a name only when the theme has it. Plasma on KWin 6.6 drew the pictures with an unresolvable name set; do not depend on that elsewhere.

## Several windows

Any number of ordinary windows can be open; every event carries its window id, and closing one leaves the others alone.

## Moves and resizes started by the program

`Window.StartMove()`, `StartResize(ResizeEdge)` and `ShowWindowMenu(x, y)` call from a pointer-button-down handler. On Wayland they quote the serial of the latest button or key press. On X11 `StartMove` and `StartResize` send `_NET_WM_MOVERESIZE`; `ShowWindowMenu` does nothing there.

## Bringing a window forward

`Window.Activate(token)` raises a window, un-minimizes it and gives it the keyboard. Window systems refuse a program that tries this unprompted, so the request carries proof that a user action started it.

- Wayland: `xdg_activation_v1`. A token from the launcher (`XDG_ACTIVATION_TOKEN`, or `ActivationRequest.ActivationToken` when a second launch forwarded it) is used as it is. Without one, the platform layer asks the compositor for a token tied to the window's surface and the latest input serial and activates when it arrives; the compositor may still refuse a window that has had no recent input and show a taskbar hint instead. A compositor without the protocol makes `Activate` throw `ActivationUnavailableException` whose `Requirement` is `xdg_activation_v1`. Popups cannot be activated. Wayland announces no minimized state, so `IsMinimized` is true after `Minimize()` and false again once the window is handed the focus.
- X11: the token is a startup-notification id (`DESKTOP_STARTUP_ID`), stored as `_NET_STARTUP_ID`. A minimized window is mapped again (ICCCM), then `_NET_ACTIVE_WINDOW` goes to the root with source "application" and the time of the latest key or button press. With no window manager the window raises itself and takes the focus.
- Win32: `ShowWindow(SW_RESTORE)` and `SetForegroundWindow`. Windows only lets the foreground process, or one it permitted, do that, so the second launch calls `WindowActivation.AllowForeground(firstInstanceProcessId)` before it exits. If Windows still refuses, the call retries with the foreground thread's input queue attached for a moment.
- Cocoa: `deminiaturize:`, `activateIgnoringOtherApps:` and `makeKeyAndOrderFront:`.

A second launch under a launcher inherits the token in its environment; `SingleInstance.Acquire` forwards it in `platform_data` (`activation-token`, `desktop-startup-id`) and the running instance passes `request.ActivationToken` to `Activate`.

## Keeping a window on top

`Window.SetKeepAbove(bool)` is the toggle for an ordinary decorated window (not for overlays, which are placed with `WindowOptions.Overlay`). `Window.KeepAbove` is the state, and `Window.CanKeepAbove` says whether it can work right now. Where it cannot, `SetKeepAbove` throws `KeepAboveUnavailableException` (a `PlatformException`; `Requirement` names what is missing). Call all three on the UI thread.

- X11: the `_NET_WM_STATE` client message with `_NET_WM_STATE_ABOVE` (EWMH). It needs a window manager; without one `CanKeepAbove` is false. `KeepAbove` is read back from the property, so a change the person makes in the window menu shows up.
- Win32: `SetWindowPos` with `HWND_TOPMOST` or `HWND_NOTOPMOST`, without moving, sizing or activating; the state read back is the `WS_EX_TOPMOST` bit.
- Cocoa: the window level, floating (3) or normal (0).
- Headless: the state only.
- Wayland: `xdg-toplevel` has no keep-above request, and there is no cross-compositor protocol for it. Under KWin, and only there, the platform layer uses KWin's scripting interface on the session bus (`org.kde.KWin`, `/Scripting`). Each change writes one small script into `XDG_RUNTIME_DIR`, loads and runs it, waits for its report, then unloads it and deletes the file, all before the call returns, so nothing stays loaded. The script finds windows whose `resourceClass` or `desktopFileName` equals the `WindowOptions.AppId` the window was created with and sets or clears their `keepAbove`; it reads no title or size and writes no other property. KWin gives a client no way to name one of its own windows, so every window of the same app id changes together. The call blocks for the answer (normally milliseconds; at most 3 s, then it throws). It throws the typed error when the session bus has no KWin (any other compositor), when scripting is refused, or when KWin knows no window with the app id yet (ask again once the window is shown). `CanKeepAbove` asks the bus whether KWin is there.

## Protocols

Bound versions: `xdg_wm_base` 5, `zxdg_decoration_manager_v1` 1, `zwlr_layer_shell_v1` 4, `wl_subcompositor` 1, `wp_cursor_shape_manager_v1` 1, `xdg_activation_v1` 1, `xdg_toplevel_icon_manager_v1` 1 (when offered). Tables are generated by `tools/WaylandGen` from `tools/WaylandGen/protocols`.
