How GIMP Manages Floating Selection States
GIMP handles floating selections as temporary, specialized pseudo-layers that attach directly to an existing target layer rather than functioning as independent elements in the main layer stack. This article explains how GIMP’s internal image architecture represents these selections, how they integrate into the document's layer tree hierarchy, and the operational constraints that govern their lifecycle until they are either anchored or converted into standard layers.
The Nature of a Floating Selection
In GIMP's internal data model, a floating selection (represented
programmatically as GimpFloatingSel) is a subclass of a
standard layer (GimpLayer). It possesses its own pixel
buffer (backed by GEGL buffers in modern GIMP versions), transformation
coordinates, and blend modes.
However, unlike a regular layer, an image can contain only one active floating selection at any time. Rather than residing as an autonomous node in the root or group layers of the image's tree hierarchy, it is directly tethered to a specific target drawable (an existing layer or channel).
Attachment to the Layer Hierarchy
GIMP's core image object (GimpImage) maintains an
explicit reference to the floating selection. When a user pastes image
data or cuts a selection without immediately creating a new layer, GIMP
executes the following structural steps:
- Node Instantiation: GIMP allocates a new
GimpLayerconfigured with a floating selection flag. - Parent-Child Linkage: The floating selection is
associated with the active
GimpDrawable. The target drawable stores a pointer to the floating layer, and the floating layer stores a back-pointer to the target. - Z-Order Placement: Within the visual rendering graph, the floating selection is dynamically evaluated immediately above its parent drawable. It does not exist as a global sibling to other layers; it moves and renders relative to the layer it is tethered to.
Hierarchy Locking and Operational Constraints
Because the floating selection sits in an indeterminate state between an active selection mask and an independent layer, GIMP enforces strict transactional integrity across the layer tree:
- Tree Mutation Locks: Most layer-tree modifications—such as adding regular layers, deleting underlying layers, or reordering the stack—are blocked while a floating selection exists.
- Input Redirection: Paint tools, transformations, and filters are restricted to modify only the floating selection node, preventing accidental divergence of the underlying layer's state.
- Selection Mask Deactivation: The global selection boundary is temporarily replaced by the boundary of the floating selection.
Resolution: Anchoring vs. Promotion
A floating selection cannot persist indefinitely in the layer tree. To restore the hierarchy to a regular state, the node must be resolved through one of three pathways:
- Anchoring (
gimp_floating_sel_anchor): The pixel data inside the floating selection is composited directly into the target drawable's pixel buffer according to the floating selection's offset and opacity. Once the merge is complete, the floating selection node is destroyed, its reference inGimpImageis cleared toNULL, and standard tree operations resume. - Promotion to Layer
(
gimp_floating_sel_to_layer): GIMP severs the tether between the floating selection and its parent drawable. The node is stripped of its floating selection flags and inserted into the layer tree as an autonomousGimpLayernode at the index immediately above the original parent. - Deletion (
gimp_floating_sel_remove): The floating selection node and its buffer are deallocated entirely without altering the underlying parent drawable.