shithub: acme-themes

ref: ef88bf19c7f048b4bcf188a3d4767375d759edbc
dir: /acme-themes.patch/

View raw version
--- /sys/src/cmd/acme/acme.c
+++ acme/acme.c
diff -u /sys/src/cmd/acme/acme.c acme/acme.c
@@ -20,6 +20,7 @@
 void	xfidallocthread(void*);
 void	newwindowthread(void*);
 void plumbproc(void*);
+void 	themeload(char *s, int n);
 
 Reffont	**fontcache;
 int		nfontcache;
@@ -869,6 +870,32 @@
 	 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00}
 };
 
+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;
+}
+
 void
 iconinit(void)
 {
@@ -875,20 +902,44 @@
 	Rectangle r;
 	Image *tmp;
 
-	/* Blue */
-	tagcols[BACK] = allocimagemix(display, DPalebluegreen, DWhite);
-	tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen);
-	tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
-	tagcols[TEXT] = display->black;
-	tagcols[HTEXT] = display->black;
+	/* jgs3 - Apply the themes */
+	int f, sz;
+	char *s;
+	if((f = open("/dev/theme", OREAD|OCEXEC)) >= 0){
+		if((s = readall(f, &sz)) != nil)
+			themeload(s, sz);
+		free(s);
+		close(f);
 
-	/* Yellow */
-	textcols[BACK] = allocimagemix(display, DPaleyellow, DWhite);
-	textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
-	textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DYellowgreen);
-	textcols[TEXT] = display->black;
-	textcols[HTEXT] = display->black;
+		/* Menu */
+		tagcols[BACK] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colmenuback].rgb<<8|0xff);
+		tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colmenuhigh].rgb<<8|0xff);
+		tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colmenubord].rgb<<8|0xff);
+		tagcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colmenutext].rgb<<8|0xff);
+		tagcols[HTEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colmenuhtext].rgb<<8|0xff);
 
+		/* Body */
+		textcols[BACK] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colback].rgb<<8|0xff);
+		textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colhigh].rgb<<8|0xff);
+		textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colbord].rgb<<8|0xff);
+		textcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Coltext].rgb<<8|0xff);
+		textcols[HTEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, theme[Colhtext].rgb<<8|0xff);
+	} else {
+		/* Blue */
+		tagcols[BACK] = allocimagemix(display, DPalebluegreen, DWhite);
+		tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen);
+		tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
+		tagcols[TEXT] = display->black;
+		tagcols[HTEXT] = display->black;
+
+		/* Yellow */
+		textcols[BACK] = allocimagemix(display, DPaleyellow, DWhite);
+		textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
+		textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DYellowgreen);
+		textcols[TEXT] = display->black;
+		textcols[HTEXT] = display->black;
+	}
+
 	if(button){
 		freeimage(button);
 		freeimage(modbutton);
@@ -961,4 +1012,56 @@
 	seek(snarffd, 0, 0);
 	bufreset(&snarfbuf);
 	bufload(&snarfbuf, 0, snarffd, &nulls);
+}
+
+void
+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;
+					}
+					if(new != nil){
+						freeimage(col[i]);
+						col[i] = newc;
+					}
+					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;
 }
--- /sys/src/cmd/acme/addr.c
+++ acme/addr.c
--- /sys/src/cmd/acme/buff.c
+++ acme/buff.c
--- /sys/src/cmd/acme/cols.c
+++ acme/cols.c
--- /sys/src/cmd/acme/dat.h
+++ acme/dat.h
diff -u /sys/src/cmd/acme/dat.h acme/dat.h
@@ -569,3 +569,67 @@
 Channel	*cwarn;		/* chan(void*)[1] (really chan(unit)[1]) */
 
 #define	STACK	8192
+
+enum {
+	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},
+};
+
+Image *col[Numcolors];
--- /sys/src/cmd/acme/disk.c
+++ acme/disk.c
--- /sys/src/cmd/acme/ecmd.c
+++ acme/ecmd.c
--- /sys/src/cmd/acme/edit.c
+++ acme/edit.c
--- /sys/src/cmd/acme/edit.h
+++ acme/edit.h
--- /sys/src/cmd/acme/elog.c
+++ acme/elog.c
--- /sys/src/cmd/acme/exec.c
+++ acme/exec.c
--- /sys/src/cmd/acme/file.c
+++ acme/file.c
--- /sys/src/cmd/acme/fns.h
+++ acme/fns.h
--- /sys/src/cmd/acme/fsys.c
+++ acme/fsys.c
--- /sys/src/cmd/acme/logf.c
+++ acme/logf.c
--- /sys/src/cmd/acme/look.c
+++ acme/look.c
--- /sys/src/cmd/acme/mkfile
+++ acme/mkfile
diff -u /sys/src/cmd/acme/mkfile acme/mkfile
@@ -1,7 +1,7 @@
 </$objtype/mkfile
 BIN=/$objtype/bin
 
-TARG=acme
+TARG=tacme
 
 OFILES=\
 	acme.$O\
--- /sys/src/cmd/acme/regx.c
+++ acme/regx.c
--- /sys/src/cmd/acme/rows.c
+++ acme/rows.c
--- /sys/src/cmd/acme/scrl.c
+++ acme/scrl.c
--- /sys/src/cmd/acme/text.c
+++ acme/text.c
--- /sys/src/cmd/acme/time.c
+++ acme/time.c
--- /sys/src/cmd/acme/util.c
+++ acme/util.c
--- /sys/src/cmd/acme/wind.c
+++ acme/wind.c
--- /sys/src/cmd/acme/xfid.c
+++ acme/xfid.c