aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-09 06:55:00 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-09 06:57:02 +0100
commited39a9b434f90a62d80b984eb98e89ac833b5b4b (patch)
tree9c054882678b157c58a87018d84d3b175883bca1
parenta135d6f332c31b11b8d4c4b3c3cfb0b500beffb7 (diff)
downloadfiv-ed39a9b434f90a62d80b984eb98e89ac833b5b4b.tar.gz
fiv-ed39a9b434f90a62d80b984eb98e89ac833b5b4b.tar.xz
fiv-ed39a9b434f90a62d80b984eb98e89ac833b5b4b.zip
Add elementary scrolling support to the view
-rw-r--r--fastiv-view.c11
-rw-r--r--fastiv.c16
2 files changed, 14 insertions, 13 deletions
diff --git a/fastiv-view.c b/fastiv-view.c
index 037008d..da4aa12 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -60,21 +60,15 @@ static void
fastiv_view_get_preferred_height(
GtkWidget *widget, gint *minimum, gint *natural)
{
- *minimum = 0;
- *natural = 0;
-
FastivView *self = FASTIV_VIEW(widget);
- *natural = get_display_height(self);
+ *minimum = *natural = get_display_height(self);
}
static void
fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
{
- *minimum = 0;
- *natural = 0;
-
FastivView *self = FASTIV_VIEW(widget);
- *natural = get_display_width(self);
+ *minimum = *natural = get_display_width(self);
}
static void
@@ -207,6 +201,7 @@ fastiv_view_open(FastivView *self, const gchar *path, GError **error)
cairo_surface_destroy(self->surface);
self->surface = surface;
+ self->scale = 1.0;
gtk_widget_queue_resize(GTK_WIDGET(self));
return TRUE;
}
diff --git a/fastiv.c b/fastiv.c
index 5af7324..7266212 100644
--- a/fastiv.c
+++ b/fastiv.c
@@ -63,6 +63,7 @@ struct {
GtkWidget *window;
GtkWidget *stack;
GtkWidget *view;
+ GtkWidget *view_scroller;
GtkWidget *browser;
GtkWidget *browser_scroller;
} g;
@@ -149,7 +150,7 @@ open(const gchar *path)
}
gtk_window_set_title(GTK_WINDOW(g.window), path);
- gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view);
+ gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view_scroller);
gchar *basename = g_path_get_basename(path);
g_free(g.basename);
@@ -281,9 +282,10 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event,
case GDK_KEY_Tab:
case GDK_KEY_Return:
gtk_stack_set_visible_child(GTK_STACK(g.stack),
- gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view
+ gtk_stack_get_visible_child(GTK_STACK(g.stack)) ==
+ g.view_scroller
? g.browser_scroller
- : g.view);
+ : g.view_scroller);
return TRUE;
}
}
@@ -328,8 +330,12 @@ main(int argc, char *argv[])
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g.view_scroller = gtk_scrolled_window_new(NULL, NULL);
g.view = g_object_new(FASTIV_TYPE_VIEW, NULL);
- gtk_widget_show_all(g.view);
+ gtk_widget_set_vexpand(g.view, TRUE);
+ gtk_widget_set_hexpand(g.view, TRUE);
+ gtk_container_add(GTK_CONTAINER(g.view_scroller), g.view);
+ gtk_widget_show_all(g.view_scroller);
g.browser_scroller = gtk_scrolled_window_new(NULL, NULL);
g.browser = g_object_new(FASTIV_TYPE_BROWSER, NULL);
@@ -344,7 +350,7 @@ main(int argc, char *argv[])
g.stack = gtk_stack_new();
gtk_stack_set_transition_type(
GTK_STACK(g.stack), GTK_STACK_TRANSITION_TYPE_NONE);
- gtk_container_add(GTK_CONTAINER(g.stack), g.view);
+ gtk_container_add(GTK_CONTAINER(g.stack), g.view_scroller);
gtk_container_add(GTK_CONTAINER(g.stack), g.browser_scroller);
g.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);