]> git.lizzy.rs Git - plan9front.git/commitdiff
vncv: adjust window size on desktop resize, fix canresize checks
authorcinap_lenrek <cinap_lenrek@felloff.net>
Tue, 21 Aug 2018 00:02:50 +0000 (02:02 +0200)
committercinap_lenrek <cinap_lenrek@felloff.net>
Tue, 21 Aug 2018 00:02:50 +0000 (02:02 +0200)
sys/src/cmd/vnc/draw.c
sys/src/cmd/vnc/vncv.h
sys/src/cmd/vnc/wsys.c

index eac7178339354bb7b542ffe2b1912d27074006ab..b83060f698fd844f14cd3176a34c638d6e1fc062 100644 (file)
@@ -29,6 +29,9 @@ vncsetdim(Vnc *v, Rectangle dim)
        pixbuf = realloc(pixbuf, v->dim.max.x * pixb * v->dim.max.y);
        if(linebuf == nil || pixbuf == nil)
                sysfatal("can't allocate pix decompression storage");
+       lockdisplay(display);
+       adjustwin(v, 0);
+       unlockdisplay(display);
 }
 
 static void
@@ -79,7 +82,7 @@ requestupdate(Vnc *v, int incremental)
        r = rectsubpt(screen->r, screen->r.min);
        unlockdisplay(display);
        vnclock(v);
-       if(incremental == 0 && v->canresize && !eqrect(r, v->dim)){
+       if(incremental == 0 && (v->canresize&2)!=0 && !eqrect(r, v->dim)){
                vncwrchar(v, MSetDesktopSize);
                vncwrchar(v, 0);
                vncwrpoint(v, r.max);
index c4f9bcbe32514ed5e3210932a65eb6735169b863..564ef0b9ce3e053cc6bb15710754910fbc7d10b0 100644 (file)
@@ -18,6 +18,7 @@ extern        Vnc*            vnc;
 extern int             mousefd;
 
 /* wsys.c */
+extern void            adjustwin(Vnc*, int);
 extern void            readkbd(Vnc*);
 extern void            initmouse(void);
 extern void            mousewarp(Point);
index 21c8ce424b1d2ceeaedd947fa8340c69c49885b4..81ffb39d9385ab21e156cc13ff210e31bc1869cc 100644 (file)
@@ -10,35 +10,46 @@ struct Mouse {
        Point xy;
 };
 
-static void
-resize(Vnc *v, int first)
+void
+adjustwin(Vnc *v, int force)
 {
        int fd;
        Point d;
 
-       lockdisplay(display);
-       if(getwindow(display, Refnone) < 0)
-               sysfatal("internal error: can't get the window image");
-       if(!v->canresize){
+       if(force)
+               d = v->dim.max;
+       else {
                /*
                 * limit the window to at most the vnc server's size
                 */
-               d = addpt(v->dim.max, Pt(2*Borderwidth, 2*Borderwidth));
-               if(first || d.x < Dx(screen->r) || d.y < Dy(screen->r)){
-                       fd = open("/dev/wctl", OWRITE);
-                       if(fd >= 0){
-                               fprint(fd, "resize -dx %d -dy %d", d.x, d.y);
-                               close(fd);
-                       }
+               d = subpt(screen->r.max, screen->r.min);
+               if(d.x > v->dim.max.x){
+                       d.x = v->dim.max.x;
+                       force = 1;
+               }
+               if(d.y > v->dim.max.y){
+                       d.y = v->dim.max.y;
+                       force = 1;
+               }
+       }
+       if(force) {
+               fd = open("/dev/wctl", OWRITE);
+               if(fd >= 0){
+                       fprint(fd, "resize -dx %d -dy %d", d.x+2*Borderwidth, d.y+2*Borderwidth);
+                       close(fd);
                }
        }
-       unlockdisplay(display);
 }
 
 static void
-eresized(void)
+resized(int first)
 {
-       resize(vnc, 0);
+       lockdisplay(display);
+       if(getwindow(display, Refnone) < 0)
+               sysfatal("internal error: can't get the window image");
+       if((vnc->canresize&2) == 0)
+               adjustwin(vnc, first);
+       unlockdisplay(display);
        requestupdate(vnc, 0);
 }
 
@@ -130,8 +141,7 @@ readmouse(Vnc *v)
        memmove(curs+2*4, cs->clr, 2*2*16);
        write(cursorfd, curs, sizeof curs);
 
-       resize(v, 1);
-       requestupdate(vnc, 0);
+       resized(1);
        start = end = buf;
        len = 0;
        for(;;){
@@ -155,8 +165,7 @@ readmouse(Vnc *v)
                                        }
                                }
                        } else
-                               eresized();
-
+                               resized(0);
                        start += EventSize;
                        len -= EventSize;
                }