From 9026f9246911562482e9796ca323fad192cea9d0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:55:50 +0200 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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);