shithub: lola

Download patch

ref: 56008bbe96df8235a0633d6221b0e8809337fe41
parent: 1ee61ee58ef158458a8727f31e3a94de3447412f
author: aap <aap@papnet.eu>
date: Mon Sep 30 15:33:51 EDT 2024

better code for blocking requests. extended 1-3 menu. small fixes.

--- a/data.c
+++ b/data.c
@@ -168,6 +168,7 @@
 Image*
 mkcolor(ulong col)
 {
+// TODO: what if we can't get RGBA32?
 //	return allocimage(display, Rect(0,0,1,1), screen->chan, 1, col);
 	return allocimage(display, Rect(0,0,1,1), RGBA32, 1, col);
 }
--- a/fs.c
+++ b/fs.c
@@ -588,39 +588,46 @@
 }
 
 static char*
-readblocking(Req *r, Channel *readchan)
+waitblocking(Req *r, Channel *waitchan, Channel **replychan)
 {
 	WinTab *w;
-	Channel *chan;
-	Stringpair pair;
 	enum { Adata, Agone, Aflush, NALT };
 	Alt alts[NALT+1];
 
 	w = XF(r->fid)->w;
 
-	alts[Adata] = ALT(readchan, &chan, CHANRCV);
-	if(w)
-		alts[Agone] = ALT(w->gone, nil, CHANRCV);
-	else
-		alts[Agone] = ALT(nil, nil, CHANNOP);
+	*replychan = nil;
+	alts[Adata] = ALT(waitchan, replychan, CHANRCV);
+	alts[Agone] = w ? ALT(w->gone, nil, CHANRCV)
+			: ALT(nil, nil, CHANNOP);
 	alts[Aflush] = ALT(XR(r)->flush, nil, CHANRCV);
 	alts[NALT].op = CHANEND;
 	switch(alt(alts)){
-	case Adata:
-		pair.s = r->ofcall.data;
-		pair.ns = r->ifcall.count;
-		send(chan, &pair);
-		recv(chan, &pair);
-		r->ofcall.count = min(r->ifcall.count, pair.ns);
-		return nil;
-	case Agone:
-		return Edeleted;
-	case Aflush:
-		return Eflush;
+	case Adata: return nil;
+	case Agone: return Edeleted;
+	case Aflush: return Eflush;
 	}
-	return nil;	/* can't happen */
+	assert(0);	/* can't happen */
+	return nil;
 }
 
+static char*
+readblocking(Req *r, Channel *readchan)
+{
+	Channel *chan;
+	Stringpair pair;
+	char *err;
+
+	if(err = waitblocking(r, readchan, &chan))
+		return err;
+	pair.s = r->ofcall.data;
+	pair.ns = r->ifcall.count;
+	send(chan, &pair);
+	recv(chan, &pair);
+	r->ofcall.count = min(r->ifcall.count, pair.ns);
+	return nil;
+}
+
 static void
 xread(Req *r)
 {
@@ -720,12 +727,10 @@
 	Text *x;
 	vlong offset;
 	u32int count;
-	char *data, *p, *e;
+	char *data, *p, *e, *err;
 	Point pt;
-	Channel *kbd;
+	Channel *chan;
 	Stringpair pair;
-	enum { Adata, Agone, Aflush, NALT };
-	Alt alts[NALT+1];
 
 	xf = XF(r->fid);
 	w = xf->w;
@@ -746,25 +751,15 @@
 	switch(f){
 	case Qtext:
 	case Qcons:
-		alts[Adata] = ALT(w->conswrite, &kbd, CHANRCV);
-		alts[Agone] = ALT(w->gone, nil, CHANRCV);
-		alts[Aflush] = ALT(XR(r)->flush, nil, CHANRCV);
-		alts[NALT].op = CHANEND;
-		switch(alt(alts)){
-		case Adata:
-			cnvsize(&xf->cnv, count);
-			memmove(xf->cnv.buf+xf->cnv.n, data, count);
-			xf->cnv.n += count;
-			pair = b2r(&xf->cnv);
-			send(kbd, &pair);
-			break;
-		case Agone:
-			respond(r, Edeleted);
+		if(err = waitblocking(r, w->conswrite, &chan)){
+			respond(r, err);
 			return;
-		case Aflush:
-			respond(r, Eflush);
-			return;
 		}
+		cnvsize(&xf->cnv, count);
+		memmove(xf->cnv.buf+xf->cnv.n, data, count);
+		xf->cnv.n += count;
+		pair = b2r(&xf->cnv);
+		send(chan, &pair);
 		break;
 
 	case Qconsctl:
--- a/main.c
+++ b/main.c
@@ -482,7 +482,7 @@
 		Send,
 		Scroll
 	};
-	static char *menu2str[] = {
+	static char *str[] = {
 		"cut",
 		"paste",
 		"snarf",
@@ -492,7 +492,7 @@
 		"scroll",
 		nil
 	};
-	static Menu menu2 = { menu2str };
+	static Menu menu = { str };
 
 	int sel;
 	Text *x;
@@ -499,8 +499,8 @@
 	Cursor *c;
 
 	x = &w->text;
-	menu2str[Scroll] = w->scrolling ? "noscroll" : "scroll";
-	sel = menuhit(2, mctl, &menu2, wscreen);
+	str[Scroll] = w->scrolling ? "noscroll" : "scroll";
+	sel = menuhit(2, mctl, &menu, wscreen);
 	switch(sel){
 	case Cut:
 		xsnarf(x);
@@ -613,18 +613,30 @@
 {
 	enum {
 		RefreshScreen,
+		Scroll,
+		Title,
 		Exit
 	};
 	static char *str[] = {
 		"Refresh",
+		"Scroll",
+		"Title",
 		"Exit",
 		nil
 	};
 	static Menu menu = { str };
 
+	str[Scroll] = scrolling ? "!Scroll" : "Scroll";
+	str[Title] = notitle ? "Title" : "!Title";
 	switch(menuhit(3, mctl, &menu, wscreen)){
 	case RefreshScreen:
 		refresh();
+		break;
+	case Scroll:
+		scrolling = !scrolling;
+		break;
+	case Title:
+		notitle = !notitle;
 		break;
 	case Exit:
 		killprocs();
--- a/simple.c
+++ b/simple.c
@@ -69,12 +69,10 @@
 		r = w->rect;
 		border(w->frame, r, bordersz, wincolors[c], ZP);
 		border(w->frame, r, 1, wincolors[c2], ZP);
-		border(w->frame, insetrect(w->contrect,-1), 1, wincolors[c2], ZP);
 	}
 
 	if(!w->notitle){
 		r = w->titlerect;
-		r.max.y--;
 		draw(w->frame, r, wincolors[c], nil, ZP);
 
 		b1 = r;
@@ -93,6 +91,7 @@
 		if(w->cur)
 			string(w->frame, pt, wincolors[c1], pt, font, w->cur->label);
 	}
+	border(w->frame, insetrect(w->contrect,-1), 1, wincolors[c2], ZP);
 
 	r = rectsubpt(w->tabrect, Pt(0,1));
 	draw(w->frame, r, wincolors[c], nil, ZP);
--- a/wctl.c
+++ b/wctl.c
@@ -424,7 +424,7 @@
 
 	switch(cmd.cmd){
 	case Screenoffset:
-		screenoffset(r.min.x, r.min.y);
+		screenoffset(cmd.r.min.x, cmd.r.min.y);
 		return nil;
 	case Screenrefresh:
 		refresh();