diff --git a/callbacks.c b/callbacks.c index dec83ba..8fab8ab 100644 --- a/callbacks.c +++ b/callbacks.c @@ -6,6 +6,7 @@ #include #include "zathura.h" +#include "render.h" #include "ft/document.h" gboolean @@ -61,44 +62,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ ) { - - /* render page */ - GtkWidget* image = zathura_page_render(page); - if(!image) { - printf("error: rendering failed\n"); - return; - } - - /* add new page */ - GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); - GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page_id); - g_list_free(list); - - if(widget) { - /* child packaging information */ - gboolean expand; - gboolean fill; - guint padding; - GtkPackType pack_type; - - gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); - - /* delete old widget */ - gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); - - /* add new widget */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); - - /* set old packaging values */ - gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); - - /* reorder child */ - gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page_id); - } else { - printf("error: page container does not exist\n"); - g_object_unref(image); - return; - } + page_render(Zathura.document->pages[page_id]); } } } diff --git a/render.c b/render.c new file mode 100644 index 0000000..1e067fd --- /dev/null +++ b/render.c @@ -0,0 +1,44 @@ +#include "render.h" +#include "zathura.h" + +bool page_render(zathura_page_t* page) +{ + GtkWidget* image = zathura_page_render(page); + if(!image) { + printf("error: rendering failed\n"); + return false; + } + + /* add new page */ + GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); + GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); + g_list_free(list); + + if(!widget) { + printf("error: page container does not exist\n"); + g_object_unref(image); + return false; + } + + /* child packaging information */ + gboolean expand; + gboolean fill; + guint padding; + GtkPackType pack_type; + + gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); + + /* delete old widget */ + gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); + + /* add new widget */ + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + + /* set old packaging values */ + gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); + + /* reorder child */ + gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + + return true; +} diff --git a/render.h b/render.h new file mode 100644 index 0000000..e162f91 --- /dev/null +++ b/render.h @@ -0,0 +1,7 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "ft/document.h" + +bool page_render(zathura_page_t* page); diff --git a/zathura.c b/zathura.c index e263bad..a3fc688 100644 --- a/zathura.c +++ b/zathura.c @@ -145,26 +145,6 @@ document_close() return true; } -bool -page_render(zathura_page_t* page) -{ - GtkWidget* image = zathura_page_render(page); - if(!image) { - goto error_out; - } - - /* draw new rendered page */ - if(!girara_set_view(Zathura.UI.session, image)) { - goto error_out; - } - - return true; - -error_out: - - return false; -} - bool page_set(unsigned int page_id) {