Show master client title as workspace label in bar
Each tag is drawn as a fixed-width label with the first tagtitlelen characters of its master client's title; empty tags show tagempty. Redraw the bar on any title change and after movestack/zoom, since these can change a label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user