xlogo.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/StringDefs.h>
  25. #include <X11/Shell.h>
  26. #include "xlogo.h"
  27. #include "Logo.h"
  28. #include <X11/Xaw/Cardinals.h>
  29. #ifdef XKB
  30. #include <X11/extensions/XKBbells.h>
  31. #endif
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. /* Global vars*/
  35. const char *ProgramName; /* program name (from argv[0]) */
  36. static void quit(Widget w, XEvent *event, String *params, Cardinal *num_params);
  37. static XrmOptionDescRec options[] = {
  38. { "-shape", "*shapeWindow", XrmoptionNoArg, (XPointer) "on" },
  39. #ifdef XRENDER
  40. {"-render", "*render",XrmoptionNoArg, "TRUE"},
  41. {"-sharp", "*sharp", XrmoptionNoArg, "TRUE"},
  42. #endif
  43. {"-v", "Verbose", XrmoptionNoArg, "TRUE"},
  44. {"-q", "Quiet", XrmoptionNoArg, "TRUE"},
  45. };
  46. static XtActionsRec actions[] = {
  47. {"quit", quit },
  48. };
  49. static Atom wm_delete_window;
  50. /* See xlogo.h */
  51. XLogoResourceData userOptions;
  52. #define Offset(field) XtOffsetOf(XLogoResourceData, field)
  53. static XtResource resources[] = {
  54. {"verbose", "Verbose", XtRBoolean, sizeof(Boolean), Offset(verbose), XtRImmediate, (XtPointer)False},
  55. {"quiet", "Quiet", XtRBoolean, sizeof(Boolean), Offset(quiet), XtRImmediate, (XtPointer)False},
  56. };
  57. static String fallback_resources[] = {
  58. "*iconPixmap: xlogo32",
  59. "*iconMask: xlogo32",
  60. "*baseTranslations: #override \\"
  61. "\t<Key>q: quit()",
  62. NULL,
  63. };
  64. static void
  65. die(Widget w, XtPointer client_data, XtPointer call_data)
  66. {
  67. XtAppSetExitFlag(XtWidgetToApplicationContext(w));
  68. }
  69. static void
  70. save(Widget w, XtPointer client_data, XtPointer call_data)
  71. {
  72. return;
  73. }
  74. /*
  75. * Report the syntax for calling xlogo.
  76. */
  77. static void
  78. Syntax(Widget toplevel)
  79. {
  80. Arg arg;
  81. SmcConn connection;
  82. String reasons[10];
  83. int i, n = 0;
  84. reasons[n++] = "Usage: ";
  85. reasons[n++] = (String)ProgramName;
  86. reasons[n++] = " [-fg <color>] [-bg <color>] [-rv] [-bw <pixels>] [-bd <color>]\n";
  87. reasons[n++] = " [-v] [-q]\n";
  88. reasons[n++] = " [-d [<host>]:[<vs>]]\n";
  89. reasons[n++] = " [-g [<width>][x<height>][<+-><xoff>[<+-><yoff>]]]\n";
  90. #ifdef XRENDER
  91. reasons[n++] = " [-render] [-sharp]\n";
  92. #endif /* XRENDER */
  93. reasons[n++] = " [-shape]\n\n";
  94. XtSetArg(arg, XtNconnection, &connection);
  95. XtGetValues(toplevel, &arg, (Cardinal)1);
  96. if (connection)
  97. SmcCloseConnection(connection, n, reasons);
  98. else {
  99. for (i=0; i < n; i++)
  100. printf("%s", reasons[i]);
  101. }
  102. exit(EXIT_FAILURE);
  103. }
  104. int
  105. main(int argc, char *argv[])
  106. {
  107. Widget toplevel;
  108. XtAppContext app_con;
  109. ProgramName = argv[0];
  110. toplevel = XtOpenApplication(&app_con, "XLogo",
  111. options, XtNumber(options),
  112. &argc, argv, fallback_resources,
  113. sessionShellWidgetClass, NULL, ZERO);
  114. if (argc != 1)
  115. Syntax(toplevel);
  116. XtGetApplicationResources(toplevel, (XtPointer)&userOptions, resources,
  117. XtNumber(resources), NULL, 0);
  118. XtAppAddActions(app_con, actions, XtNumber(actions));
  119. XtAddCallback(toplevel, XtNsaveCallback, save, NULL);
  120. XtAddCallback(toplevel, XtNdieCallback, die, NULL);
  121. XtOverrideTranslations
  122. (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  123. XtCreateManagedWidget("xlogo", logoWidgetClass, toplevel, NULL, ZERO);
  124. XtRealizeWidget(toplevel);
  125. wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
  126. False);
  127. (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  128. &wm_delete_window, 1);
  129. XtAppMainLoop(app_con);
  130. return EXIT_SUCCESS;
  131. }
  132. /*ARGSUSED*/
  133. static void
  134. quit(Widget w, XEvent *event, String *params, Cardinal *num_params)
  135. {
  136. Arg arg;
  137. if (event->type == ClientMessage &&
  138. (Atom)event->xclient.data.l[0] != wm_delete_window) {
  139. #ifdef XKB
  140. XkbStdBell(XtDisplay(w), XtWindow(w), 0, XkbBI_BadValue);
  141. #else
  142. XBell(XtDisplay(w), 0);
  143. #endif
  144. } else {
  145. /* resign from the session */
  146. XtSetArg(arg, XtNjoinSession, False);
  147. XtSetValues(w, &arg, ONE);
  148. die(w, NULL, NULL);
  149. }
  150. }