From: mdw Date: Thu, 3 Dec 1998 01:00:19 +0000 (+0000) Subject: Honour escape presses in the dialogue boxes. X-Git-Tag: 1.1.0~6 X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/commitdiff_plain/87dabe6f706aab4cfe1d96ccff80cf73fe397032 Honour escape presses in the dialogue boxes. --- diff --git a/xshutdown.c b/xshutdown.c index f76dc39..d2a1750 100644 --- a/xshutdown.c +++ b/xshutdown.c @@ -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 #include +#include #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);