diff options
| author | bakkeby <[email protected]> | 2020-05-27 21:04:22 +0200 |
|---|---|---|
| committer | bakkeby <[email protected]> | 2020-05-27 21:04:22 +0200 |
| commit | 2e30bddc160bea3881288d9c88bcbde0cff8a686 (patch) | |
| tree | f7ca9082f4c184ec95317df41d80eefe21783f73 /patch | |
| parent | 1bf50728a7acaba9ed32d423b4118d52db274f39 (diff) | |
| download | dwm-flexipatch-2e30bddc160bea3881288d9c88bcbde0cff8a686.tar.gz dwm-flexipatch-2e30bddc160bea3881288d9c88bcbde0cff8a686.zip | |
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.
Diffstat (limited to 'patch')
| -rw-r--r-- | patch/status2d.c | 51 | ||||
| -rw-r--r-- | patch/status2d.h | 3 |
2 files changed, 51 insertions, 3 deletions
diff --git a/patch/status2d.c b/patch/status2d.c index 1ab9043..c2c3d75 100644 --- a/patch/status2d.c +++ b/patch/status2d.c @@ -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; }
\ No newline at end of file diff --git a/patch/status2d.h b/patch/status2d.h index af9c0ed..53f6c69 100644 --- a/patch/status2d.h +++ b/patch/status2d.h @@ -1 +1,2 @@ -static int drawstatusbar(Monitor *m, int bh, char* text, int stw, int stp);
\ No newline at end of file +static int drawstatusbar(Monitor *m, int bh, char* text, int stw, int stp); +static int status2dtextlength(char* stext);
\ No newline at end of file |
