/* -*-c-*-
*
- * $Id: xshutdown.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
+ * $Id: xshutdown.c,v 1.5 1998/12/03 01:00:19 mdw Exp $
*
* Pretty GTK interface to waking up an xwait
*
/*----- 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.
+ *
+ * Revision 1.3 1998/11/30 22:36:49 mdw
+ * Tidy up tabbing in help texts very slightly.
+ *
+ * Revision 1.2 1998/11/21 22:30:23 mdw
+ * Support GNU-style long options throughout, and introduce proper help
+ * text to all programs. Update manual pages to match.
+ *
* Revision 1.1 1998/11/16 23:00:49 mdw
* Initial versions.
*
#include <gtk/gtk.h>
#include <gdk/gdkprivate.h>
+#include <gdk/gdkkeysyms.h>
+#include "mdwfocus.h"
#include "mdwopt.h"
+#include "quis.h"
#include "xwait.h"
/*----- Static variables --------------------------------------------------*/
/*----- 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.
gtk_main_quit();
}
+/* --- @version@ --- */
+
+static void version(FILE *fp)
+{
+ fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
+}
+
+/* --- @usage@ --- */
+
+static void usage(FILE *fp)
+{
+ fprintf(fp, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS);
+}
+
/* --- @main@ --- *
*
* Main program.
{
char *prompt = "Are you sure you want to shut down this session?";
char *title = "xshutdown";
+ ego(argv[0]);
gtk_init(&argc, &argv);
/* --- Parse options --- */
for (;;) {
static struct option opt[] = {
+ { "help", 0, 0, 'h' },
+ { "usage", 0, 0, 'u' },
+ { "version", 0, 0, 'v' },
{ "atom", required_argument, 0, 'a' },
{ "msg", required_argument, 0, 'm' },
{ "prompt", required_argument, 0, 'p' },
};
int i;
- i = getopt_long(argc, argv, "a:m:p:t:", opt, 0);
+ i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0);
if (i < 0)
break;
switch (i) {
+ case 'h':
+ version(stdout);
+ fputs("\n", stdout);
+ usage(stdout);
+ fputs(
+"\n"
+"Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
+"\n"
+"Options available are:\n"
+"\n"
+"-h, --help Display this help text\n"
+"-u, --usage Display a short usage summary\n"
+"-v, --version Display the program's version number\n"
+"\n"
+"-a, --atom=ATOM\t Select the atom that `xwait' is waiting for\n"
+"-m, --msg=MSG Select the message to send to `xwait'\n"
+"-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
+"-t, --title=TITLE Select the title string in the confirmation box\n",
+ stdout);
+ exit(0);
+ break;
+ case 'u':
+ usage(stdout);
+ exit(0);
+ break;
+ case 'v':
+ version(stdout);
+ exit(0);
+ break;
+
case 'a':
atom = optarg;
break;
title = optarg;
break;
default:
+ usage(stderr);
exit(EXIT_FAILURE);
}
}
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);
/* --- Make everything work --- */
+ gtk_widget_realize(win);
+ mdwfocus(win);
gtk_widget_show(win);
gtk_main();
exit(EXIT_FAILURE);
/* --- 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);
}