
sochotnicky at redhat
Apr 27, 2010, 7:36 AM
Post #1 of 5
(1694 views)
Permalink
|
|
[PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard
|
|
First let me note that this patch is probably not ideal, but it solves problems people in some window managers have with pinentry-gtk-2. Feel free to tear it apart, I can modify it if you have better solution. This is basically a workaround. In some cases when pinentry-gtk-2 received map-event but the window was not actually created yet. This has been true especially in *box window managers which caused pinentry-gtk to cancel dialog with error message. This patch adds 50ms timer before actually trying to grab keyboard. Simple tests showed that this is enough to fix grabbing failure and 50ms should be fast enought to prevent sniffing of keyboard input. --- gtk+-2/pinentry-gtk-2.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c index d4be09e..2b06ef5 100644 --- a/gtk+-2/pinentry-gtk-2.c +++ b/gtk+-2/pinentry-gtk-2.c @@ -127,20 +127,25 @@ make_transient (GtkWidget *win, GdkEvent *event, gpointer data) gdk_window_set_transient_for (win->window, root); } +static int grab_keyboard(void *win) +{ + if (gdk_keyboard_grab (((GtkWidget*)win)->window, FALSE, GDK_CURRENT_TIME)) + { + g_critical ("could not grab keyboard"); + grab_failed = 1; + gtk_main_quit (); + } + return FALSE; +} /* Grab the keyboard for maximum security */ static void -grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) +grab_keyboard_timed (GtkWidget *win, GdkEvent *event, gpointer data) { if (! pinentry->grab) return; - if (gdk_keyboard_grab (win->window, FALSE, gdk_event_get_time (event))) - { - g_critical ("could not grab keyboard"); - grab_failed = 1; - gtk_main_quit (); - } + g_timeout_add(50, grab_keyboard, win); } @@ -311,7 +316,7 @@ create_window (int confirm_mode) g_signal_connect (G_OBJECT (win), pinentry->grab ? "map-event" : "focus-in-event", - G_CALLBACK (grab_keyboard), NULL); + G_CALLBACK (grab_keyboard_timed), NULL); g_signal_connect (G_OBJECT (win), pinentry->grab ? "unmap-event" : "focus-out-event", G_CALLBACK (ungrab_keyboard), NULL); -- 1.6.6.1 -- Stanislav Ochotnicky <sochotnicky [at] redhat> Associate Software Engineer - Base Operating Systems Brno Mobile: +420 775 633 759 Red Hat Inc. http://cz.redhat.com
|