Attempt to better guess the initial size of the window when viewing images

This commit is contained in:
Pierre Pronchery 2014-09-10 21:12:07 +02:00
parent a46a1689c0
commit 78ab3ef4af

View File

@ -292,8 +292,8 @@ static GtkWidget * _new_image(View * view, char const * path)
GtkWidget * window; GtkWidget * window;
GError * error = NULL; GError * error = NULL;
GdkPixbufAnimation * pixbuf; GdkPixbufAnimation * pixbuf;
int pw; int width;
int ph; int height;
GdkScreen * screen; GdkScreen * screen;
gint monitor; gint monitor;
GdkRectangle rect; GdkRectangle rect;
@ -312,8 +312,11 @@ static GtkWidget * _new_image(View * view, char const * path)
view->view = gtk_image_new_from_animation(pixbuf); view->view = gtk_image_new_from_animation(pixbuf);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(window), gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(window),
view->view); view->view);
pw = gdk_pixbuf_animation_get_width(pixbuf) + 4; /* get the current window size */
ph = gdk_pixbuf_animation_get_height(pixbuf) + 4; gtk_window_get_size(GTK_WINDOW(view->window), &width, &height);
/* add the size of the image */
width += gdk_pixbuf_animation_get_width(pixbuf);
height += gdk_pixbuf_animation_get_height(pixbuf);
/* get the current monitor size */ /* get the current monitor size */
screen = gdk_screen_get_default(); screen = gdk_screen_get_default();
#if GTK_CHECK_VERSION(2, 14, 0) #if GTK_CHECK_VERSION(2, 14, 0)
@ -325,8 +328,9 @@ static GtkWidget * _new_image(View * view, char const * path)
#endif #endif
gdk_screen_get_monitor_geometry(screen, monitor, &rect); gdk_screen_get_monitor_geometry(screen, monitor, &rect);
/* set an upper bound to the size of the window */ /* set an upper bound to the size of the window */
gtk_window_set_default_size(GTK_WINDOW(view->window), min(pw, gtk_window_set_default_size(GTK_WINDOW(view->window),
rect.width), min(ph, rect.height)); min(width, rect.width),
min(height, rect.height));
return window; return window;
} }