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:
@@ -23,6 +23,8 @@ static uint32_t colors[][3] = {
|
|||||||
|
|
||||||
/* tagging */
|
/* tagging */
|
||||||
static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
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 */
|
/* logging */
|
||||||
static int log_level = WLR_ERROR;
|
static int log_level = WLR_ERROR;
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ static uint32_t colors[][3] = {
|
|||||||
|
|
||||||
/* tagging */
|
/* tagging */
|
||||||
static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
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 */
|
/* logging */
|
||||||
static int log_level = WLR_ERROR;
|
static int log_level = WLR_ERROR;
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
|
|||||||
static Monitor *dirtomon(enum wlr_direction dir);
|
static Monitor *dirtomon(enum wlr_direction dir);
|
||||||
static void drawbar(Monitor *m);
|
static void drawbar(Monitor *m);
|
||||||
static void drawbars(void);
|
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 focusclient(Client *c, int lift);
|
||||||
static void focusmon(const Arg *arg);
|
static void focusmon(const Arg *arg);
|
||||||
static void focusstack(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;
|
unsigned int i = 0, x = 0;
|
||||||
double cx;
|
double cx;
|
||||||
|
char label[64];
|
||||||
unsigned int click;
|
unsigned int click;
|
||||||
struct wlr_pointer_button_event *event = data;
|
struct wlr_pointer_button_event *event = data;
|
||||||
struct wlr_keyboard *keyboard;
|
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)) &&
|
(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) {
|
(buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) {
|
||||||
cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
|
cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale;
|
||||||
do
|
do {
|
||||||
x += TEXTW(selmon, tags[i]);
|
taglabel(selmon, i, label, sizeof(label));
|
||||||
while (cx >= x && ++i < LENGTH(tags));
|
x += TEXTW(selmon, label);
|
||||||
|
} while (cx >= x && ++i < LENGTH(tags));
|
||||||
if (i < LENGTH(tags)) {
|
if (i < LENGTH(tags)) {
|
||||||
click = ClkTagBar;
|
click = ClkTagBar;
|
||||||
arg.ui = 1 << i;
|
arg.ui = 1 << i;
|
||||||
@@ -1684,7 +1687,8 @@ drawbar(Monitor *m)
|
|||||||
int x, w, tw = 0;
|
int x, w, tw = 0;
|
||||||
int boxs = m->drw->font->height / 9;
|
int boxs = m->drw->font->height / 9;
|
||||||
int boxw = m->drw->font->height / 6 + 2;
|
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;
|
Client *c;
|
||||||
Buffer *buf;
|
Buffer *buf;
|
||||||
|
|
||||||
@@ -1703,20 +1707,16 @@ drawbar(Monitor *m)
|
|||||||
wl_list_for_each(c, &clients, link) {
|
wl_list_for_each(c, &clients, link) {
|
||||||
if (c->mon != m)
|
if (c->mon != m)
|
||||||
continue;
|
continue;
|
||||||
occ |= c->tags;
|
|
||||||
if (c->isurgent)
|
if (c->isurgent)
|
||||||
urg |= c->tags;
|
urg |= c->tags;
|
||||||
}
|
}
|
||||||
x = 0;
|
x = 0;
|
||||||
c = focustop(m);
|
c = focustop(m);
|
||||||
for (i = 0; i < LENGTH(tags); i++) {
|
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_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);
|
drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, label, 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;
|
x += w;
|
||||||
}
|
}
|
||||||
w = TEXTW(m, m->ltsymbol);
|
w = TEXTW(m, m->ltsymbol);
|
||||||
@@ -3110,6 +3110,40 @@ tag(const Arg *arg)
|
|||||||
drawbars();
|
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
|
void
|
||||||
tagcyclemon(const Arg *arg)
|
tagcyclemon(const Arg *arg)
|
||||||
{
|
{
|
||||||
@@ -3462,8 +3496,9 @@ void
|
|||||||
updatetitle(struct wl_listener *listener, void *data)
|
updatetitle(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
Client *c = wl_container_of(listener, c, set_title);
|
Client *c = wl_container_of(listener, c, set_title);
|
||||||
if (c == focustop(c->mon))
|
/* workspace labels show titles, so every title change matters */
|
||||||
drawbars();
|
if (c->mon)
|
||||||
|
drawbar(c->mon);
|
||||||
|
|
||||||
if (c->foreign_toplevel_handle) {
|
if (c->foreign_toplevel_handle) {
|
||||||
struct wlr_ext_foreign_toplevel_handle_v1_state foreign_toplevel_state = {
|
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);
|
wl_list_insert(&c->link, &sel->link);
|
||||||
else
|
else
|
||||||
wl_list_insert(c->link.prev, &sel->link);
|
wl_list_insert(c->link.prev, &sel->link);
|
||||||
arrange(selmon);
|
arrange(selmon); drawbar(selmon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -3652,7 +3687,7 @@ zoom(const Arg *arg)
|
|||||||
wl_list_insert(&clients, &sel->link);
|
wl_list_insert(&clients, &sel->link);
|
||||||
|
|
||||||
focusclient(sel, 1);
|
focusclient(sel, 1);
|
||||||
arrange(selmon);
|
arrange(selmon); drawbar(selmon);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XWAYLAND
|
#ifdef XWAYLAND
|
||||||
|
|||||||
Reference in New Issue
Block a user