srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/wayland/src/gtk_shell.rs
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-05-30 16:10:00 +0200
committersrdusr <[email protected]>2024-05-30 16:10:00 +0200
commit1c175642d073689ca11b9252411ea5f8446007d0 (patch)
tree00b8f9062cf1261d2d2642c059a14ff5790522e5 /crates/wayland/src/gtk_shell.rs
parent3d3057ae384ef7389284af8988410889e99c6bb9 (diff)
downloadsrdwm-1c175642d073689ca11b9252411ea5f8446007d0.tar.gz
srdwm-1c175642d073689ca11b9252411ea5f8446007d0.zip
Fix decoration drift during animated transitions; checkpoint IPC/global-menu/output-management work
Border/titlebar decoration was built from Window.geometry (the animation's final target) in both wayland backends' render loops, while sync_geometry already draws a window's actual content at window_anims' interpolated rect during any maximize/fullscreen/open-slide tween. Border and content read two different rectangles for the whole transition, so the border visibly detached from the window it was outlining - reported as "borders aren't flush." Both udev.rs and winit.rs now read the same animated rect for titlebar placement, border-strip placement, and the occlusion test against later windows in stacking order. Verified: cargo build --workspace, cargo clippy (0 new warnings), cargo test -p srdwm-core (111/111). Also checkpoints substantial protocol/IPC work from prior sessions that had accumulated uncommitted: gtk-shell1 support (gtk_shell.rs, the vendored gtk-shell.xml, xwayland.rs's X11-side mirror) backing the global app menu; zwlr_foreign_toplevel_manager_v1 (foreign_toplevel.rs) broadcasting distinct maximized/minimized/fullscreen/activated state per window; output_management (ext-output-management + layer-shell exclusive-zone reservation tracking); workspace.rs and context_menu.rs; a Unix-socket IPC crate (platform/src/ ipc.rs) and a `srd` control-CLI crate (crates/ctl); xkb_config.rs; and a theme module (core/src/theme.rs). A peer session working the AGS shell concurrently verified several of these live against a running srdwm: the global menu rendering a real app's File/Edit menu over gtk-shell1, and foreign-toplevel correctly reporting maximized and fullscreen as independent, non-simultaneous states with the geometry each implies (maximize stops at a reserved top bar and past a dock; fullscreen reaches the true monitor edge).
Diffstat (limited to 'crates/wayland/src/gtk_shell.rs')
-rw-r--r--crates/wayland/src/gtk_shell.rs116
1 files changed, 116 insertions, 0 deletions
diff --git a/crates/wayland/src/gtk_shell.rs b/crates/wayland/src/gtk_shell.rs
new file mode 100644
index 0000000..f4ae030
--- /dev/null
+++ b/crates/wayland/src/gtk_shell.rs
@@ -0,0 +1,116 @@
+//! `gtk_shell1`/`gtk_surface1`: the Wayland-native half of global-menu
+//! support - see `srdwm_core::GlobalMenu`'s doc comment and `xwayland.rs`'s
+//! `EwmhState::read_global_menu` for the XWayland half and the full
+//! rationale (carry the D-Bus *address*, never the menu content itself).
+//!
+//! GTK4 only calls `gtk_surface1.set_dbus_properties` - the one request
+//! this module actually needs - once it knows the compositor supports the
+//! protocol at all, which it establishes by binding `gtk_shell1` and
+//! getting a `capabilities` event back. Everything else in the protocol
+//! (startup-notification IDs, tiled-state events, modal hints, the
+//! titlebar-gesture request GNOME Shell uses for its own double/right/
+//! middle-click-titlebar handling) is real but out of scope for what this
+//! pass is actually for - acknowledged with a no-op rather than silently
+//! ignored, so a future pass extending this has a clear list of what was
+//! deliberately left alone.
+
+use smithay::reexports::wayland_server::backend::GlobalId;
+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
+use smithay::reexports::wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New};
+
+use crate::gtk_shell_protocol::server::gtk_shell1::{self, GtkShell1};
+use crate::gtk_shell_protocol::server::gtk_surface1::{self, GtkSurface1};
+use crate::state::CompState;
+
+const PROTOCOL_VERSION: u32 = 7;
+
+/// `global_app_menu | global_menu_bar` - both bits set unconditionally.
+/// srdwm has no reason to advertise one without the other: both map onto
+/// the same `GlobalMenu`, just the app-menu-only fallback for a client
+/// that never got around to exporting a real menu bar.
+const CAPABILITIES: u32 = 0b011;
+
+pub struct GtkShellState {
+ _global: GlobalId,
+}
+
+impl GtkShellState {
+ pub fn new<D>(dh: &DisplayHandle) -> Self
+ where
+ D: GlobalDispatch<GtkShell1, ()> + 'static,
+ {
+ Self { _global: dh.create_global::<D, GtkShell1, _>(PROTOCOL_VERSION, ()) }
+ }
+}
+
+/// The `wl_surface` a `gtk_surface1` was created for - the only thing
+/// `set_dbus_properties` needs to know which `WindowId` to attach its
+/// payload to.
+pub struct GtkSurfaceData {
+ surface: WlSurface,
+}
+
+impl GlobalDispatch<GtkShell1, (), CompState> for CompState {
+ fn bind(_state: &mut CompState, _dh: &DisplayHandle, _client: &Client, resource: New<GtkShell1>, _global_data: &(), data_init: &mut DataInit<'_, CompState>) {
+ let shell = data_init.init(resource, ());
+ // Sent once, right after bind - see this module's doc comment for
+ // why this has to happen unprompted rather than waiting to be
+ // asked: GTK only bothers calling `set_dbus_properties` later if it
+ // saw this first.
+ shell.capabilities(CAPABILITIES);
+ }
+}
+
+impl Dispatch<GtkShell1, ()> for CompState {
+ fn request(state: &mut CompState, _client: &Client, _resource: &GtkShell1, request: gtk_shell1::Request, _data: &(), _dh: &DisplayHandle, data_init: &mut DataInit<'_, CompState>) {
+ if let gtk_shell1::Request::GetGtkSurface { gtk_surface, surface } = request {
+ data_init.init(gtk_surface, GtkSurfaceData { surface });
+ }
+ // `set_startup_id`/`system_bell`/`notify_launch`: no startup-
+ // notification or accessibility-bell feature exists to wire these
+ // into yet - see this module's doc comment.
+ let _ = state;
+ }
+}
+
+impl Dispatch<GtkSurface1, GtkSurfaceData> for CompState {
+ fn request(state: &mut CompState, _client: &Client, _resource: &GtkSurface1, request: gtk_surface1::Request, data: &GtkSurfaceData, _dh: &DisplayHandle, _data_init: &mut DataInit<'_, CompState>) {
+ let gtk_surface1::Request::SetDbusProperties { menubar_path, app_menu_path, window_object_path, application_object_path, unique_bus_name, .. } = request else {
+ // `set_modal`/`unset_modal`/`present`/`request_focus`/`release`/
+ // `titlebar_gesture`/`set_a11y_properties`: real requests, none
+ // of which this pass has a feature behind yet.
+ return;
+ };
+ let Some(&id) = state.surface_to_id.get(&data.surface) else { return };
+ // A `None`/empty bus name means the client is *clearing* its menu
+ // (or never had one) - matches `xwayland.rs`'s `read_global_menu`
+ // returning `None` for the same case, so a panel sees the same
+ // shape regardless of which backend a window came from.
+ // Always `MenuSource::Gtk`: this protocol has no Unity-style
+ // equivalent to carry, unlike XWayland's `_UNITY_OBJECT_PATH` --
+ // see `xwayland.rs`'s `read_global_menu` for the case that needs
+ // the other variant.
+ let menu = unique_bus_name.filter(|s| !s.is_empty()).map(|bus_name| srdwm_core::GlobalMenu {
+ bus_name,
+ menu_path: menubar_path.filter(|s| !s.is_empty()).or_else(|| app_menu_path.filter(|s| !s.is_empty())),
+ app_path: application_object_path.filter(|s| !s.is_empty()),
+ window_path: window_object_path.filter(|s| !s.is_empty()),
+ source: srdwm_core::MenuSource::Gtk,
+ });
+ if let Some(w) = state.wm.borrow_mut().window_mut(id) {
+ w.global_menu = menu;
+ }
+ }
+
+ fn destroyed(state: &mut CompState, _client: smithay::reexports::wayland_server::backend::ClientId, _resource: &GtkSurface1, data: &GtkSurfaceData) {
+ // The surface itself may already be gone (this fires on the normal
+ // window-close teardown path too, not just an explicit `release`)
+ // - `surface_to_id` simply won't resolve in that case, same as
+ // any other post-close lookup elsewhere in this codebase.
+ if let Some(&id) = state.surface_to_id.get(&data.surface) {
+ if let Some(w) = state.wm.borrow_mut().window_mut(id) {
+ w.global_menu = None;
+ }
+ }
+ }
+}