Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: gpa

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

 

 

GnuPG gpa RSS feed   Index | Next | Previous | View Threaded


sochotnicky at redhat

Apr 27, 2010, 7:36 AM

Post #1 of 5 (2634 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


sochotnicky at redhat

Apr 27, 2010, 8:26 AM

Post #2 of 5 (2516 views)
Permalink
Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard [In reply to]

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 <sochotnicky [at] redhat>
Associate Software Engineer - Base Operating Systems Brno

Mobile: +420 775 633 759
Red Hat Inc. http://cz.redhat.com
Attachments: signature.asc (0.19 KB)


lists at edman007

Apr 27, 2010, 2:10 PM

Post #3 of 5 (2516 views)
Permalink
Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard [In reply to]

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 <sochotnicky [at] redhat>
> Associate Software Engineer - Base Operating Systems Brno
>
> Mobile: +420 775 633 759
> Red Hat Inc. http://cz.redhat.com
>
>
> _______________________________________________
> Gpa-dev mailing list
> Gpa-dev [at] gnupg
> http://lists.gnupg.org/mailman/listinfo/gpa-dev


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


sochotnicky at redhat

Apr 28, 2010, 12:55 AM

Post #4 of 5 (2529 views)
Permalink
Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard [In reply to]

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 <sochotnicky [at] redhat>
Associate Software Engineer - Base Operating Systems Brno

Mobile: +420 775 633 759
Red Hat Inc. http://cz.redhat.com
Attachments: signature.asc (0.19 KB)


wk at gnupg

May 3, 2010, 6:59 AM

Post #5 of 5 (2522 views)
Permalink
Re: [PATCH] pinentry-gtk-2: Fix ERROR: could not grab keyboard [In reply to]

On Tue, 27 Apr 2010 23:10, lists [at] edman007 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
Gpa-dev [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gpa-dev

GnuPG gpa RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.