oclock.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. Copyright 1989, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include <X11/Intrinsic.h>
  24. #include <X11/Xatom.h>
  25. #include <X11/StringDefs.h>
  26. #include <X11/Shell.h>
  27. #include <X11/Xmu/Editres.h>
  28. #include "Clock.h"
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #ifdef XKB
  32. #include <X11/extensions/XKBbells.h>
  33. #endif
  34. #include "oclock.bit"
  35. #include "oclmask.bit"
  36. static void die ( Widget w, XtPointer client_data, XtPointer call_data );
  37. static void save ( Widget w, XtPointer client_data, XtPointer call_data );
  38. static void usage ( void );
  39. static void quit ( Widget w, XEvent *event, String *params,
  40. Cardinal *num_params );
  41. static XtActionsRec actions[] = {
  42. {"quit", quit}
  43. };
  44. static Atom wm_delete_window;
  45. static void die(Widget w, XtPointer client_data, XtPointer call_data)
  46. {
  47. XCloseDisplay(XtDisplay(w));
  48. exit(0);
  49. }
  50. static void save(Widget w, XtPointer client_data, XtPointer call_data)
  51. {
  52. return; /* stateless */
  53. }
  54. /* Exit with message describing command line format */
  55. static void usage(void)
  56. {
  57. fprintf(stderr,
  58. "usage: oclock\n"
  59. " [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n"
  60. " [-display [{host}]:[{vs}]]\n"
  61. " [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n"
  62. " [-minute {color}] [-hour {color}] [-jewel {color}]\n"
  63. " [-backing {backing-store}] [-shape] [-noshape] [-transparent]\n");
  64. exit(1);
  65. }
  66. /* Command line options table. Only resources are entered here...there is a
  67. pass over the remaining options after XtParseCommand is let loose. */
  68. static XrmOptionDescRec options[] = {
  69. {"-fg", "*Foreground", XrmoptionSepArg, NULL},
  70. {"-bg", "*Background", XrmoptionSepArg, NULL},
  71. {"-foreground", "*Foreground", XrmoptionSepArg, NULL},
  72. {"-background", "*Background", XrmoptionSepArg, NULL},
  73. {"-minute", "*clock.minute", XrmoptionSepArg, NULL},
  74. {"-hour", "*clock.hour", XrmoptionSepArg, NULL},
  75. {"-jewel", "*clock.jewel", XrmoptionSepArg, NULL},
  76. {"-backing", "*clock.backingStore", XrmoptionSepArg, NULL},
  77. {"-shape", "*clock.shapeWindow", XrmoptionNoArg, "TRUE"},
  78. {"-noshape", "*clock.shapeWindow", XrmoptionNoArg, "FALSE"},
  79. {"-transparent","*clock.transparent", XrmoptionNoArg, "TRUE"},
  80. };
  81. int
  82. main(int argc, char *argv[])
  83. {
  84. XtAppContext xtcontext;
  85. Widget toplevel;
  86. Arg arg[2];
  87. int i;
  88. toplevel = XtOpenApplication(&xtcontext, "Clock",
  89. options, XtNumber(options), &argc, argv, NULL,
  90. sessionShellWidgetClass, NULL, 0);
  91. if (argc != 1) usage();
  92. XtAddCallback(toplevel, XtNsaveCallback, save, NULL);
  93. XtAddCallback(toplevel, XtNdieCallback, die, NULL);
  94. XtAppAddActions
  95. (xtcontext, actions, XtNumber(actions));
  96. XtOverrideTranslations
  97. (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  98. i = 0;
  99. XtSetArg (arg[i], XtNiconPixmap,
  100. XCreateBitmapFromData (XtDisplay(toplevel),
  101. XtScreen(toplevel)->root,
  102. (char *)oclock_bits,
  103. oclock_width, oclock_height));
  104. i++;
  105. XtSetArg (arg[i], XtNiconMask,
  106. XCreateBitmapFromData (XtDisplay(toplevel),
  107. XtScreen(toplevel)->root,
  108. (char *)oclmask_bits,
  109. oclmask_width, oclmask_height));
  110. i++;
  111. XtSetValues (toplevel, arg, i);
  112. (void) XtCreateManagedWidget("clock", clockWidgetClass, toplevel, NULL, 0);
  113. XtRealizeWidget (toplevel);
  114. wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
  115. False);
  116. (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  117. &wm_delete_window, 1);
  118. XtAddEventHandler(toplevel, (EventMask) 0, TRUE,
  119. _XEditResCheckMessages, NULL);
  120. XtAppMainLoop(xtcontext);
  121. exit(0);
  122. }
  123. static void quit(Widget w, XEvent *event, String *params, Cardinal *num_params)
  124. {
  125. Arg arg;
  126. if (event->type == ClientMessage &&
  127. event->xclient.data.l[0] != wm_delete_window) {
  128. #ifdef XKB
  129. XkbStdBell(XtDisplay(w), XtWindow(w), 0, XkbBI_BadValue);
  130. #else
  131. XBell(XtDisplay(w), 0);
  132. #endif
  133. } else {
  134. XtSetArg(arg, XtNjoinSession, False);
  135. XtSetValues(w, &arg, (Cardinal)1);
  136. die(w, NULL, NULL);
  137. }
  138. }