client.h 5.9 KB

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