chiark / gitweb /
Return & escape work in Disobedience login window
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 28 Jun 2008 15:30:14 +0000 (16:30 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 28 Jun 2008 15:30:14 +0000 (16:30 +0100)
disobedience/disobedience.h
disobedience/login.c

index 1f631088e4503a8969bf90c8ccb659255b62adf5..2c9eb0435ddb24b575f2243d41f6d567efa29b34 100644 (file)
@@ -53,6 +53,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdkkeysyms.h>
 
 /* Types ------------------------------------------------------------------- */
 
index b1047d689fd2ea15b5b50a91f8b277349bb6610b..0fa2176e73cfd9ea4bd4689fa4473aab87130f4f 100644 (file)
@@ -29,7 +29,6 @@
  * It you hit Cancel then the window disappears without saving anything.
  *
  * TODO
- * - escape and return should work
  * - cancel/close should be consistent with properties
  */
 
@@ -173,6 +172,24 @@ static void login_cancel(GtkButton attribute((unused)) *button,
   gtk_widget_destroy(login_window);
 }
 
+/** @brief Keypress handler */
+static gboolean login_keypress(GtkWidget attribute((unused)) *widget,
+                               GdkEventKey *event,
+                               gpointer attribute((unused)) user_data) {
+  if(event->state)
+    return FALSE;
+  switch(event->keyval) {
+  case GDK_Return:
+    login_ok(0, 0);
+    return TRUE;
+  case GDK_Escape:
+    login_cancel(0, 0);
+    return TRUE;
+  default:
+    return FALSE;
+  }
+}
+
 /* Buttons that appear at the bottom of the window */
 static struct button buttons[] = {
   {
@@ -241,6 +258,9 @@ void login_box(void) {
   gtk_container_add(GTK_CONTAINER(login_window), frame_widget(vbox, NULL));
   gtk_window_set_transient_for(GTK_WINDOW(login_window),
                                GTK_WINDOW(toplevel));
+  /* Keyboard shortcuts */
+  g_signal_connect(login_window, "key-press-event",
+                   G_CALLBACK(login_keypress), 0);
   gtk_widget_show_all(login_window);
 }