mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2025-09-07 11:44:51 +00:00
Added barcolors patch
This commit is contained in:
parent
373c8dd630
commit
12a8d4b7d5
12
patches/barcolors/README.md
Normal file
12
patches/barcolors/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
### Description
|
||||
Adds support for colored status text. Text can be colored in the same manner as with dwlb, namely by wrapping it between `^fg(color)` and `^fg()` or `^bg(color)` and `^bg()`, where `color` is a 6-digit hexadecimal value. This patch only works if the bar patch has been applied before.
|
||||
|
||||
### Download
|
||||
- [git branch](https://codeberg.org/kerberoge/dwl/src/branch/barcolors)
|
||||
- [2024-07-28](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/barcolors/barcolors.patch)
|
||||
|
||||
### Authors
|
||||
- [Kerberoge](https://codeberg.org/kerberoge)
|
||||
sjoerdenjh@gmail.com
|
||||
kerberoge at [Libera IRC dwl channel](https://web.libera.chat/?channels=#dwl)
|
||||
kerberoge at [dwl Discord](https://discord.gg/jJxZnrGPWN)
|
132
patches/barcolors/barcolors.patch
Normal file
132
patches/barcolors/barcolors.patch
Normal file
@ -0,0 +1,132 @@
|
||||
From 14d59d55fe815a081d99db4090febaf69b482ded Mon Sep 17 00:00:00 2001
|
||||
From: Kerberoge <sjoerdenjh@gmail.com>
|
||||
Date: Sun, 28 Jul 2024 13:02:41 +0200
|
||||
Subject: [PATCH] Created barcolors patch
|
||||
|
||||
---
|
||||
dwl.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
|
||||
1 file changed, 82 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/dwl.c b/dwl.c
|
||||
index 60f3087..40c094e 100644
|
||||
--- a/dwl.c
|
||||
+++ b/dwl.c
|
||||
@@ -313,6 +313,7 @@ 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 int drawstatus(Monitor *m);
|
||||
static void focusclient(Client *c, int lift);
|
||||
static void focusmon(const Arg *arg);
|
||||
static void focusstack(const Arg *arg);
|
||||
@@ -443,7 +444,7 @@ static struct wlr_box sgeom;
|
||||
static struct wl_list mons;
|
||||
static Monitor *selmon;
|
||||
|
||||
-static char stext[256];
|
||||
+static char stext[512];
|
||||
static struct wl_event_source *status_event_source;
|
||||
|
||||
static const struct wlr_buffer_impl buffer_impl = {
|
||||
@@ -1480,11 +1481,8 @@ drawbar(Monitor *m)
|
||||
drwl_prepare_drawing(m->drw, m->b.width, m->b.height, buf->data, stride);
|
||||
|
||||
/* 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);
|
||||
- }
|
||||
+ if (m == selmon) /* status is only drawn on selected monitor */
|
||||
+ tw = drawstatus(m);
|
||||
|
||||
wl_list_for_each(c, &clients, link) {
|
||||
if (c->mon != m)
|
||||
@@ -1539,6 +1537,84 @@ drawbars(void)
|
||||
drawbar(m);
|
||||
}
|
||||
|
||||
+int
|
||||
+drawstatus(Monitor *m)
|
||||
+{
|
||||
+ int x, tw, iw;
|
||||
+ char rstext[512] = "";
|
||||
+ char *p, *argstart, *argend, *itext;
|
||||
+ uint32_t scheme[3], *color;
|
||||
+
|
||||
+ /* calculate real width of stext */
|
||||
+ for (p = stext; *p; p++) {
|
||||
+ if (*p == '^') {
|
||||
+ p++;
|
||||
+ if (!strncmp(p, "fg(", 3) || !strncmp(p, "bg(", 3)) {
|
||||
+ argend = strchr(p, ')');
|
||||
+ if (!argend)
|
||||
+ argend = p + 2;
|
||||
+ p = argend;
|
||||
+ } else if (*p == '^') {
|
||||
+ strncat(rstext, p, 1);
|
||||
+ } else {
|
||||
+ strncat(rstext, p - 1, 2);
|
||||
+ }
|
||||
+ } else {
|
||||
+ strncat(rstext, p, 1);
|
||||
+ }
|
||||
+ }
|
||||
+ tw = TEXTW(m, rstext) - m->lrpad + 2; /* 2px right padding */
|
||||
+
|
||||
+ x = m->b.width - tw;
|
||||
+ itext = stext;
|
||||
+ scheme[0] = colors[SchemeNorm][0];
|
||||
+ scheme[1] = colors[SchemeNorm][1];
|
||||
+ drwl_setscheme(m->drw, scheme);
|
||||
+ for (p = stext; *p; p++) {
|
||||
+ if (*p == '^') {
|
||||
+ p++;
|
||||
+ if (!strncmp(p, "fg(", 3) || !strncmp(p, "bg(", 3)) {
|
||||
+ *(p - 1) = '\0';
|
||||
+ iw = TEXTW(m, itext) - m->lrpad;
|
||||
+ if (*itext) /* only draw text if there is something to draw */
|
||||
+ x = drwl_text(m->drw, x, 0, iw, m->b.height, 0, itext, 0);
|
||||
+ *(p - 1) = '^';
|
||||
+
|
||||
+ argstart = p + 3;
|
||||
+ argend = strchr(argstart, ')');
|
||||
+ if (!argend) argend = argstart - 1;
|
||||
+ itext = argend + 1;
|
||||
+
|
||||
+ if (!strncmp(p, "fg(", 3)) /* foreground */
|
||||
+ color = &scheme[0];
|
||||
+ else /* background */
|
||||
+ color = &scheme[1];
|
||||
+
|
||||
+ if (argend - argstart > 0) {
|
||||
+ *argend = '\0';
|
||||
+ *color = strtoul(argstart, NULL, 16);
|
||||
+ *color = *color << 8 | 0xff; /* add alpha channel */
|
||||
+ *argend = ')';
|
||||
+ } else {
|
||||
+ *color = 0;
|
||||
+ }
|
||||
+
|
||||
+ /* reset color back to normal if none was provided */
|
||||
+ if (!scheme[0])
|
||||
+ scheme[0] = colors[SchemeNorm][0];
|
||||
+ if (!scheme[1])
|
||||
+ scheme[1] = colors[SchemeNorm][1];
|
||||
+
|
||||
+ drwl_setscheme(m->drw, scheme);
|
||||
+ p = argend;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ iw = TEXTW(m, itext) - m->lrpad;
|
||||
+ drwl_text(m->drw, x, 0, iw, m->b.height, 0, itext, 0);
|
||||
+ return tw;
|
||||
+}
|
||||
+
|
||||
void
|
||||
focusclient(Client *c, int lift)
|
||||
{
|
||||
--
|
||||
2.45.2
|
||||
|
Loading…
x
Reference in New Issue
Block a user