From a2e2db06ddf65c3566ec17e4bf2627fa626c380a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 25 Sep 2025 15:37:38 +0200 Subject: [PATCH 1/8] keyboard-events: Check for error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is an initable so lets use it Signed-off-by: Guido Günther Part-of: --- src/keyboard-events.c | 5 ++--- src/keyboard-events.h | 3 +-- src/shell.c | 15 ++++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/keyboard-events.c b/src/keyboard-events.c index 99b1ecff8..f729179ac 100644 --- a/src/keyboard-events.c +++ b/src/keyboard-events.c @@ -315,11 +315,10 @@ phosh_keyboard_events_init (PhoshKeyboardEvents *self) PhoshKeyboardEvents * -phosh_keyboard_events_new (void) +phosh_keyboard_events_new (GError **err) { - g_autoptr (GError) err = NULL; return g_initable_new (PHOSH_TYPE_KEYBOARD_EVENTS, NULL, - &err, + err, NULL); } diff --git a/src/keyboard-events.h b/src/keyboard-events.h index 06b152880..3dd201032 100644 --- a/src/keyboard-events.h +++ b/src/keyboard-events.h @@ -19,5 +19,4 @@ G_DECLARE_FINAL_TYPE (PhoshKeyboardEvents, KEYBOARD_EVENTS, GSimpleActionGroup) -PhoshKeyboardEvents *phosh_keyboard_events_new (void); - +PhoshKeyboardEvents *phosh_keyboard_events_new (GError **err); diff --git a/src/shell.c b/src/shell.c index a40b95f39..2cb66ca8c 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1012,6 +1012,7 @@ phosh_shell_constructed (GObject *object) { PhoshShell *self = PHOSH_SHELL (object); PhoshShellPrivate *priv = phosh_shell_get_instance_private (self); + g_autoptr (GError) err = NULL; guint id; G_OBJECT_CLASS (phosh_shell_parent_class)->constructed (object); @@ -1076,11 +1077,15 @@ phosh_shell_constructed (GObject *object) priv->polkit_auth_agent = phosh_polkit_auth_agent_new (); priv->feedback_manager = phosh_feedback_manager_new (); - priv->keyboard_events = phosh_keyboard_events_new (); - g_signal_connect_swapped (priv->keyboard_events, - "pressed", - G_CALLBACK (on_keyboard_events_pressed), - self); + priv->keyboard_events = phosh_keyboard_events_new (&err); + if (priv->keyboard_events) { + g_signal_connect_swapped (priv->keyboard_events, + "pressed", + G_CALLBACK (on_keyboard_events_pressed), + self); + } else { + g_warning ("Failed to initialize keyboard events: %s", err->message); + } id = g_idle_add ((GSourceFunc) setup_idle_cb, self); g_source_set_name_by_id (id, "[PhoshShell] idle"); -- GitLab From c37f2f5aa91e6c1ead77e3f3021935a9a4ff96a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 08:56:24 +0200 Subject: [PATCH 2/8] keyboard-events: Modernize header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- src/keyboard-events.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/keyboard-events.h b/src/keyboard-events.h index 3dd201032..f2fefc6c3 100644 --- a/src/keyboard-events.h +++ b/src/keyboard-events.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 Evangelos Ribeiro Tzaras + * 2025 Phosh.mobi e.V. * * SPDX-License-Identifier: GPL-3.0-or-later * @@ -8,8 +9,9 @@ #pragma once -#include -#include +#include + +G_BEGIN_DECLS #define PHOSH_TYPE_KEYBOARD_EVENTS (phosh_keyboard_events_get_type ()) @@ -20,3 +22,5 @@ G_DECLARE_FINAL_TYPE (PhoshKeyboardEvents, GSimpleActionGroup) PhoshKeyboardEvents *phosh_keyboard_events_new (GError **err); + +G_END_DECLS -- GitLab From cf2e15c7f2a3373d4470b27fdd2b35163c2067f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:03:00 +0200 Subject: [PATCH 3/8] util: Add helper to construct keybindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This happens in different places of the shell and is repetitive Signed-off-by: Guido Günther Part-of: --- src/util.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/util.h b/src/util.h index 09f52a29f..afd4fe0a1 100644 --- a/src/util.h +++ b/src/util.h @@ -19,6 +19,31 @@ G_IO_ERROR_NOT_FOUND, G_IO_ERROR_CANCELLED, \ __VA_ARGS__) +/** + * PHOSH_UTIL_BUILD_KEYBINDING: + * @actions: (array)(element-type GActionEntry)(inout): The action array to build + * @builder: A `GStrvBuilder` for the action names + * @settings: The settings + * @key: The settings key + * @callback: The callback to invoke when the keybinding is pressed + * + * Helper to construct keybindings easily + * + * Append the actions for the keybindings found in the settings and add the keybindings + * strings to builder. + */ +#define PHOSH_UTIL_BUILD_KEYBINDING(actions, builder, settings, key, callback) \ + G_STMT_START { \ + GStrv _bindings = g_settings_get_strv (settings, key); \ + for (int i = 0; _bindings[i]; i++) { \ + GActionEntry _entry = { .name = _bindings[i], .activate = callback }; \ + g_array_append_val (actions, _entry); \ + g_strv_builder_take (builder, _bindings[i]); \ + } \ + /* Free container but keep individual strings for action_names */ \ + g_free (_bindings); \ + } G_STMT_END + void phosh_cp_widget_destroy (void *widget); GDesktopAppInfo *phosh_get_desktop_app_info_for_app_id (const char *app_id); char *phosh_munge_app_id (const char *app_id); -- GitLab From ade448d32a41f83b24fa130476d6cda9e94ff62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:06:30 +0200 Subject: [PATCH 4/8] top-panel: Use keybindings builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/top-panel.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/top-panel.c b/src/top-panel.c index 8c8ec6ad4..d6f1267fa 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -437,19 +437,20 @@ toggle_message_tray_action (GSimpleAction *action, GVariant *param, gpointer dat static void add_keybindings (PhoshTopPanel *self) { - g_auto (GStrv) keybindings = NULL; + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); g_autoptr (GArray) actions = g_array_new (FALSE, TRUE, sizeof (GActionEntry)); - keybindings = g_settings_get_strv (self->kb_settings, KEYBINDING_KEY_TOGGLE_MESSAGE_TRAY); - for (int i = 0; i < g_strv_length (keybindings); i++) { - GActionEntry entry = { .name = keybindings[i], .activate = toggle_message_tray_action }; - g_array_append_val (actions, entry); - } + PHOSH_UTIL_BUILD_KEYBINDING (actions, + builder, + self->kb_settings, + KEYBINDING_KEY_TOGGLE_MESSAGE_TRAY, + toggle_message_tray_action); + phosh_shell_add_global_keyboard_action_entries (phosh_shell_get_default (), (GActionEntry*) actions->data, actions->len, self); - self->action_names = g_steal_pointer (&keybindings); + self->action_names = g_strv_builder_end (builder); } -- GitLab From 327c3dcd187c37c356edb36e08192ba36dee0419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:06:30 +0200 Subject: [PATCH 5/8] home: Use keybindings builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/home.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/home.c b/src/home.c index a57c8026a..df59629b4 100644 --- a/src/home.c +++ b/src/home.c @@ -397,30 +397,21 @@ add_keybindings (PhoshHome *self) { "Super_R", .activate = toggle_overview_action }, { "Super_L", .activate = toggle_overview_action }, }; - GStrv overview_bindings; - GStrv app_view_bindings; - GPtrArray *action_names = g_ptr_array_new (); + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); g_autoptr (GSettings) settings = g_settings_new (KEYBINDINGS_SCHEMA_ID); g_autoptr (GArray) actions = g_array_new (FALSE, TRUE, sizeof (GActionEntry)); - overview_bindings = g_settings_get_strv (settings, KEYBINDING_KEY_TOGGLE_OVERVIEW); - for (int i = 0; i < g_strv_length (overview_bindings); i++) { - GActionEntry entry = { .name = overview_bindings[i], .activate = toggle_overview_action }; - g_array_append_val (actions, entry); - g_ptr_array_add (action_names, overview_bindings[i]); - } - /* Free GStrv container but keep individual strings for action_names */ - g_free (overview_bindings); - - app_view_bindings = g_settings_get_strv (settings, KEYBINDING_KEY_TOGGLE_APPLICATION_VIEW); - for (int i = 0; i < g_strv_length (app_view_bindings); i++) { - GActionEntry entry = { .name = app_view_bindings[i], .activate = toggle_application_view_action }; - g_array_append_val (actions, entry); - g_ptr_array_add (action_names, app_view_bindings[i]); - } - /* Free GStrv container but keep individual strings for action_names */ - g_free (app_view_bindings); - g_ptr_array_add (action_names, NULL); + PHOSH_UTIL_BUILD_KEYBINDING (actions, + builder, + settings, + KEYBINDING_KEY_TOGGLE_OVERVIEW, + toggle_overview_action); + + PHOSH_UTIL_BUILD_KEYBINDING (actions, + builder, + settings, + KEYBINDING_KEY_TOGGLE_APPLICATION_VIEW, + toggle_application_view_action); phosh_shell_add_global_keyboard_action_entries (phosh_shell_get_default (), (GActionEntry*) actions->data, @@ -432,7 +423,7 @@ add_keybindings (PhoshHome *self) G_N_ELEMENTS (entries), self); - self->action_names = (GStrv) g_ptr_array_free (action_names, FALSE); + self->action_names = g_strv_builder_end (builder); } -- GitLab From cf63a3d7e0f9765622dae8a7362b28fb84b1b727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:16:35 +0200 Subject: [PATCH 6/8] home: Don't forget to add the super key entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to have them in the keybinding names as well so they get removed on dispose. Signed-off-by: Guido Günther Part-of: --- src/home.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/home.c b/src/home.c index df59629b4..e08641008 100644 --- a/src/home.c +++ b/src/home.c @@ -393,7 +393,7 @@ toggle_application_view_action (GSimpleAction *action, GVariant *param, gpointer static void add_keybindings (PhoshHome *self) { - const GActionEntry entries[] = { + const GActionEntry super_entries[] = { { "Super_R", .activate = toggle_overview_action }, { "Super_L", .activate = toggle_overview_action }, }; @@ -419,10 +419,13 @@ add_keybindings (PhoshHome *self) self); phosh_shell_add_global_keyboard_action_entries (phosh_shell_get_default (), - (GActionEntry*)entries, - G_N_ELEMENTS (entries), + (GActionEntry*)super_entries, + G_N_ELEMENTS (super_entries), self); + for (int i = 0; i < G_N_ELEMENTS (super_entries); i++) + g_strv_builder_add (builder, super_entries[i].name); + self->action_names = g_strv_builder_end (builder); } -- GitLab From cc6c3634ab40c20a2503109cbd0c6f05b90ad063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:06:30 +0200 Subject: [PATCH 7/8] run-command-manager: Use keybindings builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/run-command-manager.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/run-command-manager.c b/src/run-command-manager.c index 9604c1e4d..97f2e656d 100644 --- a/src/run-command-manager.c +++ b/src/run-command-manager.c @@ -119,19 +119,20 @@ show_run_command_dialog (GSimpleAction *action, GVariant *param, gpointer data) static void add_keybindings (PhoshRunCommandManager *self) { - g_auto (GStrv) bindings = NULL; + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); g_autoptr (GArray) actions = g_array_new (FALSE, TRUE, sizeof (GActionEntry)); - bindings = g_settings_get_strv (self->settings, KEYBINDING_KEY_RUN_DIALOG); - for (int i = 0; i < g_strv_length (bindings); i++) { - GActionEntry entry = { .name = bindings[i], .activate = show_run_command_dialog }; - g_array_append_val (actions, entry); - } + PHOSH_UTIL_BUILD_KEYBINDING (actions, + builder, + self->settings, + KEYBINDING_KEY_RUN_DIALOG, + show_run_command_dialog); + phosh_shell_add_global_keyboard_action_entries (phosh_shell_get_default (), (GActionEntry *)actions->data, actions->len, self); - self->action_names = g_steal_pointer (&bindings); + self->action_names = g_strv_builder_end (builder); } static void -- GitLab From 2067949710ae1aecd5dfe5d8050fe6db2d8ff85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 28 Sep 2025 09:06:30 +0200 Subject: [PATCH 8/8] screenshot-manager: Use keybindings builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/screenshot-manager.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/screenshot-manager.c b/src/screenshot-manager.c index 2dfb43380..f5b72f007 100644 --- a/src/screenshot-manager.c +++ b/src/screenshot-manager.c @@ -1207,20 +1207,20 @@ take_screenshot (GSimpleAction *action, GVariant *param, gpointer data) static void add_keybindings (PhoshScreenshotManager *self) { - g_auto (GStrv) bindings = NULL; + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); g_autoptr (GArray) actions = g_array_new (FALSE, TRUE, sizeof (GActionEntry)); - bindings = g_settings_get_strv (self->settings, KEYBINDING_KEY_SCREENSHOT); - for (int i = 0; i < g_strv_length (bindings); i++) { - GActionEntry entry = { .name = bindings[i], .activate = take_screenshot }; - g_array_append_val (actions, entry); - } + PHOSH_UTIL_BUILD_KEYBINDING (actions, + builder, + self->settings, + KEYBINDING_KEY_SCREENSHOT, + take_screenshot); phosh_shell_add_global_keyboard_action_entries (phosh_shell_get_default (), (GActionEntry *)actions->data, actions->len, self); - self->action_names = g_steal_pointer (&bindings); + self->action_names = g_strv_builder_end (builder); } -- GitLab