From: Richard Kettlewell Date: Sat, 28 Jun 2008 15:30:14 +0000 (+0100) Subject: Return & escape work in Disobedience login window X-Git-Tag: 4.2~11^2~6 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/453bdfe01bf48694ddce9ef6edf0c7e79d57ac27?ds=sidebyside Return & escape work in Disobedience login window --- diff --git a/disobedience/disobedience.h b/disobedience/disobedience.h index 1f63108..2c9eb04 100644 --- a/disobedience/disobedience.h +++ b/disobedience/disobedience.h @@ -53,6 +53,7 @@ #include #include #include +#include /* Types ------------------------------------------------------------------- */ diff --git a/disobedience/login.c b/disobedience/login.c index b1047d6..0fa2176 100644 --- a/disobedience/login.c +++ b/disobedience/login.c @@ -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); }