From efa2fe2d130bf08ec85032b99d88ecdb74a3b83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Nov 2025 17:41:04 +0100 Subject: [PATCH 1/2] display-panel-run-phosh: Send SIGTERM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send SIGTERM to phoc for clean shutdown. Signed-off-by: Guido Günther Part-of: --- examples/gm-display-panel-run-phosh.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/gm-display-panel-run-phosh.c b/examples/gm-display-panel-run-phosh.c index 895a7d4..f8f61a1 100644 --- a/examples/gm-display-panel-run-phosh.c +++ b/examples/gm-display-panel-run-phosh.c @@ -39,6 +39,8 @@ on_shutdown_signal (gpointer unused) g_autoptr (GError) err = NULL; gboolean success; + g_subprocess_send_signal (phoc, SIGTERM); + success = g_subprocess_wait (phoc, NULL, &err); if (!success) g_warning ("Failed to terminate phoc: %s", err->message); -- GitLab From 9a8e0661c79c15618e5a4394a67ad0a3d64913c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 10 Nov 2025 17:36:18 +0100 Subject: [PATCH 2/2] display-panel-run-phosh: Allow to take screenshot Allow to take a screenshot via `-S name`. We use a delayed callback to give phosh enough time to start so we don't accidentally bind to another process exposing the same API. Should that not prove to be robust enough we can spawn a separate bus. Closes: https://gitlab.gnome.org/World/Phosh/gmobile/-/issues/10 Part-of: --- examples/gm-display-panel-run-phosh.c | 71 ++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/examples/gm-display-panel-run-phosh.c b/examples/gm-display-panel-run-phosh.c index f8f61a1..8b5a7ce 100644 --- a/examples/gm-display-panel-run-phosh.c +++ b/examples/gm-display-panel-run-phosh.c @@ -24,6 +24,7 @@ GMainLoop *loop; GSubprocess *phoc; +GDBusProxy *proxy; G_NORETURN static void print_version (void) @@ -33,8 +34,8 @@ print_version (void) } -static gboolean -on_shutdown_signal (gpointer unused) +static void +quit(void) { g_autoptr (GError) err = NULL; gboolean success; @@ -46,6 +47,13 @@ on_shutdown_signal (gpointer unused) g_warning ("Failed to terminate phoc: %s", err->message); g_main_loop_quit (loop); +} + + +static gboolean +on_shutdown_signal (gpointer unused) +{ + quit(); return G_SOURCE_REMOVE; } @@ -120,6 +128,60 @@ phoc_utils_compute_scale (int32_t phys_width, int32_t phys_height, } +static void +on_screenshot_proxy_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + g_autoptr (GError) err = NULL; + g_autoptr (GVariant) result = NULL; + const char *filename, *template = user_data; + gboolean success; + + g_assert (template); + proxy = g_dbus_proxy_new_for_bus_finish (res, &err); + if (!proxy) { + g_critical ("Failed to get screensaver proxy: %s", err->message); + if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + quit (); + return; + } + + result = g_dbus_proxy_call_sync (proxy, "Screenshot", + g_variant_new ("(bbs)", + FALSE, + FALSE, + template), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &err); + if (!result) { + g_warning ("Failed to take screenshot: %s", err->message); + } else { + g_variant_get (result, "(b&s)", &success, &filename); + g_print ("Took screenshot '%s'", filename); + } + + quit (); +} + + +static void +on_timeout (gpointer user_data) +{ + char *template = user_data; + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.gnome.Shell.Screenshot", + "/org/gnome/Shell/Screenshot", + "org.gnome.Shell.Screenshot", + NULL, + on_screenshot_proxy_ready, + template); +} + + int main (int argc, char **argv) @@ -131,6 +193,7 @@ main (int argc, char **argv) g_auto (GStrv) compatibles = NULL; GmDisplayPanel *panel = NULL; GStrv compatibles_opt = NULL; + char *screenshot_name = NULL; g_autofree char *phoc_ini = NULL; g_autoptr (GSubprocessLauncher) phoc_launcher = NULL; double scale_opt = -1.0; @@ -143,6 +206,8 @@ main (int argc, char **argv) "The display scale", NULL }, {"headless", 'H', 0, G_OPTION_ARG_NONE, &headless, "Use headless backend", NULL }, + {"screenshot", 'S', 0, G_OPTION_ARG_FILENAME, &screenshot_name, + "Take screenshot", NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } @@ -212,6 +277,8 @@ main (int argc, char **argv) g_unix_signal_add (SIGTERM, on_shutdown_signal, NULL); g_unix_signal_add (SIGINT, on_shutdown_signal, NULL); + g_timeout_add_seconds_once (2, on_timeout, screenshot_name); + loop = g_main_loop_new (NULL, FALSE); g_message ("Launching phosh and phoc, hit CTRL-C to quit"); -- GitLab