summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--walls.ui21
-rw-r--r--window_main.c77
2 files changed, 66 insertions, 32 deletions
diff --git a/walls.ui b/walls.ui
index 2f234bb..bd57bbd 100644
--- a/walls.ui
+++ b/walls.ui
@@ -4,6 +4,7 @@
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window">
<signal name="destroy" handler="gtk_main_quit"/>
+ <signal name="size_allocate" handler="on_window_size_allocate"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
@@ -72,7 +73,7 @@
</packing>
</child>
<child>
- <object class="GtkHPaned" id="hpaned1">
+ <object class="GtkHPaned" id="window_hpane">
<property name="visible">True</property>
<child>
<object class="GtkNotebook" id="left_pages">
@@ -108,22 +109,14 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkLayout" id="layout">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkViewport" id="viewport1">
+ <object class="GtkImage" id="image">
+ <property name="width_request">100</property>
+ <property name="height_request">80</property>
<property name="visible">True</property>
- <property name="resize_mode">queue</property>
- <property name="shadow_type">none</property>
- <child>
- <object class="GtkImage" id="image">
- <property name="visible">True</property>
- <property name="stock">gtk-missing-image</property>
- </object>
- </child>
+ <property name="stock">gtk-missing-image</property>
</object>
</child>
</object>
diff --git a/window_main.c b/window_main.c
index 57c8885..47c70ec 100644
--- a/window_main.c
+++ b/window_main.c
@@ -7,9 +7,13 @@
#include "db.h"
#include "walls_model.h"
-GdkPixbuf *pixbuf = NULL;
+GdkPixbuf *orig_pixbuf = NULL;
+gint last_width = 0,
+ last_height = 0,
+ last_pos = 0;
GtkImage *image = NULL;
+GtkWidget *layout = NULL;
void on_filetree_selection_changed(GtkTreeSelection *treeselection, gpointer user_data);
@@ -63,24 +67,17 @@ inline static void filetree_init(GtkTreeView *filetree) {
g_signal_connect(selection, "changed", G_CALLBACK(on_filetree_selection_changed), filetree);
}
-static void load_pixbuf(struct wallpaper_t *wall) {
- GdkPixbuf *pb, *pb2;
- GError *error = NULL;
+static void resize_pixbuf() {
+ GdkPixbuf *pb;
GdkWindow *window;
gint win_width, win_height, img_width, img_height, width, height;
gdouble scalex, scaley, width_ratio, height_ratio, max_ratio;
- pb = gdk_pixbuf_new_from_file(wall->filepath, &error);
- if(!pb) {
- g_warning("%s", error->message);
- g_free(error);
- return;
- }
-
- window = gtk_widget_get_window(GTK_WIDGET(image));
+ window = gtk_widget_get_window(layout);
gdk_drawable_get_size(window, &win_width, &win_height);
- img_width = gdk_pixbuf_get_width(pb);
- img_height = gdk_pixbuf_get_height(pb);
+ 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);
/* do we need to resize? */
if(img_width > win_width || img_height > win_height) {
@@ -98,17 +95,57 @@ static void load_pixbuf(struct wallpaper_t *wall) {
scalex = (gdouble)width / (gdouble)img_width;
scaley = (gdouble)height / (gdouble)img_height;
}
- pb2 = pb;
pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
- gdk_pixbuf_scale(pb2, pb, 0, 0, width, height, 0, 0, scalex, scaley, GDK_INTERP_BILINEAR);
- gdk_pixbuf_unref(pb2);
+ gdk_pixbuf_scale(orig_pixbuf, pb, 0, 0, width, height, 0, 0, scalex, scaley, GDK_INTERP_BILINEAR);
+ } else {
+ width = img_width;
+ height = img_height;
+ pb = gdk_pixbuf_copy(orig_pixbuf);
}
- //gtk_image_set_from_file(image, wall->filepath);
+ gtk_widget_set_size_request(GTK_WIDGET(image), width, height);
+ gtk_widget_set_uposition(GTK_WIDGET(image), (width < win_width ? win_width / 2 - width / 2 : 0), (height < win_height ? win_height / 2 - height / 2 : 0));
gtk_image_set_from_pixbuf(image, pb);
gdk_pixbuf_unref(pb);
}
+void on_window_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) {
+ if(orig_pixbuf && (allocation->width != last_width || allocation->height != last_height)) {
+ resize_pixbuf();
+ last_width = allocation->width;
+ last_height = allocation->height;
+ }
+}
+
+void on_window_hpane_resized(GObject *gobject, GParamSpec *pspec, gpointer user_data) {
+ gint pos;
+
+ pos = gtk_paned_get_position(GTK_PANED(gobject));
+ if(orig_pixbuf && pos != last_pos) {
+ resize_pixbuf();
+ last_pos = pos;
+ }
+}
+
+static void load_pixbuf(struct wallpaper_t *wall) {
+ GdkPixbuf *pb;
+ GError *error = NULL;
+ GdkWindow *window;
+ gint win_width, win_height, img_width, img_height, width, height;
+ gdouble scalex, scaley, width_ratio, height_ratio, max_ratio;
+
+ if(orig_pixbuf)
+ gdk_pixbuf_unref(orig_pixbuf);
+ orig_pixbuf = gdk_pixbuf_new_from_file(wall->filepath, &error);
+ if(!orig_pixbuf) {
+ g_warning("%s", error->message);
+ g_free(error);
+ return;
+ }
+
+ resize_pixbuf();
+}
+
void on_filetree_selection_changed(GtkTreeSelection *treeselection, gpointer user_data) {
GtkTreeModel *model;
GtkTreeIter iter;
@@ -125,6 +162,7 @@ void on_filetree_selection_changed(GtkTreeSelection *treeselection, gpointer use
int gui_main(int argc, char **argv) {
GtkWidget *window;
GtkWidget *filetree;
+ GtkWidget *window_hpane;
GtkBuilder *builder ;
GError *error = NULL;
@@ -147,6 +185,9 @@ int gui_main(int argc, char **argv) {
filetree_init(GTK_TREE_VIEW(filetree));
image = GTK_IMAGE(gtk_builder_get_object(builder, "image"));
+ layout = GTK_WIDGET(gtk_builder_get_object(builder, "layout"));
+ window_hpane = GTK_WIDGET(gtk_builder_get_object(builder, "window_hpane"));
+ g_signal_connect(window_hpane, "notify::position", G_CALLBACK(on_window_hpane_resized), window_hpane);
gtk_builder_connect_signals(builder, NULL);