aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-11-12 09:09:33 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-11-12 09:37:25 +0300
commitd193928f315912b67cc997ab4e6f96675695374e (patch)
tree4e17af4386b8109897eecb64f9223e4add09d80b /src/utils/mod.rs
parent17861e0003c122dec9ad8cca1177c750ca6390c8 (diff)
downloadniri-d193928f315912b67cc997ab4e6f96675695374e.tar.gz
niri-d193928f315912b67cc997ab4e6f96675695374e.tar.bz2
niri-d193928f315912b67cc997ab4e6f96675695374e.zip
Add PID to Window IPC
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 3d40d890..0b75966b 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -16,12 +16,16 @@ use smithay::output::{self, Output};
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::reexports::wayland_server::{DisplayHandle, Resource as _};
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::{
ToplevelSurface, XdgToplevelSurfaceData, XdgToplevelSurfaceRoleAttributes,
};
+use wayland_backend::server::Credentials;
+
+use crate::niri::ClientState;
pub mod id;
pub mod scale;
@@ -244,6 +248,19 @@ pub fn with_toplevel_role<T>(
})
}
+pub fn get_credentials_for_surface(surface: &WlSurface) -> Option<Credentials> {
+ let handle = surface.handle().upgrade()?;
+ let dh = DisplayHandle::from(handle);
+
+ let client = dh.get_client(surface.id()).ok()?;
+ let data = client.get_data::<ClientState>().unwrap();
+ if data.credentials_unknown {
+ return None;
+ }
+
+ client.get_credentials(&dh).ok()
+}
+
#[cfg(feature = "dbus")]
pub fn show_screenshot_notification(image_path: Option<PathBuf>) {
let mut notification = notify_rust::Notification::new();