diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-11-12 09:09:33 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-11-12 09:37:25 +0300 |
| commit | d193928f315912b67cc997ab4e6f96675695374e (patch) | |
| tree | 4e17af4386b8109897eecb64f9223e4add09d80b /src | |
| parent | 17861e0003c122dec9ad8cca1177c750ca6390c8 (diff) | |
| download | niri-d193928f315912b67cc997ab4e6f96675695374e.tar.gz niri-d193928f315912b67cc997ab4e6f96675695374e.tar.bz2 niri-d193928f315912b67cc997ab4e6f96675695374e.zip | |
Add PID to Window IPC
Diffstat (limited to 'src')
| -rw-r--r-- | src/dbus/mutter_service_channel.rs | 2 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 1 | ||||
| -rw-r--r-- | src/ipc/client.rs | 6 | ||||
| -rw-r--r-- | src/ipc/server.rs | 1 | ||||
| -rw-r--r-- | src/niri.rs | 3 | ||||
| -rw-r--r-- | src/utils/mod.rs | 17 | ||||
| -rw-r--r-- | src/window/mapped.rs | 17 |
7 files changed, 46 insertions, 1 deletions
diff --git a/src/dbus/mutter_service_channel.rs b/src/dbus/mutter_service_channel.rs index 3d30ac17..c78dcbee 100644 --- a/src/dbus/mutter_service_channel.rs +++ b/src/dbus/mutter_service_channel.rs @@ -30,6 +30,8 @@ impl ServiceChannel { // Would be nice to thread config here but for now it's fine. can_view_decoration_globals: false, restricted: false, + // FIXME: maybe you can get the PID from D-Bus somehow? + credentials_unknown: true, }); self.display.insert_client(sock2, data).unwrap(); Ok(unsafe { zbus::zvariant::OwnedFd::from_raw_fd(sock1.into_raw_fd()) }) diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 6de1e09e..fcd1fb7d 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -410,6 +410,7 @@ impl SecurityContextHandler for State { compositor_state: Default::default(), can_view_decoration_globals: config.prefer_no_csd, restricted: true, + credentials_unknown: false, }); if let Err(err) = state.niri.display_handle.insert_client(client, data) { diff --git a/src/ipc/client.rs b/src/ipc/client.rs index 472daab2..112447f4 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -449,6 +449,12 @@ fn print_window(window: &Window) { println!(" App ID: (unset)"); } + if let Some(pid) = window.pid { + println!(" PID: {pid}"); + } else { + println!(" PID: (unknown)"); + } + if let Some(workspace_id) = window.workspace_id { println!(" Workspace ID: {workspace_id}"); } else { diff --git a/src/ipc/server.rs b/src/ipc/server.rs index be463aa2..91801028 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -363,6 +363,7 @@ fn make_ipc_window(mapped: &Mapped, workspace_id: Option<WorkspaceId>) -> niri_i id: mapped.id().get(), title: role.title.clone(), app_id: role.app_id.clone(), + pid: mapped.credentials().map(|c| c.pid), workspace_id: workspace_id.map(|id| id.get()), is_focused: mapped.is_focused(), }) diff --git a/src/niri.rs b/src/niri.rs index a9210a69..ee3116d0 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -1773,6 +1773,7 @@ impl Niri { compositor_state: Default::default(), can_view_decoration_globals: config.prefer_no_csd, restricted: false, + credentials_unknown: false, }); if let Err(err) = state.niri.display_handle.insert_client(client, data) { @@ -4825,6 +4826,8 @@ pub struct ClientState { pub can_view_decoration_globals: bool, /// Whether this client is denied from the restricted protocols such as security-context. pub restricted: bool, + /// We cannot retrieve this client's socket credentials. + pub credentials_unknown: bool, } impl ClientData for ClientState { 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(); diff --git a/src/window/mapped.rs b/src/window/mapped.rs index e9f087bd..b1213c8f 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -15,7 +15,9 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::Resource as _; use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform}; use smithay::wayland::compositor::{remove_pre_commit_hook, with_states, HookId}; +use smithay::wayland::seat::WaylandFocus; use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; +use wayland_backend::server::Credentials; use super::{ResolvedWindowRules, WindowRef}; use crate::handlers::KdeDecorationsModeState; @@ -33,7 +35,9 @@ use crate::render_helpers::surface::render_snapshot_from_surface_tree; use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; use crate::utils::id::IdCounter; use crate::utils::transaction::Transaction; -use crate::utils::{send_scale_transform, with_toplevel_role, ResizeEdge}; +use crate::utils::{ + get_credentials_for_surface, send_scale_transform, with_toplevel_role, ResizeEdge, +}; #[derive(Debug)] pub struct Mapped { @@ -42,6 +46,9 @@ pub struct Mapped { /// Unique ID of this `Mapped`. id: MappedId, + /// Credentials of the process that created the Wayland connection. + credentials: Option<Credentials>, + /// Pre-commit hook that we have on all mapped toplevel surfaces. pre_commit_hook: HookId, @@ -136,9 +143,13 @@ impl InteractiveResize { impl Mapped { pub fn new(window: Window, rules: ResolvedWindowRules, hook: HookId) -> Self { + let surface = window.wl_surface().expect("no X11 support"); + let credentials = get_credentials_for_surface(&surface); + Self { window, id: MappedId::next(), + credentials, pre_commit_hook: hook, rules, need_to_recompute_rules: false, @@ -188,6 +199,10 @@ impl Mapped { self.id } + pub fn credentials(&self) -> Option<&Credentials> { + self.credentials.as_ref() + } + pub fn is_focused(&self) -> bool { self.is_focused } |
