From b5783b1e39122f466c1a577720496284223e2217 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 7 Mar 2021 20:26:30 +0100 Subject: rio: make window focus changes deterministic, cleanup wind.c Switching window focus used to be non deterministic as the current window in focus (Window *input) was set concurrently while processing window messages such as Resized and Topped. This implements a new approach where wcurrent() and wuncurrent() are responsible for the synchronization and switch of the input. It is implemented by sending a Repaint message to the old input window first, neccesarily waiting until that window releases the focus and then input is updated and then a Topped or Reshaped message is send to the new input window. Note, that when the whole screen is resized that no input changes need to happening anymore. --- sys/src/cmd/rio/dat.h | 22 +- sys/src/cmd/rio/rio.c | 28 +- sys/src/cmd/rio/wctl.c | 4 +- sys/src/cmd/rio/wind.c | 3102 ++++++++++++++++++++++++------------------------ 4 files changed, 1571 insertions(+), 1585 deletions(-) diff --git a/sys/src/cmd/rio/dat.h b/sys/src/cmd/rio/dat.h index edc855595..dac32da5f 100644 --- a/sys/src/cmd/rio/dat.h +++ b/sys/src/cmd/rio/dat.h @@ -183,45 +183,25 @@ Window* wtop(Point); void wtopme(Window*); void wbottomme(Window*); char* wcontents(Window*, int*); -int wbswidth(Window*, Rune); -int wclickmatch(Window*, int, int, int, uint*); int wclose(Window*); -int wctlmesg(Window*, int, Rectangle, void*); uint wbacknl(Window*, uint, uint); -uint winsert(Window*, Rune*, int, uint); -void waddraw(Window*, Rune*, int); -void wborder(Window*, int); -void wclunk(Window*); -void wclosewin(Window*); void wcurrent(Window*); +void wuncurrent(Window*); void wcut(Window*); -void wdelete(Window*, uint, uint); -void wstretchsel(Window*, uint, uint*, uint*, int); -void wfill(Window*); -void wframescroll(Window*, int); -void wkeyctl(Window*, Rune); -void wmousectl(Window*); -void wmovemouse(Window*, Point); void wpaste(Window*); void wplumb(Window*); void wlook(Window*); -void wrefresh(Window*); -void wrepaint(Window*); -void wresize(Window*, Image*); void wscrdraw(Window*); void wscroll(Window*, int); -void wselect(Window*); void wsend(Window*); void wsendctlmesg(Window*, int, Rectangle, void*); void wsetcursor(Window*, int); void wsetname(Window*); void wsetorigin(Window*, uint, int); void wsetpid(Window*, int, int); -void wsetselect(Window*, uint, uint); void wshow(Window*, uint); void wsnarf(Window*); void wscrsleep(Window*, uint); -void wsetcols(Window*, int); struct Dirtab { diff --git a/sys/src/cmd/rio/rio.c b/sys/src/cmd/rio/rio.c index a28fb2ccc..9c18a6955 100644 --- a/sys/src/cmd/rio/rio.c +++ b/sys/src/cmd/rio/rio.c @@ -530,8 +530,10 @@ mousethread(void*) else i = drag(winput); sweeping = FALSE; - if(i != nil) + if(i != nil){ + wcurrent(winput); wsendctlmesg(winput, Reshaped, i->r, i); + } wclose(winput); continue; } @@ -616,9 +618,10 @@ resized(void) if(j < nhidden){ im = allocimage(display, r, screen->chan, 0, DNofill); r = ZR; - } else + } else { im = allocwindow(wscreen, r, Refbackup, DNofill); - if(im) + } + if(im!=nil) wsendctlmesg(w, Reshaped, r, im); wclose(w); } @@ -1001,7 +1004,7 @@ delete(void) Window *w; w = pointto(TRUE); - if(w) + if(w!=nil) wsendctlmesg(w, Deleted, ZR, nil); } @@ -1016,8 +1019,10 @@ resize(void) return; incref(w); i = sweep(); - if(i) + if(i!=nil){ + wcurrent(w); wsendctlmesg(w, Reshaped, i->r, i); + } wclose(w); } @@ -1032,8 +1037,10 @@ move(void) return; incref(w); i = drag(w); - if(i) + if(i!=nil){ + wcurrent(w); wsendctlmesg(w, Reshaped, i->r, i); + } wclose(w); } @@ -1049,8 +1056,9 @@ whide(Window *w) if(nhidden >= nelem(hidden)) return 0; incref(w); + wuncurrent(w); i = allocimage(display, w->screenr, w->i->chan, 0, DNofill); - if(i){ + if(i!=nil){ hidden[nhidden++] = w; wsendctlmesg(w, Reshaped, ZR, i); } @@ -1070,8 +1078,9 @@ wunhide(Window *w) if(j == nhidden) return -1; /* not hidden */ incref(w); + wcurrent(w); i = allocwindow(wscreen, w->i->r, Refbackup, DNofill); - if(i){ + if(i!=nil){ --nhidden; memmove(hidden+j, hidden+j+1, (nhidden-j)*sizeof(Window*)); wsendctlmesg(w, Reshaped, w->i->r, i); @@ -1109,8 +1118,9 @@ unhide(int j) for(j=0; j