Skip to content

feat(window): expose reactive Cx decoration mode, tiled edges and window actions with X11 backend - #2249

Merged
Hona merged 1 commit into
devfrom
feat/313-cx-wm-state-x11
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
feat/313-cx-wm-state-x11

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Refs #313

Exposes reactive, tri-state window-manager state on Cx — confirmed decoration mode, per-edge tiled state, and allowed window actions — with an X11 backend and zero vendor/winit changes (Wayland configure getters and X11 PropertyNotify wake follow separately).

API

use rune::{Cx, DecorationMode, El, el, text};

fn header(_: &(), cx: &mut Cx<()>) -> El {
    let tiled = cx.tiled_edges().is_some_and(|e| e.any());
    let can_max = cx.window_actions().maximize != Some(false);
    let mode = match cx.decoration_mode() {
        DecorationMode::Server => "SSD",
        DecorationMode::Client => "CSD",
        _ => "Unknown",
    };
    el().radius(if tiled { 0.0 } else { 10.0 })
        .child(text(format!("{mode} | max={can_max}")))
}
  • New #[non_exhaustive] types (crates/rune/src/window/wm_state.rs, re-exported from rune): DecorationMode (Unknown / Server / Client), TiledEdges (top, right, bottom, left, NONE, ALL, new, any, is_empty), WindowActions (window_menu, maximize, minimize, fullscreen, close, each Option<bool>), and WindowManagerState.
  • Reactive Cx & headless API (runtime/cx.rs, runtime/api.rs, runtime/commit/measure.rs): Cx::decoration_mode(), Cx::tiled_edges(), Cx::window_actions(), and Runtime::set_window_manager_state(WindowManagerState). Packs 17 bits into unused bits 8..=24 of chrome_bits()[4] (leaving bits 3..=7 clear for WindowBackdrop) so memo closures rebuild automatically with zero key growth. Tracks whether the committed view read any of the three accessors so apps that never read them do zero extra view builds or redraws when WM state changes. Cx::clear_chrome resets the state to default unknown for staged playground subviews.
  • X11 backend (crates/rune/src/platform/x11/wm_state.rs, window/chrome.rs, window/host/events.rs): pipelined x11rb query on sync_chrome_core (create, resize, scale change, focus, un-occlusion) and X11 WindowEvent::Moved, with zero X11 round trips on ordinary redraws:
    • _NET_FRAME_EXTENTS (CARDINAL[4]): any > 0 → Server, all 0 → Client, absent or length != 4 → Unknown (never inferred from missing actions or is_decorated()).
    • _GTK_EDGE_CONSTRAINTS (CARDINAL[1]): bit 0=top, bit 2=right, bit 4=bottom, bit 6=left (ignoring resizable bits 1/3/5/7); Some(TiledEdges::NONE) when absent while advertised in _NET_SUPPORTED, None otherwise (never guessed from _NET_WM_STATE_MAXIMIZED_VERT).
    • Per-window _NET_WM_ALLOWED_ACTIONS: minimize, maximize (_NET_WM_ACTION_MAXIMIZE_HORZ && _NET_WM_ACTION_MAXIMIZE_VERT), fullscreen, close; None when absent.
    • Root _NET_SUPPORTED: window_menu (_GTK_SHOW_WINDOW_MENU); None when _NET_SUPPORTED is absent.
  • Other platforms: Wayland (pending follow-up winit support), macOS, Windows, web, overlays, adopted macOS panels, and headless runs honestly report DecorationMode::Unknown, tiled_edges: None, and all WindowActions as None.
  • Example: crates/rune/examples/custom_titlebar.rs prints live decoration mode, tiled edges, and allowed actions.

Outside references

  • Chromium Linux (ui/ozone/platform/x11, ui/ozone/platform/wayland/host/wayland_window.h WindowTiledEdges, ui/linux/window_frame_provider.h)
  • GTK4 (gdk/x11/gdksurface-x11.c _GTK_EDGE_CONSTRAINTS bitmask: bits 0/2/4/6 tiled, bits 1/3/5/7 resizable) and libadwaita (.tiled-* classes)
  • Freedesktop EWMH (_NET_FRAME_EXTENTS, _NET_WM_ALLOWED_ACTIONS, _NET_SUPPORTED)

Verification

  • Pure cross-platform X11 decoder unit tests, 17-bit encoder uniqueness tests, and headless Runtime reactivity / zero-extra-work / clear_chrome tests on Windows, macOS, and Linux container.
  • Compiled doctests (cargo test -p rune --doc), cargo check -p rune -p rune-kit --examples --benches --tests on Windows, macOS, and Linux, cargo check-wasm and cargo check-webgl, and cargo clippy on Windows, macOS, and Linux.
  • Not run live: real X11/XWayland desktop window (Mutter/GNOME Shell) — verified only via unit tests and Linux container compilation/tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant