bar-0.6.patch 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. From 85e40afc2ad8acba453ce8c57233542e340c1c2b Mon Sep 17 00:00:00 2001
  2. From: sewn <sewn@disroot.org>
  3. Date: Fri, 23 Aug 2024 09:42:04 +0300
  4. Subject: [PATCH] Implement dwm bar clone
  5. ---
  6. Makefile | 2 +-
  7. config.def.h | 31 +++-
  8. drwl.h | 311 ++++++++++++++++++++++++++++++++++++
  9. dwl.c | 442 +++++++++++++++++++++++++++++++++++++++++----------
  10. 4 files changed, 691 insertions(+), 95 deletions(-)
  11. create mode 100644 drwl.h
  12. diff --git a/Makefile b/Makefile
  13. index 0d651e7..2a11396 100644
  14. --- a/Makefile
  15. +++ b/Makefile
  16. @@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement \
  17. -Wfloat-conversion
  18. # CFLAGS / LDFLAGS
  19. -PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
  20. +PKGS = wlroots wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS)
  21. DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
  22. LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
  23. diff --git a/config.def.h b/config.def.h
  24. index 22d2171..5d1dc2b 100644
  25. --- a/config.def.h
  26. +++ b/config.def.h
  27. @@ -7,15 +7,21 @@
  28. static const int sloppyfocus = 1; /* focus follows mouse */
  29. static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
  30. static const unsigned int borderpx = 1; /* border pixel of windows */
  31. -static const float rootcolor[] = COLOR(0x222222ff);
  32. -static const float bordercolor[] = COLOR(0x444444ff);
  33. -static const float focuscolor[] = COLOR(0x005577ff);
  34. -static const float urgentcolor[] = COLOR(0xff0000ff);
  35. +static const int showbar = 1; /* 0 means no bar */
  36. +static const int topbar = 1; /* 0 means bottom bar */
  37. +static const char *fonts[] = {"monospace:size=10"};
  38. +static const float rootcolor[] = COLOR(0x000000ff);
  39. /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
  40. static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */
  41. +static uint32_t colors[][3] = {
  42. + /* fg bg border */
  43. + [SchemeNorm] = { 0xbbbbbbff, 0x222222ff, 0x444444ff },
  44. + [SchemeSel] = { 0xeeeeeeff, 0x005577ff, 0x005577ff },
  45. + [SchemeUrg] = { 0, 0, 0x770000ff },
  46. +};
  47. /* tagging - TAGCOUNT must be no greater than 31 */
  48. -#define TAGCOUNT (9)
  49. +static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  50. /* logging */
  51. static int log_level = WLR_ERROR;
  52. @@ -127,6 +133,7 @@ static const Key keys[] = {
  53. /* modifier key function argument */
  54. { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
  55. { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
  56. + { MODKEY, XKB_KEY_b, togglebar, {0} },
  57. { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
  58. { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
  59. { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
  60. @@ -170,7 +177,15 @@ static const Key keys[] = {
  61. };
  62. static const Button buttons[] = {
  63. - { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
  64. - { MODKEY, BTN_MIDDLE, togglefloating, {0} },
  65. - { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
  66. + { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} },
  67. + { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} },
  68. + { ClkTitle, 0, BTN_MIDDLE, zoom, {0} },
  69. + { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} },
  70. + { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
  71. + { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} },
  72. + { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
  73. + { ClkTagBar, 0, BTN_LEFT, view, {0} },
  74. + { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} },
  75. + { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} },
  76. + { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} },
  77. };
  78. diff --git a/drwl.h b/drwl.h
  79. new file mode 100644
  80. index 0000000..b06a736
  81. --- /dev/null
  82. +++ b/drwl.h
  83. @@ -0,0 +1,311 @@
  84. +/*
  85. + * drwl - https://codeberg.org/sewn/drwl
  86. + *
  87. + * Copyright (c) 2023-2024 sewn <sewn@disroot.org>
  88. + * Copyright (c) 2024 notchoc <notchoc@disroot.org>
  89. + *
  90. + * Permission is hereby granted, free of charge, to any person obtaining
  91. + * a copy of this software and associated documentation files (the
  92. + * "Software"), to deal in the Software without restriction, including
  93. + * without limitation the rights to use, copy, modify, merge, publish,
  94. + * distribute, sublicense, and/or sell copies of the Software, and to
  95. + * permit persons to whom the Software is furnished to do so, subject to
  96. + * the following conditions:
  97. + *
  98. + * The above copyright notice and this permission notice shall be
  99. + * included in all copies or substantial portions of the Software.
  100. + *
  101. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  102. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  103. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  104. + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  105. + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  106. + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  107. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  108. + *
  109. + * The UTF-8 Decoder included is from Bjoern Hoehrmann:
  110. + * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
  111. + * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
  112. + */
  113. +#pragma once
  114. +
  115. +#include <stdlib.h>
  116. +#include <fcft/fcft.h>
  117. +#include <pixman-1/pixman.h>
  118. +
  119. +enum { ColFg, ColBg, ColBorder }; /* colorscheme index */
  120. +
  121. +typedef struct fcft_font Fnt;
  122. +typedef pixman_image_t Img;
  123. +
  124. +typedef struct {
  125. + Img *image;
  126. + Fnt *font;
  127. + uint32_t *scheme;
  128. +} Drwl;
  129. +
  130. +#define UTF8_ACCEPT 0
  131. +#define UTF8_REJECT 12
  132. +#define UTF8_INVALID 0xFFFD
  133. +
  134. +static const uint8_t utf8d[] = {
  135. + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  136. + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  137. + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  138. + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  139. + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
  140. + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  141. + 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  142. + 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
  143. +
  144. + 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
  145. + 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
  146. + 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
  147. + 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
  148. + 12,36,12,12,12,12,12,12,12,12,12,12,
  149. +};
  150. +
  151. +static inline uint32_t
  152. +utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte)
  153. +{
  154. + uint32_t type = utf8d[byte];
  155. +
  156. + *codep = (*state != UTF8_ACCEPT) ?
  157. + (byte & 0x3fu) | (*codep << 6) :
  158. + (0xff >> type) & (byte);
  159. +
  160. + *state = utf8d[256 + *state + type];
  161. + return *state;
  162. +}
  163. +
  164. +static int
  165. +drwl_init(void)
  166. +{
  167. + fcft_set_scaling_filter(FCFT_SCALING_FILTER_LANCZOS3);
  168. + return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR);
  169. +}
  170. +
  171. +static Drwl *
  172. +drwl_create(void)
  173. +{
  174. + Drwl *drwl;
  175. +
  176. + if (!(drwl = calloc(1, sizeof(Drwl))))
  177. + return NULL;
  178. +
  179. + return drwl;
  180. +}
  181. +
  182. +static void
  183. +drwl_setfont(Drwl *drwl, Fnt *font)
  184. +{
  185. + if (drwl)
  186. + drwl->font = font;
  187. +}
  188. +
  189. +static void
  190. +drwl_setimage(Drwl *drwl, Img *image)
  191. +{
  192. + if (drwl)
  193. + drwl->image = image;
  194. +}
  195. +
  196. +static Fnt *
  197. +drwl_font_create(Drwl *drwl, size_t count,
  198. + const char *names[static count], const char *attributes)
  199. +{
  200. + Fnt *font = fcft_from_name(count, names, attributes);
  201. + if (drwl)
  202. + drwl_setfont(drwl, font);
  203. + return font;
  204. +}
  205. +
  206. +static void
  207. +drwl_font_destroy(Fnt *font)
  208. +{
  209. + fcft_destroy(font);
  210. +}
  211. +
  212. +static inline pixman_color_t
  213. +convert_color(uint32_t clr)
  214. +{
  215. + return (pixman_color_t){
  216. + ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
  217. + ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
  218. + ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
  219. + (clr & 0xFF) * 0x101
  220. + };
  221. +}
  222. +
  223. +static void
  224. +drwl_setscheme(Drwl *drwl, uint32_t *scm)
  225. +{
  226. + if (drwl)
  227. + drwl->scheme = scm;
  228. +}
  229. +
  230. +static Img *
  231. +drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits)
  232. +{
  233. + Img *image;
  234. + pixman_region32_t clip;
  235. +
  236. + image = pixman_image_create_bits_no_clear(
  237. + PIXMAN_a8r8g8b8, w, h, bits, w * 4);
  238. + if (!image)
  239. + return NULL;
  240. + pixman_region32_init_rect(&clip, 0, 0, w, h);
  241. + pixman_image_set_clip_region32(image, &clip);
  242. + pixman_region32_fini(&clip);
  243. +
  244. + if (drwl)
  245. + drwl_setimage(drwl, image);
  246. + return image;
  247. +}
  248. +
  249. +static void
  250. +drwl_rect(Drwl *drwl,
  251. + int x, int y, unsigned int w, unsigned int h,
  252. + int filled, int invert)
  253. +{
  254. + pixman_color_t clr;
  255. + if (!drwl || !drwl->scheme || !drwl->image)
  256. + return;
  257. +
  258. + clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
  259. + if (filled)
  260. + pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1,
  261. + &(pixman_rectangle16_t){x, y, w, h});
  262. + else
  263. + pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4,
  264. + (pixman_rectangle16_t[4]){
  265. + { x, y, w, 1 },
  266. + { x, y + h - 1, w, 1 },
  267. + { x, y, 1, h },
  268. + { x + w - 1, y, 1, h }});
  269. +}
  270. +
  271. +static int
  272. +drwl_text(Drwl *drwl,
  273. + int x, int y, unsigned int w, unsigned int h,
  274. + unsigned int lpad, const char *text, int invert)
  275. +{
  276. + int ty;
  277. + int render = x || y || w || h;
  278. + long x_kern;
  279. + uint32_t cp = 0, last_cp = 0, state;
  280. + pixman_color_t clr;
  281. + pixman_image_t *fg_pix = NULL;
  282. + int noellipsis = 0;
  283. + const struct fcft_glyph *glyph, *eg = NULL;
  284. + int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT;
  285. +
  286. + if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font)
  287. + return 0;
  288. +
  289. + if (!render) {
  290. + w = invert ? invert : ~invert;
  291. + } else {
  292. + clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
  293. + fg_pix = pixman_image_create_solid_fill(&clr);
  294. +
  295. + drwl_rect(drwl, x, y, w, h, 1, !invert);
  296. +
  297. + x += lpad;
  298. + w -= lpad;
  299. + }
  300. +
  301. + if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF)
  302. + fcft_subpixel_mode = FCFT_SUBPIXEL_NONE;
  303. +
  304. + if (render)
  305. + eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode);
  306. +
  307. + for (const char *p = text, *pp; pp = p, *p; p++) {
  308. + for (state = UTF8_ACCEPT; *p &&
  309. + utf8decode(&state, &cp, *p) > UTF8_REJECT; p++)
  310. + ;
  311. + if (!*p || state == UTF8_REJECT) {
  312. + cp = UTF8_INVALID;
  313. + if (p > pp)
  314. + p--;
  315. + }
  316. +
  317. + glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode);
  318. + if (!glyph)
  319. + continue;
  320. +
  321. + x_kern = 0;
  322. + if (last_cp)
  323. + fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL);
  324. + last_cp = cp;
  325. +
  326. + ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent;
  327. +
  328. + if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w &&
  329. + *(p + 1) != '\0') {
  330. + /* cannot fit ellipsis after current codepoint */
  331. + if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) {
  332. + noellipsis = 1;
  333. + } else {
  334. + w -= eg->advance.x;
  335. + pixman_image_composite32(
  336. + PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0,
  337. + x + eg->x, ty - eg->y, eg->width, eg->height);
  338. + }
  339. + }
  340. +
  341. + if ((x_kern + glyph->advance.x) > w)
  342. + break;
  343. +
  344. + x += x_kern;
  345. +
  346. + if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)
  347. + /* pre-rendered glyphs (eg. emoji) */
  348. + pixman_image_composite32(
  349. + PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0,
  350. + x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
  351. + else if (render)
  352. + pixman_image_composite32(
  353. + PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0,
  354. + x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
  355. +
  356. + x += glyph->advance.x;
  357. + w -= glyph->advance.x;
  358. + }
  359. +
  360. + if (render)
  361. + pixman_image_unref(fg_pix);
  362. +
  363. + return x + (render ? w : 0);
  364. +}
  365. +
  366. +static unsigned int
  367. +drwl_font_getwidth(Drwl *drwl, const char *text)
  368. +{
  369. + if (!drwl || !drwl->font || !text)
  370. + return 0;
  371. + return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0);
  372. +}
  373. +
  374. +static void
  375. +drwl_image_destroy(Img *image)
  376. +{
  377. + pixman_image_unref(image);
  378. +}
  379. +
  380. +static void
  381. +drwl_destroy(Drwl *drwl)
  382. +{
  383. + if (drwl->font)
  384. + drwl_font_destroy(drwl->font);
  385. + if (drwl->image)
  386. + drwl_image_destroy(drwl->image);
  387. + free(drwl);
  388. +}
  389. +
  390. +static void
  391. +drwl_fini(void)
  392. +{
  393. + fcft_fini();
  394. +}
  395. diff --git a/dwl.c b/dwl.c
  396. index 145fd01..ab1bc31 100644
  397. --- a/dwl.c
  398. +++ b/dwl.c
  399. @@ -5,6 +5,7 @@
  400. #include <libinput.h>
  401. #include <linux/input-event-codes.h>
  402. #include <math.h>
  403. +#include <libdrm/drm_fourcc.h>
  404. #include <signal.h>
  405. #include <stdio.h>
  406. #include <stdlib.h>
  407. @@ -57,6 +58,7 @@
  408. #include <wlr/types/wlr_xdg_decoration_v1.h>
  409. #include <wlr/types/wlr_xdg_output_v1.h>
  410. #include <wlr/types/wlr_xdg_shell.h>
  411. +#include <wlr/interfaces/wlr_buffer.h>
  412. #include <wlr/util/log.h>
  413. #include <wlr/util/region.h>
  414. #include <xkbcommon/xkbcommon.h>
  415. @@ -67,6 +69,7 @@
  416. #endif
  417. #include "util.h"
  418. +#include "drwl.h"
  419. /* macros */
  420. #define MAX(A, B) ((A) > (B) ? (A) : (B))
  421. @@ -75,14 +78,17 @@
  422. #define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
  423. #define LENGTH(X) (sizeof X / sizeof X[0])
  424. #define END(A) ((A) + LENGTH(A))
  425. -#define TAGMASK ((1u << TAGCOUNT) - 1)
  426. +#define TAGMASK ((1u << LENGTH(tags)) - 1)
  427. #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
  428. #define LISTEN_STATIC(E, H) do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
  429. +#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
  430. /* enums */
  431. +enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
  432. enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
  433. enum { XDGShell, LayerShell, X11 }; /* client types */
  434. enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
  435. +enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
  436. #ifdef XWAYLAND
  437. enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
  438. NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
  439. @@ -96,6 +102,7 @@ typedef union {
  440. } Arg;
  441. typedef struct {
  442. + unsigned int click;
  443. unsigned int mod;
  444. unsigned int button;
  445. void (*func)(const Arg *);
  446. @@ -185,10 +192,19 @@ typedef struct {
  447. void (*arrange)(Monitor *);
  448. } Layout;
  449. +typedef struct {
  450. + struct wlr_buffer base;
  451. + struct wl_listener release;
  452. + bool busy;
  453. + Img *image;
  454. + uint32_t data[];
  455. +} Buffer;
  456. +
  457. struct Monitor {
  458. struct wl_list link;
  459. struct wlr_output *wlr_output;
  460. struct wlr_scene_output *scene_output;
  461. + struct wlr_scene_buffer *scene_buffer; /* bar buffer */
  462. struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
  463. struct wl_listener frame;
  464. struct wl_listener destroy;
  465. @@ -196,6 +212,11 @@ struct Monitor {
  466. struct wl_listener destroy_lock_surface;
  467. struct wlr_session_lock_surface_v1 *lock_surface;
  468. struct wlr_box m; /* monitor area, layout-relative */
  469. + struct {
  470. + int width, height;
  471. + int real_width, real_height; /* non-scaled */
  472. + float scale;
  473. + } b; /* bar area */
  474. struct wlr_box w; /* window area, layout-relative */
  475. struct wl_list layers[4]; /* LayerSurface.link */
  476. const Layout *lt[2];
  477. @@ -207,6 +228,9 @@ struct Monitor {
  478. int nmaster;
  479. char ltsymbol[16];
  480. int asleep;
  481. + Drwl *drw;
  482. + Buffer *pool[2];
  483. + int lrpad;
  484. };
  485. typedef struct {
  486. @@ -249,6 +273,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
  487. struct wlr_box *usable_area, int exclusive);
  488. static void arrangelayers(Monitor *m);
  489. static void axisnotify(struct wl_listener *listener, void *data);
  490. +static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
  491. +static void bufdestroy(struct wlr_buffer *buffer);
  492. +static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
  493. + void **data, uint32_t *format, size_t *stride);
  494. +static void bufdataend(struct wlr_buffer *buffer);
  495. +static Buffer *bufmon(Monitor *m);
  496. +static void bufrelease(struct wl_listener *listener, void *data);
  497. static void buttonpress(struct wl_listener *listener, void *data);
  498. static void chvt(const Arg *arg);
  499. static void checkidleinhibitor(struct wlr_surface *exclude);
  500. @@ -282,6 +313,8 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
  501. static void destroysessionmgr(struct wl_listener *listener, void *data);
  502. static void destroykeyboardgroup(struct wl_listener *listener, void *data);
  503. static Monitor *dirtomon(enum wlr_direction dir);
  504. +static void drawbar(Monitor *m);
  505. +static void drawbars(void);
  506. static void focusclient(Client *c, int lift);
  507. static void focusmon(const Arg *arg);
  508. static void focusstack(const Arg *arg);
  509. @@ -309,7 +342,6 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
  510. static void outputmgrtest(struct wl_listener *listener, void *data);
  511. static void pointerfocus(Client *c, struct wlr_surface *surface,
  512. double sx, double sy, uint32_t time);
  513. -static void printstatus(void);
  514. static void powermgrsetmode(struct wl_listener *listener, void *data);
  515. static void quit(const Arg *arg);
  516. static void rendermon(struct wl_listener *listener, void *data);
  517. @@ -331,9 +363,11 @@ static void setsel(struct wl_listener *listener, void *data);
  518. static void setup(void);
  519. static void spawn(const Arg *arg);
  520. static void startdrag(struct wl_listener *listener, void *data);
  521. +static int statusin(int fd, unsigned int mask, void *data);
  522. static void tag(const Arg *arg);
  523. static void tagmon(const Arg *arg);
  524. static void tile(Monitor *m);
  525. +static void togglebar(const Arg *arg);
  526. static void togglefloating(const Arg *arg);
  527. static void togglefullscreen(const Arg *arg);
  528. static void toggletag(const Arg *arg);
  529. @@ -342,6 +376,7 @@ static void unlocksession(struct wl_listener *listener, void *data);
  530. static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
  531. static void unmapnotify(struct wl_listener *listener, void *data);
  532. static void updatemons(struct wl_listener *listener, void *data);
  533. +static void updatebar(Monitor *m);
  534. static void updatetitle(struct wl_listener *listener, void *data);
  535. static void urgent(struct wl_listener *listener, void *data);
  536. static void view(const Arg *arg);
  537. @@ -408,6 +443,15 @@ static struct wlr_box sgeom;
  538. static struct wl_list mons;
  539. static Monitor *selmon;
  540. +static char stext[256];
  541. +static struct wl_event_source *status_event_source;
  542. +
  543. +static const struct wlr_buffer_impl buffer_impl = {
  544. + .destroy = bufdestroy,
  545. + .begin_data_ptr_access = bufdatabegin,
  546. + .end_data_ptr_access = bufdataend,
  547. +};
  548. +
  549. #ifdef XWAYLAND
  550. static void activatex11(struct wl_listener *listener, void *data);
  551. static void associatex11(struct wl_listener *listener, void *data);
  552. @@ -548,6 +592,11 @@ arrangelayers(Monitor *m)
  553. if (!m->wlr_output->enabled)
  554. return;
  555. + if (m->scene_buffer->node.enabled) {
  556. + usable_area.height -= m->b.real_height;
  557. + usable_area.y += topbar ? m->b.real_height : 0;
  558. + }
  559. +
  560. /* Arrange exclusive surfaces from top->bottom */
  561. for (i = 3; i >= 0; i--)
  562. arrangelayer(m, &m->layers[i], &usable_area, 1);
  563. @@ -590,17 +639,102 @@ axisnotify(struct wl_listener *listener, void *data)
  564. event->delta_discrete, event->source);
  565. }
  566. +bool
  567. +baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
  568. +{
  569. + return true;
  570. +}
  571. +
  572. +void
  573. +bufdestroy(struct wlr_buffer *wlr_buffer)
  574. +{
  575. + Buffer *buf = wl_container_of(wlr_buffer, buf, base);
  576. + if (buf->busy)
  577. + wl_list_remove(&buf->release.link);
  578. + drwl_image_destroy(buf->image);
  579. + free(buf);
  580. +}
  581. +
  582. +bool
  583. +bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
  584. + void **data, uint32_t *format, size_t *stride)
  585. +{
  586. + Buffer *buf = wl_container_of(wlr_buffer, buf, base);
  587. +
  588. + if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
  589. +
  590. + *data = buf->data;
  591. + *stride = wlr_buffer->width * 4;
  592. + *format = DRM_FORMAT_ARGB8888;
  593. +
  594. + return true;
  595. +}
  596. +
  597. +void
  598. +bufdataend(struct wlr_buffer *wlr_buffer)
  599. +{
  600. +}
  601. +
  602. +Buffer *
  603. +bufmon(Monitor *m)
  604. +{
  605. + size_t i;
  606. + Buffer *buf = NULL;
  607. +
  608. + for (i = 0; i < LENGTH(m->pool); i++) {
  609. + if (m->pool[i]) {
  610. + if (m->pool[i]->busy)
  611. + continue;
  612. + buf = m->pool[i];
  613. + break;
  614. + }
  615. +
  616. + buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
  617. + buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
  618. + wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
  619. + m->pool[i] = buf;
  620. + break;
  621. + }
  622. + if (!buf)
  623. + return NULL;
  624. +
  625. + buf->busy = true;
  626. + LISTEN(&buf->base.events.release, &buf->release, bufrelease);
  627. + wlr_buffer_lock(&buf->base);
  628. + drwl_setimage(m->drw, buf->image);
  629. + return buf;
  630. +}
  631. +
  632. +void
  633. +bufrelease(struct wl_listener *listener, void *data)
  634. +{
  635. + Buffer *buf = wl_container_of(listener, buf, release);
  636. + buf->busy = false;
  637. + wl_list_remove(&buf->release.link);
  638. +}
  639. +
  640. void
  641. buttonpress(struct wl_listener *listener, void *data)
  642. {
  643. + unsigned int i = 0, x = 0;
  644. + double cx;
  645. + unsigned int click;
  646. struct wlr_pointer_button_event *event = data;
  647. struct wlr_keyboard *keyboard;
  648. + struct wlr_scene_node *node;
  649. + struct wlr_scene_buffer *buffer;
  650. uint32_t mods;
  651. + Arg arg = {0};
  652. Client *c;
  653. const Button *b;
  654. wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
  655. + click = ClkRoot;
  656. + xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
  657. + if (c)
  658. + click = ClkClient;
  659. +
  660. switch (event->state) {
  661. case WLR_BUTTON_PRESSED:
  662. cursor_mode = CurPressed;
  663. @@ -608,17 +742,34 @@ buttonpress(struct wl_listener *listener, void *data)
  664. if (locked)
  665. break;
  666. + if (!c && !exclusive_focus &&
  667. + (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
  668. + (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
  669. + cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
  670. + do
  671. + x += TEXTW(selmon, tags[i]);
  672. + while (cx >= x && ++i < LENGTH(tags));
  673. + if (i < LENGTH(tags)) {
  674. + click = ClkTagBar;
  675. + arg.ui = 1 << i;
  676. + } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
  677. + click = ClkLtSymbol;
  678. + else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
  679. + click = ClkStatus;
  680. + } else
  681. + click = ClkTitle;
  682. + }
  683. +
  684. /* Change focus if the button was _pressed_ over a client */
  685. xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
  686. - if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
  687. + if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
  688. focusclient(c, 1);
  689. keyboard = wlr_seat_get_keyboard(seat);
  690. mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
  691. for (b = buttons; b < END(buttons); b++) {
  692. - if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
  693. - event->button == b->button && b->func) {
  694. - b->func(&b->arg);
  695. + if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
  696. + b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
  697. return;
  698. }
  699. }
  700. @@ -689,6 +840,8 @@ cleanup(void)
  701. /* Destroy after the wayland display (when the monitors are already destroyed)
  702. to avoid destroying them with an invalid scene output. */
  703. wlr_scene_node_destroy(&scene->tree.node);
  704. +
  705. + drwl_fini();
  706. }
  707. void
  708. @@ -704,6 +857,12 @@ cleanupmon(struct wl_listener *listener, void *data)
  709. wlr_layer_surface_v1_destroy(l->layer_surface);
  710. }
  711. + for (i = 0; i < LENGTH(m->pool); i++)
  712. + wlr_buffer_drop(&m->pool[i]->base);
  713. +
  714. + drwl_setimage(m->drw, NULL);
  715. + drwl_destroy(m->drw);
  716. +
  717. wl_list_remove(&m->destroy.link);
  718. wl_list_remove(&m->frame.link);
  719. wl_list_remove(&m->link);
  720. @@ -714,6 +873,7 @@ cleanupmon(struct wl_listener *listener, void *data)
  721. closemon(m);
  722. wlr_scene_node_destroy(&m->fullscreen_bg->node);
  723. + wlr_scene_node_destroy(&m->scene_buffer->node);
  724. free(m);
  725. }
  726. @@ -743,7 +903,7 @@ closemon(Monitor *m)
  727. setmon(c, selmon, c->tags);
  728. }
  729. focusclient(focustop(selmon), 1);
  730. - printstatus();
  731. + drawbars();
  732. }
  733. void
  734. @@ -980,8 +1140,15 @@ createmon(struct wl_listener *listener, void *data)
  735. wlr_output_commit_state(wlr_output, &state);
  736. wlr_output_state_finish(&state);
  737. + if (!(m->drw = drwl_create()))
  738. + die("failed to create drwl context");
  739. +
  740. + m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
  741. + m->scene_buffer->point_accepts_input = baracceptsinput;
  742. + updatebar(m);
  743. +
  744. wl_list_insert(&mons, &m->link);
  745. - printstatus();
  746. + drawbars();
  747. /* The xdg-protocol specifies:
  748. *
  749. @@ -1312,6 +1479,80 @@ dirtomon(enum wlr_direction dir)
  750. return selmon;
  751. }
  752. +void
  753. +drawbar(Monitor *m)
  754. +{
  755. + int x, w, tw = 0;
  756. + int boxs = m->drw->font->height / 9;
  757. + int boxw = m->drw->font->height / 6 + 2;
  758. + uint32_t i, occ = 0, urg = 0;
  759. + Client *c;
  760. + Buffer *buf;
  761. +
  762. + if (!m->scene_buffer->node.enabled)
  763. + return;
  764. + if (!(buf = bufmon(m)))
  765. + return;
  766. +
  767. + /* draw status first so it can be overdrawn by tags later */
  768. + if (m == selmon) { /* status is only drawn on selected monitor */
  769. + drwl_setscheme(m->drw, colors[SchemeNorm]);
  770. + tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
  771. + drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
  772. + }
  773. +
  774. + wl_list_for_each(c, &clients, link) {
  775. + if (c->mon != m)
  776. + continue;
  777. + occ |= c->tags;
  778. + if (c->isurgent)
  779. + urg |= c->tags;
  780. + }
  781. + x = 0;
  782. + c = focustop(m);
  783. + for (i = 0; i < LENGTH(tags); i++) {
  784. + w = TEXTW(m, tags[i]);
  785. + drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
  786. + drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
  787. + if (occ & 1 << i)
  788. + drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
  789. + m == selmon && c && c->tags & 1 << i,
  790. + urg & 1 << i);
  791. + x += w;
  792. + }
  793. + w = TEXTW(m, m->ltsymbol);
  794. + drwl_setscheme(m->drw, colors[SchemeNorm]);
  795. + x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
  796. +
  797. + if ((w = m->b.width - tw - x) > m->b.height) {
  798. + if (c) {
  799. + drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
  800. + drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
  801. + if (c && c->isfloating)
  802. + drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
  803. + } else {
  804. + drwl_setscheme(m->drw, colors[SchemeNorm]);
  805. + drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
  806. + }
  807. + }
  808. +
  809. + wlr_scene_buffer_set_dest_size(m->scene_buffer,
  810. + m->b.real_width, m->b.real_height);
  811. + wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
  812. + m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
  813. + wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
  814. + wlr_buffer_unlock(&buf->base);
  815. +}
  816. +
  817. +void
  818. +drawbars(void)
  819. +{
  820. + Monitor *m = NULL;
  821. +
  822. + wl_list_for_each(m, &mons, link)
  823. + drawbar(m);
  824. +}
  825. +
  826. void
  827. focusclient(Client *c, int lift)
  828. {
  829. @@ -1347,13 +1588,13 @@ focusclient(Client *c, int lift)
  830. /* Don't change border color if there is an exclusive focus or we are
  831. * handling a drag operation */
  832. if (!exclusive_focus && !seat->drag)
  833. - client_set_border_color(c, focuscolor);
  834. + client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
  835. }
  836. /* Deactivate old client if focus is changing */
  837. if (old && (!c || client_surface(c) != old)) {
  838. /* If an overlay is focused, don't focus or activate the client,
  839. - * but only update its position in fstack to render its border with focuscolor
  840. + * but only update its position in fstack to render its border with its color
  841. * and focus it after the overlay is closed. */
  842. if (old_client_type == LayerShell && wlr_scene_node_coords(
  843. &old_l->scene->node, &unused_lx, &unused_ly)
  844. @@ -1364,12 +1605,11 @@ focusclient(Client *c, int lift)
  845. /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
  846. * and probably other clients */
  847. } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
  848. - client_set_border_color(old_c, bordercolor);
  849. -
  850. + client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
  851. client_activate_surface(old, 0);
  852. }
  853. }
  854. - printstatus();
  855. + drawbars();
  856. if (!c) {
  857. /* With no client, all we have left is to clear focus */
  858. @@ -1666,7 +1906,7 @@ mapnotify(struct wl_listener *listener, void *data)
  859. for (i = 0; i < 4; i++) {
  860. c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
  861. - c->isurgent ? urgentcolor : bordercolor);
  862. + (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
  863. c->border[i]->node.data = c;
  864. }
  865. @@ -1689,7 +1929,7 @@ mapnotify(struct wl_listener *listener, void *data)
  866. } else {
  867. applyrules(c);
  868. }
  869. - printstatus();
  870. + drawbars();
  871. unset_fullscreen:
  872. m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
  873. @@ -1982,46 +2222,6 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
  874. wlr_seat_pointer_notify_motion(seat, time, sx, sy);
  875. }
  876. -void
  877. -printstatus(void)
  878. -{
  879. - Monitor *m = NULL;
  880. - Client *c;
  881. - uint32_t occ, urg, sel;
  882. - const char *appid, *title;
  883. -
  884. - wl_list_for_each(m, &mons, link) {
  885. - occ = urg = 0;
  886. - wl_list_for_each(c, &clients, link) {
  887. - if (c->mon != m)
  888. - continue;
  889. - occ |= c->tags;
  890. - if (c->isurgent)
  891. - urg |= c->tags;
  892. - }
  893. - if ((c = focustop(m))) {
  894. - title = client_get_title(c);
  895. - appid = client_get_appid(c);
  896. - printf("%s title %s\n", m->wlr_output->name, title ? title : broken);
  897. - printf("%s appid %s\n", m->wlr_output->name, appid ? appid : broken);
  898. - printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
  899. - printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
  900. - sel = c->tags;
  901. - } else {
  902. - printf("%s title \n", m->wlr_output->name);
  903. - printf("%s appid \n", m->wlr_output->name);
  904. - printf("%s fullscreen \n", m->wlr_output->name);
  905. - printf("%s floating \n", m->wlr_output->name);
  906. - sel = 0;
  907. - }
  908. -
  909. - printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
  910. - printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
  911. - m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
  912. - printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
  913. - }
  914. - fflush(stdout);
  915. -}
  916. void
  917. powermgrsetmode(struct wl_listener *listener, void *data)
  918. @@ -2175,30 +2375,17 @@ run(char *startup_cmd)
  919. /* Now that the socket exists and the backend is started, run the startup command */
  920. if (startup_cmd) {
  921. - int piperw[2];
  922. - if (pipe(piperw) < 0)
  923. - die("startup: pipe:");
  924. if ((child_pid = fork()) < 0)
  925. die("startup: fork:");
  926. if (child_pid == 0) {
  927. + close(STDIN_FILENO);
  928. setsid();
  929. - dup2(piperw[0], STDIN_FILENO);
  930. - close(piperw[0]);
  931. - close(piperw[1]);
  932. execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
  933. die("startup: execl:");
  934. }
  935. - dup2(piperw[1], STDOUT_FILENO);
  936. - close(piperw[1]);
  937. - close(piperw[0]);
  938. }
  939. - /* Mark stdout as non-blocking to avoid people who does not close stdin
  940. - * nor consumes it in their startup script getting dwl frozen */
  941. - if (fd_set_nonblock(STDOUT_FILENO) < 0)
  942. - close(STDOUT_FILENO);
  943. -
  944. - printstatus();
  945. + drawbars();
  946. /* At this point the outputs are initialized, choose initial selmon based on
  947. * cursor position, and set default cursor image */
  948. @@ -2262,7 +2449,7 @@ setfloating(Client *c, int floating)
  949. wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen
  950. ? LyrFS : c->isfloating ? LyrFloat : LyrTile]);
  951. arrange(c->mon);
  952. - printstatus();
  953. + drawbars();
  954. }
  955. void
  956. @@ -2285,7 +2472,7 @@ setfullscreen(Client *c, int fullscreen)
  957. resize(c, c->prev, 0);
  958. }
  959. arrange(c->mon);
  960. - printstatus();
  961. + drawbars();
  962. }
  963. void
  964. @@ -2310,7 +2497,7 @@ setlayout(const Arg *arg)
  965. selmon->lt[selmon->sellt] = (Layout *)arg->v;
  966. strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
  967. arrange(selmon);
  968. - printstatus();
  969. + drawbar(selmon);
  970. }
  971. /* arg > 1.0 will set mfact absolutely */
  972. @@ -2383,6 +2570,7 @@ setup(void)
  973. for (i = 0; i < (int)LENGTH(sig); i++)
  974. sigaction(sig[i], &sa, NULL);
  975. +
  976. wlr_log_init(log_level, NULL);
  977. /* The Wayland display is managed by libwayland. It handles accepting
  978. @@ -2569,6 +2757,11 @@ setup(void)
  979. wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
  980. + drwl_init();
  981. +
  982. + status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
  983. + STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
  984. +
  985. /* Make sure XWayland clients don't connect to the parent X server,
  986. * e.g when running in the x11 backend or the wayland backend and the
  987. * compositor has Xwayland support */
  988. @@ -2593,6 +2786,7 @@ void
  989. spawn(const Arg *arg)
  990. {
  991. if (fork() == 0) {
  992. + close(STDIN_FILENO);
  993. dup2(STDERR_FILENO, STDOUT_FILENO);
  994. setsid();
  995. execvp(((char **)arg->v)[0], (char **)arg->v);
  996. @@ -2611,6 +2805,30 @@ startdrag(struct wl_listener *listener, void *data)
  997. LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
  998. }
  999. +int
  1000. +statusin(int fd, unsigned int mask, void *data)
  1001. +{
  1002. + char status[1024];
  1003. + ssize_t n;
  1004. +
  1005. + if (mask & WL_EVENT_ERROR)
  1006. + die("status in event error");
  1007. + if (mask & WL_EVENT_HANGUP)
  1008. + wl_event_source_remove(status_event_source);
  1009. +
  1010. + n = read(fd, status, sizeof(status) - 1);
  1011. + if (n < 0 && errno != EWOULDBLOCK)
  1012. + die("read:");
  1013. +
  1014. + status[n] = '\0';
  1015. + status[strcspn(status, "\n")] = '\0';
  1016. +
  1017. + strncpy(stext, status, sizeof(stext));
  1018. + drawbars();
  1019. +
  1020. + return 0;
  1021. +}
  1022. +
  1023. void
  1024. tag(const Arg *arg)
  1025. {
  1026. @@ -2621,7 +2839,7 @@ tag(const Arg *arg)
  1027. sel->tags = arg->ui & TAGMASK;
  1028. focusclient(focustop(selmon), 1);
  1029. arrange(selmon);
  1030. - printstatus();
  1031. + drawbars();
  1032. }
  1033. void
  1034. @@ -2666,6 +2884,14 @@ tile(Monitor *m)
  1035. }
  1036. }
  1037. +void
  1038. +togglebar(const Arg *arg)
  1039. +{
  1040. + wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
  1041. + !selmon->scene_buffer->node.enabled);
  1042. + arrangelayers(selmon);
  1043. +}
  1044. +
  1045. void
  1046. togglefloating(const Arg *arg)
  1047. {
  1048. @@ -2694,7 +2920,7 @@ toggletag(const Arg *arg)
  1049. sel->tags = newtags;
  1050. focusclient(focustop(selmon), 1);
  1051. arrange(selmon);
  1052. - printstatus();
  1053. + drawbars();
  1054. }
  1055. void
  1056. @@ -2707,7 +2933,7 @@ toggleview(const Arg *arg)
  1057. selmon->tagset[selmon->seltags] = newtagset;
  1058. focusclient(focustop(selmon), 1);
  1059. arrange(selmon);
  1060. - printstatus();
  1061. + drawbars();
  1062. }
  1063. void
  1064. @@ -2755,7 +2981,7 @@ unmapnotify(struct wl_listener *listener, void *data)
  1065. }
  1066. wlr_scene_node_destroy(&c->scene->node);
  1067. - printstatus();
  1068. + drawbars();
  1069. motionnotify(0, NULL, 0, 0, 0, 0);
  1070. }
  1071. @@ -2855,6 +3081,13 @@ updatemons(struct wl_listener *listener, void *data)
  1072. }
  1073. }
  1074. + if (stext[0] == '\0')
  1075. + strncpy(stext, "dwl-"VERSION, sizeof(stext));
  1076. + wl_list_for_each(m, &mons, link) {
  1077. + updatebar(m);
  1078. + drawbar(m);
  1079. + }
  1080. +
  1081. /* FIXME: figure out why the cursor image is at 0,0 after turning all
  1082. * the monitors on.
  1083. * Move the cursor image where it used to be. It does not generate a
  1084. @@ -2865,12 +3098,45 @@ updatemons(struct wl_listener *listener, void *data)
  1085. wlr_output_manager_v1_set_configuration(output_mgr, config);
  1086. }
  1087. +void
  1088. +updatebar(Monitor *m)
  1089. +{
  1090. + size_t i;
  1091. + int rw, rh;
  1092. + char fontattrs[12];
  1093. +
  1094. + wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
  1095. + m->b.width = rw;
  1096. + m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
  1097. +
  1098. + wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
  1099. +
  1100. + for (i = 0; i < LENGTH(m->pool); i++)
  1101. + if (m->pool[i]) {
  1102. + wlr_buffer_drop(&m->pool[i]->base);
  1103. + m->pool[i] = NULL;
  1104. + }
  1105. +
  1106. + if (m->b.scale == m->wlr_output->scale && m->drw)
  1107. + return;
  1108. +
  1109. + drwl_font_destroy(m->drw->font);
  1110. + snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
  1111. + if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
  1112. + die("Could not load font");
  1113. +
  1114. + m->b.scale = m->wlr_output->scale;
  1115. + m->lrpad = m->drw->font->height;
  1116. + m->b.height = m->drw->font->height + 2;
  1117. + m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
  1118. +}
  1119. +
  1120. void
  1121. updatetitle(struct wl_listener *listener, void *data)
  1122. {
  1123. Client *c = wl_container_of(listener, c, set_title);
  1124. if (c == focustop(c->mon))
  1125. - printstatus();
  1126. + drawbars();
  1127. }
  1128. void
  1129. @@ -2883,10 +3149,10 @@ urgent(struct wl_listener *listener, void *data)
  1130. return;
  1131. c->isurgent = 1;
  1132. - printstatus();
  1133. + drawbars();
  1134. if (client_surface(c)->mapped)
  1135. - client_set_border_color(c, urgentcolor);
  1136. + client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
  1137. }
  1138. void
  1139. @@ -2899,7 +3165,7 @@ view(const Arg *arg)
  1140. selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
  1141. focusclient(focustop(selmon), 1);
  1142. arrange(selmon);
  1143. - printstatus();
  1144. + drawbars();
  1145. }
  1146. void
  1147. @@ -2940,6 +3206,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
  1148. {
  1149. struct wlr_scene_node *node, *pnode;
  1150. struct wlr_surface *surface = NULL;
  1151. + struct wlr_scene_surface *scene_surface = NULL;
  1152. Client *c = NULL;
  1153. LayerSurface *l = NULL;
  1154. int layer;
  1155. @@ -2948,9 +3215,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
  1156. if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
  1157. continue;
  1158. - if (node->type == WLR_SCENE_NODE_BUFFER)
  1159. - surface = wlr_scene_surface_try_from_buffer(
  1160. - wlr_scene_buffer_from_node(node))->surface;
  1161. + if (node->type == WLR_SCENE_NODE_BUFFER) {
  1162. + scene_surface = wlr_scene_surface_try_from_buffer(
  1163. + wlr_scene_buffer_from_node(node));
  1164. + if (!scene_surface) continue;
  1165. + surface = scene_surface->surface;
  1166. + }
  1167. /* Walk the tree to find a node that knows the client */
  1168. for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
  1169. c = pnode->data;
  1170. @@ -3089,10 +3359,10 @@ sethints(struct wl_listener *listener, void *data)
  1171. return;
  1172. c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
  1173. - printstatus();
  1174. + drawbars();
  1175. if (c->isurgent && surface && surface->mapped)
  1176. - client_set_border_color(c, urgentcolor);
  1177. + client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
  1178. }
  1179. void
  1180. --
  1181. 2.46.0