Nucleus
Tool windows

SatellitesNew

Declare tool palettes and inspectors once, let them follow the focused document window, dock them, and save the layout.

View as Markdown

A satellite is a native window that belongs to another window: it follows its parent, stays above it, hides with it, and keeps out of the taskbar. The user can float it or dock it into the document. Satellites are @ExperimentalNucleusApi (see Tool windows).

Declare a workspace

Document windows join a SatelliteWorkspace with JoinSatelliteWorkspace. Declare satellites at application scope, next to the windows:

Main.kt
fun main() = nucleusApplication {
    val workspace = rememberSatelliteWorkspace()

    DecoratedWindow(onCloseRequest = ::exitApplication, title = "Document") {
        JoinSatelliteWorkspace(workspace)
        WindowScaffold(titleBar = { TitleBar { Text("Document") } }) { padding ->
            DockLayout(workspace, Modifier.padding(padding)) { Document() }
        }
    }

    Satellite(workspace, id = "tools", title = "Tools") { ToolsPanel() }
    Satellite(
        workspace,
        id = "colors",
        title = "Colors",
        initialPlacement = SatellitePlacement.Docked(DockSide.Right),
    ) { ColorPanel() }
}

Tools opens as a floating window, Colors as a docked panel. Each gets a header with Dock, Float and Close actions; dragging it moves the satellite between the two hosts.

The floating Tools and Layers palettes follow the document as it moves; Dock puts Layers in the document, Float takes it back out

Satellite parameters

ParameterDefaultMeaning
workspace, id, titlerequiredWorkspace, stable identity, header and window title
initialPlacementSatellitePlacement.Floating()Where it starts on first declaration
initiallyOpentrueWhether it is shown on first declaration
dockSidesall four DockSidesSides it may dock on. Empty makes a floating-only palette
floatabletruefalse makes a fixed panel. Requires a docked initialPlacement
reorderabletruefalse pins its rank on its side. Requires a docked initialPlacement
resizabletrueWhether the user can resize the floating window
hideWhileOwnerFullscreenOrMaximizedtrueHide the floating window while the owner fills the screen
nativeContextMenutrueNative context menu for text fields in the floating window
controlButtonsDirectionControlButtonsDirection.AutoSide of the floating window's controls. Pass the main window's value, such as SystemNative
header{ DefaultSatelliteHeader() }Chrome in the floating title bar and above the docked panel
floatingCaption{}See Floating satellites on Wayland
floatingBarMovesWindowfalseSee Give the whole bar to the compositor
contentrequiredThe body, with SatelliteScope as receiver

initialPlacement through reorderable apply the first time an id is declared, unless restore placed it. Contradicting values throw. Docking options are on Docking.

Choose where a satellite starts

SatellitePlacement.Docked(side, order = 0, extent = null, weight = 1f) puts it in the owner's DockLayout. See Size a docked panel. SatellitePlacement.Floating places a window relative to the owner:

SatellitePlacement.Floating(
    positioner = WindowPositioner(
        parentAnchor = WindowAnchor.Right,
        childAnchor = WindowAnchor.Left,
        offset = DpOffset(12.dp, 0.dp),
        constraintAdjustment = WindowConstraintAdjustment.FlipAndSlide,
    ),
    size = DpSize(300.dp, 400.dp), // default 320 × 240 dp
)

The default positioner puts it at the owner's top-right corner with a 12 dp gap. anchorRect anchors to a rectangle of the owner instead of its frame. constraintAdjustment keeps the window on the monitor: None, Slide, Flip, FlipAndSlide (default) or All (also shrinks).

Placement runs once. To apply a new rule later, set entry.windowState.positioner and call entry.windowState.reanchor().

Choose the owner

Floating satellites follow the workspace's owner: the member focused last with followFocus = true (the default), else the pinned member or the first to join. workspace.pinTo(window) forces an owner; pinTo(null) undoes it.

Drive satellites from code

CallEffect
open(id) / close(id) / toggle(id)Show or hide; placement and state are kept
dock(id, side, order = null, host = null)Dock on side of host, else the current dock host, else the owner
undock(id, placement = null)Float it over its panel, or at placement
visiblefalse hides every satellite without closing any
owner, pinnedOwner, members, satellites, satellite(id)Snapshot state to read

Call the workspace from effects and UI callbacks, not during composition.

Write a header

header and content run with SatelliteScope: workspace, satellite (the entry), isDocked, isCompositorPlaced, floatingBarMovesWindow, and dock(side), undock(), close().

A custom header puts Modifier.satelliteDragHandle(scope) on the docked strip only. The floating title bar already carries the handle, and a second one would start two drags. A press without movement does nothing, so buttons can sit inside the handle.

@Composable
fun SatelliteScope.PaneHeader() {
    Row(
        Modifier
            .fillMaxWidth()
            .height(32.dp)
            .then(if (isDocked) Modifier.satelliteDragHandle(this) else Modifier),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Text(satellite.title, Modifier.weight(1f))
        if (isDocked) {
            if (satellite.isFloatable) IconButton(onClick = { undock() }) { Text("↗") }
        } else {
            IconButton(onClick = { dock() }) { Text("↙") }
        }
        IconButton(onClick = { close() }) { Text("—") }
    }
}

Save and restore the layout

val saved = workspace.snapshot()   // SatelliteLayoutSnapshot
workspace.restore(saved)

SatelliteLayoutSnapshot holds each satellite's placement and isOpen, plus the side extents. It is a plain data class; you serialize it. restore also applies to satellites declared later and leaves unnamed ones alone.

Floating satellites on Wayland

On a compositor-placed window only the compositor can move the window. The floating title bar splits there: the header docks the satellite, and a 56 dp strip (SatelliteCaptionStripWidth) beside the window controls moves the window. Nucleus composes floatingCaption in that strip, only when isCompositorPlaced is true. Put a "move" glyph there, not a control.

Give the whole bar to the compositor

For palettes the user moves around more often than docks, pass floatingBarMovesWindow = true. On a compositor-placed window a press anywhere on the floating title bar then moves the window, as on any other window, and no caption strip is reserved. The satellite docks from what the header marks itself: a dock() action, or a grip with Modifier.satelliteDragHandle.

Satellite(workspace, id = "tools", title = "Tools", floatingBarMovesWindow = true) { ToolsPanel() }

DefaultSatelliteHeader handles it: it makes its drag grip the dock handle and drops the chip. A custom header reads SatelliteScope.floatingBarMovesWindow, true only while floating on a compositor-placed window, and puts the handle on a grip in that case too. The parameter has no effect where the app places its windows: the whole bar drags the satellite there either way.

Open a standalone satellite window

SatelliteWindow attaches one palette to one window, without a workspace or docking:

DecoratedWindow(onCloseRequest = ::exitApplication) {
    var inspector by remember { mutableStateOf(true) }
    if (inspector) {
        SatelliteWindow(
            onCloseRequest = { inspector = false },
            state = rememberSatelliteWindowState(
                size = DpSize(260.dp, 420.dp),
                positioner = WindowPositioner(WindowAnchor.TopRight, WindowAnchor.TopLeft),
            ),
            title = "Inspector",
        ) { InspectorPanel() }
    }
}

onCloseRequest also fires when the parent is destroyed. parent defaults to the enclosing window, and the default positioner centers the satellite on it. The other parameters match DecoratedWindow, plus hideWhileParentFullscreenOrMaximized and nativeContextMenu. The state publishes offsetFromParent (null on native Wayland), isHiddenByParent and isActive.

What's next

  • Docking: side order, split and layered sides, fixed panels.
  • Tabs: give each tab window its own satellites.
  • Linux and Wayland: compositor-placed windows.
Was this page helpful?
Edit on GitHub

Last updated on