aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-11-02 10:35:05 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-11-02 10:53:55 +0300
commit86bdc6898bc8a13368ba852692ff0cc248345128 (patch)
tree4c3106f4bc51501289a2cd2aa858f8d14d332677 /src/utils
parente5ca3351153fa6f3d1e3b00806f85058a8182065 (diff)
downloadniri-86bdc6898bc8a13368ba852692ff0cc248345128.tar.gz
niri-86bdc6898bc8a13368ba852692ff0cc248345128.tar.bz2
niri-86bdc6898bc8a13368ba852692ff0cc248345128.zip
Add with_toplevel_role() util function
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mod.rs21
1 files changed, 20 insertions, 1 deletions
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<T>(
+ toplevel: &ToplevelSurface,
+ f: impl FnOnce(&mut XdgToplevelSurfaceRoleAttributes) -> T,
+) -> T {
+ with_states(toplevel.wl_surface(), |states| {
+ let mut role = states
+ .data_map
+ .get::<XdgToplevelSurfaceData>()
+ .unwrap()
+ .lock()
+ .unwrap();
+
+ f(&mut role)
+ })
+}
+
#[cfg(feature = "dbus")]
pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
let mut notification = notify_rust::Notification::new();