Honour escape presses in the dialogue boxes.
authormdw <mdw>
Thu, 3 Dec 1998 01:00:19 +0000 (01:00 +0000)
committermdw <mdw>
Thu, 3 Dec 1998 01:00:19 +0000 (01:00 +0000)
xshutdown.c

index f76dc39..d2a1750 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xshutdown.c,v 1.4 1998/12/03 00:39:45 mdw Exp $
+ * $Id: xshutdown.c,v 1.5 1998/12/03 01:00:19 mdw Exp $
  *
  * Pretty GTK interface to waking up an xwait
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xshutdown.c,v $
+ * Revision 1.5  1998/12/03 01:00:19  mdw
+ * Honour escape presses in the dialogue boxes.
+ *
  * Revision 1.4  1998/12/03 00:39:45  mdw
  * Force focus when starting up.
  *
@@ -55,6 +58,7 @@
 
 #include <gtk/gtk.h>
 #include <gdk/gdkprivate.h>
+#include <gdk/gdkkeysyms.h>
 
 #include "mdwfocus.h"
 #include "mdwopt.h"
@@ -70,6 +74,29 @@ static Atom xwait_die;
 
 /*----- Main code ---------------------------------------------------------*/
 
+/* --- @check_escape@ --- *
+ *
+ * Arguments:  @GtkWidget *w@ = widget raising the signal
+ *             @GdkEventKey *ev@ = pointer to event data
+ *             @gpointer *p@ = widget to activate in response
+ *
+ * Returns:    ---
+ *
+ * Use:                Activates a widget when an escape keypress is detected.
+ */
+
+static gboolean check_escape(GtkWidget *w, GdkEventKey *ev, gpointer *p)
+{
+  if (ev->keyval == GDK_Escape) {
+    if (p)
+      gtk_widget_activate(GTK_WIDGET(p));
+    else
+      gtk_object_destroy(GTK_OBJECT(w));
+    return (1);
+  }
+  return (0);
+}
+
 /* --- @cancel@ --- *
  *
  * Just end the main loop.
@@ -210,6 +237,8 @@ int main(int argc, char *argv[])
       gtk_window_set_title(GTK_WINDOW(win), "xshutdown");
       gtk_signal_connect(GTK_OBJECT(win), "destroy",
                       GTK_SIGNAL_FUNC(cancel), 0);
+      gtk_signal_connect(GTK_OBJECT(win), "key_press_event",
+                        GTK_SIGNAL_FUNC(check_escape), 0);
 
       gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
 
@@ -282,6 +311,8 @@ int main(int argc, char *argv[])
 
     /* --- Show the completed window --- */
 
+    gtk_signal_connect(GTK_OBJECT(win), "key_press_event",
+                      GTK_SIGNAL_FUNC(check_escape), 0);
     gtk_widget_realize(win);
     mdwfocus(win);
     gtk_widget_show(win);