diff --git a/Cargo.lock b/Cargo.lock index 9ed56891..f95c8f4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4961,7 +4961,7 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "smithay" version = "0.7.0" -source = "git+https://github.com/smithay/smithay.git?rev=eb45814#eb45814725597a7f0db07eccf4bd473d87c730bc" +source = "git+https://github.com/smithay/smithay.git?rev=d743e1a#d743e1a317fa0f01d1c4cadd96d277a1ec7b59d9" dependencies = [ "aliasable", "appendlist", diff --git a/Cargo.toml b/Cargo.toml index 12b37dc9..1bc217b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,4 +145,4 @@ cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch cosmic-client-toolkit = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" } [patch.crates-io] -smithay = { git = "https://github.com/smithay/smithay.git", rev = "eb45814" } +smithay = { git = "https://github.com/smithay/smithay.git", rev = "d743e1a" } diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index 89e21392..098b386d 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -43,7 +43,9 @@ use smithay::{ wayland::{ compositor::{SurfaceData, TraversalAction, with_states, with_surface_tree_downward}, seat::WaylandFocus, - shell::xdg::{SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceData}, + shell::xdg::{ + SurfaceCachedState, ToplevelCachedState, ToplevelSurface, XdgToplevelSurfaceData, + }, }, xwayland::{X11Surface, xwm::X11Relatable}, }; @@ -215,7 +217,7 @@ impl CosmicSurface { pub fn is_activated(&self, pending: bool) -> bool { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| { - state.states.contains(ToplevelState::Activated) + state.is_some_and(|state| state.states.contains(ToplevelState::Activated)) }), WindowSurface::X11(surface) => surface.is_activated(), } @@ -247,9 +249,11 @@ impl CosmicSurface { }); let xdg_state = with_toplevel_state(toplevel, pending, |state| { - state - .decoration_mode - .map(|mode| mode == DecorationMode::ClientSide) + state.and_then(|state| { + state + .decoration_mode + .map(|mode| mode == DecorationMode::ClientSide) + }) }); kde_state.or(xdg_state).unwrap_or(true) @@ -262,7 +266,9 @@ impl CosmicSurface { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => { if enable { - let previous_decoration_state = toplevel.current_state().decoration_mode; + let previous_decoration_state = toplevel.with_committed_state(|state| { + state.map_or_else(Default::default, |state| state.decoration_mode) + }); if PreferredDecorationMode::is_unset(&self.0) { PreferredDecorationMode::update(&self.0, previous_decoration_state); } @@ -298,7 +304,7 @@ impl CosmicSurface { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => { Some(with_toplevel_state(toplevel, pending, |state| { - state.states.contains(ToplevelState::Resizing) + state.is_some_and(|state| state.states.contains(ToplevelState::Resizing)) })) } WindowSurface::X11(_surface) => None, @@ -322,7 +328,7 @@ impl CosmicSurface { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => { Some(with_toplevel_state(toplevel, pending, |state| { - state.states.contains(ToplevelState::TiledLeft) + state.is_some_and(|state| state.states.contains(ToplevelState::TiledLeft)) })) } WindowSurface::X11(_surface) => None, @@ -351,7 +357,7 @@ impl CosmicSurface { pub fn is_fullscreen(&self, pending: bool) -> bool { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| { - state.states.contains(ToplevelState::Fullscreen) + state.is_some_and(|state| state.states.contains(ToplevelState::Fullscreen)) }), WindowSurface::X11(surface) => surface.is_fullscreen(), } @@ -375,7 +381,7 @@ impl CosmicSurface { pub fn is_maximized(&self, pending: bool) -> bool { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| { - state.states.contains(ToplevelState::Maximized) + state.is_some_and(|state| state.states.contains(ToplevelState::Maximized)) }), WindowSurface::X11(surface) => surface.is_maximized(), } @@ -491,10 +497,9 @@ impl CosmicSurface { .lock() .unwrap(); attrs - .configure_serial + .last_acked .as_ref() - .map(|s| s >= serial) - .unwrap_or(false) + .is_some_and(|configure| configure.serial >= *serial) }), WindowSurface::X11(_surface) => true, } @@ -503,17 +508,12 @@ impl CosmicSurface { pub fn serial_past(&self, serial: &Serial) -> bool { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| { - let attrs = states - .data_map - .get::() - .unwrap() - .lock() - .unwrap(); - attrs - .current_serial + let mut guard = states.cached_state.get::(); + guard + .current() + .last_acked .as_ref() - .map(|s| s >= serial) - .unwrap_or(false) + .is_some_and(|configure| configure.serial >= *serial) }), WindowSurface::X11(_surface) => true, } @@ -531,12 +531,18 @@ impl CosmicSurface { .unwrap(); let current_server = attributes.current_server_state(); - if attributes.current.size == current_server.size { + let mut guard = states.cached_state.get::(); + if guard + .current() + .last_acked + .as_ref() + .is_some_and(|configure| configure.state.size == current_server.size) + { // The window had committed for our previous size change, so we can // change the size again. trace!( "current size matches server size: {:?}", - attributes.current.size + guard.current().last_acked.as_ref().unwrap().state.size ); true } else { @@ -927,15 +933,14 @@ where } } -fn with_toplevel_state T>( +fn with_toplevel_state) -> T>( toplevel: &ToplevelSurface, pending: bool, cb: F, ) -> T { if pending { - toplevel.with_pending_state(|pending| cb(pending)) + toplevel.with_pending_state(|pending| cb(Some(pending))) } else { - let current = toplevel.current_state(); - cb(¤t) + toplevel.with_committed_state(|committed| cb(committed)) } } diff --git a/src/wayland/handlers/xdg_shell/popup.rs b/src/wayland/handlers/xdg_shell/popup.rs index b008d057..645c47f5 100644 --- a/src/wayland/handlers/xdg_shell/popup.rs +++ b/src/wayland/handlers/xdg_shell/popup.rs @@ -15,7 +15,9 @@ use smithay::{ wayland::{ compositor::{get_role, with_states}, seat::WaylandFocus, - shell::xdg::{PopupSurface, ToplevelSurface, XDG_POPUP_ROLE, XdgPopupSurfaceData}, + shell::xdg::{ + PopupCachedState, PopupSurface, ToplevelSurface, XDG_POPUP_ROLE, XdgPopupSurfaceData, + }, }, }; use tracing::warn; @@ -87,14 +89,12 @@ pub fn update_reactive_popups<'a>( for (popup, _) in PopupManager::popups_for_surface(toplevel.wl_surface()) { match popup { PopupKind::Xdg(surface) => { - let positioner = with_states(surface.wl_surface(), |states| { - let attributes = states - .data_map - .get::() - .unwrap() - .lock() - .unwrap(); - attributes.current.positioner + let positioner = with_states(&surface.wl_surface(), |states| { + let mut guard = states.cached_state.get::(); + guard + .current() + .last_acked + .map_or_else(Default::default, |configure| configure.state.positioner) }); if positioner.reactive { let anchor_point = loc + positioner.get_anchor_point().as_global();