diff --git a/config.def.h b/config.def.h index 1fc6203..4e13856 100644 --- a/config.def.h +++ b/config.def.h @@ -23,6 +23,8 @@ static uint32_t colors[][3] = { /* tagging */ static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *tagempty = "[ - ]"; /* label of empty workspaces */ +static const unsigned int tagtitlelen = 7; /* title characters per workspace label */ /* logging */ static int log_level = WLR_ERROR; diff --git a/config.h b/config.h index 078bfd0..88cc304 100644 --- a/config.h +++ b/config.h @@ -23,6 +23,8 @@ static uint32_t colors[][3] = { /* tagging */ static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *tagempty = "[ - ]"; /* label of empty workspaces */ +static const unsigned int tagtitlelen = 7; /* title characters per workspace label */ /* logging */ static int log_level = WLR_ERROR; diff --git a/dwl.c b/dwl.c index 534de1b..482e011 100644 --- a/dwl.c +++ b/dwl.c @@ -337,6 +337,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 void taglabel(Monitor *m, unsigned int i, char *buf, size_t size); static void focusclient(Client *c, int lift); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); @@ -817,6 +818,7 @@ buttonpress(struct wl_listener *listener, void *data) { unsigned int i = 0, x = 0; double cx; + char label[64]; unsigned int click; struct wlr_pointer_button_event *event = data; struct wlr_keyboard *keyboard; @@ -846,9 +848,10 @@ buttonpress(struct wl_listener *listener, void *data) (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)); + do { + taglabel(selmon, i, label, sizeof(label)); + x += TEXTW(selmon, label); + } while (cx >= x && ++i < LENGTH(tags)); if (i < LENGTH(tags)) { click = ClkTagBar; arg.ui = 1 << i; @@ -1684,7 +1687,8 @@ 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; + uint32_t i, urg = 0; + char label[64]; Client *c; Buffer *buf; @@ -1703,20 +1707,16 @@ drawbar(Monitor *m) 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]); + taglabel(m, i, label, sizeof(label)); + w = TEXTW(m, label); 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); + drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, label, urg & 1 << i); x += w; } w = TEXTW(m, m->ltsymbol); @@ -3110,6 +3110,40 @@ tag(const Arg *arg) drawbars(); } +/* Workspace label: first tagtitlelen characters of the tag's master client + * title, padded with spaces. Empty tags show tagempty. */ +void +taglabel(Monitor *m, unsigned int i, char *buf, size_t size) +{ + Client *c, *master = NULL; + const char *s; + size_t n = 0; + unsigned int chars = 0; + + wl_list_for_each(c, &clients, link) { + if (c->mon != m || !(c->tags & 1u << i)) + continue; + if (!c->isfloating) { + master = c; + break; + } + if (!master) + master = c; + } + + s = master ? client_get_title(master) : tagempty; + /* copy whole UTF-8 characters only */ + while (*s && chars < tagtitlelen && n + 4 < size) { + do + buf[n++] = *s++; + while ((*s & 0xc0) == 0x80 && n < size - 1); + chars++; + } + for (; chars < tagtitlelen && n < size - 1; chars++) + buf[n++] = ' '; + buf[n] = '\0'; +} + void tagcyclemon(const Arg *arg) { @@ -3462,8 +3496,9 @@ void updatetitle(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, set_title); - if (c == focustop(c->mon)) - drawbars(); + /* workspace labels show titles, so every title change matters */ + if (c->mon) + drawbar(c->mon); if (c->foreign_toplevel_handle) { struct wlr_ext_foreign_toplevel_handle_v1_state foreign_toplevel_state = { @@ -3619,7 +3654,7 @@ movestack(const Arg *arg) wl_list_insert(&c->link, &sel->link); else wl_list_insert(c->link.prev, &sel->link); - arrange(selmon); + arrange(selmon); drawbar(selmon); } void @@ -3652,7 +3687,7 @@ zoom(const Arg *arg) wl_list_insert(&clients, &sel->link); focusclient(sel, 1); - arrange(selmon); + arrange(selmon); drawbar(selmon); } #ifdef XWAYLAND