Skip to content

Commit

Permalink
Fix the windowsize
Browse files Browse the repository at this point in the history
Opening a new window from a collection should not set the default size.
Unfortunately the size of the image is not available in the early state.
  • Loading branch information
mowgli committed Dec 23, 2010
1 parent 55de20b commit 6e695dd
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
35 changes: 35 additions & 0 deletions src/gq-marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ gq_marshal_VOID__INT_INT_INT_INT(GClosure *closure,
data2);
}

void gq_marshal_VOID__INT_INT(GClosure *closure,
GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1,
gint arg_1,
gint arg_2,
gpointer data2);
register GMarshalFunc_VOID__INT_INT callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;

g_return_if_fail(n_param_values == 3);

if (G_CCLOSURE_SWAP_DATA(closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer(param_values + 0);
}
else
{
data1 = g_value_peek_pointer(param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);

callback(data1,
g_marshal_value_peek_int(param_values + 1),
g_marshal_value_peek_int(param_values + 2),
data2);
}

/* VOID:DOUBLE (gq-marshal.list:3) */

/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
7 changes: 7 additions & 0 deletions src/gq-marshal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ extern void gq_marshal_VOID__INT_INT_INT_INT (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);

extern void gq_marshal_VOID__INT_INT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);

/* VOID:DOUBLE (gq-marshal.list:3) */
#define gq_marshal_VOID__DOUBLE g_cclosure_marshal_VOID__DOUBLE

Expand Down
22 changes: 20 additions & 2 deletions src/image-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum {
SIGNAL_ERROR,
SIGNAL_DONE,
SIGNAL_PERCENT,
SIGNAL_SIZE,
SIGNAL_COUNT
};

Expand Down Expand Up @@ -150,6 +151,17 @@ static void image_loader_class_init(ImageLoaderClass *class)
G_TYPE_NONE, 1,
G_TYPE_DOUBLE);

signals[SIGNAL_SIZE] =
g_signal_new("size_prepared",
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
NULL, NULL,
gq_marshal_VOID__INT_INT,
G_TYPE_NONE, 2,
G_TYPE_INT,
G_TYPE_INT);

}

static void image_loader_finalize(GObject *object)
Expand Down Expand Up @@ -424,6 +436,7 @@ static void image_loader_size_cb(GdkPixbufLoader *loader,
if (il->requested_width < 1 || il->requested_height < 1)
{
g_mutex_unlock(il->data_mutex);
g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
return;
}
g_mutex_unlock(il->data_mutex);
Expand All @@ -440,13 +453,17 @@ static void image_loader_size_cb(GdkPixbufLoader *loader,
}
g_strfreev(mime_types);

if (!scale) return;
if (!scale)
{
g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
return;
}

g_mutex_lock(il->data_mutex);

gint nw, nh;
if (width > il->requested_width || height > il->requested_height)
{
gint nw, nh;

if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
{
Expand All @@ -466,6 +483,7 @@ static void image_loader_size_cb(GdkPixbufLoader *loader,
}
g_mutex_unlock(il->data_mutex);

g_signal_emit(il, signals[SIGNAL_SIZE], 0, nw, nh);
}

static void image_loader_stop_loader(ImageLoader *il)
Expand Down
9 changes: 9 additions & 0 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,14 @@ static void image_load_done_cb(ImageLoader *il, gpointer data)
image_read_ahead_start(imd);
}

static void image_load_size_cb(ImageLoader *il, guint width, guint height, gpointer data)
{
ImageWindow *imd = data;

DEBUG_1("image_load_size_cb: %dx%d", width, height);
pixbuf_renderer_set_size_early((PixbufRenderer *)imd->pr, width, height);
}

static void image_load_error_cb(ImageLoader *il, gpointer data)
{
DEBUG_1("%s image error", get_exec_time());
Expand All @@ -674,6 +682,7 @@ static void image_load_set_signals(ImageWindow *imd, gboolean override_old_signa
g_signal_connect(G_OBJECT(imd->il), "area_ready", (GCallback)image_load_area_cb, imd);
g_signal_connect(G_OBJECT(imd->il), "error", (GCallback)image_load_error_cb, imd);
g_signal_connect(G_OBJECT(imd->il), "done", (GCallback)image_load_done_cb, imd);
g_signal_connect(G_OBJECT(imd->il), "size_prepared", (GCallback)image_load_size_cb, imd);
}

/* this read ahead is located here merely for the callbacks, above */
Expand Down
7 changes: 7 additions & 0 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionDat
image_change_fd(vw->imd, fd, image_zoom_get_default(NULL));
}

/* Wait until image is loaded otherwise size is not defined */
for (int count = 10; count && !w && !h; count++)
{
image_get_image_size(vw->imd, &w, &h);
usleep(100000);
}

if (image_zoom_get(vw->imd) == 0.0)
{
image_get_image_size(vw->imd, &w, &h);
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
#define DEFAULT_THUMB_WIDTH 96
#define DEFAULT_THUMB_HEIGHT 72

#define DEFAULT_MINIMAL_WINDOW_SIZE 32
#define DEFAULT_MINIMAL_WINDOW_SIZE 100

#define IMAGE_MIN_WIDTH 100
#define SIDEBAR_DEFAULT_WIDTH 250
Expand Down
25 changes: 22 additions & 3 deletions src/pixbuf-renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,7 @@ static void pr_update_signal(PixbufRenderer *pr)
#if 0
log_printf("FIXME: send updated signal\n");
#endif
DEBUG_1("%s pixbuf renderer updated - started drawing %p", get_exec_time(), pr);
DEBUG_1("%s pixbuf renderer updated - started drawing %p, img: %dx%d", get_exec_time(), pr, pr->image_width, pr->image_height);
pr->debug_updated = TRUE;
}

Expand Down Expand Up @@ -4357,7 +4357,7 @@ gboolean pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint *h
g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
g_return_val_if_fail(width != NULL && height != NULL, FALSE);

if (!pr->pixbuf && !pr->source_tiles_enabled)
if (!pr->pixbuf && !pr->source_tiles_enabled && (!pr->image_width || !pr->image_height))
{
*width = 0;
*height = 0;
Expand All @@ -4374,7 +4374,7 @@ gboolean pixbuf_renderer_get_scaled_size(PixbufRenderer *pr, gint *width, gint *
g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
g_return_val_if_fail(width != NULL && height != NULL, FALSE);

if (!pr->pixbuf && !pr->source_tiles_enabled)
if (!pr->pixbuf && !pr->source_tiles_enabled && (!pr->image_width || !pr->image_height))
{
*width = 0;
*height = 0;
Expand Down Expand Up @@ -4428,4 +4428,23 @@ gboolean pixbuf_renderer_get_virtual_rect(PixbufRenderer *pr, GdkRectangle *rect
rect->height = pr->vis_height;
return TRUE;
}

void pixbuf_renderer_set_size_early(PixbufRenderer *pr, guint width, guint height)
{
gdouble zoom;
gint w, h;

zoom = pixbuf_renderer_zoom_get(pr);
pr->image_width = width;
pr->image_height = height;

pr_zoom_clamp(pr, zoom, PR_ZOOM_FORCE, NULL);

//w = width;
//h = height;

//pr->width = width;
//pr->height = height;
}

/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
2 changes: 2 additions & 0 deletions src/pixbuf-renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,7 @@ gboolean pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel, g
gboolean pixbuf_renderer_get_pixel_colors(PixbufRenderer *pr, gint x_pixel, gint y_pixel,
gint *r_mouse, gint *g_mouse, gint *b_mouse);

void pixbuf_renderer_set_size_early(PixbufRenderer *pr, guint width, guint height);

#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */

0 comments on commit 6e695dd

Please sign in to comment.