summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md218
-rw-r--r--config.def.h166
-rw-r--r--config.mk8
-rw-r--r--drwl.h310
-rw-r--r--dwl.c584
-rw-r--r--patches/bar/README.md34
-rw-r--r--patches/bar/bar-0.6.patch1245
-rw-r--r--patches/bar/bar-0.7.patch1245
-rw-r--r--patches/bar/bar.patch1271
-rw-r--r--patches/bar/bar.pngbin0 -> 3486 bytes
-rw-r--r--patches/client-opacity-focus/README.md20
-rw-r--r--patches/client-opacity-focus/client-opacity-focus.dwl.patch156
-rw-r--r--patches/client-opacity-focus/client-opacity-focus.patch202
-rw-r--r--patches/gaps/README.md14
-rw-r--r--patches/gaps/gaps.patch127
-rw-r--r--patches/movestack/README.md13
-rw-r--r--patches/movestack/movestack-0.7.patch87
-rw-r--r--patches/movestack/movestack-0.8.patch87
-rw-r--r--patches/shiftview/README.md9
-rw-r--r--patches/shiftview/shiftview.patch76
-rw-r--r--shiftview.c30
22 files changed, 5546 insertions, 358 deletions
diff --git a/Makefile b/Makefile
index 578194f..279b1c0 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -Wpedantic -Wall -Wextra -Wdeclaration-after-statement \
-Wfloat-conversion
# CFLAGS / LDFLAGS
-PKGS = wayland-server xkbcommon libinput $(XLIBS)
+PKGS = wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS)
DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(WLR_INCS) $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(WLR_LIBS) -lm $(LIBS)
diff --git a/README.md b/README.md
index 38211c4..07adaf3 100644
--- a/README.md
+++ b/README.md
@@ -1,219 +1,3 @@
# dwl - dwm for Wayland
-2025-08-16:
-dwl IS CURRENTLY UN-MAINTAINED.
-AT THE PRESENT TIME, I (@fauxmight) DO NOT HAVE
-THE TIME OR CAPACITY TO KEEP UP WITH [wlroots] CHANGES.
-IF YOU ARE INTERESTED IN TAKING ON LEAD DEVELOPER RESPONSIBILITIES,
-SEE ISSUE [#1166](https://codeberg.org/dwl/dwl/issues/1166).
----
-
-Join us on our IRC channel: [#dwl on Libera Chat]
-Or on the community-maintained [Discord server].
-
-dwl is a compact, hackable compositor for [Wayland] based on [wlroots]. It is
-intended to fill the same space in the Wayland world that [dwm] does in X11,
-primarily in terms of functionality, and secondarily in terms of
-philosophy. Like [dwm], dwl is:
-
-- Easy to understand, hack on, and extend with patches
-- One C source file (or a very small number) configurable via `config.h`
-- Tied to as few external dependencies as possible
-
-## Getting Started:
-
-### Latest semi-stable [release]
-This is probably where you want to start. This builds against the [wlroots]
-versions currently shipping in major distributions. If your
-distribution's `wlroots` version is older, use an earlier dwl [release].
-The `wlroots` version against which a given `dwl` release builds is specified
-with each release on the [release] page
-
-### Development branch [main]
-Active development progresses on the `main` branch. The `main` branch is built
-against a late (and often changing) git commit of wlroots. While the adventurous
-are welcome to use `main`, it is a rocky road. Using `main` requires that the
-user be willing to chase git commits of wlroots. Testing development pull
-requests may involve merging unmerged pull requests in [wlroots]' git repository
-and/or git commits of wayland.
-
-### Building dwl
-dwl has the following dependencies:
-- libinput
-- wayland
-- wlroots (compiled with the libinput backend)
-- xkbcommon
-- wayland-protocols (compile-time only)
-- pkg-config (compile-time only)
-
-dwl has the following additional dependencies if XWayland support is enabled:
-- libxcb
-- libxcb-wm
-- wlroots (compiled with X11 support)
-- Xwayland (runtime only)
-
-Install these (and their `-devel` versions if your distro has separate
-development packages) and run `make`. If you wish to build against a released
-version of wlroots (*you probably do*), use a [release] or a [0.x branch]. If
-you want to use the unstable development `main` branch, you need to use the git
-version of [wlroots].
-
-To enable XWayland, you should uncomment its flags in `config.mk`.
-
-## Configuration
-
-All configuration is done by editing `config.h` and recompiling, in the same
-manner as [dwm]. There is no way to separately restart the window manager in
-Wayland without restarting the entire display server, so any changes will take
-effect the next time dwl is executed.
-
-As in the [dwm] community, we encourage users to share patches they have
-created. Check out the [dwl-patches] repository!
-
-## Running dwl
-
-dwl can be run on any of the backends supported by wlroots. This means you can
-run it as a separate window inside either an X11 or Wayland session, as well as
-directly from a VT console. Depending on your distro's setup, you may need to
-add your user to the `video` and `input` groups before you can run dwl on a
-VT. If you are using `elogind` or `systemd-logind` you need to install polkit;
-otherwise you need to add yourself in the `seat` group and enable/start the
-seatd daemon.
-
-When dwl is run with no arguments, it will launch the server and begin handling
-any shortcuts configured in `config.h`. There is no status bar or other
-decoration initially; these are instead clients that can be run within the
-Wayland session. Do note that the default background color is grey. This can be
-modified in `config.h`.
-
-If you would like to run a script or command automatically at startup, you can
-specify the command using the `-s` option. This command will be executed as a
-shell command using `/bin/sh -c`. It serves a similar function to `.xinitrc`,
-but differs in that the display server will not shut down when this process
-terminates. Instead, dwl will send this process a SIGTERM at shutdown and wait
-for it to terminate (if it hasn't already). This makes it ideal for execing into
-a user service manager like [s6], [anopa], [runit], [dinit], or [`systemd
---user`].
-
-Note: The `-s` command is run as a *child process* of dwl, which means that it
-does not have the ability to affect the environment of dwl or of any processes
-that it spawns. If you need to set environment variables that affect the entire
-dwl session, these must be set prior to running dwl. For example, Wayland
-requires a valid `XDG_RUNTIME_DIR`, which is usually set up by a session manager
-such as `elogind` or `systemd-logind`. If your system doesn't do this
-automatically, you will need to configure it prior to launching `dwl`, e.g.:
-
- export XDG_RUNTIME_DIR=/tmp/xdg-runtime-$(id -u)
- mkdir -p $XDG_RUNTIME_DIR
- dwl
-
-### Status information
-
-Information about selected layouts, current window title, app-id, and
-selected/occupied/urgent tags is written to the stdin of the `-s` command (see
-the `STATUS INFORMATION` section in `_dwl_(1)`). This information can be used to
-populate an external status bar with a script that parses the
-information. Failing to read this information will cause dwl to block, so if you
-do want to run a startup command that does not consume the status information,
-you can close standard input with the `<&-` shell redirection, for example:
-
- dwl -s 'foot --server <&-'
-
-If your startup command is a shell script, you can achieve the same inside the
-script with the line
-
- exec <&-
-
-To get a list of status bars that work with dwl consult our [wiki].
-
-### (Known) Java nonreparenting WM issue
-Certain IDEs don't display correctly unless an environmental variable for Java AWT
-indicates that the WM is nonreparenting.
-
-For some Java AWT-based IDEs, such as Xilinx Vivado and Microchip MPLAB X, the
-following environment variable needs to be set before running the IDE or dwl:
-
- export _JAVA_AWT_WM_NONREPARENTING=1
-
-## Replacements for X applications
-
-You can find a [list of useful resources on our wiki].
-
-## Background
-
-dwl is not meant to provide every feature under the sun. Instead, like [dwm], it
-sticks to features which are necessary, simple, and straightforward to implement
-given the base on which it is built. Implemented default features are:
-
-- Any features provided by [dwm]/Xlib: simple window borders, tags, keybindings,
- client rules, mouse move/resize. Providing a built-in status bar is an
- exception to this goal, to avoid dependencies on font rendering and/or drawing
- libraries when an external bar could work well.
-- Configurable multi-monitor layout support, including position and rotation
-- Configurable HiDPI/multi-DPI support
-- Idle-inhibit protocol which lets applications such as mpv disable idle
- monitoring
-- Provide information to external status bars via stdout/stdin
-- Urgency hints via xdg-activate protocol
-- Support screen lockers via ext-session-lock-v1 protocol
-- Various Wayland protocols
-- XWayland support as provided by wlroots (can be enabled in `config.mk`)
-- Zero flickering - Wayland users naturally expect that "every frame is perfect"
-- Layer shell popups (used by Waybar)
-- Damage tracking provided by scenegraph API
-
-Given the Wayland architecture, dwl has to implement features from [dwm] **and**
-the xorg-server. Because of this, it is impossible to maintain the original
-project goal of 2000 SLOC and have a reasonably complete compositor with
-features comparable to [dwm]. However, this does not mean that the code will grow
-indiscriminately. We will try to keep the code as small as possible.
-
-Features under consideration (possibly as patches) are:
-
-- Protocols made trivial by wlroots
-- Implement the text-input and input-method protocols to support IME once ibus
- implements input-method v2 (see https://github.com/ibus/ibus/pull/2256 and
- https://codeberg.org/dwl/dwl/pulls/235)
-
-Feature *non-goals* for the main codebase include:
-
-- Client-side decoration (any more than is necessary to tell the clients not to)
-- Client-initiated window management, such as move, resize, and close, which can
- be done through the compositor
-- Animations and visual effects
-
-## Acknowledgements
-
-dwl began by extending the TinyWL example provided (CC0) by the sway/wlroots
-developers. This was made possible in many cases by looking at how sway
-accomplished something, then trying to do the same in as suckless a way as
-possible.
-
-Many thanks to suckless.org and the [dwm] developers and community for the
-inspiration, and to the various contributors to the project, including:
-
-- **Devin J. Pohly for creating and nurturing the fledgling project**
-- Alexander Courtis for the XWayland implementation
-- Guido Cella for the layer-shell protocol implementation, patch maintenance,
- and for helping to keep the project running
-- Stivvo for output management and fullscreen support, and patch maintenance
-
-
-[wlroots]: https://gitlab.freedesktop.org/wlroots
-[dwm]: https://dwm.suckless.org/
-[`systemd --user`]: https://wiki.archlinux.org/title/Systemd/User
-[#dwl on Libera Chat]: https://web.libera.chat/?channels=#dwl
-[0.7-rc1]: https://codeberg.org/dwl/dwl/releases/tag/v0.7-rc1
-[0.x branch]: https://codeberg.org/dwl/dwl/branches
-[anopa]: https://jjacky.com/anopa/
-[dinit]: https://davmac.org/projects/dinit/
-[dwl-patches]: https://codeberg.org/dwl/dwl-patches
-[list of useful resources on our wiki]: https://codeberg.org/dwl/dwl/wiki/Home#migrating-from-x
-[main]: https://codeberg.org/dwl/dwl/src/branch/main
-[release]: https://codeberg.org/dwl/dwl/releases
-[runit]: http://smarden.org/runit/faq.html#userservices
-[s6]: https://skarnet.org/software/s6/
-[wlroots]: https://gitlab.freedesktop.org/wlroots/wlroots/
-[wiki]: https://codeberg.org/dwl/dwl/wiki/Home#compatible-status-bars
-[Discord server]: https://discord.gg/jJxZnrGPWN
-[Wayland]: https://wayland.freedesktop.org/
+Fork of [dwl](https://codeberg.org/dwl/dwl)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..0a09255 100644
--- a/config.def.h
+++ b/config.def.h
@@ -6,25 +6,51 @@
/* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
-static const unsigned int borderpx = 1; /* border pixel of windows */
-static const float rootcolor[] = COLOR(0x222222ff);
+static const unsigned int borderpx = 0; /* border pixel of windows */
+static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */
+static int gaps = 1; /* 1 means gaps between windows are added */
+static const unsigned int gappx = 10; /* gap pixel between windows */
+//static const float rootcolor[] = COLOR(0x222222ff);
+static const float rootcolor[] = COLOR(0x000000ff); // from bar patch?
static const float bordercolor[] = COLOR(0x444444ff);
static const float focuscolor[] = COLOR(0x005577ff);
static const float urgentcolor[] = COLOR(0xff0000ff);
/* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */
+static const float default_opacity_unfocus = 0.80f;
+static const float default_opacity_focus = 1.00f;
+// from bar patch
+static const int showbar = 1; /* 0 means no bar */
+static const int topbar = 1; /* 0 means bottom bar */
+static const char *fonts[] = {"Maple Mono NL:size=12"};
+static uint32_t colors[][3] = {
+ /* fg bg border */
+ [SchemeNorm] = { 0xaebbccff, 0x00000000, 0x00000000 },
+ [SchemeSel] = { 0xb1c855ff, 0x52453590, 0x00000000 },
+ [SchemeUrg] = { 0, 0, 0x00000000 },
+};
+
+/* tagging */
+static char *tags[] = { "🌎", "🍁", "🍂", "⛵", "𝄇" };
+#define TAGCOUNT (sizeof(tags) / sizeof(tags[0]))
-/* tagging - TAGCOUNT must be no greater than 31 */
-#define TAGCOUNT (9)
/* logging */
static int log_level = WLR_ERROR;
static const Rule rules[] = {
- /* app_id title tags mask isfloating monitor */
- { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
- { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
- /* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */
+ /* app_id title tags mask isfloating monitor */
+// { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
+// { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
+// { "Gimp_EXAMPLE", NULL, 0, 1, 1.00, 0.20, -1 }, /* Start on currently visible tags floating, not tiled */
+// { "firefox_EXAMPLE", NULL, 1 << 8, 0, 1.00, 1.00, -1 }, /* Start on ONLY tag "9" */
+ /* app_id title tags mask isfloating alpha focus alpha unfocus monitor */
+ { "Gimp", NULL, 0, 1, default_opacity_focus, default_opacity_unfocus, -1 },
+ { "mpv", NULL, 0, 1, 1, 1, -1 },
+ { "librewolf", NULL, 1, 0, default_opacity_focus, default_opacity_unfocus, -1 },
+ { "Thunderbird",NULL, 1 << 1, 0, default_opacity_focus, default_opacity_unfocus, 0 },
+ { "pwvucontrol",NULL, 1 << 4, 0, 1, 1, 0 },
+ /* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */
};
/* layout(s) */
@@ -53,11 +79,13 @@ static const struct xkb_rule_names xkb_rules = {
/* example:
.options = "ctrl:nocaps",
*/
- .options = NULL,
+ // set capslock to escape
+ // maybe can repurpose windows key here too ...
+ .options = "caps:escape",
};
static const int repeat_rate = 25;
-static const int repeat_delay = 600;
+static const int repeat_delay = 300;
/* Trackpad */
static const int tap_to_click = 1;
@@ -116,44 +144,80 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
/* commands */
static const char *termcmd[] = { "foot", NULL };
-static const char *menucmd[] = { "wmenu-run", NULL };
+static const char *menucmd[] = {
+ "wmenu-run",
+ "-i",
+ "-f", "Maple Mono NL 12",
+ "-m", "aebbccff",
+ "-M", "6d792dff",
+ "-n", "b1c855ff",
+ "-N", "524535ff",
+ "-s", "aebbccff",
+ "-S", "6d792dff",
+ "-p", "Run:",
+ NULL
+};
+static const char *passcmd[] = { "passmenu", NULL };
+static const char *otpcmd[] = { "otp", NULL };
+static const char *webcmd[] = { "web", NULL };
+static const char *radarcmd[] = { "radar", NULL };
+
+#include "shiftview.c"
static const Key keys[] = {
/* Note that Shift changes certain key codes: 2 -> at, etc. */
/* modifier key function argument */
- { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
- { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
- { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
- { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
- { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
- { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
- { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
- { MODKEY, XKB_KEY_Return, zoom, {0} },
- { MODKEY, XKB_KEY_Tab, view, {0} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c, killclient, {0} },
- { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
- { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
- { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
- { MODKEY, XKB_KEY_space, setlayout, {0} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
- { MODKEY, XKB_KEY_e, togglefullscreen, {0} },
- { MODKEY, XKB_KEY_0, view, {.ui = ~0} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
- { MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
- { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
- TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
- TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
- TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
- TAGKEYS( XKB_KEY_4, XKB_KEY_dollar, 3),
- TAGKEYS( XKB_KEY_5, XKB_KEY_percent, 4),
- TAGKEYS( XKB_KEY_6, XKB_KEY_asciicircum, 5),
- TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6),
- TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7),
- TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_q, quit, {0} },
+ // commands
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_p, spawn, {.v = passcmd } },
+ { MODKEY, XKB_KEY_o, spawn, {.v = otpcmd } },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_A, spawn, {.v = webcmd } },
+ { MODKEY, XKB_KEY_r, spawn, {.v = radarcmd } },
+ // basic functionality
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY, XKB_KEY_b, togglebar, {0} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+ { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_j, movestack, {.i = +1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_k, movestack, {.i = -1} },
+ { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
+ { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
+ { MODKEY, XKB_KEY_Return, zoom, {0} },
+ { MODKEY, XKB_KEY_Tab, view, {0} },
+ // shiftview
+ { MODKEY, XKB_KEY_q, shiftview, { .i = -1 } },
+ { MODKEY, XKB_KEY_w, shiftview, { .i = 1 } },
+ { MODKEY, XKB_KEY_g, togglegaps, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XKB_KEY_space, setlayout, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
+ { MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+ { MODKEY, XKB_KEY_0, view, {.ui = ~0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
+ { MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
+ { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
+ // From client-opacity-focus patch
+ { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_k, setopacityunfocus, {.f = +0.1f} },
+ { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_j, setopacityunfocus, {.f = -0.1f} },
+ { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_K, setopacityfocus, {.f = +0.1f} },
+ { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_J, setopacityfocus, {.f = -0.1f} },
+ TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
+ TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
+ TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
+ TAGKEYS( XKB_KEY_4, XKB_KEY_dollar, 3),
+ TAGKEYS( XKB_KEY_5, XKB_KEY_percent, 4),
+// TAGKEYS( XKB_KEY_6, XKB_KEY_asciicircum, 5),
+// TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6),
+// TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7),
+// TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} },
/* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */
{ WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} },
@@ -166,7 +230,15 @@ static const Key keys[] = {
};
static const Button buttons[] = {
- { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
- { MODKEY, BTN_MIDDLE, togglefloating, {0} },
- { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
+ { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} },
+ { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} },
+ { ClkTitle, 0, BTN_MIDDLE, zoom, {0} },
+ { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} },
+ { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
+ { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} },
+ { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
+ { ClkTagBar, 0, BTN_LEFT, view, {0} },
+ { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} },
+ { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} },
+ { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} },
};
diff --git a/config.mk b/config.mk
index eb08a05..b84ac8e 100644
--- a/config.mk
+++ b/config.mk
@@ -24,11 +24,11 @@ WLR_LIBS = `$(PKG_CONFIG) --libs wlroots-0.19`
# -I$(PWD)/wlroots/0.19/include/wlroots-0.19
#WLR_LIBS = -Wl,-rpath,$(PWD)/wlroots/0.19/lib64 -L$(PWD)/wlroots/0.19/lib64 -lwlroots-0.19
-XWAYLAND =
-XLIBS =
+#XWAYLAND =
+#XLIBS =
# Uncomment to build XWayland support
-#XWAYLAND = -DXWAYLAND
-#XLIBS = xcb xcb-icccm
+XWAYLAND = -DXWAYLAND
+XLIBS = xcb xcb-icccm
# dwl itself only uses C99 features, but wlroots' headers use anonymous unions (C11).
# To avoid warnings about them, we do not use -std=c99 and instead of using the
diff --git a/drwl.h b/drwl.h
new file mode 100644
index 0000000..21afd21
--- /dev/null
+++ b/drwl.h
@@ -0,0 +1,310 @@
+/*
+ * drwl - https://codeberg.org/sewn/drwl
+ *
+ * Copyright (c) 2023-2025 sewn <sewn@disroot.org>
+ * Copyright (c) 2024 notchoc <notchoc@disroot.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The UTF-8 Decoder included is from Bjoern Hoehrmann:
+ * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
+ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
+ */
+#pragma once
+
+#include <stdlib.h>
+#include <fcft/fcft.h>
+#include <pixman-1/pixman.h>
+
+enum { ColFg, ColBg, ColBorder }; /* colorscheme index */
+
+typedef struct fcft_font Fnt;
+typedef pixman_image_t Img;
+
+typedef struct {
+ Img *image;
+ Fnt *font;
+ uint32_t *scheme;
+} Drwl;
+
+#define UTF8_ACCEPT 0
+#define UTF8_REJECT 12
+#define UTF8_INVALID 0xFFFD
+
+static const uint8_t utf8d[] = {
+ 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,
+ 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,
+ 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,
+ 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,
+ 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,
+ 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,
+ 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,
+ 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,
+
+ 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
+ 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
+ 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
+ 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
+ 12,36,12,12,12,12,12,12,12,12,12,12,
+};
+
+static inline uint32_t
+utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte)
+{
+ uint32_t type = utf8d[byte];
+
+ *codep = (*state != UTF8_ACCEPT) ?
+ (byte & 0x3fu) | (*codep << 6) :
+ (0xff >> type) & (byte);
+
+ *state = utf8d[256 + *state + type];
+ return *state;
+}
+
+static int
+drwl_init(void)
+{
+ return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR);
+}
+
+static Drwl *
+drwl_create(void)
+{
+ Drwl *drwl;
+
+ if (!(drwl = calloc(1, sizeof(Drwl))))
+ return NULL;
+
+ return drwl;
+}
+
+static void
+drwl_setfont(Drwl *drwl, Fnt *font)
+{
+ if (drwl)
+ drwl->font = font;
+}
+
+static void
+drwl_setimage(Drwl *drwl, Img *image)
+{
+ if (drwl)
+ drwl->image = image;
+}
+
+static Fnt *
+drwl_font_create(Drwl *drwl, size_t count,
+ const char *names[static count], const char *attributes)
+{
+ Fnt *font = fcft_from_name(count, names, attributes);
+ if (drwl)
+ drwl_setfont(drwl, font);
+ return font;
+}
+
+static void
+drwl_font_destroy(Fnt *font)
+{
+ fcft_destroy(font);
+}
+
+static inline pixman_color_t
+convert_color(uint32_t clr)
+{
+ return (pixman_color_t){
+ ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
+ ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
+ ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
+ (clr & 0xFF) * 0x101
+ };
+}
+
+static void
+drwl_setscheme(Drwl *drwl, uint32_t *scm)
+{
+ if (drwl)
+ drwl->scheme = scm;
+}
+
+static Img *
+drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits)
+{
+ Img *image;
+ pixman_region32_t clip;
+
+ image = pixman_image_create_bits_no_clear(
+ PIXMAN_a8r8g8b8, w, h, bits, w * 4);
+ if (!image)
+ return NULL;
+ pixman_region32_init_rect(&clip, 0, 0, w, h);
+ pixman_image_set_clip_region32(image, &clip);
+ pixman_region32_fini(&clip);
+
+ if (drwl)
+ drwl_setimage(drwl, image);
+ return image;
+}
+
+static void
+drwl_rect(Drwl *drwl,
+ int x, int y, unsigned int w, unsigned int h,
+ int filled, int invert)
+{
+ pixman_color_t clr;
+ if (!drwl || !drwl->scheme || !drwl->image)
+ return;
+
+ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
+ if (filled)
+ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1,
+ &(pixman_rectangle16_t){x, y, w, h});
+ else
+ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4,
+ (pixman_rectangle16_t[4]){
+ { x, y, w, 1 },
+ { x, y + h - 1, w, 1 },
+ { x, y, 1, h },
+ { x + w - 1, y, 1, h }});
+}
+
+static int
+drwl_text(Drwl *drwl,
+ int x, int y, unsigned int w, unsigned int h,
+ unsigned int lpad, const char *text, int invert)
+{
+ int ty;
+ int render = x || y || w || h;
+ long x_kern;
+ uint32_t cp = 0, last_cp = 0, state;
+ pixman_color_t clr;
+ pixman_image_t *fg_pix = NULL;
+ int noellipsis = 0;
+ const struct fcft_glyph *glyph, *eg = NULL;
+ int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT;
+
+ if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font)
+ return 0;
+
+ if (!render) {
+ w = invert ? invert : ~invert;
+ } else {
+ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
+ fg_pix = pixman_image_create_solid_fill(&clr);
+
+ drwl_rect(drwl, x, y, w, h, 1, !invert);
+
+ x += lpad;
+ w -= lpad;
+ }
+
+ if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF)
+ fcft_subpixel_mode = FCFT_SUBPIXEL_NONE;
+
+ if (render)
+ eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode);
+
+ for (const char *p = text, *pp; pp = p, *p; p++) {
+ for (state = UTF8_ACCEPT; *p &&
+ utf8decode(&state, &cp, *p) > UTF8_REJECT; p++)
+ ;
+ if (!*p || state == UTF8_REJECT) {
+ cp = UTF8_INVALID;
+ if (p > pp)
+ p--;
+ }
+
+ glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode);
+ if (!glyph)
+ continue;
+
+ x_kern = 0;
+ if (last_cp)
+ fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL);
+ last_cp = cp;
+
+ ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent;
+
+ if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w &&
+ *(p + 1) != '\0') {
+ /* cannot fit ellipsis after current codepoint */
+ if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) {
+ noellipsis = 1;
+ } else {
+ w -= eg->advance.x;
+ pixman_image_composite32(
+ PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0,
+ x + eg->x, ty - eg->y, eg->width, eg->height);
+ }
+ }
+
+ if ((x_kern + glyph->advance.x) > w)
+ break;
+
+ x += x_kern;
+
+ if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)
+ /* pre-rendered glyphs (eg. emoji) */
+ pixman_image_composite32(
+ PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0,
+ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
+ else if (render)
+ pixman_image_composite32(
+ PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0,
+ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
+
+ x += glyph->advance.x;
+ w -= glyph->advance.x;
+ }
+
+ if (render)
+ pixman_image_unref(fg_pix);
+
+ return x + (render ? w : 0);
+}
+
+static unsigned int
+drwl_font_getwidth(Drwl *drwl, const char *text)
+{
+ if (!drwl || !drwl->font || !text)
+ return 0;
+ return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0);
+}
+
+static void
+drwl_image_destroy(Img *image)
+{
+ pixman_image_unref(image);
+}
+
+static void
+drwl_destroy(Drwl *drwl)
+{
+ if (drwl->font)
+ drwl_font_destroy(drwl->font);
+ if (drwl->image)
+ drwl_image_destroy(drwl->image);
+ free(drwl);
+}
+
+static void
+drwl_fini(void)
+{
+ fcft_fini();
+}
diff --git a/dwl.c b/dwl.c
index 8e5c87f..7c7d291 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1,10 +1,12 @@
/*
* See LICENSE file for copyright and license details.
*/
+#include <fcntl.h>
#include <getopt.h>
#include <libinput.h>
#include <linux/input-event-codes.h>
#include <math.h>
+#include <libdrm/drm_fourcc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -59,6 +61,7 @@
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
+#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h>
@@ -69,6 +72,7 @@
#endif
#include "util.h"
+#include "drwl.h"
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
@@ -77,14 +81,17 @@
#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
-#define TAGMASK ((1u << TAGCOUNT) - 1)
+#define TAGMASK ((1u << LENGTH(tags)) - 1)
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
+#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
/* enums */
+enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
+enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
typedef union {
int i;
@@ -94,6 +101,7 @@ typedef union {
} Arg;
typedef struct {
+ unsigned int click;
unsigned int mod;
unsigned int button;
void (*func)(const Arg *);
@@ -139,6 +147,9 @@ typedef struct {
unsigned int bw;
uint32_t tags;
int isfloating, isurgent, isfullscreen;
+ float opacity;
+ float opacity_focus;
+ float opacity_unfocus;
uint32_t resize; /* configure serial of a pending resize */
} Client;
@@ -184,10 +195,19 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct {
+ struct wlr_buffer base;
+ struct wl_listener release;
+ bool busy;
+ Img *image;
+ uint32_t data[];
+} Buffer;
+
struct Monitor {
struct wl_list link;
struct wlr_output *wlr_output;
struct wlr_scene_output *scene_output;
+ struct wlr_scene_buffer *scene_buffer; /* bar buffer */
struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
struct wl_listener frame;
struct wl_listener destroy;
@@ -195,9 +215,15 @@ struct Monitor {
struct wl_listener destroy_lock_surface;
struct wlr_session_lock_surface_v1 *lock_surface;
struct wlr_box m; /* monitor area, layout-relative */
+ struct {
+ int width, height;
+ int real_width, real_height; /* non-scaled */
+ float scale;
+ } b; /* bar area */
struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface.link */
const Layout *lt[2];
+ int gaps;
Pertag *pertag;
unsigned int seltags;
unsigned int sellt;
@@ -207,6 +233,9 @@ struct Monitor {
int nmaster;
char ltsymbol[16];
int asleep;
+ Drwl *drw;
+ Buffer *pool[2];
+ int lrpad;
};
typedef struct {
@@ -229,6 +258,8 @@ typedef struct {
const char *title;
uint32_t tags;
int isfloating;
+ float opacity_focus;
+ float opacity_unfocus;
int monitor;
} Rule;
@@ -249,6 +280,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m);
static void axisnotify(struct wl_listener *listener, void *data);
+static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
+static void bufdestroy(struct wlr_buffer *buffer);
+static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
+ void **data, uint32_t *format, size_t *stride);
+static void bufdataend(struct wlr_buffer *buffer);
+static Buffer *bufmon(Monitor *m);
+static void bufrelease(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
@@ -284,6 +322,8 @@ static void destroypointerconstraint(struct wl_listener *listener, void *data);
static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
+static void drawbar(Monitor *m);
+static void drawbars(void);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
@@ -302,6 +342,7 @@ static void locksession(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
+static void movestack(const Arg *arg);
static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
double sy, double sx_unaccel, double sy_unaccel);
@@ -312,7 +353,6 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
-static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
@@ -321,6 +361,7 @@ static void requeststartdrag(struct wl_listener *listener, void *data);
static void requestmonstate(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact);
static void run(char *startup_cmd);
+static void scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data);
static void setcursor(struct wl_listener *listener, void *data);
static void setcursorshape(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating);
@@ -328,22 +369,28 @@ static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, uint32_t newtags);
+static void setopacityunfocus(const Arg *arg);
+static void setopacityfocus(const Arg *arg);
static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data);
static void setup(void);
static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
+static int statusin(int fd, unsigned int mask, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
+static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
+static void togglegaps(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
static void updatemons(struct wl_listener *listener, void *data);
+static void updatebar(Monitor *m);
static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
@@ -408,6 +455,15 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static char stext[256];
+static struct wl_event_source *status_event_source;
+
+static const struct wlr_buffer_impl buffer_impl = {
+ .destroy = bufdestroy,
+ .begin_data_ptr_access = bufdatabegin,
+ .end_data_ptr_access = bufdataend,
+};
+
/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};
static struct wl_listener cursor_button = {.notify = buttonpress};
@@ -500,6 +556,8 @@ applyrules(Client *c)
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating;
+ c->opacity_unfocus = r->opacity_unfocus;
+ c->opacity_focus = r->opacity_focus;
newtags |= r->tags;
i = 0;
wl_list_for_each(m, &mons, link) {
@@ -531,7 +589,7 @@ arrange(Monitor *m)
wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
(c = focustop(m)) && c->isfullscreen);
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
/* We move all clients (except fullscreen and unmanaged) to LyrTile while
* in floating layout to avoid "real" floating clients be always on top */
@@ -586,6 +644,11 @@ arrangelayers(Monitor *m)
if (!m->wlr_output->enabled)
return;
+ if (m->scene_buffer->node.enabled) {
+ usable_area.height -= m->b.real_height;
+ usable_area.y += topbar ? m->b.real_height : 0;
+ }
+
/* Arrange exclusive surfaces from top->bottom */
for (i = 3; i >= 0; i--)
arrangelayer(m, &m->layers[i], &usable_area, 1);
@@ -628,17 +691,102 @@ axisnotify(struct wl_listener *listener, void *data)
event->delta_discrete, event->source, event->relative_direction);
}
+bool
+baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
+{
+ return true;
+}
+
+void
+bufdestroy(struct wlr_buffer *wlr_buffer)
+{
+ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
+ if (buf->busy)
+ wl_list_remove(&buf->release.link);
+ drwl_image_destroy(buf->image);
+ free(buf);
+}
+
+bool
+bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
+ void **data, uint32_t *format, size_t *stride)
+{
+ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
+
+ if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
+
+ *data = buf->data;
+ *stride = wlr_buffer->width * 4;
+ *format = DRM_FORMAT_ARGB8888;
+
+ return true;
+}
+
+void
+bufdataend(struct wlr_buffer *wlr_buffer)
+{
+}
+
+Buffer *
+bufmon(Monitor *m)
+{
+ size_t i;
+ Buffer *buf = NULL;
+
+ for (i = 0; i < LENGTH(m->pool); i++) {
+ if (m->pool[i]) {
+ if (m->pool[i]->busy)
+ continue;
+ buf = m->pool[i];
+ break;
+ }
+
+ buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
+ buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
+ wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
+ m->pool[i] = buf;
+ break;
+ }
+ if (!buf)
+ return NULL;
+
+ buf->busy = true;
+ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
+ wlr_buffer_lock(&buf->base);
+ drwl_setimage(m->drw, buf->image);
+ return buf;
+}
+
+void
+bufrelease(struct wl_listener *listener, void *data)
+{
+ Buffer *buf = wl_container_of(listener, buf, release);
+ buf->busy = false;
+ wl_list_remove(&buf->release.link);
+}
+
void
buttonpress(struct wl_listener *listener, void *data)
{
+ unsigned int i = 0, x = 0;
+ double cx;
+ unsigned int click;
struct wlr_pointer_button_event *event = data;
struct wlr_keyboard *keyboard;
+ struct wlr_scene_node *node;
+ struct wlr_scene_buffer *buffer;
uint32_t mods;
+ Arg arg = {0};
Client *c;
const Button *b;
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+ click = ClkRoot;
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+ if (c)
+ click = ClkClient;
+
switch (event->state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
cursor_mode = CurPressed;
@@ -646,17 +794,34 @@ buttonpress(struct wl_listener *listener, void *data)
if (locked)
break;
+ if (!c && !exclusive_focus &&
+ (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
+ (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
+ cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
+ do
+ x += TEXTW(selmon, tags[i]);
+ while (cx >= x && ++i < LENGTH(tags));
+ if (i < LENGTH(tags)) {
+ click = ClkTagBar;
+ arg.ui = 1 << i;
+ } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
+ click = ClkLtSymbol;
+ else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
+ click = ClkStatus;
+ } else
+ click = ClkTitle;
+ }
+
/* Change focus if the button was _pressed_ over a client */
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
- if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat);
mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
for (b = buttons; b < END(buttons); b++) {
- if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
- event->button == b->button && b->func) {
- b->func(&b->arg);
+ if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
+ b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
return;
}
}
@@ -731,6 +896,8 @@ cleanup(void)
/* Destroy after the wayland display (when the monitors are already destroyed)
to avoid destroying them with an invalid scene output. */
wlr_scene_node_destroy(&scene->tree.node);
+
+ drwl_fini();
}
void
@@ -746,6 +913,12 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_layer_surface_v1_destroy(l->layer_surface);
}
+ for (i = 0; i < LENGTH(m->pool); i++)
+ wlr_buffer_drop(&m->pool[i]->base);
+
+ drwl_setimage(m->drw, NULL);
+ drwl_destroy(m->drw);
+
wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link);
wl_list_remove(&m->link);
@@ -759,6 +932,7 @@ cleanupmon(struct wl_listener *listener, void *data)
free(m->pertag);
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
+ wlr_scene_node_destroy(&m->scene_buffer->node);
free(m);
}
@@ -825,7 +999,7 @@ closemon(Monitor *m)
setmon(c, selmon, c->tags);
}
focusclient(focustop(selmon), 1);
- printstatus();
+ drawbars();
}
void
@@ -1068,6 +1242,8 @@ createmon(struct wl_listener *listener, void *data)
wlr_output_state_init(&state);
/* Initialize monitor state using configured rules */
+ m->gaps = gaps;
+
m->tagset[0] = m->tagset[1] = 1;
for (r = monrules; r < END(monrules); r++) {
if (!r->name || strstr(wlr_output->name, r->name)) {
@@ -1077,7 +1253,7 @@ createmon(struct wl_listener *listener, void *data)
m->nmaster = r->nmaster;
m->lt[0] = r->lt;
m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]];
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
wlr_output_state_set_scale(&state, r->scale);
wlr_output_state_set_transform(&state, r->rr);
break;
@@ -1099,8 +1275,15 @@ createmon(struct wl_listener *listener, void *data)
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
+ if (!(m->drw = drwl_create()))
+ die("failed to create drwl context");
+
+ m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
+ m->scene_buffer->point_accepts_input = baracceptsinput;
+ updatebar(m);
+
wl_list_insert(&mons, &m->link);
- printstatus();
+ drawbars();
m->pertag = calloc(1, sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1;
@@ -1150,6 +1333,10 @@ createnotify(struct wl_listener *listener, void *data)
c = toplevel->base->data = ecalloc(1, sizeof(*c));
c->surface.xdg = toplevel->base;
c->bw = borderpx;
+ /* Set default opacity*/
+ c->opacity_unfocus = default_opacity_unfocus;
+ c->opacity_focus = default_opacity_focus;
+ c->opacity = default_opacity_unfocus;
LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
@@ -1423,6 +1610,80 @@ dirtomon(enum wlr_direction dir)
}
void
+drawbar(Monitor *m)
+{
+ int x, w, tw = 0;
+ int boxs = m->drw->font->height / 9;
+ int boxw = m->drw->font->height / 6 + 2;
+ uint32_t i, occ = 0, urg = 0;
+ Client *c;
+ Buffer *buf;
+
+ if (!m->scene_buffer->node.enabled)
+ return;
+ if (!(buf = bufmon(m)))
+ return;
+
+ /* draw status first so it can be overdrawn by tags later */
+ if (m == selmon) { /* status is only drawn on selected monitor */
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
+ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
+ }
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m)
+ continue;
+ occ |= c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+ }
+ x = 0;
+ c = focustop(m);
+ for (i = 0; i < LENGTH(tags); i++) {
+ w = TEXTW(m, tags[i]);
+ drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
+ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
+ if (occ & 1 << i)
+ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
+ m == selmon && c && c->tags & 1 << i,
+ urg & 1 << i);
+ x += w;
+ }
+ w = TEXTW(m, m->ltsymbol);
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
+
+ if ((w = m->b.width - tw - x) > m->b.height) {
+ if (c) {
+ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
+ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
+ if (c && c->isfloating)
+ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
+ } else {
+ drwl_setscheme(m->drw, colors[SchemeNorm]);
+ drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
+ }
+ }
+
+ wlr_scene_buffer_set_dest_size(m->scene_buffer,
+ m->b.real_width, m->b.real_height);
+ wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
+ m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
+ wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
+ wlr_buffer_unlock(&buf->base);
+}
+
+void
+drawbars(void)
+{
+ Monitor *m = NULL;
+
+ wl_list_for_each(m, &mons, link)
+ drawbar(m);
+}
+
+void
focusclient(Client *c, int lift)
{
struct wlr_surface *old = seat->keyboard_state.focused_surface;
@@ -1452,17 +1713,18 @@ focusclient(Client *c, int lift)
wl_list_insert(&fstack, &c->flink);
selmon = c->mon;
c->isurgent = 0;
+ c->opacity = c->opacity_focus;
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
if (!exclusive_focus && !seat->drag)
- client_set_border_color(c, focuscolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
}
/* Deactivate old client if focus is changing */
if (old && (!c || client_surface(c) != old)) {
/* If an overlay is focused, don't focus or activate the client,
- * but only update its position in fstack to render its border with focuscolor
+ * but only update its position in fstack to render its border with its color
* and focus it after the overlay is closed. */
if (old_client_type == LayerShell && wlr_scene_node_coords(
&old_l->scene->node, &unused_lx, &unused_ly)
@@ -1473,12 +1735,12 @@ focusclient(Client *c, int lift)
/* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
* and probably other clients */
} else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
- client_set_border_color(old_c, bordercolor);
-
+ client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
client_activate_surface(old, 0);
+ old_c->opacity = old_c->opacity_unfocus;
}
}
- printstatus();
+ drawbars();
if (!c) {
/* With no client, all we have left is to clear focus */
@@ -1792,7 +2054,7 @@ mapnotify(struct wl_listener *listener, void *data)
for (i = 0; i < 4; i++) {
c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
- c->isurgent ? urgentcolor : bordercolor);
+ (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
c->border[i]->node.data = c;
}
@@ -1815,7 +2077,7 @@ mapnotify(struct wl_listener *listener, void *data)
} else {
applyrules(c);
}
- printstatus();
+ drawbars();
unset_fullscreen:
m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
@@ -1862,6 +2124,48 @@ monocle(Monitor *m)
}
void
+movestack(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon);
+
+ if (!sel) {
+ return;
+ }
+
+ if (wl_list_length(&clients) <= 1) {
+ return;
+ }
+
+ if (arg->i > 0) {
+ wl_list_for_each(c, &sel->link, link) {
+ if (&c->link == &clients) {
+ c = wl_container_of(&clients, c, link);
+ break; /* wrap past the sentinel node */
+ }
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ } else {
+ wl_list_for_each_reverse(c, &sel->link, link) {
+ if (&c->link == &clients) {
+ c = wl_container_of(&clients, c, link);
+ break; /* wrap past the sentinel node */
+ }
+ if (VISIBLEON(c, selmon) || &c->link == &clients) {
+ break; /* found it */
+ }
+ }
+ /* backup one client */
+ c = wl_container_of(c->link.prev, c, link);
+ }
+
+ wl_list_remove(&sel->link);
+ wl_list_insert(&c->link, &sel->link);
+ arrange(selmon);
+}
+
+void
motionabsolute(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an _absolute_
@@ -2109,44 +2413,6 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
}
void
-printstatus(void)
-{
- Monitor *m = NULL;
- Client *c;
- uint32_t occ, urg, sel;
-
- wl_list_for_each(m, &mons, link) {
- occ = urg = 0;
- wl_list_for_each(c, &clients, link) {
- if (c->mon != m)
- continue;
- occ |= c->tags;
- if (c->isurgent)
- urg |= c->tags;
- }
- if ((c = focustop(m))) {
- printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
- printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
- printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
- printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
- sel = c->tags;
- } else {
- printf("%s title \n", m->wlr_output->name);
- printf("%s appid \n", m->wlr_output->name);
- printf("%s fullscreen \n", m->wlr_output->name);
- printf("%s floating \n", m->wlr_output->name);
- sel = 0;
- }
-
- printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
- printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
- m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
- printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
- }
- fflush(stdout);
-}
-
-void
powermgrsetmode(struct wl_listener *listener, void *data)
{
struct wlr_output_power_v1_set_mode_event *event = data;
@@ -2183,6 +2449,7 @@ rendermon(struct wl_listener *listener, void *data)
/* Render if no XDG clients have an outstanding resize and are visible on
* this monitor. */
wl_list_for_each(c, &clients, link) {
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c))
goto skip;
}
@@ -2274,22 +2541,14 @@ run(char *startup_cmd)
/* Now that the socket exists and the backend is started, run the startup command */
if (startup_cmd) {
- int piperw[2];
- if (pipe(piperw) < 0)
- die("startup: pipe:");
if ((child_pid = fork()) < 0)
die("startup: fork:");
if (child_pid == 0) {
+ close(STDIN_FILENO);
setsid();
- dup2(piperw[0], STDIN_FILENO);
- close(piperw[0]);
- close(piperw[1]);
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
die("startup: execl:");
}
- dup2(piperw[1], STDOUT_FILENO);
- close(piperw[1]);
- close(piperw[0]);
}
/* Mark stdout as non-blocking to avoid the startup script
@@ -2299,7 +2558,7 @@ run(char *startup_cmd)
if (fd_set_nonblock(STDOUT_FILENO) < 0)
close(STDOUT_FILENO);
- printstatus();
+ drawbars();
/* At this point the outputs are initialized, choose initial selmon based on
* cursor position, and set default cursor image */
@@ -2320,6 +2579,15 @@ run(char *startup_cmd)
}
void
+scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *data)
+{
+ Client *c = data;
+ /* xdg-popups are children of Client.scene, we do not have to worry about
+ * messing with them. */
+ wlr_scene_buffer_set_opacity(buffer, c->isfullscreen ? 1 : c->opacity);
+}
+
+void
setcursor(struct wl_listener *listener, void *data)
{
/* This event is raised by the seat when a client provides a cursor image */
@@ -2365,7 +2633,7 @@ setfloating(Client *c, int floating)
(p && p->isfullscreen) ? LyrFS
: c->isfloating ? LyrFloat : LyrTile]);
arrange(c->mon);
- printstatus();
+ drawbars();
}
void
@@ -2387,8 +2655,9 @@ setfullscreen(Client *c, int fullscreen)
* client positions are set by the user and cannot be recalculated */
resize(c, c->prev, 0);
}
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
arrange(c->mon);
- printstatus();
+ drawbars();
}
void
@@ -2402,7 +2671,7 @@ setlayout(const Arg *arg)
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
arrange(selmon);
- printstatus();
+ drawbar(selmon);
}
/* arg > 1.0 will set mfact absolutely */
@@ -2443,6 +2712,44 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
focusclient(focustop(selmon), 1);
}
+
+void
+setopacityunfocus(const Arg *arg)
+{
+ Client *sel = focustop(selmon);
+ if (!sel)
+ return;
+
+ sel->opacity_unfocus += arg->f;
+ if (sel->opacity_unfocus > 1.0)
+ sel->opacity_unfocus = 1.0f;
+
+ if (sel->opacity_unfocus < 0.1)
+ sel->opacity_unfocus = 0.1f;
+
+ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
+}
+
+void
+setopacityfocus(const Arg *arg)
+{
+ Client *sel = focustop(selmon);
+ if (!sel)
+ return;
+
+ sel->opacity_focus += arg->f;
+ if (sel->opacity_focus > 1.0)
+ sel->opacity_focus = 1.0f;
+
+ if (sel->opacity_focus < 0.1)
+ sel->opacity_focus = 0.1f;
+
+ /* Change opacity from current client */
+ sel->opacity = sel->opacity_focus;
+
+ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
+}
+
void
setpsel(struct wl_listener *listener, void *data)
{
@@ -2475,6 +2782,7 @@ setup(void)
for (i = 0; i < (int)LENGTH(sig); i++)
sigaction(sig[i], &sa, NULL);
+
wlr_log_init(log_level, NULL);
/* The Wayland display is managed by libwayland. It handles accepting
@@ -2669,6 +2977,11 @@ setup(void)
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+ drwl_init();
+
+ status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
+ STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
+
/* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the
* compositor has Xwayland support */
@@ -2693,6 +3006,8 @@ void
spawn(const Arg *arg)
{
if (fork() == 0) {
+ close(STDIN_FILENO);
+ open("/dev/null", O_RDWR);
dup2(STDERR_FILENO, STDOUT_FILENO);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
@@ -2711,6 +3026,30 @@ startdrag(struct wl_listener *listener, void *data)
LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
}
+int
+statusin(int fd, unsigned int mask, void *data)
+{
+ char status[256];
+ ssize_t n;
+
+ if (mask & WL_EVENT_ERROR)
+ die("status in event error");
+ if (mask & WL_EVENT_HANGUP)
+ wl_event_source_remove(status_event_source);
+
+ n = read(fd, status, sizeof(status) - 1);
+ if (n < 0 && errno != EWOULDBLOCK)
+ die("read:");
+
+ status[n] = '\0';
+ status[strcspn(status, "\n")] = '\0';
+
+ strncpy(stext, status, sizeof(stext));
+ drawbars();
+
+ return 0;
+}
+
void
tag(const Arg *arg)
{
@@ -2721,7 +3060,7 @@ tag(const Arg *arg)
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2735,7 +3074,7 @@ tagmon(const Arg *arg)
void
tile(Monitor *m)
{
- unsigned int mw, my, ty;
+ unsigned int h, r, e = m->gaps, mw, my, ty;
int i, n = 0;
Client *c;
@@ -2744,29 +3083,45 @@ tile(Monitor *m)
n++;
if (n == 0)
return;
+ if (smartgaps == n)
+ e = 0;
if (n > m->nmaster)
- mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
+ mw = m->nmaster ? (int)roundf((m->w.width + gappx*e) * m->mfact) : 0;
else
mw = m->w.width;
- i = my = ty = 0;
+ i = 0;
+ my = ty = gappx*e;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue;
if (i < m->nmaster) {
- resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw,
- .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
- my += c->geom.height;
+ r = MIN(n, m->nmaster) - i;
+ h = (m->w.height - my - gappx*e - gappx*e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + gappx*e, .y = m->w.y + my,
+ .width = mw - 2*gappx*e, .height = h}, 0);
+ my += c->geom.height + gappx*e;
} else {
+ r = n - i;
+ h = (m->w.height - ty - gappx*e - gappx*e * (r - 1)) / r;
resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
- .width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
- ty += c->geom.height;
+ .width = m->w.width - mw - gappx*e, .height = h}, 0);
+ ty += c->geom.height + gappx*e;
}
i++;
}
}
void
+togglebar(const Arg *arg)
+{
+ wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
+ !selmon->scene_buffer->node.enabled);
+ arrangelayers(selmon);
+ drawbars();
+}
+
+void
togglefloating(const Arg *arg)
{
Client *sel = focustop(selmon);
@@ -2784,6 +3139,13 @@ togglefullscreen(const Arg *arg)
}
void
+togglegaps(const Arg *arg)
+{
+ selmon->gaps = !selmon->gaps;
+ arrange(selmon);
+}
+
+void
toggletag(const Arg *arg)
{
uint32_t newtags;
@@ -2794,7 +3156,7 @@ toggletag(const Arg *arg)
sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2827,7 +3189,7 @@ toggleview(const Arg *arg)
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -2875,7 +3237,7 @@ unmapnotify(struct wl_listener *listener, void *data)
}
wlr_scene_node_destroy(&c->scene->node);
- printstatus();
+ drawbars();
motionnotify(0, NULL, 0, 0, 0, 0);
}
@@ -2975,6 +3337,13 @@ updatemons(struct wl_listener *listener, void *data)
}
}
+ if (stext[0] == '\0')
+ strncpy(stext, "dwl-"VERSION, sizeof(stext));
+ wl_list_for_each(m, &mons, link) {
+ updatebar(m);
+ drawbar(m);
+ }
+
/* FIXME: figure out why the cursor image is at 0,0 after turning all
* the monitors on.
* Move the cursor image where it used to be. It does not generate a
@@ -2986,11 +3355,44 @@ updatemons(struct wl_listener *listener, void *data)
}
void
+updatebar(Monitor *m)
+{
+ size_t i;
+ int rw, rh;
+ char fontattrs[12];
+
+ wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
+ m->b.width = rw;
+ m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
+
+ wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
+
+ for (i = 0; i < LENGTH(m->pool); i++)
+ if (m->pool[i]) {
+ wlr_buffer_drop(&m->pool[i]->base);
+ m->pool[i] = NULL;
+ }
+
+ if (m->b.scale == m->wlr_output->scale && m->drw)
+ return;
+
+ drwl_font_destroy(m->drw->font);
+ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
+ if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
+ die("Could not load font");
+
+ m->b.scale = m->wlr_output->scale;
+ m->lrpad = m->drw->font->height;
+ m->b.height = m->drw->font->height + 2;
+ m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
+}
+
+void
updatetitle(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon))
- printstatus();
+ drawbars();
}
void
@@ -3003,10 +3405,10 @@ urgent(struct wl_listener *listener, void *data)
return;
c->isurgent = 1;
- printstatus();
+ drawbars();
if (client_surface(c)->mapped)
- client_set_border_color(c, urgentcolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void
@@ -3041,7 +3443,7 @@ view(const Arg *arg)
focusclient(focustop(selmon), 1);
arrange(selmon);
- printstatus();
+ drawbars();
}
void
@@ -3082,6 +3484,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
{
struct wlr_scene_node *node, *pnode;
struct wlr_surface *surface = NULL;
+ struct wlr_scene_surface *scene_surface = NULL;
Client *c = NULL;
LayerSurface *l = NULL;
int layer;
@@ -3090,9 +3493,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
continue;
- if (node->type == WLR_SCENE_NODE_BUFFER)
- surface = wlr_scene_surface_try_from_buffer(
- wlr_scene_buffer_from_node(node))->surface;
+ if (node->type == WLR_SCENE_NODE_BUFFER) {
+ scene_surface = wlr_scene_surface_try_from_buffer(
+ wlr_scene_buffer_from_node(node));
+ if (!scene_surface) continue;
+ surface = scene_surface->surface;
+ }
/* Walk the tree to find a node that knows the client */
for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
c = pnode->data;
@@ -3225,10 +3631,10 @@ sethints(struct wl_listener *listener, void *data)
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
- printstatus();
+ drawbars();
if (c->isurgent && surface && surface->mapped)
- client_set_border_color(c, urgentcolor);
+ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
}
void
diff --git a/patches/bar/README.md b/patches/bar/README.md
new file mode 100644
index 0000000..5fedeeb
--- /dev/null
+++ b/patches/bar/README.md
@@ -0,0 +1,34 @@
+### Description
+
+Add a bar identical to dwm's bar.
+
+To use a status-bar, you can pass in status text via stdin:
+```
+slstatus -s | dwl
+```
+
+### Dependencies
+* tllist (build dependency, required & pulled automatically by fcft)
+* fcft
+* pixman
+
+### Download
+- [main 2026-01-05](/dwl/dwl-patches/raw/branch/main/patches/bar/bar.patch)
+- [0.7](/dwl/dwl-patches/raw/branch/main/patches/bar/bar-0.7.patch)
+- [0.6](/dwl/dwl-patches/raw/branch/main/patches/bar/bar-0.6.patch)
+
+It is required to remove, regenerate or update `config.h` after applying the patch,
+since it makes changes to the configuration structure.
+For example, in the `pertag` patch, `TAGCOUNT` must be replaced with `LENGTH(tags)`.
+
+Below is a preview of the patch.
+
+![bar patch preview](bar.png)
+
+### Authors
+- [sewn](https://codeberg.org/sewn)
+
+### Credits
+- [MadcowOG](https://github.com/MadcowOG)
+- [kolumni](https://github.com/kolunmi/dwlb)
+
diff --git a/patches/bar/bar-0.6.patch b/patches/bar/bar-0.6.patch
new file mode 100644
index 0000000..70c9f12
--- /dev/null
+++ b/patches/bar/bar-0.6.patch
@@ -0,0 +1,1245 @@
+From 85e40afc2ad8acba453ce8c57233542e340c1c2b Mon Sep 17 00:00:00 2001
+From: sewn <sewn@disroot.org>
+Date: Fri, 23 Aug 2024 09:42:04 +0300
+Subject: [PATCH] Implement dwm bar clone
+
+---
+ Makefile | 2 +-
+ config.def.h | 31 +++-
+ drwl.h | 311 ++++++++++++++++++++++++++++++++++++
+ dwl.c | 442 +++++++++++++++++++++++++++++++++++++++++----------
+ 4 files changed, 691 insertions(+), 95 deletions(-)
+ create mode 100644 drwl.h
+
+diff --git a/Makefile b/Makefile
+index 0d651e7..2a11396 100644
+--- a/Makefile
++++ b/Makefile
+@@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement \
+ -Wfloat-conversion
+
+ # CFLAGS / LDFLAGS
+-PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
++PKGS = wlroots wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS)
+ DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
+ LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
+
+diff --git a/config.def.h b/config.def.h
+index 22d2171..5d1dc2b 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -7,15 +7,21 @@
+ static const int sloppyfocus = 1; /* focus follows mouse */
+ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+-static const float rootcolor[] = COLOR(0x222222ff);
+-static const float bordercolor[] = COLOR(0x444444ff);
+-static const float focuscolor[] = COLOR(0x005577ff);
+-static const float urgentcolor[] = COLOR(0xff0000ff);
++static const int showbar = 1; /* 0 means no bar */
++static const int topbar = 1; /* 0 means bottom bar */
++static const char *fonts[] = {"monospace:size=10"};
++static const float rootcolor[] = COLOR(0x000000ff);
+ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
+ static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */
++static uint32_t colors[][3] = {
++ /* fg bg border */
++ [SchemeNorm] = { 0xbbbbbbff, 0x222222ff, 0x444444ff },
++ [SchemeSel] = { 0xeeeeeeff, 0x005577ff, 0x005577ff },
++ [SchemeUrg] = { 0, 0, 0x770000ff },
++};
+
+ /* tagging - TAGCOUNT must be no greater than 31 */
+-#define TAGCOUNT (9)
++static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+
+ /* logging */
+ static int log_level = WLR_ERROR;
+@@ -127,6 +133,7 @@ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
++ { MODKEY, XKB_KEY_b, togglebar, {0} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+@@ -170,7 +177,15 @@ static const Key keys[] = {
+ };
+
+ static const Button buttons[] = {
+- { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
+- { MODKEY, BTN_MIDDLE, togglefloating, {0} },
+- { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} },
++ { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} },
++ { ClkTitle, 0, BTN_MIDDLE, zoom, {0} },
++ { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} },
++ { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
++ { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} },
++ { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkTagBar, 0, BTN_LEFT, view, {0} },
++ { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} },
++ { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} },
++ { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} },
+ };
+diff --git a/drwl.h b/drwl.h
+new file mode 100644
+index 0000000..b06a736
+--- /dev/null
++++ b/drwl.h
+@@ -0,0 +1,311 @@
++/*
++ * drwl - https://codeberg.org/sewn/drwl
++ *
++ * Copyright (c) 2023-2024 sewn <sewn@disroot.org>
++ * Copyright (c) 2024 notchoc <notchoc@disroot.org>
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining
++ * a copy of this software and associated documentation files (the
++ * "Software"), to deal in the Software without restriction, including
++ * without limitation the rights to use, copy, modify, merge, publish,
++ * distribute, sublicense, and/or sell copies of the Software, and to
++ * permit persons to whom the Software is furnished to do so, subject to
++ * the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ * The UTF-8 Decoder included is from Bjoern Hoehrmann:
++ * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
++ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
++ */
++#pragma once
++
++#include <stdlib.h>
++#include <fcft/fcft.h>
++#include <pixman-1/pixman.h>
++
++enum { ColFg, ColBg, ColBorder }; /* colorscheme index */
++
++typedef struct fcft_font Fnt;
++typedef pixman_image_t Img;
++
++typedef struct {
++ Img *image;
++ Fnt *font;
++ uint32_t *scheme;
++} Drwl;
++
++#define UTF8_ACCEPT 0
++#define UTF8_REJECT 12
++#define UTF8_INVALID 0xFFFD
++
++static const uint8_t utf8d[] = {
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++
++ 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
++ 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
++ 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
++ 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
++ 12,36,12,12,12,12,12,12,12,12,12,12,
++};
++
++static inline uint32_t
++utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte)
++{
++ uint32_t type = utf8d[byte];
++
++ *codep = (*state != UTF8_ACCEPT) ?
++ (byte & 0x3fu) | (*codep << 6) :
++ (0xff >> type) & (byte);
++
++ *state = utf8d[256 + *state + type];
++ return *state;
++}
++
++static int
++drwl_init(void)
++{
++ fcft_set_scaling_filter(FCFT_SCALING_FILTER_LANCZOS3);
++ return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR);
++}
++
++static Drwl *
++drwl_create(void)
++{
++ Drwl *drwl;
++
++ if (!(drwl = calloc(1, sizeof(Drwl))))
++ return NULL;
++
++ return drwl;
++}
++
++static void
++drwl_setfont(Drwl *drwl, Fnt *font)
++{
++ if (drwl)
++ drwl->font = font;
++}
++
++static void
++drwl_setimage(Drwl *drwl, Img *image)
++{
++ if (drwl)
++ drwl->image = image;
++}
++
++static Fnt *
++drwl_font_create(Drwl *drwl, size_t count,
++ const char *names[static count], const char *attributes)
++{
++ Fnt *font = fcft_from_name(count, names, attributes);
++ if (drwl)
++ drwl_setfont(drwl, font);
++ return font;
++}
++
++static void
++drwl_font_destroy(Fnt *font)
++{
++ fcft_destroy(font);
++}
++
++static inline pixman_color_t
++convert_color(uint32_t clr)
++{
++ return (pixman_color_t){
++ ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ (clr & 0xFF) * 0x101
++ };
++}
++
++static void
++drwl_setscheme(Drwl *drwl, uint32_t *scm)
++{
++ if (drwl)
++ drwl->scheme = scm;
++}
++
++static Img *
++drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits)
++{
++ Img *image;
++ pixman_region32_t clip;
++
++ image = pixman_image_create_bits_no_clear(
++ PIXMAN_a8r8g8b8, w, h, bits, w * 4);
++ if (!image)
++ return NULL;
++ pixman_region32_init_rect(&clip, 0, 0, w, h);
++ pixman_image_set_clip_region32(image, &clip);
++ pixman_region32_fini(&clip);
++
++ if (drwl)
++ drwl_setimage(drwl, image);
++ return image;
++}
++
++static void
++drwl_rect(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ int filled, int invert)
++{
++ pixman_color_t clr;
++ if (!drwl || !drwl->scheme || !drwl->image)
++ return;
++
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ if (filled)
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1,
++ &(pixman_rectangle16_t){x, y, w, h});
++ else
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4,
++ (pixman_rectangle16_t[4]){
++ { x, y, w, 1 },
++ { x, y + h - 1, w, 1 },
++ { x, y, 1, h },
++ { x + w - 1, y, 1, h }});
++}
++
++static int
++drwl_text(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ unsigned int lpad, const char *text, int invert)
++{
++ int ty;
++ int render = x || y || w || h;
++ long x_kern;
++ uint32_t cp = 0, last_cp = 0, state;
++ pixman_color_t clr;
++ pixman_image_t *fg_pix = NULL;
++ int noellipsis = 0;
++ const struct fcft_glyph *glyph, *eg = NULL;
++ int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT;
++
++ if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font)
++ return 0;
++
++ if (!render) {
++ w = invert ? invert : ~invert;
++ } else {
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ fg_pix = pixman_image_create_solid_fill(&clr);
++
++ drwl_rect(drwl, x, y, w, h, 1, !invert);
++
++ x += lpad;
++ w -= lpad;
++ }
++
++ if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF)
++ fcft_subpixel_mode = FCFT_SUBPIXEL_NONE;
++
++ if (render)
++ eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode);
++
++ for (const char *p = text, *pp; pp = p, *p; p++) {
++ for (state = UTF8_ACCEPT; *p &&
++ utf8decode(&state, &cp, *p) > UTF8_REJECT; p++)
++ ;
++ if (!*p || state == UTF8_REJECT) {
++ cp = UTF8_INVALID;
++ if (p > pp)
++ p--;
++ }
++
++ glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode);
++ if (!glyph)
++ continue;
++
++ x_kern = 0;
++ if (last_cp)
++ fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL);
++ last_cp = cp;
++
++ ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent;
++
++ if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w &&
++ *(p + 1) != '\0') {
++ /* cannot fit ellipsis after current codepoint */
++ if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) {
++ noellipsis = 1;
++ } else {
++ w -= eg->advance.x;
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0,
++ x + eg->x, ty - eg->y, eg->width, eg->height);
++ }
++ }
++
++ if ((x_kern + glyph->advance.x) > w)
++ break;
++
++ x += x_kern;
++
++ if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)
++ /* pre-rendered glyphs (eg. emoji) */
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++ else if (render)
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++
++ x += glyph->advance.x;
++ w -= glyph->advance.x;
++ }
++
++ if (render)
++ pixman_image_unref(fg_pix);
++
++ return x + (render ? w : 0);
++}
++
++static unsigned int
++drwl_font_getwidth(Drwl *drwl, const char *text)
++{
++ if (!drwl || !drwl->font || !text)
++ return 0;
++ return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0);
++}
++
++static void
++drwl_image_destroy(Img *image)
++{
++ pixman_image_unref(image);
++}
++
++static void
++drwl_destroy(Drwl *drwl)
++{
++ if (drwl->font)
++ drwl_font_destroy(drwl->font);
++ if (drwl->image)
++ drwl_image_destroy(drwl->image);
++ free(drwl);
++}
++
++static void
++drwl_fini(void)
++{
++ fcft_fini();
++}
+diff --git a/dwl.c b/dwl.c
+index 145fd01..ab1bc31 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -5,6 +5,7 @@
+ #include <libinput.h>
+ #include <linux/input-event-codes.h>
+ #include <math.h>
++#include <libdrm/drm_fourcc.h>
+ #include <signal.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -57,6 +58,7 @@
+ #include <wlr/types/wlr_xdg_decoration_v1.h>
+ #include <wlr/types/wlr_xdg_output_v1.h>
+ #include <wlr/types/wlr_xdg_shell.h>
++#include <wlr/interfaces/wlr_buffer.h>
+ #include <wlr/util/log.h>
+ #include <wlr/util/region.h>
+ #include <xkbcommon/xkbcommon.h>
+@@ -67,6 +69,7 @@
+ #endif
+
+ #include "util.h"
++#include "drwl.h"
+
+ /* macros */
+ #define MAX(A, B) ((A) > (B) ? (A) : (B))
+@@ -75,14 +78,17 @@
+ #define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define END(A) ((A) + LENGTH(A))
+-#define TAGMASK ((1u << TAGCOUNT) - 1)
++#define TAGMASK ((1u << LENGTH(tags)) - 1)
+ #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
+ #define LISTEN_STATIC(E, H) do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
++#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
+
+ /* enums */
++enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
+ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
+ enum { XDGShell, LayerShell, X11 }; /* client types */
+ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
++enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
+ #ifdef XWAYLAND
+ enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
+ NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
+@@ -96,6 +102,7 @@ typedef union {
+ } Arg;
+
+ typedef struct {
++ unsigned int click;
+ unsigned int mod;
+ unsigned int button;
+ void (*func)(const Arg *);
+@@ -185,10 +192,19 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct {
++ struct wlr_buffer base;
++ struct wl_listener release;
++ bool busy;
++ Img *image;
++ uint32_t data[];
++} Buffer;
++
+ struct Monitor {
+ struct wl_list link;
+ struct wlr_output *wlr_output;
+ struct wlr_scene_output *scene_output;
++ struct wlr_scene_buffer *scene_buffer; /* bar buffer */
+ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wl_listener frame;
+ struct wl_listener destroy;
+@@ -196,6 +212,11 @@ struct Monitor {
+ struct wl_listener destroy_lock_surface;
+ struct wlr_session_lock_surface_v1 *lock_surface;
+ struct wlr_box m; /* monitor area, layout-relative */
++ struct {
++ int width, height;
++ int real_width, real_height; /* non-scaled */
++ float scale;
++ } b; /* bar area */
+ struct wlr_box w; /* window area, layout-relative */
+ struct wl_list layers[4]; /* LayerSurface.link */
+ const Layout *lt[2];
+@@ -207,6 +228,9 @@ struct Monitor {
+ int nmaster;
+ char ltsymbol[16];
+ int asleep;
++ Drwl *drw;
++ Buffer *pool[2];
++ int lrpad;
+ };
+
+ typedef struct {
+@@ -249,6 +273,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
+ struct wlr_box *usable_area, int exclusive);
+ static void arrangelayers(Monitor *m);
+ static void axisnotify(struct wl_listener *listener, void *data);
++static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
++static void bufdestroy(struct wlr_buffer *buffer);
++static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride);
++static void bufdataend(struct wlr_buffer *buffer);
++static Buffer *bufmon(Monitor *m);
++static void bufrelease(struct wl_listener *listener, void *data);
+ static void buttonpress(struct wl_listener *listener, void *data);
+ static void chvt(const Arg *arg);
+ static void checkidleinhibitor(struct wlr_surface *exclude);
+@@ -282,6 +313,8 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
+ static void destroysessionmgr(struct wl_listener *listener, void *data);
+ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
+ static Monitor *dirtomon(enum wlr_direction dir);
++static void drawbar(Monitor *m);
++static void drawbars(void);
+ static void focusclient(Client *c, int lift);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
+@@ -309,7 +342,6 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
+ static void outputmgrtest(struct wl_listener *listener, void *data);
+ static void pointerfocus(Client *c, struct wlr_surface *surface,
+ double sx, double sy, uint32_t time);
+-static void printstatus(void);
+ static void powermgrsetmode(struct wl_listener *listener, void *data);
+ static void quit(const Arg *arg);
+ static void rendermon(struct wl_listener *listener, void *data);
+@@ -331,9 +363,11 @@ static void setsel(struct wl_listener *listener, void *data);
+ static void setup(void);
+ static void spawn(const Arg *arg);
+ static void startdrag(struct wl_listener *listener, void *data);
++static int statusin(int fd, unsigned int mask, void *data);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *m);
++static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
+ static void togglefullscreen(const Arg *arg);
+ static void toggletag(const Arg *arg);
+@@ -342,6 +376,7 @@ static void unlocksession(struct wl_listener *listener, void *data);
+ static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
+ static void unmapnotify(struct wl_listener *listener, void *data);
+ static void updatemons(struct wl_listener *listener, void *data);
++static void updatebar(Monitor *m);
+ static void updatetitle(struct wl_listener *listener, void *data);
+ static void urgent(struct wl_listener *listener, void *data);
+ static void view(const Arg *arg);
+@@ -408,6 +443,15 @@ static struct wlr_box sgeom;
+ static struct wl_list mons;
+ static Monitor *selmon;
+
++static char stext[256];
++static struct wl_event_source *status_event_source;
++
++static const struct wlr_buffer_impl buffer_impl = {
++ .destroy = bufdestroy,
++ .begin_data_ptr_access = bufdatabegin,
++ .end_data_ptr_access = bufdataend,
++};
++
+ #ifdef XWAYLAND
+ static void activatex11(struct wl_listener *listener, void *data);
+ static void associatex11(struct wl_listener *listener, void *data);
+@@ -548,6 +592,11 @@ arrangelayers(Monitor *m)
+ if (!m->wlr_output->enabled)
+ return;
+
++ if (m->scene_buffer->node.enabled) {
++ usable_area.height -= m->b.real_height;
++ usable_area.y += topbar ? m->b.real_height : 0;
++ }
++
+ /* Arrange exclusive surfaces from top->bottom */
+ for (i = 3; i >= 0; i--)
+ arrangelayer(m, &m->layers[i], &usable_area, 1);
+@@ -590,17 +639,102 @@ axisnotify(struct wl_listener *listener, void *data)
+ event->delta_discrete, event->source);
+ }
+
++bool
++baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
++{
++ return true;
++}
++
++void
++bufdestroy(struct wlr_buffer *wlr_buffer)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++ if (buf->busy)
++ wl_list_remove(&buf->release.link);
++ drwl_image_destroy(buf->image);
++ free(buf);
++}
++
++bool
++bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++
++ if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
++
++ *data = buf->data;
++ *stride = wlr_buffer->width * 4;
++ *format = DRM_FORMAT_ARGB8888;
++
++ return true;
++}
++
++void
++bufdataend(struct wlr_buffer *wlr_buffer)
++{
++}
++
++Buffer *
++bufmon(Monitor *m)
++{
++ size_t i;
++ Buffer *buf = NULL;
++
++ for (i = 0; i < LENGTH(m->pool); i++) {
++ if (m->pool[i]) {
++ if (m->pool[i]->busy)
++ continue;
++ buf = m->pool[i];
++ break;
++ }
++
++ buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
++ buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
++ wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
++ m->pool[i] = buf;
++ break;
++ }
++ if (!buf)
++ return NULL;
++
++ buf->busy = true;
++ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
++ wlr_buffer_lock(&buf->base);
++ drwl_setimage(m->drw, buf->image);
++ return buf;
++}
++
++void
++bufrelease(struct wl_listener *listener, void *data)
++{
++ Buffer *buf = wl_container_of(listener, buf, release);
++ buf->busy = false;
++ wl_list_remove(&buf->release.link);
++}
++
+ void
+ buttonpress(struct wl_listener *listener, void *data)
+ {
++ unsigned int i = 0, x = 0;
++ double cx;
++ unsigned int click;
+ struct wlr_pointer_button_event *event = data;
+ struct wlr_keyboard *keyboard;
++ struct wlr_scene_node *node;
++ struct wlr_scene_buffer *buffer;
+ uint32_t mods;
++ Arg arg = {0};
+ Client *c;
+ const Button *b;
+
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+
++ click = ClkRoot;
++ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
++ if (c)
++ click = ClkClient;
++
+ switch (event->state) {
+ case WLR_BUTTON_PRESSED:
+ cursor_mode = CurPressed;
+@@ -608,17 +742,34 @@ buttonpress(struct wl_listener *listener, void *data)
+ if (locked)
+ break;
+
++ if (!c && !exclusive_focus &&
++ (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
++ (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
++ cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
++ do
++ x += TEXTW(selmon, tags[i]);
++ while (cx >= x && ++i < LENGTH(tags));
++ if (i < LENGTH(tags)) {
++ click = ClkTagBar;
++ arg.ui = 1 << i;
++ } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
++ click = ClkLtSymbol;
++ else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
++ click = ClkStatus;
++ } else
++ click = ClkTitle;
++ }
++
+ /* Change focus if the button was _pressed_ over a client */
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+- if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
++ if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ focusclient(c, 1);
+
+ keyboard = wlr_seat_get_keyboard(seat);
+ mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
+ for (b = buttons; b < END(buttons); b++) {
+- if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
+- event->button == b->button && b->func) {
+- b->func(&b->arg);
++ if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
++ b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
+ return;
+ }
+ }
+@@ -689,6 +840,8 @@ cleanup(void)
+ /* Destroy after the wayland display (when the monitors are already destroyed)
+ to avoid destroying them with an invalid scene output. */
+ wlr_scene_node_destroy(&scene->tree.node);
++
++ drwl_fini();
+ }
+
+ void
+@@ -704,6 +857,12 @@ cleanupmon(struct wl_listener *listener, void *data)
+ wlr_layer_surface_v1_destroy(l->layer_surface);
+ }
+
++ for (i = 0; i < LENGTH(m->pool); i++)
++ wlr_buffer_drop(&m->pool[i]->base);
++
++ drwl_setimage(m->drw, NULL);
++ drwl_destroy(m->drw);
++
+ wl_list_remove(&m->destroy.link);
+ wl_list_remove(&m->frame.link);
+ wl_list_remove(&m->link);
+@@ -714,6 +873,7 @@ cleanupmon(struct wl_listener *listener, void *data)
+
+ closemon(m);
+ wlr_scene_node_destroy(&m->fullscreen_bg->node);
++ wlr_scene_node_destroy(&m->scene_buffer->node);
+ free(m);
+ }
+
+@@ -743,7 +903,7 @@ closemon(Monitor *m)
+ setmon(c, selmon, c->tags);
+ }
+ focusclient(focustop(selmon), 1);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -980,8 +1140,15 @@ createmon(struct wl_listener *listener, void *data)
+ wlr_output_commit_state(wlr_output, &state);
+ wlr_output_state_finish(&state);
+
++ if (!(m->drw = drwl_create()))
++ die("failed to create drwl context");
++
++ m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
++ m->scene_buffer->point_accepts_input = baracceptsinput;
++ updatebar(m);
++
+ wl_list_insert(&mons, &m->link);
+- printstatus();
++ drawbars();
+
+ /* The xdg-protocol specifies:
+ *
+@@ -1312,6 +1479,80 @@ dirtomon(enum wlr_direction dir)
+ return selmon;
+ }
+
++void
++drawbar(Monitor *m)
++{
++ int x, w, tw = 0;
++ int boxs = m->drw->font->height / 9;
++ int boxw = m->drw->font->height / 6 + 2;
++ uint32_t i, occ = 0, urg = 0;
++ Client *c;
++ Buffer *buf;
++
++ if (!m->scene_buffer->node.enabled)
++ return;
++ if (!(buf = bufmon(m)))
++ return;
++
++ /* draw status first so it can be overdrawn by tags later */
++ if (m == selmon) { /* status is only drawn on selected monitor */
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
++ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
++ }
++
++ wl_list_for_each(c, &clients, link) {
++ if (c->mon != m)
++ continue;
++ occ |= c->tags;
++ if (c->isurgent)
++ urg |= c->tags;
++ }
++ x = 0;
++ c = focustop(m);
++ for (i = 0; i < LENGTH(tags); i++) {
++ w = TEXTW(m, tags[i]);
++ drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
++ if (occ & 1 << i)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
++ m == selmon && c && c->tags & 1 << i,
++ urg & 1 << i);
++ x += w;
++ }
++ w = TEXTW(m, m->ltsymbol);
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
++
++ if ((w = m->b.width - tw - x) > m->b.height) {
++ if (c) {
++ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
++ if (c && c->isfloating)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
++ } else {
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
++ }
++ }
++
++ wlr_scene_buffer_set_dest_size(m->scene_buffer,
++ m->b.real_width, m->b.real_height);
++ wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
++ m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
++ wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
++ wlr_buffer_unlock(&buf->base);
++}
++
++void
++drawbars(void)
++{
++ Monitor *m = NULL;
++
++ wl_list_for_each(m, &mons, link)
++ drawbar(m);
++}
++
+ void
+ focusclient(Client *c, int lift)
+ {
+@@ -1347,13 +1588,13 @@ focusclient(Client *c, int lift)
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+ if (!exclusive_focus && !seat->drag)
+- client_set_border_color(c, focuscolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
+ }
+
+ /* Deactivate old client if focus is changing */
+ if (old && (!c || client_surface(c) != old)) {
+ /* If an overlay is focused, don't focus or activate the client,
+- * but only update its position in fstack to render its border with focuscolor
++ * but only update its position in fstack to render its border with its color
+ * and focus it after the overlay is closed. */
+ if (old_client_type == LayerShell && wlr_scene_node_coords(
+ &old_l->scene->node, &unused_lx, &unused_ly)
+@@ -1364,12 +1605,11 @@ focusclient(Client *c, int lift)
+ /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
+ * and probably other clients */
+ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
+- client_set_border_color(old_c, bordercolor);
+-
++ client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
+ client_activate_surface(old, 0);
+ }
+ }
+- printstatus();
++ drawbars();
+
+ if (!c) {
+ /* With no client, all we have left is to clear focus */
+@@ -1666,7 +1906,7 @@ mapnotify(struct wl_listener *listener, void *data)
+
+ for (i = 0; i < 4; i++) {
+ c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
+- c->isurgent ? urgentcolor : bordercolor);
++ (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
+ c->border[i]->node.data = c;
+ }
+
+@@ -1689,7 +1929,7 @@ mapnotify(struct wl_listener *listener, void *data)
+ } else {
+ applyrules(c);
+ }
+- printstatus();
++ drawbars();
+
+ unset_fullscreen:
+ m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
+@@ -1982,46 +2222,6 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
+ wlr_seat_pointer_notify_motion(seat, time, sx, sy);
+ }
+
+-void
+-printstatus(void)
+-{
+- Monitor *m = NULL;
+- Client *c;
+- uint32_t occ, urg, sel;
+- const char *appid, *title;
+-
+- wl_list_for_each(m, &mons, link) {
+- occ = urg = 0;
+- wl_list_for_each(c, &clients, link) {
+- if (c->mon != m)
+- continue;
+- occ |= c->tags;
+- if (c->isurgent)
+- urg |= c->tags;
+- }
+- if ((c = focustop(m))) {
+- title = client_get_title(c);
+- appid = client_get_appid(c);
+- printf("%s title %s\n", m->wlr_output->name, title ? title : broken);
+- printf("%s appid %s\n", m->wlr_output->name, appid ? appid : broken);
+- printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
+- printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
+- sel = c->tags;
+- } else {
+- printf("%s title \n", m->wlr_output->name);
+- printf("%s appid \n", m->wlr_output->name);
+- printf("%s fullscreen \n", m->wlr_output->name);
+- printf("%s floating \n", m->wlr_output->name);
+- sel = 0;
+- }
+-
+- printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
+- printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
+- m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
+- printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+- }
+- fflush(stdout);
+-}
+
+ void
+ powermgrsetmode(struct wl_listener *listener, void *data)
+@@ -2175,30 +2375,17 @@ run(char *startup_cmd)
+
+ /* Now that the socket exists and the backend is started, run the startup command */
+ if (startup_cmd) {
+- int piperw[2];
+- if (pipe(piperw) < 0)
+- die("startup: pipe:");
+ if ((child_pid = fork()) < 0)
+ die("startup: fork:");
+ if (child_pid == 0) {
++ close(STDIN_FILENO);
+ setsid();
+- dup2(piperw[0], STDIN_FILENO);
+- close(piperw[0]);
+- close(piperw[1]);
+ execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
+ die("startup: execl:");
+ }
+- dup2(piperw[1], STDOUT_FILENO);
+- close(piperw[1]);
+- close(piperw[0]);
+ }
+
+- /* Mark stdout as non-blocking to avoid people who does not close stdin
+- * nor consumes it in their startup script getting dwl frozen */
+- if (fd_set_nonblock(STDOUT_FILENO) < 0)
+- close(STDOUT_FILENO);
+-
+- printstatus();
++ drawbars();
+
+ /* At this point the outputs are initialized, choose initial selmon based on
+ * cursor position, and set default cursor image */
+@@ -2262,7 +2449,7 @@ setfloating(Client *c, int floating)
+ wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen
+ ? LyrFS : c->isfloating ? LyrFloat : LyrTile]);
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2285,7 +2472,7 @@ setfullscreen(Client *c, int fullscreen)
+ resize(c, c->prev, 0);
+ }
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2310,7 +2497,7 @@ setlayout(const Arg *arg)
+ selmon->lt[selmon->sellt] = (Layout *)arg->v;
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
+ arrange(selmon);
+- printstatus();
++ drawbar(selmon);
+ }
+
+ /* arg > 1.0 will set mfact absolutely */
+@@ -2383,6 +2570,7 @@ setup(void)
+ for (i = 0; i < (int)LENGTH(sig); i++)
+ sigaction(sig[i], &sa, NULL);
+
++
+ wlr_log_init(log_level, NULL);
+
+ /* The Wayland display is managed by libwayland. It handles accepting
+@@ -2569,6 +2757,11 @@ setup(void)
+
+ wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
+
++ drwl_init();
++
++ status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
++ STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
++
+ /* Make sure XWayland clients don't connect to the parent X server,
+ * e.g when running in the x11 backend or the wayland backend and the
+ * compositor has Xwayland support */
+@@ -2593,6 +2786,7 @@ void
+ spawn(const Arg *arg)
+ {
+ if (fork() == 0) {
++ close(STDIN_FILENO);
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+@@ -2611,6 +2805,30 @@ startdrag(struct wl_listener *listener, void *data)
+ LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
+ }
+
++int
++statusin(int fd, unsigned int mask, void *data)
++{
++ char status[1024];
++ ssize_t n;
++
++ if (mask & WL_EVENT_ERROR)
++ die("status in event error");
++ if (mask & WL_EVENT_HANGUP)
++ wl_event_source_remove(status_event_source);
++
++ n = read(fd, status, sizeof(status) - 1);
++ if (n < 0 && errno != EWOULDBLOCK)
++ die("read:");
++
++ status[n] = '\0';
++ status[strcspn(status, "\n")] = '\0';
++
++ strncpy(stext, status, sizeof(stext));
++ drawbars();
++
++ return 0;
++}
++
+ void
+ tag(const Arg *arg)
+ {
+@@ -2621,7 +2839,7 @@ tag(const Arg *arg)
+ sel->tags = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2666,6 +2884,14 @@ tile(Monitor *m)
+ }
+ }
+
++void
++togglebar(const Arg *arg)
++{
++ wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
++ !selmon->scene_buffer->node.enabled);
++ arrangelayers(selmon);
++}
++
+ void
+ togglefloating(const Arg *arg)
+ {
+@@ -2694,7 +2920,7 @@ toggletag(const Arg *arg)
+ sel->tags = newtags;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2707,7 +2933,7 @@ toggleview(const Arg *arg)
+ selmon->tagset[selmon->seltags] = newtagset;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2755,7 +2981,7 @@ unmapnotify(struct wl_listener *listener, void *data)
+ }
+
+ wlr_scene_node_destroy(&c->scene->node);
+- printstatus();
++ drawbars();
+ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+@@ -2855,6 +3081,13 @@ updatemons(struct wl_listener *listener, void *data)
+ }
+ }
+
++ if (stext[0] == '\0')
++ strncpy(stext, "dwl-"VERSION, sizeof(stext));
++ wl_list_for_each(m, &mons, link) {
++ updatebar(m);
++ drawbar(m);
++ }
++
+ /* FIXME: figure out why the cursor image is at 0,0 after turning all
+ * the monitors on.
+ * Move the cursor image where it used to be. It does not generate a
+@@ -2865,12 +3098,45 @@ updatemons(struct wl_listener *listener, void *data)
+ wlr_output_manager_v1_set_configuration(output_mgr, config);
+ }
+
++void
++updatebar(Monitor *m)
++{
++ size_t i;
++ int rw, rh;
++ char fontattrs[12];
++
++ wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
++ m->b.width = rw;
++ m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
++
++ wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
++
++ for (i = 0; i < LENGTH(m->pool); i++)
++ if (m->pool[i]) {
++ wlr_buffer_drop(&m->pool[i]->base);
++ m->pool[i] = NULL;
++ }
++
++ if (m->b.scale == m->wlr_output->scale && m->drw)
++ return;
++
++ drwl_font_destroy(m->drw->font);
++ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
++ if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
++ die("Could not load font");
++
++ m->b.scale = m->wlr_output->scale;
++ m->lrpad = m->drw->font->height;
++ m->b.height = m->drw->font->height + 2;
++ m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
++}
++
+ void
+ updatetitle(struct wl_listener *listener, void *data)
+ {
+ Client *c = wl_container_of(listener, c, set_title);
+ if (c == focustop(c->mon))
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2883,10 +3149,10 @@ urgent(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = 1;
+- printstatus();
++ drawbars();
+
+ if (client_surface(c)->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+@@ -2899,7 +3165,7 @@ view(const Arg *arg)
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2940,6 +3206,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ {
+ struct wlr_scene_node *node, *pnode;
+ struct wlr_surface *surface = NULL;
++ struct wlr_scene_surface *scene_surface = NULL;
+ Client *c = NULL;
+ LayerSurface *l = NULL;
+ int layer;
+@@ -2948,9 +3215,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
+ continue;
+
+- if (node->type == WLR_SCENE_NODE_BUFFER)
+- surface = wlr_scene_surface_try_from_buffer(
+- wlr_scene_buffer_from_node(node))->surface;
++ if (node->type == WLR_SCENE_NODE_BUFFER) {
++ scene_surface = wlr_scene_surface_try_from_buffer(
++ wlr_scene_buffer_from_node(node));
++ if (!scene_surface) continue;
++ surface = scene_surface->surface;
++ }
+ /* Walk the tree to find a node that knows the client */
+ for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
+ c = pnode->data;
+@@ -3089,10 +3359,10 @@ sethints(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
+- printstatus();
++ drawbars();
+
+ if (c->isurgent && surface && surface->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+--
+2.46.0
+
diff --git a/patches/bar/bar-0.7.patch b/patches/bar/bar-0.7.patch
new file mode 100644
index 0000000..523ca36
--- /dev/null
+++ b/patches/bar/bar-0.7.patch
@@ -0,0 +1,1245 @@
+From 1431cf1e9e03c8e59050af3b37514a6a2293d71d Mon Sep 17 00:00:00 2001
+From: sewn <sewn@disroot.org>
+Date: Fri, 23 Aug 2024 09:42:04 +0300
+Subject: [PATCH] Implement dwm bar clone
+
+---
+ Makefile | 2 +-
+ config.def.h | 31 +++-
+ drwl.h | 311 ++++++++++++++++++++++++++++++++++++
+ dwl.c | 442 +++++++++++++++++++++++++++++++++++++++++----------
+ 4 files changed, 691 insertions(+), 95 deletions(-)
+ create mode 100644 drwl.h
+
+diff --git a/Makefile b/Makefile
+index 3358bae..9bc67db 100644
+--- a/Makefile
++++ b/Makefile
+@@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement \
+ -Wfloat-conversion
+
+ # CFLAGS / LDFLAGS
+-PKGS = wlroots-0.18 wayland-server xkbcommon libinput $(XLIBS)
++PKGS = wlroots-0.18 wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS)
+ DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
+ LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
+
+diff --git a/config.def.h b/config.def.h
+index 22d2171..5d1dc2b 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -7,15 +7,21 @@
+ static const int sloppyfocus = 1; /* focus follows mouse */
+ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+-static const float rootcolor[] = COLOR(0x222222ff);
+-static const float bordercolor[] = COLOR(0x444444ff);
+-static const float focuscolor[] = COLOR(0x005577ff);
+-static const float urgentcolor[] = COLOR(0xff0000ff);
++static const int showbar = 1; /* 0 means no bar */
++static const int topbar = 1; /* 0 means bottom bar */
++static const char *fonts[] = {"monospace:size=10"};
++static const float rootcolor[] = COLOR(0x000000ff);
+ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
+ static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */
++static uint32_t colors[][3] = {
++ /* fg bg border */
++ [SchemeNorm] = { 0xbbbbbbff, 0x222222ff, 0x444444ff },
++ [SchemeSel] = { 0xeeeeeeff, 0x005577ff, 0x005577ff },
++ [SchemeUrg] = { 0, 0, 0x770000ff },
++};
+
+ /* tagging - TAGCOUNT must be no greater than 31 */
+-#define TAGCOUNT (9)
++static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+
+ /* logging */
+ static int log_level = WLR_ERROR;
+@@ -127,6 +133,7 @@ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
++ { MODKEY, XKB_KEY_b, togglebar, {0} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+@@ -170,7 +177,15 @@ static const Key keys[] = {
+ };
+
+ static const Button buttons[] = {
+- { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
+- { MODKEY, BTN_MIDDLE, togglefloating, {0} },
+- { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} },
++ { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} },
++ { ClkTitle, 0, BTN_MIDDLE, zoom, {0} },
++ { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} },
++ { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
++ { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} },
++ { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkTagBar, 0, BTN_LEFT, view, {0} },
++ { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} },
++ { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} },
++ { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} },
+ };
+diff --git a/drwl.h b/drwl.h
+new file mode 100644
+index 0000000..b06a736
+--- /dev/null
++++ b/drwl.h
+@@ -0,0 +1,311 @@
++/*
++ * drwl - https://codeberg.org/sewn/drwl
++ *
++ * Copyright (c) 2023-2024 sewn <sewn@disroot.org>
++ * Copyright (c) 2024 notchoc <notchoc@disroot.org>
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining
++ * a copy of this software and associated documentation files (the
++ * "Software"), to deal in the Software without restriction, including
++ * without limitation the rights to use, copy, modify, merge, publish,
++ * distribute, sublicense, and/or sell copies of the Software, and to
++ * permit persons to whom the Software is furnished to do so, subject to
++ * the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ * The UTF-8 Decoder included is from Bjoern Hoehrmann:
++ * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
++ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
++ */
++#pragma once
++
++#include <stdlib.h>
++#include <fcft/fcft.h>
++#include <pixman-1/pixman.h>
++
++enum { ColFg, ColBg, ColBorder }; /* colorscheme index */
++
++typedef struct fcft_font Fnt;
++typedef pixman_image_t Img;
++
++typedef struct {
++ Img *image;
++ Fnt *font;
++ uint32_t *scheme;
++} Drwl;
++
++#define UTF8_ACCEPT 0
++#define UTF8_REJECT 12
++#define UTF8_INVALID 0xFFFD
++
++static const uint8_t utf8d[] = {
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++
++ 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
++ 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
++ 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
++ 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
++ 12,36,12,12,12,12,12,12,12,12,12,12,
++};
++
++static inline uint32_t
++utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte)
++{
++ uint32_t type = utf8d[byte];
++
++ *codep = (*state != UTF8_ACCEPT) ?
++ (byte & 0x3fu) | (*codep << 6) :
++ (0xff >> type) & (byte);
++
++ *state = utf8d[256 + *state + type];
++ return *state;
++}
++
++static int
++drwl_init(void)
++{
++ fcft_set_scaling_filter(FCFT_SCALING_FILTER_LANCZOS3);
++ return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR);
++}
++
++static Drwl *
++drwl_create(void)
++{
++ Drwl *drwl;
++
++ if (!(drwl = calloc(1, sizeof(Drwl))))
++ return NULL;
++
++ return drwl;
++}
++
++static void
++drwl_setfont(Drwl *drwl, Fnt *font)
++{
++ if (drwl)
++ drwl->font = font;
++}
++
++static void
++drwl_setimage(Drwl *drwl, Img *image)
++{
++ if (drwl)
++ drwl->image = image;
++}
++
++static Fnt *
++drwl_font_create(Drwl *drwl, size_t count,
++ const char *names[static count], const char *attributes)
++{
++ Fnt *font = fcft_from_name(count, names, attributes);
++ if (drwl)
++ drwl_setfont(drwl, font);
++ return font;
++}
++
++static void
++drwl_font_destroy(Fnt *font)
++{
++ fcft_destroy(font);
++}
++
++static inline pixman_color_t
++convert_color(uint32_t clr)
++{
++ return (pixman_color_t){
++ ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ (clr & 0xFF) * 0x101
++ };
++}
++
++static void
++drwl_setscheme(Drwl *drwl, uint32_t *scm)
++{
++ if (drwl)
++ drwl->scheme = scm;
++}
++
++static Img *
++drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits)
++{
++ Img *image;
++ pixman_region32_t clip;
++
++ image = pixman_image_create_bits_no_clear(
++ PIXMAN_a8r8g8b8, w, h, bits, w * 4);
++ if (!image)
++ return NULL;
++ pixman_region32_init_rect(&clip, 0, 0, w, h);
++ pixman_image_set_clip_region32(image, &clip);
++ pixman_region32_fini(&clip);
++
++ if (drwl)
++ drwl_setimage(drwl, image);
++ return image;
++}
++
++static void
++drwl_rect(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ int filled, int invert)
++{
++ pixman_color_t clr;
++ if (!drwl || !drwl->scheme || !drwl->image)
++ return;
++
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ if (filled)
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1,
++ &(pixman_rectangle16_t){x, y, w, h});
++ else
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4,
++ (pixman_rectangle16_t[4]){
++ { x, y, w, 1 },
++ { x, y + h - 1, w, 1 },
++ { x, y, 1, h },
++ { x + w - 1, y, 1, h }});
++}
++
++static int
++drwl_text(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ unsigned int lpad, const char *text, int invert)
++{
++ int ty;
++ int render = x || y || w || h;
++ long x_kern;
++ uint32_t cp = 0, last_cp = 0, state;
++ pixman_color_t clr;
++ pixman_image_t *fg_pix = NULL;
++ int noellipsis = 0;
++ const struct fcft_glyph *glyph, *eg = NULL;
++ int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT;
++
++ if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font)
++ return 0;
++
++ if (!render) {
++ w = invert ? invert : ~invert;
++ } else {
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ fg_pix = pixman_image_create_solid_fill(&clr);
++
++ drwl_rect(drwl, x, y, w, h, 1, !invert);
++
++ x += lpad;
++ w -= lpad;
++ }
++
++ if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF)
++ fcft_subpixel_mode = FCFT_SUBPIXEL_NONE;
++
++ if (render)
++ eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode);
++
++ for (const char *p = text, *pp; pp = p, *p; p++) {
++ for (state = UTF8_ACCEPT; *p &&
++ utf8decode(&state, &cp, *p) > UTF8_REJECT; p++)
++ ;
++ if (!*p || state == UTF8_REJECT) {
++ cp = UTF8_INVALID;
++ if (p > pp)
++ p--;
++ }
++
++ glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode);
++ if (!glyph)
++ continue;
++
++ x_kern = 0;
++ if (last_cp)
++ fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL);
++ last_cp = cp;
++
++ ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent;
++
++ if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w &&
++ *(p + 1) != '\0') {
++ /* cannot fit ellipsis after current codepoint */
++ if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) {
++ noellipsis = 1;
++ } else {
++ w -= eg->advance.x;
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0,
++ x + eg->x, ty - eg->y, eg->width, eg->height);
++ }
++ }
++
++ if ((x_kern + glyph->advance.x) > w)
++ break;
++
++ x += x_kern;
++
++ if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)
++ /* pre-rendered glyphs (eg. emoji) */
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++ else if (render)
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++
++ x += glyph->advance.x;
++ w -= glyph->advance.x;
++ }
++
++ if (render)
++ pixman_image_unref(fg_pix);
++
++ return x + (render ? w : 0);
++}
++
++static unsigned int
++drwl_font_getwidth(Drwl *drwl, const char *text)
++{
++ if (!drwl || !drwl->font || !text)
++ return 0;
++ return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0);
++}
++
++static void
++drwl_image_destroy(Img *image)
++{
++ pixman_image_unref(image);
++}
++
++static void
++drwl_destroy(Drwl *drwl)
++{
++ if (drwl->font)
++ drwl_font_destroy(drwl->font);
++ if (drwl->image)
++ drwl_image_destroy(drwl->image);
++ free(drwl);
++}
++
++static void
++drwl_fini(void)
++{
++ fcft_fini();
++}
+diff --git a/dwl.c b/dwl.c
+index a2711f6..ece537a 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -5,6 +5,7 @@
+ #include <libinput.h>
+ #include <linux/input-event-codes.h>
+ #include <math.h>
++#include <libdrm/drm_fourcc.h>
+ #include <signal.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -58,6 +59,7 @@
+ #include <wlr/types/wlr_xdg_decoration_v1.h>
+ #include <wlr/types/wlr_xdg_output_v1.h>
+ #include <wlr/types/wlr_xdg_shell.h>
++#include <wlr/interfaces/wlr_buffer.h>
+ #include <wlr/util/log.h>
+ #include <wlr/util/region.h>
+ #include <xkbcommon/xkbcommon.h>
+@@ -68,6 +70,7 @@
+ #endif
+
+ #include "util.h"
++#include "drwl.h"
+
+ /* macros */
+ #define MAX(A, B) ((A) > (B) ? (A) : (B))
+@@ -76,14 +79,17 @@
+ #define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define END(A) ((A) + LENGTH(A))
+-#define TAGMASK ((1u << TAGCOUNT) - 1)
++#define TAGMASK ((1u << LENGTH(tags)) - 1)
+ #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
+ #define LISTEN_STATIC(E, H) do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
++#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
+
+ /* enums */
++enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
+ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
+ enum { XDGShell, LayerShell, X11 }; /* client types */
+ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
++enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
+ #ifdef XWAYLAND
+ enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
+ NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
+@@ -97,6 +103,7 @@ typedef union {
+ } Arg;
+
+ typedef struct {
++ unsigned int click;
+ unsigned int mod;
+ unsigned int button;
+ void (*func)(const Arg *);
+@@ -186,10 +193,19 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct {
++ struct wlr_buffer base;
++ struct wl_listener release;
++ bool busy;
++ Img *image;
++ uint32_t data[];
++} Buffer;
++
+ struct Monitor {
+ struct wl_list link;
+ struct wlr_output *wlr_output;
+ struct wlr_scene_output *scene_output;
++ struct wlr_scene_buffer *scene_buffer; /* bar buffer */
+ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wl_listener frame;
+ struct wl_listener destroy;
+@@ -197,6 +213,11 @@ struct Monitor {
+ struct wl_listener destroy_lock_surface;
+ struct wlr_session_lock_surface_v1 *lock_surface;
+ struct wlr_box m; /* monitor area, layout-relative */
++ struct {
++ int width, height;
++ int real_width, real_height; /* non-scaled */
++ float scale;
++ } b; /* bar area */
+ struct wlr_box w; /* window area, layout-relative */
+ struct wl_list layers[4]; /* LayerSurface.link */
+ const Layout *lt[2];
+@@ -208,6 +229,9 @@ struct Monitor {
+ int nmaster;
+ char ltsymbol[16];
+ int asleep;
++ Drwl *drw;
++ Buffer *pool[2];
++ int lrpad;
+ };
+
+ typedef struct {
+@@ -250,6 +274,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
+ struct wlr_box *usable_area, int exclusive);
+ static void arrangelayers(Monitor *m);
+ static void axisnotify(struct wl_listener *listener, void *data);
++static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
++static void bufdestroy(struct wlr_buffer *buffer);
++static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride);
++static void bufdataend(struct wlr_buffer *buffer);
++static Buffer *bufmon(Monitor *m);
++static void bufrelease(struct wl_listener *listener, void *data);
+ static void buttonpress(struct wl_listener *listener, void *data);
+ static void chvt(const Arg *arg);
+ static void checkidleinhibitor(struct wlr_surface *exclude);
+@@ -285,6 +316,8 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
+ static void destroysessionmgr(struct wl_listener *listener, void *data);
+ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
+ static Monitor *dirtomon(enum wlr_direction dir);
++static void drawbar(Monitor *m);
++static void drawbars(void);
+ static void focusclient(Client *c, int lift);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
+@@ -313,7 +346,6 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
+ static void outputmgrtest(struct wl_listener *listener, void *data);
+ static void pointerfocus(Client *c, struct wlr_surface *surface,
+ double sx, double sy, uint32_t time);
+-static void printstatus(void);
+ static void powermgrsetmode(struct wl_listener *listener, void *data);
+ static void quit(const Arg *arg);
+ static void rendermon(struct wl_listener *listener, void *data);
+@@ -335,9 +367,11 @@ static void setsel(struct wl_listener *listener, void *data);
+ static void setup(void);
+ static void spawn(const Arg *arg);
+ static void startdrag(struct wl_listener *listener, void *data);
++static int statusin(int fd, unsigned int mask, void *data);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *m);
++static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
+ static void togglefullscreen(const Arg *arg);
+ static void toggletag(const Arg *arg);
+@@ -346,6 +380,7 @@ static void unlocksession(struct wl_listener *listener, void *data);
+ static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
+ static void unmapnotify(struct wl_listener *listener, void *data);
+ static void updatemons(struct wl_listener *listener, void *data);
++static void updatebar(Monitor *m);
+ static void updatetitle(struct wl_listener *listener, void *data);
+ static void urgent(struct wl_listener *listener, void *data);
+ static void view(const Arg *arg);
+@@ -413,6 +448,15 @@ static struct wlr_box sgeom;
+ static struct wl_list mons;
+ static Monitor *selmon;
+
++static char stext[256];
++static struct wl_event_source *status_event_source;
++
++static const struct wlr_buffer_impl buffer_impl = {
++ .destroy = bufdestroy,
++ .begin_data_ptr_access = bufdatabegin,
++ .end_data_ptr_access = bufdataend,
++};
++
+ #ifdef XWAYLAND
+ static void activatex11(struct wl_listener *listener, void *data);
+ static void associatex11(struct wl_listener *listener, void *data);
+@@ -553,6 +597,11 @@ arrangelayers(Monitor *m)
+ if (!m->wlr_output->enabled)
+ return;
+
++ if (m->scene_buffer->node.enabled) {
++ usable_area.height -= m->b.real_height;
++ usable_area.y += topbar ? m->b.real_height : 0;
++ }
++
+ /* Arrange exclusive surfaces from top->bottom */
+ for (i = 3; i >= 0; i--)
+ arrangelayer(m, &m->layers[i], &usable_area, 1);
+@@ -595,17 +644,102 @@ axisnotify(struct wl_listener *listener, void *data)
+ event->delta_discrete, event->source, event->relative_direction);
+ }
+
++bool
++baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
++{
++ return true;
++}
++
++void
++bufdestroy(struct wlr_buffer *wlr_buffer)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++ if (buf->busy)
++ wl_list_remove(&buf->release.link);
++ drwl_image_destroy(buf->image);
++ free(buf);
++}
++
++bool
++bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++
++ if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
++
++ *data = buf->data;
++ *stride = wlr_buffer->width * 4;
++ *format = DRM_FORMAT_ARGB8888;
++
++ return true;
++}
++
++void
++bufdataend(struct wlr_buffer *wlr_buffer)
++{
++}
++
++Buffer *
++bufmon(Monitor *m)
++{
++ size_t i;
++ Buffer *buf = NULL;
++
++ for (i = 0; i < LENGTH(m->pool); i++) {
++ if (m->pool[i]) {
++ if (m->pool[i]->busy)
++ continue;
++ buf = m->pool[i];
++ break;
++ }
++
++ buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
++ buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
++ wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
++ m->pool[i] = buf;
++ break;
++ }
++ if (!buf)
++ return NULL;
++
++ buf->busy = true;
++ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
++ wlr_buffer_lock(&buf->base);
++ drwl_setimage(m->drw, buf->image);
++ return buf;
++}
++
++void
++bufrelease(struct wl_listener *listener, void *data)
++{
++ Buffer *buf = wl_container_of(listener, buf, release);
++ buf->busy = false;
++ wl_list_remove(&buf->release.link);
++}
++
+ void
+ buttonpress(struct wl_listener *listener, void *data)
+ {
++ unsigned int i = 0, x = 0;
++ double cx;
++ unsigned int click;
+ struct wlr_pointer_button_event *event = data;
+ struct wlr_keyboard *keyboard;
++ struct wlr_scene_node *node;
++ struct wlr_scene_buffer *buffer;
+ uint32_t mods;
++ Arg arg = {0};
+ Client *c;
+ const Button *b;
+
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+
++ click = ClkRoot;
++ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
++ if (c)
++ click = ClkClient;
++
+ switch (event->state) {
+ case WL_POINTER_BUTTON_STATE_PRESSED:
+ cursor_mode = CurPressed;
+@@ -613,17 +747,34 @@ buttonpress(struct wl_listener *listener, void *data)
+ if (locked)
+ break;
+
++ if (!c && !exclusive_focus &&
++ (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
++ (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
++ cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
++ do
++ x += TEXTW(selmon, tags[i]);
++ while (cx >= x && ++i < LENGTH(tags));
++ if (i < LENGTH(tags)) {
++ click = ClkTagBar;
++ arg.ui = 1 << i;
++ } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
++ click = ClkLtSymbol;
++ else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
++ click = ClkStatus;
++ } else
++ click = ClkTitle;
++ }
++
+ /* Change focus if the button was _pressed_ over a client */
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+- if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
++ if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ focusclient(c, 1);
+
+ keyboard = wlr_seat_get_keyboard(seat);
+ mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
+ for (b = buttons; b < END(buttons); b++) {
+- if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
+- event->button == b->button && b->func) {
+- b->func(&b->arg);
++ if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
++ b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
+ return;
+ }
+ }
+@@ -697,6 +848,8 @@ cleanup(void)
+ /* Destroy after the wayland display (when the monitors are already destroyed)
+ to avoid destroying them with an invalid scene output. */
+ wlr_scene_node_destroy(&scene->tree.node);
++
++ drwl_fini();
+ }
+
+ void
+@@ -712,6 +865,12 @@ cleanupmon(struct wl_listener *listener, void *data)
+ wlr_layer_surface_v1_destroy(l->layer_surface);
+ }
+
++ for (i = 0; i < LENGTH(m->pool); i++)
++ wlr_buffer_drop(&m->pool[i]->base);
++
++ drwl_setimage(m->drw, NULL);
++ drwl_destroy(m->drw);
++
+ wl_list_remove(&m->destroy.link);
+ wl_list_remove(&m->frame.link);
+ wl_list_remove(&m->link);
+@@ -722,6 +881,7 @@ cleanupmon(struct wl_listener *listener, void *data)
+
+ closemon(m);
+ wlr_scene_node_destroy(&m->fullscreen_bg->node);
++ wlr_scene_node_destroy(&m->scene_buffer->node);
+ free(m);
+ }
+
+@@ -751,7 +911,7 @@ closemon(Monitor *m)
+ setmon(c, selmon, c->tags);
+ }
+ focusclient(focustop(selmon), 1);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -1022,8 +1182,15 @@ createmon(struct wl_listener *listener, void *data)
+ wlr_output_commit_state(wlr_output, &state);
+ wlr_output_state_finish(&state);
+
++ if (!(m->drw = drwl_create()))
++ die("failed to create drwl context");
++
++ m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
++ m->scene_buffer->point_accepts_input = baracceptsinput;
++ updatebar(m);
++
+ wl_list_insert(&mons, &m->link);
+- printstatus();
++ drawbars();
+
+ /* The xdg-protocol specifies:
+ *
+@@ -1336,6 +1503,80 @@ dirtomon(enum wlr_direction dir)
+ return selmon;
+ }
+
++void
++drawbar(Monitor *m)
++{
++ int x, w, tw = 0;
++ int boxs = m->drw->font->height / 9;
++ int boxw = m->drw->font->height / 6 + 2;
++ uint32_t i, occ = 0, urg = 0;
++ Client *c;
++ Buffer *buf;
++
++ if (!m->scene_buffer->node.enabled)
++ return;
++ if (!(buf = bufmon(m)))
++ return;
++
++ /* draw status first so it can be overdrawn by tags later */
++ if (m == selmon) { /* status is only drawn on selected monitor */
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
++ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
++ }
++
++ wl_list_for_each(c, &clients, link) {
++ if (c->mon != m)
++ continue;
++ occ |= c->tags;
++ if (c->isurgent)
++ urg |= c->tags;
++ }
++ x = 0;
++ c = focustop(m);
++ for (i = 0; i < LENGTH(tags); i++) {
++ w = TEXTW(m, tags[i]);
++ drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
++ if (occ & 1 << i)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
++ m == selmon && c && c->tags & 1 << i,
++ urg & 1 << i);
++ x += w;
++ }
++ w = TEXTW(m, m->ltsymbol);
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
++
++ if ((w = m->b.width - tw - x) > m->b.height) {
++ if (c) {
++ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
++ if (c && c->isfloating)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
++ } else {
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
++ }
++ }
++
++ wlr_scene_buffer_set_dest_size(m->scene_buffer,
++ m->b.real_width, m->b.real_height);
++ wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
++ m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
++ wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
++ wlr_buffer_unlock(&buf->base);
++}
++
++void
++drawbars(void)
++{
++ Monitor *m = NULL;
++
++ wl_list_for_each(m, &mons, link)
++ drawbar(m);
++}
++
+ void
+ focusclient(Client *c, int lift)
+ {
+@@ -1371,13 +1612,13 @@ focusclient(Client *c, int lift)
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+ if (!exclusive_focus && !seat->drag)
+- client_set_border_color(c, focuscolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
+ }
+
+ /* Deactivate old client if focus is changing */
+ if (old && (!c || client_surface(c) != old)) {
+ /* If an overlay is focused, don't focus or activate the client,
+- * but only update its position in fstack to render its border with focuscolor
++ * but only update its position in fstack to render its border with its color
+ * and focus it after the overlay is closed. */
+ if (old_client_type == LayerShell && wlr_scene_node_coords(
+ &old_l->scene->node, &unused_lx, &unused_ly)
+@@ -1388,12 +1629,11 @@ focusclient(Client *c, int lift)
+ /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
+ * and probably other clients */
+ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
+- client_set_border_color(old_c, bordercolor);
+-
++ client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
+ client_activate_surface(old, 0);
+ }
+ }
+- printstatus();
++ drawbars();
+
+ if (!c) {
+ /* With no client, all we have left is to clear focus */
+@@ -1715,7 +1955,7 @@ mapnotify(struct wl_listener *listener, void *data)
+
+ for (i = 0; i < 4; i++) {
+ c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
+- c->isurgent ? urgentcolor : bordercolor);
++ (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
+ c->border[i]->node.data = c;
+ }
+
+@@ -1738,7 +1978,7 @@ mapnotify(struct wl_listener *listener, void *data)
+ } else {
+ applyrules(c);
+ }
+- printstatus();
++ drawbars();
+
+ unset_fullscreen:
+ m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
+@@ -2032,46 +2272,6 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
+ wlr_seat_pointer_notify_motion(seat, time, sx, sy);
+ }
+
+-void
+-printstatus(void)
+-{
+- Monitor *m = NULL;
+- Client *c;
+- uint32_t occ, urg, sel;
+- const char *appid, *title;
+-
+- wl_list_for_each(m, &mons, link) {
+- occ = urg = 0;
+- wl_list_for_each(c, &clients, link) {
+- if (c->mon != m)
+- continue;
+- occ |= c->tags;
+- if (c->isurgent)
+- urg |= c->tags;
+- }
+- if ((c = focustop(m))) {
+- title = client_get_title(c);
+- appid = client_get_appid(c);
+- printf("%s title %s\n", m->wlr_output->name, title ? title : broken);
+- printf("%s appid %s\n", m->wlr_output->name, appid ? appid : broken);
+- printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
+- printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
+- sel = c->tags;
+- } else {
+- printf("%s title \n", m->wlr_output->name);
+- printf("%s appid \n", m->wlr_output->name);
+- printf("%s fullscreen \n", m->wlr_output->name);
+- printf("%s floating \n", m->wlr_output->name);
+- sel = 0;
+- }
+-
+- printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
+- printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
+- m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
+- printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+- }
+- fflush(stdout);
+-}
+
+ void
+ powermgrsetmode(struct wl_listener *listener, void *data)
+@@ -2226,30 +2426,17 @@ run(char *startup_cmd)
+
+ /* Now that the socket exists and the backend is started, run the startup command */
+ if (startup_cmd) {
+- int piperw[2];
+- if (pipe(piperw) < 0)
+- die("startup: pipe:");
+ if ((child_pid = fork()) < 0)
+ die("startup: fork:");
+ if (child_pid == 0) {
++ close(STDIN_FILENO);
+ setsid();
+- dup2(piperw[0], STDIN_FILENO);
+- close(piperw[0]);
+- close(piperw[1]);
+ execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
+ die("startup: execl:");
+ }
+- dup2(piperw[1], STDOUT_FILENO);
+- close(piperw[1]);
+- close(piperw[0]);
+ }
+
+- /* Mark stdout as non-blocking to avoid people who does not close stdin
+- * nor consumes it in their startup script getting dwl frozen */
+- if (fd_set_nonblock(STDOUT_FILENO) < 0)
+- close(STDOUT_FILENO);
+-
+- printstatus();
++ drawbars();
+
+ /* At this point the outputs are initialized, choose initial selmon based on
+ * cursor position, and set default cursor image */
+@@ -2315,7 +2502,7 @@ setfloating(Client *c, int floating)
+ (p && p->isfullscreen) ? LyrFS
+ : c->isfloating ? LyrFloat : LyrTile]);
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2338,7 +2525,7 @@ setfullscreen(Client *c, int fullscreen)
+ resize(c, c->prev, 0);
+ }
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2363,7 +2550,7 @@ setlayout(const Arg *arg)
+ selmon->lt[selmon->sellt] = (Layout *)arg->v;
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
+ arrange(selmon);
+- printstatus();
++ drawbar(selmon);
+ }
+
+ /* arg > 1.0 will set mfact absolutely */
+@@ -2436,6 +2623,7 @@ setup(void)
+ for (i = 0; i < (int)LENGTH(sig); i++)
+ sigaction(sig[i], &sa, NULL);
+
++
+ wlr_log_init(log_level, NULL);
+
+ /* The Wayland display is managed by libwayland. It handles accepting
+@@ -2625,6 +2813,11 @@ setup(void)
+ LISTEN_STATIC(&output_mgr->events.apply, outputmgrapply);
+ LISTEN_STATIC(&output_mgr->events.test, outputmgrtest);
+
++ drwl_init();
++
++ status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
++ STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
++
+ /* Make sure XWayland clients don't connect to the parent X server,
+ * e.g when running in the x11 backend or the wayland backend and the
+ * compositor has Xwayland support */
+@@ -2649,6 +2842,7 @@ void
+ spawn(const Arg *arg)
+ {
+ if (fork() == 0) {
++ close(STDIN_FILENO);
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+@@ -2667,6 +2861,30 @@ startdrag(struct wl_listener *listener, void *data)
+ LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
+ }
+
++int
++statusin(int fd, unsigned int mask, void *data)
++{
++ char status[1024];
++ ssize_t n;
++
++ if (mask & WL_EVENT_ERROR)
++ die("status in event error");
++ if (mask & WL_EVENT_HANGUP)
++ wl_event_source_remove(status_event_source);
++
++ n = read(fd, status, sizeof(status) - 1);
++ if (n < 0 && errno != EWOULDBLOCK)
++ die("read:");
++
++ status[n] = '\0';
++ status[strcspn(status, "\n")] = '\0';
++
++ strncpy(stext, status, sizeof(stext));
++ drawbars();
++
++ return 0;
++}
++
+ void
+ tag(const Arg *arg)
+ {
+@@ -2677,7 +2895,7 @@ tag(const Arg *arg)
+ sel->tags = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2722,6 +2940,14 @@ tile(Monitor *m)
+ }
+ }
+
++void
++togglebar(const Arg *arg)
++{
++ wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
++ !selmon->scene_buffer->node.enabled);
++ arrangelayers(selmon);
++}
++
+ void
+ togglefloating(const Arg *arg)
+ {
+@@ -2750,7 +2976,7 @@ toggletag(const Arg *arg)
+ sel->tags = newtags;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2763,7 +2989,7 @@ toggleview(const Arg *arg)
+ selmon->tagset[selmon->seltags] = newtagset;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2811,7 +3037,7 @@ unmapnotify(struct wl_listener *listener, void *data)
+ }
+
+ wlr_scene_node_destroy(&c->scene->node);
+- printstatus();
++ drawbars();
+ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+@@ -2911,6 +3137,13 @@ updatemons(struct wl_listener *listener, void *data)
+ }
+ }
+
++ if (stext[0] == '\0')
++ strncpy(stext, "dwl-"VERSION, sizeof(stext));
++ wl_list_for_each(m, &mons, link) {
++ updatebar(m);
++ drawbar(m);
++ }
++
+ /* FIXME: figure out why the cursor image is at 0,0 after turning all
+ * the monitors on.
+ * Move the cursor image where it used to be. It does not generate a
+@@ -2921,12 +3154,45 @@ updatemons(struct wl_listener *listener, void *data)
+ wlr_output_manager_v1_set_configuration(output_mgr, config);
+ }
+
++void
++updatebar(Monitor *m)
++{
++ size_t i;
++ int rw, rh;
++ char fontattrs[12];
++
++ wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
++ m->b.width = rw;
++ m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
++
++ wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
++
++ for (i = 0; i < LENGTH(m->pool); i++)
++ if (m->pool[i]) {
++ wlr_buffer_drop(&m->pool[i]->base);
++ m->pool[i] = NULL;
++ }
++
++ if (m->b.scale == m->wlr_output->scale && m->drw)
++ return;
++
++ drwl_font_destroy(m->drw->font);
++ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
++ if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
++ die("Could not load font");
++
++ m->b.scale = m->wlr_output->scale;
++ m->lrpad = m->drw->font->height;
++ m->b.height = m->drw->font->height + 2;
++ m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
++}
++
+ void
+ updatetitle(struct wl_listener *listener, void *data)
+ {
+ Client *c = wl_container_of(listener, c, set_title);
+ if (c == focustop(c->mon))
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2939,10 +3205,10 @@ urgent(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = 1;
+- printstatus();
++ drawbars();
+
+ if (client_surface(c)->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+@@ -2955,7 +3221,7 @@ view(const Arg *arg)
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2996,6 +3262,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ {
+ struct wlr_scene_node *node, *pnode;
+ struct wlr_surface *surface = NULL;
++ struct wlr_scene_surface *scene_surface = NULL;
+ Client *c = NULL;
+ LayerSurface *l = NULL;
+ int layer;
+@@ -3004,9 +3271,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
+ continue;
+
+- if (node->type == WLR_SCENE_NODE_BUFFER)
+- surface = wlr_scene_surface_try_from_buffer(
+- wlr_scene_buffer_from_node(node))->surface;
++ if (node->type == WLR_SCENE_NODE_BUFFER) {
++ scene_surface = wlr_scene_surface_try_from_buffer(
++ wlr_scene_buffer_from_node(node));
++ if (!scene_surface) continue;
++ surface = scene_surface->surface;
++ }
+ /* Walk the tree to find a node that knows the client */
+ for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
+ c = pnode->data;
+@@ -3145,10 +3415,10 @@ sethints(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
+- printstatus();
++ drawbars();
+
+ if (c->isurgent && surface && surface->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+--
+2.46.0
+
diff --git a/patches/bar/bar.patch b/patches/bar/bar.patch
new file mode 100644
index 0000000..e098118
--- /dev/null
+++ b/patches/bar/bar.patch
@@ -0,0 +1,1271 @@
+From d6a2c4e7f0d3108c7a8a1ad6e76a62e854b2f8e1 Mon Sep 17 00:00:00 2001
+From: sewn <sewn@disroot.org>
+Date: Mon, 5 Jan 2026 16:51:14 +0300
+Subject: [PATCH] Implement dwm bar clone
+
+---
+ Makefile | 2 +-
+ config.def.h | 33 ++--
+ drwl.h | 310 +++++++++++++++++++++++++++++++++++
+ dwl.c | 444 +++++++++++++++++++++++++++++++++++++++++----------
+ 4 files changed, 697 insertions(+), 92 deletions(-)
+ create mode 100644 drwl.h
+
+diff --git a/Makefile b/Makefile
+index 578194f..279b1c0 100644
+--- a/Makefile
++++ b/Makefile
+@@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -Wpedantic -Wall -Wextra -Wdeclaration-after-statement \
+ -Wfloat-conversion
+
+ # CFLAGS / LDFLAGS
+-PKGS = wayland-server xkbcommon libinput $(XLIBS)
++PKGS = wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS)
+ DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(WLR_INCS) $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
+ LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(WLR_LIBS) -lm $(LIBS)
+
+diff --git a/config.def.h b/config.def.h
+index 8a6eda0..7da50d2 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -7,15 +7,21 @@
+ static const int sloppyfocus = 1; /* focus follows mouse */
+ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+-static const float rootcolor[] = COLOR(0x222222ff);
+-static const float bordercolor[] = COLOR(0x444444ff);
+-static const float focuscolor[] = COLOR(0x005577ff);
+-static const float urgentcolor[] = COLOR(0xff0000ff);
++static const int showbar = 1; /* 0 means no bar */
++static const int topbar = 1; /* 0 means bottom bar */
++static const char *fonts[] = {"monospace:size=10"};
++static const float rootcolor[] = COLOR(0x000000ff);
+ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
+ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */
++static uint32_t colors[][3] = {
++ /* fg bg border */
++ [SchemeNorm] = { 0xbbbbbbff, 0x222222ff, 0x444444ff },
++ [SchemeSel] = { 0xeeeeeeff, 0x005577ff, 0x005577ff },
++ [SchemeUrg] = { 0, 0, 0x770000ff },
++};
+
+-/* tagging - TAGCOUNT must be no greater than 31 */
+-#define TAGCOUNT (9)
++/* tagging */
++static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+
+ /* logging */
+ static int log_level = WLR_ERROR;
+@@ -123,6 +129,7 @@ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
++ { MODKEY, XKB_KEY_b, togglebar, {0} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+@@ -166,7 +173,15 @@ static const Key keys[] = {
+ };
+
+ static const Button buttons[] = {
+- { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
+- { MODKEY, BTN_MIDDLE, togglefloating, {0} },
+- { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} },
++ { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} },
++ { ClkTitle, 0, BTN_MIDDLE, zoom, {0} },
++ { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} },
++ { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
++ { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} },
++ { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
++ { ClkTagBar, 0, BTN_LEFT, view, {0} },
++ { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} },
++ { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} },
++ { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} },
+ };
+diff --git a/drwl.h b/drwl.h
+new file mode 100644
+index 0000000..21afd21
+--- /dev/null
++++ b/drwl.h
+@@ -0,0 +1,310 @@
++/*
++ * drwl - https://codeberg.org/sewn/drwl
++ *
++ * Copyright (c) 2023-2025 sewn <sewn@disroot.org>
++ * Copyright (c) 2024 notchoc <notchoc@disroot.org>
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining
++ * a copy of this software and associated documentation files (the
++ * "Software"), to deal in the Software without restriction, including
++ * without limitation the rights to use, copy, modify, merge, publish,
++ * distribute, sublicense, and/or sell copies of the Software, and to
++ * permit persons to whom the Software is furnished to do so, subject to
++ * the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ * The UTF-8 Decoder included is from Bjoern Hoehrmann:
++ * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
++ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
++ */
++#pragma once
++
++#include <stdlib.h>
++#include <fcft/fcft.h>
++#include <pixman-1/pixman.h>
++
++enum { ColFg, ColBg, ColBorder }; /* colorscheme index */
++
++typedef struct fcft_font Fnt;
++typedef pixman_image_t Img;
++
++typedef struct {
++ Img *image;
++ Fnt *font;
++ uint32_t *scheme;
++} Drwl;
++
++#define UTF8_ACCEPT 0
++#define UTF8_REJECT 12
++#define UTF8_INVALID 0xFFFD
++
++static const uint8_t utf8d[] = {
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++ 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,
++
++ 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
++ 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
++ 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
++ 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
++ 12,36,12,12,12,12,12,12,12,12,12,12,
++};
++
++static inline uint32_t
++utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte)
++{
++ uint32_t type = utf8d[byte];
++
++ *codep = (*state != UTF8_ACCEPT) ?
++ (byte & 0x3fu) | (*codep << 6) :
++ (0xff >> type) & (byte);
++
++ *state = utf8d[256 + *state + type];
++ return *state;
++}
++
++static int
++drwl_init(void)
++{
++ return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR);
++}
++
++static Drwl *
++drwl_create(void)
++{
++ Drwl *drwl;
++
++ if (!(drwl = calloc(1, sizeof(Drwl))))
++ return NULL;
++
++ return drwl;
++}
++
++static void
++drwl_setfont(Drwl *drwl, Fnt *font)
++{
++ if (drwl)
++ drwl->font = font;
++}
++
++static void
++drwl_setimage(Drwl *drwl, Img *image)
++{
++ if (drwl)
++ drwl->image = image;
++}
++
++static Fnt *
++drwl_font_create(Drwl *drwl, size_t count,
++ const char *names[static count], const char *attributes)
++{
++ Fnt *font = fcft_from_name(count, names, attributes);
++ if (drwl)
++ drwl_setfont(drwl, font);
++ return font;
++}
++
++static void
++drwl_font_destroy(Fnt *font)
++{
++ fcft_destroy(font);
++}
++
++static inline pixman_color_t
++convert_color(uint32_t clr)
++{
++ return (pixman_color_t){
++ ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF,
++ (clr & 0xFF) * 0x101
++ };
++}
++
++static void
++drwl_setscheme(Drwl *drwl, uint32_t *scm)
++{
++ if (drwl)
++ drwl->scheme = scm;
++}
++
++static Img *
++drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits)
++{
++ Img *image;
++ pixman_region32_t clip;
++
++ image = pixman_image_create_bits_no_clear(
++ PIXMAN_a8r8g8b8, w, h, bits, w * 4);
++ if (!image)
++ return NULL;
++ pixman_region32_init_rect(&clip, 0, 0, w, h);
++ pixman_image_set_clip_region32(image, &clip);
++ pixman_region32_fini(&clip);
++
++ if (drwl)
++ drwl_setimage(drwl, image);
++ return image;
++}
++
++static void
++drwl_rect(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ int filled, int invert)
++{
++ pixman_color_t clr;
++ if (!drwl || !drwl->scheme || !drwl->image)
++ return;
++
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ if (filled)
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1,
++ &(pixman_rectangle16_t){x, y, w, h});
++ else
++ pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4,
++ (pixman_rectangle16_t[4]){
++ { x, y, w, 1 },
++ { x, y + h - 1, w, 1 },
++ { x, y, 1, h },
++ { x + w - 1, y, 1, h }});
++}
++
++static int
++drwl_text(Drwl *drwl,
++ int x, int y, unsigned int w, unsigned int h,
++ unsigned int lpad, const char *text, int invert)
++{
++ int ty;
++ int render = x || y || w || h;
++ long x_kern;
++ uint32_t cp = 0, last_cp = 0, state;
++ pixman_color_t clr;
++ pixman_image_t *fg_pix = NULL;
++ int noellipsis = 0;
++ const struct fcft_glyph *glyph, *eg = NULL;
++ int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT;
++
++ if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font)
++ return 0;
++
++ if (!render) {
++ w = invert ? invert : ~invert;
++ } else {
++ clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]);
++ fg_pix = pixman_image_create_solid_fill(&clr);
++
++ drwl_rect(drwl, x, y, w, h, 1, !invert);
++
++ x += lpad;
++ w -= lpad;
++ }
++
++ if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF)
++ fcft_subpixel_mode = FCFT_SUBPIXEL_NONE;
++
++ if (render)
++ eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode);
++
++ for (const char *p = text, *pp; pp = p, *p; p++) {
++ for (state = UTF8_ACCEPT; *p &&
++ utf8decode(&state, &cp, *p) > UTF8_REJECT; p++)
++ ;
++ if (!*p || state == UTF8_REJECT) {
++ cp = UTF8_INVALID;
++ if (p > pp)
++ p--;
++ }
++
++ glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode);
++ if (!glyph)
++ continue;
++
++ x_kern = 0;
++ if (last_cp)
++ fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL);
++ last_cp = cp;
++
++ ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent;
++
++ if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w &&
++ *(p + 1) != '\0') {
++ /* cannot fit ellipsis after current codepoint */
++ if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) {
++ noellipsis = 1;
++ } else {
++ w -= eg->advance.x;
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0,
++ x + eg->x, ty - eg->y, eg->width, eg->height);
++ }
++ }
++
++ if ((x_kern + glyph->advance.x) > w)
++ break;
++
++ x += x_kern;
++
++ if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8)
++ /* pre-rendered glyphs (eg. emoji) */
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++ else if (render)
++ pixman_image_composite32(
++ PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0,
++ x + glyph->x, ty - glyph->y, glyph->width, glyph->height);
++
++ x += glyph->advance.x;
++ w -= glyph->advance.x;
++ }
++
++ if (render)
++ pixman_image_unref(fg_pix);
++
++ return x + (render ? w : 0);
++}
++
++static unsigned int
++drwl_font_getwidth(Drwl *drwl, const char *text)
++{
++ if (!drwl || !drwl->font || !text)
++ return 0;
++ return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0);
++}
++
++static void
++drwl_image_destroy(Img *image)
++{
++ pixman_image_unref(image);
++}
++
++static void
++drwl_destroy(Drwl *drwl)
++{
++ if (drwl->font)
++ drwl_font_destroy(drwl->font);
++ if (drwl->image)
++ drwl_image_destroy(drwl->image);
++ free(drwl);
++}
++
++static void
++drwl_fini(void)
++{
++ fcft_fini();
++}
+diff --git a/dwl.c b/dwl.c
+index 44f3ad9..7b2abf5 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -1,10 +1,12 @@
+ /*
+ * See LICENSE file for copyright and license details.
+ */
++#include <fcntl.h>
+ #include <getopt.h>
+ #include <libinput.h>
+ #include <linux/input-event-codes.h>
+ #include <math.h>
++#include <libdrm/drm_fourcc.h>
+ #include <signal.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -59,6 +61,7 @@
+ #include <wlr/types/wlr_xdg_decoration_v1.h>
+ #include <wlr/types/wlr_xdg_output_v1.h>
+ #include <wlr/types/wlr_xdg_shell.h>
++#include <wlr/interfaces/wlr_buffer.h>
+ #include <wlr/util/log.h>
+ #include <wlr/util/region.h>
+ #include <xkbcommon/xkbcommon.h>
+@@ -69,6 +72,7 @@
+ #endif
+
+ #include "util.h"
++#include "drwl.h"
+
+ /* macros */
+ #define MAX(A, B) ((A) > (B) ? (A) : (B))
+@@ -77,14 +81,17 @@
+ #define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define END(A) ((A) + LENGTH(A))
+-#define TAGMASK ((1u << TAGCOUNT) - 1)
++#define TAGMASK ((1u << LENGTH(tags)) - 1)
+ #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
+ #define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
++#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
+
+ /* enums */
++enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
+ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
+ enum { XDGShell, LayerShell, X11 }; /* client types */
+ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
++enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
+
+ typedef union {
+ int i;
+@@ -94,6 +101,7 @@ typedef union {
+ } Arg;
+
+ typedef struct {
++ unsigned int click;
+ unsigned int mod;
+ unsigned int button;
+ void (*func)(const Arg *);
+@@ -183,10 +191,19 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct {
++ struct wlr_buffer base;
++ struct wl_listener release;
++ bool busy;
++ Img *image;
++ uint32_t data[];
++} Buffer;
++
+ struct Monitor {
+ struct wl_list link;
+ struct wlr_output *wlr_output;
+ struct wlr_scene_output *scene_output;
++ struct wlr_scene_buffer *scene_buffer; /* bar buffer */
+ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wl_listener frame;
+ struct wl_listener destroy;
+@@ -194,6 +211,11 @@ struct Monitor {
+ struct wl_listener destroy_lock_surface;
+ struct wlr_session_lock_surface_v1 *lock_surface;
+ struct wlr_box m; /* monitor area, layout-relative */
++ struct {
++ int width, height;
++ int real_width, real_height; /* non-scaled */
++ float scale;
++ } b; /* bar area */
+ struct wlr_box w; /* window area, layout-relative */
+ struct wl_list layers[4]; /* LayerSurface.link */
+ const Layout *lt[2];
+@@ -205,6 +227,9 @@ struct Monitor {
+ int nmaster;
+ char ltsymbol[16];
+ int asleep;
++ Drwl *drw;
++ Buffer *pool[2];
++ int lrpad;
+ };
+
+ typedef struct {
+@@ -247,6 +272,13 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
+ struct wlr_box *usable_area, int exclusive);
+ static void arrangelayers(Monitor *m);
+ static void axisnotify(struct wl_listener *listener, void *data);
++static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
++static void bufdestroy(struct wlr_buffer *buffer);
++static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride);
++static void bufdataend(struct wlr_buffer *buffer);
++static Buffer *bufmon(Monitor *m);
++static void bufrelease(struct wl_listener *listener, void *data);
+ static void buttonpress(struct wl_listener *listener, void *data);
+ static void chvt(const Arg *arg);
+ static void checkidleinhibitor(struct wlr_surface *exclude);
+@@ -282,6 +314,8 @@ static void destroypointerconstraint(struct wl_listener *listener, void *data);
+ static void destroysessionlock(struct wl_listener *listener, void *data);
+ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
+ static Monitor *dirtomon(enum wlr_direction dir);
++static void drawbar(Monitor *m);
++static void drawbars(void);
+ static void focusclient(Client *c, int lift);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
+@@ -310,7 +344,6 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int
+ static void outputmgrtest(struct wl_listener *listener, void *data);
+ static void pointerfocus(Client *c, struct wlr_surface *surface,
+ double sx, double sy, uint32_t time);
+-static void printstatus(void);
+ static void powermgrsetmode(struct wl_listener *listener, void *data);
+ static void quit(const Arg *arg);
+ static void rendermon(struct wl_listener *listener, void *data);
+@@ -331,9 +364,11 @@ static void setsel(struct wl_listener *listener, void *data);
+ static void setup(void);
+ static void spawn(const Arg *arg);
+ static void startdrag(struct wl_listener *listener, void *data);
++static int statusin(int fd, unsigned int mask, void *data);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *m);
++static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
+ static void togglefullscreen(const Arg *arg);
+ static void toggletag(const Arg *arg);
+@@ -342,6 +377,7 @@ static void unlocksession(struct wl_listener *listener, void *data);
+ static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
+ static void unmapnotify(struct wl_listener *listener, void *data);
+ static void updatemons(struct wl_listener *listener, void *data);
++static void updatebar(Monitor *m);
+ static void updatetitle(struct wl_listener *listener, void *data);
+ static void urgent(struct wl_listener *listener, void *data);
+ static void view(const Arg *arg);
+@@ -406,6 +442,15 @@ static struct wlr_box sgeom;
+ static struct wl_list mons;
+ static Monitor *selmon;
+
++static char stext[256];
++static struct wl_event_source *status_event_source;
++
++static const struct wlr_buffer_impl buffer_impl = {
++ .destroy = bufdestroy,
++ .begin_data_ptr_access = bufdatabegin,
++ .end_data_ptr_access = bufdataend,
++};
++
+ /* global event handlers */
+ static struct wl_listener cursor_axis = {.notify = axisnotify};
+ static struct wl_listener cursor_button = {.notify = buttonpress};
+@@ -521,7 +566,7 @@ arrange(Monitor *m)
+ wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
+ (c = focustop(m)) && c->isfullscreen);
+
+- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
++ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
+
+ /* We move all clients (except fullscreen and unmanaged) to LyrTile while
+ * in floating layout to avoid "real" floating clients be always on top */
+@@ -576,6 +621,11 @@ arrangelayers(Monitor *m)
+ if (!m->wlr_output->enabled)
+ return;
+
++ if (m->scene_buffer->node.enabled) {
++ usable_area.height -= m->b.real_height;
++ usable_area.y += topbar ? m->b.real_height : 0;
++ }
++
+ /* Arrange exclusive surfaces from top->bottom */
+ for (i = 3; i >= 0; i--)
+ arrangelayer(m, &m->layers[i], &usable_area, 1);
+@@ -618,17 +668,102 @@ axisnotify(struct wl_listener *listener, void *data)
+ event->delta_discrete, event->source, event->relative_direction);
+ }
+
++bool
++baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
++{
++ return true;
++}
++
++void
++bufdestroy(struct wlr_buffer *wlr_buffer)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++ if (buf->busy)
++ wl_list_remove(&buf->release.link);
++ drwl_image_destroy(buf->image);
++ free(buf);
++}
++
++bool
++bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
++ void **data, uint32_t *format, size_t *stride)
++{
++ Buffer *buf = wl_container_of(wlr_buffer, buf, base);
++
++ if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
++
++ *data = buf->data;
++ *stride = wlr_buffer->width * 4;
++ *format = DRM_FORMAT_ARGB8888;
++
++ return true;
++}
++
++void
++bufdataend(struct wlr_buffer *wlr_buffer)
++{
++}
++
++Buffer *
++bufmon(Monitor *m)
++{
++ size_t i;
++ Buffer *buf = NULL;
++
++ for (i = 0; i < LENGTH(m->pool); i++) {
++ if (m->pool[i]) {
++ if (m->pool[i]->busy)
++ continue;
++ buf = m->pool[i];
++ break;
++ }
++
++ buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height));
++ buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data);
++ wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height);
++ m->pool[i] = buf;
++ break;
++ }
++ if (!buf)
++ return NULL;
++
++ buf->busy = true;
++ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
++ wlr_buffer_lock(&buf->base);
++ drwl_setimage(m->drw, buf->image);
++ return buf;
++}
++
++void
++bufrelease(struct wl_listener *listener, void *data)
++{
++ Buffer *buf = wl_container_of(listener, buf, release);
++ buf->busy = false;
++ wl_list_remove(&buf->release.link);
++}
++
+ void
+ buttonpress(struct wl_listener *listener, void *data)
+ {
++ unsigned int i = 0, x = 0;
++ double cx;
++ unsigned int click;
+ struct wlr_pointer_button_event *event = data;
+ struct wlr_keyboard *keyboard;
++ struct wlr_scene_node *node;
++ struct wlr_scene_buffer *buffer;
+ uint32_t mods;
++ Arg arg = {0};
+ Client *c;
+ const Button *b;
+
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+
++ click = ClkRoot;
++ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
++ if (c)
++ click = ClkClient;
++
+ switch (event->state) {
+ case WL_POINTER_BUTTON_STATE_PRESSED:
+ cursor_mode = CurPressed;
+@@ -636,17 +771,34 @@ buttonpress(struct wl_listener *listener, void *data)
+ if (locked)
+ break;
+
++ if (!c && !exclusive_focus &&
++ (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) &&
++ (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
++ cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
++ do
++ x += TEXTW(selmon, tags[i]);
++ while (cx >= x && ++i < LENGTH(tags));
++ if (i < LENGTH(tags)) {
++ click = ClkTagBar;
++ arg.ui = 1 << i;
++ } else if (cx < x + TEXTW(selmon, selmon->ltsymbol))
++ click = ClkLtSymbol;
++ else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) {
++ click = ClkStatus;
++ } else
++ click = ClkTitle;
++ }
++
+ /* Change focus if the button was _pressed_ over a client */
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+- if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
++ if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ focusclient(c, 1);
+
+ keyboard = wlr_seat_get_keyboard(seat);
+ mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
+ for (b = buttons; b < END(buttons); b++) {
+- if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
+- event->button == b->button && b->func) {
+- b->func(&b->arg);
++ if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) {
++ b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg);
+ return;
+ }
+ }
+@@ -721,6 +873,8 @@ cleanup(void)
+ /* Destroy after the wayland display (when the monitors are already destroyed)
+ to avoid destroying them with an invalid scene output. */
+ wlr_scene_node_destroy(&scene->tree.node);
++
++ drwl_fini();
+ }
+
+ void
+@@ -736,6 +890,12 @@ cleanupmon(struct wl_listener *listener, void *data)
+ wlr_layer_surface_v1_destroy(l->layer_surface);
+ }
+
++ for (i = 0; i < LENGTH(m->pool); i++)
++ wlr_buffer_drop(&m->pool[i]->base);
++
++ drwl_setimage(m->drw, NULL);
++ drwl_destroy(m->drw);
++
+ wl_list_remove(&m->destroy.link);
+ wl_list_remove(&m->frame.link);
+ wl_list_remove(&m->link);
+@@ -748,6 +908,7 @@ cleanupmon(struct wl_listener *listener, void *data)
+
+ closemon(m);
+ wlr_scene_node_destroy(&m->fullscreen_bg->node);
++ wlr_scene_node_destroy(&m->scene_buffer->node);
+ free(m);
+ }
+
+@@ -814,7 +975,7 @@ closemon(Monitor *m)
+ setmon(c, selmon, c->tags);
+ }
+ focusclient(focustop(selmon), 1);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -1066,7 +1227,7 @@ createmon(struct wl_listener *listener, void *data)
+ m->nmaster = r->nmaster;
+ m->lt[0] = r->lt;
+ m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]];
+- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
++ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol));
+ wlr_output_state_set_scale(&state, r->scale);
+ wlr_output_state_set_transform(&state, r->rr);
+ break;
+@@ -1088,8 +1249,15 @@ createmon(struct wl_listener *listener, void *data)
+ wlr_output_commit_state(wlr_output, &state);
+ wlr_output_state_finish(&state);
+
++ if (!(m->drw = drwl_create()))
++ die("failed to create drwl context");
++
++ m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL);
++ m->scene_buffer->point_accepts_input = baracceptsinput;
++ updatebar(m);
++
+ wl_list_insert(&mons, &m->link);
+- printstatus();
++ drawbars();
+
+ /* The xdg-protocol specifies:
+ *
+@@ -1399,6 +1567,80 @@ dirtomon(enum wlr_direction dir)
+ return selmon;
+ }
+
++void
++drawbar(Monitor *m)
++{
++ int x, w, tw = 0;
++ int boxs = m->drw->font->height / 9;
++ int boxw = m->drw->font->height / 6 + 2;
++ uint32_t i, occ = 0, urg = 0;
++ Client *c;
++ Buffer *buf;
++
++ if (!m->scene_buffer->node.enabled)
++ return;
++ if (!(buf = bufmon(m)))
++ return;
++
++ /* draw status first so it can be overdrawn by tags later */
++ if (m == selmon) { /* status is only drawn on selected monitor */
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
++ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
++ }
++
++ wl_list_for_each(c, &clients, link) {
++ if (c->mon != m)
++ continue;
++ occ |= c->tags;
++ if (c->isurgent)
++ urg |= c->tags;
++ }
++ x = 0;
++ c = focustop(m);
++ for (i = 0; i < LENGTH(tags); i++) {
++ w = TEXTW(m, tags[i]);
++ drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i);
++ if (occ & 1 << i)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw,
++ m == selmon && c && c->tags & 1 << i,
++ urg & 1 << i);
++ x += w;
++ }
++ w = TEXTW(m, m->ltsymbol);
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
++
++ if ((w = m->b.width - tw - x) > m->b.height) {
++ if (c) {
++ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0);
++ if (c && c->isfloating)
++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
++ } else {
++ drwl_setscheme(m->drw, colors[SchemeNorm]);
++ drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1);
++ }
++ }
++
++ wlr_scene_buffer_set_dest_size(m->scene_buffer,
++ m->b.real_width, m->b.real_height);
++ wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x,
++ m->m.y + (topbar ? 0 : m->m.height - m->b.real_height));
++ wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base);
++ wlr_buffer_unlock(&buf->base);
++}
++
++void
++drawbars(void)
++{
++ Monitor *m = NULL;
++
++ wl_list_for_each(m, &mons, link)
++ drawbar(m);
++}
++
+ void
+ focusclient(Client *c, int lift)
+ {
+@@ -1433,13 +1675,13 @@ focusclient(Client *c, int lift)
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+ if (!exclusive_focus && !seat->drag)
+- client_set_border_color(c, focuscolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder]));
+ }
+
+ /* Deactivate old client if focus is changing */
+ if (old && (!c || client_surface(c) != old)) {
+ /* If an overlay is focused, don't focus or activate the client,
+- * but only update its position in fstack to render its border with focuscolor
++ * but only update its position in fstack to render its border with its color
+ * and focus it after the overlay is closed. */
+ if (old_client_type == LayerShell && wlr_scene_node_coords(
+ &old_l->scene->node, &unused_lx, &unused_ly)
+@@ -1450,12 +1692,11 @@ focusclient(Client *c, int lift)
+ /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
+ * and probably other clients */
+ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
+- client_set_border_color(old_c, bordercolor);
+-
++ client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder]));
+ client_activate_surface(old, 0);
+ }
+ }
+- printstatus();
++ drawbars();
+
+ if (!c) {
+ /* With no client, all we have left is to clear focus */
+@@ -1769,7 +2010,7 @@ mapnotify(struct wl_listener *listener, void *data)
+
+ for (i = 0; i < 4; i++) {
+ c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
+- c->isurgent ? urgentcolor : bordercolor);
++ (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder]));
+ c->border[i]->node.data = c;
+ }
+
+@@ -1792,7 +2033,7 @@ mapnotify(struct wl_listener *listener, void *data)
+ } else {
+ applyrules(c);
+ }
+- printstatus();
++ drawbars();
+
+ unset_fullscreen:
+ m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
+@@ -2085,44 +2326,6 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
+ wlr_seat_pointer_notify_motion(seat, time, sx, sy);
+ }
+
+-void
+-printstatus(void)
+-{
+- Monitor *m = NULL;
+- Client *c;
+- uint32_t occ, urg, sel;
+-
+- wl_list_for_each(m, &mons, link) {
+- occ = urg = 0;
+- wl_list_for_each(c, &clients, link) {
+- if (c->mon != m)
+- continue;
+- occ |= c->tags;
+- if (c->isurgent)
+- urg |= c->tags;
+- }
+- if ((c = focustop(m))) {
+- printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
+- printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
+- printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
+- printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
+- sel = c->tags;
+- } else {
+- printf("%s title \n", m->wlr_output->name);
+- printf("%s appid \n", m->wlr_output->name);
+- printf("%s fullscreen \n", m->wlr_output->name);
+- printf("%s floating \n", m->wlr_output->name);
+- sel = 0;
+- }
+-
+- printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
+- printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
+- m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
+- printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+- }
+- fflush(stdout);
+-}
+-
+ void
+ powermgrsetmode(struct wl_listener *listener, void *data)
+ {
+@@ -2251,22 +2454,14 @@ run(char *startup_cmd)
+
+ /* Now that the socket exists and the backend is started, run the startup command */
+ if (startup_cmd) {
+- int piperw[2];
+- if (pipe(piperw) < 0)
+- die("startup: pipe:");
+ if ((child_pid = fork()) < 0)
+ die("startup: fork:");
+ if (child_pid == 0) {
++ close(STDIN_FILENO);
+ setsid();
+- dup2(piperw[0], STDIN_FILENO);
+- close(piperw[0]);
+- close(piperw[1]);
+ execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
+ die("startup: execl:");
+ }
+- dup2(piperw[1], STDOUT_FILENO);
+- close(piperw[1]);
+- close(piperw[0]);
+ }
+
+ /* Mark stdout as non-blocking to avoid the startup script
+@@ -2276,7 +2471,7 @@ run(char *startup_cmd)
+ if (fd_set_nonblock(STDOUT_FILENO) < 0)
+ close(STDOUT_FILENO);
+
+- printstatus();
++ drawbars();
+
+ /* At this point the outputs are initialized, choose initial selmon based on
+ * cursor position, and set default cursor image */
+@@ -2342,7 +2537,7 @@ setfloating(Client *c, int floating)
+ (p && p->isfullscreen) ? LyrFS
+ : c->isfloating ? LyrFloat : LyrTile]);
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2365,7 +2560,7 @@ setfullscreen(Client *c, int fullscreen)
+ resize(c, c->prev, 0);
+ }
+ arrange(c->mon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2377,9 +2572,9 @@ setlayout(const Arg *arg)
+ selmon->sellt ^= 1;
+ if (arg && arg->v)
+ selmon->lt[selmon->sellt] = (Layout *)arg->v;
+- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
++ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol));
+ arrange(selmon);
+- printstatus();
++ drawbar(selmon);
+ }
+
+ /* arg > 1.0 will set mfact absolutely */
+@@ -2452,6 +2647,7 @@ setup(void)
+ for (i = 0; i < (int)LENGTH(sig); i++)
+ sigaction(sig[i], &sa, NULL);
+
++
+ wlr_log_init(log_level, NULL);
+
+ /* The Wayland display is managed by libwayland. It handles accepting
+@@ -2646,6 +2842,11 @@ setup(void)
+ wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
+ wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+
++ drwl_init();
++
++ status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy),
++ STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL);
++
+ /* Make sure XWayland clients don't connect to the parent X server,
+ * e.g when running in the x11 backend or the wayland backend and the
+ * compositor has Xwayland support */
+@@ -2670,6 +2871,8 @@ void
+ spawn(const Arg *arg)
+ {
+ if (fork() == 0) {
++ close(STDIN_FILENO);
++ open("/dev/null", O_RDWR);
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+@@ -2688,6 +2891,30 @@ startdrag(struct wl_listener *listener, void *data)
+ LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
+ }
+
++int
++statusin(int fd, unsigned int mask, void *data)
++{
++ char status[256];
++ ssize_t n;
++
++ if (mask & WL_EVENT_ERROR)
++ die("status in event error");
++ if (mask & WL_EVENT_HANGUP)
++ wl_event_source_remove(status_event_source);
++
++ n = read(fd, status, sizeof(status) - 1);
++ if (n < 0 && errno != EWOULDBLOCK)
++ die("read:");
++
++ status[n] = '\0';
++ status[strcspn(status, "\n")] = '\0';
++
++ strncpy(stext, status, sizeof(stext));
++ drawbars();
++
++ return 0;
++}
++
+ void
+ tag(const Arg *arg)
+ {
+@@ -2698,7 +2925,7 @@ tag(const Arg *arg)
+ sel->tags = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2743,6 +2970,15 @@ tile(Monitor *m)
+ }
+ }
+
++void
++togglebar(const Arg *arg)
++{
++ wlr_scene_node_set_enabled(&selmon->scene_buffer->node,
++ !selmon->scene_buffer->node.enabled);
++ arrangelayers(selmon);
++ drawbars();
++}
++
+ void
+ togglefloating(const Arg *arg)
+ {
+@@ -2771,7 +3007,7 @@ toggletag(const Arg *arg)
+ sel->tags = newtags;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2784,7 +3020,7 @@ toggleview(const Arg *arg)
+ selmon->tagset[selmon->seltags] = newtagset;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2832,7 +3068,7 @@ unmapnotify(struct wl_listener *listener, void *data)
+ }
+
+ wlr_scene_node_destroy(&c->scene->node);
+- printstatus();
++ drawbars();
+ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+@@ -2932,6 +3168,13 @@ updatemons(struct wl_listener *listener, void *data)
+ }
+ }
+
++ if (stext[0] == '\0')
++ strncpy(stext, "dwl-"VERSION, sizeof(stext));
++ wl_list_for_each(m, &mons, link) {
++ updatebar(m);
++ drawbar(m);
++ }
++
+ /* FIXME: figure out why the cursor image is at 0,0 after turning all
+ * the monitors on.
+ * Move the cursor image where it used to be. It does not generate a
+@@ -2942,12 +3185,45 @@ updatemons(struct wl_listener *listener, void *data)
+ wlr_output_manager_v1_set_configuration(output_mgr, config);
+ }
+
++void
++updatebar(Monitor *m)
++{
++ size_t i;
++ int rw, rh;
++ char fontattrs[12];
++
++ wlr_output_transformed_resolution(m->wlr_output, &rw, &rh);
++ m->b.width = rw;
++ m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale);
++
++ wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0);
++
++ for (i = 0; i < LENGTH(m->pool); i++)
++ if (m->pool[i]) {
++ wlr_buffer_drop(&m->pool[i]->base);
++ m->pool[i] = NULL;
++ }
++
++ if (m->b.scale == m->wlr_output->scale && m->drw)
++ return;
++
++ drwl_font_destroy(m->drw->font);
++ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale);
++ if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs)))
++ die("Could not load font");
++
++ m->b.scale = m->wlr_output->scale;
++ m->lrpad = m->drw->font->height;
++ m->b.height = m->drw->font->height + 2;
++ m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale);
++}
++
+ void
+ updatetitle(struct wl_listener *listener, void *data)
+ {
+ Client *c = wl_container_of(listener, c, set_title);
+ if (c == focustop(c->mon))
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -2960,10 +3236,10 @@ urgent(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = 1;
+- printstatus();
++ drawbars();
+
+ if (client_surface(c)->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+@@ -2976,7 +3252,7 @@ view(const Arg *arg)
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+- printstatus();
++ drawbars();
+ }
+
+ void
+@@ -3017,6 +3293,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ {
+ struct wlr_scene_node *node, *pnode;
+ struct wlr_surface *surface = NULL;
++ struct wlr_scene_surface *scene_surface = NULL;
+ Client *c = NULL;
+ LayerSurface *l = NULL;
+ int layer;
+@@ -3025,9 +3302,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
+ if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
+ continue;
+
+- if (node->type == WLR_SCENE_NODE_BUFFER)
+- surface = wlr_scene_surface_try_from_buffer(
+- wlr_scene_buffer_from_node(node))->surface;
++ if (node->type == WLR_SCENE_NODE_BUFFER) {
++ scene_surface = wlr_scene_surface_try_from_buffer(
++ wlr_scene_buffer_from_node(node));
++ if (!scene_surface) continue;
++ surface = scene_surface->surface;
++ }
+ /* Walk the tree to find a node that knows the client */
+ for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
+ c = pnode->data;
+@@ -3160,10 +3440,10 @@ sethints(struct wl_listener *listener, void *data)
+ return;
+
+ c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
+- printstatus();
++ drawbars();
+
+ if (c->isurgent && surface && surface->mapped)
+- client_set_border_color(c, urgentcolor);
++ client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
+ }
+
+ void
+--
+2.52.0
+
diff --git a/patches/bar/bar.png b/patches/bar/bar.png
new file mode 100644
index 0000000..276256b
--- /dev/null
+++ b/patches/bar/bar.png
Binary files differ
diff --git a/patches/client-opacity-focus/README.md b/patches/client-opacity-focus/README.md
new file mode 100644
index 0000000..cb2c8b5
--- /dev/null
+++ b/patches/client-opacity-focus/README.md
@@ -0,0 +1,20 @@
+### Description
+This patch is based on the
+[client-opacity](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/client-opacity/client-opacity.patch)
+patch. This patch adds differing opacity levels depending upon whether the client is focused or not.
+
+The opacity levels can be change by short cuts.
+
+```
+[MODKEY]+[Ctrl]+[k] -> increase focus opacity unfocused client
+[MODKEY]+[Ctrl]+[j] -> decrease focus opacity unfocused client
+[MODKEY]+[Ctrl]+[Shift]+[k] -> increase focus opacity focused client
+[MODKEY]+[Ctrl]+[Shift]+[j] -> decrease focus opacity focused client
+```
+
+### Download
+- [git branch](https://codeberg.org/Hansvon/dwl/src/branch/client-opacity-focus)
+- [2026-04-27](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/client-opacity-focus/client-opacity-focus.patch)
+
+### Authors
+- [Hansvon](https://codeberg.org/Hansvon)
diff --git a/patches/client-opacity-focus/client-opacity-focus.dwl.patch b/patches/client-opacity-focus/client-opacity-focus.dwl.patch
new file mode 100644
index 0000000..11aa973
--- /dev/null
+++ b/patches/client-opacity-focus/client-opacity-focus.dwl.patch
@@ -0,0 +1,156 @@
+diff --git a/dwl.c b/dwl.c
+index 12f441e..e45e420 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -138,6 +138,9 @@ typedef struct {
+ unsigned int bw;
+ uint32_t tags;
+ int isfloating, isurgent, isfullscreen;
++ float opacity;
++ float opacity_focus;
++ float opacity_unfocus;
+ uint32_t resize; /* configure serial of a pending resize */
+ } Client;
+
+@@ -227,6 +230,8 @@ typedef struct {
+ const char *title;
+ uint32_t tags;
+ int isfloating;
++ float opacity_focus;
++ float opacity_unfocus;
+ int monitor;
+ } Rule;
+
+@@ -319,6 +324,7 @@ static void requeststartdrag(struct wl_listener *listener, void *data);
+ static void requestmonstate(struct wl_listener *listener, void *data);
+ static void resize(Client *c, struct wlr_box geo, int interact);
+ static void run(char *startup_cmd);
++static void scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data);
+ static void setcursor(struct wl_listener *listener, void *data);
+ static void setcursorshape(struct wl_listener *listener, void *data);
+ static void setfloating(Client *c, int floating);
+@@ -326,6 +332,8 @@ static void setfullscreen(Client *c, int fullscreen);
+ static void setlayout(const Arg *arg);
+ static void setmfact(const Arg *arg);
+ static void setmon(Client *c, Monitor *m, uint32_t newtags);
++static void setopacityunfocus(const Arg *arg);
++static void setopacityfocus(const Arg *arg);
+ static void setpsel(struct wl_listener *listener, void *data);
+ static void setsel(struct wl_listener *listener, void *data);
+ static void setup(void);
+@@ -490,6 +498,8 @@ applyrules(Client *c)
+ if ((!r->title || strstr(title, r->title))
+ && (!r->id || strstr(appid, r->id))) {
+ c->isfloating = r->isfloating;
++ c->opacity_unfocus = r->opacity_unfocus;
++ c->opacity_focus = r->opacity_focus;
+ newtags |= r->tags;
+ i = 0;
+ wl_list_for_each(m, &mons, link) {
+@@ -1127,6 +1137,10 @@ createnotify(struct wl_listener *listener, void *data)
+ c = toplevel->base->data = ecalloc(1, sizeof(*c));
+ c->surface.xdg = toplevel->base;
+ c->bw = borderpx;
++ /* Set default opacity*/
++ c->opacity_unfocus = default_opacity_unfocus;
++ c->opacity_focus = default_opacity_focus;
++ c->opacity = default_opacity_unfocus;
+
+ LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
+ LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
+@@ -1429,6 +1443,7 @@ focusclient(Client *c, int lift)
+ wl_list_insert(&fstack, &c->flink);
+ selmon = c->mon;
+ c->isurgent = 0;
++ c->opacity = c->opacity_focus;
+
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+@@ -1453,6 +1468,7 @@ focusclient(Client *c, int lift)
+ client_set_border_color(old_c, bordercolor);
+
+ client_activate_surface(old, 0);
++ old_c->opacity = old_c->opacity_unfocus;
+ }
+ }
+ printstatus();
+@@ -2159,6 +2175,7 @@ rendermon(struct wl_listener *listener, void *data)
+ /* Render if no XDG clients have an outstanding resize and are visible on
+ * this monitor. */
+ wl_list_for_each(c, &clients, link) {
++ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+ if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c))
+ goto skip;
+ }
+@@ -2295,6 +2312,15 @@ run(char *startup_cmd)
+ wl_display_run(dpy);
+ }
+
++void
++scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *data)
++{
++ Client *c = data;
++ /* xdg-popups are children of Client.scene, we do not have to worry about
++ * messing with them. */
++ wlr_scene_buffer_set_opacity(buffer, c->isfullscreen ? 1 : c->opacity);
++}
++
+ void
+ setcursor(struct wl_listener *listener, void *data)
+ {
+@@ -2363,6 +2389,7 @@ setfullscreen(Client *c, int fullscreen)
+ * client positions are set by the user and cannot be recalculated */
+ resize(c, c->prev, 0);
+ }
++ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+ arrange(c->mon);
+ printstatus();
+ }
+@@ -2419,6 +2446,44 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
+ focusclient(focustop(selmon), 1);
+ }
+
++
++void
++setopacityunfocus(const Arg *arg)
++{
++ Client *sel = focustop(selmon);
++ if (!sel)
++ return;
++
++ sel->opacity_unfocus += arg->f;
++ if (sel->opacity_unfocus > 1.0)
++ sel->opacity_unfocus = 1.0f;
++
++ if (sel->opacity_unfocus < 0.1)
++ sel->opacity_unfocus = 0.1f;
++
++ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
++}
++
++void
++setopacityfocus(const Arg *arg)
++{
++ Client *sel = focustop(selmon);
++ if (!sel)
++ return;
++
++ sel->opacity_focus += arg->f;
++ if (sel->opacity_focus > 1.0)
++ sel->opacity_focus = 1.0f;
++
++ if (sel->opacity_focus < 0.1)
++ sel->opacity_focus = 0.1f;
++
++ /* Change opacity from current client */
++ sel->opacity = sel->opacity_focus;
++
++ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
++}
++
+ void
+ setpsel(struct wl_listener *listener, void *data)
+ {
+--
+2.53.0
+
diff --git a/patches/client-opacity-focus/client-opacity-focus.patch b/patches/client-opacity-focus/client-opacity-focus.patch
new file mode 100644
index 0000000..90b5846
--- /dev/null
+++ b/patches/client-opacity-focus/client-opacity-focus.patch
@@ -0,0 +1,202 @@
+From 57c5475d7f715b77ec05d69a2bda808b224cf0b4 Mon Sep 17 00:00:00 2001
+From: Hans von Hohenstaufen <Hans.von.Hohenstaufen@protonmail.com>
+Date: Mon, 22 Dec 2025 01:43:50 +0000
+Subject: [PATCH] Add client opacity focus
+
+---
+ config.def.h | 12 +++++++---
+ dwl.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 74 insertions(+), 3 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 95c2afa..55abf84 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -13,6 +13,8 @@ static const float focuscolor[] = COLOR(0x005577ff);
+ static const float urgentcolor[] = COLOR(0xff0000ff);
+ /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
+ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */
++static const float default_opacity_unfocus = 0.70f;
++static const float default_opacity_focus = 1.00f;
+
+ /* tagging - TAGCOUNT must be no greater than 31 */
+ #define TAGCOUNT (9)
+@@ -22,10 +24,10 @@ static int log_level = WLR_ERROR;
+
+ static const Rule rules[] = {
+- /* app_id title tags mask isfloating monitor */
++ /* app_id title tags mask isfloating alpha focus alpha unfocus monitor */
+ /* examples: */
+- { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
+- { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
++ { "Gimp_EXAMPLE", NULL, 0, 1, 1.00, 0.20, -1 }, /* Start on currently visible tags floating, not tiled */
++ { "firefox_EXAMPLE", NULL, 1 << 8, 0, 1.00, 1.00, -1 }, /* Start on ONLY tag "9" */
+ };
+
+ /* layout(s) */
+@@ -135,6 +137,10 @@ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
++ { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_k, setopacityunfocus, {.f = +0.1f} },
++ { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_j, setopacityunfocus, {.f = -0.1f} },
++ { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_K, setopacityfocus, {.f = +0.1f} },
++ { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_J, setopacityfocus, {.f = -0.1f} },
+ { MODKEY, XKB_KEY_space, setlayout, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
+ { MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+diff --git a/dwl.c b/dwl.c
+index 12f441e..e45e420 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -138,6 +138,9 @@ typedef struct {
+ unsigned int bw;
+ uint32_t tags;
+ int isfloating, isurgent, isfullscreen;
++ float opacity;
++ float opacity_focus;
++ float opacity_unfocus;
+ uint32_t resize; /* configure serial of a pending resize */
+ } Client;
+
+@@ -227,6 +230,8 @@ typedef struct {
+ const char *title;
+ uint32_t tags;
+ int isfloating;
++ float opacity_focus;
++ float opacity_unfocus;
+ int monitor;
+ } Rule;
+
+@@ -319,6 +324,7 @@ static void requeststartdrag(struct wl_listener *listener, void *data);
+ static void requestmonstate(struct wl_listener *listener, void *data);
+ static void resize(Client *c, struct wlr_box geo, int interact);
+ static void run(char *startup_cmd);
++static void scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data);
+ static void setcursor(struct wl_listener *listener, void *data);
+ static void setcursorshape(struct wl_listener *listener, void *data);
+ static void setfloating(Client *c, int floating);
+@@ -326,6 +332,8 @@ static void setfullscreen(Client *c, int fullscreen);
+ static void setlayout(const Arg *arg);
+ static void setmfact(const Arg *arg);
+ static void setmon(Client *c, Monitor *m, uint32_t newtags);
++static void setopacityunfocus(const Arg *arg);
++static void setopacityfocus(const Arg *arg);
+ static void setpsel(struct wl_listener *listener, void *data);
+ static void setsel(struct wl_listener *listener, void *data);
+ static void setup(void);
+@@ -490,6 +498,8 @@ applyrules(Client *c)
+ if ((!r->title || strstr(title, r->title))
+ && (!r->id || strstr(appid, r->id))) {
+ c->isfloating = r->isfloating;
++ c->opacity_unfocus = r->opacity_unfocus;
++ c->opacity_focus = r->opacity_focus;
+ newtags |= r->tags;
+ i = 0;
+ wl_list_for_each(m, &mons, link) {
+@@ -1127,6 +1137,10 @@ createnotify(struct wl_listener *listener, void *data)
+ c = toplevel->base->data = ecalloc(1, sizeof(*c));
+ c->surface.xdg = toplevel->base;
+ c->bw = borderpx;
++ /* Set default opacity*/
++ c->opacity_unfocus = default_opacity_unfocus;
++ c->opacity_focus = default_opacity_focus;
++ c->opacity = default_opacity_unfocus;
+
+ LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
+ LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
+@@ -1429,6 +1443,7 @@ focusclient(Client *c, int lift)
+ wl_list_insert(&fstack, &c->flink);
+ selmon = c->mon;
+ c->isurgent = 0;
++ c->opacity = c->opacity_focus;
+
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+@@ -1453,6 +1468,7 @@ focusclient(Client *c, int lift)
+ client_set_border_color(old_c, bordercolor);
+
+ client_activate_surface(old, 0);
++ old_c->opacity = old_c->opacity_unfocus;
+ }
+ }
+ printstatus();
+@@ -2159,6 +2175,7 @@ rendermon(struct wl_listener *listener, void *data)
+ /* Render if no XDG clients have an outstanding resize and are visible on
+ * this monitor. */
+ wl_list_for_each(c, &clients, link) {
++ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+ if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c))
+ goto skip;
+ }
+@@ -2295,6 +2312,15 @@ run(char *startup_cmd)
+ wl_display_run(dpy);
+ }
+
++void
++scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *data)
++{
++ Client *c = data;
++ /* xdg-popups are children of Client.scene, we do not have to worry about
++ * messing with them. */
++ wlr_scene_buffer_set_opacity(buffer, c->isfullscreen ? 1 : c->opacity);
++}
++
+ void
+ setcursor(struct wl_listener *listener, void *data)
+ {
+@@ -2363,6 +2389,7 @@ setfullscreen(Client *c, int fullscreen)
+ * client positions are set by the user and cannot be recalculated */
+ resize(c, c->prev, 0);
+ }
++ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+ arrange(c->mon);
+ printstatus();
+ }
+@@ -2419,6 +2446,44 @@ setmon(Client *c, Monitor *m, uint32_t newtags)
+ focusclient(focustop(selmon), 1);
+ }
+
++
++void
++setopacityunfocus(const Arg *arg)
++{
++ Client *sel = focustop(selmon);
++ if (!sel)
++ return;
++
++ sel->opacity_unfocus += arg->f;
++ if (sel->opacity_unfocus > 1.0)
++ sel->opacity_unfocus = 1.0f;
++
++ if (sel->opacity_unfocus < 0.1)
++ sel->opacity_unfocus = 0.1f;
++
++ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
++}
++
++void
++setopacityfocus(const Arg *arg)
++{
++ Client *sel = focustop(selmon);
++ if (!sel)
++ return;
++
++ sel->opacity_focus += arg->f;
++ if (sel->opacity_focus > 1.0)
++ sel->opacity_focus = 1.0f;
++
++ if (sel->opacity_focus < 0.1)
++ sel->opacity_focus = 0.1f;
++
++ /* Change opacity from current client */
++ sel->opacity = sel->opacity_focus;
++
++ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
++}
++
+ void
+ setpsel(struct wl_listener *listener, void *data)
+ {
+--
+2.53.0
+
diff --git a/patches/gaps/README.md b/patches/gaps/README.md
new file mode 100644
index 0000000..4925a47
--- /dev/null
+++ b/patches/gaps/README.md
@@ -0,0 +1,14 @@
+### Description
+Adds gaps between clients, providing the ability to disable them at run-time.
+
+`smartgaps` can also be changed to remove gaps when there is only one client present.
+
+### Download
+- [git branch](https://codeberg.org/bigman/dwl/src/branch/gaps)
+- [2024-07-12](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/gaps/gaps.patch)
+
+### Authors
+- [peesock](https://codeberg.org/bigman)
+- [sewn](https://codeberg.org/sewn)
+- [Serene Void](https://github.com/serenevoid)
+- [Rayan Nakib](https://nakibrayan2.pages.dev)
diff --git a/patches/gaps/gaps.patch b/patches/gaps/gaps.patch
new file mode 100644
index 0000000..c025baf
--- /dev/null
+++ b/patches/gaps/gaps.patch
@@ -0,0 +1,127 @@
+From 50e3dd4746b6cb719efb9f8213b94ac52a5320d9 Mon Sep 17 00:00:00 2001
+From: peesock <kcormn@gmail.com>
+Date: Mon, 24 Jun 2024 20:06:42 -0700
+Subject: [PATCH] gaps!
+
+Co-authored-by: sewn <sewn@disroot.org>
+Co-authored-by: serenevoid <ajuph9224@gmail.com>
+---
+ config.def.h | 4 ++++
+ dwl.c | 34 ++++++++++++++++++++++++++--------
+ 2 files changed, 30 insertions(+), 8 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 22d2171..b388b4e 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -6,6 +6,9 @@
+ /* appearance */
+ static const int sloppyfocus = 1; /* focus follows mouse */
+ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
++static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */
++static int gaps = 1; /* 1 means gaps between windows are added */
++static const unsigned int gappx = 10; /* gap pixel between windows */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const float rootcolor[] = COLOR(0x222222ff);
+ static const float bordercolor[] = COLOR(0x444444ff);
+@@ -135,6 +138,7 @@ static const Key keys[] = {
+ { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
+ { MODKEY, XKB_KEY_Return, zoom, {0} },
+ { MODKEY, XKB_KEY_Tab, view, {0} },
++ { MODKEY, XKB_KEY_g, togglegaps, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+diff --git a/dwl.c b/dwl.c
+index dc0437e..dc851df 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -199,6 +199,7 @@ struct Monitor {
+ struct wlr_box w; /* window area, layout-relative */
+ struct wl_list layers[4]; /* LayerSurface.link */
+ const Layout *lt[2];
++ int gaps;
+ unsigned int seltags;
+ unsigned int sellt;
+ uint32_t tagset[2];
+@@ -336,6 +337,7 @@ static void tagmon(const Arg *arg);
+ static void tile(Monitor *m);
+ static void togglefloating(const Arg *arg);
+ static void togglefullscreen(const Arg *arg);
++static void togglegaps(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
+ static void unlocksession(struct wl_listener *listener, void *data);
+@@ -949,6 +951,8 @@ createmon(struct wl_listener *listener, void *data)
+
+ wlr_output_state_init(&state);
+ /* Initialize monitor state using configured rules */
++ m->gaps = gaps;
++
+ m->tagset[0] = m->tagset[1] = 1;
+ for (r = monrules; r < END(monrules); r++) {
+ if (!r->name || strstr(wlr_output->name, r->name)) {
+@@ -2638,7 +2642,7 @@ tagmon(const Arg *arg)
+ void
+ tile(Monitor *m)
+ {
+- unsigned int mw, my, ty;
++ unsigned int h, r, e = m->gaps, mw, my, ty;
+ int i, n = 0;
+ Client *c;
+
+@@ -2647,23 +2651,30 @@ tile(Monitor *m)
+ n++;
+ if (n == 0)
+ return;
++ if (smartgaps == n)
++ e = 0;
+
+ if (n > m->nmaster)
+- mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
++ mw = m->nmaster ? (int)roundf((m->w.width + gappx*e) * m->mfact) : 0;
+ else
+ mw = m->w.width;
+- i = my = ty = 0;
++ i = 0;
++ my = ty = gappx*e;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ if (i < m->nmaster) {
+- resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw,
+- .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
+- my += c->geom.height;
++ r = MIN(n, m->nmaster) - i;
++ h = (m->w.height - my - gappx*e - gappx*e * (r - 1)) / r;
++ resize(c, (struct wlr_box){.x = m->w.x + gappx*e, .y = m->w.y + my,
++ .width = mw - 2*gappx*e, .height = h}, 0);
++ my += c->geom.height + gappx*e;
+ } else {
++ r = n - i;
++ h = (m->w.height - ty - gappx*e - gappx*e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
+- .width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
+- ty += c->geom.height;
++ .width = m->w.width - mw - gappx*e, .height = h}, 0);
++ ty += c->geom.height + gappx*e;
+ }
+ i++;
+ }
+@@ -2686,6 +2697,13 @@ togglefullscreen(const Arg *arg)
+ setfullscreen(sel, !sel->isfullscreen);
+ }
+
++void
++togglegaps(const Arg *arg)
++{
++ selmon->gaps = !selmon->gaps;
++ arrange(selmon);
++}
++
+ void
+ toggletag(const Arg *arg)
+ {
+--
+2.45.2
+
diff --git a/patches/movestack/README.md b/patches/movestack/README.md
new file mode 100644
index 0000000..8695374
--- /dev/null
+++ b/patches/movestack/README.md
@@ -0,0 +1,13 @@
+### Description
+Allows you to move a window up and down the stack.
+
+### Download
+- [0.8](/dwl/dwl-patches/raw/branch/main/patches/movestack/movestack-0.8.patch)
+- [0.7](/dwl/dwl-patches/raw/branch/main/patches/movestack/movestack-0.7.patch)
+
+### Authors
+- [wochap](https://codeberg.org/wochap)
+- [sam-barr](https://github.com/ss7m)
+- [Dmitry Zakharchenko](https://github.com/dm1tz)
+- [Abanoub8](https://github.com/Abanoub8)
+- [Nikita Ivanov](https://github.com/NikitaIvanovV)
diff --git a/patches/movestack/movestack-0.7.patch b/patches/movestack/movestack-0.7.patch
new file mode 100644
index 0000000..2543c66
--- /dev/null
+++ b/patches/movestack/movestack-0.7.patch
@@ -0,0 +1,87 @@
+From 08230817bd3926e29d9897657eb1852cb27d461f Mon Sep 17 00:00:00 2001
+From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
+Date: Tue, 4 Feb 2025 23:21:19 +0100
+Subject: [PATCH] Allows you to move a window up and down the stack
+
+---
+ config.def.h | 2 ++
+ dwl.c | 43 +++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 45 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 22d2171..2c129f2 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -129,6 +129,8 @@ static const Key keys[] = {
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, movestack, {.i = +1} },
++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, movestack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+ { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
+ { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
+diff --git a/dwl.c b/dwl.c
+index def2562..045d6fa 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -303,6 +303,7 @@ static void locksession(struct wl_listener *listener, void *data);
+ static void mapnotify(struct wl_listener *listener, void *data);
+ static void maximizenotify(struct wl_listener *listener, void *data);
+ static void monocle(Monitor *m);
++static void movestack(const Arg *arg);
+ static void motionabsolute(struct wl_listener *listener, void *data);
+ static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
+ double sy, double sx_unaccel, double sy_unaccel);
+@@ -1786,6 +1787,48 @@ monocle(Monitor *m)
+ wlr_scene_node_raise_to_top(&c->scene->node);
+ }
+
++void
++movestack(const Arg *arg)
++{
++ Client *c, *sel = focustop(selmon);
++
++ if (!sel) {
++ return;
++ }
++
++ if (wl_list_length(&clients) <= 1) {
++ return;
++ }
++
++ if (arg->i > 0) {
++ wl_list_for_each(c, &sel->link, link) {
++ if (&c->link == &clients) {
++ c = wl_container_of(&clients, c, link);
++ break; /* wrap past the sentinel node */
++ }
++ if (VISIBLEON(c, selmon) || &c->link == &clients) {
++ break; /* found it */
++ }
++ }
++ } else {
++ wl_list_for_each_reverse(c, &sel->link, link) {
++ if (&c->link == &clients) {
++ c = wl_container_of(&clients, c, link);
++ break; /* wrap past the sentinel node */
++ }
++ if (VISIBLEON(c, selmon) || &c->link == &clients) {
++ break; /* found it */
++ }
++ }
++ /* backup one client */
++ c = wl_container_of(c->link.prev, c, link);
++ }
++
++ wl_list_remove(&sel->link);
++ wl_list_insert(&c->link, &sel->link);
++ arrange(selmon);
++}
++
+ void
+ motionabsolute(struct wl_listener *listener, void *data)
+ {
+--
+2.48.1
+
diff --git a/patches/movestack/movestack-0.8.patch b/patches/movestack/movestack-0.8.patch
new file mode 100644
index 0000000..cf0c933
--- /dev/null
+++ b/patches/movestack/movestack-0.8.patch
@@ -0,0 +1,87 @@
+From 7e8de6e79d24114272b22b55c906d7b55c36173a Mon Sep 17 00:00:00 2001
+From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
+Date: Mon, 16 Mar 2026 20:50:44 +0100
+Subject: [PATCH] Add movestack
+
+---
+ config.def.h | 2 ++
+ dwl.c | 43 +++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 45 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 8a6eda0..f490e24 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -125,6 +125,8 @@ static const Key keys[] = {
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_j, movestack, {.i = +1} },
++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_k, movestack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+ { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
+ { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
+diff --git a/dwl.c b/dwl.c
+index 44f3ad9..726fbdd 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -300,6 +300,7 @@ static void locksession(struct wl_listener *listener, void *data);
+ static void mapnotify(struct wl_listener *listener, void *data);
+ static void maximizenotify(struct wl_listener *listener, void *data);
+ static void monocle(Monitor *m);
++static void movestack(const Arg *arg);
+ static void motionabsolute(struct wl_listener *listener, void *data);
+ static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
+ double sy, double sx_unaccel, double sy_unaccel);
+@@ -1838,6 +1839,48 @@ monocle(Monitor *m)
+ wlr_scene_node_raise_to_top(&c->scene->node);
+ }
+
++void
++movestack(const Arg *arg)
++{
++ Client *c, *sel = focustop(selmon);
++
++ if (!sel) {
++ return;
++ }
++
++ if (wl_list_length(&clients) <= 1) {
++ return;
++ }
++
++ if (arg->i > 0) {
++ wl_list_for_each(c, &sel->link, link) {
++ if (&c->link == &clients) {
++ c = wl_container_of(&clients, c, link);
++ break; /* wrap past the sentinel node */
++ }
++ if (VISIBLEON(c, selmon) || &c->link == &clients) {
++ break; /* found it */
++ }
++ }
++ } else {
++ wl_list_for_each_reverse(c, &sel->link, link) {
++ if (&c->link == &clients) {
++ c = wl_container_of(&clients, c, link);
++ break; /* wrap past the sentinel node */
++ }
++ if (VISIBLEON(c, selmon) || &c->link == &clients) {
++ break; /* found it */
++ }
++ }
++ /* backup one client */
++ c = wl_container_of(c->link.prev, c, link);
++ }
++
++ wl_list_remove(&sel->link);
++ wl_list_insert(&c->link, &sel->link);
++ arrange(selmon);
++}
++
+ void
+ motionabsolute(struct wl_listener *listener, void *data)
+ {
+--
+2.53.0
+
diff --git a/patches/shiftview/README.md b/patches/shiftview/README.md
new file mode 100644
index 0000000..8e26f4d
--- /dev/null
+++ b/patches/shiftview/README.md
@@ -0,0 +1,9 @@
+### Description
+Add keybindings to cycle through tags with visible clients.
+
+### Download
+- [git branch](https://codeberg.org/guidocella/dwl/src/branch/shiftview)
+- [2026-02-09](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/shiftview/shiftview.patch)
+
+### Authors
+- [Guido Cella](https://codeberg.org/guidocella)
diff --git a/patches/shiftview/shiftview.patch b/patches/shiftview/shiftview.patch
new file mode 100644
index 0000000..50a849b
--- /dev/null
+++ b/patches/shiftview/shiftview.patch
@@ -0,0 +1,76 @@
+From ce4217d8ee9c28ba76ca34fae7a7c3ef1aceecb0 Mon Sep 17 00:00:00 2001
+From: Guido Cella <guido@guidocella.xyz>
+Date: Sat, 27 Jan 2024 22:43:29 +0100
+Subject: [PATCH] cycle through tags
+
+---
+ config.def.h | 4 ++++
+ shiftview.c | 34 ++++++++++++++++++++++++++++++++++
+ 2 files changed, 38 insertions(+)
+ create mode 100644 shiftview.c
+
+diff --git a/config.def.h b/config.def.h
+index 8a6eda0..fd80703 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -118,6 +118,8 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
+ static const char *termcmd[] = { "foot", NULL };
+ static const char *menucmd[] = { "wmenu-run", NULL };
+
++#include "shiftview.c"
++
+ static const Key keys[] = {
+ /* Note that Shift changes certain key codes: 2 -> at, etc. */
+ /* modifier key function argument */
+@@ -131,6 +133,8 @@ static const Key keys[] = {
+ { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
+ { MODKEY, XKB_KEY_Return, zoom, {0} },
+ { MODKEY, XKB_KEY_Tab, view, {0} },
++ { MODKEY, XKB_KEY_a, shiftview, { .i = -1 } },
++ { MODKEY, XKB_KEY_semicolon, shiftview, { .i = 1 } },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c, killclient, {0} },
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+diff --git a/shiftview.c b/shiftview.c
+new file mode 100644
+index 0000000..fa53db0
+--- /dev/null
++++ b/shiftview.c
+@@ -0,0 +1,34 @@
++// "arg->i" stores the number of tags to shift right (positive value)
++// or left (negative value)
++void
++shiftview(const Arg *arg)
++{
++ Arg a;
++ Client *c;
++ bool visible = false;
++ int i = arg->i;
++ int count = 0;
++ int nextseltags, curseltags = selmon->tagset[selmon->seltags];
++
++ do {
++ if (i > 0) // left circular shift
++ nextseltags = (curseltags << i) | (curseltags >> (TAGCOUNT - i));
++ else // right circular shift
++ nextseltags = curseltags >> (-i) | (curseltags << (TAGCOUNT + i));
++
++ // Check if the tag is visible
++ wl_list_for_each(c, &clients, link) {
++ if (c->mon == selmon && nextseltags & c->tags) {
++ visible = true;
++ break;
++ }
++ }
++
++ i += arg->i;
++ } while (!visible && ++count <= TAGCOUNT);
++
++ if (count <= TAGCOUNT) {
++ a.i = nextseltags;
++ view(&a);
++ }
++}
+--
+2.52.0
+
diff --git a/shiftview.c b/shiftview.c
new file mode 100644
index 0000000..ddd81ef
--- /dev/null
+++ b/shiftview.c
@@ -0,0 +1,30 @@
+// shiftview all tags regardless of tags having open windows
+void
+shiftview(const Arg *arg)
+{
+ Arg view_argument;
+ uint32_t destination_tag;
+
+ // arg->i represents the direction and distance passed from config.def.h (usually -1 and +1)
+ if(arg->i > 0){
+ // shift right (increase tag index), move the active tag bit to the left (0001) to (0010)
+ destination_tag = selmon->tagset[selmon->seltags] << arg->i;
+ }else{
+ // shift to the left
+ destination_tag = selmon->tagset[selmon->seltags] >> (-arg->i);
+ }
+
+ // TAGMASK defines the valid boundary for tags (111111111) for 9 tags
+ // if the shift pushed the active bit outside the bounds, destination_tag will become 0
+ if(!(destination_tag & TAGMASK)){
+ // If we went off to the right edge, wrap around to the first tag (000000001)
+ // If we went off to the left, wrap around to the last tag (bit 1 shifted left by TAGCOUNT - 1)
+ destination_tag = arg->i > 0 ? 1 : 1 << (TAGCOUNT - 1);
+ }
+
+ // pack the destination tag bitmask into the required dwl argument struct
+ view_argument.ui = destination_tag;
+
+ // pass the destination tag to dwl's view function
+ view(&view_argument);
+}