shithub: lola

Download patch

ref: f09a60d8cd60d2ec193b0315bfe0d7fd74b23406
parent: d525a8fd26307afc029ae75f7adfed741d5ee36f
author: aap <aap@papnet.eu>
date: Mon Jan 30 08:29:10 EST 2023

attach names; none attach

--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 rethink resizing and repainting
 rethink hiding/unhiding
 file permissions
-attach names (none, new, ...)
 border resize/move
 write text
 top/bottom/current seems to work a bit different in rio
--- a/fs.c
+++ b/fs.c
@@ -3,7 +3,13 @@
 enum {
 	Qroot,
 	Qwsys,
+	Qscreen,
+	Qsnarf,
+	Qwctl,
+	Qtap,
+	Qglobal = Qtap,	/* last global one */
 
+	/* these need a window */
 	Qcons,
 	Qconsctl,
 	Qcursor,
@@ -12,15 +18,11 @@
 	Qlabel,
 	Qkbd,
 	Qmouse,
-	Qscreen,
-	Qsnarf,
 	Qtext,
 	Qwdir,
 	Qwindow,
-	Qwctl,
-	Qtap,
 
-	NQids
+	NQids,
 };
 
 typedef struct Dirent Dirent;
@@ -153,7 +155,8 @@
 	xf = emalloc(sizeof(Xfid));
 	memset(&xf->cnv, 0, sizeof(xf->cnv));
 	xf->w = w;
-	incref(w);
+	if(w)
+		incref(w);
 	return xf;
 }
 
@@ -160,6 +163,7 @@
 #define QID(w, q) ((w)<<8|(q))
 #define QWIN(q) ((q)>>8)
 #define QFILE(q) ((q)&0xFF)
+#define ID(w) ((w) ? (w)->id : 0)
 
 static void
 fsattach(Req *r)
@@ -167,24 +171,37 @@
 	Window *w;
 	char *end;
 	int id;
+	Wctlcmd cmd;
 
-	w = nil;
-	if(strcmp(r->ifcall.aname, "new") == 0){
-// TODO: parse
-		w = wcreate(rectaddpt(newrect(), screen->r.min), FALSE, scrolling);
-		wincmd(w, 0, nil, nil);
+	if(strncmp(r->ifcall.aname, "new", 3) == 0){
+		cmd = parsewctl(r->ifcall.aname, ZR);
+		if(cmd.error){
+			respond(r, cmd.error);
+			return;
+		}
+		w = wcreate(cmd.r, cmd.hidden, cmd.scrolling);
+		if(w == nil){
+			respond(r, "window creation failed");
+			return;
+		}
+		wincmd(w, cmd.pid, cmd.dir, nil);
 		flushimage(display, 1);
 		decref(w);	/* don't delete, xfid will take it */
+	}else if(strncmp(r->ifcall.aname, "none", 4) == 0){
+		w = nil;
 	}else if(id = strtol(r->ifcall.aname, &end, 10), *end == '\0'){
 		w = wfind(id);
-	}
-	if(w == nil){
+		if(w == nil){
+			respond(r, "bad attach name");
+			return;
+		}
+	}else{
 		respond(r, "bad attach name");
 		return;
 	}
 
 	r->fid->aux = getxfid(w);
-	r->fid->qid = (Qid){QID(w->id,Qroot),0,QTDIR};
+	r->fid->qid = (Qid){QID(ID(w),Qroot),0,QTDIR};
 	r->ofcall.qid = r->fid->qid;
 	respond(r, nil);
 }
@@ -226,8 +243,9 @@
 		}
 		for(i = 0; i < nelem(dirents); i++){
 			d = &dirents[i];
-			if(!skipfile(d->name) && strcmp(name, d->name) == 0){
-				fid->qid = (Qid){QID(w->id,d->path), 0, d->type};
+			if((w || d->path <= Qglobal) &&
+			   !skipfile(d->name) && strcmp(name, d->name) == 0){
+				fid->qid = (Qid){QID(ID(w),d->path), 0, d->type};
 				*qid = fid->qid;
 				return nil;
 			}
@@ -236,7 +254,7 @@
 		char *end;
 		int id;
 		if(strcmp(name, "..") == 0){
-			fid->qid = (Qid){QID(w->id,Qroot), 0, QTDIR};
+			fid->qid = (Qid){QID(ID(w),Qroot), 0, QTDIR};
 			*qid = fid->qid;
 			return nil;
 		}
@@ -246,7 +264,7 @@
 				incref(w);
 				wrelease(xf->w);
 				xf->w = w;
-				fid->qid = (Qid){QID(w->id,Qroot), 0, QTDIR};
+				fid->qid = (Qid){QID(ID(w),Qroot), 0, QTDIR};
 				*qid = fid->qid;
 				return nil;
 			}
@@ -268,7 +286,9 @@
 		if(i >= nelem(dirents))
 			return -1;
 		/* we know the last file is never skipped */
-		while(skipfile(dirents[i].name)) i++;
+		while(w == nil && dirents[i].path > Qglobal ||
+		      skipfile(dirents[i].name))
+			i++;
 	}
 
 	d->atime = time(nil);
@@ -276,7 +296,7 @@
 	d->uid = estrdup9p(getuser());
 	d->gid = estrdup9p(d->uid);
 	d->muid = estrdup9p(d->uid);
-	d->qid = (Qid){QID(w->id,dirents[i].path), 0, dirents[i].type};
+	d->qid = (Qid){QID(ID(w),dirents[i].path), 0, dirents[i].type};
 	d->mode = 0664;
 	if(dirents[i].type & QTDIR)
 		d->mode |= 0111;
@@ -325,7 +345,7 @@
 
 	/* TODO: check and sanitize mode */
 
-	if(w == nil || w->deleted){
+	if(w && w->deleted){
 		respond(r, Edeleted);
 		return;
 	}
@@ -367,7 +387,7 @@
 		break;
 
 	case Qwctl:
-		if(r->ifcall.mode==ORDWR || r->ifcall.mode==OREAD){
+		if(w && (r->ifcall.mode==ORDWR || r->ifcall.mode==OREAD)){
 			/* can only have one reader of wctl */
 			if(w->wctlopen){
 				respond(r, Einuse);
@@ -438,7 +458,7 @@
 		break;
 
 	case Qwctl:
-		if(fid->omode==ORDWR || fid->omode==OREAD)
+		if(w && (fid->omode==ORDWR || fid->omode==OREAD))
 			w->wctlopen = FALSE;
 		break;
 
@@ -448,7 +468,8 @@
 		break;
 	}
 
-	wrelease(xf->w);
+	if(xf->w)
+		wrelease(xf->w);
 	free(xf->cnv.buf);
 	free(xf);
 	fid->aux = nil;
@@ -551,7 +572,7 @@
 
 	w = XF(r->fid)->w;
 
-	if(w == nil || w->deleted){
+	if(w && w->deleted){
 		respond(r, Edeleted);
 		return;
 	}
@@ -597,12 +618,25 @@
 		respond(r, readimg(r, w->img));
 		return;
 	case Qwctl:
-		if(r->ifcall.count < 4*12){
-			respond(r, Etooshort);
+/* TODO: what's with the Etooshort conditions?? */
+		if(w == nil){
+			if(r->ifcall.count < 6*12){
+				respond(r, Etooshort);
+				return;
+			}
+			data = smprint("%11d %11d %11d %11d nowindow    nowindow    ",
+				screen->r.min.x, screen->r.min.y, screen->r.max.x, screen->r.max.y);
+			readstr(r, data);
+			free(data);
+		}else{
+			if(r->ifcall.count < 4*12){
+				respond(r, Etooshort);
+				return;
+			}
+			respond(r, readblocking(r, w->wctlread));
 			return;
 		}
-		respond(r, readblocking(r, w->wctlread));
-		return;
+		break;
 	case Qtap:
 		respond(r, readblocking(r, totap));
 		return;
@@ -639,7 +673,7 @@
 	/* custom emalloc9p allows us this */
 	data[count] = '\0';
 
-	if(w == nil || w->deleted){
+	if(w && w->deleted){
 		respond(r, Edeleted);
 		return;
 	}
--- a/inc.h
+++ b/inc.h
@@ -246,6 +246,21 @@
 void wtype(Window *w, Rune r);
 int wincmd(Window *w, int pid, char *dir, char **argv);
 
+typedef struct Wctlcmd Wctlcmd;
+struct Wctlcmd
+{
+	int cmd;
+	Rectangle r;
+	char *args;
+	int pid;
+	int id;
+	bool hidden;
+	bool scrolling;
+	char *dir;
+	char *error;
+};
+
+Wctlcmd parsewctl(char *s, Rectangle r);
 char *writewctl(Window *w, char *data);
 
 enum{
--- a/main.c
+++ b/main.c
@@ -849,8 +849,8 @@
 threadmain(int, char *[])
 {
 	char buf[256];
-rfork(RFENVG);
-newwindow("-dx 1280 -dy 800");
+//rfork(RFENVG);
+//newwindow("-dx 1280 -dy 800");
 
 	if(getwd(buf, sizeof(buf)) == nil)
 		startdir = estrdup(".");