shithub: scripts

ref: a4c1f8359d8e4aadf881585ecb137cf6d4904ce2
dir: /patches/winwatch.patch/

View raw version
8a9,34
> static char *
> readall(int f, int *osz)
> {
> 	int bufsz, sz, n;
> 	char *s;
> 
> 	bufsz = 1023;
> 	s = nil;
> 	for(sz = 0;; sz += n){
> 		if(bufsz-sz < 1024){
> 			bufsz *= 2;
> 			s = realloc(s, bufsz);
> 		}
> 		if((n = readn(f, s+sz, bufsz-sz-1)) < 1)
> 			break;
> 	}
> 	if(n < 0 || sz < 1){
> 		free(s);
> 		return nil;
> 	}
> 	s[sz] = 0;
> 	*osz = sz;
> 
> 	return s;
> }
> 
9a36,106
> 	Colrioback,
> 
> 	/* the following group has to be in order, they are used by libframe */
> 	Colback,
> 	Colhigh,
> 	Colbord,
> 	Coltext,
> 	Colhtext,
> 
> 	Coltitle,
> 	Colltitle,
> 	Colhold,
> 	Collhold,
> 	Colpalehold,
> 	Colpaletext,
> 	Colsize,
> 
> 	/* menuhit */
> 	Colmenubar,
> 	Colmenuback,
> 	Colmenuhigh,
> 	Colmenubord,
> 	Colmenutext,
> 	Colmenuhtext,
> 
> 	Numcolors
> };
> 
> typedef struct Color Color;
> 
> struct Color {
> 	char *id;
> 	union {
> 		u32int rgb;
> 		char *path;
> 	};
> 	int flags;
> };
> 
> static Color theme[Numcolors] = {
> 	[Colrioback]   = {"rioback",   {0x777777}, 0},
> 	[Colback]      = {"back",      {0xffffff}, 0},
> 	[Colhigh]      = {"high",      {0xcccccc}, 0},
> 	[Colbord]      = {"border",    {0x999999}, 0},
> 	[Coltext]      = {"text",      {DBlack>>8}, 0},
> 	[Colhtext]     = {"htext",     {DBlack>>8}, 0},
> 	[Coltitle]     = {"title",     {DGreygreen>>8}, 0},
> 	[Colltitle]    = {"ltitle",    {DPalegreygreen>>8}, 0},
> 	[Colhold]      = {"hold",      {DMedblue>>8}, 0},
> 	[Collhold]     = {"lhold",     {DGreyblue>>8}, 0},
> 	[Colpalehold]  = {"palehold",  {DPalegreyblue>>8}, 0},
> 	[Colpaletext]  = {"paletext",  {0x666666}, 0},
> 	[Colsize]      = {"size",      {DRed>>8}, 0},
> 	[Colmenubar]   = {"menubar",   {DDarkgreen>>8}, 1},
> 	[Colmenuback]  = {"menuback",  {0xeaffea}, 1},
> 	[Colmenuhigh]  = {"menuhigh",  {DDarkgreen>>8}, 1},
> 	[Colmenubord]  = {"menubord",  {DMedgreen>>8}, 1},
> 	[Colmenutext]  = {"menutext",  {DBlack>>8}, 1},
> 	[Colmenuhtext] = {"menuhtext", {0xeaffea}, 1},
> };
> 
> u32int
> color2rgb(Color c, int scale)
> {
> 	return ((((c.rgb >> 16) & 0xff) / scale) << 24) |
> 			((((c.rgb >> 8) & 0xff) / scale) << 16) |
> 			(((c.rgb & 0xff) / scale) << 8) |
> 			0xff;
> }
> 
> enum {
30c127
< Image *statecol[4];
---
> Image *statecol[5];
178c275
< 	_string(screen, addpt(win[i].r.min, Pt(2,0)), display->black, ZP,
---
> 	_string(screen, addpt(win[i].r.min, Pt(2,0)), statecol[4], ZP,
181c278
< 	border(screen, win[i].r, 1, display->black, ZP);	
---
> 	border(screen, win[i].r, 1, statecol[4], ZP);	
316a414,461
> themeload(char *s, int n)
> {
> 	int i;
> 	char *t, *a[2], *e;
> 	Image *newc;
> 	u32int rgb;
> 
> 	if((t = malloc(n+1)) == nil)
> 		return;
> 	memmove(t, s, n);
> 	t[n] = 0;
> 
> 	for(s = t; s != nil && *s; s = e){
> 		if((e = strchr(s, '\n')) != nil)
> 			*e++ = 0;
> 		if(tokenize(s, a, 2) == 2){
> 			for(i = 0; i < nelem(theme); i++) {
> 				if(strcmp(theme[i].id, a[0]) == 0) {
> 					rgb = strtoul(a[1], nil, 16);
> 					if((newc = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, rgb<<8 | 0xff)) != nil) {
> 						theme[i].rgb = rgb;
> 					}
> 					break;
> 				}
> 			}
> 		}
> 	}
> 	free(t);
> }
> 
> char *
> themestring(int *n)
> {
> 	char *s, *t, *e;
> 	int i;
> 
> 	if((t = malloc(512)) != nil){
> 		s = t;
> 		e = s+512;
> 		for(i = 0; i < nelem(theme); i++)
> 			s = seprint(s, e, "%s\t%06ux\n", theme[i].id, theme[i].rgb);
> 		*n = s - t;
> 	}
> 
> 	return t;
> }
> 
> void
342d486
< 	lightblue = allocimagemix(display, DPalebluegreen, DWhite);
344c488,501
< 	statecol[0] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCFF);
---
> 	// load theme
> 	int sz, f;
> 	char *s;
> 
> 	if((f = open("/dev/theme", OREAD|OCEXEC)) >= 0){
> 		if((s = readall(f, &sz)) != nil)
> 			themeload(s, sz);
> 		free(s);
> 		close(f);
> 	}
> 
> 	lightblue = allocimagemix(display, color2rgb(theme[Colback], 1), color2rgb(theme[Colback], 1));
> 
> 	statecol[0] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, color2rgb(theme[Colhold], 2));
347c504,505
< 	statecol[3] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen);
---
> 	statecol[3] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, color2rgb(theme[Colltitle], 1));
> 	statecol[4] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, color2rgb(theme[Colmenubord], 1));