git: 9front

Download patch

ref: 14244da5be11e77e2f4de8b609377e0e14b073b2
parent: d8c23cddc270daad840b822fdb9056466cf8b14d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Dec 7 11:32:04 EST 2018

rio: get rid of window delete thread, fix mysterious disappearing windows

because a client might not handle resize, rio would try to move ther
window offsceen after 750 ms. however, it does this by window name,
which could have been reassigned by another concurrent rio, causing the
wrong window to disappear.

now we always move the window offscreen before freeimage(). this way we
are sure to still have the right reference to the original window.

--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -341,7 +341,6 @@
 int		scrolling;
 int		maxtab;
 Channel*	winclosechan;
-Channel*	deletechan;
 char		*startdir;
 int		sweeping;
 int		wctlfd;
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -39,7 +39,6 @@
 void	mousethread(void*);
 void	keyboardthread(void*);
 void	winclosethread(void*);
-void	deletethread(void*);
 void	initcmd(void*);
 Channel* initkbd(void);
 
@@ -190,7 +189,6 @@
 
 	exitchan = chancreate(sizeof(int), 0);
 	winclosechan = chancreate(sizeof(Window*), 0);
-	deletechan = chancreate(sizeof(char*), 0);
 
 	view = screen;
 	viewr = view->r;
@@ -211,7 +209,6 @@
 	threadcreate(keyboardthread, nil, STACK);
 	threadcreate(mousethread, nil, STACK);
 	threadcreate(winclosethread, nil, STACK);
-	threadcreate(deletethread, nil, STACK);
 	filsys = filsysinit(xfidinit());
 
 	if(filsys == nil)
@@ -427,37 +424,6 @@
 		w = recvp(winclosechan);
 		wclose(w);
 	}
-}
-
-/* thread to make Deleted windows that the client still holds disappear offscreen after an interval */
-void
-deletethread(void*)
-{
-	char *s;
-	Image *i;
-
-	threadsetname("deletethread");
-	for(;;){
-		s = recvp(deletechan);
-		i = namedimage(display, s);
-		if(i != nil){
-			/* move it off-screen to hide it, since client is slow in letting it go */
-			originwindow(i, i->r.min, view->r.max);
-			freeimage(i);
-			flushimage(display, 1);
-		}
-		free(s);
-	}
-}
-
-void
-deletetimeoutproc(void *v)
-{
-	char *s;
-
-	s = v;
-	sleep(750);	/* remove window from screen after 3/4 of a second */
-	sendp(deletechan, s);
 }
 
 /*
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -12,8 +12,6 @@
 #include "dat.h"
 #include "fns.h"
 
-#define MOVEIT if(0)
-
 enum
 {
 	HiWater	= 640000,	/* max size of history */
@@ -91,7 +89,7 @@
 {
 	Rectangle r;
 
-	freeimage(w->i);
+	wclosewin(w);
 	w->i = i;
 	w->mc.image = i;
 	r = insetrect(i->r, Selborder+1);
@@ -1099,7 +1097,6 @@
 int
 wctlmesg(Window *w, int m, Rectangle r, void *p)
 {
-	char *oldname;
 	Image *i = p;
 
 	switch(m){
@@ -1115,10 +1112,8 @@
 			freeimage(i);
 			break;
 		}
-		oldname = estrdup(w->name);
 		w->screenr = r;
 		wresize(w, i);
-		proccreate(deletetimeoutproc, oldname, 4096);
 		if(Dx(r)<=0){	/* window got hidden, if we had the input, drop it */
 			if(w==input)
 				input = nil;
@@ -1205,14 +1200,13 @@
 		wclunk(w);
 		if(w->notefd >= 0)
 			write(w->notefd, "hangup", 6);
-		if(w->i!=nil){
-			proccreate(deletetimeoutproc, estrdup(w->name), 4096);
-			wclosewin(w);
-		}
+		wclosewin(w);
+		flushimage(display, 1);
 		break;
 	case Exited:
 		wclosewin(w);
 		frclear(w, TRUE);
+		flushimage(display, 1);
 		if(w->notefd >= 0)
 			close(w->notefd);
 		chanfree(w->mc.c);
@@ -1397,18 +1391,13 @@
 void
 wclosewin(Window *w)
 {
-	Image *i;
-
-	assert(w->deleted==TRUE);
-
-	i = w->i;
-	if(i){
-		w->i = nil;
-		/* move it off-screen to hide it, in case client is slow in letting it go */
-		MOVEIT originwindow(i, i->r.min, view->r.max);
-		freeimage(i);
-		flushimage(display, 1);
-	}
+	Image *i = w->i;
+	if(i == nil)
+		return;
+	w->i = nil;
+	/* move it off-screen to hide it, in case client is slow in letting it go */
+	originwindow(i, i->r.min, view->r.max);
+	freeimage(i);
 }
 
 void
--