forge
Explore
Log in

Don't you dare go Hollow

Show client in cast ipc for ext-image-copy-capture

Browse files at this commit

66d04a7d72e25a6c74307bab33a91924d124755dPatrick GaskinParent: 298acfe
  • feat
    • show client in cast ipc for ext-image-copy-capture
Show full message
feat: show client in cast ipc for ext-image-copy-capture
Cargo.lockmodified+2 -2
@@ -3455,7 +3455,7 @@ checksum = "e8e2fb0f499abb4d162f2bedad68f5ef91a1682b5a03596ddb67efd37768d100"
34553455 [[package]]
34563456 name = "smithay"
34573457 version = "0.7.0"
3458-source = "git+https://github.com/Smithay/smithay.git?rev=0ff00983b6007257a7a161a4fe8b14a778e2ac8f#0ff00983b6007257a7a161a4fe8b14a778e2ac8f"
3458+source = "git+https://github.com/Smithay/smithay.git?rev=22571baa20d34d71092942dbb520c4e3fbbd6263#22571baa20d34d71092942dbb520c4e3fbbd6263"
34593459 dependencies = [
34603460 "aliasable",
34613461 "appendlist",
@@ -3532,7 +3532,7 @@ dependencies = [
35323532 [[package]]
35333533 name = "smithay-drm-extras"
35343534 version = "0.1.0"
3535-source = "git+https://github.com/Smithay/smithay.git?rev=0ff00983b6007257a7a161a4fe8b14a778e2ac8f#0ff00983b6007257a7a161a4fe8b14a778e2ac8f"
3535+source = "git+https://github.com/Smithay/smithay.git?rev=22571baa20d34d71092942dbb520c4e3fbbd6263#22571baa20d34d71092942dbb520c4e3fbbd6263"
35363536 dependencies = [
35373537 "drm",
35383538 "libdisplay-info",
Cargo.tomlmodified+2 -2
@@ -28,13 +28,13 @@ tracy-client = { version = "0.18.5", default-features = false }
2828 [workspace.dependencies.smithay]
2929 # version = "0.4.1"
3030 git = "https://github.com/Smithay/smithay.git"
31-rev = "0ff00983b6007257a7a161a4fe8b14a778e2ac8f"
31+rev = "22571baa20d34d71092942dbb520c4e3fbbd6263"
3232 default-features = false
3333
3434 [workspace.dependencies.smithay-drm-extras]
3535 # version = "0.1.0"
3636 git = "https://github.com/Smithay/smithay.git"
37-rev = "0ff00983b6007257a7a161a4fe8b14a778e2ac8f"
37+rev = "22571baa20d34d71092942dbb520c4e3fbbd6263"
3838 # path = "../smithay/smithay-drm-extras"
3939
4040 [package]
src/handlers/image_copy_capture.rsmodified+20 -1
@@ -12,6 +12,7 @@ use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
1212 use smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer;
1313 use smithay::reexports::wayland_server::protocol::wl_pointer::WlPointer;
1414 use smithay::reexports::wayland_server::protocol::wl_shm;
15+use smithay::reexports::wayland_server::{Client, DisplayHandle};
1516 use smithay::utils::{
1617 Buffer as BufferCoords, Logical, Physical, Point, Rectangle, Scale, Size, Transform,
1718 };
@@ -25,10 +26,11 @@ use smithay::wayland::image_copy_capture::{
2526 Frame, FrameRef, ImageCopyCaptureHandler, ImageCopyCaptureState, Session, SessionRef,
2627 };
2728 use smithay::wayland::shm;
29+use wayland_backend::server::Credentials;
2830
2931 use crate::cursor::{RenderCursor, XCursor};
3032 use crate::niri::{Niri, State};
31-use crate::utils::{CastSessionId, CastStreamId};
33+use crate::utils::{get_credentials_for_client, CastSessionId, CastStreamId};
3234
3335 /// Output capture session.
3436 pub struct ImageCopySession {
@@ -40,6 +42,8 @@ pub struct ImageCopySession {
4042 pub session_id: CastSessionId,
4143 /// Cast stream id, unique to this session.
4244 pub stream_id: CastStreamId,
45+ /// Credentials of the capturing client, if known.
46+ pub credentials: Option<Credentials>,
4347 }
4448
4549 /// Cursor capture session of an output.
@@ -53,6 +57,17 @@ pub struct ImageCopyCursorSession {
5357 pub session_id: CastSessionId,
5458 /// Cast stream id, unique to this session.
5559 pub stream_id: CastStreamId,
60+ /// Credentials of the capturing client, if known.
61+ pub credentials: Option<Credentials>,
62+}
63+
64+/// Credentials for the client which created a capture session.
65+///
66+/// Returns `None` if the session doesn't have its client (it has already been
67+/// dropped) or if the credentials cannot be determined (e.g., if peer is
68+/// credentials_unknown like mutter_service_channel).
69+fn session_credentials(dh: &DisplayHandle, client: Option<Client>) -> Option<Credentials> {
70+ get_credentials_for_client(dh, &client?)
5671 }
5772
5873 /// Cast session id of an image capture source.
@@ -311,12 +326,14 @@ impl ImageCopyCaptureHandler for State {
311326 // Will be updated with the output properties before capture.
312327 let damage_tracker = OutputDamageTracker::new((0, 0), 1.0, Transform::Normal);
313328 let session_id = source_session_id(&session.source());
329+ let credentials = session_credentials(&self.niri.display_handle, session.client());
314330 self.niri.image_copy_sessions.push(ImageCopySession {
315331 session,
316332 damage_tracker,
317333 pending_frame: None,
318334 session_id,
319335 stream_id: CastStreamId::next(),
336+ credentials,
320337 });
321338 }
322339
@@ -324,6 +341,7 @@ impl ImageCopyCaptureHandler for State {
324341 // Will be updated with the output properties before capture.
325342 let damage_tracker = OutputDamageTracker::new((0, 0), 1.0, Transform::Normal);
326343 let session_id = source_session_id(&session.source());
344+ let credentials = session_credentials(&self.niri.display_handle, session.client());
327345 self.niri
328346 .image_copy_cursor_sessions
329347 .push(ImageCopyCursorSession {
@@ -332,6 +350,7 @@ impl ImageCopyCaptureHandler for State {
332350 pending_frame: None,
333351 session_id,
334352 stream_id: CastStreamId::next(),
353+ credentials,
335354 });
336355 // Send the initial cursor position and hotspot.
337356 self.niri.refresh_image_copy_cursor_sessions();
src/ipc/server.rsmodified+4 -5
@@ -916,13 +916,13 @@ impl State {
916916 .niri
917917 .image_copy_sessions
918918 .iter()
919- .map(|s| (s.session_id, s.stream_id, s.session.source()));
919+ .map(|s| (s.session_id, s.stream_id, s.session.source(), s.credentials));
920920 let cursor_sessions = self
921921 .niri
922922 .image_copy_cursor_sessions
923923 .iter()
924- .map(|s| (s.session_id, s.stream_id, s.session.source()));
925- for (session_id, stream_id, source) in output_sessions.chain(cursor_sessions) {
924+ .map(|s| (s.session_id, s.stream_id, s.session.source(), s.credentials));
925+ for (session_id, stream_id, source, credentials) in output_sessions.chain(cursor_sessions) {
926926 let Some(output) = image_copy_capture::source_output(&source) else {
927927 continue;
928928 };
@@ -940,8 +940,7 @@ impl State {
940940 },
941941 is_dynamic_target: false,
942942 is_active: true,
943- // FIXME: smithay doesn't expose the client of a image-copy-capture session.
944- pid: None,
943+ pid: credentials.map(|creds| creds.pid),
945944 pw_node_id: None,
946945 };
947946 events.push(Event::CastStartedOrChanged { cast });