Merge branch 'newpatch' into front

This commit is contained in:
xfnw 2022-04-16 21:50:35 -04:00
commit 5e89dcb387
10 changed files with 233 additions and 35 deletions

9
sys/src/cmd/rio/col.h Normal file
View file

@ -0,0 +1,9 @@
enum {
Colrioback,
Numcolors,
};
extern Image *col[Numcolors];
void themeload(char *s, int n);
char *themestring(int *n);

View file

@ -14,6 +14,7 @@ enum
Qscreen,
Qsnarf,
Qtext,
Qtheme,
Qwctl,
Qwindow,
Qwsys, /* directory of window directories */
@ -295,7 +296,6 @@ Cursor whitearrow;
Cursor query;
Cursor *corners[9];
Image *background;
Image *cols[NCOL];
Image *titlecol;
Image *lighttitlecol;
@ -334,3 +334,5 @@ int snarfversion; /* updated each time it is written */
int messagesize; /* negotiated in 9P version setup */
int shiftdown;
int debug;
#include "col.h"

View file

@ -172,10 +172,61 @@ Cursor *corners[9] = {
&bl, &b, &br,
};
enum {
Noredraw = 1,
Rgbcol = 2,
Imagecol = 3,
};
typedef struct Color Color;
struct Color {
char *id;
int type;
union {
u32int rgb;
char *path;
};
int flags;
};
static Color theme[Numcolors] = {
[Colrioback] = {"rioback", Rgbcol, {0x777777}, 0},
};
Image *col[Numcolors];
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)
{
background = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
int i, f, sz;
char *s;
/* greys are multiples of 0x11111100+0xFF, 14* being palest */
cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse);
@ -201,4 +252,97 @@ iconinit(void)
holdcol = dholdcol;
else
holdcol = paleholdcol;
if((f = open("/dev/theme", OREAD|OCEXEC)) >= 0){
if((s = readall(f, &sz)) != nil)
themeload(s, sz);
free(s);
close(f);
}
for (i = 0; i < nelem(col); i++){
if(col[i] == nil)
col[i] = allocimage(display, Rect(0,0,1,1), RGB24, 1, theme[i].rgb<8|0x777777ff);
}
}
void redraw(void);
void
themeload(char *s, int n)
{
int i, fd;
char *t, *a[2], *e, *newp;
Image *newc, *repl;
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) {
newc = nil;
if(a[1][0] == '/'){
if((fd = open(a[1], OREAD)) >= 0){
if ((newc = readimage(display, fd, 0)) == nil)
goto End;
close(fd);
if ((repl = allocimage(display, Rect(0, 0, Dx(newc->r), Dy(newc->r)), RGB24, 1, 0x000000ff)) == nil)
goto End;
if (theme[i].type == Imagecol)
free(theme[i].path);
if ((newp = strdup(a[1])) == nil)
goto End;
theme[i].type = Imagecol;
theme[i].path = newp;
draw(repl, repl->r, newc, 0, newc->r.min);
freeimage(newc);
newc = repl;
}
}else{
rgb = strtoul(a[1], nil, 16);
if((newc = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, rgb<<8 | 0xff)) != nil) {
if (theme[i].type == Imagecol)
free(theme[i].path);
theme[i].type = Rgbcol;
theme[i].rgb = rgb;
}
}
if(new != nil){
freeimage(col[i]);
col[i] = newc;
}
break;
}
}
}
}
End:
free(t);
redraw();
}
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++)
if (theme[i].type == Rgbcol)
s = seprint(s, e, "%s\t%06ux\n", theme[i].id, theme[i].rgb);
else if (theme[i].type == Imagecol)
s = seprint(s, e, "%s\t%s\n", theme[i].id, theme[i].path);
*n = s - t;
}
return t;
}

View file

@ -33,6 +33,7 @@ Dirtab dirtab[]=
{ "screen", QTFILE, Qscreen, 0400 },
{ "snarf", QTFILE, Qsnarf, 0600 },
{ "text", QTFILE, Qtext, 0600 },
{ "theme", QTFILE, Qtheme, 0600 },
{ "wdir", QTFILE, Qwdir, 0600 },
{ "wctl", QTFILE, Qwctl, 0600 },
{ "window", QTFILE, Qwindow, 0400 },

View file

@ -39,6 +39,7 @@ int threadrforkflag = 0; /* should be RFENVG but that hides rio from plumber */
void mousethread(void*);
void keyboardthread(void*);
void winclosethread(void*);
void themethread(void*);
void initcmd(void*);
Channel* initkbd(void);
@ -199,10 +200,10 @@ threadmain(int argc, char *argv[])
kbdchan = initkbd();
if(kbdchan == nil)
error("can't find keyboard");
wscreen = allocscreen(screen, background, 0);
wscreen = allocscreen(screen, col[Colrioback], 0);
if(wscreen == nil)
error("can't allocate screen");
draw(view, viewr, background, nil, ZP);
draw(view, viewr, col[Colrioback], nil, ZP);
flushimage(display, 1);
timerinit();
@ -580,6 +581,48 @@ wtopcmp(void *a, void *b)
return (*(Window**)a)->topped - (*(Window**)b)->topped;
}
void
redraw(void)
{
Image *im;
int i, j;
Rectangle r;
Point o, n;
Window *w;
view = screen;
draw(view, view->r, col[Colrioback], nil, ZP);
o = subpt(viewr.max, viewr.min);
n = subpt(view->clipr.max, view->clipr.min);
qsort(window, nwindow, sizeof(window[0]), wtopcmp);
for(i=0; i<nwindow; i++){
w = window[i];
r = rectsubpt(w->i->r, viewr.min);
r.min.x = (r.min.x*n.x)/o.x;
r.min.y = (r.min.y*n.y)/o.y;
r.max.x = (r.max.x*n.x)/o.x;
r.max.y = (r.max.y*n.y)/o.y;
r = rectaddpt(r, view->clipr.min);
if(!goodrect(r))
r = rectsubpt(w->i->r, subpt(w->i->r.min, r.min));
for(j=0; j<nhidden; j++)
if(w == hidden[j])
break;
frinittick(w);
incref(w);
if(j < nhidden){
im = allocimage(display, r, screen->chan, 0, DNofill);
r = ZR;
} else
im = allocwindow(wscreen, r, Refbackup, DNofill);
if(im)
wsendctlmesg(w, Reshaped, r, im);
wclose(w);
}
viewr = view->r;
flushimage(display, 1);
}
void
resized(void)
{
@ -594,10 +637,10 @@ resized(void)
freescrtemps();
view = screen;
freescreen(wscreen);
wscreen = allocscreen(screen, background, 0);
wscreen = allocscreen(screen, col[Colrioback], 0);
if(wscreen == nil)
error("can't re-allocate screen");
draw(view, view->r, background, nil, ZP);
draw(view, view->r, col[Colrioback], nil, ZP);
o = subpt(viewr.max, viewr.min);
n = subpt(view->clipr.max, view->clipr.min);
qsort(window, nwindow, sizeof(window[0]), wtopcmp);

View file

@ -502,6 +502,10 @@ xfidwrite(Xfid *x)
memmove(w->label, x->data, cnt);
break;
case Qtheme:
themeload(x->data, cnt);
break;
case Qmouse:
if(w!=input || Dx(w->screenr)<=0)
break;
@ -746,6 +750,10 @@ xfidread(Xfid *x)
t = wcontents(w, &n);
goto Text;
case Qtheme:
t = themestring(&n);
goto Text;
Text:
if(off > n){
off = n;

View file

@ -29,17 +29,17 @@ flstart(Rectangle r)
lDrect = r;
/* Main text is yellowish */
maincols[BACK] = allocimagemix(display, DPaleyellow, DWhite);
maincols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
maincols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, DYellowgreen);
maincols[TEXT] = display->black;
maincols[BACK] = display->black;
maincols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x555555FF);
maincols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, 0x222222FF);
maincols[TEXT] = display->white;
maincols[HTEXT] = display->black;
/* Command text is blueish */
cmdcols[BACK] = allocimagemix(display, DPalebluegreen, DWhite);
cmdcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen);
cmdcols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, DPurpleblue);
cmdcols[TEXT] = display->black;
cmdcols[BACK] = display->black;
cmdcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x555555FF);
cmdcols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, 0x222222FF);
cmdcols[TEXT] = display->white;
cmdcols[HTEXT] = display->black;
}
@ -83,18 +83,19 @@ flinit(Flayer *l, Rectangle r, Font *ft, Image **cols)
draw(screen, l->entire, l->f.cols[BACK], nil, ZP);
scrdraw(l, 0L);
flborder(l, 0);
flrefresh(l, l->entire, 0);
}
void
flclose(Flayer *l)
{
if(l->visible == All)
draw(screen, l->entire, display->white, nil, ZP);
draw(screen, l->entire, display->black, nil, ZP);
else if(l->visible == Some){
if(l->f.b == 0)
l->f.b = allocimage(display, l->entire, screen->chan, 0, DNofill);
if(l->f.b){
draw(l->f.b, l->entire, display->white, nil, ZP);
draw(l->f.b, l->entire, display->black, nil, ZP);
flrefresh(l, l->entire, 0);
}
}
@ -362,7 +363,7 @@ flresize(Rectangle dr)
if(0 && Dx(dr)==Dx(olDrect) && Dy(dr)==Dy(olDrect))
move = 1;
else
draw(screen, lDrect, display->white, nil, ZP);
draw(screen, lDrect, display->black, nil, ZP);
for(i=0; i<nllist; i++){
l = llist[i];
l->lastsr = ZR;

View file

@ -246,24 +246,14 @@ getr(Rectangle *rp)
Point p;
Rectangle r;
*rp = getrect(3, mousectl);
if(rp->max.x && rp->max.x-rp->min.x<=5 && rp->max.y-rp->min.y<=5){
p = rp->min;
r = cmd.l[cmd.front].entire;
*rp = screen->r;
if(cmd.nwin==1){
if (p.y <= r.min.y)
rp->max.y = r.min.y;
else if (p.y >= r.max.y)
*rp = screen->r;
p = rp->min;
r = cmd.l[cmd.front].entire;
if(cmd.nwin==1)
rp->min.y = r.max.y;
if (p.x <= r.min.x)
rp->max.x = r.min.x;
else if (p.x >= r.max.x)
rp->min.x = r.max.x;
}
}
return rectclip(rp, screen->r) &&
rp->max.x-rp->min.x>100 && rp->max.y-rp->min.y>40;
rp->max.x-rp->min.x>100 && rp->max.y-rp->min.y>40;
}
void

View file

@ -207,7 +207,7 @@ sweeptext(int new, int tag)
if(getr(&r) && (t = malloc(sizeof(Text)))){
memset((void*)t, 0, sizeof(Text));
current((Flayer *)0);
//current((Flayer *)0);
flnew(&t->l[0], gettext, 0, (char *)t);
flinit(&t->l[0], r, font, maincols); /*bnl*/
t->nwin = 1;

View file

@ -46,7 +46,7 @@ getscreen(int argc, char **argv)
if(t != nil)
maxtab = strtoul(t, nil, 0);
free(t);
draw(screen, screen->clipr, display->white, nil, ZP);
draw(screen, screen->clipr, display->black, nil, ZP);
}
int