tdevdraw: notify window resize promptly on x11 - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1f799495e4aa89be5f32e3fcda8da342f3057f3c
 (DIR) parent 40d787ab1276f191bcf030748a954d6708d83228
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Tue, 14 Jan 2020 19:43:32 -0500
       
       devdraw: notify window resize promptly on x11
       
       Fixes #339.
       
       Diffstat:
         M src/cmd/devdraw/devdraw.c           |       5 +----
         M src/cmd/devdraw/devdraw.h           |       1 +
         M src/cmd/devdraw/mac-screen.m        |       1 -
         M src/cmd/devdraw/srv.c               |      18 ++++++++++++++++++
         M src/cmd/devdraw/x11-screen.c        |      16 ++++++++--------
       
       5 files changed, 28 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/devdraw/devdraw.c b/src/cmd/devdraw/devdraw.c
       t@@ -55,10 +55,7 @@ gfx_replacescreenimage(Client *c, Memimage *m)
                        _freememimage(om);
                }
                qunlock(&c->drawlk);
       -
       -        qlock(&c->eventlk);
       -        c->mouse.resized = 1;
       -        qunlock(&c->eventlk);
       +        gfx_mouseresized(c);
        }
        
        static void
 (DIR) diff --git a/src/cmd/devdraw/devdraw.h b/src/cmd/devdraw/devdraw.h
       t@@ -187,6 +187,7 @@ void        gfx_keystroke(Client*, int);
        void        gfx_main(void);
        void        gfx_mousetrack(Client*, int, int, int, uint);
        void        gfx_replacescreenimage(Client*, Memimage*);
       +void        gfx_mouseresized(Client*);
        void        gfx_started(void);
        
        // rpc_* routines are called on the RPC thread,
 (DIR) diff --git a/src/cmd/devdraw/mac-screen.m b/src/cmd/devdraw/mac-screen.m
       t@@ -518,7 +518,6 @@ rpc_resizeimg(Client *c)
        - (void)resizeimg {
                [self initimg];
                gfx_replacescreenimage(self.client, self.img);
       -        [self sendmouse:0];
        }
        
        - (void)windowDidResize:(NSNotification *)notification {
 (DIR) diff --git a/src/cmd/devdraw/srv.c b/src/cmd/devdraw/srv.c
       t@@ -395,11 +395,29 @@ matchmouse(Client *c)
        }
        
        void
       +gfx_mouseresized(Client *c)
       +{
       +        gfx_mousetrack(c, -1, -1, -1, -1);
       +}
       +
       +void
        gfx_mousetrack(Client *c, int x, int y, int b, uint ms)
        {
                Mouse *m;
        
                qlock(&c->eventlk);
       +        if(x == -1 && y == -1 && b == -1 && ms == -1) {
       +                Mouse *copy;
       +                // repeat last mouse event for resize
       +                if(c->mouse.ri == 0)
       +                        copy = &c->mouse.m[nelem(c->mouse.m)-1];
       +                else
       +                        copy = &c->mouse.m[c->mouse.ri-1];
       +                x = copy->xy.x;
       +                y = copy->xy.y;
       +                b = copy->buttons;
       +                ms = copy->msec;
       +        }
                if(x < c->mouserect.min.x)
                        x = c->mouserect.min.x;
                if(x > c->mouserect.max.x)
 (DIR) diff --git a/src/cmd/devdraw/x11-screen.c b/src/cmd/devdraw/x11-screen.c
       t@@ -44,7 +44,7 @@ static Xwin*
        newxwin(Client *c)
        {
                Xwin *w;
       -        
       +
                w = mallocz(sizeof *w, 1);
                if(w == nil)
                        sysfatal("out of memory");
       t@@ -59,7 +59,7 @@ static Xwin*
        findxwin(XDrawable d)
        {
                Xwin *w, **l;
       -        
       +
                for(l=&_x.windows; (w=*l) != nil; l=&w->next) {
                        if(w->drawable == d) {
                                /* move to front */
       t@@ -658,7 +658,7 @@ xattach(Client *client, char *label, char *winsize)
                        _x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
                        _x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);
                }
       -        
       +
                atoms[0] = _x.takefocus;
                atoms[1] = _x.losefocus;
                XChangeProperty(_x.display, w->drawable, _x.wmprotos, XA_ATOM, 32,
       t@@ -700,7 +700,7 @@ xattach(Client *client, char *label, char *winsize)
                        _x.gcsimplesrc         = xgc(w->screenpm, FillStippled, -1);
                        _x.gczero        = xgc(w->screenpm, -1, -1);
                        _x.gcreplsrc        = xgc(w->screenpm, FillTiled, -1);
       -        
       +
                        pmid = XCreatePixmap(_x.display, w->drawable, 1, 1, 1);
                        _x.gcfill0        = xgc(pmid, FillSolid, 0);
                        _x.gccopy0        = xgc(pmid, -1, -1);
       t@@ -729,7 +729,7 @@ rpc_setlabel(Client *client, char *label)
        {
                Xwin *w = (Xwin*)client->view;
                XTextProperty name;
       -        
       +
                /*
                 * Label and other properties required by ICCCCM.
                 */
       t@@ -1032,7 +1032,7 @@ _xreplacescreenimage(Client *client)
                XDrawable pixmap;
                Rectangle r;
                Xwin *w;
       -        
       +
                w = (Xwin*)client->view;
                r = w->newscreenr;
                pixmap = XCreatePixmap(_x.display, w->drawable, Dx(r), Dy(r), _x.depth);
       t@@ -1527,7 +1527,7 @@ __xputsnarf(char *data)
        {
                XButtonEvent e;
                Xwin *w;
       -        
       +
                if(strlen(data) >= SnarfSize)
                        return;
                qlock(&clip.lk);
       t@@ -1730,7 +1730,7 @@ rpc_bouncemouse(Client *c, Mouse m)
                Xwin *w = (Xwin*)c->view;
                XButtonEvent e;
                XWindow dw;
       -        
       +
                xlock();
                e.type = ButtonPress;
                e.state = 0;