Use mgLib's `msg' box rather than doing things the hard way.
authormdw <mdw>
Fri, 11 Dec 1998 09:51:51 +0000 (09:51 +0000)
committermdw <mdw>
Fri, 11 Dec 1998 09:51:51 +0000 (09:51 +0000)
xshutdown.c

index d2a1750..c669871 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xshutdown.c,v 1.5 1998/12/03 01:00:19 mdw Exp $
+ * $Id: xshutdown.c,v 1.6 1998/12/11 09:51:51 mdw Exp $
  *
  * Pretty GTK interface to waking up an xwait
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xshutdown.c,v $
+ * Revision 1.6  1998/12/11 09:51:51  mdw
+ * Use mgLib's `msg' box rather than doing things the hard way.
+ *
  * Revision 1.5  1998/12/03 01:00:19  mdw
  * Honour escape presses in the dialogue boxes.
  *
 #include <gdk/gdkprivate.h>
 #include <gdk/gdkkeysyms.h>
 
-#include "mdwfocus.h"
-#include "mdwopt.h"
-#include "quis.h"
+#include <mLib/mdwopt.h>
+#include <mLib/quis.h>
+
+#include <mgLib/msg.h>
+
 #include "xwait.h"
 
 /*----- Static variables --------------------------------------------------*/
 
 static char *atom = XWAIT_DIE;
-static char *msg = XWAIT_DIE_MSG;
+static char *xmsg = XWAIT_DIE_MSG;
 
 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.
- */
-
-static void cancel(GtkWidget *w, gpointer *p)
-{
-  gtk_main_quit();
-}
-
-/* --- @ok@ --- *
- *
- * Send the xwait process a message.
- */
-
-static void ok(GtkWidget *w, gpointer *p)
-{
-  XTextProperty prop;
-  XStringListToTextProperty(&msg, 1, &prop);
-  XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
-                  &prop, xwait_die);
-  gtk_main_quit();
-}
-
 /* --- @version@ --- */
 
 static void version(FILE *fp)
@@ -202,7 +160,7 @@ int main(int argc, char *argv[])
        atom = optarg;
        break;
       case 'm':
-       msg = optarg;
+       xmsg = optarg;
        break;
       case 'p':
        prompt = optarg;
@@ -228,99 +186,20 @@ int main(int argc, char *argv[])
 
     if (!XGetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
                          &prop, xwait_die)) {
-      char buf[64];
-      GtkWidget *win = gtk_dialog_new();
-      GtkWidget *w;
-
-      /* --- Make the main window --- */
-
-      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 the label --- */
-
-      sprintf(buf, "no xwait listening for `%s'\n", atom);
-      w = gtk_label_new(buf);
-      gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
-      gtk_misc_set_padding(GTK_MISC(w), 8, 8);
-      gtk_widget_show(w);
-
-      /* --- Make the little button --- */
-
-      w = gtk_button_new_with_label("OK");
-      gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-      GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-      gtk_widget_grab_default(w);
-      gtk_signal_connect(GTK_OBJECT(w), "clicked",
-                        GTK_SIGNAL_FUNC(cancel), 0);
-      gtk_widget_show(w);
-
-      /* --- Make everything work --- */
-
-      gtk_widget_realize(win);
-      mdwfocus(win);
-      gtk_widget_show(win);
-      gtk_main();
+      msg("!:~OK", "no xwait listening for `%s'", atom);
       exit(EXIT_FAILURE);
     }
   }
 
   /* --- Main code --- */
 
-  {
-    GtkWidget *win;
-    GtkWidget *w;
-
-    /* --- Make the main dialogue box --- */
-
-    win = gtk_dialog_new();
-    gtk_window_set_title(GTK_WINDOW(win), title);
-    gtk_signal_connect(GTK_OBJECT(win), "destroy",
-                      GTK_SIGNAL_FUNC(cancel), 0);
-
-    gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
-
-    /* --- Make the prompt label --- */
-
-    w = gtk_label_new(prompt);
-    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
-    gtk_misc_set_padding(GTK_MISC(w), 8, 8);
-    gtk_widget_show(w);
-
-    /* --- Make the OK button --- */
-
-    w = gtk_button_new_with_label("OK");
-    gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-    gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ok), 0);
-    GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-    gtk_widget_show(w);
-    gtk_widget_grab_default(w);
-
-    /* --- And the cancel button --- */
-
-    w = gtk_button_new_with_label("Cancel");
-    gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-    gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(cancel), 0);
-    GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-    gtk_widget_show(w);
-
-    /* --- 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);
+  if (msg("!:OK,~Cancel", "%s", prompt) == 0) {
+    XTextProperty prop;
+    XStringListToTextProperty(&xmsg, 1, &prop);
+    XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
+                    &prop, xwait_die);
   }
 
-  /* --- Let rip --- */
-
-  gtk_main();
   return (0);
 }