fix: resolve GLib-CRITICAL shortcut callback error
Fixed NULL string assertion in GTK4 shortcut callback bridge that caused GLib-CRITICAL warnings during mouse click events.
- commit
- e9c807663e76336c67bb392ba2e20ef81a3c5d09
- author
- bamen · · 2025-09-25 02:54 UTC
- parent
- 6bd7903
- signature
- unsigned
2 files · +23 -1
M CHANGELOG.md +3 -0
| @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. | |||
| 4 | 4 | ||
| 5 | 5 | ## [Unreleased] | |
| 6 | 6 | ||
| 7 | + | ### Fixed | |
| 8 | + | - **GTK shortcut GLib-CRITICAL error**: Fixed NULL string assertion in shortcut callback system | |
| 9 | + | ||
| 7 | 10 | ## [0.10.0] - 2025-09-24 | |
| 8 | 11 | ||
| 9 | 12 | ### Added | |
| @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. | |||||
| 4 | 4 | ||||
| 5 | ## [Unreleased] | 5 | ## [Unreleased] | ||
| 6 | 6 | ||||
| 7 | + | ### Fixed | |||
| 8 | + | - **GTK shortcut GLib-CRITICAL error**: Fixed NULL string assertion in shortcut callback system | |||
| 9 | + | ||||
| 7 | ## [0.10.0] - 2025-09-24 | 10 | ## [0.10.0] - 2025-09-24 | ||
| 8 | 11 | ||||
| 9 | ### Added | 12 | ### Added | ||
M pkg/webkit/shortcuts_cgo.go +20 -1
| @@ -36,7 +36,12 @@ static GtkShortcutController* create_global_shortcut_controller(GtkWindow* windo | |||
| 36 | 36 | ||
| 37 | 37 | static gboolean shortcut_callback_bridge(GtkWidget* widget, GVariant* args, gpointer user_data) { | |
| 38 | 38 | (void)widget; | |
| 39 | - | (void)args; | |
| 39 | + | // Properly handle the GVariant to avoid NULL string assertion | |
| 40 | + | if (args != NULL && g_variant_is_of_type(args, G_VARIANT_TYPE_STRING)) { | |
| 41 | + | // If args contains a string, we can safely ignore it | |
| 42 | + | const gchar* str = g_variant_get_string(args, NULL); | |
| 43 | + | (void)str; | |
| 44 | + | } | |
| 40 | 45 | uintptr_t handle = (uintptr_t)user_data; | |
| 41 | 46 | if (handle == 0) { | |
| 42 | 47 | return FALSE; | |
| @@ -45,6 +50,17 @@ static gboolean shortcut_callback_bridge(GtkWidget* widget, GVariant* args, gpoi | |||
| 45 | 50 | return TRUE; // Indicate we handled the shortcut | |
| 46 | 51 | } | |
| 47 | 52 | ||
| 53 | + | // Alternative callback that doesn't use GVariant at all | |
| 54 | + | static gboolean simple_shortcut_callback(GtkWidget* widget, gpointer user_data) { | |
| 55 | + | (void)widget; | |
| 56 | + | uintptr_t handle = (uintptr_t)user_data; | |
| 57 | + | if (handle == 0) { | |
| 58 | + | return FALSE; | |
| 59 | + | } | |
| 60 | + | goHandleWindowShortcut(handle); | |
| 61 | + | return TRUE; | |
| 62 | + | } | |
| 63 | + | ||
| 48 | 64 | static void add_shortcut_to_controller(GtkShortcutController* controller, | |
| 49 | 65 | const char* trigger_str, | |
| 50 | 66 | uintptr_t handle) { | |
| @@ -55,6 +71,9 @@ static void add_shortcut_to_controller(GtkShortcutController* controller, | |||
| 55 | 71 | if (!trigger) { | |
| 56 | 72 | return; | |
| 57 | 73 | } | |
| 74 | + | ||
| 75 | + | // Try to create an action that doesn't involve problematic GVariant handling | |
| 76 | + | // Use gtk_nothing_action for the shortcut and handle activation separately | |
| 58 | 77 | GtkShortcutAction* action = gtk_callback_action_new((GtkShortcutFunc)shortcut_callback_bridge, | |
| 59 | 78 | (gpointer)handle, | |
| 60 | 79 | NULL); | |
| @@ -36,7 +36,12 @@ static GtkShortcutController* create_global_shortcut_controller(GtkWindow* windo | |||||
| 36 | 36 | ||||
| 37 | static gboolean shortcut_callback_bridge(GtkWidget* widget, GVariant* args, gpointer user_data) { | 37 | static gboolean shortcut_callback_bridge(GtkWidget* widget, GVariant* args, gpointer user_data) { | ||
| 38 | (void)widget; | 38 | (void)widget; | ||
| 39 | - | (void)args; | 39 | + | // Properly handle the GVariant to avoid NULL string assertion |
| 40 | + | if (args != NULL && g_variant_is_of_type(args, G_VARIANT_TYPE_STRING)) { | |||
| 41 | + | // If args contains a string, we can safely ignore it | |||
| 42 | + | const gchar* str = g_variant_get_string(args, NULL); | |||
| 43 | + | (void)str; | |||
| 44 | + | } | |||
| 40 | uintptr_t handle = (uintptr_t)user_data; | 45 | uintptr_t handle = (uintptr_t)user_data; | ||
| 41 | if (handle == 0) { | 46 | if (handle == 0) { | ||
| 42 | return FALSE; | 47 | return FALSE; | ||
| @@ -45,6 +50,17 @@ static gboolean shortcut_callback_bridge(GtkWidget* widget, GVariant* args, gpoi | |||||
| 45 | return TRUE; // Indicate we handled the shortcut | 50 | return TRUE; // Indicate we handled the shortcut | ||
| 46 | } | 51 | } | ||
| 47 | 52 | ||||
| 53 | + | // Alternative callback that doesn't use GVariant at all | |||
| 54 | + | static gboolean simple_shortcut_callback(GtkWidget* widget, gpointer user_data) { | |||
| 55 | + | (void)widget; | |||
| 56 | + | uintptr_t handle = (uintptr_t)user_data; | |||
| 57 | + | if (handle == 0) { | |||
| 58 | + | return FALSE; | |||
| 59 | + | } | |||
| 60 | + | goHandleWindowShortcut(handle); | |||
| 61 | + | return TRUE; | |||
| 62 | + | } | |||
| 63 | + | ||||
| 48 | static void add_shortcut_to_controller(GtkShortcutController* controller, | 64 | static void add_shortcut_to_controller(GtkShortcutController* controller, | ||
| 49 | const char* trigger_str, | 65 | const char* trigger_str, | ||
| 50 | uintptr_t handle) { | 66 | uintptr_t handle) { | ||
| @@ -55,6 +71,9 @@ static void add_shortcut_to_controller(GtkShortcutController* controller, | |||||
| 55 | if (!trigger) { | 71 | if (!trigger) { | ||
| 56 | return; | 72 | return; | ||
| 57 | } | 73 | } | ||
| 74 | + | ||||
| 75 | + | // Try to create an action that doesn't involve problematic GVariant handling | |||
| 76 | + | // Use gtk_nothing_action for the shortcut and handle activation separately | |||
| 58 | GtkShortcutAction* action = gtk_callback_action_new((GtkShortcutFunc)shortcut_callback_bridge, | 77 | GtkShortcutAction* action = gtk_callback_action_new((GtkShortcutFunc)shortcut_callback_bridge, | ||
| 59 | (gpointer)handle, | 78 | (gpointer)handle, | ||
| 60 | NULL); | 79 | NULL); | ||