[dev] [dwm] patch for statuscolors improved
Hello suckless folks- Attached is a patch that enables colors in the statusbar text. Yes, a very similar patch already exists (http://dwm.suckless.org/patches/statuscolors), so why did I make this one? 1) the pre-existing patch inserts a space for every color change code in the text. This one does not add extra spaces. 2) the pre-existing patch pads the statusbar text, wasting space at the upper left corner of the screen (only one character, but it annoyed me). compared to the pre-existing patch, the code for drawcoloredtext() is a bit cleaner due to the absence of padding considerations. And the code for the textnw() function now needs to filter out the non-printing characters before it calculates the width. I'm not sure if my method of creating a new string is "suckless" -- if it can be improved, please reply with suggestions. The basis for this patch is dwm version 5.8.2 Dan - diff --git a/config.def.h b/config.def.h index 91cf439..6189d7e 100644 --- a/config.def.h +++ b/config.def.h @@ -2,12 +2,13 @@ /* appearance */ static const char font[]= "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; -static const char normbordercolor[] = "#cc"; -static const char normbgcolor[] = "#cc"; -static const char normfgcolor[] = "#00"; -static const char selbordercolor[] = "#0066ff"; -static const char selbgcolor[] = "#0066ff"; -static const char selfgcolor[] = "#ff"; +#define NUMCOLORS 3 // need at least 3 +static const char colors[NUMCOLORS][ColLast][8] = { + // border foreground background + { "#cc", "#88", "#00" }, // 0 = normal + { "#cc", "#00", "#00" }, // 1 = selected + { "#ff6600", "#00", "#ff6600" }, // 2 = urgent/warning +}; static const unsigned int borderpx = 1;/* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const Bool showbar = True; /* False means no bar */ @@ -45,7 +46,7 @@ static const Layout layouts[] = { #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ -static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", colors[0][ColBG], "-nf", colors[0][ColFG], "-sb", colors[1][ColBG], "-sf", colors[1][ColFG], NULL }; static const char *termcmd[] = { "uxterm", NULL }; static Key keys[] = { diff --git a/dwm.c b/dwm.c index 670afbe..fd2f394 100644 --- a/dwm.c +++ b/dwm.c @@ -48,6 +48,7 @@ #define LENGTH(X) (sizeof X / sizeof X[0]) #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) +#define MAXCOLORS 8 // avoid circular reference to NUMCOLORS #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X)((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) @@ -97,8 +98,7 @@ struct Client { typedef struct { int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; +unsigned long colors[MAXCOLORS][ColLast]; Drawable drawable; GC gc; struct { @@ -175,8 +175,9 @@ static void die(const char *errstr, ...); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); +static void drawcoloredtext(char *text); +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -696,36 +697,37 @@ drawbar(Monitor *m) { dc.x = 0; for(i = 0; i < LENGTH(tags); i++) { dc.w = TEXTW(tags[i]); - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; - drawtext(tags[i], col, urg & 1 << i); + col = dc.colors[ (m->tagset[m->seltags] & 1 << i) ? + 1 : (urg & 1 << i ? 2:0) ]; + drawtext(tags[i], col, True); drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - occ & 1 << i, urg & 1 << i, col); + occ & 1 << i, col); dc.x += dc.w; } dc.w = blw = TEXTW(m->ltsymbol); - drawtext(m->ltsymbol, dc.norm, False); + drawtext(m->ltsymbol, dc.colors[0], False); dc.x += dc.w; x = dc.x; if(m == selmon) { /* status is only drawn on selected monitor */ - dc.w = TEXTW(stext); + dc.w = textnw(stext, strlen(stext)); // no padding dc.x = m->ww - dc.w;
Re: [dev] [st] add -c option to change class
On Fri, Nov 19, 2010 at 5:15 PM, Gregor Best wrote: > Also, a fixed version of the patch is attached (with correct \t usage > and manpage this time). Nice, applied.
Re: [dev] [st] add -c option to change class
On Thu, Nov 18, 2010 at 8:43 PM, Moritz Wilhelmy wrote: > Hi, > > Why not call it -class? That way it's xterm-compatible. Because -- and I hope I'm not surprising you -- it's completely inconsistent with almost every CLI tool on unix? Making st xterm-compatible at the escape sequence level is frightening enough :)
Re: [dev] Re: [st] multibyte patch
On Fri, Nov 19, 2010 at 2:38 PM, Hiltjo Posthuma wrote: > Offtopic and not specificly aimed at you: > I noticed the coding style of st is quite ugly. Lots of > non-descriptive variable names, recurring logic which could be grouped > in a function. Inconsistent. One can take an example to look at dwm > imo, it's pretty clean. I'm sorry you feel that way. I am not completely happy about it too but it's far from ugly. Selection and unicode code have been added recently and I'm currently trying to integrate them well. Remember that st hasn't made any release yet. Apart from that, I really don't know what you mean. Have you looked the rest of the source? Function directly dealing with X are prefixed with x, same for tty and t (terminal emulation). Functions that glue everything together don't have any prefix. Variable names are short just like in dwm. *Some* logic could be factored (i'm thinking about scrolling in particular) but it would just be harder to read/understand. As for the escape sequence handling, if you have a better solution feel free to mention it. Concerning the unreachable code, I'm sure Damian will fix what has to be fixed. There's no rush.
Re: [dev] [st] add -c option to change class
On Thu, Nov 18, 2010 at 08:43:15PM +0100, Moritz Wilhelmy wrote: > [...] > Why not call it -class? That way it's xterm-compatible. > One could also think about renaming -t to -title. > [...] Well, I wanted to keep with the current style... Also, a fixed version of the patch is attached (with correct \t usage and manpage this time). -- $l="\n";$p=q-sub r{rand}sub c{((shift)**2+(shift)**2)<1}while( $i++<=$s){$t++if c r,r}die("Gregor Best, 0xDB9F9A7C, ".($t/$s* 4).$l)-;$s+=ord$$|$_ for split //,$p;srand($s|$$);eval$p;die$@ # HG changeset patch # User Gregor Best # Date 1290183193 -3600 # Branch class # Node ID 3551035ea8a6d3ef5388d587b118fb3ca0a9ed5b # Parent 4cd71bc46f0fd25a2bdfd5c46815efc4d0f2612c Add -c option to override the default window class diff -r 4cd71bc46f0f -r 3551035ea8a6 st.1 --- a/st.1 Thu Nov 18 12:43:33 2010 +0100 +++ b/st.1 Fri Nov 19 17:13:13 2010 +0100 @@ -4,6 +4,7 @@ .SH SYNOPSIS .B st .RB [ \-e " "] +.RB [ \-c " "] .RB [ \-t " "] .RB [ \-v ] .SH DESCRIPTION @@ -17,5 +18,8 @@ .B \-t Overrides the default title (st) .TP +.B \-c +Overrides the default class ($TERM) +.TP .BI \-v Prints version information to standard output, then exits. diff -r 4cd71bc46f0f -r 3551035ea8a6 st.c --- a/st.c Thu Nov 18 12:43:33 2010 +0100 +++ b/st.c Fri Nov 19 17:13:13 2010 +0100 @@ -31,7 +31,7 @@ #define USAGE \ "st-" VERSION ", (c) 2010 st engineers\n" \ - "usage: st [-t title] [-e cmd] [-v]\n" + "usage: st [-t title] [-c class] [-e cmd] [-v]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -252,6 +252,7 @@ static Selection sel; static char *opt_cmd = NULL; static char *opt_title = NULL; +static char *opt_class = NULL; /* UTF-8 decode */ static int stou(char *s, long *u) { @@ -1443,7 +1444,7 @@ void xhints(void) { - XClassHint class = {TNAME, TNAME}; + XClassHint class = {opt_class ? opt_class : TNAME, TNAME}; XWMHints wm = {.flags = InputHint, .input = 1}; XSizeHints size = { .flags = PSize | PResizeInc | PBaseSize, @@ -1838,6 +1839,9 @@ case 't': if(++i < argc) opt_title = argv[i]; break; + case 'c': + if(++i < argc) opt_class = argv[i]; + break; case 'e': if(++i < argc) opt_cmd = argv[i]; break; pgpMEPwhdSE8f.pgp Description: PGP signature
Re: [dev] Re: [st] multibyte patch
On Sat, Nov 13, 2010 at 10:53 PM, Damian Okrasa wrote: > I removed the wchar_t completely, added some UTF-8 parsing functions. > No support for combining, bidi, doublecolumn etc. Markus Kuhn's UTF-8 > stress test file is not working 100% correctly (the decoder works > however, even when reading bytes one by one). > I noticed in canstou(): 329 /* use this if your buffer is less than UTF_SIZ, it returns 1 if you can decode 330UTF-8 otherwise return 0 */ 331 static int canstou(char *s, int b) { 332 unsigned char c = *s; 333 int n; 334 335 if (b < 1) 336 return 0; 337 else if (~c&B7) 338 return 1; 339 else if ((c&(B7|B6|B5)) == (B7|B6)) 340 n = 1; 341 else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5)) 342 n = 2; 343 else if ((c&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) 344 n = 3; 345 else 346 return 1; | v this is never reached. 347 for (--b,++s; n>0&&b>0; --n,--b,++s) { 348 c = *s; 349 if ((c&(B7|B6)) != B7) 350 break; 351 } 352 if (n > 0 && b == 0) 353 return 0; 354 else 355 return 1; 356 } If the current function is correct, then it can be simplified to: /* use this if your buffer is less than UTF_SIZ, it returns 1 if you can decode UTF-8 otherwise return 0 */ static int canstou(char *s, int b) { unsigned char c = *s; if (b < 1) return 0; else if (~c&B7) return 1; else if ((c&(B7|B6|B5)) == (B7|B6)) return 1; else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5)) return 2; else if ((c&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) return 3; return 1; } the (b < 1) check shouldnt probably be there either. Offtopic and not specificly aimed at you: I noticed the coding style of st is quite ugly. Lots of non-descriptive variable names, recurring logic which could be grouped in a function. Inconsistent. One can take an example to look at dwm imo, it's pretty clean. Kind regards, Hiltjo
[dev] dmenu-4.2
Hi there, I'm glad to announce the new dmenu 4.2 release which can be downloaded from: http://dl.suckless.org/tools/dmenu-4.2.tar.gz This release contains plenty code cleanups mainly developed by Connor Lane Smith (aka cls in #suckless)! Thanks your great contribution! It does not yet contain any select all functionality as it will need some time for consideration, as usual. Kind regards, Anselm PS: I also announce that I'm back again, after being very busy at my day job(s) and recent relocations.
Re: [dev][st] multibyte patch
On 19.11.2010 01:12, Damian Okrasa wrote: > #define TNAME "st" Nice, that worked, thanks!