client.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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. /* free = false for originally free client */
  724. if(r->flags & RULE_FREE)
  725. c->flags |= CLIENT_FREE;
  726. else
  727. c->flags &= ~CLIENT_FREE;
  728. /* Free rule is not compatible with tab rule */
  729. if(r->flags & RULE_TAB)
  730. W->flags ^= WMFS_TABNOC; /* < can be disable by client_tab_next_opened */
  731. /* TODO
  732. if(r->flags & RULE_IGNORE_TAG)
  733. {}
  734. */
  735. c->flags |= CLIENT_RULED;
  736. }
  737. flags = 0;
  738. }
  739. if(role)
  740. free(role);
  741. if(wmname)
  742. free(wmname);
  743. }
  744. struct client*
  745. client_new(Window w, XWindowAttributes *wa, bool scan)
  746. {
  747. struct client *c = xcalloc(1, sizeof(struct client));
  748. /* C attributes */
  749. c->win = w;
  750. c->flags = 0;
  751. c->screen = screen_update_sel();
  752. c->theme = W->ctheme;
  753. c->tag = NULL;
  754. c->tabmaster = NULL;
  755. /* struct geometry */
  756. c->geo.x = wa->x;
  757. c->geo.y = wa->y;
  758. c->geo.w = wa->width;
  759. c->geo.h = wa->height;
  760. c->tgeo = c->wgeo = c->rgeo = c->geo;
  761. c->tbgeo = NULL;
  762. client_get_sizeh(c);
  763. if(!scan)
  764. {
  765. if(c->flags & CLIENT_HINT_FLAG /* && OPTIONKIVABIEN */)
  766. c->flags |= CLIENT_FREE;
  767. client_apply_rule(c);
  768. }
  769. /*
  770. * Conf option set per client, for possibility
  771. * to config only one client
  772. */
  773. c->border = c->theme->client_border_width;
  774. if(!(c->tbarw = c->theme->client_titlebar_width))
  775. c->tbarw = c->border;
  776. c->ncol = c->theme->client_n;
  777. c->scol = c->theme->client_s;
  778. client_frame_new(c);
  779. if(!scan)
  780. tag_client((c->flags & CLIENT_RULED ? c->tag : c->screen->seltag), c);
  781. /* Map, not at reload */
  782. if(c->tag == c->screen->seltag)
  783. client_map(c);
  784. /* X window attributes */
  785. XSelectInput(W->dpy, w, EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask);
  786. XSetWindowBorderWidth(W->dpy, w, 0);
  787. client_grabbuttons(c, false);
  788. /* Attach */
  789. SLIST_INSERT_HEAD(&W->h.client, c, next);
  790. ewmh_set_wm_state(w, NormalState);
  791. if(!scan)
  792. {
  793. client_get_name(c);
  794. client_focus(c);
  795. client_configure(c);
  796. ewmh_manage_window_type(c);
  797. }
  798. return c;
  799. }
  800. void
  801. client_update_props(struct client *c, Flags f)
  802. {
  803. if(f & CPROP_LOC)
  804. {
  805. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_TAG"), XA_CARDINAL, 32,
  806. PropModeReplace, (unsigned char*)&(c->tag->id), 1);
  807. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_SCREEN"), XA_CARDINAL, 32,
  808. PropModeReplace, (unsigned char*)&(c->screen->id), 1);
  809. }
  810. if(f & CPROP_FLAG)
  811. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_FLAGS"), XA_CARDINAL, 32,
  812. PropModeReplace, (unsigned char*)&(c->flags), 1);
  813. if(f & CPROP_GEO)
  814. {
  815. long g[4] = { (long)c->geo.x, (long)c->geo.y, (long)c->geo.w, (long)c->geo.h };
  816. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_GEO"), XA_CARDINAL, 32,
  817. PropModeReplace, (unsigned char*)g, 4);
  818. }
  819. if(f & CPROP_TAB)
  820. {
  821. Window w = (c->tabmaster ? c->tabmaster->win : 0);
  822. XChangeProperty(W->dpy, c->win, ATOM("_WMFS_TABMASTER"), XA_WINDOW, 32,
  823. PropModeReplace, (unsigned char*)&w, 1);
  824. }
  825. }
  826. void
  827. client_geo_hints(struct geo *g, int *s)
  828. {
  829. /* base */
  830. g->w -= s[BASEW];
  831. g->h -= s[BASEH];
  832. /* aspect */
  833. if((s[MINAY] | s[MAXAY] | s[MINAX] | s[MAXAX]) > 0)
  834. {
  835. if(g->w * s[MAXAY] > g->h * s[MAXAX])
  836. g->w = g->h * s[MAXAX] / s[MAXAY];
  837. else if(g->w * s[MINAY] < g->h * s[MINAX])
  838. g->h = g->w * s[MINAY] / s[MINAX];
  839. }
  840. /* incremental */
  841. if(s[INCW])
  842. g->w -= g->w % s[INCW];
  843. if(s[INCH])
  844. g->h -= g->h % s[INCH];
  845. /* base dimension */
  846. g->w += s[BASEW];
  847. g->h += s[BASEH];
  848. if(s[MINW] > 0 && g->w < s[MINW])
  849. g->w = s[MINW];
  850. if(s[MINH] > 0 && g->h < s[MINH])
  851. g->h = s[MINH];
  852. if(s[MAXW] > 0 && g->w > s[MAXW])
  853. g->w = s[MAXW];
  854. if(s[MAXH] > 0 && g->h > s[MAXH])
  855. g->h = s[MAXH];
  856. }
  857. /* Manage window size in frame in tiling mode */
  858. bool
  859. client_winsize(struct client *c, struct geo *g)
  860. {
  861. int ow, oh;
  862. struct geo og = c->wgeo;
  863. /* Window geo */
  864. c->wgeo.x = c->border;
  865. c->wgeo.y = c->tbarw;
  866. c->wgeo.h = oh = g->h - (c->border + c->tbarw);
  867. c->wgeo.w = ow = g->w - (c->border << 1);
  868. client_geo_hints(&c->wgeo, (int*)c->sizeh);
  869. /* Check possible problem for tile integration */
  870. if(ow < c->sizeh[MINW] || oh < c->sizeh[MINH])
  871. if(g->w < c->geo.w || g->h < c->geo.h)
  872. {
  873. c->wgeo = og;
  874. return true;
  875. }
  876. /* Balance position with new size */
  877. c->wgeo.x += (ow - c->wgeo.w) >> 1;
  878. c->flags |= CLIENT_DID_WINSIZE;
  879. return false;
  880. }
  881. void
  882. client_moveresize(struct client *c, struct geo *g)
  883. {
  884. if(c->flags & CLIENT_TABBED)
  885. return;
  886. /* Adjust frame regarding window required size */
  887. if(c->flags & CLIENT_FREE)
  888. {
  889. g->w -= c->border + c->border;
  890. g->h -= c->tbarw + c->border;
  891. client_geo_hints(g, (int*)c->sizeh);
  892. c->wgeo = c->geo = c->rgeo = *g;
  893. c->wgeo.x = c->border;
  894. c->wgeo.y = c->tbarw;
  895. c->geo.w = c->rgeo.w = c->wgeo.w + c->border + c->border;
  896. c->geo.h = c->rgeo.h = c->wgeo.h + c->tbarw + c->border;
  897. c->rgeo.x += c->screen->ugeo.x;
  898. c->rgeo.y += c->screen->ugeo.y;
  899. if(!INAREA(c->rgeo.x, c->rgeo.y, c->screen->ugeo))
  900. {
  901. /* New screen (moved by mouse) */
  902. if(c->flags & CLIENT_MOUSE)
  903. {
  904. c->flags |= CLIENT_IGNORE_LAYOUT;
  905. c->screen = screen_gb_geo(c->rgeo.x, c->rgeo.y);
  906. tag_client(c->screen->seltag, c);
  907. c->geo.x = c->rgeo.x - c->screen->ugeo.x;
  908. c->geo.y = c->rgeo.y - c->screen->ugeo.y;
  909. }
  910. /* Out of the screen case */
  911. else
  912. {
  913. c->geo.x = (c->screen->ugeo.w >> 1) - (c->geo.w >> 1);
  914. c->geo.y = (c->screen->ugeo.h >> 1) - (c->geo.h >> 1);
  915. c->rgeo.x = c->screen->ugeo.x + c->geo.x;
  916. c->rgeo.y = c->screen->ugeo.y + c->geo.y;
  917. }
  918. }
  919. }
  920. /* Adjust window regarding required size for frame (tiling) */
  921. else
  922. {
  923. c->ttgeo = c->tgeo = c->rgeo = c->geo = *g;
  924. if(!(c->flags & CLIENT_DID_WINSIZE))
  925. client_winsize(c, g);
  926. c->rgeo.x += c->screen->ugeo.x;
  927. c->rgeo.y += c->screen->ugeo.y;
  928. }
  929. XMoveResizeWindow(W->dpy, c->frame,
  930. c->rgeo.x, c->rgeo.y,
  931. c->rgeo.w, c->rgeo.h);
  932. if(!(c->flags & CLIENT_FULLSCREEN))
  933. XMoveResizeWindow(W->dpy, c->win,
  934. c->wgeo.x, c->wgeo.y,
  935. c->wgeo.w, c->wgeo.h);
  936. c->flags &= ~CLIENT_DID_WINSIZE;
  937. client_frame_update(c, CCOL(c));
  938. client_update_props(c, CPROP_GEO);
  939. client_configure(c);
  940. }
  941. void
  942. client_maximize(struct client *c)
  943. {
  944. c->geo.x = c->geo.y = 0;
  945. c->geo.w = c->screen->ugeo.w;
  946. c->geo.h = c->screen->ugeo.h;
  947. client_moveresize(c, &c->geo);
  948. layout_save_set(c->tag);
  949. }
  950. /*
  951. * Client factor resize: allow clients to be resized in
  952. * manual tile layout.
  953. */
  954. static inline void
  955. _fac_apply(struct client *c, enum position p, int fac)
  956. {
  957. switch(p)
  958. {
  959. case Top:
  960. c->tgeo.y -= fac;
  961. case Bottom:
  962. c->tgeo.h += fac;
  963. break;
  964. case Left:
  965. c->tgeo.x -= fac;
  966. default:
  967. case Right:
  968. c->tgeo.w += fac;
  969. break;
  970. }
  971. c->flags |= (CLIENT_IGNORE_ENTER | CLIENT_FAC_APPLIED);
  972. }
  973. static inline void
  974. _fac_arrange_row(struct client *c, enum position p, int fac)
  975. {
  976. struct geo g = c->tgeo;
  977. struct client *cc;
  978. /* Travel clients to search row parents and apply fac */
  979. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  980. if(GEO_PARENTROW(g, cc->tgeo, p))
  981. _fac_apply(cc, p, fac);
  982. }
  983. static inline void
  984. _fac_check_to_reverse(struct client *c)
  985. {
  986. struct client *gc, *cc;
  987. /*
  988. * Check if every clients are compatible with
  989. * future globals geo. Problem here is that we must *not*
  990. * resize client because of possible error with next
  991. * clients in linked list.
  992. */
  993. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext)
  994. if(gc->flags & CLIENT_FAC_APPLIED
  995. && client_winsize(gc, &gc->tgeo))
  996. {
  997. /*
  998. * Reverse back the flag and the window geo
  999. * in previous affected clients
  1000. */
  1001. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  1002. {
  1003. cc->tgeo = cc->ttgeo;
  1004. cc->flags &= ~CLIENT_DID_WINSIZE;
  1005. }
  1006. return;
  1007. }
  1008. }
  1009. void
  1010. _fac_resize(struct client *c, enum position p, int fac)
  1011. {
  1012. struct client *cc, *gc = client_next_with_pos(c, p);
  1013. enum position rp = RPOS(p);
  1014. if(!gc || gc->screen != c->screen || !(c->flags & CLIENT_TILED))
  1015. return;
  1016. FOREACH_NFCLIENT(cc, &c->tag->clients, tnext)
  1017. cc->ttgeo = cc->tgeo;
  1018. if(GEO_CHECK2(c->tgeo, gc->tgeo, p))
  1019. {
  1020. _fac_apply(c, p, fac);
  1021. _fac_apply(gc, rp, -fac);
  1022. }
  1023. else
  1024. {
  1025. _fac_arrange_row(c, p, fac);
  1026. _fac_arrange_row(gc, rp, -fac);
  1027. }
  1028. _fac_check_to_reverse(c);
  1029. }
  1030. void
  1031. client_apply_tgeo(struct tag *t)
  1032. {
  1033. struct client *c;
  1034. FOREACH_NFCLIENT(c, &t->clients, tnext)
  1035. {
  1036. client_moveresize(c, &c->tgeo);
  1037. c->flags &= ~CLIENT_FAC_APPLIED;
  1038. }
  1039. }
  1040. #define _REV_BORDER() \
  1041. do { \
  1042. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext) \
  1043. draw_reversed_rect(W->root, gc, true); \
  1044. } while(/* CONSTCOND */ 0);
  1045. void
  1046. client_fac_resize(struct client *c, enum position p, int fac)
  1047. {
  1048. struct keybind *k;
  1049. struct client *gc;
  1050. bool b = true;
  1051. XEvent ev;
  1052. KeySym keysym;
  1053. /* Do it once before */
  1054. _fac_resize(c, p, fac);
  1055. /* TODO
  1056. if(option_simple_manual_resize)
  1057. return;
  1058. */
  1059. XGrabServer(W->dpy);
  1060. XGrabKeyboard(W->dpy, W->root, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  1061. _REV_BORDER();
  1062. do
  1063. {
  1064. XMaskEvent(W->dpy, KeyPressMask, &ev);
  1065. if(ev.type == KeyPress)
  1066. {
  1067. XKeyPressedEvent *ke = &ev.xkey;
  1068. keysym = XKeycodeToKeysym(W->dpy, (KeyCode)ke->keycode, 0);
  1069. _REV_BORDER();
  1070. SLIST_FOREACH(k, &W->h.keybind, next)
  1071. if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ke->state)
  1072. && k->func)
  1073. {
  1074. if(k->func == uicb_client_resize_Right)
  1075. _fac_resize(c, Right, ATOI(k->cmd));
  1076. else if(k->func == uicb_client_resize_Left)
  1077. _fac_resize(c, Left, ATOI(k->cmd));
  1078. else if(k->func == uicb_client_resize_Top)
  1079. _fac_resize(c, Top, ATOI(k->cmd));
  1080. else if(k->func == uicb_client_resize_Bottom)
  1081. _fac_resize(c, Bottom, ATOI(k->cmd));
  1082. else
  1083. {
  1084. k->func(k->cmd);
  1085. keysym = XK_Escape;
  1086. }
  1087. }
  1088. _REV_BORDER();
  1089. /* Gtfo of this loop */
  1090. if(keysym == XK_Return)
  1091. break;
  1092. else if(keysym == XK_Escape)
  1093. {
  1094. b = false;
  1095. break;
  1096. }
  1097. XSync(W->dpy, False);
  1098. }
  1099. XNextEvent(W->dpy, &ev);
  1100. } while(ev.type != KeyPress);
  1101. _REV_BORDER();
  1102. /* Success, resize clients */
  1103. if(b)
  1104. {
  1105. client_apply_tgeo(c->tag);
  1106. layout_save_set(c->tag);
  1107. }
  1108. /* Aborted with escape, Set back original geos */
  1109. else
  1110. {
  1111. FOREACH_NFCLIENT(gc, &c->tag->clients, tnext)
  1112. {
  1113. gc->tgeo = gc->geo;
  1114. gc->flags &= ~CLIENT_DID_WINSIZE;
  1115. }
  1116. }
  1117. XUngrabServer(W->dpy);
  1118. XUngrabKeyboard(W->dpy, CurrentTime);
  1119. }
  1120. void
  1121. client_fac_hint(struct client *c)
  1122. {
  1123. int w = c->sizeh[MINW] + c->border + c->border;
  1124. int h = c->sizeh[MINH] + c->tbarw + c->border;
  1125. if(c->geo.h < h)
  1126. _fac_resize(c, Top, (h - c->geo.h));
  1127. if(c->tgeo.h < h)
  1128. _fac_resize(c, Bottom, (h - c->tgeo.h));
  1129. if(c->geo.w < w)
  1130. _fac_resize(c, Left, (w - c->geo.w));
  1131. if(c->tgeo.w < w)
  1132. _fac_resize(c, Right, (w - c->tgeo.w));
  1133. client_apply_tgeo(c->tag);
  1134. }
  1135. void
  1136. client_remove(struct client *c)
  1137. {
  1138. c->flags |= CLIENT_DYING;
  1139. XGrabServer(W->dpy);
  1140. XSetErrorHandler(wmfs_error_handler_dummy);
  1141. client_map(c);
  1142. XReparentWindow(W->dpy, c->win, W->root, c->rgeo.x, c->rgeo.y);
  1143. client_untab(c);
  1144. XDestroyWindow(W->dpy, c->frame);
  1145. if(c->titlebar)
  1146. barwin_remove(c->titlebar);
  1147. /* Remove from global client list */
  1148. SLIST_REMOVE(&W->h.client, c, client, next);
  1149. tag_client(NULL, c);
  1150. ewmh_set_wm_state(c->win, WithdrawnState);
  1151. XUngrabServer(W->dpy);
  1152. XSync(W->dpy, False);
  1153. XSetErrorHandler(wmfs_error_handler);
  1154. free(c);
  1155. }
  1156. void
  1157. uicb_client_toggle_free(Uicb cmd)
  1158. {
  1159. struct client *c;
  1160. (void)cmd;
  1161. if(!(W->client))
  1162. return;
  1163. W->client->flags ^= CLIENT_FREE;
  1164. layout_client(W->client);
  1165. /* Set tabbed client of toggled client as free */
  1166. if(W->client->flags & CLIENT_TABMASTER)
  1167. {
  1168. SLIST_FOREACH(c, &W->client->tag->clients, tnext)
  1169. if(c->tabmaster == W->client && c != W->client)
  1170. c->flags ^= CLIENT_FREE;
  1171. }
  1172. }
  1173. void
  1174. uicb_client_tab_next_opened(Uicb cmd)
  1175. {
  1176. (void)cmd;
  1177. W->flags ^= WMFS_TABNOC;
  1178. }
  1179. void
  1180. client_free(void)
  1181. {
  1182. FREE_LIST(client, W->h.client);
  1183. }