Commit dfe3c40f authored by Richard Molitor's avatar Richard Molitor
Browse files

zoom: implement scale-down without flicker

this actually uses the old "force geometry" workaround to get the
scale down behaviour (which makes the code a lot cleaner) by
first setting the geometry after the window is created (to avoid
creating a 0x0 sized window, which X does not like).
parent cbf5046f
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -612,14 +612,8 @@ void feh_event_handle_keypress(XEvent * ev)
	}
	else if (feh_is_kp(&keys.zoom_default, keysym, state)) {
		winwid->zoom = 1.0;
		/* --scale-down will revert our operation if old_zoom == 1.0 */
		if (opt.scale_down)
			winwid->old_zoom = 1.001;
		winwidget_center_image(winwid);
		winwidget_render_image(winwid, 0, 0);
		/* --scale-down will also do weird stuff if zoom is 1.0 */
		if (opt.scale_down)
			winwid->zoom = 1.001;
	}
	else if (feh_is_kp(&keys.zoom_fit, keysym, state)) {
		feh_calc_needed_zoom(&winwid->zoom, winwid->im_w, winwid->im_h, winwid->w, winwid->h);
+8 −25
Original line number Diff line number Diff line
@@ -298,6 +298,11 @@ void winwidget_create_window(winwidget ret, int w, int h)
	XSetCommand(disp, ret->win, cmdargv, cmdargc);

	winwidget_register(ret);
	if (opt.scale_down) {
		opt.geom_w = w;
		opt.geom_h = h;
		opt.geom_flags |= WidthValue | HeightValue;
	}
	return;
}

@@ -409,28 +414,6 @@ void winwidget_render_image(winwidget winwid, int resize, int force_alias)

	winwidget_setup_pixmaps(winwid);

	if (!winwid->full_screen && opt.scale_down &&
							  (winwid->type != WIN_TYPE_THUMBNAIL) &&
							  (winwid->old_zoom == 1.0)) {
        int max_w = winwid->w, max_h = winwid->h;
        if (opt.geom_flags & WidthValue) {
            max_w = opt.geom_w;
        }
        if (opt.geom_flags & HeightValue) {
            max_h = opt.geom_h;
        }
        D(("max: %dx%d, size: %dx%d\n", max_w, max_h, winwid->im_w, winwid->im_h));
        if (max_w < winwid->im_w || max_h < winwid->im_h) {
            D(("scaling down image %dx%d\n", max_w, max_h));

            feh_calc_needed_zoom(&(winwid->zoom), winwid->im_w, winwid->im_h,
                    max_w, max_h);
            if (resize)
                winwidget_resize(winwid, winwid->im_w * winwid->zoom, winwid->im_h * winwid->zoom);
            D(("after scaling down image %dx%d\n", winwid->w, winwid->h));
        }
	}

	if (!winwid->full_screen && ((gib_imlib_image_has_alpha(winwid->im))
				     || (opt.geom_flags & (WidthValue | HeightValue))
				     || (winwid->im_x || winwid->im_y) || (winwid->zoom != 1.0)
@@ -445,7 +428,7 @@ void winwidget_render_image(winwidget winwid, int resize, int force_alias)


	if (resize && (winwid->full_screen
                     || (!opt.scale_down && (opt.geom_flags & (WidthValue | HeightValue))))) {
                     || (opt.geom_flags & (WidthValue | HeightValue)))) {
		int smaller;	/* Is the image smaller than screen? */
		int max_w = 0, max_h = 0;

@@ -533,7 +516,7 @@ void winwidget_render_image(winwidget winwid, int resize, int force_alias)
			winwid->im_y = (int) (max_h - (winwid->im_h * winwid->zoom)) >> 1;
		}
	}
	else if (need_center && !winwid->full_screen && opt.scale_down
	else if (need_center && !winwid->full_screen
			&& (winwid->type != WIN_TYPE_THUMBNAIL)) {
		winwid->im_x = (int) (winwid->w - (winwid->im_w * winwid->zoom)) >> 1;
		winwid->im_y = (int) (winwid->h - (winwid->im_h * winwid->zoom)) >> 1;
@@ -848,7 +831,7 @@ void winwidget_resize(winwidget winwid, int w, int h)
	D(("   x %d y %d w %d h %d\n", attributes.x, attributes.y, winwid->w,
		winwid->h));

    if (!opt.scale_down && opt.geom_flags & (WidthValue | HeightValue)) {
    if (opt.geom_flags & (WidthValue | HeightValue)) {
        winwid->had_resize = 1;
        return;
    }