mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Add PID to Window IPC
This commit is contained in:
@@ -695,6 +695,11 @@ pub struct Window {
|
||||
pub title: Option<String>,
|
||||
/// Application ID, if set.
|
||||
pub app_id: Option<String>,
|
||||
/// Process ID that created the Wayland connection for this window, if known.
|
||||
///
|
||||
/// Currently, windows created by xdg-desktop-portal-gnome will have a `None` PID, but this may
|
||||
/// change in the future.
|
||||
pub pid: Option<i32>,
|
||||
/// Id of the workspace this window is on, if any.
|
||||
pub workspace_id: Option<u64>,
|
||||
/// Whether this window is currently focused.
|
||||
|
||||
@@ -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()) })
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
+16
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user