xeyes.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. Copyright (c) 1991 X Consortium
  3. Permission is hereby granted, free of charge, to any person obtaining
  4. a copy of this software and associated documentation files (the
  5. "Software"), to deal in the Software without restriction, including
  6. without limitation the rights to use, copy, modify, merge, publish,
  7. distribute, sublicense, and/or sell copies of the Software, and to
  8. permit persons to whom the Software is furnished to do so, subject to
  9. the following conditions:
  10. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  16. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  17. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  18. OTHER DEALINGS IN THE SOFTWARE.
  19. Except as contained in this notice, the name of the X Consortium shall
  20. not be used in advertising or otherwise to promote the sale, use or
  21. other dealings in this Software without prior written authorization
  22. from the X Consortium.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. # include "config.h"
  26. #endif
  27. #include <X11/Intrinsic.h>
  28. #include <X11/StringDefs.h>
  29. #include <X11/Shell.h>
  30. #include "Eyes.h"
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include "eyes.bit"
  34. #include "eyesmask.bit"
  35. /* Exit with message describing command line format */
  36. static void
  37. usage(void)
  38. {
  39. fprintf(stderr,
  40. "usage: xeyes\n"
  41. " [-display [{host}]:[{vs}]]\n"
  42. " [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n"
  43. " [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n"
  44. " [-shape | +shape] [-outline {color}] [-center {color}]\n"
  45. " [-backing {backing-store}] [-distance]\n");
  46. #ifdef XRENDER
  47. fprintf(stderr,
  48. " [-render | +render]\n");
  49. #endif
  50. exit(1);
  51. }
  52. /* Command line options table. Only resources are entered here...there is a
  53. pass over the remaining options after XtParseCommand is let loose. */
  54. static XrmOptionDescRec options[] = {
  55. {"-outline", "*eyes.outline", XrmoptionSepArg, NULL},
  56. {"-center", "*eyes.center", XrmoptionSepArg, NULL},
  57. {"-backing", "*eyes.backingStore", XrmoptionSepArg, NULL},
  58. {"-shape", "*eyes.shapeWindow", XrmoptionNoArg, "TRUE"},
  59. {"+shape", "*eyes.shapeWindow", XrmoptionNoArg, "FALSE"},
  60. #ifdef XRENDER
  61. {"-render", "*eyes.render", XrmoptionNoArg, "TRUE"},
  62. {"+render", "*eyes.render", XrmoptionNoArg, "FALSE"},
  63. #endif
  64. {"-distance", "*eyes.distance", XrmoptionNoArg, "TRUE"},
  65. };
  66. static Atom wm_delete_window;
  67. /*ARGSUSED*/
  68. static void
  69. quit(Widget w, XEvent *event, String *params, Cardinal *num_params)
  70. {
  71. if (event->type == ClientMessage &&
  72. event->xclient.data.l[0] != wm_delete_window) {
  73. XBell(XtDisplay(w), 0);
  74. } else {
  75. XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
  76. exit(0);
  77. }
  78. }
  79. static XtActionsRec actions[] = {
  80. {"quit", quit}
  81. };
  82. int
  83. main(int argc, char **argv)
  84. {
  85. XtAppContext app_context;
  86. Widget toplevel;
  87. Arg arg[2];
  88. Cardinal i;
  89. XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
  90. toplevel = XtAppInitialize(&app_context, "XEyes",
  91. options, XtNumber(options), &argc, argv,
  92. NULL, arg, (Cardinal) 0);
  93. if (argc != 1) usage();
  94. wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
  95. False);
  96. XtAppAddActions(app_context, actions, XtNumber(actions));
  97. XtOverrideTranslations
  98. (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  99. i = 0;
  100. XtSetArg (arg[i], XtNiconPixmap,
  101. XCreateBitmapFromData (XtDisplay(toplevel),
  102. XtScreen(toplevel)->root,
  103. (char *)eyes_bits, eyes_width, eyes_height));
  104. i++;
  105. XtSetArg (arg[i], XtNiconMask,
  106. XCreateBitmapFromData (XtDisplay(toplevel),
  107. XtScreen(toplevel)->root,
  108. (char *)eyesmask_bits,
  109. eyesmask_width, eyesmask_height));
  110. i++;
  111. XtSetValues (toplevel, arg, i);
  112. (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0);
  113. XtRealizeWidget (toplevel);
  114. (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  115. &wm_delete_window, 1);
  116. XtAppMainLoop(app_context);
  117. return 0;
  118. }