From 93a94e767b5c6b0e348748fccefcbaf0be149aac Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 3 Oct 2022 16:29:16 +0300 Subject: [PATCH] compositor: authorize new screenshooter protocol This is necessary in order to convert clients/screenshot.c into the protocol. We authorize a client the same way as before: if the wl_client is the one we spawned, it's allowed. Allowing screenshots on --debug was authorized by an earlier patch in compositor/main.c. Signed-off-by: Pekka Paalanen --- compositor/weston-screenshooter.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compositor/weston-screenshooter.c b/compositor/weston-screenshooter.c index 9b437d3ce..9099fc740 100644 --- a/compositor/weston-screenshooter.c +++ b/compositor/weston-screenshooter.c @@ -1,5 +1,6 @@ /* * Copyright © 2008-2011 Kristian Høgsberg + * Copyright 2022 Collabora, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -41,6 +42,7 @@ struct screenshooter { struct weston_process process; struct wl_listener destroy_listener; struct weston_recorder *recorder; + struct wl_listener authorization; }; static void @@ -165,6 +167,17 @@ recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time, } } +static void +authorize_screenshooter(struct wl_listener *l, + struct weston_output_capture_attempt *att) +{ + struct screenshooter *shooter = wl_container_of(l, shooter, + authorization); + + if (shooter->client && att->who->client == shooter->client) + att->authorized = true; +} + static void screenshooter_destroy(struct wl_listener *listener, void *data) { @@ -172,6 +185,7 @@ screenshooter_destroy(struct wl_listener *listener, void *data) container_of(listener, struct screenshooter, destroy_listener); wl_list_remove(&shooter->destroy_listener.link); + wl_list_remove(&shooter->authorization.link); wl_global_destroy(shooter->global); free(shooter); @@ -198,4 +212,7 @@ screenshooter_create(struct weston_compositor *ec) shooter->destroy_listener.notify = screenshooter_destroy; wl_signal_add(&ec->destroy_signal, &shooter->destroy_listener); + + weston_compositor_add_screenshot_authority(ec, &shooter->authorization, + authorize_screenshooter); }