From 17228b1afa3a466c3ae3ba53459f5cea56ac17bd Mon Sep 17 00:00:00 2001 From: Andrey Skvortsov Date: Tue, 20 May 2025 15:51:53 +0300 Subject: [PATCH] Add possibility to use hardware volume buttons to take a picture On many mobile operating systems it's possible to take picture using hardware volume buttons. It's easier to hold the phone and take pictures this way. Additionally it makes possible to use selfie stick (at least with jack plug). To be able to handle volume buttons global system shortcuts, that controls audio level has to be disabled. gdk_toplevel_inhibit_system_shortcuts tells compositor to block system keyboard shortcuts, when the camera app has focus. In all other cases system shortcuts are working like before even if camera app is running in background. --- src/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 51c39ea..a7e92a0 100644 --- a/src/main.c +++ b/src/main.c @@ -1395,7 +1395,12 @@ activate(GtkApplication *app, gpointer data) create_simple_action(app, "quit", G_CALLBACK(run_quit_action)); // Setup shortcuts - const char *capture_accels[] = { "space", NULL }; + const char *capture_accels[] = { + "space", + "AudioLowerVolume", + "AudioRaiseVolume", + NULL + }; gtk_application_set_accels_for_action(app, "app.capture", capture_accels); const char *quit_accels[] = { "q", "w", NULL }; @@ -1496,6 +1501,12 @@ activate(GtkApplication *app, gpointer data) gtk_application_add_window(app, GTK_WINDOW(window)); gtk_widget_set_visible(window, true); + + // Inhibit system shortcuts to be able to use + // VolumeUp and VolumeDown hardware buttons to take a picture + GtkNative *native = gtk_widget_get_native (GTK_WIDGET (window)); + GdkSurface *surface = gtk_native_get_surface (native); + gdk_toplevel_inhibit_system_shortcuts (GDK_TOPLEVEL (surface), NULL); } static void