akbjker
2014-01-18 07:08:04 UTC
Quick patch to center-align pages that have different sizes.
Also fixes a bug that forces all the ZathuraPages to the size of the
largest one, therefore causing GTK's default background color to be
drawn instead of the one set in zathurarc.
This feels kind of hacky, though. In the long term, it might be better
to manually draw the whole content area, rather than relying on Gtk's
layout containers.
-------------- next part --------------
diff --git a/zathura.c b/zathura.c
index 1f5f4fd..5335def 100644
--- a/zathura.c
+++ b/zathura.c
@@ -943,10 +943,6 @@ document_close(zathura_t* zathura, bool keep_monitor)
/* remove widgets */
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer) 1);
- for (unsigned int i = 0; i < zathura_document_get_number_of_pages(zathura->document); i++) {
- g_object_unref(zathura->pages[i]);
- g_object_unref(zathura->pages[i]); // FIXME
- }
free(zathura->pages);
zathura->pages = NULL;
@@ -1062,9 +1058,15 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
int x = (i + first_page_column - 1) % pages_per_row;
int y = (i + first_page_column - 1) / pages_per_row;
- zathura_page_t* page = zathura_document_get_page(zathura->document, i);
- GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
- gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1);
+ GtkWidget* page_widget = zathura->pages[i];
+
+ GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
+ if (gtk_widget_get_parent(page_widget))
+ gtk_widget_reparent(page_widget, align);
+ else
+ gtk_container_add(GTK_CONTAINER(align), page_widget);
+
+ gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), align, x, y, 1, 1);
}
gtk_widget_show_all(zathura->ui.page_widget);
Also fixes a bug that forces all the ZathuraPages to the size of the
largest one, therefore causing GTK's default background color to be
drawn instead of the one set in zathurarc.
This feels kind of hacky, though. In the long term, it might be better
to manually draw the whole content area, rather than relying on Gtk's
layout containers.
-------------- next part --------------
diff --git a/zathura.c b/zathura.c
index 1f5f4fd..5335def 100644
--- a/zathura.c
+++ b/zathura.c
@@ -943,10 +943,6 @@ document_close(zathura_t* zathura, bool keep_monitor)
/* remove widgets */
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer) 1);
- for (unsigned int i = 0; i < zathura_document_get_number_of_pages(zathura->document); i++) {
- g_object_unref(zathura->pages[i]);
- g_object_unref(zathura->pages[i]); // FIXME
- }
free(zathura->pages);
zathura->pages = NULL;
@@ -1062,9 +1058,15 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
int x = (i + first_page_column - 1) % pages_per_row;
int y = (i + first_page_column - 1) / pages_per_row;
- zathura_page_t* page = zathura_document_get_page(zathura->document, i);
- GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
- gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1);
+ GtkWidget* page_widget = zathura->pages[i];
+
+ GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
+ if (gtk_widget_get_parent(page_widget))
+ gtk_widget_reparent(page_widget, align);
+ else
+ gtk_container_add(GTK_CONTAINER(align), page_widget);
+
+ gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), align, x, y, 1, 1);
}
gtk_widget_show_all(zathura->ui.page_widget);