From 7d18faa452dfedd241bb5bbd8aec407b3693e848 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 13:27:21 +0100 Subject: [PATCH 01/39] Replace GtkWidget with zathura_image_buffer_t --- document.c | 42 +++++++++++++++++++++++++---- document.h | 64 ++++++++++++++++++++------------------------ ft/djvu/djvu.c | 2 +- ft/djvu/djvu.h | 2 +- ft/pdf-mupdf/pdf.c | 2 +- ft/pdf-mupdf/pdf.h | 2 +- ft/pdf-poppler/pdf.c | 2 +- ft/pdf-poppler/pdf.h | 2 +- render.c | 12 ++++----- 9 files changed, 78 insertions(+), 52 deletions(-) diff --git a/document.c b/document.c index 48d97d1..b1d0e4f 100644 --- a/document.c +++ b/document.c @@ -124,7 +124,7 @@ zathura_document_plugins_free(void) bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) { - if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) + if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { fprintf(stderr, "plugin: could not register\n"); return false; @@ -469,7 +469,7 @@ zathura_page_form_fields_free(zathura_list_t* list) return false; } -GtkWidget* +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page) { if (!page || !page->document) { @@ -481,13 +481,13 @@ zathura_page_render(zathura_page_t* page) return NULL; } - GtkWidget* widget = page->document->functions.page_render(page); + zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - if (widget) { + if (buffer) { page->rendered = true; } - return widget; + return buffer; } zathura_index_element_t* @@ -523,3 +523,35 @@ zathura_index_element_free(zathura_index_element_t* index) g_free(index); } + +zathura_image_buffer_t* +zathura_image_buffer_create(unsigned int width, unsigned int height) +{ + zathura_image_buffer_t* image_buffer = malloc(sizeof(zathura_image_buffer_t)); + + if (image_buffer == NULL) { + return NULL; + } + + image_buffer->data = calloc(width * height * 3, sizeof(unsigned char)); + + if (image_buffer->data == NULL) { + free(image_buffer); + return NULL; + } + + image_buffer->width = width; + image_buffer->height = height; + + return image_buffer; +} + +void +zathura_image_buffer_free(zathura_image_buffer_t* image_buffer) +{ + if (image_buffer == NULL) { + return; + } + + free(image_buffer->data); +} diff --git a/document.h b/document.h index 6af627d..f05ee68 100644 --- a/document.h +++ b/document.h @@ -43,6 +43,32 @@ struct zathura_list_s struct zathura_list_s* next; /**> Next element in the list */ }; +/** + * Image buffer + */ +typedef struct zathura_image_buffer_s +{ + unsigned char* data; /**> Image buffer data */ + unsigned int height; /**> Height of the image */ + unsigned int width; /**> Width of the image */ +} zathura_image_buffer_t; + +/** + * Creates an image buffer + * + * @param width Width of the image stored in the buffer + * @param height Height of the image stored in the buffer + * @return Image buffer or NULL if an error occured + */ +zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height); + +/** + * Frees the image buffer + * + * @param zathura_image_buffer_t + */ +void zathura_image_buffer_free(zathura_image_buffer_t*); + /** * Rectangle structure */ @@ -141,83 +167,51 @@ struct zathura_document_s { /** * Frees the document - * - * @param document The document */ bool (*document_free)(zathura_document_t* document); /** * Generates the document index - * - * @param document The document - * @return NULL if an error occured or no index exists */ girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); /** * Save the document - * - * @param document The document - * @param path The new path - * @return true if no error occured */ bool (*document_save_as)(zathura_document_t* document, const char* path); /** * Get list of attachments - * - * @param document The document - * @return NULL if an error occured, otherwise the attachment list */ zathura_list_t* (*document_attachments_get)(zathura_document_t* document); /** * Gets the page object - * - * @param document The document - * @param page_id Number of the page - * @return The page object or NULL, if an error occured */ zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); /** * Search text - * - * @param page The page - * @param text Search item - * @return List of results */ zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); /** * Get links on a page - * - * @param page - * @return List of links */ zathura_list_t* (*page_links_get)(zathura_page_t* page); /** * Get form fields - * - * @param page - * @return List of form fields */ zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); /** * Renders the page - * - * @param page - * @return Rendered page */ - GtkWidget* (*page_render)(zathura_page_t* page); + zathura_image_buffer_t* (*page_render)(zathura_page_t* page); /** * Free page - * - * @param page - * @return true if no error occured, otherwise false */ bool (*page_free)(zathura_page_t* page); } functions; @@ -356,9 +350,9 @@ bool zathura_page_form_fields_free(zathura_list_t* list); * Render page * * @param page The page object - * @return Rendered page + * @return Image buffer or NULL if an error occured */ -GtkWidget* zathura_page_render(zathura_page_t* page); +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page); /** * Create new index element diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index a45ac83..7c795ce 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -215,7 +215,7 @@ djvu_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->document) { diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index f043f69..31444ff 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -24,7 +24,7 @@ zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* djvu_page_links_get(zathura_page_t* page); zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); -GtkWidget* djvu_page_render(zathura_page_t* page); +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page); bool djvu_page_free(zathura_page_t* page); #endif // DJVU_H diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index 09bd3e0..a676826 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -173,7 +173,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-mupdf/pdf.h b/ft/pdf-mupdf/pdf.h index 9d53949..84d7b38 100644 --- a/ft/pdf-mupdf/pdf.h +++ b/ft/pdf-mupdf/pdf.h @@ -27,7 +27,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 36b192e..8415468 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -250,7 +250,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-poppler/pdf.h b/ft/pdf-poppler/pdf.h index 5b959d0..ce76613 100644 --- a/ft/pdf-poppler/pdf.h +++ b/ft/pdf-poppler/pdf.h @@ -22,7 +22,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/render.c b/render.c index f863ae7..c163638 100644 --- a/render.c +++ b/render.c @@ -132,9 +132,9 @@ bool render(zathura_page_t* page) { g_static_mutex_lock(&(page->lock)); - GtkWidget* image = zathura_page_render(page); + zathura_image_buffer_t* buffer = zathura_page_render(page); - if (!image) { + if (!buffer) { g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); return false; @@ -148,7 +148,7 @@ render(zathura_page_t* page) if (!widget) { g_static_mutex_unlock(&(page->lock)); printf("error: page container does not exist\n"); - g_object_unref(image); + // TODO: zathura_image_buffer_free(image); return false; } @@ -164,13 +164,13 @@ render(zathura_page_t* page) 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); + // TODO: 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); + // TODO: 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); + // TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); g_static_mutex_unlock(&(page->lock)); return true; From 6689a3422a8a2309c3bae8a724c8038d3b2a61bd Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 14:10:42 +0100 Subject: [PATCH 02/39] Updated plugin render functions --- ft/djvu/djvu.c | 65 +++++--------------------------------------- ft/pdf-mupdf/pdf.c | 26 ++++-------------- ft/pdf-poppler/pdf.c | 39 +++++++++++++++----------- 3 files changed, 35 insertions(+), 95 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 7c795ce..5fe130e 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -243,76 +243,25 @@ djvu_page_render(zathura_page_t* page) ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3)); - if (!buffer) { + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); + + if (image_buffer == NULL) { goto error_free; } /* set rotation */ - GdkPixbufRotation gdk_angle = GDK_PIXBUF_ROTATE_NONE; - ddjvu_page_rotation_t ddjvu_angle = DDJVU_ROTATE_0; - - switch(Zathura.document->rotate) { - case 90: - gdk_angle = GDK_PIXBUF_ROTATE_CLOCKWISE; - ddjvu_angle = DDJVU_ROTATE_90; - break; - case 180: - gdk_angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; - ddjvu_angle = DDJVU_ROTATE_180; - break; - case 270: - gdk_angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; - ddjvu_angle = DDJVU_ROTATE_270; - break; - default: - gdk_angle = GDK_PIXBUF_ROTATE_NONE; - ddjvu_angle = DDJVU_ROTATE_0; - break; - } - - ddjvu_page_set_rotation(djvu_page, ddjvu_angle); + ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0); /* render page */ ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, - 3 * page_width, (char*) buffer); + 3 * page_width, (char*) image_buffer); - /* create pixbuf */ - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, - page_width, page_height, 3 * page_width, NULL, NULL); - - if (!pixbuf) { - goto error_free; - } - - /* rotate page */ - if (Zathura.document->rotate != 0) { - GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle); - if (!pixbuf_temp) { - goto error_free; - } - - pixbuf = pixbuf_temp; - } - - GtkWidget* image = gtk_image_new(); - - if (!image) { - goto error_free; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - - ddjvu_page_release(djvu_page); - - return image; + return image_buffer; error_free: ddjvu_page_release(djvu_page); - free(buffer); - g_object_unref(pixbuf); + zathura_image_buffer_free(image_buffer); error_out: diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index a676826..bb760c4 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -191,11 +191,10 @@ pdf_page_render(zathura_page_t* page) page_height = dim_temp; } - /* create pixbuf */ - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, - page_width, page_height); + /* create image buffer */ + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - if (!pixbuf) { + if (image_buffer == NULL) { return NULL; } @@ -221,10 +220,6 @@ pdf_page_render(zathura_page_t* page) ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate)); fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); - guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); - int rowstride = gdk_pixbuf_get_rowstride(pixbuf); - int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); fz_clearpixmapwithcolor(pixmap, 0xFF); @@ -235,7 +230,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < pixmap->h; y++) { for (unsigned int x = 0; x < pixmap->w; x++) { unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; - guchar* p = pixels + y * rowstride + x * n_channels; + guchar* p = image_buffer->data + y * image_buffer->width + x; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; @@ -245,16 +240,5 @@ pdf_page_render(zathura_page_t* page) fz_droppixmap(pixmap); fz_freedisplaylist(display_list); - /* write pixbuf */ - GtkWidget* image = gtk_image_new(); - - if (!image) { - g_object_unref(pixbuf); - return NULL; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - - return image; + return image_buffer; } diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 8415468..fadf9cc 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -261,34 +261,41 @@ pdf_page_render(zathura_page_t* page) unsigned int page_width = Zathura.document->scale * page->width; unsigned int page_height = Zathura.document->scale * page->height; - if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { - unsigned int dim_temp = 0; - dim_temp = page_width; - page_width = page_height; - page_height = dim_temp; - } - /* create pixbuf */ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); - if (!pixbuf) { + if (pixbuf == NULL) { return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale, - Zathura.document->rotate, pixbuf); + poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, + Zathura.document->scale, 90, pixbuf); - /* write pixbuf */ - GtkWidget* image = gtk_image_new(); + /* create image buffer */ + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - if (!image) { + if (image_buffer == NULL) { g_object_unref(pixbuf); return NULL; } - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); + /* copy buffer */ + guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); + int rowstride = gdk_pixbuf_get_rowstride(pixbuf); + int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - return image; + for (unsigned int y = 0; y < page_height; y++) { + for (unsigned int x = 0; x < page_width; x++) { + unsigned char *s = pixels + y * rowstride + x * n_channels; + guchar* p = image_buffer->data + y * image_buffer->width + x; + p[0] = s[0]; + p[1] = s[1]; + p[2] = s[2]; + } + } + + g_object_unref(pixbuf); + + return image_buffer; } From dd973877159fbb872c780ca8f051b7e4f047b4dc Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 18:40:20 +0100 Subject: [PATCH 03/39] Began to implement dual/multiple view --- callbacks.c | 19 ++++++++------ config.c | 4 ++- document.c | 9 +++---- document.h | 2 +- render.c | 43 ++++++++++-------------------- shortcuts.c | 7 ++--- zathura.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--------- zathura.h | 12 +++++++++ 8 files changed, 110 insertions(+), 61 deletions(-) diff --git a/callbacks.c b/callbacks.c index d8384bf..e6b03ae 100644 --- a/callbacks.c +++ b/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]); } + /*}*/ } } diff --git a/config.c b/config.c index 70b4543..e45454f 100644 --- a/config.c +++ b/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); diff --git a/document.c b/document.c index b1d0e4f..fb6901d 100644 --- a/document.c +++ b/document.c @@ -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)); } diff --git a/document.h b/document.h index f05ee68..5f48fae 100644 --- a/document.h +++ b/document.h @@ -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; diff --git a/render.c b/render.c index c163638..fccf2bf 100644 --- a/render.c +++ b/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; } diff --git a/shortcuts.c b/shortcuts.c index aa8b664..3a8ce74 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -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);*/ } } diff --git a/zathura.c b/zathura.c index 90e07ee..86d73d2 100644 --- a/zathura.c +++ b/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[]) { diff --git a/zathura.h b/zathura.h index 3052e32..5378480 100644 --- a/zathura.h +++ b/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 From e5d0b6bac0e6ff27567cb84cd9bc55383d8a4dad Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 01:43:02 +0100 Subject: [PATCH 04/39] Remove wrong threads_enter/leave --- zathura.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/zathura.c b/zathura.c index 86d73d2..2bdc7ff 100644 --- a/zathura.c +++ b/zathura.c @@ -188,8 +188,6 @@ error_out: 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)) { @@ -215,7 +213,6 @@ page_view_set_mode(unsigned int pages_per_row) } gtk_widget_show_all(Zathura.UI.page_view); - gdk_threads_leave(); } void From c5491675aa41eb6c283166a4a46fd0eeae8a9487 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 02:09:04 +0100 Subject: [PATCH 05/39] Update rendering --- callbacks.c | 2 +- document.c | 5 +++-- document.h | 1 + render.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/callbacks.c b/callbacks.c index e6b03ae..f90d632 100644 --- a/callbacks.c +++ b/callbacks.c @@ -68,7 +68,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 <]*/ /*) {*/ - if (page_id < 5) { + if (page_id < 1) { render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); } /*}*/ diff --git a/document.c b/document.c index fb6901d..7af7f23 100644 --- a/document.c +++ b/document.c @@ -537,8 +537,9 @@ zathura_image_buffer_create(unsigned int width, unsigned int height) return NULL; } - image_buffer->width = width; - image_buffer->height = height; + image_buffer->width = width; + image_buffer->height = height; + image_buffer->rowstride = width * 3; return image_buffer; } diff --git a/document.h b/document.h index 5f48fae..c39d8e1 100644 --- a/document.h +++ b/document.h @@ -51,6 +51,7 @@ typedef struct zathura_image_buffer_s unsigned char* data; /**> Image buffer data */ unsigned int height; /**> Height of the image */ unsigned int width; /**> Width of the image */ + unsigned int rowstride; /**> Rowstride of the image */ } zathura_image_buffer_t; /** diff --git a/render.c b/render.c index fccf2bf..61fd660 100644 --- a/render.c +++ b/render.c @@ -20,7 +20,10 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - render(page); + if (render(page) != true) { + fprintf(stderr, "rendering failed\n"); + } + printf("Rendered %d\n", page->number); } @@ -131,28 +134,51 @@ render(zathura_page_t* page) { gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); - zathura_image_buffer_t* buffer = zathura_page_render(page); + zathura_image_buffer_t* image_buffer = zathura_page_render(page); - if (!buffer) { + if (image_buffer == NULL) { g_static_mutex_unlock(&(page->lock)); - printf("error: rendering failed\n"); gdk_threads_leave(); return false; } - /* create drawing area */ - /*GtkWidget* drawing_area = gtk_drawing_area_new();*/ + /* remove old image */ + GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box)); + if (widget != NULL) { + gtk_container_remove(GTK_CONTAINER(page->event_box), widget); + } - /*[> remove old image <]*/ - /*GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box));*/ - /*if (widget != NULL) {*/ - /*g_object_unref(widget);*/ - /*}*/ + /* create cairo surface */ + unsigned int page_width = page->width * Zathura.document->scale; + unsigned int page_height = page->height * Zathura.document->scale; - /*[> set new image <]*/ - /*gtk_box_pack_start(GTK_BOX(page->event_box), drawing_area, TRUE, TRUE, 0);*/ + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); - zathura_image_buffer_free(buffer); + int rowstride = cairo_image_surface_get_stride(surface); + unsigned char* image = cairo_image_surface_get_data(surface); + + for (unsigned int y = 0; y < page_height; y++) { + unsigned char* dst = image + y * rowstride; + unsigned char* src = image_buffer->data + y * image_buffer->rowstride; + + for (unsigned int x = 0; x < page_width; x++) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst += 3; + } + } + + /* draw to gtk widget */ + GtkWidget* drawing_area = gtk_drawing_area_new(); + gtk_container_add(GTK_CONTAINER(page->event_box), drawing_area); + + cairo_t* cairo = gdk_cairo_create(drawing_area->window); + cairo_set_source_surface(cairo, surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + + zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); gdk_threads_leave(); From 801fe030099374e56b0644570cd5673a718ca686 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 02:53:24 +0100 Subject: [PATCH 06/39] Changed the strucure a bit --- document.c | 10 +++++++--- document.h | 3 ++- render.c | 5 +---- zathura.c | 14 +++++--------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/document.c b/document.c index 7af7f23..99a41fb 100644 --- a/document.c +++ b/document.c @@ -385,9 +385,13 @@ 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->event_box = gtk_event_box_new(); + page->number = page_id; + page->rendered = false; + page->event_box = gtk_event_box_new(); + page->drawing_area = gtk_drawing_area_new(); + + gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); + g_static_mutex_init(&(page->lock)); } diff --git a/document.h b/document.h index c39d8e1..5fb78e2 100644 --- a/document.h +++ b/document.h @@ -147,7 +147,8 @@ typedef struct zathura_page_s zathura_document_t* document; /**> Document */ void* data; /**> Custom data */ bool rendered; /**> Page has been rendered */ - GtkWidget* event_box; /**> Widget wrapper */ + GtkWidget* event_box; /**> Widget wrapper for mouse events */ + GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ } zathura_page_t; diff --git a/render.c b/render.c index 61fd660..02208b7 100644 --- a/render.c +++ b/render.c @@ -170,10 +170,7 @@ render(zathura_page_t* page) } /* draw to gtk widget */ - GtkWidget* drawing_area = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(page->event_box), drawing_area); - - cairo_t* cairo = gdk_cairo_create(drawing_area->window); + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); cairo_set_source_surface(cairo, surface, 0, 0); cairo_paint(cairo); cairo_destroy(cairo); diff --git a/zathura.c b/zathura.c index 2bdc7ff..df916b2 100644 --- a/zathura.c +++ b/zathura.c @@ -224,16 +224,12 @@ create_blank_pages() 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); + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + cairo_set_source_rgb(cairo, 1, 1, 1); + cairo_rectangle(cairo, 0, 0, page->width, page->height); + cairo_fill(cairo); + cairo_destroy(cairo); - 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)); } } From cfb2580b7b553dff1fc3512f7d31864dd17476ae Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:03:08 +0200 Subject: [PATCH 07/39] Return value for create_blank_pages --- zathura.c | 17 +++++++++++++++-- zathura.h | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/zathura.c b/zathura.c index df916b2..86d9dc3 100644 --- a/zathura.c +++ b/zathura.c @@ -2,6 +2,8 @@ #include +#include + #include "callbacks.h" #include "config.h" #include "document.h" @@ -101,7 +103,9 @@ document_open(const char* path, const char* password) Zathura.document = document; /* init view */ - create_blank_pages(); + if (create_blank_pages() == false) { + return false; + } /* view mode */ int* value = girara_setting_get(Zathura.UI.session, "pages-per-row"); @@ -215,7 +219,7 @@ page_view_set_mode(unsigned int pages_per_row) gtk_widget_show_all(Zathura.UI.page_view); } -void +bool create_blank_pages() { /* create blank pages */ @@ -225,6 +229,13 @@ create_blank_pages() g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + + if (cairo == NULL) { + girara_error("Could not create blank page"); + g_static_mutex_unlock(&(page->lock)); + return false; + } + cairo_set_source_rgb(cairo, 1, 1, 1); cairo_rectangle(cairo, 0, 0, page->width, page->height); cairo_fill(cairo); @@ -232,6 +243,8 @@ create_blank_pages() g_static_mutex_unlock(&(page->lock)); } + + return true; } /* main function */ diff --git a/zathura.h b/zathura.h index 5378480..fc59099 100644 --- a/zathura.h +++ b/zathura.h @@ -89,7 +89,9 @@ void page_view_set_mode(unsigned int pages_per_row); /** * Create blank pages + * + * @return false if an error occured, otherwise true */ -void create_blank_pages(); +bool create_blank_pages(); #endif // ZATHURA_H From db832069ea31f0e00a3c40f73a27636f255a03e6 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 17:22:44 +0200 Subject: [PATCH 08/39] replace global Zathura object with zathura session --- config.c | 148 ++++++++++++++++++++++++++++--------------------------- config.h | 4 +- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/config.c b/config.c index e45454f..aaedab2 100644 --- a/config.c +++ b/config.c @@ -1,95 +1,97 @@ /* See LICENSE file for license and copyright information */ +#include "config.h" #include "commands.h" #include "completion.h" #include "shortcuts.h" -#include "zathura.h" void -config_load_default(void) +config_load_default(zathura_t* zathura) { - if (!Zathura.UI.session) + if (zathura || !session->UI.session) { return; + } int int_value = 0; + girara_session_t* gsession = zathura->ui.session; /* general settings */ - girara_mode_set(Zathura.UI.session, NORMAL); + girara_mode_set(gsession, NORMAL); /* zathura settings */ int_value = 10; - girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + girara_setting_add(gsession, "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); + girara_setting_add(gsession, "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); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(Zathura.UI.session, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, TOP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, BOTTOM, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_navigate_index, INDEX, UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_i, NULL, sc_recolor, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_R, NULL, sc_reload, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_r, NULL, sc_rotate, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL | INDEX, 0, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_n, NULL, sc_toggle_statusbar, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_q, NULL, sc_quit, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_plus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); + girara_shortcut_add(gsession, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); + girara_shortcut_add(gsession, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL); + girara_shortcut_add(gsession, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); + girara_shortcut_add(gsession, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); + girara_shortcut_add(gsession, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); + girara_shortcut_add(gsession, 0, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(gsession, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(gsession, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, TOP, NULL); + girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, BOTTOM, NULL); + girara_shortcut_add(gsession, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_k, NULL, sc_navigate_index, INDEX, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); + girara_shortcut_add(gsession, 0, GDK_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); + girara_shortcut_add(gsession, 0, GDK_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(gsession, 0, GDK_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_i, NULL, sc_recolor, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_R, NULL, sc_reload, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_r, NULL, sc_rotate, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_h, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(gsession, 0, GDK_j, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_k, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(gsession, 0, GDK_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(gsession, 0, GDK_Up, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); + girara_shortcut_add(gsession, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); + girara_shortcut_add(gsession, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); + girara_shortcut_add(gsession, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL | INDEX, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_n, NULL, sc_toggle_statusbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_q, NULL, sc_quit, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_plus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); /* define default inputbar commands */ - girara_inputbar_command_add(Zathura.UI.session, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); - girara_inputbar_command_add(Zathura.UI.session, "bdelete", NULL, cmd_bookmark_delete, NULL, "Delete a bookmark"); - girara_inputbar_command_add(Zathura.UI.session, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); - girara_inputbar_command_add(Zathura.UI.session, "close", NULL, cmd_close, NULL, "Close current file"); - girara_inputbar_command_add(Zathura.UI.session, "info", NULL, cmd_info, NULL, "Show file information"); - girara_inputbar_command_add(Zathura.UI.session, "print", NULL, cmd_print, cc_print, "Print document"); - girara_inputbar_command_add(Zathura.UI.session, "save", NULL, cmd_save, NULL, "Save document"); + girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); + girara_inputbar_command_add(gsession, "bdelete", NULL, cmd_bookmark_delete, NULL, "Delete a bookmark"); + girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); + girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, "Close current file"); + girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); + girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document"); + girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); } diff --git a/config.h b/config.h index a3a03e7..4103598 100644 --- a/config.h +++ b/config.h @@ -3,9 +3,11 @@ #ifndef CONFIG_H #define CONFIG_H +#include "zathura.h" + /** * This function loads the default values of the configuration */ -void config_load_default(void); +void config_load_default(zathura_t* zathura); #endif // CONFIG_H From 87df00fef053579716a97e03abe7cd7663309c5b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 17:24:19 +0200 Subject: [PATCH 09/39] typo --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index aaedab2..33972f9 100644 --- a/config.c +++ b/config.c @@ -8,7 +8,7 @@ void config_load_default(zathura_t* zathura) { - if (zathura || !session->UI.session) { + if (zathura || !zathura->UI.session) { return; } From 8960b6e83d8137bc4e1eb86ed482e87ca932d796 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:27:49 +0200 Subject: [PATCH 10/39] Updated zathura.h/zathura.c --- callbacks.c | 9 +--- zathura.c | 148 ++++++++++++++++++++++++++++++---------------------- zathura.h | 36 +++++++++---- 3 files changed, 112 insertions(+), 81 deletions(-) diff --git a/callbacks.c b/callbacks.c index f90d632..c16b6c5 100644 --- a/callbacks.c +++ b/callbacks.c @@ -12,14 +12,7 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data) { - if (Zathura.UI.session) { - girara_session_destroy(Zathura.UI.session); - } - - document_close(); - - /* free registered plugins */ - zathura_document_plugins_free(); + zathura_free(data); return TRUE; } diff --git a/zathura.c b/zathura.c index 86d9dc3..f889ae3 100644 --- a/zathura.c +++ b/zathura.c @@ -12,59 +12,65 @@ #include "utils.h" /* function implementation */ -bool -init_zathura() +zathura_t* +zathura_init(int argc, char* argv[]) { + zathura_t* zathura = malloc(sizeof(zathura_t)); + + if (zathura == NULL) { + return NULL; + } + /* UI */ - if (!(Zathura.UI.session = girara_session_create())) { + if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; } - if (!girara_session_init(Zathura.UI.session)) { + if (girara_session_init(zathura->ui.session) == false) { goto error_out; } - Zathura.UI.statusbar.file = NULL; - Zathura.UI.statusbar.buffer = NULL; - Zathura.UI.statusbar.page_number = NULL; - Zathura.UI.page_view = NULL; - Zathura.UI.index = NULL; + zathura->ui.statusbar.file = NULL; + zathura->ui.statusbar.buffer = NULL; + zathura->ui.statusbar.page_number = NULL; + zathura->ui.page_view = NULL; + zathura->ui.index = NULL; /* page view */ - Zathura.UI.page_view = gtk_vbox_new(FALSE, 0); - if (!Zathura.UI.page_view) { + zathura->ui.page_view = gtk_vbox_new(FALSE, 0); + if (!zathura->ui.page_view) { goto error_free; } - gtk_widget_show(Zathura.UI.page_view); - gtk_box_set_spacing(GTK_BOX(Zathura.UI.page_view), 0); + gtk_widget_show(zathura->ui.page_view); + gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); /* statusbar */ - Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); - if (!Zathura.UI.statusbar.file) { + zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); + if (zathura->ui.statusbar.file == NULL) { goto error_free; } - Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if (!Zathura.UI.statusbar.buffer) { + zathura->ui.statusbar.buffer = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + if (zathura->ui.statusbar.buffer == NULL) { goto error_free; } - Zathura.UI.statusbar.page_number = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if (!Zathura.UI.statusbar.page_number) { + zathura->ui.statusbar.page_number = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + if (!zathura->ui.statusbar.page_number) { goto error_free; } - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, "[No Name]"); /* signals */ - g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), NULL); /* girara events */ - Zathura.UI.session->events.buffer_changed = buffer_changed; + zathura->ui.session->events.buffer_changed = buffer_changed; /* load plugins */ zathura_document_plugins_load(); @@ -72,23 +78,40 @@ init_zathura() /* configuration */ config_load_default(); - return true; + return zathura; error_free: - if (Zathura.UI.page_view) { - g_object_unref(Zathura.UI.page_view); + if (zathura->ui.page_view) { + g_object_unref(zathura->ui.page_view); } - girara_session_destroy(Zathura.UI.session); + girara_session_destroy(zathura->ui.session); error_out: - return false; + return NULL; +} + +void +zathura_free(zathura_t* zathura) +{ + if (zathura == NULL) { + return; + } + + if (zathura->ui.session != NULL) { + girara_session_destroy(zathura->ui.session); + } + + document_close(zathura); + + /* free registered plugins */ + zathura_document_plugins_free(); } bool -document_open(const char* path, const char* password) +document_open(zathura_t* zathura, const char* path, const char* password) { if (!path) { goto error_out; @@ -100,30 +123,30 @@ document_open(const char* path, const char* password) goto error_out; } - Zathura.document = document; + zathura->document = document; /* init view */ - if (create_blank_pages() == false) { + if (create_blank_pages(zathura) == false) { return false; } /* view mode */ - int* value = girara_setting_get(Zathura.UI.session, "pages-per-row"); + 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); + page_view_set_mode(zathura, pages_per_row); - girara_set_view(Zathura.UI.session, Zathura.UI.page_view); + girara_set_view(zathura->ui.session, zathura->ui.page_view); /* threads */ - Zathura.Sync.render_thread = render_init(); + zathura->sync.render_thread = render_init(); - if (!Zathura.Sync.render_thread) { + if (!zathura->sync.render_thread) { goto error_free; } /* first page */ - if (!page_set(0)) { + if (!page_set(zathura, 0)) { goto error_free; } @@ -139,47 +162,47 @@ error_out: } bool -document_close() +document_close(zathura_t* zathura) { - if (!Zathura.document) { + if (!zathura->document) { return false; } - if (Zathura.Sync.render_thread) { - render_free(Zathura.Sync.render_thread); + if (zathura->sync.render_thread) { + render_free(zathura->sync.render_thread); } - zathura_document_free(Zathura.document); + zathura_document_free(zathura->document); return true; } bool -page_set(unsigned int page_id) +page_set(zathura_t* zathura, unsigned int page_id) { - if (!Zathura.document || !Zathura.document->pages) { + if (!zathura->document || !zathura->document->pages) { goto error_out; } - if (page_id >= Zathura.document->number_of_pages) { + if (page_id >= zathura->document->number_of_pages) { goto error_out; } /* render page */ - zathura_page_t* page = Zathura.document->pages[page_id]; + zathura_page_t* page = zathura->document->pages[page_id]; if (!page) { goto error_out; } - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); /* update page number */ - Zathura.document->current_page_number = page_id; + zathura->document->current_page_number = page_id; - char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages); - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.page_number, page_number); + char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, zathura->document->number_of_pages); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number); g_free(page_number); return true; @@ -190,42 +213,42 @@ error_out: } void -page_view_set_mode(unsigned int pages_per_row) +page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { /* empty page view */ - GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.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); + 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++) + 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); + 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_box_pack_start(GTK_BOX(zathura->ui.page_view), row, FALSE, FALSE, 1); } } - gtk_widget_show_all(Zathura.UI.page_view); + gtk_widget_show_all(zathura->ui.page_view); } bool -create_blank_pages() +create_blank_pages(zathura_t* zathura) { /* create blank pages */ - for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++) + for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { - zathura_page_t* page = Zathura.document->pages[i]; + zathura_page_t* page = zathura->document->pages[i]; g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); @@ -254,13 +277,14 @@ int main(int argc, char* argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - if (!init_zathura()) { + zathura_t* zathura = zathura_init(argc, argv); + if (zathura == NULL) { printf("error: coult not initialize zathura\n"); return -1; } if (argc > 1) { - if (!document_open(argv[1], NULL)) { + if (!document_open(zathura, argv[1], NULL)) { printf("error: could not open document\n"); return -1; } diff --git a/zathura.h b/zathura.h index fc59099..bb3a2cc 100644 --- a/zathura.h +++ b/zathura.h @@ -24,7 +24,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, #define NORMAL (1 << 3) #define INSERT (1 << 4) -struct +typedef struct zathura_s { struct { @@ -39,59 +39,73 @@ struct GtkWidget *page_view; /**> Widget that contains all rendered pages */ GtkWidget *index; /**> Widget to show the index of the document */ - } UI; + } ui; struct { render_thread_t* render_thread; /**> The thread responsible for rendering the pages */ - } Sync; + } sync; zathura_document_t* document; /**> The current document */ -} Zathura; +} zathura_t; /** * Initializes zathura * - * @return If no error occured true, otherwise false, is returned. + * @param argc Number of arguments + * @param argv Values of arguments + * @return Zathura zathura object or NULL if zathura could not been initialized */ -bool init_zathura(); +zathura_t* zathura_init(int argc, char* argv[]); + +/** + * Free zathura zathura + * + * @param zathura The zathura zathura + */ +void zathura_free(zathura_t* zathura); /** * Opens a file * + * @param zathura The zathura zathura * @param path The path to the file * @param password The password of the file * * @return If no error occured true, otherwise false, is returned. */ -bool document_open(const char* path, const char* password); +bool document_open(zathura_t* zathura, const char* path, const char* password); /** * Closes the current opened document * + * @param zathura The zathura zathura * @return If no error occured true, otherwise false, is returned. */ -bool document_close(); +bool document_close(zathura_t* zathura); /** * Opens the page with the given number * + * @param zathura The zathura zathura * @return If no error occured true, otherwise false, is returned. */ -bool page_set(unsigned int page_id); +bool page_set(zathura_t* zathura, unsigned int page_id); /** * Builds the box structure to show the rendered pages * + * @param zathura The zathura zathura * @param pages_per_row Number of shown pages per row */ -void page_view_set_mode(unsigned int pages_per_row); +void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row); /** * Create blank pages * + * @param zathura The zathura zathura * @return false if an error occured, otherwise true */ -bool create_blank_pages(); +bool create_blank_pages(zathura_t* zathura); #endif // ZATHURA_H From a181c0477505cdaf7e05052805026379cd3e6542 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:28:27 +0200 Subject: [PATCH 11/39] Fixed config.c --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index 33972f9..b847456 100644 --- a/config.c +++ b/config.c @@ -8,7 +8,7 @@ void config_load_default(zathura_t* zathura) { - if (zathura || !zathura->UI.session) { + if (zathura || !zathura->ui.session) { return; } From daa523aaf5f6e4769ee9a8be679736f1da5c4f7d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:37:03 +0200 Subject: [PATCH 12/39] Updated callbacks.c --- callbacks.c | 19 +++++++++++++------ zathura.c | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/callbacks.c b/callbacks.c index c16b6c5..8fb333d 100644 --- a/callbacks.c +++ b/callbacks.c @@ -21,33 +21,40 @@ void buffer_changed(girara_session_t* session) { g_return_if_fail(session != NULL); + g_return_if_fail(session->global.data != NULL); + + zathura_t* zathura = session->global.data; char* buffer = girara_buffer_get(session); if (buffer) { - girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); + girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer); free(buffer); } else { - girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, ""); + girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, ""); } } void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { - if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) { + g_return_if_fail(data != NULL); + + zathura_t* zathura = data; + if (!zathura->document || !zathura->document->pages || !zathura->ui.page_view) { return; } + // FIXME /* get current adjustment values */ /*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++) + for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { - zathura_page_t* page = Zathura.document->pages[page_id]; + zathura_page_t* page = zathura->document->pages[page_id]; /* check for rendered attribute */ if (page->rendered) { @@ -62,7 +69,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ if (page_id < 1) { - render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); + render_page(zathura->sync.render_thread, zathura->document->pages[page_id]); } /*}*/ } diff --git a/zathura.c b/zathura.c index f889ae3..602cfb8 100644 --- a/zathura.c +++ b/zathura.c @@ -30,6 +30,7 @@ zathura_init(int argc, char* argv[]) goto error_out; } + zathura->ui.session->global.data = zathura; zathura->ui.statusbar.file = NULL; zathura->ui.statusbar.buffer = NULL; zathura->ui.statusbar.page_number = NULL; @@ -67,7 +68,7 @@ zathura_init(int argc, char* argv[]) g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), NULL); + g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; @@ -76,7 +77,7 @@ zathura_init(int argc, char* argv[]) zathura_document_plugins_load(); /* configuration */ - config_load_default(); + config_load_default(zathura); return zathura; From 9026f9246911562482e9796ca323fad192cea9d0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:55:50 +0200 Subject: [PATCH 13/39] Updated shortcuts.c --- shortcuts.c | 153 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 51 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 3a8ce74..8178891 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -13,6 +13,8 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; girara_mode_set(session, NORMAL); @@ -22,12 +24,20 @@ sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } @@ -35,6 +45,8 @@ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; girara_mode_set(session, argument->n); @@ -45,6 +57,8 @@ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); @@ -62,15 +76,21 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsign bool sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } bool sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); if (argument->n == TOP) { girara_argument_t arg = { TOP, NULL }; @@ -85,12 +105,12 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) return true; } - unsigned int number_of_pages = Zathura.document->number_of_pages; + unsigned int number_of_pages = zathura->document->number_of_pages; if (t > 0 && t <= number_of_pages) { // 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;*/ + /*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);*/ } } @@ -101,12 +121,14 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); - unsigned int number_of_pages = Zathura.document->number_of_pages; - unsigned int new_page = Zathura.document->current_page_number; + unsigned int number_of_pages = zathura->document->number_of_pages; + unsigned int new_page = zathura->document->current_page_number; if (argument->n == NEXT) { new_page = (new_page + 1) % number_of_pages; @@ -122,24 +144,35 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + + zathura_t* zathura = session->global.data; + return false; } bool sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + + zathura_t* zathura = session->global.data; + return false; } bool sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(zathura->document != NULL, false); /* update rotate value */ - Zathura.document->rotate = (Zathura.document->rotate + 90) % 360; + zathura->document->rotate = (zathura->document->rotate + 90) % 360; /* render all pages again */ render_all(); @@ -150,11 +183,17 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); + GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) - adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); else - adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble value = gtk_adjustment_get_value(adjustment); @@ -202,40 +241,54 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); + return false; } bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); + return false; } bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); girara_tree_node_t* document_index = NULL; GtkWidget* treeview = NULL; GtkTreeModel* model = NULL; GtkCellRenderer* renderer = NULL; - if (Zathura.UI.index == NULL) { + if (zathura->UI.index == NULL) { /* create new index widget */ - Zathura.UI.index = gtk_scrolled_window_new(NULL, NULL); + zathura->UI.index = gtk_scrolled_window_new(NULL, NULL); - if (Zathura.UI.index == NULL) { + if (zathura->UI.index == NULL) { goto error_ret; } - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->UI.index), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* create index */ - document_index = zathura_document_index_generate(Zathura.document); + document_index = zathura_document_index_generate(zathura->document); if (document_index == NULL) { // TODO: Error message goto error_free; @@ -269,31 +322,31 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); /*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/ - gtk_container_add(GTK_CONTAINER(Zathura.UI.index), treeview); + gtk_container_add(GTK_CONTAINER(zathura->UI.index), treeview); gtk_widget_show(treeview); } - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.index))) { - girara_set_view(session, Zathura.UI.page_view); - gtk_widget_hide(GTK_WIDGET(Zathura.UI.index)); + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->UI.index))) { + girara_set_view(session, zathura->UI.page_view); + gtk_widget_hide(GTK_WIDGET(zathura->UI.index)); } else { - girara_set_view(session, Zathura.UI.index); - gtk_widget_show(GTK_WIDGET(Zathura.UI.index)); + girara_set_view(session, zathura->UI.index); + gtk_widget_show(GTK_WIDGET(zathura->UI.index)); } return false; error_free: - if (Zathura.UI.index != NULL) { - g_object_ref_sink(Zathura.UI.index); - Zathura.UI.index = NULL; + if (zathura->UI.index != NULL) { + g_object_ref_sink(zathura->UI.index); + zathura->UI.index = NULL; } if (document_index != NULL) { girara_node_free(document_index); } - + error_ret: return false; @@ -302,9 +355,7 @@ error_ret: bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); @@ -318,9 +369,7 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); static bool fullscreen = false; @@ -338,9 +387,7 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, uns bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); @@ -354,6 +401,8 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsi bool sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + girara_argument_t arg = { GIRARA_HIDE, NULL }; girara_isc_completion(session, &arg, 0); @@ -367,12 +416,14 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + g_return_val_if_fail(zathura->document != NULL, false); /* retreive zoom step value */ - int* value = girara_setting_get(Zathura.UI.session, "zoom-step"); + int* value = girara_setting_get(zathura->UI.session, "zoom-step"); if (value == NULL) { return false; } @@ -380,11 +431,11 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) float zoom_step = *value / 100.0f; if (argument->n == ZOOM_IN) { - Zathura.document->scale += zoom_step; + zathura->document->scale += zoom_step; } else if (argument->n == ZOOM_OUT) { - Zathura.document->scale -= zoom_step; + zathura->document->scale -= zoom_step; } else { - Zathura.document->scale = 1.0; + zathura->document->scale = 1.0; } render_all(); From 2eed47a31445b6b944e2485ce684b14ce8d56f34 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:00:08 +0200 Subject: [PATCH 14/39] Updated render.c/render.h --- render.c | 27 ++++++++++++++------------- render.h | 8 ++++++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/render.c b/render.c index 02208b7..0329711 100644 --- a/render.c +++ b/render.c @@ -20,7 +20,7 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - if (render(page) != true) { + if (render(render_thread->zathura, page) != true) { fprintf(stderr, "rendering failed\n"); } @@ -31,7 +31,7 @@ render_job(void* data) } render_thread_t* -render_init(void) +render_init(zathura_t* zathura) { render_thread_t* render_thread = malloc(sizeof(render_thread_t)); @@ -40,9 +40,10 @@ render_init(void) } /* init */ - render_thread->list = NULL; - render_thread->thread = NULL; - render_thread->cond = NULL; + render_thread->list = NULL; + render_thread->thread = NULL; + render_thread->cond = NULL; + render_thread->zathura = zathura; /* setup */ render_thread->list = girara_list_new(); @@ -130,7 +131,7 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) } bool -render(zathura_page_t* page) +render(zathura_t* zathura, zathura_page_t* page) { gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); @@ -149,8 +150,8 @@ render(zathura_page_t* page) } /* create cairo surface */ - unsigned int page_width = page->width * Zathura.document->scale; - unsigned int page_height = page->height * Zathura.document->scale; + unsigned int page_width = page->width * zathura->document->scale; + unsigned int page_height = page->height * zathura->document->scale; cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); @@ -183,18 +184,18 @@ render(zathura_page_t* page) } void -render_all(void) +render_all(zathura_t* zathura) { - if (Zathura.document == NULL) { + if (zathura->document == NULL) { return; } /* unmark all pages */ - for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) { - Zathura.document->pages[page_id]->rendered = false; + for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { + zathura->document->pages[page_id]->rendered = false; } /* redraw current page */ - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); } diff --git a/render.h b/render.h index 1f48f95..53f03e3 100644 --- a/render.h +++ b/render.h @@ -16,14 +16,16 @@ typedef struct render_thread_s GThread* thread; /**> The thread object */ GMutex* lock; /**> Lock */ GCond* cond; /**> Condition */ + zathura_t* zathura; /**> Zathura object */ } render_thread_t; /** * This function initializes a render thread * + * @param Zathura object * @return The render thread object or NULL if an error occured */ -render_thread_t* render_init(void); +render_thread_t* render_init(zathura_t* zathura); /** * This function destroys the render thread object @@ -46,7 +48,9 @@ bool render_page(render_thread_t* render_thread, zathura_page_t* page); * This function is used to unmark all pages as not rendered. This should * be used if all pages should be rendered again (e.g.: the zoom level or the * colors have changed) + * + * @param zathura Zathura object */ -void render_all(void); +void render_all(zathura_t* zathura); #endif // RENDER_H From 08117975d3dffa4e0692643dae6b1691af81c86a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:05:17 +0200 Subject: [PATCH 15/39] Updated plugins --- ft/djvu/djvu.c | 6 +++--- ft/pdf-mupdf/pdf.c | 12 ++++++------ ft/pdf-poppler/pdf.c | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 5fe130e..26b822a 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -218,13 +218,13 @@ djvu_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* djvu_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->document) { + if (!page || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; if (!page_width || !page_height) { goto error_out; diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index bb760c4..f602ffa 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -176,15 +176,15 @@ pdf_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->data || !page->document) { + if (!page || !page->data || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; - if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { + if (page->document->rotate == 90 || page->document->rotate == 270) { unsigned int dim_temp = 0; dim_temp = page_width; page_width = page_height; @@ -215,9 +215,9 @@ pdf_page_render(zathura_page_t* page) fz_matrix ctm = fz_identity; ctm = fz_concat(ctm, fz_translate(0, -mupdf_page->page->mediabox.y1)); - ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); + ctm = fz_concat(ctm, fz_scale(page->document->scale, -page->document->scale)); ctm = fz_concat(ctm, fz_rotate(mupdf_page->page->rotate)); - ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate)); + ctm = fz_concat(ctm, fz_rotate(page->document->rotate)); fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index fadf9cc..6d50638 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -253,13 +253,13 @@ pdf_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->data || !page->document) { + if (!page || !page->data || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; /* create pixbuf */ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, @@ -270,7 +270,7 @@ pdf_page_render(zathura_page_t* page) } poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, - Zathura.document->scale, 90, pixbuf); + page->document->scale, 90, pixbuf); /* create image buffer */ zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); From f57fe5dfde903b01e442faf6754f5715c522465f Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 18:19:41 +0200 Subject: [PATCH 16/39] update document.c/.h --- config.h | 2 ++ document.c | 92 ++++++++++++++++++++++++++---------------------------- document.h | 20 +++++++----- render.h | 6 ++-- zathura.c | 11 +++++-- zathura.h | 19 +++++++++-- 6 files changed, 85 insertions(+), 65 deletions(-) diff --git a/config.h b/config.h index 4103598..b5b152d 100644 --- a/config.h +++ b/config.h @@ -7,6 +7,8 @@ /** * This function loads the default values of the configuration + * + * @param zathura the zathura session */ void config_load_default(zathura_t* zathura); diff --git a/document.c b/document.c index 99a41fb..6a1d462 100644 --- a/document.c +++ b/document.c @@ -18,10 +18,8 @@ #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) -zathura_document_plugin_t* zathura_document_plugins = NULL; - void -zathura_document_plugins_load(void) +zathura_document_plugins_load(zathura_t* zathura) { /* read all files in the plugin directory */ DIR* dir = opendir(PLUGIN_DIR); @@ -76,7 +74,7 @@ zathura_document_plugins_load(void) register_plugin(plugin); - bool r = zathura_document_plugin_register(plugin, handle); + bool r = zathura_document_plugin_register(zathura, plugin, handle); if (r == false) { fprintf(stderr, "error: could not register plugin (%s)\n", path); @@ -107,60 +105,54 @@ error_continue: } void -zathura_document_plugins_free(void) +zathura_document_plugins_free(zathura_t* zathura) { - /* free registered plugins */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { - zathura_document_plugin_t* tmp = plugin->next; - free(plugin->file_extension); - free(plugin); - plugin = tmp; + if (zathura == NULL) { + return; } - zathura_document_plugins = NULL; + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter == NULL) { + return; + } + + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); + free(plugin->file_extension); + free(plugin); + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } bool -zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) +zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* new_plugin, void* handle) { if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { - fprintf(stderr, "plugin: could not register\n"); + girara_error("plugin: could not register\n"); return false; } /* search existing plugins */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { - if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { - fprintf(stderr, "plugin: already registered for filetype %s\n", plugin->file_extension); - return false; - } - - if (plugin->next == NULL) { - break; - } - - plugin = plugin->next; - } - - /* create new plugin */ - new_plugin->handle = handle; - new_plugin->next = NULL; - - /* append to list */ - if (plugin == NULL) { - zathura_document_plugins = new_plugin; - } else { - plugin->next = new_plugin; + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter) { + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); + if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { + girara_error("plugin: already registered for filetype %s\n", plugin->file_extension); + girara_list_iterator_free(iter); + return false; + } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } + girara_list_append(zathura->plugins.plugins, new_plugin); return true; } zathura_document_t* -zathura_document_open(const char* path, const char* password) +zathura_document_open(zathura_t* zathura, const char* path, const char* password) { if (!path) { goto error_out; @@ -224,14 +216,19 @@ zathura_document_open(const char* path, const char* password) document->functions.page_form_fields_get = NULL; document->functions.page_render = NULL; - /* init plugin with associated file type */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter == NULL) { + return; + } + + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); if (!strcmp(file_extension, plugin->file_extension)) { + girara_list_iterator_free(iter); if (plugin->open_function) { if (plugin->open_function(document)) { /* update statusbar */ - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path); /* read all pages */ document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); @@ -250,16 +247,15 @@ zathura_document_open(const char* path, const char* password) return document; } else { - fprintf(stderr, "error: could not open file\n"); + girara_error("could not open file\n"); goto error_free; } } } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); - plugin = plugin->next; - } - - fprintf(stderr, "error: unknown file type\n"); + girara_error("unknown file type\n"); error_free: diff --git a/document.h b/document.h index 5fb78e2..2536958 100644 --- a/document.h +++ b/document.h @@ -7,12 +7,13 @@ #include #include +#include "zathura.h" #define PLUGIN_DIR "/usr/lib/zathura" #define PLUGIN_REGISTER_FUNCTION "plugin_register" typedef struct zathura_list_s zathura_list_t; -typedef struct zathura_document_s zathura_document_t; +// typedef struct zathura_document_s zathura_document_t; typedef bool (*zathura_document_open_t)(zathura_document_t* document); @@ -24,7 +25,6 @@ typedef struct zathura_document_plugin_s char* file_extension; /**> File extension */ zathura_document_open_t open_function; /**> Document open function */ void* handle; /**> DLL handle */ - struct zathura_document_plugin_s *next; /**> Next plugin */ // TODO: Use list_t } zathura_document_plugin_t; /** @@ -139,7 +139,7 @@ typedef struct zathura_form_s /** * Page */ -typedef struct zathura_page_s +struct zathura_page_s { double height; /**> Page height */ double width; /**> Page width */ @@ -150,7 +150,7 @@ typedef struct zathura_page_s GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ -} zathura_page_t; +}; /** * Document @@ -226,18 +226,22 @@ struct zathura_document_s /** * Load all document plugins + * + * @param zathura the zathura session */ -void zathura_document_plugins_load(void); +void zathura_document_plugins_load(zathura_t* zathura); /** * Free all document plugins + * + * @param zathura the zathura session */ -void zathura_document_plugins_free(void); +void zathura_document_plugins_free(zathura_t* zathura); /** * Register document plugin */ -bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle); +bool zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* new_plugin, void* handle); /** * Open the document @@ -246,7 +250,7 @@ bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, voi * @param password Password of the document or NULL * @return The document object */ -zathura_document_t* zathura_document_open(const char* path, const char* password); +zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, const char* password); /** * Free the document diff --git a/render.h b/render.h index 1f48f95..362bafd 100644 --- a/render.h +++ b/render.h @@ -7,16 +7,16 @@ #include #include -#include "document.h" +#include "zathura.h" #include "callbacks.h" -typedef struct render_thread_s +struct render_thread_s { girara_list_t* list; /**> The list of pages */ GThread* thread; /**> The thread object */ GMutex* lock; /**> Lock */ GCond* cond; /**> Condition */ -} render_thread_t; +}; /** * This function initializes a render thread diff --git a/zathura.c b/zathura.c index 602cfb8..f1715ff 100644 --- a/zathura.c +++ b/zathura.c @@ -10,6 +10,7 @@ #include "shortcuts.h" #include "zathura.h" #include "utils.h" +#include "render.h" /* function implementation */ zathura_t* @@ -21,6 +22,10 @@ zathura_init(int argc, char* argv[]) return NULL; } + /* plugins */ + zathura->plugins.plugins = girara_list_new(); + zathura->plugins.path = NULL; + /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; @@ -74,7 +79,7 @@ zathura_init(int argc, char* argv[]) zathura->ui.session->events.buffer_changed = buffer_changed; /* load plugins */ - zathura_document_plugins_load(); + zathura_document_plugins_load(zathura); /* configuration */ config_load_default(zathura); @@ -108,7 +113,7 @@ zathura_free(zathura_t* zathura) document_close(zathura); /* free registered plugins */ - zathura_document_plugins_free(); + zathura_document_plugins_free(zathura); } bool @@ -118,7 +123,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) goto error_out; } - zathura_document_t* document = zathura_document_open(path, password); + zathura_document_t* document = zathura_document_open(zathura, path, password); if (!document) { goto error_out; diff --git a/zathura.h b/zathura.h index bb3a2cc..c90d5c1 100644 --- a/zathura.h +++ b/zathura.h @@ -6,9 +6,6 @@ #include #include -#include "render.h" -#include "document.h" - enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, @@ -24,6 +21,16 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, #define NORMAL (1 << 3) #define INSERT (1 << 4) +/* forward declaration for types from document.h */ +struct zathura_document_s; +struct zathura_page_s; +typedef struct zathura_document_s zathura_document_t; +typedef struct zathura_page_s zathura_page_t; + +/* forward declaration for types from render.h */ +struct render_thread_s; +typedef struct render_thread_s render_thread_t; + typedef struct zathura_s { struct @@ -46,6 +53,12 @@ typedef struct zathura_s render_thread_t* render_thread; /**> The thread responsible for rendering the pages */ } sync; + struct + { + girara_list_t* plugins; + girara_list_t* path; + } plugins; + zathura_document_t* document; /**> The current document */ } zathura_t; From 0d5a06ce291df348c3637f8ea0a9ebafe4504970 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 18:21:33 +0200 Subject: [PATCH 17/39] free plugins --- zathura.c | 1 + 1 file changed, 1 insertion(+) diff --git a/zathura.c b/zathura.c index f1715ff..62411a5 100644 --- a/zathura.c +++ b/zathura.c @@ -114,6 +114,7 @@ zathura_free(zathura_t* zathura) /* free registered plugins */ zathura_document_plugins_free(zathura); + girara_list_free(zathura->plugins.plugins); } bool From 536862900ea352fcc06dd8a72f71201430f4d4b2 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:23:34 +0200 Subject: [PATCH 18/39] Updated document.c/zathura.c --- document.c | 2 +- zathura.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/document.c b/document.c index 6a1d462..4979b1d 100644 --- a/document.c +++ b/document.c @@ -218,7 +218,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); if (iter == NULL) { - return; + goto error_free; } do { diff --git a/zathura.c b/zathura.c index 62411a5..5bfed4c 100644 --- a/zathura.c +++ b/zathura.c @@ -146,7 +146,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) girara_set_view(zathura->ui.session, zathura->ui.page_view); /* threads */ - zathura->sync.render_thread = render_init(); + zathura->sync.render_thread = render_init(zathura); if (!zathura->sync.render_thread) { goto error_free; From 4a8f4df2dbc02ea49a7bcd8468115f7be96169c2 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:29:50 +0200 Subject: [PATCH 19/39] Updated commands/render/shortcuts/utils for zathura object --- commands.c | 7 ++++++- render.c | 5 +++-- shortcuts.c | 57 +++++++++++++++++++---------------------------------- utils.c | 1 + 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/commands.c b/commands.c index a7dd660..bfe368a 100644 --- a/commands.c +++ b/commands.c @@ -24,7 +24,12 @@ cmd_bookmark_open(girara_session_t* session, int argc, char** argv) bool cmd_close(girara_session_t* session, int argc, char** argv) { - document_close(); + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(zathura->document != NULL, false); + + document_close(zathura); return true; } diff --git a/render.c b/render.c index 0329711..821d665 100644 --- a/render.c +++ b/render.c @@ -1,8 +1,9 @@ #include "render.h" #include "zathura.h" +#include "document.h" void* render_job(void* data); -bool render(zathura_page_t* page); +bool render(zathura_t* zathura, zathura_page_t* page); void* render_job(void* data) @@ -196,6 +197,6 @@ render_all(zathura_t* zathura) } /* redraw current page */ - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); } diff --git a/shortcuts.c b/shortcuts.c index 8178891..72acb44 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -5,6 +5,7 @@ #include "callbacks.h" #include "shortcuts.h" +#include "document.h" #include "zathura.h" #include "render.h" #include "utils.h" @@ -13,8 +14,6 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; girara_mode_set(session, NORMAL); @@ -25,8 +24,6 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -35,8 +32,6 @@ bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -45,8 +40,6 @@ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; girara_mode_set(session, argument->n); @@ -57,8 +50,6 @@ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); @@ -77,8 +68,6 @@ bool sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -136,7 +125,7 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int new_page = (new_page + number_of_pages - 1) % number_of_pages; } - page_set(new_page); + page_set(zathura, new_page); return false; } @@ -145,9 +134,6 @@ bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - - zathura_t* zathura = session->global.data; return false; } @@ -156,9 +142,6 @@ bool sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - - zathura_t* zathura = session->global.data; return false; } @@ -175,7 +158,7 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t zathura->document->rotate = (zathura->document->rotate + 90) % 360; /* render all pages again */ - render_all(); + render_all(zathura); return false; } @@ -191,9 +174,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) - adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); else - adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble value = gtk_adjustment_get_value(adjustment); @@ -276,15 +259,15 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned GtkTreeModel* model = NULL; GtkCellRenderer* renderer = NULL; - if (zathura->UI.index == NULL) { + if (zathura->ui.index == NULL) { /* create new index widget */ - zathura->UI.index = gtk_scrolled_window_new(NULL, NULL); + zathura->ui.index = gtk_scrolled_window_new(NULL, NULL); - if (zathura->UI.index == NULL) { + if (zathura->ui.index == NULL) { goto error_ret; } - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->UI.index), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* create index */ @@ -322,25 +305,25 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); /*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/ - gtk_container_add(GTK_CONTAINER(zathura->UI.index), treeview); + gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview); gtk_widget_show(treeview); } - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->UI.index))) { - girara_set_view(session, zathura->UI.page_view); - gtk_widget_hide(GTK_WIDGET(zathura->UI.index)); + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->ui.index))) { + girara_set_view(session, zathura->ui.page_view); + gtk_widget_hide(GTK_WIDGET(zathura->ui.index)); } else { - girara_set_view(session, zathura->UI.index); - gtk_widget_show(GTK_WIDGET(zathura->UI.index)); + girara_set_view(session, zathura->ui.index); + gtk_widget_show(GTK_WIDGET(zathura->ui.index)); } return false; error_free: - if (zathura->UI.index != NULL) { - g_object_ref_sink(zathura->UI.index); - zathura->UI.index = NULL; + if (zathura->ui.index != NULL) { + g_object_ref_sink(zathura->ui.index); + zathura->ui.index = NULL; } if (document_index != NULL) { @@ -423,7 +406,7 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) g_return_val_if_fail(zathura->document != NULL, false); /* retreive zoom step value */ - int* value = girara_setting_get(zathura->UI.session, "zoom-step"); + int* value = girara_setting_get(zathura->ui.session, "zoom-step"); if (value == NULL) { return false; } @@ -438,7 +421,7 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) zathura->document->scale = 1.0; } - render_all(); + render_all(zathura); return false; } diff --git a/utils.c b/utils.c index 79494f8..9183924 100644 --- a/utils.c +++ b/utils.c @@ -10,6 +10,7 @@ #include "utils.h" #include "zathura.h" +#include "document.h" #define BLOCK_SIZE 64 From 8bcb79ea940d30523ec9b03416e01941ca9d6cb5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 21:22:35 +0200 Subject: [PATCH 20/39] Update --- callbacks.c | 5 +--- document.c | 2 ++ render.c | 32 ++++++++++++++++++++-- render.h | 10 +++++++ zathura.c | 78 +++++++++++++++++++++++++---------------------------- zathura.h | 8 ------ 6 files changed, 80 insertions(+), 55 deletions(-) diff --git a/callbacks.c b/callbacks.c index 8fb333d..be7f3a4 100644 --- a/callbacks.c +++ b/callbacks.c @@ -38,14 +38,11 @@ buffer_changed(girara_session_t* session) void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { - g_return_if_fail(data != NULL); - zathura_t* zathura = data; - if (!zathura->document || !zathura->document->pages || !zathura->ui.page_view) { + if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) { return; } - // FIXME /* get current adjustment values */ /*gdouble lower = gtk_adjustment_get_value(adjustment);*/ diff --git a/document.c b/document.c index 4979b1d..8802593 100644 --- a/document.c +++ b/document.c @@ -15,6 +15,7 @@ #include "document.h" #include "utils.h" #include "zathura.h" +#include "render.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) @@ -385,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->rendered = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); + g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); diff --git a/render.c b/render.c index 821d665..967f7b9 100644 --- a/render.c +++ b/render.c @@ -22,7 +22,7 @@ render_job(void* data) g_mutex_unlock(render_thread->lock); if (render(render_thread->zathura, page) != true) { - fprintf(stderr, "rendering failed\n"); + girara_error("Rendering failed\n"); } printf("Rendered %d\n", page->number); @@ -134,6 +134,10 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) bool render(zathura_t* zathura, zathura_page_t* page) { + if (zathura == NULL || page == NULL) { + return false; + } + gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); zathura_image_buffer_t* image_buffer = zathura_page_render(page); @@ -198,5 +202,29 @@ render_all(zathura_t* zathura) /* redraw current page */ GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, NULL); + cb_view_vadjustment_value_changed(view_vadjustment, zathura); +} + +gboolean +page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) +{ + zathura_page_t* page = data; + g_static_mutex_lock(&(page->lock)); + + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + + if (cairo == NULL) { + girara_error("Could not create blank page"); + g_static_mutex_unlock(&(page->lock)); + return false; + } + + cairo_set_source_rgb(cairo, 0, 0, 0); + cairo_rectangle(cairo, 0, 0, page->width, page->height); + cairo_fill(cairo); + cairo_destroy(cairo); + + g_static_mutex_unlock(&(page->lock)); + + return true; } diff --git a/render.h b/render.h index c20c5c7..73f2a27 100644 --- a/render.h +++ b/render.h @@ -53,4 +53,14 @@ bool render_page(render_thread_t* render_thread, zathura_page_t* page); */ void render_all(zathura_t* zathura); +/** + * Renders page + * + * @param widget Drawing area + * @param event Event + * @param data Optional data + * @return true if no error occured + */ +gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data); + #endif // RENDER_H diff --git a/zathura.c b/zathura.c index 5bfed4c..25d479c 100644 --- a/zathura.c +++ b/zathura.c @@ -12,6 +12,15 @@ #include "utils.h" #include "render.h" +typedef struct zathura_document_info_s +{ + zathura_t* zathura; + const char* path; + const char* password; +} zathura_document_info_t; + +gboolean document_info_open(gpointer data); + /* function implementation */ zathura_t* zathura_init(int argc, char* argv[]) @@ -84,6 +93,17 @@ zathura_init(int argc, char* argv[]) /* configuration */ config_load_default(zathura); + if (argc > 1) { + zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); + + if (document_info != NULL) { + document_info->zathura = zathura; + document_info->path = argv[1]; + document_info->password = (argc >= 2) ? argv[2] : NULL; + g_idle_add(document_info_open, document_info); + } + } + return zathura; error_free: @@ -117,6 +137,22 @@ zathura_free(zathura_t* zathura) girara_list_free(zathura->plugins.plugins); } +gboolean +document_info_open(gpointer data) +{ + zathura_document_info_t* document_info = data; + g_return_val_if_fail(document_info != NULL, FALSE); + + if (document_info->zathura == NULL || document_info->path == NULL) { + free(document_info); + return FALSE; + } + + document_open(document_info->zathura, document_info->path, document_info->password); + + return FALSE; +} + bool document_open(zathura_t* zathura, const char* path, const char* password) { @@ -132,11 +168,6 @@ document_open(zathura_t* zathura, const char* path, const char* password) zathura->document = document; - /* init view */ - if (create_blank_pages(zathura) == false) { - return false; - } - /* view mode */ int* value = girara_setting_get(zathura->ui.session, "pages-per-row"); int pages_per_row = (value) ? *value : 1; @@ -203,7 +234,7 @@ page_set(zathura_t* zathura, unsigned int page_id) } GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, NULL); + cb_view_vadjustment_value_changed(view_vadjustment, zathura); /* update page number */ zathura->document->current_page_number = page_id; @@ -249,34 +280,6 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) gtk_widget_show_all(zathura->ui.page_view); } -bool -create_blank_pages(zathura_t* zathura) -{ - /* 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)); - - cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); - - if (cairo == NULL) { - girara_error("Could not create blank page"); - g_static_mutex_unlock(&(page->lock)); - return false; - } - - cairo_set_source_rgb(cairo, 1, 1, 1); - cairo_rectangle(cairo, 0, 0, page->width, page->height); - cairo_fill(cairo); - cairo_destroy(cairo); - - g_static_mutex_unlock(&(page->lock)); - } - - return true; -} - /* main function */ int main(int argc, char* argv[]) { @@ -290,13 +293,6 @@ int main(int argc, char* argv[]) return -1; } - if (argc > 1) { - if (!document_open(zathura, argv[1], NULL)) { - printf("error: could not open document\n"); - return -1; - } - } - gdk_threads_enter(); gtk_main(); gdk_threads_leave(); diff --git a/zathura.h b/zathura.h index c90d5c1..739cd76 100644 --- a/zathura.h +++ b/zathura.h @@ -113,12 +113,4 @@ bool page_set(zathura_t* zathura, unsigned int page_id); */ void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row); -/** - * Create blank pages - * - * @param zathura The zathura zathura - * @return false if an error occured, otherwise true - */ -bool create_blank_pages(zathura_t* zathura); - #endif // ZATHURA_H From fdf0bd56495fce0bc9bcd49d026df40b67f94226 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 22:59:59 +0200 Subject: [PATCH 21/39] Save surface temporary in page_t --- document.c | 1 + document.h | 1 + render.c | 27 ++++++++++++++++----------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/document.c b/document.c index 8802593..6525711 100644 --- a/document.c +++ b/document.c @@ -386,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->rendered = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); + page->surface = NULL; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); diff --git a/document.h b/document.h index 2536958..56a3e90 100644 --- a/document.h +++ b/document.h @@ -150,6 +150,7 @@ struct zathura_page_s GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ + cairo_surface_t* surface; /** Cairo surface */ }; /** diff --git a/render.c b/render.c index 967f7b9..3be9558 100644 --- a/render.c +++ b/render.c @@ -176,10 +176,7 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ - cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); - cairo_set_source_surface(cairo, surface, 0, 0); - cairo_paint(cairo); - cairo_destroy(cairo); + page->surface = surface; zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); @@ -209,22 +206,30 @@ gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { zathura_page_t* page = data; + if (page == NULL) { + return FALSE; + } + g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); if (cairo == NULL) { - girara_error("Could not create blank page"); + girara_error("Could not retreive cairo object"); g_static_mutex_unlock(&(page->lock)); - return false; + return FALSE; } - cairo_set_source_rgb(cairo, 0, 0, 0); - cairo_rectangle(cairo, 0, 0, page->width, page->height); - cairo_fill(cairo); - cairo_destroy(cairo); + if (page->surface == NULL) { + cairo_set_source_surface(cairo, page->surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + + cairo_surface_destroy(page->surface); + page->surface = NULL; + } g_static_mutex_unlock(&(page->lock)); - return true; + return TRUE; } From b2fc17207eb9c1e2dbae5f9e66b2ae834c6913e4 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 00:36:56 +0200 Subject: [PATCH 22/39] Make plugin path configurable * We don't fail if we can't load a plugin. There can be anything. * Reintroduce the command line parser from glib. * Use fstatat as it is more reliable than d_type from dirent. --- document.c | 156 +++++++++++++++++++++++++++++------------------------ document.h | 1 - zathura.c | 60 ++++++++++++++++++++- zathura.h | 6 +++ 4 files changed, 150 insertions(+), 73 deletions(-) diff --git a/document.c b/document.c index 6525711..34ab250 100644 --- a/document.c +++ b/document.c @@ -1,7 +1,7 @@ /* See LICENSE file for license and copyright information */ #define _BSD_SOURCE -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 700 // TODO: Implement realpath #include @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #include "document.h" #include "utils.h" @@ -22,87 +25,98 @@ void zathura_document_plugins_load(zathura_t* zathura) { - /* read all files in the plugin directory */ - DIR* dir = opendir(PLUGIN_DIR); - if (dir == NULL) { - fprintf(stderr, "error: could not open plugin directory: %s\n", PLUGIN_DIR); + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.path); + if (iter == NULL) { return; } - struct dirent* entry; - while ((entry = readdir(dir)) != NULL) { - /* check if entry is a file */ - if (entry->d_type != 0x8) { + do + { + char* plugindir = girara_list_iterator_data(iter); + + /* read all files in the plugin directory */ + DIR* dir = opendir(plugindir); + if (dir == NULL) { + girara_error("could not open plugin directory: %s", plugindir); continue; } - void* handle = NULL; - zathura_document_plugin_t* plugin = NULL; - char* path = NULL; + int fddir = dirfd(dir); + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) { + struct stat statbuf; + if (fstatat(fddir, entry->d_name, &statbuf, 0) != 0) { + girara_error("failed to fstatat %s/%s; errno is %d.", plugindir, entry->d_name, errno); + continue; + } - /* get full path */ - path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); + /* check if entry is a file */ + if (S_ISREG(statbuf.st_mode) == 0) { + girara_info("%s/%s is not a regular file. Skipping.", plugindir, entry->d_name); + continue; + } - if (path == NULL) { - goto error_continue; + void* handle = NULL; + zathura_document_plugin_t* plugin = NULL; + char* path = NULL; + + /* get full path */ + path = g_build_filename(plugindir, entry->d_name, NULL); + if (path == NULL) { + g_error("failed to allocate memory!"); + break; + } + + /* load plugin */ + handle = dlopen(path, RTLD_NOW); + if (handle == NULL) { + girara_error("could not load plugin %s (%s)", path, dlerror()); + g_free(path); + continue; + } + + /* resolve symbol */ + zathura_plugin_register_service_t register_plugin; + *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); + + if (register_plugin == NULL) { + girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path); + g_free(path); + dlclose(handle); + continue; + } + + plugin = malloc(sizeof(zathura_document_plugin_t)); + + if (plugin == NULL) { + g_error("failed to allocate memory!"); + break; + } + + plugin->file_extension = NULL; + plugin->open_function = NULL; + + register_plugin(plugin); + + bool r = zathura_document_plugin_register(zathura, plugin, handle); + + if (r == false) { + girara_error("could not register plugin %s", path); + free(plugin); + dlclose(handle); + } + else { + girara_info("successfully loaded plugin %s", path); + } + + g_free(path); } - /* load plugin */ - handle = dlopen(path, RTLD_NOW); - - if (handle == NULL) { - fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); - goto error_free; + if (closedir(dir) == -1) { + girara_error("could not close plugin directory %s", plugindir); } - - /* resolve symbol */ - zathura_plugin_register_service_t register_plugin; - *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); - - if (register_plugin == NULL) { - fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); - goto error_free; - } - - plugin = malloc(sizeof(zathura_document_plugin_t)); - - if (plugin == NULL) { - goto error_free; - } - - plugin->file_extension = NULL; - plugin->open_function = NULL; - - register_plugin(plugin); - - bool r = zathura_document_plugin_register(zathura, plugin, handle); - - if (r == false) { - fprintf(stderr, "error: could not register plugin (%s)\n", path); - goto error_free; - } - - free(path); - - continue; - -error_free: - - free(path); - free(plugin); - - if (handle) { - dlclose(handle); - } - -error_continue: - - continue; - } - - if (closedir(dir) == -1) { - fprintf(stderr, "error: could not close plugin directory: %s\n", PLUGIN_DIR); - } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } void diff --git a/document.h b/document.h index 56a3e90..358b945 100644 --- a/document.h +++ b/document.h @@ -9,7 +9,6 @@ #include #include "zathura.h" -#define PLUGIN_DIR "/usr/lib/zathura" #define PLUGIN_REGISTER_FUNCTION "plugin_register" typedef struct zathura_list_s zathura_list_t; diff --git a/zathura.c b/zathura.c index 25d479c..f444c3b 100644 --- a/zathura.c +++ b/zathura.c @@ -33,7 +33,8 @@ zathura_init(int argc, char* argv[]) /* plugins */ zathura->plugins.plugins = girara_list_new(); - zathura->plugins.path = NULL; + zathura->plugins.path = girara_list_new(); + girara_list_set_free_function(zathura->plugins.path, g_free); /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { @@ -87,6 +88,58 @@ zathura_init(int argc, char* argv[]) /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; + /* parse command line options */ + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; + GOptionEntry entries[] = + { + /* { "reparent", 'e', 0, G_OPTION_ARG_INT, &Zathura.UI.embed, "Reparents to window specified by xid", "xid" }, */ + { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, + { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, + { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, + { NULL } + }; + + GOptionContext* context = g_option_context_new(" [file] [password]"); + g_option_context_add_main_entries(context, entries, NULL); + + GError* error = NULL; + if (!g_option_context_parse(context, &argc, &argv, &error)) + { + printf("Error parsing command line arguments: %s\n", error->message); + g_option_context_free(context); + g_error_free(error); + goto error_free; + } + g_option_context_free(context); + + if (config_dir) { + zathura->config.config_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_CONFIG); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (data_dir) { + zathura->config.data_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_DATA); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (plugin_path) { + gchar** paths = g_strsplit(plugin_path, ":", 0); + for (unsigned int i = 0; paths[i] != '\0'; ++i) { + girara_list_append(zathura->plugins.path, g_strdup(paths[i])); + } + g_strfreev(paths); + } else { + /* XXX: this shouldn't be hard coded! */ + girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); + girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); + } + /* load plugins */ zathura_document_plugins_load(zathura); @@ -135,6 +188,11 @@ zathura_free(zathura_t* zathura) /* free registered plugins */ zathura_document_plugins_free(zathura); girara_list_free(zathura->plugins.plugins); + girara_list_free(zathura->plugins.path); + + /* free config variables */ + g_free(zathura->config.config_dir); + g_free(zathura->config.data_dir); } gboolean diff --git a/zathura.h b/zathura.h index 739cd76..86c17a9 100644 --- a/zathura.h +++ b/zathura.h @@ -59,6 +59,12 @@ typedef struct zathura_s girara_list_t* path; } plugins; + struct + { + gchar* config_dir; + gchar* data_dir; + } config; + zathura_document_t* document; /**> The current document */ } zathura_t; From 298c9d2c7a807f4d529fbfa8d3b5b73124b19305 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 14:46:08 +0200 Subject: [PATCH 23/39] readd tabbed support --- zathura.c | 106 +++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/zathura.c b/zathura.c index f444c3b..ddd5540 100644 --- a/zathura.c +++ b/zathura.c @@ -36,11 +36,65 @@ zathura_init(int argc, char* argv[]) zathura->plugins.path = girara_list_new(); girara_list_set_free_function(zathura->plugins.path, g_free); + /* parse command line options */ + GdkNativeWindow embed = 0; + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; + GOptionEntry entries[] = + { + { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, "Reparents to window specified by xid", "xid" }, + { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, + { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, + { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, + { NULL } + }; + + GOptionContext* context = g_option_context_new(" [file] [password]"); + g_option_context_add_main_entries(context, entries, NULL); + + GError* error = NULL; + if (!g_option_context_parse(context, &argc, &argv, &error)) + { + printf("Error parsing command line arguments: %s\n", error->message); + g_option_context_free(context); + g_error_free(error); + goto error_free; + } + g_option_context_free(context); + + if (config_dir) { + zathura->config.config_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_CONFIG); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (data_dir) { + zathura->config.data_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_DATA); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (plugin_path) { + gchar** paths = g_strsplit(plugin_path, ":", 0); + for (unsigned int i = 0; paths[i] != '\0'; ++i) { + girara_list_append(zathura->plugins.path, g_strdup(paths[i])); + } + g_strfreev(paths); + } else { + /* XXX: this shouldn't be hard coded! */ + girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); + girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); + } + /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; } + zathura->ui.session->gtk.embed = embed; if (girara_session_init(zathura->ui.session) == false) { goto error_out; } @@ -88,58 +142,6 @@ zathura_init(int argc, char* argv[]) /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; - /* parse command line options */ - gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; - GOptionEntry entries[] = - { - /* { "reparent", 'e', 0, G_OPTION_ARG_INT, &Zathura.UI.embed, "Reparents to window specified by xid", "xid" }, */ - { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, - { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, - { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, - { NULL } - }; - - GOptionContext* context = g_option_context_new(" [file] [password]"); - g_option_context_add_main_entries(context, entries, NULL); - - GError* error = NULL; - if (!g_option_context_parse(context, &argc, &argv, &error)) - { - printf("Error parsing command line arguments: %s\n", error->message); - g_option_context_free(context); - g_error_free(error); - goto error_free; - } - g_option_context_free(context); - - if (config_dir) { - zathura->config.config_dir = g_strdup(config_dir); - } else { - gchar* path = girara_get_xdg_path(XDG_CONFIG); - zathura->config.config_dir = g_build_filename(path, "zathura", NULL); - g_free(path); - } - - if (data_dir) { - zathura->config.data_dir = g_strdup(config_dir); - } else { - gchar* path = girara_get_xdg_path(XDG_DATA); - zathura->config.config_dir = g_build_filename(path, "zathura", NULL); - g_free(path); - } - - if (plugin_path) { - gchar** paths = g_strsplit(plugin_path, ":", 0); - for (unsigned int i = 0; paths[i] != '\0'; ++i) { - girara_list_append(zathura->plugins.path, g_strdup(paths[i])); - } - g_strfreev(paths); - } else { - /* XXX: this shouldn't be hard coded! */ - girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); - girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); - } - /* load plugins */ zathura_document_plugins_load(zathura); From 45afe89e874d913ac77c596b0976704558284c09 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:23:55 +0200 Subject: [PATCH 24/39] invalidate rect --- render.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/render.c b/render.c index 3be9558..05cb7d5 100644 --- a/render.c +++ b/render.c @@ -148,12 +148,6 @@ render(zathura_t* zathura, zathura_page_t* page) return false; } - /* remove old image */ - GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box)); - if (widget != NULL) { - gtk_container_remove(GTK_CONTAINER(page->event_box), widget); - } - /* create cairo surface */ unsigned int page_width = page->width * zathura->document->scale; unsigned int page_height = page->height * zathura->document->scale; @@ -176,7 +170,9 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ + girara_info("surface: %d %p", page->number, surface); page->surface = surface; + gdk_window_invalidate_rect(page->drawing_area->window, NULL, TRUE); zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); @@ -205,6 +201,7 @@ render_all(zathura_t* zathura) gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { + girara_info("in expose"); zathura_page_t* page = data; if (page == NULL) { return FALSE; @@ -220,14 +217,16 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) return FALSE; } + girara_info("page->num %d page->surface: %p", page->number, page->surface); if (page->surface == NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); - cairo_destroy(cairo); cairo_surface_destroy(page->surface); page->surface = NULL; } + girara_info("visible: %d", GTK_WIDGET_VISIBLE(GTK_WIDGET(page->drawing_area))); + cairo_destroy(cairo); g_static_mutex_unlock(&(page->lock)); From 4eef03c2015b2b09e685b13bc99da132456e55c2 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:26:26 +0200 Subject: [PATCH 25/39] invalidate rect --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render.c b/render.c index 05cb7d5..f22427f 100644 --- a/render.c +++ b/render.c @@ -218,7 +218,7 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) } girara_info("page->num %d page->surface: %p", page->number, page->surface); - if (page->surface == NULL) { + if (page->surface != NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); From 7dd5c0d5672b8fb533d2e69864e457ba7cabe1be Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:39:10 +0200 Subject: [PATCH 26/39] resize --- render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render.c b/render.c index f22427f..45802df 100644 --- a/render.c +++ b/render.c @@ -172,7 +172,8 @@ render(zathura_t* zathura, zathura_page_t* page) /* draw to gtk widget */ girara_info("surface: %d %p", page->number, surface); page->surface = surface; - gdk_window_invalidate_rect(page->drawing_area->window, NULL, TRUE); + gtk_widget_set_size_request(page->drawing_area, page_width, page_height); + gtk_widget_queue_draw(page->drawing_area); zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); From fd283c8873e499bef254c64f4aa622b4cb932fa7 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 16:02:54 +0200 Subject: [PATCH 27/39] memory leak --- document.c | 1 + 1 file changed, 1 insertion(+) diff --git a/document.c b/document.c index 34ab250..9ee63ae 100644 --- a/document.c +++ b/document.c @@ -569,4 +569,5 @@ zathura_image_buffer_free(zathura_image_buffer_t* image_buffer) } free(image_buffer->data); + free(image_buffer); } From 5151b84a6fe9da205366868f5aed1e32055a7552 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:03:42 +0200 Subject: [PATCH 28/39] Update render function --- ft/pdf-poppler/pdf.c | 2 +- render.c | 3 ++- zathura.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 6d50638..ac5eb07 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -270,7 +270,7 @@ pdf_page_render(zathura_page_t* page) } poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, - page->document->scale, 90, pixbuf); + page->document->scale, 0, pixbuf); /* create image buffer */ zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); diff --git a/render.c b/render.c index 45802df..66b3a40 100644 --- a/render.c +++ b/render.c @@ -165,7 +165,8 @@ render(zathura_t* zathura, zathura_page_t* page) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; - dst += 3; + src += 3; + dst += 4; } } diff --git a/zathura.c b/zathura.c index ddd5540..a2e9055 100644 --- a/zathura.c +++ b/zathura.c @@ -321,7 +321,6 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) GtkWidget* row = NULL; - /* create blank pages */ for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { if (i % pages_per_row == 0) { From 07cc456ae9969f1b507f3a9423562480e9d3d61e Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:24:19 +0200 Subject: [PATCH 29/39] Fixed rendering for mupdf/poppler backend --- ft/pdf-mupdf/pdf.c | 2 +- ft/pdf-poppler/pdf.c | 4 ++-- render.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index f602ffa..31d7cb2 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -230,7 +230,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < pixmap->h; y++) { for (unsigned int x = 0; x < pixmap->w; x++) { unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; - guchar* p = image_buffer->data + y * image_buffer->width + x; + guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index ac5eb07..3850ceb 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -269,7 +269,7 @@ pdf_page_render(zathura_page_t* page) return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, + poppler_page_render_to_pixbuf(page->data, 0, 0, page->width, page->height, page->document->scale, 0, pixbuf); /* create image buffer */ @@ -288,7 +288,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < page_height; y++) { for (unsigned int x = 0; x < page_width; x++) { unsigned char *s = pixels + y * rowstride + x * n_channels; - guchar* p = image_buffer->data + y * image_buffer->width + x; + guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; diff --git a/render.c b/render.c index 66b3a40..ef3a7af 100644 --- a/render.c +++ b/render.c @@ -162,9 +162,9 @@ render(zathura_t* zathura, zathura_page_t* page) unsigned char* src = image_buffer->data + y * image_buffer->rowstride; for (unsigned int x = 0; x < page_width; x++) { - dst[0] = src[0]; + dst[0] = src[2]; dst[1] = src[1]; - dst[2] = src[2]; + dst[2] = src[0]; src += 3; dst += 4; } From 48d5dad99d43717de077924c1600b576953d4917 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:42:16 +0200 Subject: [PATCH 30/39] Fixed rendering for djvu backend --- ft/djvu/djvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 26b822a..46908c2 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -254,7 +254,7 @@ djvu_page_render(zathura_page_t* page) /* render page */ ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, - 3 * page_width, (char*) image_buffer); + 3 * page_width, (char*) image_buffer->data); return image_buffer; From a80770a32050557730c8a1810cc64627120eb266 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 17:46:44 +0200 Subject: [PATCH 31/39] Save zathura object in zathura_ocument_t --- document.c | 1 + document.h | 1 + 2 files changed, 2 insertions(+) diff --git a/document.c b/document.c index 9ee63ae..db8dd07 100644 --- a/document.c +++ b/document.c @@ -219,6 +219,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password document->rotate = 0; document->data = NULL; document->pages = NULL; + document->zathura = zathura; document->functions.document_free = NULL; document->functions.document_index_generate = NULL; diff --git a/document.h b/document.h index 358b945..5fc5ae6 100644 --- a/document.h +++ b/document.h @@ -164,6 +164,7 @@ struct zathura_document_s double scale; /**> Scale value */ int rotate; /**> Rotation */ void* data; /**> Custom data */ + zathura_t* zathura; /** Zathura object */ struct { From a415666cc1ebcdd7683937417a884a8e3f60d02b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 18:33:28 +0200 Subject: [PATCH 32/39] zathura_page_t: replace rendered by visible --- callbacks.c | 5 +++-- document.c | 7 +------ document.h | 2 +- render.c | 14 ++++++++------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/callbacks.c b/callbacks.c index be7f3a4..5677e54 100644 --- a/callbacks.c +++ b/callbacks.c @@ -54,7 +54,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) zathura_page_t* page = zathura->document->pages[page_id]; /* check for rendered attribute */ - if (page->rendered) { + if (page->surface != NULL) { continue; } @@ -66,7 +66,8 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ if (page_id < 1) { - render_page(zathura->sync.render_thread, zathura->document->pages[page_id]); + page->visible = true; + render_page(zathura->sync.render_thread, page); } /*}*/ } diff --git a/document.c b/document.c index db8dd07..894722b 100644 --- a/document.c +++ b/document.c @@ -398,7 +398,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) if (page) { page->number = page_id; - page->rendered = false; + page->visible = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); page->surface = NULL; @@ -497,11 +497,6 @@ zathura_page_render(zathura_page_t* page) } zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - - if (buffer) { - page->rendered = true; - } - return buffer; } diff --git a/document.h b/document.h index 5fc5ae6..63517c4 100644 --- a/document.h +++ b/document.h @@ -145,7 +145,7 @@ struct zathura_page_s unsigned int number; /**> Page number */ zathura_document_t* document; /**> Document */ void* data; /**> Custom data */ - bool rendered; /**> Page has been rendered */ + bool visible; /**> Page is visible */ GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ diff --git a/render.c b/render.c index ef3a7af..a363cac 100644 --- a/render.c +++ b/render.c @@ -25,7 +25,7 @@ render_job(void* data) girara_error("Rendering failed\n"); } - printf("Rendered %d\n", page->number); + girara_info("rendered page %d\n", page->number); } return NULL; @@ -117,7 +117,7 @@ render_free(render_thread_t* render_thread) bool render_page(render_thread_t* render_thread, zathura_page_t* page) { - if (!render_thread || !page || !render_thread->list || page->rendered) { + if (!render_thread || !page || !render_thread->list || page->surface) { return false; } @@ -192,7 +192,8 @@ render_all(zathura_t* zathura) /* unmark all pages */ for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { - zathura->document->pages[page_id]->rendered = false; + cairo_surface_destroy(zathura->document->pages[page_id]->surface); + zathura->document->pages[page_id]->surface = NULL; } /* redraw current page */ @@ -224,10 +225,11 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); - cairo_surface_destroy(page->surface); - page->surface = NULL; + // cairo_surface_destroy(page->surface); + // page->surface = NULL; + } else if (page->visible) { + render_page(page->document->zathura->sync.render_thread, page); } - girara_info("visible: %d", GTK_WIDGET_VISIBLE(GTK_WIDGET(page->drawing_area))); cairo_destroy(cairo); g_static_mutex_unlock(&(page->lock)); From 8025225e149720dc1efce41cfa2bc5694de965f9 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 18:53:41 +0200 Subject: [PATCH 33/39] create dependencies --- Makefile | 10 +++++++--- ft/djvu/Makefile | 10 +++++++--- ft/pdf-mupdf/Makefile | 10 +++++++--- ft/pdf-poppler/Makefile | 10 +++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 27daaaa..9bb1219 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -34,7 +36,7 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ - ${DOBJECTS} ${PROJECT}-debug + ${DOBJECTS} ${PROJECT}-debug .depend make -C ft clean ${PROJECT}-debug: ${DOBJECTS} @@ -76,3 +78,5 @@ uninstall: @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @make -C ft uninstall + +-include $(wildcard .depend/*.dep) diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index d5e7617..bf406b2 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) diff --git a/ft/pdf-mupdf/Makefile b/ft/pdf-mupdf/Makefile index e14ed8c..e191eb9 100644 --- a/ft/pdf-mupdf/Makefile +++ b/ft/pdf-mupdf/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) diff --git a/ft/pdf-poppler/Makefile b/ft/pdf-poppler/Makefile index e14ed8c..e191eb9 100644 --- a/ft/pdf-poppler/Makefile +++ b/ft/pdf-poppler/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) From 0a18af5912a2764066ab83243694773f4f81cb93 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 19:07:18 +0200 Subject: [PATCH 34/39] ignore .depend --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 720cd3f..bceaf5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *~ *.rej *.swp +.depend From dc7c3d86eb59462f1a287164369e56a9d3b9fa9c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 19:24:03 +0200 Subject: [PATCH 35/39] Calculate page offset --- config.c | 2 ++ utils.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- utils.h | 17 +++++++++++++++ zathura.c | 5 +++++ zathura.h | 5 +++++ 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index b847456..287b991 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,8 @@ config_load_default(zathura_t* zathura) /* zathura settings */ int_value = 10; girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + int_value = 1; + girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL); int_value = 2; girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); diff --git a/utils.c b/utils.c index 9183924..42aad30 100644 --- a/utils.c +++ b/utils.c @@ -178,7 +178,8 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_ } while ((it = girara_list_iterator_next(it))); } -char* string_concat(const char* string1, ...) +char* +string_concat(const char* string1, ...) { if(!string1) { return NULL; @@ -234,3 +235,65 @@ char* string_concat(const char* string1, ...) return c; } + + +page_offset_t* +page_offset_top(zathura_page_t* page) +{ + if (page == NULL || page->document == NULL || page->document->zathura == NULL) { + return NULL; + } + + page_offset_t* offset = malloc(sizeof(page_offset_t)); + + if (offset == NULL) { + return NULL; + } + + zathura_document_t* document = page->document; + zathura_t* zathura = document->zathura; + + int* tmp = girara_setting_get(zathura->ui.session, "pages-per-row"); + + unsigned int page_padding = zathura->global.page_padding; + unsigned int pages_per_row = (tmp && *tmp != 0) ? *tmp : 1; + unsigned int number_of_rows = (document->number_of_pages / pages_per_row) + 1; + + free(tmp); + + for (unsigned int row = 0; row < number_of_rows; row++) { + unsigned int tmp = -1; + for (unsigned int column = 0; column < pages_per_row; column++) + { + unsigned int page_id = row * pages_per_row + column; + double page_height = document->pages[page_id]->height * document->scale; + + if (tmp == -1) { + tmp = page_height; + } else if (page_height > tmp) { + tmp = page_height; + } + } + + offset->y += tmp + (row == (number_of_rows - 1)) ? 0 : page_padding; + } + + for (unsigned int column = 0; column < pages_per_row; column++) { + unsigned int tmp = -1; + for (unsigned int row = 0; row < number_of_rows; row++) + { + unsigned int page_id = row * pages_per_row + column; + double page_width = document->pages[page_id]->width * document->scale; + + if (tmp == -1) { + tmp = page_width; + } else if (page_width > tmp) { + tmp = page_width; + } + } + + offset->x += tmp + (column == (pages_per_row - 1)) ? 0 : page_padding; + } + + return offset; +} diff --git a/utils.h b/utils.h index 735317a..8c10724 100644 --- a/utils.h +++ b/utils.h @@ -7,6 +7,14 @@ #include #include +#include "document.h" + +typedef struct page_offset_s +{ + int x; + int y; +} page_offset_t; + /** * Checks if the given file exists * @@ -61,4 +69,13 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_ */ char* string_concat(const char* string1, ...); +/** + * Calculates the offset of the page to the top of the viewing area as + * well as to the left side of it. The result has to be freed. + * + * @param page The Page + * @return The calculated offset or NULL if an error occured + */ +page_offset_t* page_calculate_offset(zathura_page_t* page); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index a2e9055..5e823c7 100644 --- a/zathura.c +++ b/zathura.c @@ -148,6 +148,11 @@ zathura_init(int argc, char* argv[]) /* configuration */ config_load_default(zathura); + /* save page padding */ + int* page_padding = girara_setting_get(zathura->ui.session, "page-padding"); + zathura->global.page_padding = (page_padding) ? *page_padding : 1; + + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); diff --git a/zathura.h b/zathura.h index 86c17a9..262ee74 100644 --- a/zathura.h +++ b/zathura.h @@ -65,6 +65,11 @@ typedef struct zathura_s gchar* data_dir; } config; + struct + { + unsigned int page_padding; + } global; + zathura_document_t* document; /**> The current document */ } zathura_t; From 222bd718e4b87e3373ba5b7b4223d858545e8a24 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 20:23:58 +0200 Subject: [PATCH 36/39] Simplify offset calculation --- callbacks.c | 9 ++++++++- utils.c | 45 ++++----------------------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/callbacks.c b/callbacks.c index 5677e54..cc5464a 100644 --- a/callbacks.c +++ b/callbacks.c @@ -8,6 +8,7 @@ #include "zathura.h" #include "render.h" #include "document.h" +#include "utils.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) @@ -53,6 +54,12 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { zathura_page_t* page = zathura->document->pages[page_id]; + page_offset_t* offset = page_calculate_offset(page); + if (offset) { + fprintf(stderr, "offset: %d %d\n", offset->x, offset->y); + free(offset); + } + /* check for rendered attribute */ if (page->surface != NULL) { continue; @@ -65,7 +72,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 <]*/ /*) {*/ - if (page_id < 1) { + if (page_id < 10) { page->visible = true; render_page(zathura->sync.render_thread, page); } diff --git a/utils.c b/utils.c index 42aad30..68d6d50 100644 --- a/utils.c +++ b/utils.c @@ -238,7 +238,7 @@ string_concat(const char* string1, ...) page_offset_t* -page_offset_top(zathura_page_t* page) +page_calculate_offset(zathura_page_t* page) { if (page == NULL || page->document == NULL || page->document->zathura == NULL) { return NULL; @@ -253,46 +253,9 @@ page_offset_top(zathura_page_t* page) zathura_document_t* document = page->document; zathura_t* zathura = document->zathura; - int* tmp = girara_setting_get(zathura->ui.session, "pages-per-row"); - - unsigned int page_padding = zathura->global.page_padding; - unsigned int pages_per_row = (tmp && *tmp != 0) ? *tmp : 1; - unsigned int number_of_rows = (document->number_of_pages / pages_per_row) + 1; - - free(tmp); - - for (unsigned int row = 0; row < number_of_rows; row++) { - unsigned int tmp = -1; - for (unsigned int column = 0; column < pages_per_row; column++) - { - unsigned int page_id = row * pages_per_row + column; - double page_height = document->pages[page_id]->height * document->scale; - - if (tmp == -1) { - tmp = page_height; - } else if (page_height > tmp) { - tmp = page_height; - } - } - - offset->y += tmp + (row == (number_of_rows - 1)) ? 0 : page_padding; - } - - for (unsigned int column = 0; column < pages_per_row; column++) { - unsigned int tmp = -1; - for (unsigned int row = 0; row < number_of_rows; row++) - { - unsigned int page_id = row * pages_per_row + column; - double page_width = document->pages[page_id]->width * document->scale; - - if (tmp == -1) { - tmp = page_width; - } else if (page_width > tmp) { - tmp = page_width; - } - } - - offset->x += tmp + (column == (pages_per_row - 1)) ? 0 : page_padding; + if (gtk_widget_translate_coordinates(page->event_box, zathura->ui.page_view, 0, 0, &(offset->x), &(offset->y)) == false) { + free(offset); + return NULL; } return offset; From 09328e8e895975c26a41733ed914a3dfba3b8491 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 20:41:16 +0200 Subject: [PATCH 37/39] use GtkTable for page layout --- callbacks.c | 33 +++++++++++++++++---------------- zathura.c | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/callbacks.c b/callbacks.c index cc5464a..79d0857 100644 --- a/callbacks.c +++ b/callbacks.c @@ -46,36 +46,37 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) // 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++) { zathura_page_t* page = zathura->document->pages[page_id]; - page_offset_t* offset = page_calculate_offset(page); - if (offset) { - fprintf(stderr, "offset: %d %d\n", offset->x, offset->y); - free(offset); - } - /* check for rendered attribute */ if (page->surface != NULL) { continue; } - /*double begin = page->offset;*/ - /*double end = page->offset + page->height;*/ + page_offset_t* offset = page_calculate_offset(page); + if (offset == NULL) { + continue; + } - /*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 < 10) { + double begin = offset->y; + double end = offset->y + page->height; + + girara_info("%f %f; %f %f", begin, end, lower, upper); + + 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 <] */ + ) { page->visible = true; render_page(zathura->sync.render_thread, page); } - /*}*/ + + free(offset); } } diff --git a/zathura.c b/zathura.c index 5e823c7..43aec68 100644 --- a/zathura.c +++ b/zathura.c @@ -107,7 +107,7 @@ zathura_init(int argc, char* argv[]) zathura->ui.index = NULL; /* page view */ - zathura->ui.page_view = gtk_vbox_new(FALSE, 0); + zathura->ui.page_view = gtk_table_new(0, 0, TRUE); if (!zathura->ui.page_view) { goto error_free; } @@ -115,6 +115,9 @@ zathura_init(int argc, char* argv[]) gtk_widget_show(zathura->ui.page_view); gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); + /* Put the table in the main window */ + // gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table); + /* statusbar */ zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); if (zathura->ui.statusbar.file == NULL) { @@ -319,26 +322,23 @@ void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { /* empty page view */ - GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.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; + GtkWidget* row = NULL; */ + /* create blank pages */ + + + gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); 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); - } + int x = i % pages_per_row; + int y = i / pages_per_row; + girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row); + gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding); } gtk_widget_show_all(zathura->ui.page_view); From 752ca8ec1184eafdfb3368e62d37a5dad2e3c65a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 20:46:33 +0200 Subject: [PATCH 38/39] Destroy surface if page is not visible --- callbacks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/callbacks.c b/callbacks.c index 79d0857..fb4a180 100644 --- a/callbacks.c +++ b/callbacks.c @@ -75,6 +75,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) ) { page->visible = true; render_page(zathura->sync.render_thread, page); + } else { + page->visible = false; + cairo_surface_destroy(page->surface); + page->surface = NULL; } free(offset); From 5c5df5bf828c15e7eceee2b81dc9d461f61084a7 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 21:42:18 +0200 Subject: [PATCH 39/39] Fixed rendering --- callbacks.c | 14 ++++---------- document.c | 1 + render.c | 26 ++++++++++++++++++-------- zathura.c | 34 ++++++++++++++-------------------- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/callbacks.c b/callbacks.c index fb4a180..e027b6b 100644 --- a/callbacks.c +++ b/callbacks.c @@ -44,7 +44,6 @@ 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); @@ -54,11 +53,6 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { zathura_page_t* page = zathura->document->pages[page_id]; - /* check for rendered attribute */ - if (page->surface != NULL) { - continue; - } - page_offset_t* offset = page_calculate_offset(page); if (offset == NULL) { continue; @@ -67,14 +61,14 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) double begin = offset->y; double end = offset->y + page->height; - girara_info("%f %f; %f %f", begin, end, lower, upper); - - if ( ( (begin >= lower) && (end <= upper) ) /* [> 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 <] */ ) { page->visible = true; - render_page(zathura->sync.render_thread, page); + if (page->surface == NULL) { + render_page(zathura->sync.render_thread, page); + } } else { page->visible = false; cairo_surface_destroy(page->surface); diff --git a/document.c b/document.c index 894722b..d553a57 100644 --- a/document.c +++ b/document.c @@ -404,6 +404,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->surface = NULL; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); + gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); g_static_mutex_init(&(page->lock)); diff --git a/render.c b/render.c index a363cac..9e4f288 100644 --- a/render.c +++ b/render.c @@ -24,8 +24,6 @@ render_job(void* data) if (render(render_thread->zathura, page) != true) { girara_error("Rendering failed\n"); } - - girara_info("rendered page %d\n", page->number); } return NULL; @@ -171,7 +169,6 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ - girara_info("surface: %d %p", page->number, surface); page->surface = surface; gtk_widget_set_size_request(page->drawing_area, page_width, page_height); gtk_widget_queue_draw(page->drawing_area); @@ -204,7 +201,6 @@ render_all(zathura_t* zathura) gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { - girara_info("in expose"); zathura_page_t* page = data; if (page == NULL) { return FALSE; @@ -220,14 +216,28 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) return FALSE; } - girara_info("page->num %d page->surface: %p", page->number, page->surface); if (page->surface != NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); + } else { + /* set background color */ + cairo_set_source_rgb(cairo, 255, 255, 255); + cairo_rectangle(cairo, 0, 0, page->width * page->document->scale, page->height * page->document->scale); + cairo_fill(cairo); - // cairo_surface_destroy(page->surface); - // page->surface = NULL; - } else if (page->visible) { + /* write text */ + cairo_set_source_rgb(cairo, 0, 0, 0); + const char* text = "Loading..."; + cairo_select_font_face(cairo, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cairo, 16.0); + cairo_text_extents_t extents; + cairo_text_extents(cairo, text, &extents); + double x = (page->width * page->document->scale) / 2 - (extents.width / 2 + extents.x_bearing); + double y = (page->height * page->document->scale) / 2 - (extents.height / 2 + extents.y_bearing); + cairo_move_to(cairo, x, y); + cairo_show_text(cairo, text); + + /* render real page */ render_page(page->document->zathura->sync.render_thread, page); } cairo_destroy(cairo); diff --git a/zathura.c b/zathura.c index 43aec68..c476245 100644 --- a/zathura.c +++ b/zathura.c @@ -112,8 +112,13 @@ zathura_init(int argc, char* argv[]) goto error_free; } + /* callbacks */ + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); + GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + g_signal_connect(G_OBJECT(view_hadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); + gtk_widget_show(zathura->ui.page_view); - gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); /* Put the table in the main window */ // gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table); @@ -139,9 +144,6 @@ zathura_init(int argc, char* argv[]) /* signals */ g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); - /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; @@ -155,6 +157,9 @@ zathura_init(int argc, char* argv[]) int* page_padding = girara_setting_get(zathura->ui.session, "page-padding"); zathura->global.page_padding = (page_padding) ? *page_padding : 1; + gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); + gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); @@ -251,9 +256,10 @@ document_open(zathura_t* zathura, const char* path, const char* password) goto error_free; } - /* first page */ - if (!page_set(zathura, 0)) { - goto error_free; + /* create blank pages */ + for (int page_id = 0; page_id < document->number_of_pages; page_id++) { + zathura_page_t* page = document->pages[page_id]; + gtk_widget_realize(page->event_box); } return true; @@ -321,24 +327,12 @@ error_out: void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { - /* 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 */ - - gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { int x = i % pages_per_row; int y = i / pages_per_row; - girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row); - gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding); + gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, 0, 0); } gtk_widget_show_all(zathura->ui.page_view);