[PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

Stanislav Ochotnicky-2
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 <[hidden email]>
Associate Software Engineer - Base Operating Systems Brno

Mobile: +420 775 633 759
Red Hat Inc.                               http://cz.redhat.com


_______________________________________________
Gpa-dev mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gpa-dev

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

Stanislav Ochotnicky-2
On 04/27/2010 04:36 PM, Stanislav Ochotnicky wrote:
> 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.

Now that I think about it...maybe it would be best if we kept trying to
grab keyboard every X ms until we get it? Meanwhile if pinentry is
configured to use global grab and we don't have it yet, display BIG RED
WARNING. pinentry is not long running application so this should not
have that significant impact on performance...what do you think?

--
Stanislav Ochotnicky <[hidden email]>
Associate Software Engineer - Base Operating Systems Brno

Mobile: +420 775 633 759
Red Hat Inc.                               http://cz.redhat.com



_______________________________________________
Gpa-dev mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gpa-dev

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

Ed Martin-3
I already fixed this and submitted it to the list long ago (and i'm not about to search for it), it got lost to the spam and never committed. The problem is X does send an event when the window is visible (instead of just mapped) but gtk does not offer this signal by default, and the keyboard needs to be grabbed when it is visible. Debian's list was not full of spam and has already accepted my patch.

Anyways, a like to a patch that addresses the problem instead of fixing it.

http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=27;bug=401957

Maybe someone can commit it upstream this time.

On Apr 27, 2010, at 11:26 AM, Stanislav Ochotnicky wrote:

> On 04/27/2010 04:36 PM, Stanislav Ochotnicky wrote:
>> 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.
>
> Now that I think about it...maybe it would be best if we kept trying to
> grab keyboard every X ms until we get it? Meanwhile if pinentry is
> configured to use global grab and we don't have it yet, display BIG RED
> WARNING. pinentry is not long running application so this should not
> have that significant impact on performance...what do you think?
>
> --
> Stanislav Ochotnicky <[hidden email]>
> Associate Software Engineer - Base Operating Systems Brno
>
> Mobile: +420 775 633 759
> Red Hat Inc.                               http://cz.redhat.com
>
>
> _______________________________________________
> Gpa-dev mailing list
> [hidden email]
> http://lists.gnupg.org/mailman/listinfo/gpa-dev


_______________________________________________
Gpa-dev mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gpa-dev
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

Stanislav Ochotnicky-2
On 04/27/2010 11:10 PM, Ed Martin wrote:
> I already fixed this and submitted it to the list long ago (and i'm not about to search for it), it got lost to the spam and never committed. The problem is X does send an event when the window is visible (instead of just mapped) but gtk does not offer this signal by default, and the keyboard needs to be grabbed when it is visible. Debian's list was not full of spam and has already accepted my patch.

Well, the list doesn't seem to be full with spam anymore so maybe you'll
be more lucky :-)

> Anyways, a like to a patch that addresses the problem instead of fixing it.
>
> http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=27;bug=401957
>
> Maybe someone can commit it upstream this time.

I have verified that debian patch, it works even for trunk and fixes
problems with *box WMs. So this patch actually addresses the issue
instead of creating workaround.

If you use any patch for this, I suggest you use debian patch and not my
workaround.


--
Stanislav Ochotnicky <[hidden email]>
Associate Software Engineer - Base Operating Systems Brno

Mobile: +420 775 633 759
Red Hat Inc.                               http://cz.redhat.com



_______________________________________________
Gpa-dev mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gpa-dev

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard

Werner Koch
In reply to this post by Ed Martin-3
On Tue, 27 Apr 2010 23:10, [hidden email] said:

> committed. The problem is X does send an event when the window is
> visible (instead of just mapped) but gtk does not offer this signal by
> default, and the keyboard needs to be grabbed when it is

Intersting.  This might also help me with my emacs23 problems on
kfreebsd which are also related to the map notification.

I'll try your patch.


Shalom-Salam,

   Werner

--
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.


_______________________________________________
Gpa-dev mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gpa-dev