client.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #ifndef CLIENT_H
  6. #define CLIENT_H
  7. #include <X11/XKBlib.h>
  8. #include "wmfs.h"
  9. #include "layout.h"
  10. #include "ewmh.h"
  11. #include "util.h"
  12. #define TCLIENT_CHECK(C) (C->flags & CLIENT_TABBED && !(C->flags & CLIENT_TABMASTER))
  13. /* SLIST_FOREACH for client with no free client */
  14. #define FOREACH_NFCLIENT(V, H, F) \
  15. SLIST_FOREACH(V, H, F) \
  16. if(!(V->flags & CLIENT_FREE))
  17. /* Are two clients compatibles ? (to be tabbed together) */
  18. #define COMPCLIENT(C1, C2) ((C1->flags & CLIENT_IGNORE_TAG) == (C2->flags & CLIENT_IGNORE_TAG))
  19. void client_configure(struct client *c);
  20. struct client *client_gb_win(Window w);
  21. struct client *client_gb_frame(Window w);
  22. struct client *client_gb_pos(struct tag *t, int x, int y);
  23. struct client *client_gb_titlebar(Window w);
  24. struct client *client_next_with_pos(struct client *bc, enum position p);
  25. void client_swap2(struct client *c1, struct client *c2);
  26. void client_swap(struct client *c, enum position p);
  27. #define CCOL(c) (c == W->client ? &c->scol : &c->ncol)
  28. void client_frame_update(struct client *c, struct colpair *cp);
  29. void client_tab_pull(struct client *c);
  30. void _client_tab(struct client *c, struct client *cm);
  31. void client_tab_focus(struct client *c);
  32. void client_focus(struct client *c);
  33. void uicb_client_focus_click(Uicb);
  34. void client_get_name(struct client *c);
  35. void client_close(struct client *c);
  36. void uicb_client_close(Uicb cmd);
  37. struct client *client_new(Window w, XWindowAttributes *wa, bool scan);
  38. void client_geo_hints(struct geo *g, int *s);
  39. void client_get_sizeh(struct client *c);
  40. bool client_winsize(struct client *c, struct geo *geo);
  41. void client_moveresize(struct client *c, struct geo *g);
  42. void client_place_at_mouse(struct client *c);
  43. void client_maximize(struct client *c);
  44. void client_fac_resize(struct client *c, enum position p, int fac);
  45. void client_fac_adjust(struct client *c);
  46. void client_remove(struct client *c);
  47. void client_free(void);
  48. void _fac_resize(struct client *c, enum position p, int fac);
  49. void client_apply_tgeo(struct tag *t);
  50. #define CPROP_LOC 0x01
  51. #define CPROP_FLAG 0x02
  52. #define CPROP_GEO 0x04
  53. #define CPROP_TAB 0x08
  54. void client_update_props(struct client *c, Flags f);
  55. void client_fac_hint(struct client *c);
  56. void uicb_client_untab(Uicb cmd);
  57. void uicb_client_toggle_free(Uicb cmd);
  58. void uicb_client_toggle_ignore_tag(Uicb cmd);
  59. void uicb_client_tab_next_opened(Uicb cmd);
  60. /* Generated */
  61. void uicb_client_resize_Right(Uicb);
  62. void uicb_client_resize_Left(Uicb);
  63. void uicb_client_resize_Top(Uicb);
  64. void uicb_client_resize_Bottom(Uicb);
  65. void uicb_client_focus_Right(Uicb);
  66. void uicb_client_focus_Left(Uicb);
  67. void uicb_client_focus_Top(Uicb);
  68. void uicb_client_focus_Bottom(Uicb);
  69. void uicb_client_tab_Right(Uicb);
  70. void uicb_client_tab_Left(Uicb);
  71. void uicb_client_tab_Top(Uicb);
  72. void uicb_client_tab_Bottom(Uicb);
  73. void uicb_client_swap_Right(Uicb);
  74. void uicb_client_swap_Left(Uicb);
  75. void uicb_client_swap_Top(Uicb);
  76. void uicb_client_swap_Bottom(Uicb);
  77. void uicb_client_focus_next(Uicb);
  78. void uicb_client_focus_prev(Uicb);
  79. void uicb_client_swapsel_next(Uicb);
  80. void uicb_client_swapsel_prev(Uicb);
  81. void uicb_client_focus_next_tab(Uicb);
  82. void uicb_client_focus_prev_tab(Uicb);
  83. static inline struct client*
  84. client_next(struct client *c)
  85. {
  86. return (SLIST_NEXT(c, tnext)
  87. ? SLIST_NEXT(c, tnext)
  88. : SLIST_FIRST(&c->tag->clients));
  89. }
  90. static inline struct client*
  91. client_prev(struct client *c)
  92. {
  93. struct client *cc = SLIST_FIRST(&c->tag->clients);
  94. while(SLIST_NEXT(cc, tnext) && SLIST_NEXT(cc, tnext) != c)
  95. cc = SLIST_NEXT(cc, tnext);
  96. return cc;
  97. }
  98. static inline struct client*
  99. client_next_tab(struct client *c)
  100. {
  101. struct client *n = client_next(c);
  102. if(!(c->flags & CLIENT_TABMASTER))
  103. return NULL;
  104. while((!(n->flags & CLIENT_TABBED) || n->tabmaster != c) && n != c)
  105. n = client_next(n);
  106. return n;
  107. }
  108. static inline struct client*
  109. client_prev_tab(struct client *c)
  110. {
  111. struct client *p = client_prev(c);
  112. if(!(c->flags & CLIENT_TABMASTER))
  113. return NULL;
  114. while((!(p->flags & CLIENT_TABBED) || p->tabmaster != c) && p != c)
  115. p = client_prev(p);
  116. return p;
  117. }
  118. static inline struct client*
  119. client_tab_next(struct client *c)
  120. {
  121. return (c && c->tabmaster ? c->tabmaster : c);
  122. }
  123. static inline void
  124. client_map(struct client *c)
  125. {
  126. if(!(c->flags & CLIENT_MAPPED))
  127. {
  128. WIN_STATE(c->frame, Map);
  129. WIN_STATE(c->win, Map);
  130. ewmh_set_wm_state(c->win, NormalState);
  131. c->flags ^= CLIENT_MAPPED;
  132. }
  133. }
  134. static inline void
  135. client_unmap(struct client *c)
  136. {
  137. if(c->flags & CLIENT_MAPPED)
  138. {
  139. WIN_STATE(c->frame, Unmap);
  140. WIN_STATE(c->win, Unmap);
  141. ewmh_set_wm_state(c->win, IconicState);
  142. c->flags ^= CLIENT_MAPPED;
  143. }
  144. }
  145. static inline void
  146. clients_arrange_map(void)
  147. {
  148. struct client *c;
  149. SLIST_FOREACH(c, &W->h.client, next)
  150. {
  151. if(c->tag == c->screen->seltag && !(c->flags & CLIENT_TABBED))
  152. client_map(c);
  153. else
  154. client_unmap(c);
  155. }
  156. }
  157. static inline void
  158. clients_tag_arrange_map(struct tag *t)
  159. {
  160. struct client *c;
  161. void (*sfunc)(struct client*)
  162. = (t == t->screen->seltag ? client_map : client_unmap);
  163. SLIST_FOREACH(c, &t->clients, tnext)
  164. sfunc(c);
  165. }
  166. static inline struct client*
  167. client_get_larger(struct tag *t, bool ignoring_tag)
  168. {
  169. struct client *c, *lc = NULL;
  170. int tmp, l = 0;
  171. FOREACH_NFCLIENT(c, &t->clients, tnext)
  172. {
  173. if((tmp = (c->geo.w + c->geo.h)) > l && (c->flags & CLIENT_IGNORE_TAG) == ignoring_tag)
  174. {
  175. l = tmp;
  176. lc = c;
  177. }
  178. }
  179. if(lc && (lc->flags & CLIENT_TABBED))
  180. lc = lc->tabmaster;
  181. return lc;
  182. }
  183. #endif /* CLIENT_H */