You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

space_dapp.c 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* ---------------------------------------------------------------- *\
  2. file : space_dapp.c
  3. author : m. gumz <akira at fluxbox dot org>
  4. copyr : copyright (c) 2006 by m. gumz
  5. license : MIT - license
  6. start : Sun Sep 17 15:41:56 2006
  7. \* ---------------------------------------------------------------- */
  8. /* ---------------------------------------------------------------- *\
  9. about :
  10. simplest way for a dockapp i could come up with. use it to
  11. go further if you want.
  12. if you want to make it look like completly transparent
  13. you need to -DSHAPE and -lXext, otherwise not.
  14. compile with:
  15. gcc -o space_dapp space_dapp.c -DSHAPE \
  16. -I/usr/include/X11/ -lX11 -lXext
  17. \* ---------------------------------------------------------------- */
  18. /* ---------------------------------------------------------------- *\
  19. includes
  20. \* ---------------------------------------------------------------- */
  21. #include <assert.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <poll.h>
  26. #include <X11/Xlib.h>
  27. #include <X11/Xutil.h>
  28. #ifdef SHAPE
  29. #include <X11/extensions/shape.h>
  30. #endif /* SHAPE */
  31. /* ---------------------------------------------------------------- *\
  32. \* ---------------------------------------------------------------- */
  33. char dock_name[] = "space_dapp";
  34. void usage() {
  35. printf("%s [width] [height]\n", dock_name);
  36. }
  37. int main(int argc, char* argv[]) {
  38. int w = -1;
  39. int h = -1;
  40. Display* dpy = NULL;
  41. Window dock_win = None;
  42. Window root_win = None;
  43. int screen = 0;
  44. {
  45. int i;
  46. for (i = 1; i < argc; i++) {
  47. char* arg = argv[i];
  48. if (strcmp(arg, "-h") == 0) {
  49. usage();
  50. return 0;
  51. } else if (w < 0) {
  52. int t = atoi(arg);
  53. if (t <= 0) {
  54. fprintf(stderr, "error, width must be greater than 0.\n");
  55. return EXIT_FAILURE;
  56. }
  57. w = t;
  58. } else if (h < 0) {
  59. int t = atoi(arg);
  60. if (t <= 0) {
  61. fprintf(stderr, "error, height must be greater than 0.\n");
  62. return EXIT_FAILURE;
  63. }
  64. h = t;
  65. }
  66. }
  67. }
  68. if (w == -1) {
  69. w = 1;
  70. }
  71. if (h == -1) {
  72. h = 1;
  73. }
  74. dpy = XOpenDisplay(NULL);
  75. assert(dpy != NULL);
  76. screen = DefaultScreen(dpy);
  77. root_win = RootWindow(dpy, screen);
  78. /* create the window */
  79. {
  80. XSizeHints size_hints;
  81. XWMHints wm_hints;
  82. XClassHint class_hint;
  83. int border_width = 1;
  84. size_hints.x = 0;
  85. size_hints.y = 0;
  86. size_hints.flags = USSize|USPosition;
  87. size_hints.width = w;
  88. size_hints.height = h;
  89. dock_win = XCreateSimpleWindow(dpy, root_win,
  90. size_hints.x, size_hints.y,
  91. size_hints.width, size_hints.height,
  92. border_width,
  93. WhitePixel(dpy, screen),
  94. BlackPixel(dpy, screen));
  95. assert(dock_win != None);
  96. #ifdef SHAPE
  97. {
  98. const int bytes = ((w / 8) + 1) * h;
  99. char* mask = (char*)malloc(bytes);
  100. assert(mask != NULL);
  101. memset(mask, 0x00, bytes);
  102. {
  103. Pixmap pm = XCreateBitmapFromData(dpy, dock_win, mask, w, h);
  104. assert(pm != None);
  105. XShapeCombineMask(dpy, dock_win, ShapeBounding, 0, 0, pm, ShapeSet);
  106. XFreePixmap(dpy, pm);;
  107. }
  108. }
  109. #endif /* SHAPE */
  110. XSetWMNormalHints(dpy, dock_win, &size_hints);
  111. class_hint.res_name = dock_name;
  112. class_hint.res_class = dock_name;
  113. XSetClassHint(dpy, dock_win, &class_hint);
  114. XSelectInput(dpy,
  115. dock_win,
  116. ButtonPressMask|ExposureMask|ButtonReleaseMask|PointerMotionMask|StructureNotifyMask);
  117. wm_hints.initial_state = WithdrawnState;
  118. wm_hints.icon_window = None;
  119. wm_hints.window_group = dock_win;
  120. wm_hints.flags = StateHint | WindowGroupHint;
  121. XSetWMHints(dpy, dock_win, &wm_hints);
  122. XMapWindow(dpy, dock_win);
  123. }
  124. /* eventloop */
  125. {
  126. XEvent event;
  127. for (;;) {
  128. if (XPending(dpy)) {
  129. XNextEvent(dpy, &event);
  130. switch (event.type) {
  131. case DestroyNotify:
  132. break;
  133. }
  134. }
  135. poll(NULL, 0, 25);
  136. }
  137. }
  138. XDestroyWindow(dpy, dock_win);
  139. XCloseDisplay(dpy);
  140. return EXIT_SUCCESS;
  141. }
  142. /* ---------------------------------------------------------------- *\
  143. \* ---------------------------------------------------------------- */