---
title: "Desktop shell"
url: https://recursiveai.org/oneapp/docs/shell/
description: "What an app can do around its page: several windows, menus, and the desktop's own services. All of it is called on the UI thread, the one that made the…"
version: "1.0.0"
source: https://github.com/recursive-ai-oss/oneapp-csharp/blob/64b0f3162f8c1b7bb766ceae32357442feaa5960/docs/shell.md
---

# Desktop shell

What an app can do around its page: several windows, menus, and the desktop's own services. All of it is called on the UI thread, the one that made the `AppHost`.

## Windows

`AppHost.Create(options)` opens the first window. `host.OpenWindow(new AppWindowOptions(html) { ... })` opens more, each with its own page, setup callback and `AppWindow` handle.

| You ask for | You get |
|---|---|
| nothing special | an ordinary decorated window: movable, resizable, with a title and size limits (`MinWidth`..`MaxHeight`) |
| `Parent = someWindow` | a dialog: the window system keeps it above the parent (`xdg_toplevel.set_parent`) |
| `Overlay = new OverlayOptions { ... }` | a keep-on-top window without a frame: a `wlr-layer-shell` surface on Wayland, a dock-type window on X11. Throws `OverlayUnavailableException` when the compositor has no layer shell, unless `OverlayOptions.FallbackToToplevel` is set |

Every window carries `AppOptions.AppId` as its app id, which the window system matches to the app's `.desktop` file (icon, grouping, task switcher). Frames come from the compositor (server-side decorations) where it offers them and from the platform layer where it does not (`AppOptions.Decorations` and `AppWindowOptions.Decorations` override).

Closing a window leaves the others open. The app ends when its last *main* window closes (`ExitPolicy.LastMainWindowClosed`, the default): ordinary windows are main windows, dialogs and overlays are not (`AppWindowOptions.IsMain` overrides). `ExitPolicy.Never` keeps a tray app alive with no window until `host.Quit()`. `AppWindow.CloseRequested` lets the app answer the close button itself ("save changes?") instead of closing; `Closed` fires once when the window is gone.

`host.Step()` draws every window whose page changed and sleeps in the operating system when none did. `host.Post(action)` queues work for the UI thread from any thread.

## Keep on top

`AppWindow.KeepAbove` (get, set) keeps an ordinary window above the others, for a "Keep on top" toggle; `AppWindow.CanKeepAbove` says whether the window system can do it (disable the control when it says no). It forwards to `Window.SetKeepAbove` in the platform layer (EWMH on X11, `HWND_TOPMOST` on Windows, the floating window level on macOS, a narrowly scoped KWin script on KWin Wayland; see the platform layer's window docs), and a failure is the platform's `KeepAboveUnavailableException`.

- Setting it before the window is shown works. KWin only knows a window after its first frame, so on Wayland the request is held and applied after the first frame, retried every 50 ms for two seconds. A held request that finally fails is reported through `AppWindow.KeepAboveFailed` and `KeepAboveFailure` (the setter has no caller left to throw to). While a request is held the getter returns it, and the harness `keep_above` says `pending`.
- `AppOptions.KeepAbove` and `AppWindowOptions.KeepAbove` ask for it when a window opens.
- Under KWin every window with the app's app id changes together, and a window opened later does not inherit the state: give it `AppWindowOptions.KeepAbove` (a pop-up that should stay above, say) so it asks again when it is shown. Other Wayland compositors have no way; `CanKeepAbove` is false and the setter throws.
- The toggle in `samples/ShellDemo` reads `CanKeepAbove`, dims itself with the reason when it is false, and catches the typed error.
- Harness: `keep_above` reads and sets it per window; `windows` lists `keepAbove`.

## Menus

`host.ShowMenu(window, new Menu(new MenuItem("Copy", () => ...) { Shortcut = "Ctrl+C" }, MenuItem.Separator(), ...), x, y)` opens a popup window next to a point of `window` (in its pixels), drawn by the page renderer. Items have a label, a callback, an optional shortcut hint, `Enabled` and `Checked`.

- Arrow keys, Home and End move through enabled items (wrapping); Enter or Space picks; Escape closes.
- A pointer hover highlights an item; a left click on one picks it.
- A click outside the menu (in the app, or on the desktop, where the compositor's popup grab ends it) dismisses it without picking.
- The callback runs on the UI thread *after* the menu has closed, so it can open a dialog or another menu. Only one menu is open at a time.
- A grabbing popup needs a recent click or key press in the parent window, so call `ShowMenu` from an input handler.

Linux has no global menu bar, so an app menu is part of the page: each title in the page's own menu strip calls `ShowMenu` at its bottom-left corner. On macOS the same `Menu` and `MenuItem` types fill the system menu bar (see *macOS* below); only the host differs, not the item model.

## Desktop services: `host.Shell`

Each call returns a task that completes on the UI thread. A service the session lacks throws `DBusServiceUnavailableException` through the task, naming the interface and the bus name; nothing is skipped silently.

| Call | Service | Notes |
|---|---|---|
| `NotifyAsync(AppNotification)` | `org.freedesktop.portal.Notification`, else `org.freedesktop.Notifications` | buttons and the default click are callbacks |
| `OpenFilesAsync`, `OpenFolderAsync`, `SaveFileAsync` | `org.freedesktop.portal.FileChooser` | paths, or empty / null when cancelled |
| `ShowTrayAsync(title, icon, items)` | `org.kde.StatusNotifierItem` with a dbusmenu | needs a StatusNotifierWatcher (Plasma's tray has one) |
| `BindHotkeysAsync(Hotkey[])` | `org.freedesktop.portal.GlobalShortcuts` | the desktop may ask the user to confirm the keys. `Hotkey.Released` runs when the keys are let go (the portal's `Deactivated`), for hold-to-talk; macOS has presses only |
| `TakeScreenshotAsync()` | `org.freedesktop.portal.Screenshot` | local path of the image |

`ShowTrayAsync` returns a `TrayHandle` (also `Shell.Tray`): keep it to change the menu (`SetMenu`) or icon (`SetIcon`), and dispose it to remove the item; on Linux its `Icon` is the StatusNotifier `TrayIcon`. Every `…Async` method takes a `CancellationToken` as its last parameter: cancelling completes the task as canceled and, on Linux, closes the portal request (file dialogs, screenshot, shortcut binding); AppKit's and Windows' own dialogs and the region picker cannot be stopped, so they stay until the user closes them and their answer is dropped, and a notification already accepted stays shown. A service the system will not give the app as it is (a permission, an unsigned bundle) throws `ShellUnavailableException` through the task, with `Service` and `Requirement` saying what to do. On macOS see the section below.

The session bus connection is made on first use. Its signals and replies reach the UI thread through `DBusConnection.Dispatcher`, which the host points at `Post`. The host also tells the portal the app's id (`org.freedesktop.host.portal.Registry`), because a program that no sandbox names is anonymous to the portals, and the portals refuse requests that need an id.

## macOS

The same `AppHost` runs on Apple silicon macOS: pages draw through OneGpu's Metal backend into Cocoa windows, and `OpenWindow`, overlays and `ShowMenu` use OnePlatform's Cocoa windows (see its desktop-windows notes). The desktop services map to AppKit and friends and run on the main thread, which is the UI thread. They are OnePlatform's `MacDesktop` (see its `macos-shell.md`); `AppShell` maps its own types onto it. `ShellUnavailableException` is OnePlatform's (`OnePlatform.Shell`).

| You call | macOS API | Notes |
|---|---|---|
| `Shell.SetMenuBar([new MenuBarMenu("File", menu), ...])` | `NSMenu` set on `NSApp.mainMenu`, after the application menu | `Shortcut` strings use Command for `Ctrl`, Option for `Alt`, Control for `MacCtrl`; an item without a callback is greyed out. `AppShell.HasMenuBar` tells where it exists; elsewhere it throws `ShellUnavailableException` |
| (nothing) | the application menu: Hide, Full Screen, Quit | made by the platform layer and named with `CFBundleName` (`Quit Shell Demo`); Quit raises the quit request, so `ExitPolicy` and `CloseRequested` apply |
| `ShowTrayAsync(title, icon, items)` | `NSStatusItem` with an `NSMenu` | `icon` is an image file path, an `NSImage` name, or else the app's own icon, drawn 18 points high; with no image the title is shown |
| `OpenFilesAsync`, `OpenFolderAsync`, `SaveFileAsync` | `NSOpenPanel`, `NSSavePanel` (not modal, so the loop keeps running) | filters must be `*.ext` patterns (`ArgumentException` otherwise); `Parent` is ignored: the panel is its own window |
| `NotifyAsync` | `UNUserNotificationCenter` | needs an app bundle (see below). The first call makes the system ask the user for permission and the task completes when they answer; a refusal, or a program that is not a bundle, throws `ShellUnavailableException`. Buttons are notification actions; a notification shows even while the app is in front |
| `BindHotkeysAsync` | Carbon `RegisterEventHotKey` | needs no privacy permission. macOS has no shortcut chooser, so each `Hotkey` needs a `PreferredTrigger` (`CTRL+ALT+d`: `CTRL` is Control, `ALT` Option, `META`/`CMD`/`LOGO` Command); a key another app holds throws `ShellUnavailableException` |
| `TakeScreenshotAsync` | none | throws `ShellUnavailableException`: capturing the screen needs the user's Screen Recording permission, which an app cannot grant itself |
| `AppHost.CreateOrActivate` | a Unix socket in a private per-user folder | the first launch listens; a later launch (from a terminal, say) hands over its arguments and exits. The first copy raises `host.LaunchedAgain`, after bringing its main window forward (`Window.Activate`: `activateIgnoringOtherApps`, un-minimize). A launch through LaunchServices (`open`, Finder, the Dock) never starts a second copy: the system activates the running one |

`host.LaunchedAgain` (the second launch's arguments) is raised on every desktop; `host.Activated` carries the same launch with the D-Bus activation details on Linux only.

### App bundles and disk images

`oneapp install` builds the `.app` bundle and, with `--dmg`, the disk image; see [packaging.md](https://recursiveai.org/oneapp/docs/packaging/#macos-app-bundle-and-disk-image). A launch through LaunchServices passes the development harness with `open --env ONEAPP_HARNESS=unix:auto --env ONEAPP_HARNESS_INFO=FILE <bundle>` (Debug builds only).

## One copy per session

Set `AppOptions.SingleInstance` and start with `AppHost.CreateOrActivate(options, args)`. The first launch owns the bus name `AppId`; a later launch hands its arguments over and gets `null`, so `Main` returns. The first copy then brings its main window to the front, un-minimized and focused, with `Window.Activate` and the activation token the launcher gave the second launch (`XDG_ACTIVATION_TOKEN`, or `DESKTOP_STARTUP_ID` on X11), and raises `host.Activated` on its UI thread. If the window system cannot do it (a Wayland compositor without `xdg_activation_v1`), `host.ActivationFailed` and `host.LastActivationFailure` carry the typed exception (`ActivationUnavailableException.Requirement` names what is missing) and `Activated` still follows. A compositor may also refuse a launch it cannot tie to a user action and only flag the window in the task switcher. `AppOptions.ActivateOnSecondLaunch = false` leaves the window alone so the handler decides. On Windows the launching process must also call `WindowActivation.AllowForeground` for the first instance's process; the host does not yet do that (the hand-over carries no process id).

## Installing for the current user: `oneapp install`

```
oneapp install <project|dir> [--configuration Release] [--rid linux-x64] [--no-aot]
oneapp uninstall <app id|project|dir>
```

The app names itself in its project file:

```xml
<OneAppId>org.example.Notes</OneAppId>          <!-- required: reverse DNS; desktop file, icon, window app id -->
<OneAppName>Notes</OneAppName>
<OneAppComment>Short description</OneAppComment>
<OneAppCategories>Office;</OneAppCategories>
<OneAppIcon>assets/icon.png</OneAppIcon>         <!-- PNG or SVG, relative to the project -->
```

### The app's identity for the portals

The desktop portals (global shortcuts, notifications, file dialogs) need to know which app is asking, and refuse a program they cannot name ("An app id is required"). OneApp declares `AppOptions.AppId` (when it is a reverse-DNS id such as `org.example.Notes`; the default `oneapp` is not, and is never declared) and `AppOptions.Title` to the portal's host registry before the first portal call. The portal accepts an id only when a matching `<id>.desktop` file exists in the user's or the system's `applications` folders. When the program runs from an AppImage (the `APPIMAGE` variable is set), OneApp lets the platform layer write a hidden entry (`NoDisplay=true`, never overwriting an existing file) in `$XDG_DATA_HOME/applications` if there is none, so an AppImage run directly, without any installation, can bind shortcuts; the desktop may ask the user once to confirm them. Other programs get no file written: install the app (`oneapp install`) or ship its desktop entry.

### The app's icon

`<OneAppIcon>` is also the icon the running app shows. The build embeds the file in the app, and OneApp decodes it and gives it to every window the app opens (title bar, taskbar and task switcher, through `xdg-toplevel-icon` on Wayland and `_NET_WM_ICON` on X11) and to the tray item `ShowTrayAsync` makes (the StatusNotifierItem's `IconPixmap`). It works from an AppImage or a build folder with nothing installed in an icon theme, so no code is needed. To choose the icon in code, set `AppOptions.Icon` (the bytes of a PNG, JPEG, WebP or SVG) or `AppOptions.IconFile` (a path); these win over the embedded one and fail with `ArgumentException` when they cannot be decoded. A square picture of 256 pixels or more is best; smaller sizes are made from it. The themed name given to `ShowTrayAsync` is passed to the tray only when an icon theme folder holds a picture of that name, because a tray that cannot find a name may draw nothing instead of the pixels. Windows and macOS keep the icon of the executable or bundle for windows (their tray items use what they did before).

`install` publishes the app (NativeAOT when the project sets `PublishAot`; `--no-aot` publishes a self-contained managed build) and writes, under `D` = `$XDG_DATA_HOME` (else `~/.local/share`):

| Path | Content |
|---|---|
| `D/oneapp/apps/<id>/` | the published files |
| `D/applications/<id>.desktop` | Desktop Entry: `Name`, `Comment`, `Exec` (absolute, quoted per the spec, with `%U`), `Icon=<id>`, `Terminal=false`, `StartupWMClass=<id>`, `Categories` |
| `D/icons/hicolor/<W>x<H>/apps/<id>.png` or `scalable/apps/<id>.svg` | the icon, sized from the PNG header |

The app's `AppOptions.AppId` should equal `OneAppId`: the compositor ties a window to its entry by that name. `DBusActivatable` is not written; a second launch runs the binary, which hands over and exits (see above). `uninstall` removes exactly those three things. See *App bundles and disk images* above for macOS; Windows is not done yet.

## Windows

The same `AppShell` calls run over the platform layer's Windows services: `SetMenuBar` fills the window's own menu bar (with its accelerators), `ShowTrayAsync` puts an icon in the notification area, `NotifyAsync` raises a notification (a toast shows only for an app that is not in the foreground; actions on a toast need a packaged app, so `AppShell.NotificationButtons` is false for an unpackaged one), `OpenFilesAsync`, `OpenFolderAsync` and `SaveFileAsync` open the Common Item Dialog, `BindHotkeysAsync` registers global hotkeys (`Hotkey.Released` runs when the keys are let go), and `TakeScreenshotAsync` captures the app's own window, or with `interactive` lets the user drag a region. A second launch of an app with `SingleInstance` hands its arguments to the first and exits. Calls made from the UI thread continue on the UI thread after an `await`, so a handler may touch windows and pages afterwards.

Windows decides per user whether an app may show notifications, and a packaged app is known by its package. When they are switched off for a packaged app (*Settings > System > Notifications*, or by group policy or the app's manifest), Windows would accept a toast and show nothing, so `NotifyAsync` asks first and faults with `NotificationsDisabledException` (a `ShellUnavailableException`), whose `Setting` says which switch is off. The setting is the per-user registry value `Enabled` under `HKCU\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\<package family>!<application id>`; Windows picks up a change to it only after a delay, and it can outlive uninstalling the package. An unpackaged app's notification has no setting Windows reports, so `NotifyAsync` completes as before; the notification platform's log (`Microsoft-Windows-PushNotification-Platform/Operational`, event 3150, `ToastSettingDisabled`) shows when one was hidden.

When no graphics device is available (a virtual machine, a remote session) the page is drawn by OneRender's rasterizer on the CPU and shown through `Window.PresentPixels`; it draws only when the page changed, so an idle window costs nothing. Page images (`<img>`, CSS background images, `data:` URLs and files the app registered) are decoded once and drawn there too, placed, scaled, clipped and blended as on the GPU.

### Presenter: GPU or CPU, and why

`AppWindow.Presenter` (and `AppHost.Presenter` for the first window) is a `PresenterStatus`: the `Kind` (`Gpu`, `Cpu`, or `None` for a headless window), a typed `Reason` and, for a failure, the error text in `Detail`. The harness `status` verb shows it as `presenter`, `presenterReason` and `presenterDetail`.

| `Reason` | Meaning |
|---|---|
| `None` | the GPU is used |
| `Requested` | `AppOptions.UseGpu = false` |
| `Environment` | the user set `ONEAPP_PRESENTER=cpu` (it wins over `UseGpu`) |
| `NoGpuDevice` | no GPU device could be made |
| `GpuFailed` | creating the swapchain, drawing or presenting failed for one window: that window moves to the CPU once, with one line on standard error, and does not go back |

On Wayland a protocol error ends the whole connection, so a driver whose first GPU frame the compositor refuses cannot fall back in place: the app stops with a `PresenterUnavailableException` (reason `GpuFailed`) instead of a bare platform error.

The CPU path needs a window that can show pixels (`Window.CanPresentPixels`, Windows today). Where it cannot, and the GPU is off or failed, the app throws `PresenterUnavailableException` (with the `Status`) naming what was expected, instead of an unhandled platform error or a window that never draws. Headless windows never need a presenter.

### Memory: which Vulkan drivers a Linux app maps

The Vulkan loader opens every installed driver when the first instance is made, and a software driver pulls in the compiler runtime with it (about 40 MB resident, 3.5 MB per extra driver). Before it makes the GPU device, OneApp reads the machine's GPUs (PCI vendor ids under `/sys/class/drm`) and the installed driver manifests (the loader's search folders for `icd.d`), and gives the loader only the driver of the best GPU present: NVIDIA, then AMD, then Intel, then others. Manifests it cannot attribute to a vendor are kept. The loader variables are set for the device creation only and removed afterwards, so programs the app starts do not inherit them. When the chosen driver is NVIDIA's, the same call also gives glvnd only NVIDIA's EGL vendor file (`__EGL_VENDOR_LIBRARY_FILENAMES`): without a reachable X display the NVIDIA driver loads the EGL dispatch library at start, and that would load Mesa's EGL vendor and the compiler runtime (about 42 MB resident). Both are skipped when the user set `__EGL_VENDOR_LIBRARY_FILENAMES` or `__EGL_VENDOR_LIBRARY_DIRS`. On a machine whose only driver is a software one, or whose GPUs match no installed driver, nothing is changed.

A test machine with an NVIDIA GPU, an AMD integrated GPU, and the NVIDIA, Radeon and software drivers installed went from 255 MB to 175 MB resident for the shell demo; the CPU path (`ONEAPP_PRESENTER=cpu`) uses about 57 MB.

To choose drivers yourself, set `VK_DRIVER_FILES` (or `VK_ICD_FILENAMES`, `VK_LOADER_DRIVERS_SELECT`, `VK_LOADER_DRIVERS_DISABLE`), `ONEGPU_ADAPTER` or `ONEGPU_VULKAN_LIBRARY` before the app starts: when any is set OneApp leaves the loader alone. Set `VK_DRIVER_FILES` to a software driver's manifest, for instance, to run on it.

The runtime's garbage collector is left at its defaults. Measured on the samples, workstation or server, concurrent or not, `GCConserveMemory` and gen0 limits change resident memory by under 1 MB; an app that holds a lot of managed data can set `ConcurrentGarbageCollection`, `ServerGarbageCollector` and `System.GC.ConserveMemory` in its project as for any .NET app.
