mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 20:23:49 +01:00
Began to implement dual/multiple view
This commit is contained in:
parent
6689a3422a
commit
dd97387715
19
callbacks.c
19
callbacks.c
@ -46,9 +46,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME
|
||||
/* get current adjustment values */
|
||||
gdouble lower = gtk_adjustment_get_value(adjustment);
|
||||
gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
|
||||
/*gdouble lower = gtk_adjustment_get_value(adjustment);*/
|
||||
/*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/
|
||||
|
||||
/* find page that fits */
|
||||
for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
|
||||
@ -60,14 +61,16 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
||||
continue;
|
||||
}
|
||||
|
||||
double begin = page->offset;
|
||||
double end = page->offset + page->height;
|
||||
/*double begin = page->offset;*/
|
||||
/*double end = page->offset + page->height;*/
|
||||
|
||||
if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */
|
||||
|| ( (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 */
|
||||
) {
|
||||
/*if ( ( (begin >= lower) && (end <= upper) ) [> page is in viewport <]*/
|
||||
/*|| ( (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 <]*/
|
||||
/*) {*/
|
||||
if (page_id < 5) {
|
||||
render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]);
|
||||
}
|
||||
/*}*/
|
||||
}
|
||||
}
|
||||
|
4
config.c
4
config.c
@ -18,7 +18,9 @@ config_load_default(void)
|
||||
|
||||
/* zathura settings */
|
||||
int_value = 10;
|
||||
girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL);
|
||||
girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL);
|
||||
int_value = 2;
|
||||
girara_setting_add(Zathura.UI.session, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL);
|
||||
|
||||
/* define default shortcuts */
|
||||
girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);
|
||||
|
@ -239,16 +239,12 @@ zathura_document_open(const char* path, const char* password)
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
double offset = 0;
|
||||
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||
zathura_page_t* page = zathura_page_get(document, page_id);
|
||||
if (!page) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
page->offset = offset;
|
||||
offset += page->height;
|
||||
|
||||
document->pages[page_id] = page;
|
||||
}
|
||||
|
||||
@ -389,8 +385,9 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
|
||||
zathura_page_t* page = document->functions.page_get(document, page_id);
|
||||
|
||||
if (page) {
|
||||
page->number = page_id;
|
||||
page->rendered = false;
|
||||
page->number = page_id;
|
||||
page->rendered = false;
|
||||
page->event_box = gtk_event_box_new();
|
||||
g_static_mutex_init(&(page->lock));
|
||||
}
|
||||
|
||||
|
@ -142,11 +142,11 @@ typedef struct zathura_page_s
|
||||
{
|
||||
double height; /**> Page height */
|
||||
double width; /**> Page width */
|
||||
double offset; /**> Page offset */
|
||||
unsigned int number; /**> Page number */
|
||||
zathura_document_t* document; /**> Document */
|
||||
void* data; /**> Custom data */
|
||||
bool rendered; /**> Page has been rendered */
|
||||
GtkWidget* event_box; /**> Widget wrapper */
|
||||
GStaticMutex lock; /**> Lock */
|
||||
} zathura_page_t;
|
||||
|
||||
|
43
render.c
43
render.c
@ -20,10 +20,8 @@ render_job(void* data)
|
||||
girara_list_remove(render_thread->list, page);
|
||||
g_mutex_unlock(render_thread->lock);
|
||||
|
||||
gdk_threads_enter();
|
||||
render(page);
|
||||
printf("Rendered %d\n", page->number);
|
||||
gdk_threads_leave();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -131,48 +129,33 @@ render_page(render_thread_t* render_thread, zathura_page_t* page)
|
||||
bool
|
||||
render(zathura_page_t* page)
|
||||
{
|
||||
gdk_threads_enter();
|
||||
g_static_mutex_lock(&(page->lock));
|
||||
zathura_image_buffer_t* buffer = zathura_page_render(page);
|
||||
|
||||
if (!buffer) {
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
printf("error: rendering failed\n");
|
||||
gdk_threads_leave();
|
||||
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);
|
||||
/* create drawing area */
|
||||
/*GtkWidget* drawing_area = gtk_drawing_area_new();*/
|
||||
|
||||
if (!widget) {
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
printf("error: page container does not exist\n");
|
||||
// TODO: zathura_image_buffer_free(image);
|
||||
return false;
|
||||
}
|
||||
/*[> remove old image <]*/
|
||||
/*GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box));*/
|
||||
/*if (widget != NULL) {*/
|
||||
/*g_object_unref(widget);*/
|
||||
/*}*/
|
||||
|
||||
/* child packaging information */
|
||||
gboolean expand;
|
||||
gboolean fill;
|
||||
guint padding;
|
||||
GtkPackType pack_type;
|
||||
/*[> set new image <]*/
|
||||
/*gtk_box_pack_start(GTK_BOX(page->event_box), drawing_area, TRUE, TRUE, 0);*/
|
||||
|
||||
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 */
|
||||
// TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0);
|
||||
|
||||
/* set old packaging values */
|
||||
// TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type);
|
||||
|
||||
/* reorder child */
|
||||
// TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number);
|
||||
zathura_image_buffer_free(buffer);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
|
||||
gdk_threads_leave();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,10 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t)
|
||||
unsigned int number_of_pages = Zathura.document->number_of_pages;
|
||||
|
||||
if (t > 0 && t <= number_of_pages) {
|
||||
GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view));
|
||||
unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale;
|
||||
gtk_adjustment_set_value(adjustment, offset);
|
||||
// TODO: Calculate offset
|
||||
/*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view));*/
|
||||
/*unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale;*/
|
||||
/*gtk_adjustment_set_value(adjustment, offset);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
75
zathura.c
75
zathura.c
@ -100,19 +100,14 @@ document_open(const char* path, const char* password)
|
||||
|
||||
Zathura.document = document;
|
||||
|
||||
/* create blank pages */
|
||||
for (unsigned int i = 0; i < document->number_of_pages; i++)
|
||||
{
|
||||
/* create blank page */
|
||||
GtkWidget* image = page_blank(document->pages[i]->width, document->pages[i]->height);
|
||||
/* init view */
|
||||
create_blank_pages();
|
||||
|
||||
if (!image) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* pack to page view */
|
||||
gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 1);
|
||||
}
|
||||
/* view mode */
|
||||
int* value = girara_setting_get(Zathura.UI.session, "pages-per-row");
|
||||
int pages_per_row = (value) ? *value : 1;
|
||||
free(value);
|
||||
page_view_set_mode(pages_per_row);
|
||||
|
||||
girara_set_view(Zathura.UI.session, Zathura.UI.page_view);
|
||||
|
||||
@ -190,6 +185,62 @@ error_out:
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
page_view_set_mode(unsigned int pages_per_row)
|
||||
{
|
||||
gdk_threads_enter();
|
||||
|
||||
/* empty page view */
|
||||
GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view));
|
||||
for (GList* child = container; child; child = g_list_next(child)) {
|
||||
gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), child->data);
|
||||
}
|
||||
|
||||
GtkWidget* row = NULL;
|
||||
|
||||
/* create blank pages */
|
||||
for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++)
|
||||
{
|
||||
if (i % pages_per_row == 0) {
|
||||
row = gtk_hbox_new(FALSE, 0);
|
||||
}
|
||||
|
||||
/* pack row */
|
||||
gtk_box_pack_start(GTK_BOX(row), Zathura.document->pages[i]->event_box, FALSE, FALSE, 1);
|
||||
|
||||
/* pack row to page view */
|
||||
if ((i + 1) % pages_per_row == 0) {
|
||||
gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), row, FALSE, FALSE, 1);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_show_all(Zathura.UI.page_view);
|
||||
gdk_threads_leave();
|
||||
}
|
||||
|
||||
void
|
||||
create_blank_pages()
|
||||
{
|
||||
/* create blank pages */
|
||||
for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++)
|
||||
{
|
||||
zathura_page_t* page = Zathura.document->pages[i];
|
||||
g_static_mutex_lock(&(page->lock));
|
||||
|
||||
/* create blank page */
|
||||
GtkWidget* image = page_blank(page->width, page->height);
|
||||
|
||||
if (!image) {
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* pack to page view */
|
||||
gtk_container_add(GTK_CONTAINER(page->event_box), image);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
}
|
||||
}
|
||||
|
||||
/* main function */
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
12
zathura.h
12
zathura.h
@ -80,4 +80,16 @@ bool document_close();
|
||||
*/
|
||||
bool page_set(unsigned int page_id);
|
||||
|
||||
/**
|
||||
* Builds the box structure to show the rendered pages
|
||||
*
|
||||
* @param pages_per_row Number of shown pages per row
|
||||
*/
|
||||
void page_view_set_mode(unsigned int pages_per_row);
|
||||
|
||||
/**
|
||||
* Create blank pages
|
||||
*/
|
||||
void create_blank_pages();
|
||||
|
||||
#endif // ZATHURA_H
|
||||
|
Loading…
Reference in New Issue
Block a user