barwin.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. SLIST_INIT(&b->statusmousebinds);
  48. /* Attach */
  49. SLIST_INSERT_HEAD(&W->h.barwin, b, next);
  50. return b;
  51. }
  52. /** Delete a barwin
  53. * \param bw barwin pointer
  54. */
  55. void
  56. barwin_remove(struct barwin *b)
  57. {
  58. SLIST_REMOVE(&W->h.barwin, b, barwin, next);
  59. XSelectInput(W->dpy, b->win, NoEventMask);
  60. XDestroyWindow(W->dpy, b->win);
  61. XFreePixmap(W->dpy, b->dr);
  62. free(b);
  63. }
  64. /** Resize a barwin
  65. * \param bw barwin pointer
  66. * \param w Width
  67. * \param h Height
  68. */
  69. void
  70. barwin_resize(struct barwin *b, int w, int h)
  71. {
  72. /* Frame */
  73. XFreePixmap(W->dpy, b->dr);
  74. b->dr = XCreatePixmap(W->dpy, W->root, w, h, W->xdepth);
  75. b->geo.w = w;
  76. b->geo.h = h;
  77. XResizeWindow(W->dpy, b->win, w, h);
  78. }
  79. /** Refresh the barwin Color
  80. * \param bw barwin pointer
  81. */
  82. void
  83. barwin_refresh_color(struct barwin *b)
  84. {
  85. XSetForeground(W->dpy, W->gc, b->bg);
  86. XFillRectangle(W->dpy, b->dr, W->gc, 0, 0, b->geo.w, b->geo.h);
  87. }