util.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #ifndef UTIL_H
  6. #define UTIL_H
  7. #include "wmfs.h"
  8. /* Todo FREE_LIST(type, head, function_remove) */
  9. #define FREE_LIST(type, head) \
  10. do { \
  11. struct type *Z; \
  12. while(!SLIST_EMPTY(&head)) { \
  13. Z = SLIST_FIRST(&head); \
  14. SLIST_REMOVE_HEAD(&head, next); \
  15. free(Z); /* function_remove(t)*/ \
  16. } \
  17. } while(/* CONSTCOND */ 0);
  18. /* t is Map or Unmap */
  19. #define WIN_STATE(w, t) do { \
  20. X##t##Subwindows(W->dpy, w); \
  21. X##t##Window(W->dpy, w); \
  22. } while( /* CONSTCOND */ 0);
  23. #define ATOM(a) XInternAtom(W->dpy, (a), False)
  24. #define LEN(x) (sizeof(x) / sizeof(*x))
  25. #define FLAGINT(i) (1 << i)
  26. #define ATOI(s) strtol(s, NULL, 10)
  27. #define ABS(j) (j < 0 ? -j : j)
  28. #define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h)
  29. /*
  30. * "#RRGGBB" -> 0xRRGGBB
  31. */
  32. static inline Color
  33. color_atoh(const char *col)
  34. {
  35. int shift = (col[0] == '#');
  36. return (Color)strtol(col + shift, NULL, 16);
  37. }
  38. static inline void
  39. swap_ptr(void **x, void **y)
  40. {
  41. void *t = *x;
  42. *x = *y;
  43. *y = t;
  44. }
  45. void *xmalloc(size_t nmemb, size_t size);
  46. void *xcalloc(size_t nmemb, size_t size);
  47. int xasprintf(char **strp, const char *fmt, ...);
  48. char *xstrdup(const char *str);
  49. pid_t spawn(const char *format, ...);
  50. void uicb_spawn(Uicb cmd);
  51. #endif /* UTIL_H */