client.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #include <X11/Xutil.h>
  6. #include "client.h"
  7. #include "config.h"
  8. #include "event.h"
  9. #include "barwin.h"
  10. #include "draw.h"
  11. #include "screen.h"
  12. #include "mouse.h"
  13. #define CLIENT_RESIZE_DIR(D) \
  14. void uicb_client_resize_##D(Uicb cmd) \
  15. { \
  16. if(W->client) \
  17. client_fac_resize(W->client, D, ATOI(cmd)); \
  18. }
  19. #define CLIENT_ACTION_DIR(A, D) \
  20. void uicb_client_##A##_##D(Uicb cmd) \
  21. { \
  22. (void)cmd; \
  23. struct client *c; \
  24. if(W->client && (c = client_next_with_pos(W->client, D))) \
  25. client_##A(c); \
  26. }
  27. #define CLIENT_ACTION_IDIR(A, D) \
  28. void uicb_client_##A##_##D(Uicb cmd) \
  29. { \
  30. (void)cmd; \
  31. if(W->client) \
  32. client_##A(W->client, D); \
  33. }
  34. #define CLIENT_ACTION_LIST(A, L) \
  35. void uicb_client_##A##_##L(Uicb cmd) \
  36. { \
  37. (void)cmd; \
  38. struct client *c; \
  39. if(W->client && (c = client_##L(W->client))) \
  40. client_##A(c); \
  41. }
  42. /* uicb_client_resize_dir() */
  43. CLIENT_RESIZE_DIR(Right)
  44. CLIENT_RESIZE_DIR(Left)
  45. CLIENT_RESIZE_DIR(Top)
  46. CLIENT_RESIZE_DIR(Bottom)
  47. /* uicb_client_focus_dir() */
  48. CLIENT_ACTION_DIR(focus, Right)
  49. CLIENT_ACTION_DIR(focus, Left)
  50. CLIENT_ACTION_DIR(focus, Top)
  51. CLIENT_ACTION_DIR(focus, Bottom)
  52. /* uicb_client_tab_dir() */
  53. #define client_tab(c) _client_tab(W->client, c)
  54. CLIENT_ACTION_DIR(tab, Right)
  55. CLIENT_ACTION_DIR(tab, Left)
  56. CLIENT_ACTION_DIR(tab, Top)
  57. CLIENT_ACTION_DIR(tab, Bottom)
  58. /* uicb_client_swap_dir() */
  59. CLIENT_ACTION_IDIR(swap, Right)
  60. CLIENT_ACTION_IDIR(swap, Left)
  61. CLIENT_ACTION_IDIR(swap, Top)
  62. CLIENT_ACTION_IDIR(swap, Bottom)
  63. /* uicb_client_focus_next/prev() */
  64. CLIENT_ACTION_LIST(focus, next)
  65. CLIENT_ACTION_LIST(focus, prev)
  66. /* uicb_client_swapsel_next/prev() */
  67. #define client_swapsel(c) client_swap2(W->client, c)
  68. CLIENT_ACTION_LIST(swapsel, next)
  69. CLIENT_ACTION_LIST(swapsel, prev)
  70. /* uicb_client_focus_next/prev_tab() */
  71. CLIENT_ACTION_LIST(focus, next_tab)
  72. CLIENT_ACTION_LIST(focus, prev_tab)
  73. /** Send a ConfigureRequest event to the struct client
  74. * \param c struct client pointer
  75. */
  76. void
  77. client_configure(struct client *c)
  78. {
  79. XConfigureEvent ev =
  80. {
  81. .type = ConfigureNotify,
  82. .event = c->win,
  83. .window = c->win,
  84. .x = c->rgeo.x + c->border,
  85. .y = c->rgeo.y + c->tbarw,
  86. .width = c->wgeo.w,
  87. .height = c->wgeo.h,
  88. .above = None,
  89. .border_width = 0,
  90. .override_redirect = 0
  91. };
  92. XSendEvent(W->dpy, c->win, false, StructureNotifyMask, (XEvent *)&ev);
  93. XSync(W->dpy, false);
  94. }
  95. struct client*
  96. client_gb_win(Window w)
  97. {
  98. struct client *c = SLIST_FIRST(&W->h.client);
  99. while(c && c->win != w)
  100. c = SLIST_NEXT(c, next);
  101. return c;
  102. }
  103. struct client*
  104. client_gb_frame(Window w)
  105. {
  106. struct client *c = SLIST_FIRST(&W->h.client);
  107. while(c && c->frame != w)
  108. c = SLIST_NEXT(c, next);
  109. return c;
  110. }
  111. struct client*
  112. client_gb_pos(struct tag *t, int x, int y)
  113. {
  114. struct client *c;
  115. FOREACH_NFCLIENT(c, &t->clients, tnext)
  116. if(INAREA(x, y, c->geo))
  117. return c;
  118. return NULL;
  119. }
  120. struct client*
  121. client_gb_titlebar(Window w)
  122. {
  123. struct client *c = SLIST_FIRST(&W->h.client);
  124. while(c && c->titlebar && c->titlebar->win != w)
  125. c = SLIST_NEXT(c, next);
  126. return c;
  127. }
  128. /*
  129. * Get client left/right/top/bottom of selected client
  130. */
  131. struct client*
  132. client_next_with_pos(struct client *bc, enum position p)
  133. {
  134. struct client *c;
  135. static const char scanfac[PositionLast] = { +10, -10, 0, 0 };
  136. enum position ip = Bottom - p;
  137. int x = bc->geo.x + ((p == Right) ? bc->geo.w : 0);
  138. int y = bc->geo.y + ((p == Bottom) ? bc->geo.h : 0);
  139. if(p > Left)
  140. x += bc->geo.w >> 1;
  141. if(LDIR(p))
  142. y += bc->geo.h >> 1;
  143. /* Scan in right direction to next(p) physical client */
  144. while((c = client_gb_pos(bc->tag, x, y)) == bc)
  145. {
  146. x += scanfac[p];
  147. y += scanfac[ip];
  148. }
  149. return c;
  150. }
  151. #define FLAG_SWAP2(f1, f2, m1) \
  152. if((f1 & m1) != (f2 & m1)) \
  153. { \
  154. f1 ^= m1; \
  155. f2 ^= m1; \
  156. }
  157. #define SWAP_ARRANGE_TAB(C) \
  158. SLIST_FOREACH(c, &C->tag->clients, tnext) \
  159. { \
  160. if(c->tabmaster == C) \
  161. { \
  162. c->screen = C->screen; \
  163. if((C->flags & CLIENT_FREE) != (c->flags & CLIENT_FREE)) \
  164. { \
  165. c->flags ^= CLIENT_FREE; \
  166. c->flags ^= CLIENT_TILED; \
  167. } \
  168. } \
  169. }
  170. void
  171. client_swap2(struct client *c1, struct client *c2)
  172. {
  173. struct client *c;
  174. struct tag *t;
  175. struct geo g;
  176. /* Conflict / errors */
  177. if(c1 == c2 || !c1 || !c2)
  178. return;
  179. /* Reverse FREE/TILED flags if there are different */
  180. FLAG_SWAP2(c1->flags, c2->flags, CLIENT_FREE);
  181. FLAG_SWAP2(c1->flags, c2->flags, CLIENT_TILED);
  182. if(c1->screen != c2->screen)
  183. swap_ptr((void**)&c1->screen, (void**)&c2->screen);
  184. /*
  185. * Arrange flags for all tabbed client of
  186. * possible c1/c2 tabmaster
  187. */
  188. if(c1->flags & CLIENT_TABMASTER)
  189. SWAP_ARRANGE_TAB(c1);
  190. if(c2->flags & CLIENT_TABMASTER)
  191. SWAP_ARRANGE_TAB(c2);
  192. if(c1->tag != c2->tag)
  193. {
  194. c1->flags |= CLIENT_IGNORE_LAYOUT;
  195. c2->flags |= CLIENT_IGNORE_LAYOUT;
  196. t = c1->tag;
  197. tag_client(c2->tag, c1);
  198. tag_client(t, c2);
  199. }
  200. g = c1->geo;
  201. client_moveresize(c1, &c2->geo);
  202. client_moveresize(c2, &g);
  203. c1->flags |= CLIENT_IGNORE_ENTER;
  204. c2->flags |= CLIENT_IGNORE_ENTER;
  205. }
  206. static inline struct client*
  207. _swap_get(struct client *c, enum position p)
  208. {
  209. struct client *ret = client_next_with_pos(c, p);
  210. if(!ret)
  211. return c;
  212. return ret;
  213. }
  214. #define _REV_SBORDER() \
  215. draw_reversed_rect(W->root, c2, false);
  216. void
  217. client_swap(struct client *c, enum position p)
  218. {
  219. struct keybind *k;
  220. struct client *c2;
  221. bool b = true;
  222. XEvent ev;
  223. KeySym keysym;
  224. c2 = _swap_get(c, p);
  225. /* TODO
  226. if(option_simple_manual_resize)
  227. {
  228. _swap(c, c2);
  229. return;
  230. }
  231. */
  232. XGrabKeyboard(W->dpy, W->root, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  233. _REV_SBORDER();
  234. do
  235. {
  236. XMaskEvent(W->dpy, KeyPressMask, &ev);
  237. if(ev.type == KeyPress)
  238. {
  239. XKeyPressedEvent *ke = &ev.xkey;
  240. keysym = XKeycodeToKeysym(W->dpy, (KeyCode)ke->keycode, 0);
  241. _REV_SBORDER();
  242. SLIST_FOREACH(k, &W->h.keybind, next)
  243. if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ke->state)
  244. && k->func)
  245. {
  246. if(k->func == uicb_client_swap_Right)
  247. c2 = _swap_get(c2, Right);
  248. else if(k->func == uicb_client_swap_Left)
  249. c2 = _swap_get(c2, Left);
  250. else if(k->func == uicb_client_swap_Top)
  251. c2 = _swap_get(c2, Top);
  252. else if(k->func == uicb_client_swap_Bottom)
  253. c2 = _swap_get(c2, Bottom);
  254. else
  255. {
  256. k->func(k->cmd);
  257. keysym = XK_Escape;
  258. }
  259. }
  260. _REV_SBORDER();
  261. /* Gtfo of this loop */
  262. if(keysym == XK_Return)
  263. break;
  264. else if(keysym == XK_Escape)
  265. {
  266. b = false;
  267. break;
  268. }
  269. XSync(W->dpy, False);
  270. }
  271. XNextEvent(W->dpy, &ev);
  272. } while(ev.type != KeyPress);
  273. _REV_SBORDER();
  274. if(b)
  275. client_swap2(c, c2);
  276. XUngrabKeyboard(W->dpy, CurrentTime);
  277. }
  278. static void
  279. client_grabbuttons(struct client *c, bool focused)
  280. {
  281. XUngrabButton(W->dpy, AnyButton, AnyModifier, c->win);
  282. if(focused)
  283. {
  284. int i = 0;
  285. while(i++ != Button5)
  286. {
  287. XGrabButton(W->dpy, i, W->client_mod, c->win, False,
  288. ButtonMask, GrabModeAsync, GrabModeSync, None, None);
  289. XGrabButton(W->dpy, i, W->client_mod | LockMask, c->win, False,
  290. ButtonMask, GrabModeAsync, GrabModeSync, None, None);
  291. XGrabButton(W->dpy, i, W->client_mod | W->numlockmask, c->win, False,
  292. ButtonMask, GrabModeAsync, GrabModeSync, None, None);
  293. XGrabButton(W->dpy, i, W->client_mod | LockMask | W->numlockmask, c->win, False,
  294. ButtonMask, GrabModeAsync, GrabModeSync, None, None);
  295. }
  296. return;
  297. }
  298. XGrabButton(W->dpy, AnyButton, AnyModifier, c->win, False,
  299. ButtonMask, GrabModeAsync, GrabModeSync, None, None);
  300. }
  301. #define _XTEXT() \
  302. if((xt = ((f >> 1) - (w >> 1))) < 0) \
  303. xt = c->border << 1;
  304. #define _REMAINDER() \
  305. if((rm = ((x + f) - (c->rgeo.w - c->border))) > 0) \
  306. f -= rm;
  307. #define _STATUSLINE(C, b) \
  308. sctx = (b ? &c->theme->client_s_sl : &c->theme->client_n_sl); \
  309. sctx->barwin = C->titlebar; \
  310. status_copy_mousebind(sctx); \
  311. status_render(sctx);
  312. void
  313. client_frame_update(struct client *c, struct colpair *cp)
  314. {
  315. struct client *cc;
  316. struct status_ctx *sctx;
  317. int y, f, xt, rm, w, n = 1;
  318. if(c->flags & CLIENT_TABBED)
  319. c = c->tabmaster;
  320. XSetWindowBackground(W->dpy, c->frame, cp->bg);
  321. XClearWindow(W->dpy, c->frame);
  322. if(!c->titlebar || !c->title)
  323. return;
  324. c->titlebar->fg = cp->fg;
  325. c->titlebar->bg = cp->bg;
  326. /* Get number of tabbed client if c is tabmaster */
  327. if(c->flags & CLIENT_TABMASTER)
  328. {
  329. SLIST_FOREACH(cc, &c->tag->clients, tnext)
  330. if(c == cc->tabmaster)
  331. ++n;
  332. }
  333. f = (c->rgeo.w / n) + (c->border * 1.5);
  334. y = TEXTY(c->theme, c->tbarw);
  335. if(n == 1)
  336. {
  337. w = draw_textw(c->theme, c->title);
  338. _XTEXT();
  339. barwin_reparent(c->titlebar, c->frame);
  340. barwin_move(c->titlebar, 0, 0);
  341. barwin_resize(c->titlebar, f, c->tbarw);
  342. barwin_refresh_color(c->titlebar);
  343. _STATUSLINE(c, (cp == &c->scol));
  344. draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title);
  345. barwin_refresh(c->titlebar);
  346. }
  347. /* Tabbing case, multiple titlebar in frame */
  348. else
  349. {
  350. struct geo g = { f - 1, 0, 1, c->titlebar->geo.h };
  351. int x = c->border;
  352. char *title;
  353. SLIST_FOREACH(cc, &c->tag->clients, tnext)
  354. {
  355. title = (cc->title ? cc->title : "WMFS");
  356. w = draw_textw(c->theme, title);
  357. _XTEXT();
  358. if(cc == c)
  359. {
  360. barwin_reparent(c->titlebar, c->frame);
  361. barwin_move(c->titlebar, x, 0);
  362. _REMAINDER();
  363. barwin_resize(c->titlebar, f, c->tbarw);
  364. barwin_refresh_color(c->titlebar);
  365. _STATUSLINE(c, true);
  366. draw_rect(c->titlebar->dr, &g, c->scol.bg);
  367. draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, title);
  368. barwin_refresh(c->titlebar);
  369. x += f;
  370. }
  371. if(cc->tabmaster == c)
  372. {
  373. barwin_reparent(cc->titlebar, c->frame);
  374. barwin_map(cc->titlebar);
  375. barwin_move(cc->titlebar, x, 1);
  376. _REMAINDER();
  377. barwin_resize(cc->titlebar, f, c->tbarw - 2);
  378. barwin_refresh_color(cc->titlebar);
  379. _STATUSLINE(cc, false);
  380. draw_rect(cc->titlebar->dr, &g, c->scol.bg);
  381. draw_text(cc->titlebar->dr, c->theme, xt, y - 1, c->ncol.fg, title);
  382. barwin_refresh(cc->titlebar);
  383. x += f;
  384. }
  385. }
  386. }
  387. }
  388. void
  389. client_tab_focus(struct client *c)
  390. {
  391. if(c->flags & CLIENT_TABBED && c->tabmaster)
  392. {
  393. struct client *cc;
  394. struct geo g = c->tabmaster->geo;
  395. c->flags |= CLIENT_TABMASTER;
  396. c->flags &= ~CLIENT_TABBED;
  397. client_moveresize(c, &c->tabmaster->geo);
  398. if(c->tag == c->screen->seltag)
  399. client_map(c);
  400. c->tabmaster->flags &= ~CLIENT_TABMASTER;
  401. c->tabmaster->flags |= CLIENT_TABBED;
  402. client_unmap(c->tabmaster);
  403. if(!(c->flags & CLIENT_DYING))
  404. {
  405. g.x += W->xmaxw;
  406. g.y += W->xmaxh;
  407. c->tabmaster->geo = c->tabmaster->tgeo = g;
  408. }
  409. /* Update tabmaster of tabbed client */
  410. SLIST_FOREACH(cc, &c->tag->clients, tnext)
  411. if(cc != c && cc->tabmaster == c->tabmaster)
  412. {
  413. cc->tabmaster = c;
  414. client_update_props(cc, CPROP_TAB);
  415. }
  416. c->tabmaster->tabmaster = c;
  417. client_update_props(c->tabmaster, CPROP_TAB);
  418. c->tabmaster = NULL;
  419. client_update_props(c, CPROP_TAB);
  420. }
  421. }
  422. void
  423. _client_tab(struct client *c, struct client *cm)
  424. {
  425. Flags m[2] = { CLIENT_TILED, CLIENT_FREE };
  426. /* Do not tab already tabbed client */
  427. if(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER)
  428. || c->tag != cm->tag || c == cm)
  429. return;
  430. layout_split_arrange_closed(c);
  431. cm->flags |= CLIENT_TABBED;
  432. c->geo = cm->geo;
  433. cm->tabmaster = c;
  434. if(cm->flags & CLIENT_FREE)
  435. swap_int((int*)&m[0], (int*)&m[1]);
  436. c->flags |= m[0];
  437. c->flags &= ~m[1];
  438. client_focus(cm);
  439. }
  440. static void
  441. client_untab(struct client *c)
  442. {
  443. struct client *ct, *cc = c->tabmaster;
  444. struct geo og = c->geo;
  445. bool chk = false;
  446. if(c->flags & CLIENT_REMOVEALL || !(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER)))
  447. return;
  448. if(!cc)
  449. {
  450. SLIST_FOREACH(cc, &c->tag->clients, tnext)
  451. if(cc->tabmaster == c)
  452. break;
  453. }
  454. if(cc)
  455. {
  456. client_tab_focus(cc);
  457. c->flags &= ~CLIENT_TABBED;
  458. c->flags |= CLIENT_IGNORE_ENTER;
  459. c->tabmaster = NULL;
  460. /* Looking for tabbed client in cc, if there is not
  461. * remove cc CLIENT_TABMASTER flag.
  462. */
  463. SLIST_FOREACH(ct, &c->tag->clients, tnext)
  464. if(ct->tabmaster == cc)
  465. {
  466. chk = true;
  467. break;
  468. }
  469. if(!chk)
  470. cc->flags &= ~CLIENT_TABMASTER;
  471. if(!(c->flags & CLIENT_DYING))
  472. {
  473. c->geo = c->tgeo = og;
  474. c->tag->sel = cc;
  475. layout_client(c);
  476. client_map(c);
  477. client_moveresize(c, &c->geo);
  478. client_update_props(c, CPROP_TAB);
  479. }
  480. client_frame_update(cc, CCOL(cc));
  481. }
  482. }
  483. void
  484. uicb_client_untab(Uicb cmd)
  485. {
  486. (void)cmd;
  487. if(W->client)
  488. client_untab(W->client);
  489. }
  490. void
  491. client_focus(struct client *c)
  492. {
  493. /* Unfocus selected */
  494. if(W->client && W->client != c)
  495. {
  496. client_grabbuttons(W->client, false);
  497. client_frame_update(W->client, &W->client->ncol);
  498. }
  499. /* Focus c */
  500. if((W->client = c))
  501. {
  502. c->tag->sel = c;
  503. client_grabbuttons(c, true);
  504. client_tab_focus(c);
  505. client_frame_update(c, CCOL(c));
  506. if(c->flags & CLIENT_FREE
  507. && !(c->flags & (CLIENT_FULLSCREEN | CLIENT_TABBED)))
  508. {
  509. c->tag->flags |= CLIENT_IGNORE_ENTER;
  510. XRaiseWindow(W->dpy, c->frame);
  511. }
  512. XSetInputFocus(W->dpy, c->win, RevertToPointerRoot, CurrentTime);
  513. }
  514. else
  515. {
  516. W->client = W->screen->seltag->sel = NULL;
  517. XSetInputFocus(W->dpy, W->root, RevertToPointerRoot, CurrentTime);
  518. }
  519. ewmh_update_wmfs_props();
  520. }
  521. void
  522. uicb_client_focus_click(Uicb cmd)
  523. {
  524. (void)cmd;
  525. struct client *c;
  526. if((c = client_gb_titlebar(W->last_clicked_barwin->win))
  527. || (c = client_gb_frame(W->last_clicked_barwin->win)))
  528. client_focus(c);
  529. }
  530. /** Get a client name
  531. * \param c struct client pointer
  532. */
  533. void
  534. client_get_name(struct client *c)
  535. {
  536. Atom rt;
  537. int rf;
  538. unsigned long ir, il;
  539. /* This one instead XFetchName for utf8 name support */
  540. if(XGetWindowProperty(W->dpy, c->win, ATOM("_NET_WM_NAME"), 0, 4096,
  541. False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, (unsigned char**)&c->title) != Success)
  542. XGetWindowProperty(W->dpy, c->win, ATOM("WM_NAME"), 0, 4096,
  543. False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, (unsigned char**)&c->title);
  544. /* Still no title... */
  545. if(!c->title)
  546. XFetchName(W->dpy, c->win, &(c->title));
  547. client_frame_update(c, CCOL(c));
  548. }
  549. /** Close a client
  550. * \param c struct client pointer
  551. */
  552. void
  553. client_close(struct client *c)
  554. {
  555. int proto;
  556. XEvent ev;
  557. Atom *atom = NULL;
  558. /* Event will call client_remove */
  559. if(XGetWMProtocols(W->dpy, c->win, &atom, &proto) && atom)
  560. {
  561. while(proto--)
  562. if(atom[proto] == ATOM("WM_DELETE_WINDOW"))
  563. {
  564. ev.type = ClientMessage;
  565. ev.xclient.window = c->win;
  566. ev.xclient.message_type = ATOM("WM_PROTOCOLS");
  567. ev.xclient.format = 32;
  568. ev.xclient.data.l[0] = ATOM("WM_DELETE_WINDOW");
  569. ev.xclient.data.l[1] = CurrentTime;
  570. XSendEvent(W->dpy, c->win, False, NoEventMask, &ev);
  571. XFree(atom);
  572. return;
  573. }
  574. }
  575. XKillClient(W->dpy, c->win);
  576. }
  577. void
  578. uicb_client_close(Uicb cmd)
  579. {
  580. (void)cmd;
  581. if(W->client)
  582. client_close(W->client);
  583. }
  584. void
  585. client_get_sizeh(struct client *c)
  586. {
  587. long msize;
  588. XSizeHints size;
  589. memset(c->sizeh, 0, SHLAST);
  590. if(!XGetWMNormalHints(W->dpy, c->win, &size, &msize) || !size.flags)
  591. size.flags = PSize;
  592. /* base */
  593. if(size.flags & PBaseSize)
  594. {
  595. c->sizeh[BASEW] = size.base_width;
  596. c->sizeh[BASEH] = size.base_height;
  597. }
  598. else if(size.flags & PMinSize)
  599. {
  600. c->sizeh[BASEW] = size.min_width;
  601. c->sizeh[BASEH] = size.min_height;
  602. }
  603. /* inc */
  604. if(size.flags & PResizeInc)
  605. {
  606. c->sizeh[INCW] = size.width_inc;
  607. c->sizeh[INCH] = size.height_inc;
  608. }
  609. /* max */
  610. if(size.flags & PMaxSize)
  611. {
  612. c->sizeh[MAXW] = size.max_width;
  613. c->sizeh[MAXH] = size.max_height;
  614. }
  615. /* min */
  616. if(size.flags & PMinSize)
  617. {
  618. c->sizeh[MINW] = (size.min_width ? size.min_width : 1);
  619. c->sizeh[MINH] = (size.min_height ? size.min_height: 1);
  620. }
  621. else if(size.flags & PBaseSize)
  622. {
  623. c->sizeh[MINW] = (size.base_width ? size.base_width : 1);
  624. c->sizeh[MINH] = (size.base_height ? size.base_height : 1);
  625. }
  626. /* aspect */
  627. if(size.flags & PAspect)
  628. {
  629. c->sizeh[MINAX] = size.min_aspect.x;
  630. c->sizeh[MAXAX] = size.max_aspect.x;
  631. c->sizeh[MINAY] = size.min_aspect.y;
  632. c->sizeh[MAXAY] = size.max_aspect.y;
  633. }
  634. if(c->sizeh[MAXW] && c->sizeh[MINW] && c->sizeh[MAXH] && c->sizeh[MINH]
  635. && c->sizeh[MAXW] == c->sizeh[MINW] && c->sizeh[MAXH] == c->sizeh[MINH])
  636. c->flags |= CLIENT_HINT_FLAG;
  637. }
  638. static void
  639. client_frame_new(struct client *c)
  640. {
  641. struct barwin *frameb;
  642. struct barwin *clientb;
  643. XSetWindowAttributes at =
  644. {
  645. .background_pixel = c->ncol.bg,
  646. .override_redirect = true,
  647. .background_pixmap = ParentRelative,
  648. .event_mask = BARWIN_MASK | BARWIN_ENTERMASK
  649. };
  650. /* Use a fake barwin only to store mousebinds of frame win */
  651. frameb = barwin_new(W->root, 0, 0, 1, 1, 0, 0, false);
  652. clientb = barwin_new(W->root, 0, 0, 1, 1, 0, 0, false);
  653. frameb->win =
  654. c->frame = XCreateWindow(W->dpy, W->root,
  655. c->geo.x, c->geo.y,
  656. c->geo.w, c->geo.h,
  657. 0, CopyFromParent,
  658. InputOutput,
  659. CopyFromParent,
  660. (CWOverrideRedirect | CWBackPixmap
  661. | CWBackPixel | CWEventMask), &at);
  662. clientb->win = c->win;
  663. frameb->mousebinds = W->tmp_head.client;
  664. clientb->mousebinds = W->tmp_head.client;
  665. if(c->tbarw > c->border)
  666. {
  667. c->titlebar = barwin_new(c->frame, 0, 0, 1, c->tbarw,
  668. c->ncol.fg, c->ncol.bg, true);
  669. c->titlebar->mousebinds = W->tmp_head.client;
  670. }
  671. XReparentWindow(W->dpy, c->win, c->frame, c->border, c->tbarw);
  672. }
  673. #define RINSTANCE 0x01
  674. #define RCLASS 0x02
  675. #define RROLE 0x04
  676. #define RNAME 0x08
  677. static void
  678. client_apply_rule(struct client *c)
  679. {
  680. struct rule *r;
  681. char *wmname = NULL;
  682. char *role = NULL;
  683. int f;
  684. unsigned char *data = NULL;
  685. unsigned long n, il;
  686. Flags flags = 0;
  687. Atom rf;
  688. XClassHint xch;
  689. Status s = XGetClassHint(W->dpy, c->win, &xch);
  690. /* Get WM_WINDOW_ROLE */
  691. if(XGetWindowProperty(W->dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, false,
  692. XA_STRING, &rf, &f, &n, &il, &data)
  693. == Success && data)
  694. {
  695. role = xstrdup((char*)data);
  696. XFree(data);
  697. }
  698. /* Get _NET_WM_NAME */
  699. if(XGetWindowProperty(W->dpy, c->win, W->net_atom[net_wm_name], 0, 0x77777777, false,
  700. W->net_atom[utf8_string], &rf, &f, &n, &il, &data)
  701. == Success && data)
  702. {
  703. wmname = xstrdup((char*)data);
  704. XFree(data);
  705. }
  706. SLIST_FOREACH(r, &W->h.rule, next)
  707. {
  708. if(s)
  709. {
  710. FLAGAPPLY(flags, (xch.res_name && r->instance && !strcmp(xch.res_name, r->instance)), RINSTANCE);
  711. FLAGAPPLY(flags, (xch.res_class && r->class && !strcmp(xch.res_class, r->class)), RCLASS);
  712. }
  713. FLAGAPPLY(flags, (wmname && r->name && !strcmp(wmname, r->name)), RNAME);
  714. FLAGAPPLY(flags, ((role && r->role && !strcmp(role, r->role)) || !role || !r->role), RROLE);
  715. if(flags & (RINSTANCE | RCLASS | RNAME) && flags & RROLE)
  716. {
  717. if(r->screen != -1)
  718. c->screen = screen_gb_id(r->screen);
  719. c->tag = c->screen->seltag;
  720. if(r->tag != -1)
  721. c->tag = tag_gb_id(c->screen, r->tag);
  722. c->theme = r->theme;
  723. if(r->flags & RULE_FREE)
  724. c->flags |= CLIENT_FREE;
  725. /* free = false for originally free client */
  726. else
  727. c->flags &= ~CLIENT_FREE;
  728. /* TODO
  729. if(r->flags & RULE_MAX)
  730. {}
  731. if(r->flags & RULE_IGNORE_TAG)
  732. {}
  733. */
  734. c->flags |= CLIENT_RULED;
  735. }
  736. flags = 0;
  737. }
  738. if(role)
  739. free(role);
  740. if(wmname)
  741. free(wmname);
  742. }
  743. struct client*
  744. client_new(Window w, XWindowAttributes *wa, bool scan)
  745. {
  746. struct client *c = xcalloc(1, sizeof(struct client));
  747. /* C attributes */
  748. c->win = w;
  749. c->flags = 0;
  750. c->screen = screen_update_sel();
  751. c->theme = W->ctheme;
  752. c->tag = NULL;
  753. c->tabmaster = NULL;
  754. /* struct geometry */
  755. c->geo.x = wa->x;
  756. c->geo.y = wa->y;
  757. c->geo.w = wa->width;
  758. c->geo.h = wa->height;
  759. c->tgeo = c->wgeo = c->rgeo = c->geo;
  760. c->tbgeo = NULL;
  761. client_get_sizeh(c);
  762. if(!scan)
  763. {
  764. if(c->flags & CLIENT_HINT_FLAG /* && OPTIONKIVABIEN */)
  765. c->flags |= CLIENT_FREE;
  766. client_apply_rule(c);
  767. }
  768. /*
  769. * Conf option set per client, for possibility
  770. * to config only one client
  771. */
  772. c->border = c->theme->client_border_width;
  773. if(!(c->tbarw = c->theme->client_titlebar_width))
  774. c->tbarw = c->border;
  775. c->ncol = c->theme->client_n;
  776. c->scol = c->theme->client_s;
  777. client_frame_new(c);
  778. if(!scan)
  779. tag_client((c->flags & CLIENT_RULED ? c->tag : c->screen->seltag), c);
  780. /* Map, not at reload */
  781. if(c->tag == c->screen->seltag)
  782. client_map(c);
  783. /* X window attributes */
  784. XSelectInput(W->dpy, w, EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask);
  785. XSetWindowBorderWidth(W->dpy, w, 0);
  786. client_grabbuttons(c, false);
  787. /* Attach */
  788. SLIST_INSERT_HEAD(&W->h.client, c, next);
  789. ewmh_set_wm_state(w, NormalState);
  790. if(!scan)
  791. {
  792. client_get_name(c);
  793. client_focus(c);
  794. client_configure(c);
  795. ewmh_manage_window_type(c);
  796. }
  797. return c;
  798. }
  799. void
  800. client_update_props(struct client *c, Flags f)
  801. {
  802. if(f & CPROP_LOC)
  803. {
  804. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_TAG"), XA_CARDINAL, 32,
  805. PropModeReplace, (unsigned char*)&(c->tag->id), 1);
  806. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_SCREEN"), XA_CARDINAL, 32,
  807. PropModeReplace, (unsigned char*)&(c->screen->id), 1);
  808. }
  809. if(f & CPROP_FLAG)
  810. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_FLAGS"), XA_CARDINAL, 32,
  811. PropModeReplace, (unsigned char*)&(c->flags), 1);
  812. if(f & CPROP_GEO)
  813. {
  814. long g[4] = { (long)c->geo.x, (long)c->geo.y, (long)c->geo.w, (long)c->geo.h };
  815. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_GEO"), XA_CARDINAL, 32,
  816. PropModeReplace, (unsigned char*)g, 4);
  817. }
  818. if(f & CPROP_TAB)
  819. {
  820. Window w = (c->tabmaster ? c->tabmaster->win : 0);
  821. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_TABMASTER"), XA_WINDOW, 32,
  822. PropModeReplace, (unsigned char*)&w, 1);
  823. }
  824. }
  825. void
  826. client_geo_hints(struct geo *g, int *s)
  827. {
  828. /* base */
  829. g->w -= s[BASEW];
  830. g->h -= s[BASEH];
  831. /* aspect */
  832. if((s[MINAY] | s[MAXAY] | s[MINAX] | s[MAXAX]) > 0)
  833. {
  834. if(g->w * s[MAXAY] > g->h * s[MAXAX])
  835. g->w = g->h * s[MAXAX] / s[MAXAY];
  836. else if(g->w * s[MINAY] < g->h * s[MINAX])
  837. g->h = g->w * s[MINAY] / s[MINAX];
  838. }
  839. /* incremental */
  840. if(s[INCW])
  841. g->w -= g->w % s[INCW];
  842. if(s[INCH])
  843. g->h -= g->h % s[INCH];
  844. /* base dimension */
  845. g->w += s[BASEW];
  846. g->h += s[BASEH];
  847. if(s[MINW] > 0 && g->w < s[MINW])
  848. g->w = s[MINW];
  849. if(s[MINH] > 0 && g->h < s[MINH])
  850. g->h = s[MINH];
  851. if(s[MAXW] > 0 && g->w > s[MAXW])
  852. g->w = s[MAXW];
  853. if(s[MAXH] > 0 && g->h > s[MAXH])
  854. g->h = s[MAXH];
  855. }
  856. /* Manage window size in frame in tiling mode */
  857. bool
  858. client_winsize(struct client *c, struct geo *g)
  859. {
  860. int ow, oh;
  861. struct geo og = c->wgeo;
  862. /* Window geo */
  863. c->wgeo.x = c->border;
  864. c->wgeo.y = c->tbarw;
  865. c->wgeo.h = oh = g->h - (c->border + c->tbarw);
  866. c->wgeo.w = ow = g->w - (c->border << 1);
  867. client_geo_hints(&c->wgeo, (int*)c->sizeh);
  868. /* Check possible problem for tile integration */
  869. if(ow < c->sizeh[MINW] || oh < c->sizeh[MINH])
  870. if(g->w < c->geo.w || g->h < c->geo.h)
  871. {
  872. c->wgeo = og;
  873. return true;
  874. }
  875. /* Balance position with new size */
  876. c->wgeo.x += (ow - c->wgeo.w) >> 1;
  877. c->flags |= CLIENT_DID_WINSIZE;
  878. return false;
  879. }
  880. void
  881. client_moveresize(struct client *c, struct geo *g)
  882. {
  883. if(c->flags & CLIENT_TABBED)
  884. return;
  885. /* Adjust frame regarding window required size */
  886. if(c->flags & CLIENT_FREE)
  887. {
  888. g->w -= c->border + c->border;
  889. g->h -= c->tbarw + c->border;
  890. client_geo_hints(g, (int*)c->sizeh);
  891. c->wgeo = c->geo = c->rgeo = *g;
  892. c->wgeo.x = c->border;
  893. c->wgeo.y = c->tbarw;
  894. c->geo.w = c->rgeo.w = c->wgeo.w + c->border + c->border;
  895. c->geo.h = c->rgeo.h = c->wgeo.h + c->tbarw + c->border;
  896. c->rgeo.x += c->screen->ugeo.x;
  897. c->rgeo.y += c->screen->ugeo.y;
  898. if(!INAREA(c->rgeo.x, c->rgeo.y, c->screen->ugeo))
  899. {
  900. /* New screen (moved by mouse) */
  901. if(c->flags & CLIENT_MOUSE)
  902. {
  903. c->flags |= CLIENT_IGNORE_LAYOUT;
  904. c->screen = screen_gb_geo(c->rgeo.x, c->rgeo.y);
  905. tag_client(c->screen->seltag, c);
  906. c->geo.x = c->rgeo.x - c->screen->ugeo.x;
  907. c->geo.y = c->rgeo.y - c->screen->ugeo.y;
  908. }
  909. /* Out of the screen case */
  910. else
  911. {
  912. c->geo.x = (c->screen->ugeo.w >> 1) - (c->geo.w >> 1);
  913. c->geo.y = (c->screen->ugeo.h >> 1) - (c->geo.h >> 1);
  914. c->rgeo.x = c->screen->ugeo.x + c->geo.x;
  915. c->rgeo.y = c->screen->ugeo.y + c->geo.y;
  916. }
  917. }
  918. }
  919. /* Adjust window regarding required size for frame (tiling) */
  920. else
  921. {
  922. c->ttgeo = c->tgeo = c->rgeo = c->geo = *g;
  923. if(!(c->flags & CLIENT_DID_WINSIZE))
  924. client_winsize(c, g);
  925. c->rgeo.x += c->screen->ugeo.x;
  926. c->rgeo.y += c->screen->ugeo.y;
  927. }
  928. XMoveResizeWindow(W->dpy, c->frame,
  929. c->rgeo.x, c->rgeo.y,
  930. c->rgeo.w, c->rgeo.h);
  931. if(!(c->flags & CLIENT_FULLSCREEN))
  932. XMoveResizeWindow(W->dpy, c->win,
  933. c->wgeo.x, c->wgeo.y,
  934. c->wgeo.w, c->wgeo.h);
  935. c->flags &= ~CLIENT_DID_WINSIZE;
  936. client_frame_update(c, CCOL(c));
  937. client_update_props(c, CPROP_GEO);
  938. client_configure(c);
  939. }
  940. void
  941. client_maximize(struct client *c)
  942. {
  943. c->geo.x = c->geo.y = 0;
  944. c->geo.w = c->screen->ugeo.w;
  945. c->geo.h = c->screen->ugeo.h;
  946. client_moveresize(c, &c->geo);
  947. layout_save_set(c->tag);
  948. }
  949. /*
  950. * Client factor resize: allow clients to be resized in
  951. * manual tile layout.
  952. */
  953. static inline void
  954. _fac_apply(struct client *c, enum position p, int fac)
  955. {
  956. switch(p)
  957. {
  958. case Top:
  959. c->tgeo.y -= fac;
  960. case Bottom:
  961. c->tgeo.h += fac;
  962. break;
  963. case Left:
  964. c->tgeo.x -= fac;
  965. default:
  966. case Right:
  967. c->tgeo.w += fac;
  968. break;
  969. }
  970. c->flags |= (CLIENT_IGNORE_ENTER | CLIENT_FAC_APPLIED);
  971. }
  972. static inline void
  973. _fac_arrange_row(struct client *c, enum position p, int fac)
  974. {
  975. struct geo g = c->tgeo;
  976. struct client *cc;
  977. /* Travel clients to search row parents and apply fac */
  978. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  979. if(GEO_PARENTROW(g, cc->tgeo, p))
  980. _fac_apply(cc, p, fac);
  981. }
  982. static inline void
  983. _fac_check_to_reverse(struct client *c)
  984. {
  985. struct client *gc, *cc;
  986. /*
  987. * Check if every clients are compatible with
  988. * future globals geo. Problem here is that we must *not*
  989. * resize client because of possible error with next
  990. * clients in linked list.
  991. */
  992. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext)
  993. if(gc->flags & CLIENT_FAC_APPLIED
  994. && client_winsize(gc, &gc->tgeo))
  995. {
  996. /*
  997. * Reverse back the flag and the window geo
  998. * in previous affected clients
  999. */
  1000. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  1001. {
  1002. cc->tgeo = cc->ttgeo;
  1003. cc->flags &= ~CLIENT_DID_WINSIZE;
  1004. }
  1005. return;
  1006. }
  1007. }
  1008. void
  1009. _fac_resize(struct client *c, enum position p, int fac)
  1010. {
  1011. struct client *cc, *gc = client_next_with_pos(c, p);
  1012. enum position rp = RPOS(p);
  1013. if(!gc || gc->screen != c->screen || !(c->flags & CLIENT_TILED))
  1014. return;
  1015. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  1016. cc->ttgeo = cc->tgeo;
  1017. if(GEO_CHECK2(c->tgeo, gc->tgeo, p))
  1018. {
  1019. _fac_apply(c, p, fac);
  1020. _fac_apply(gc, rp, -fac);
  1021. }
  1022. else
  1023. {
  1024. _fac_arrange_row(c, p, fac);
  1025. _fac_arrange_row(gc, rp, -fac);
  1026. }
  1027. _fac_check_to_reverse(c);
  1028. }
  1029. void
  1030. client_apply_tgeo(struct tag *t)
  1031. {
  1032. struct client *c;
  1033. FOREACH_NFCLIENT(c, &t->clients, tnext)
  1034. {
  1035. client_moveresize(c, &c->tgeo);
  1036. c->flags &= ~CLIENT_FAC_APPLIED;
  1037. }
  1038. }
  1039. #define _REV_BORDER() \
  1040. do { \
  1041. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext) \
  1042. draw_reversed_rect(W->root, gc, true); \
  1043. } while(/* CONSTCOND */ 0);
  1044. void
  1045. client_fac_resize(struct client *c, enum position p, int fac)
  1046. {
  1047. struct keybind *k;
  1048. struct client *gc;
  1049. bool b = true;
  1050. XEvent ev;
  1051. KeySym keysym;
  1052. /* Do it once before */
  1053. _fac_resize(c, p, fac);
  1054. /* TODO
  1055. if(option_simple_manual_resize)
  1056. return;
  1057. */
  1058. XGrabServer(W->dpy);
  1059. XGrabKeyboard(W->dpy, W->root, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  1060. _REV_BORDER();
  1061. do
  1062. {
  1063. XMaskEvent(W->dpy, KeyPressMask, &ev);
  1064. if(ev.type == KeyPress)
  1065. {
  1066. XKeyPressedEvent *ke = &ev.xkey;
  1067. keysym = XKeycodeToKeysym(W->dpy, (KeyCode)ke->keycode, 0);
  1068. _REV_BORDER();
  1069. SLIST_FOREACH(k, &W->h.keybind, next)
  1070. if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ke->state)
  1071. && k->func)
  1072. {
  1073. if(k->func == uicb_client_resize_Right)
  1074. _fac_resize(c, Right, ATOI(k->cmd));
  1075. else if(k->func == uicb_client_resize_Left)
  1076. _fac_resize(c, Left, ATOI(k->cmd));
  1077. else if(k->func == uicb_client_resize_Top)
  1078. _fac_resize(c, Top, ATOI(k->cmd));
  1079. else if(k->func == uicb_client_resize_Bottom)
  1080. _fac_resize(c, Bottom, ATOI(k->cmd));
  1081. else
  1082. {
  1083. k->func(k->cmd);
  1084. keysym = XK_Escape;
  1085. }
  1086. }
  1087. _REV_BORDER();
  1088. /* Gtfo of this loop */
  1089. if(keysym == XK_Return)
  1090. break;
  1091. else if(keysym == XK_Escape)
  1092. {
  1093. b = false;
  1094. break;
  1095. }
  1096. XSync(W->dpy, False);
  1097. }
  1098. XNextEvent(W->dpy, &ev);
  1099. } while(ev.type != KeyPress);
  1100. _REV_BORDER();
  1101. /* Success, resize clients */
  1102. if(b)
  1103. {
  1104. client_apply_tgeo(c->tag);
  1105. layout_save_set(c->tag);
  1106. }
  1107. /* Aborted with escape, Set back original geos */
  1108. else
  1109. {
  1110. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext)
  1111. {
  1112. gc->tgeo = gc->geo;
  1113. gc->flags &= ~CLIENT_DID_WINSIZE;
  1114. }
  1115. }
  1116. XUngrabServer(W->dpy);
  1117. XUngrabKeyboard(W->dpy, CurrentTime);
  1118. }
  1119. void
  1120. client_fac_hint(struct client *c)
  1121. {
  1122. int w = c->sizeh[MINW] + c->border + c->border;
  1123. int h = c->sizeh[MINH] + c->tbarw + c->border;
  1124. if(c->geo.h < h)
  1125. _fac_resize(c, Top, (h - c->geo.h));
  1126. if(c->tgeo.h < h)
  1127. _fac_resize(c, Bottom, (h - c->tgeo.h));
  1128. if(c->geo.w < w)
  1129. _fac_resize(c, Left, (w - c->geo.w));
  1130. if(c->tgeo.w < w)
  1131. _fac_resize(c, Right, (w - c->tgeo.w));
  1132. client_apply_tgeo(c->tag);
  1133. }
  1134. void
  1135. client_remove(struct client *c)
  1136. {
  1137. c->flags |= CLIENT_DYING;
  1138. XGrabServer(W->dpy);
  1139. XSetErrorHandler(wmfs_error_handler_dummy);
  1140. client_map(c);
  1141. XReparentWindow(W->dpy, c->win, W->root, c->rgeo.x, c->rgeo.y);
  1142. client_untab(c);
  1143. XDestroyWindow(W->dpy, c->frame);
  1144. if(c->titlebar)
  1145. barwin_remove(c->titlebar);
  1146. /* Remove from global client list */
  1147. SLIST_REMOVE(&W->h.client, c, client, next);
  1148. tag_client(NULL, c);
  1149. ewmh_set_wm_state(c->win, WithdrawnState);
  1150. XUngrabServer(W->dpy);
  1151. XSync(W->dpy, False);
  1152. XSetErrorHandler(wmfs_error_handler);
  1153. free(c);
  1154. }
  1155. void
  1156. uicb_client_toggle_free(Uicb cmd)
  1157. {
  1158. struct client *c;
  1159. (void)cmd;
  1160. if(!(W->client))
  1161. return;
  1162. W->client->flags ^= CLIENT_FREE;
  1163. layout_client(W->client);
  1164. /* Set tabbed client of toggled client as free */
  1165. if(W->client->flags & CLIENT_TABMASTER)
  1166. {
  1167. SLIST_FOREACH(c, &W->client->tag->clients, tnext)
  1168. if(c->tabmaster == W->client && c != W->client)
  1169. c->flags ^= CLIENT_FREE;
  1170. }
  1171. }
  1172. void
  1173. uicb_client_tab_next_opened(Uicb cmd)
  1174. {
  1175. (void)cmd;
  1176. W->flags ^= WMFS_TABNOC;
  1177. }
  1178. void
  1179. client_free(void)
  1180. {
  1181. FREE_LIST(client, W->h.client);
  1182. }