From 86bdc6898bc8a13368ba852692ff0cc248345128 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 2 Nov 2024 10:35:05 +0300 Subject: Add with_toplevel_role() util function --- src/utils/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/mod.rs b/src/utils/mod.rs index d5201532..959a804e 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -17,8 +17,11 @@ use smithay::reexports::rustix::time::{clock_gettime, ClockId}; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Coordinate, Logical, Point, Rectangle, Size, Transform}; -use smithay::wayland::compositor::{send_surface_state, SurfaceData}; +use smithay::wayland::compositor::{send_surface_state, with_states, SurfaceData}; use smithay::wayland::fractional_scale::with_fractional_scale; +use smithay::wayland::shell::xdg::{ + ToplevelSurface, XdgToplevelSurfaceData, XdgToplevelSurfaceRoleAttributes, +}; pub mod id; pub mod scale; @@ -221,6 +224,22 @@ pub fn output_matches_name(output: &Output, target: &str) -> bool { name.matches(target) } +pub fn with_toplevel_role( + toplevel: &ToplevelSurface, + f: impl FnOnce(&mut XdgToplevelSurfaceRoleAttributes) -> T, +) -> T { + with_states(toplevel.wl_surface(), |states| { + let mut role = states + .data_map + .get::() + .unwrap() + .lock() + .unwrap(); + + f(&mut role) + }) +} + #[cfg(feature = "dbus")] pub fn show_screenshot_notification(image_path: Option) { let mut notification = notify_rust::Notification::new(); -- cgit