Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Blame | Last modification | View Log | RSS feed

Description: Make autoscaling work.
 1) Add a StructureNotifyMask event handler to be notified of windows resizings,
    rather than checking for size changes twice every second in the Expose handler.
    Using the size of "form" seems to work best. Skip checking for pressed mouse
    buttons - those shouldn't matter in this situation, and the old code aborted
    if modifier keys were pressed or Caps Lock or Num Lock active.
 2) Avoid freaking out if the windows haven't been realized yet -
    instead use scale factor 1. This prevented setting -scale auto
    on the command line from working.
Bug: https://sourceforge.net/p/ssvnc/bugs/5/
Bug-Debian: https://bugs.debian.org/801804
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/ssvnc/+bug/1312966

--- a/vnc_unixsrc/vncviewer/desktop.c
+++ b/vnc_unixsrc/vncviewer/desktop.c
@@ -55,6 +55,7 @@ static Cursor CreateDotCursor();
 static void CopyBGR233ToScreen(CARD8 *buf, int x, int y, int width,int height);
 static void HandleBasicDesktopEvent(Widget w, XtPointer ptr, XEvent *ev,
                                    Boolean *cont);
+static void HandleResizeEvent(Widget w, XtPointer ptr, XEvent *ev, Boolean *cont);
 
 static void CopyBGR565ToScreen(CARD16 *buf, int x, int y, int width,int height);
 
@@ -110,6 +111,8 @@ void get_scale_values(double *fx, double
                if (w > 32 && h > 32) {
                        frac_x = ((double) w) / ((double) xmax);
                        frac_y = ((double) h) / ((double) ymax);
+               } else {
+                   frac_x = frac_y = 1.0;
                }
        }
        if (frac_x < 0.0 && sscanf(s, "%lf", &f) == 1) {
@@ -456,7 +459,11 @@ void create_image() {
                                        scale_x = w;
                                        scale_y = h;
 
-                                       XtVaSetValues(toplevel, XtNmaxWidth, w, XtNmaxHeight, hyc, NULL);
+                                       if (!strcmp(appData.scale, "auto")) {
+                                               XtVaSetValues(toplevel, XtNmaxWidth, dpyWidth, XtNmaxHeight, dpyHeight, NULL);
+                                       } else {
+                                               XtVaSetValues(toplevel, XtNmaxWidth, w, XtNmaxHeight, hyc, NULL);
+                                       }
 
                                        h2 = scale_round(si.framebufferHeight, frac_y);
                                        XtVaSetValues(desktop,  XtNwidth, w, XtNheight, h2, NULL);
@@ -561,6 +568,8 @@ DesktopInitBeforeRealization()
 
        XtAddEventHandler(desktop, LeaveWindowMask|EnterWindowMask|ExposureMask,
            True, HandleBasicDesktopEvent, NULL);
+       XtAddEventHandler(form, StructureNotifyMask,
+           False, HandleResizeEvent, NULL);
 
        if (appData.yCrop) {
                int hm;
@@ -707,39 +716,6 @@ void check_things() {
        dpyWidth  = WidthOfScreen(DefaultScreenOfDisplay(dpy));
        dpyHeight = HeightOfScreen(DefaultScreenOfDisplay(dpy));
 
-       if (appData.scale != NULL) {
-               static Dimension last_w = 0, last_h = 0;
-               static double last_resize = 0.0;
-               Dimension w, h;
-               if (last_w == 0) {
-                       XtVaGetValues(toplevel, XtNwidth, &last_w, XtNheight, &last_h, NULL);
-                       last_resize = now;
-               }
-               if (now < last_resize + 0.5) {
-                       ;
-               } else if (appData.fullScreen) {
-                       ;
-               } else if (!strcmp(appData.scale, "auto")) {
-                       XtVaGetValues(toplevel, XtNwidth, &w, XtNheight, &h, NULL);
-                       if (w < 32 || h < 32)  {
-                               ;
-                       } else if (last_w != w || last_h != h) {
-                               Window rr, cr, r = DefaultRootWindow(dpy);
-                               int rx, ry, wx, wy;
-                               unsigned int mask;
-                               /* make sure mouse buttons not pressed */
-                               if (XQueryPointer(dpy, r, &rr, &cr, &rx, &ry, &wx, &wy, &mask)) {
-                                       if (mask == 0) {
-                                               rescale_image();
-                                               last_w = w;
-                                               last_h = h;
-                                               last_resize = dnow();
-                                       }
-                               }
-                       }
-               }
-       }
-
        last = dnow();
 }
 
@@ -1546,6 +1522,22 @@ void releaseAllPressedModifiers(void) {
 
 #define PR_EXPOSE fprintf(stderr, "Expose: %04dx%04d+%04d+%04d %04d/%04d/%04d now: %8.4f rescale: %8.4f fullscreen: %8.4f\n", width, height, x, y, si.framebufferWidth, appData.yCrop, si.framebufferHeight, now - start_time, now - last_rescale, now - last_fullscreen);
 
+static void
+HandleResizeEvent(Widget wdg, XtPointer ptr, XEvent *ev, Boolean *cont)
+{
+    static Dimension last_w = 0, last_h = 0;
+    Dimension w, h;
+    
+    if (ev->type == ConfigureNotify && !appData.fullScreen
+       && appData.scale != NULL && !strcasecmp(appData.scale, "auto")) {
+       XtVaGetValues(form, XtNwidth, &w, XtNheight, &h, NULL);
+       if (w != last_w || h != last_h) {
+           rescale_image();
+           last_w = w;
+           last_h = h;
+       }
+    }
+}
 /*
  * HandleBasicDesktopEvent - deal with expose and leave events.
  */