diff --git a/Cargo.lock b/Cargo.lock index 1d35ea59..115b0427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3455,7 +3455,7 @@ checksum = "e8e2fb0f499abb4d162f2bedad68f5ef91a1682b5a03596ddb67efd37768d100" [[package]] name = "smithay" version = "0.7.0" -source = "git+https://github.com/Smithay/smithay.git?rev=0ff00983b6007257a7a161a4fe8b14a778e2ac8f#0ff00983b6007257a7a161a4fe8b14a778e2ac8f" +source = "git+https://github.com/Smithay/smithay.git?rev=22571baa20d34d71092942dbb520c4e3fbbd6263#22571baa20d34d71092942dbb520c4e3fbbd6263" dependencies = [ "aliasable", "appendlist", @@ -3532,7 +3532,7 @@ dependencies = [ [[package]] name = "smithay-drm-extras" version = "0.1.0" -source = "git+https://github.com/Smithay/smithay.git?rev=0ff00983b6007257a7a161a4fe8b14a778e2ac8f#0ff00983b6007257a7a161a4fe8b14a778e2ac8f" +source = "git+https://github.com/Smithay/smithay.git?rev=22571baa20d34d71092942dbb520c4e3fbbd6263#22571baa20d34d71092942dbb520c4e3fbbd6263" dependencies = [ "drm", "libdisplay-info", diff --git a/Cargo.toml b/Cargo.toml index e89acd28..dacaf042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,13 +28,13 @@ tracy-client = { version = "0.18.5", default-features = false } [workspace.dependencies.smithay] # version = "0.4.1" git = "https://github.com/Smithay/smithay.git" -rev = "0ff00983b6007257a7a161a4fe8b14a778e2ac8f" +rev = "22571baa20d34d71092942dbb520c4e3fbbd6263" default-features = false [workspace.dependencies.smithay-drm-extras] # version = "0.1.0" git = "https://github.com/Smithay/smithay.git" -rev = "0ff00983b6007257a7a161a4fe8b14a778e2ac8f" +rev = "22571baa20d34d71092942dbb520c4e3fbbd6263" # path = "../smithay/smithay-drm-extras" [package] diff --git a/src/handlers/image_copy_capture.rs b/src/handlers/image_copy_capture.rs index aad0e891..81f9fd12 100644 --- a/src/handlers/image_copy_capture.rs +++ b/src/handlers/image_copy_capture.rs @@ -12,6 +12,7 @@ use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction}; use smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer; use smithay::reexports::wayland_server::protocol::wl_pointer::WlPointer; use smithay::reexports::wayland_server::protocol::wl_shm; +use smithay::reexports::wayland_server::{Client, DisplayHandle}; use smithay::utils::{ Buffer as BufferCoords, Logical, Physical, Point, Rectangle, Scale, Size, Transform, }; @@ -25,10 +26,11 @@ use smithay::wayland::image_copy_capture::{ Frame, FrameRef, ImageCopyCaptureHandler, ImageCopyCaptureState, Session, SessionRef, }; use smithay::wayland::shm; +use wayland_backend::server::Credentials; use crate::cursor::{RenderCursor, XCursor}; use crate::niri::{Niri, State}; -use crate::utils::{CastSessionId, CastStreamId}; +use crate::utils::{get_credentials_for_client, CastSessionId, CastStreamId}; /// Output capture session. pub struct ImageCopySession { @@ -40,6 +42,8 @@ pub struct ImageCopySession { pub session_id: CastSessionId, /// Cast stream id, unique to this session. pub stream_id: CastStreamId, + /// Credentials of the capturing client, if known. + pub credentials: Option, } /// Cursor capture session of an output. @@ -53,6 +57,17 @@ pub struct ImageCopyCursorSession { pub session_id: CastSessionId, /// Cast stream id, unique to this session. pub stream_id: CastStreamId, + /// Credentials of the capturing client, if known. + pub credentials: Option, +} + +/// Credentials for the client which created a capture session. +/// +/// Returns `None` if the session doesn't have its client (it has already been +/// dropped) or if the credentials cannot be determined (e.g., if peer is +/// credentials_unknown like mutter_service_channel). +fn session_credentials(dh: &DisplayHandle, client: Option) -> Option { + get_credentials_for_client(dh, &client?) } /// Cast session id of an image capture source. @@ -311,12 +326,14 @@ impl ImageCopyCaptureHandler for State { // Will be updated with the output properties before capture. let damage_tracker = OutputDamageTracker::new((0, 0), 1.0, Transform::Normal); let session_id = source_session_id(&session.source()); + let credentials = session_credentials(&self.niri.display_handle, session.client()); self.niri.image_copy_sessions.push(ImageCopySession { session, damage_tracker, pending_frame: None, session_id, stream_id: CastStreamId::next(), + credentials, }); } @@ -324,6 +341,7 @@ impl ImageCopyCaptureHandler for State { // Will be updated with the output properties before capture. let damage_tracker = OutputDamageTracker::new((0, 0), 1.0, Transform::Normal); let session_id = source_session_id(&session.source()); + let credentials = session_credentials(&self.niri.display_handle, session.client()); self.niri .image_copy_cursor_sessions .push(ImageCopyCursorSession { @@ -332,6 +350,7 @@ impl ImageCopyCaptureHandler for State { pending_frame: None, session_id, stream_id: CastStreamId::next(), + credentials, }); // Send the initial cursor position and hotspot. self.niri.refresh_image_copy_cursor_sessions(); diff --git a/src/ipc/server.rs b/src/ipc/server.rs index aab2ba7b..374216c2 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -916,13 +916,13 @@ impl State { .niri .image_copy_sessions .iter() - .map(|s| (s.session_id, s.stream_id, s.session.source())); + .map(|s| (s.session_id, s.stream_id, s.session.source(), s.credentials)); let cursor_sessions = self .niri .image_copy_cursor_sessions .iter() - .map(|s| (s.session_id, s.stream_id, s.session.source())); - for (session_id, stream_id, source) in output_sessions.chain(cursor_sessions) { + .map(|s| (s.session_id, s.stream_id, s.session.source(), s.credentials)); + for (session_id, stream_id, source, credentials) in output_sessions.chain(cursor_sessions) { let Some(output) = image_copy_capture::source_output(&source) else { continue; }; @@ -940,8 +940,7 @@ impl State { }, is_dynamic_target: false, is_active: true, - // FIXME: smithay doesn't expose the client of a image-copy-capture session. - pid: None, + pid: credentials.map(|creds| creds.pid), pw_node_id: None, }; events.push(Event::CastStartedOrChanged { cast });