From 33a16ae04270647e99dc0741b706061e6468fa3c Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 13 Oct 2021 02:06:49 +0200 Subject: GTK: prevent crashes when pressing keys very quickly * teco_interface_key_pressed_cb() could be called multiple times __before__ the idle timer (teco_interface_pop_key_idle_cb()) fires. The recursion check would consequently not work and we started the idle timer multiple times. This would eventually crash. * We now process the first queued key immediately. The alternative would be to store the idle watcher id. * The idle watcher's priority has been increased. Since redrawing is guaranteed to take place at G_PRIORITY_HIGH_IDLE, it is sufficient to process keys at G_PRIORITY_DEFAULT_IDLE. * Should also reduce latency slightly. * fixes up 71bf522231d2998f1fb183f343c2b1f9dbcd3b15 --- src/interface-gtk/interface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 20b1e5d..27c043c 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -1187,7 +1187,8 @@ teco_interface_key_pressed_cb(GtkWidget *widget, GdkEventKey *event, gpointer us * a key pressed could result in the UI beeing frozen until the * key is eventually released. */ - g_idle_add_full(G_PRIORITY_LOW, teco_interface_pop_key_idle_cb, NULL, NULL); + if (teco_interface_pop_key_idle_cb(NULL) == G_SOURCE_CONTINUE) + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, teco_interface_pop_key_idle_cb, NULL, NULL); return TRUE; } -- cgit v1.2.3