barwin.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #include "wmfs.h"
  6. #include "barwin.h"
  7. #include "util.h"
  8. /** Create a barwin
  9. * \param parent Parent window of the BarWindow
  10. * \param x X position
  11. * \param y Y position
  12. * \param w barwin Width
  13. * \param h barwin Height
  14. * \param color barwin color
  15. * \param entermask bool for know if the EnterMask mask is needed
  16. * \return The BarWindow pointer
  17. */
  18. struct barwin*
  19. barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask)
  20. {
  21. struct barwin *b = (struct barwin*)xcalloc(1, sizeof(struct barwin));
  22. XSetWindowAttributes at =
  23. {
  24. .override_redirect = True,
  25. .background_pixmap = ParentRelative,
  26. .event_mask = BARWIN_MASK
  27. };
  28. if(entermask)
  29. at.event_mask |= BARWIN_ENTERMASK;
  30. /* Create window */
  31. b->win = XCreateWindow(W->dpy, parent,
  32. x, y, w, h,
  33. 0, W->xdepth,
  34. CopyFromParent,
  35. DefaultVisual(W->dpy, W->xscreen),
  36. BARWIN_WINCW,
  37. &at);
  38. b->dr = XCreatePixmap(W->dpy, parent, w, h, W->xdepth);
  39. /* Property */
  40. b->geo.x = x;
  41. b->geo.y = y;
  42. b->geo.w = w;
  43. b->geo.h = h;
  44. b->bg = bg;
  45. b->fg = fg;
  46. SLIST_INIT(&b->mousebinds);
  47. /* Attach */
  48. SLIST_INSERT_HEAD(&W->h.barwin, b, next);
  49. return b;
  50. }
  51. /** Delete a barwin
  52. * \param bw barwin pointer
  53. */
  54. void
  55. barwin_remove(struct barwin *b)
  56. {
  57. SLIST_REMOVE(&W->h.barwin, b, barwin, next);
  58. XSelectInput(W->dpy, b->win, NoEventMask);
  59. XDestroyWindow(W->dpy, b->win);
  60. XFreePixmap(W->dpy, b->dr);
  61. /* Free mousebinds */
  62. FREE_LIST(mousebind, b->mousebinds);
  63. free(b);
  64. }
  65. /** Resize a barwin
  66. * \param bw barwin pointer
  67. * \param w Width
  68. * \param h Height
  69. */
  70. void
  71. barwin_resize(struct barwin *b, int w, int h)
  72. {
  73. /* Frame */
  74. XFreePixmap(W->dpy, b->dr);
  75. b->dr = XCreatePixmap(W->dpy, W->root, w, h, W->xdepth);
  76. b->geo.w = w;
  77. b->geo.h = h;
  78. XResizeWindow(W->dpy, b->win, w, h);
  79. }
  80. void
  81. barwin_mousebind_new(struct barwin *b, unsigned int button, bool u, struct geo a, void (*func)(Uicb), Uicb cmd)
  82. {
  83. struct mousebind *m = (struct mousebind*)xcalloc(1, sizeof(struct mousebind));
  84. m->button = button;
  85. m->use_area = u;
  86. m->area = a;
  87. m->func = func;
  88. m->cmd = (cmd ? xstrdup(cmd) : NULL);
  89. SLIST_INSERT_HEAD(&b->mousebinds, m, next);
  90. }
  91. /** Refresh the barwin Color
  92. * \param bw barwin pointer
  93. */
  94. void
  95. barwin_refresh_color(struct barwin *b)
  96. {
  97. XSetForeground(W->dpy, W->gc, b->bg);
  98. XFillRectangle(W->dpy, b->dr, W->gc, 0, 0, b->geo.w, b->geo.h);
  99. }