]> andersk Git - openssh.git/commitdiff
- (djm) Tweak gnome-ssh-askpass2:
authordjm <djm>
Mon, 24 Feb 2003 00:48:22 +0000 (00:48 +0000)
committerdjm <djm>
Mon, 24 Feb 2003 00:48:22 +0000 (00:48 +0000)
   - Retry kb and mouse grab a couple of times, so passphrase dialog doesn't
     immediately fail if you are doing something else when it appears (e.g.
     dragging a window)
   - Perform server grab after we have the keyboard and/or pointer to avoid
     races.

ChangeLog
contrib/gnome-ssh-askpass2.c

index d8d0a050a2113c573008f1a62b7bf88a5bde5f7d..0fba6cef0ad7099c4b76baa6875585809ef4df08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+20030224
+ - (djm) Tweak gnome-ssh-askpass2:
+   - Retry kb and mouse grab a couple of times, so passphrase dialog doesn't 
+     immediately fail if you are doing something else when it appears (e.g. 
+     dragging a window)
+   - Perform server grab after we have the keyboard and/or pointer to avoid 
+     races.
+
 20030211
  - (djm) Cygwin needs libcrypt too. Patch from vinschen@redhat.com
 
index 89a412aa8137416c79fd2175fa0763a1c170988e..9e8eaf920144f5bce4854f46f9e0568e29008dd1 100644 (file)
  * you don't trust your X server. We grab the keyboard always.
  */
 
+#define GRAB_TRIES     16
+#define GRAB_WAIT      250 /* milliseconds */
+
 /*
  * Compile with:
  *
- * cc `pkg-config --cflags gtk+-2.0` \
+ * cc -Wall `pkg-config --cflags gtk+-2.0` \
  *    gnome-ssh-askpass2.c -o gnome-ssh-askpass \
  *    `pkg-config --libs gtk+-2.0`
  *
@@ -48,6 +51,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <X11/Xlib.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
@@ -84,13 +88,13 @@ passphrase_dialog(char *message)
 {
        const char *failed;
        char *passphrase, *local;
-       char **messages;
-       int result, i, grab_server, grab_pointer;
-       GtkWidget *dialog, *entry, *label;
+       int result, grab_tries, grab_server, grab_pointer;
+       GtkWidget *dialog, *entry;
        GdkGrabStatus status;
 
        grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL);
        grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL);
+       grab_tries = 0;
 
        dialog = gtk_message_dialog_new(NULL, 0,
                                        GTK_MESSAGE_QUESTION,
@@ -117,23 +121,35 @@ passphrase_dialog(char *message)
 
        /* Grab focus */
        gtk_widget_show_now(dialog);
-       if (grab_server) {
-               gdk_x11_grab_server();
-       }
        if (grab_pointer) {
-               status =  gdk_pointer_grab((GTK_WIDGET(dialog))->window, TRUE,
-                                          0, NULL, NULL, GDK_CURRENT_TIME);
-               if (status != GDK_GRAB_SUCCESS) {
-                       failed = "mouse";
-                       goto nograb;
+               for(;;) {
+                       status = gdk_pointer_grab(
+                          (GTK_WIDGET(dialog))->window, TRUE, 0, NULL, 
+                          NULL, GDK_CURRENT_TIME);
+                       if (status == GDK_GRAB_SUCCESS)
+                               break;
+                       usleep(GRAB_WAIT * 1000);
+                       if (++grab_tries > GRAB_TRIES) {
+                               failed = "mouse";
+                               goto nograb;
+                       }
                }
        }
-       status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window, FALSE,
-                                  GDK_CURRENT_TIME);
-       if (status != GDK_GRAB_SUCCESS) {
-               failed = "keyboard";
-               goto nograbkb;
+       for(;;) {
+               status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window,
+                  FALSE, GDK_CURRENT_TIME);
+               if (status == GDK_GRAB_SUCCESS)
+                       break;
+               usleep(GRAB_WAIT * 1000);
+               if (++grab_tries > GRAB_TRIES) {
+                       failed = "keyboard";
+                       goto nograbkb;
+               }
        }
+       if (grab_server) {
+               gdk_x11_grab_server();
+       }
+
        result = gtk_dialog_run(GTK_DIALOG(dialog));
 
        /* Ungrab */
This page took 0.04722 seconds and 5 git commands to generate.