diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-04 09:44:42 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-15 09:04:16 +0300 |
| commit | 9bd860b3935f34442abe37c6171fe300172fc598 (patch) | |
| tree | 2ff98959bd456b555987e9221a51db836d5d824d /src/utils | |
| parent | dd1ec83afa40b3c6b17df7fa4a5b7033c50f14ab (diff) | |
| download | niri-9bd860b3935f34442abe37c6171fe300172fc598.tar.gz niri-9bd860b3935f34442abe37c6171fe300172fc598.tar.bz2 niri-9bd860b3935f34442abe37c6171fe300172fc598.zip | |
Extract with_toplevel_last_uncommitted_configure()
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/mod.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 8efa8654..53537098 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -25,7 +25,7 @@ use smithay::utils::{Coordinate, Logical, Point, Rectangle, Size, Transform}; use smithay::wayland::compositor::{send_surface_state, with_states, SurfaceData}; use smithay::wayland::fractional_scale::with_fractional_scale; use smithay::wayland::shell::xdg::{ - ToplevelCachedState, ToplevelState, ToplevelSurface, XdgToplevelSurfaceData, + ToplevelCachedState, ToplevelConfigure, ToplevelState, ToplevelSurface, XdgToplevelSurfaceData, XdgToplevelSurfaceRoleAttributes, }; use wayland_backend::server::Credentials; @@ -299,6 +299,41 @@ pub fn with_toplevel_role_and_current<T>( }) } +pub fn with_toplevel_last_uncommitted_configure<T>( + toplevel: &ToplevelSurface, + f: impl FnOnce(Option<&ToplevelConfigure>) -> T, +) -> T { + with_states(toplevel.wl_surface(), |states| { + let role = states + .data_map + .get::<XdgToplevelSurfaceData>() + .unwrap() + .lock() + .unwrap(); + + let mut guard = states.cached_state.get::<ToplevelCachedState>(); + + if let Some(last_pending) = role.pending_configures().last() { + // Configure not yet acked by the client. + f(Some(last_pending)) + } else if let Some(last_acked) = &role.last_acked { + let mut configure = Some(last_acked); + + if let Some(committed) = &guard.current().last_acked { + if committed.serial.is_no_older_than(&last_acked.serial) { + // Already committed to this configure. + configure = None; + } + } + + f(configure) + } else { + // Surface hadn't been configured yet. + f(None) + } + }) +} + pub fn update_tiled_state( toplevel: &ToplevelSurface, prefer_no_csd: bool, |
