From ad840fe91dd4e6929104f86db04d57839eaea503 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 21 Jul 2024 09:33:26 -0400 Subject: [PATCH] GTK4: bypass bug by directly adding signal listener to webview It took me a while to arrive at this solution. Sad that I can't come up with anything better --- rosenrot4_greenfield_minimal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rosenrot4_greenfield_minimal.c b/rosenrot4_greenfield_minimal.c index 27be0f9..a0c74d9 100644 --- a/rosenrot4_greenfield_minimal.c +++ b/rosenrot4_greenfield_minimal.c @@ -80,9 +80,11 @@ static gboolean handle_signal_keypress(GtkWidget* w, static int handle_signal_keypress2(void *self, int keyval, int keycode, GdkModifierType state, void *controller) { - (void) self, (void) keycode, (void) controller; + // (void) self, (void) keycode, (void) controller; - fprintf(stdout, "New keypress!\n"); + // fprintf(stdout, "New keypress!\n"); + printf("New keypress\n"); + if (1) { printf("Keypress state: %d\n", state); printf("Keypress value: %d\n", keyval); @@ -92,6 +94,7 @@ static int handle_signal_keypress2(void *self, int keyval, int keycode, return handle_shortcut(shortcut[i].id); } } + return 0; } @@ -100,6 +103,9 @@ WebKitWebView* create_new_webview() { WebKitWebView* view = g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL); + GtkEventController *event_controller = gtk_event_controller_key_new(); + g_signal_connect(event_controller, "key-pressed", G_CALLBACK(handle_signal_keypress2), NULL); + gtk_widget_add_controller(GTK_WIDGET(view), event_controller); NOTNULL(view); return view; }