mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Fixing status2d and statuscmd / dwmblocks compatibility issues.
Text width calculations when using status2d strings resulted in statuscmd button placement calculations to be way off. Fixed by introducing a separate function status2dtextlength to get an approximate correct text width.
This commit is contained in:
parent
1bf50728a7
commit
2e30bddc16
108
dwm.c
108
dwm.c
@ -450,6 +450,7 @@ static char estext[256];
|
||||
static int screen;
|
||||
static int sw, sh; /* X display screen geometry width, height */
|
||||
static int bh, blw = 0; /* bar geometry */
|
||||
static int tw = 0; /* bar text width */
|
||||
static int lrpad; /* sum of left and right padding for text */
|
||||
#if BARPADDING_PATCH
|
||||
static int vp; /* vertical padding for bar */
|
||||
@ -764,99 +765,7 @@ buttonpress(XEvent *e)
|
||||
if (ev->x < x) {
|
||||
click = ClkLtSymbol;
|
||||
} else {
|
||||
#if HIDEVACANTTAGS_PATCH
|
||||
for (c = m->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
#endif // HIDEVACANTTAGS_PATCH
|
||||
#if TAGGRID_PATCH
|
||||
if (drawtagmask & DRAWCLASSICTAGS)
|
||||
#endif // TAGGRID_PATCH
|
||||
do {
|
||||
#if HIDEVACANTTAGS_PATCH
|
||||
/* do not reserve space for vacant tags */
|
||||
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
#endif // HIDEVACANTTAGS_PATCH
|
||||
x += TEXTW(tags[i]);
|
||||
} while (ev->x >= x && ++i < LENGTH(tags));
|
||||
if (i < LENGTH(tags)) {
|
||||
click = ClkTagBar;
|
||||
arg.ui = 1 << i;
|
||||
#if TAGGRID_PATCH
|
||||
} else if (ev->x < x + columns * bh / tagrows && (drawtagmask & DRAWTAGGRID)) {
|
||||
click = ClkTagBar;
|
||||
i = (ev->x - x) / (bh / tagrows);
|
||||
i = i + columns * (ev->y / (bh / tagrows));
|
||||
if (i >= LENGTH(tags)) {
|
||||
i = LENGTH(tags) - 1;
|
||||
}
|
||||
arg.ui = 1 << i;
|
||||
}
|
||||
else if (ev->x < x + blw + columns * bh / tagrows)
|
||||
click = ClkLtSymbol;
|
||||
#else // TAGGRID_PATCH
|
||||
} else if (ev->x < x + blw)
|
||||
click = ClkLtSymbol;
|
||||
#endif // TAGGRID_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + padding)
|
||||
#if !STATUSCMD_PATCH
|
||||
click = ClkStatusText;
|
||||
#else
|
||||
{
|
||||
click = ClkStatusText;
|
||||
|
||||
xc = selmon->ww - TEXTW(stext) + padding;
|
||||
char *text = rawstext;
|
||||
int i = -1;
|
||||
char ch;
|
||||
#if DWMBLOCKS_PATCH
|
||||
dwmblockssig = 0;
|
||||
#else
|
||||
statuscmdn = 0;
|
||||
#endif // DWMBLOCKS_PATCH
|
||||
while (text[++i]) {
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
xc += TEXTW(text) - lrpad;
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
if (xc >= ev->x)
|
||||
break;
|
||||
#if DWMBLOCKS_PATCH
|
||||
dwmblockssig = ch;
|
||||
#else
|
||||
if (ch <= LENGTH(statuscmds))
|
||||
statuscmdn = ch - 1;
|
||||
#endif // DWMBLOCKS_PATCH
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if AWESOMEBAR_PATCH
|
||||
else {
|
||||
x += blw;
|
||||
c = m->clients;
|
||||
|
||||
do {
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
else
|
||||
x += (1.0 / (double)m->bt) * m->btw;
|
||||
} while (ev->x > x && (c = c->next));
|
||||
|
||||
if (c) {
|
||||
click = ClkWinTitle;
|
||||
arg.v = c;
|
||||
}
|
||||
}
|
||||
#else
|
||||
} else
|
||||
click = ClkWinTitle;
|
||||
#endif // AWESOMEBAR_PATCH
|
||||
}
|
||||
#else // LEFTLAYOUT_PATCH
|
||||
#endif // LEFTLAYOUT_PATCH
|
||||
#if HIDEVACANTTAGS_PATCH
|
||||
for (c = m->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
@ -895,14 +804,13 @@ buttonpress(XEvent *e)
|
||||
} else if (ev->x < x + blw)
|
||||
click = ClkLtSymbol;
|
||||
#endif // TAGGRID_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + padding)
|
||||
else if (ev->x > selmon->ww - tw + padding)
|
||||
#if !STATUSCMD_PATCH
|
||||
click = ClkStatusText;
|
||||
#else
|
||||
{
|
||||
click = ClkStatusText;
|
||||
|
||||
xc = selmon->ww - TEXTW(stext) + padding;
|
||||
xc = selmon->ww - tw + padding;
|
||||
char *text = rawstext;
|
||||
int i = -1;
|
||||
char ch;
|
||||
@ -915,7 +823,11 @@ buttonpress(XEvent *e)
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
#if STATUS2D_PATCH && !STATUSCOLORS_PATCH
|
||||
xc += status2dtextlength(text);
|
||||
#else
|
||||
xc += TEXTW(text) - lrpad;
|
||||
#endif // STATUS2D_PATCH
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
@ -952,6 +864,8 @@ buttonpress(XEvent *e)
|
||||
else
|
||||
click = ClkWinTitle;
|
||||
#endif // AWESOMEBAR_PATCH
|
||||
#if LEFTLAYOUT_PATCH
|
||||
}
|
||||
#endif // LEFTLAYOUT_PATCH
|
||||
} else if ((c = wintoclient(ev->window))) {
|
||||
#if FOCUSONCLICK_PATCH
|
||||
@ -1469,7 +1383,7 @@ dirtomon(int dir)
|
||||
void
|
||||
drawbar(Monitor *m)
|
||||
{
|
||||
int x, w, tw = 0, stw = 0, stp = 0, invert;
|
||||
int x, w, stw = 0, stp = 0, invert;
|
||||
#if ALTERNATIVE_TAGS_PATCH
|
||||
int wdelta;
|
||||
#endif // ALTERNATIVE_TAGS_PATCH
|
||||
|
@ -6,14 +6,18 @@ drawstatusbar(Monitor *m, int bh, char* stext, int stw, int stp)
|
||||
char *text;
|
||||
char *p;
|
||||
|
||||
len = strlen(stext) + 1 ;
|
||||
len = strlen(stext) + 1;
|
||||
if (!(text = (char*) malloc(sizeof(char)*len)))
|
||||
die("malloc");
|
||||
p = text;
|
||||
#if STATUSCMD_PATCH
|
||||
copyvalidchars(text, stext);
|
||||
#else
|
||||
memcpy(text, stext, len);
|
||||
#endif // STATUSCMD_PATCH
|
||||
|
||||
/* compute width of the status text */
|
||||
w = stp * 2;;
|
||||
w = stp * 2;
|
||||
i = -1;
|
||||
while (text[++i]) {
|
||||
if (text[i] == '^') {
|
||||
@ -125,4 +129,47 @@ drawstatusbar(Monitor *m, int bh, char* stext, int stw, int stp)
|
||||
free(p);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
status2dtextlength(char* stext)
|
||||
{
|
||||
int i, w, len;
|
||||
short isCode = 0;
|
||||
char *text;
|
||||
|
||||
len = strlen(stext) + 1;
|
||||
if (!(text = (char*) malloc(sizeof(char)*len)))
|
||||
die("malloc");
|
||||
|
||||
#if STATUSCMD_PATCH
|
||||
copyvalidchars(text, stext);
|
||||
#else
|
||||
memcpy(text, stext, len);
|
||||
#endif // STATUSCMD_PATCH
|
||||
|
||||
/* compute width of the status text */
|
||||
w = 0;
|
||||
i = -1;
|
||||
while (text[++i]) {
|
||||
if (text[i] == '^') {
|
||||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
w += TEXTW(text) - lrpad;
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
} else {
|
||||
isCode = 0;
|
||||
text = text + i + 1;
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isCode)
|
||||
w += TEXTW(text) - lrpad;
|
||||
else
|
||||
isCode = 0;
|
||||
return w;
|
||||
}
|
@ -1 +1,2 @@
|
||||
static int drawstatusbar(Monitor *m, int bh, char* text, int stw, int stp);
|
||||
static int drawstatusbar(Monitor *m, int bh, char* text, int stw, int stp);
|
||||
static int status2dtextlength(char* stext);
|
Loading…
Reference in New Issue
Block a user