summaryrefslogtreecommitdiff
path: root/window_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'window_main.c')
-rw-r--r--window_main.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/window_main.c b/window_main.c
index 95cfe7f..38e1899 100644
--- a/window_main.c
+++ b/window_main.c
@@ -17,7 +17,8 @@ struct wallpaper_t *cur_wall = NULL;
GdkPixbuf *orig_pixbuf = NULL;
gint last_width = 0,
last_height = 0,
- last_pos = 0;
+ hpane_last_pos = 0;
+guint hpane_source_id = 0;
GtkWindow *window;
GtkImage *image = NULL;
@@ -76,9 +77,13 @@ static void resize_pixbuf() {
gint win_width, win_height, img_width, img_height, width, height;
gdouble scalex, scaley, width_ratio, height_ratio, max_ratio;
+ /* Skip if no pixbuf is loaded yet. */
+ if(!orig_pixbuf) return;
+
window = gtk_widget_get_window(layout);
gdk_drawable_get_size(window, &win_width, &win_height);
gtk_layout_set_size(GTK_LAYOUT(layout), win_width, win_height);
+
img_width = gdk_pixbuf_get_width(orig_pixbuf);
img_height = gdk_pixbuf_get_height(orig_pixbuf);
@@ -98,6 +103,7 @@ static void resize_pixbuf() {
scalex = (gdouble)width / (gdouble)img_width;
scaley = (gdouble)height / (gdouble)img_height;
}
+ if(width == 0 || height == 0) return;
pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
gdk_pixbuf_scale(orig_pixbuf, pb, 0, 0, width, height, 0, 0, scalex, scaley, GDK_INTERP_BILINEAR);
} else {
@@ -122,14 +128,30 @@ void on_window_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpoin
}
}
-void on_window_hpane_resized(GObject *gobject, GParamSpec *pspec, gpointer user_data) {
+static gboolean hpane_resize_idle_func(gpointer data) {
gint pos;
- pos = gtk_paned_get_position(GTK_PANED(gobject));
- if(orig_pixbuf && pos != last_pos) {
+ pos = gtk_paned_get_position(GTK_PANED(data));
+
+ if(pos != hpane_last_pos) {
resize_pixbuf();
- last_pos = pos;
+ hpane_last_pos = pos;
+ return TRUE; /* Ensure that we'll keep checking until we're done resizing. */
+ }
+
+ hpane_source_id = 0;
+ return FALSE;
+}
+
+void on_window_hpane_resized(GObject *gobject, GParamSpec *pspec, gpointer user_data) {
+ GSource *src;
+
+ /* Don't let hpane_resize_idle_func run until the user has stopped moving the hpane (no movement for 100 ms). */
+ if(hpane_source_id > 0) {
+ src = g_main_context_find_source_by_id(NULL, hpane_source_id);
+ if(src) g_source_destroy(src);
}
+ hpane_source_id = g_timeout_add(100, hpane_resize_idle_func, (gpointer)gobject);
}
static void walls_set_window_title() {