client.c 37 KB

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