Update smithay

Updates for `last_acked`, etc. API changes in
https://github.com/Smithay/smithay/pull/1817.

Includes layer shell fixes
from https://github.com/Smithay/smithay/pull/1819.
This commit is contained in:
Ian Douglas Scott 2025-10-09 18:18:29 -07:00 committed by Victoria Brekenfeld
parent 9816b18259
commit e129094bfb
4 changed files with 45 additions and 40 deletions

View file

@ -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::<XdgToplevelSurfaceData>()
.unwrap()
.lock()
.unwrap();
attrs
.current_serial
let mut guard = states.cached_state.get::<ToplevelCachedState>();
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::<ToplevelCachedState>();
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, F: FnOnce(&smithay::wayland::shell::xdg::ToplevelState) -> T>(
fn with_toplevel_state<T, F: FnOnce(Option<&smithay::wayland::shell::xdg::ToplevelState>) -> 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(&current)
toplevel.with_committed_state(|committed| cb(committed))
}
}