infobar.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #ifndef INFOBAR_H
  6. #define INFOBAR_H
  7. #include "wmfs.h"
  8. #include "util.h"
  9. #include "tag.h"
  10. enum { ElemTag = 0, ElemStatus, ElemSystray, ElemLauncher, ElemCustom, ElemLast };
  11. struct infobar *infobar_new(struct screen *s, char *name, struct theme *theme, enum barpos pos, const char *elem);
  12. void infobar_elem_update(struct infobar *i, int type);
  13. void infobar_refresh(struct infobar *i);
  14. void infobar_remove(struct infobar *i);
  15. void infobar_free(struct screen *s);
  16. void infobar_elem_reinit(struct infobar *i);
  17. /* Basic placement of elements */
  18. static inline void
  19. infobar_elem_placement(struct element *e)
  20. {
  21. struct element *p = TAILQ_PREV(e, esub, next);
  22. e->geo.y = 0;
  23. e->geo.h = e->infobar->geo.h;
  24. if(e->align == Left)
  25. e->geo.x = (p ? p->geo.x + p->geo.w : 0);
  26. else
  27. e->geo.x = ((p = TAILQ_NEXT(e, next))
  28. ? p->geo.x - e->geo.w
  29. : e->infobar->geo.w - e->geo.w);
  30. }
  31. /* Bars placement management and usable space management */
  32. static inline bool
  33. infobar_placement(struct infobar *i, enum barpos p)
  34. {
  35. i->pos = p;
  36. i->geo = i->screen->ugeo;
  37. i->geo.h = i->theme->bars_width;
  38. switch(p)
  39. {
  40. case BarTop:
  41. i->screen->ugeo.y += i->geo.h;
  42. i->screen->ugeo.h -= i->geo.h;
  43. break;
  44. case BarBottom:
  45. i->geo.y = (i->screen->ugeo.y + i->screen->ugeo.h) - i->geo.h;
  46. i->screen->ugeo.h -= i->geo.h;
  47. break;
  48. default:
  49. case BarHide:
  50. return false;
  51. }
  52. return true;
  53. }
  54. static inline void
  55. infobar_elem_screen_update(struct screen *s, int type)
  56. {
  57. struct infobar *i;
  58. SLIST_FOREACH(i, &s->infobars, next)
  59. infobar_elem_update(i, type);
  60. }
  61. static inline struct infobar*
  62. infobar_gb_name(const char *name)
  63. {
  64. struct screen *s;
  65. struct infobar *i;
  66. SLIST_FOREACH(s, &W->h.screen, next)
  67. {
  68. SLIST_FOREACH(i, &s->infobars, next)
  69. if(!strcmp(i->name, name))
  70. return i;
  71. }
  72. return SLIST_FIRST(&s->infobars);
  73. }
  74. #endif /* INFOBAR_H */