Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get client pid to x11 surface #1670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ wayland-server = { version = "0.31.7", optional = true }
wayland-sys = { version = "0.31.6", optional = true }
wayland-backend = { version = "0.3.8", optional = true }
winit = { version = "0.30.0", default-features = false, features = ["wayland", "wayland-dlopen", "x11", "rwh_06"], optional = true }
x11rb = { version = "0.13.0", optional = true }
x11rb = { version = "0.13.0", optional = true, features = ["res"]}
xkbcommon = { version = "0.8.0", features = ["wayland"]}
encoding_rs = { version = "0.8.33", optional = true }
profiling = "1.0.13"
Expand Down
43 changes: 40 additions & 3 deletions src/xwayland/xwm/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ use wayland_server::protocol::wl_surface::WlSurface;
use x11rb::{
connection::Connection as _,
properties::{WmClass, WmHints, WmSizeHints},
protocol::xproto::{
Atom, AtomEnum, ClientMessageEvent, ConfigureWindowAux, ConnectionExt as _, EventMask, InputFocus,
PropMode, Window as X11Window,
protocol::{
res::{query_client_ids, ClientIdSpec},
xproto::{
Atom, AtomEnum, ClientMessageEvent, ConfigureWindowAux, ConnectionExt as _, EventMask,
InputFocus, PropMode, Window as X11Window,
},
},
rust_connection::{ConnectionError, RustConnection},
wrapper::ConnectionExt,
Expand Down Expand Up @@ -924,6 +927,40 @@ impl X11Surface {
}
conn.flush()
}

/// Get the client PID associated with the X11 window.
pub fn get_client_pid(&self) -> Result<u32, Box<dyn std::error::Error>> {
if let Some(connection) = self.conn.upgrade() {
let window = self.window;

match query_client_ids(
&connection,
&[ClientIdSpec {
client: window,
mask: x11rb::protocol::res::ClientIdMask::LOCAL_CLIENT_PID,
}],
) {
Ok(cookie) => {
let reply = cookie.reply()?;

if let Some(id_value) = reply.ids.first() {
if let Some(pid) = id_value.value.first().copied() {
return Ok(pid);
} else {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"No matching client ID found",
)));
}
}
}
Err(_) => {
return Ok(0);
}
}
}
Ok(0)
}
}

/// Trait for objects, that represent an x11 window in some shape or form
Expand Down
Loading