gpui: Linux wayland set exclusive zone and edge (#60163)

# Objective

The exclusive zone and exclusive edge of a wlr-layer-shell surface could
only be set once, at creation, through `LayerShellOptions`. This adds
runtime setters so a live layer-shell window such as a panel can update
them without being recreated.

## Solution

Add two methods on `Window`:

- `set_exclusive_zone` updates how much screen space the surface
reserves. A positive value reserves that distance from the anchored
edge, 0 lets the surface be moved out of others' exclusive zones, and -1
ignores reserved space and may extend under other surfaces.
- `set_exclusive_edge` chooses which anchored edge the exclusive zone
applies to, which is needed to disambiguate a corner-anchored surface.

Setting an exclusive edge the surface is not anchored to is a fatal
protocol error, so the edge is validated (it must be a single edge that
the surface anchor contains) and an invalid edge is logged and ignored.
The same validation now also guards the creation path. Both setters only
commit the surface when a change actually applies, and are no-ops on
non-layer-shell windows and on other platforms.

This is where these 2 are documented:

https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_surface_v1:request:set_exclusive_zone

https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_surface_v1:request:set_exclusive_edge

## Testing

- Verified with a small local layer-shell window (a top bar anchored
TOP, LEFT, RIGHT) with buttons that call the setters at runtime
- No automated test was added, since this calls through to the
compositor.
- Reviewers without a layer-shell capable compositor (for example
GNOME/Mutter) cannot exercise this, as `zwlr_layer_shell_v1` is
unavailable there, I tested this on the
[Smithay](https://github.com/Smithay/smithay/) based compositor
[niri](https://github.com/niri-wm/niri)

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- N/A
This commit is contained in:
Philipp Schaffrath authored and GitHub committed 2026-07-15 08:18:46 +00:00
1 parent 1063107f5e
commit e963df8029
3 files changed
+93 -5

No files matched your search

+3
View File
@@ -800,6 +800,9 @@ pub trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
fn show_window_menu(&self, _position: Point<Pixels>) {}
fn start_window_move(&self) {}
fn start_window_resize(&self, _edge: ResizeEdge) {}
fn set_exclusive_zone(&self, _zone: Pixels) {}
#[cfg(all(target_os = "linux", feature = "wayland"))]
fn set_exclusive_edge(&self, _edge: layer_shell::Anchor) {}
fn set_input_region(&self, _region: Option<&[Bounds<Pixels>]>) {}
fn window_decorations(&self) -> Decorations {
Decorations::Server
+18
View File
@@ -1997,6 +1997,24 @@ impl Window {
self.platform_window.request_decorations(decorations);
}
/// Set the exclusive zone for a layer-shell surface: how much screen space it
/// reserves so other surfaces avoid occluding it (e.g. a panel reserving space).
/// Positive values reserve that distance from the anchored edge, 0 lets the
/// surface be moved out of others' exclusive zones, and -1 ignores reserved
/// space and may extend under other surfaces. (Wayland layer-shell windows only)
pub fn set_exclusive_zone(&self, zone: Pixels) {
self.platform_window.set_exclusive_zone(zone);
}
/// Set which anchored edge a layer-shell surface's exclusive zone applies to.
/// This is only needed to disambiguate a corner-anchored surface; otherwise the
/// edge is deduced from the anchor. The edge must be a single edge the surface
/// is anchored to, or it is ignored. (Wayland layer-shell windows only)
#[cfg(all(target_os = "linux", feature = "wayland"))]
pub fn set_exclusive_edge(&self, edge: crate::layer_shell::Anchor) {
self.platform_window.set_exclusive_edge(edge);
}
/// Start a window resize operation (Wayland)
pub fn start_window_resize(&self, edge: ResizeEdge) {
self.platform_window.start_window_resize(edge);
+72 -5
View File
@@ -36,8 +36,10 @@ use gpui::{
PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,
PromptButton, PromptLevel, RequestFrameOptions, ResizeEdge, Scene, Size, Tiling,
WindowAppearance, WindowBackgroundAppearance, WindowBounds, WindowControlArea, WindowControls,
WindowDecorations, WindowKind, WindowParams, layer_shell::LayerShellNotSupportedError,
popup::PopupOptions, px, size,
WindowDecorations, WindowKind, WindowParams,
layer_shell::{Anchor, LayerShellNotSupportedError},
popup::PopupOptions,
px, size,
};
use gpui_wgpu::{CompositorGpuHint, WgpuRenderer, WgpuSurfaceConfig, wgpu};
@@ -183,12 +185,12 @@ impl WaylandSurfaceState {
}
if let Some(exclusive_edge) = options.exclusive_edge {
layer_surface
.set_exclusive_edge(super::layer_shell::wayland_anchor(exclusive_edge));
Self::apply_exclusive_edge(&layer_surface, options.anchor, exclusive_edge);
}
return Ok(WaylandSurfaceState::LayerShell(WaylandLayerSurfaceState {
layer_surface,
anchor: options.anchor,
}));
}
@@ -298,6 +300,7 @@ pub struct WaylandXdgSurfaceState {
pub struct WaylandLayerSurfaceState {
layer_surface: zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
anchor: Anchor,
}
pub struct WaylandPopupSurfaceState {
@@ -452,6 +455,49 @@ impl WaylandSurfaceState {
}
}
fn set_exclusive_zone(&self, zone: i32) -> bool {
if let WaylandSurfaceState::LayerShell(WaylandLayerSurfaceState { layer_surface, .. }) =
self
{
layer_surface.set_exclusive_zone(zone);
true
} else {
false
}
}
/// An exclusive edge must be a single edge that the surface is anchored to,
/// otherwise the compositor raises a fatal `invalid_exclusive_edge` protocol
/// error. An invalid edge is logged and ignored. Returns whether it applied.
fn apply_exclusive_edge(
layer_surface: &zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
anchor: Anchor,
edge: Anchor,
) -> bool {
if edge.bits().count_ones() == 1 && anchor.contains(edge) {
layer_surface.set_exclusive_edge(super::layer_shell::wayland_anchor(edge));
true
} else {
log::warn!(
"ignoring exclusive edge {edge:?}: must be a single edge of the surface anchor {anchor:?}"
);
false
}
}
fn set_exclusive_edge(&self, edge: Anchor) -> bool {
if let WaylandSurfaceState::LayerShell(WaylandLayerSurfaceState {
layer_surface,
anchor,
..
}) = self
{
Self::apply_exclusive_edge(layer_surface, *anchor, edge)
} else {
false
}
}
fn destroy(&mut self) {
match self {
WaylandSurfaceState::Xdg(WaylandXdgSurfaceState {
@@ -470,7 +516,7 @@ impl WaylandSurfaceState {
toplevel.destroy();
xdg_surface.destroy();
}
WaylandSurfaceState::LayerShell(WaylandLayerSurfaceState { layer_surface }) => {
WaylandSurfaceState::LayerShell(WaylandLayerSurfaceState { layer_surface, .. }) => {
layer_surface.destroy();
}
WaylandSurfaceState::Popup(WaylandPopupSurfaceState {
@@ -1739,6 +1785,27 @@ impl PlatformWindow for WaylandWindow {
}
}
fn set_exclusive_zone(&self, zone: Pixels) {
let state = self.borrow();
if state
.surface_state
.set_exclusive_zone(f32::from(zone) as i32)
{
// Commit to apply it immediately, otherwise it only takes effect
// on the next frame.
state.surface.commit();
}
}
fn set_exclusive_edge(&self, edge: Anchor) {
let state = self.borrow();
if state.surface_state.set_exclusive_edge(edge) {
// Commit to apply it immediately, otherwise it only takes effect
// on the next frame.
state.surface.commit();
}
}
fn set_input_region(&self, region: Option<&[Bounds<Pixels>]>) {
let state = self.borrow();
match region {