From 46dfa2be2246eeedb2ae3d6692b41ed91e1142e6 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 4 Feb 2021 16:16:02 -0800 Subject: [PATCH] pinned --- .gitignore | 1 + zathura/adjustment.c | 104 +++--- zathura/adjustment.h | 4 +- zathura/document.c | 392 +++++++++----------- zathura/plugin.c | 2 +- zathura/render.c | 722 ++++++++++++++++++------------------- zathura/synctex.c | 2 +- zathura/zathura.c | 840 ++++++++++++++++++++++--------------------- 8 files changed, 1003 insertions(+), 1064 deletions(-) diff --git a/.gitignore b/.gitignore index 5a2e88c..d4a447f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ compile_commands.json *.log .ycm_extra_conf.py _*/ +.ccls-cache/ diff --git a/zathura/adjustment.c b/zathura/adjustment.c index fcd4d15..a8a99f6 100644 --- a/zathura/adjustment.c +++ b/zathura/adjustment.c @@ -5,21 +5,25 @@ #include -double -page_calc_height_width(zathura_document_t* document, double height, - double width, unsigned int* page_height, - unsigned int* page_width, bool rotate) -{ - g_return_val_if_fail(document != NULL && page_height != NULL && page_width != NULL, 0.0); +// @debug +#include + +double page_calc_height_width(zathura_document_t *document, double height, + double width, unsigned int *page_height, + unsigned int *page_width, bool rotate) { + g_return_val_if_fail( + document != NULL && page_height != NULL && page_width != NULL, 0.0); double scale = zathura_document_get_scale(document); + // TODO this just set all pages to the maximum. + // needs to adjust cell size based on the page size itself. if (rotate == true && zathura_document_get_rotation(document) % 180 != 0) { - *page_width = round(height * scale); - *page_height = round(width * scale); + *page_width = round(height * scale); + *page_height = round(width * scale); scale = MAX(*page_width / height, *page_height / width); } else { - *page_width = round(width * scale); + *page_width = round(width * scale); *page_height = round(height * scale); scale = MAX(*page_width / width, *page_height / height); } @@ -27,10 +31,8 @@ page_calc_height_width(zathura_document_t* document, double height, return scale; } -void -page_calc_position(zathura_document_t* document, double x, double y, double* xn, - double* yn) -{ +void page_calc_position(zathura_document_t *document, double x, double y, + double *xn, double *yn) { g_return_if_fail(document != NULL && xn != NULL && yn != NULL); const unsigned int rot = zathura_document_get_rotation(document); @@ -49,10 +51,8 @@ page_calc_position(zathura_document_t* document, double x, double y, double* xn, } } -unsigned int -position_to_page_number(zathura_document_t* document, double pos_x, - double pos_y) -{ +unsigned int position_to_page_number(zathura_document_t *document, double pos_x, + double pos_y) { g_return_val_if_fail(document != NULL, 0); unsigned int doc_width, doc_height; @@ -61,11 +61,11 @@ position_to_page_number(zathura_document_t* document, double pos_x, unsigned int cell_width, cell_height; zathura_document_get_cell_size(document, &cell_height, &cell_width); - unsigned int c0 = zathura_document_get_first_page_column(document); + unsigned int c0 = zathura_document_get_first_page_column(document); unsigned int npag = zathura_document_get_number_of_pages(document); unsigned int ncol = zathura_document_get_pages_per_row(document); unsigned int nrow = 0; - unsigned int pad = zathura_document_get_page_padding(document); + unsigned int pad = zathura_document_get_page_padding(document); if (c0 == 1) { /* There is no offset, so this is easy. */ @@ -75,8 +75,10 @@ position_to_page_number(zathura_document_t* document, double pos_x, nrow = 1 + (npag - (ncol - c0 - 1) + (ncol - 1)) / ncol; } - unsigned int col = floor(pos_x * (double)doc_width / (double)(cell_width + pad)); - unsigned int row = floor(pos_y * (double)doc_height / (double)(cell_height + pad)); + unsigned int col = + floor(pos_x * (double)doc_width / (double)(cell_width + pad)); + unsigned int row = + floor(pos_y * (double)doc_height / (double)(cell_height + pad)); unsigned int page = ncol * (row % nrow) + (col % ncol); if (page < c0 - 1) { @@ -86,22 +88,19 @@ position_to_page_number(zathura_document_t* document, double pos_x, } } - -void -page_number_to_position(zathura_document_t* document, unsigned int page_number, - double xalign, double yalign, double* pos_x, - double* pos_y) -{ +void page_number_to_position(zathura_document_t *document, + unsigned int page_number, double xalign, + double yalign, double *pos_x, double *pos_y) { g_return_if_fail(document != NULL); - unsigned int c0 = zathura_document_get_first_page_column(document); + unsigned int c0 = zathura_document_get_first_page_column(document); unsigned int npag = zathura_document_get_number_of_pages(document); unsigned int ncol = zathura_document_get_pages_per_row(document); - unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ + unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ /* row and column for page_number indexed from 0 */ - unsigned int row = (page_number + c0 - 1) / ncol; - unsigned int col = (page_number + c0 - 1) % ncol; + unsigned int row = (page_number + c0 - 1) / ncol; + unsigned int col = (page_number + c0 - 1) % ncol; /* sizes of page cell, viewport and document */ unsigned int cell_height = 0, cell_width = 0; @@ -113,14 +112,18 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number, unsigned int doc_height = 0, doc_width = 0; zathura_document_get_document_size(document, &doc_height, &doc_width); - /* compute the shift to align to the viewport. If the page fits to viewport, just center it. */ + /* compute the shift to align to the viewport. If the page fits to viewport, + * just center it. */ double shift_x = 0.5, shift_y = 0.5; if (cell_width > view_width) { - shift_x = 0.5 + (xalign - 0.5) * ((double)cell_width - (double)view_width) / (double)cell_width; + shift_x = 0.5 + (xalign - 0.5) * ((double)cell_width - (double)view_width) / + (double)cell_width; } if (cell_height > view_height) { - shift_y = 0.5 + (yalign - 0.5) * ((double)cell_height - (double)view_height) / (double)cell_height; + shift_y = 0.5 + (yalign - 0.5) * + ((double)cell_height - (double)view_height) / + (double)cell_height; } /* compute the position */ @@ -128,10 +131,7 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number, *pos_y = ((double)row + shift_y) / (double)nrow; } - -bool -page_is_visible(zathura_document_t *document, unsigned int page_number) -{ +bool page_is_visible(zathura_document_t *document, unsigned int page_number) { g_return_val_if_fail(document != NULL, false); /* position at the center of the viewport */ @@ -151,35 +151,31 @@ page_is_visible(zathura_document_t *document, unsigned int page_number) unsigned int view_width, view_height; zathura_document_get_viewport_size(document, &view_height, &view_width); - return ( fabs(pos_x - page_x) < 0.5 * (double)(view_width + cell_width) / (double)doc_width && - fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height); + return (fabs(pos_x - page_x) < + 0.5 * (double)(view_width + cell_width) / (double)doc_width && + fabs(pos_y - page_y) < + 0.5 * (double)(view_height + cell_height) / (double)doc_height); } -void -zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value) -{ - const gdouble lower = gtk_adjustment_get_lower(adjustment); +void zathura_adjustment_set_value(GtkAdjustment *adjustment, gdouble value) { + const gdouble lower = gtk_adjustment_get_lower(adjustment); const gdouble upper_m_size = gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment); gtk_adjustment_set_value(adjustment, MAX(lower, MIN(upper_m_size, value))); } -gdouble -zathura_adjustment_get_ratio(GtkAdjustment* adjustment) -{ - gdouble lower = gtk_adjustment_get_lower(adjustment); - gdouble upper = gtk_adjustment_get_upper(adjustment); +gdouble zathura_adjustment_get_ratio(GtkAdjustment *adjustment) { + gdouble lower = gtk_adjustment_get_lower(adjustment); + gdouble upper = gtk_adjustment_get_upper(adjustment); gdouble page_size = gtk_adjustment_get_page_size(adjustment); - gdouble value = gtk_adjustment_get_value(adjustment); + gdouble value = gtk_adjustment_get_value(adjustment); return (value - lower + page_size / 2.0) / (upper - lower); } -void -zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment, - gdouble ratio) -{ +void zathura_adjustment_set_value_from_ratio(GtkAdjustment *adjustment, + gdouble ratio) { if (ratio == 0.0) { return; } diff --git a/zathura/adjustment.h b/zathura/adjustment.h index 55110c7..033e67f 100644 --- a/zathura/adjustment.h +++ b/zathura/adjustment.h @@ -12,9 +12,9 @@ * desired. * * @param document the document - * @param height the original height + * @param height the original height * @param width the original width - * @param page_height the scaled and rotated height + * @param page_height the scaled and rotated height * @param page_width the scaled and rotated width * @param rotate honor page's rotation * @return real scale after rounding diff --git a/zathura/document.c b/zathura/document.c index 99f492f..bb98ba0 100644 --- a/zathura/document.c +++ b/zathura/document.c @@ -1,78 +1,80 @@ /* SPDX-License-Identifier: Zlib */ +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include #include #include "adjustment.h" +#include "content-type.h" #include "document.h" -#include "utils.h" -#include "zathura.h" #include "page.h" #include "plugin.h" -#include "content-type.h" +#include "utils.h" +#include "zathura.h" +// @debug +#include /** * Document */ struct zathura_document_s { - char* file_path; /**< File path of the document */ - char* uri; /**< URI of the document */ - char* basename; /**< Basename of the document */ - uint8_t hash_sha256[32]; /**< SHA256 hash of the document */ - const char* password; /**< Password of the document */ - unsigned int current_page_number; /**< Current page number */ - unsigned int number_of_pages; /**< Number of pages */ - double zoom; /**< Zoom value */ - unsigned int rotate; /**< Rotation */ - void* data; /**< Custom data */ + char *file_path; /**< File path of the document */ + char *uri; /**< URI of the document */ + char *basename; /**< Basename of the document */ + uint8_t hash_sha256[32]; /**< SHA256 hash of the document */ + const char *password; /**< Password of the document */ + unsigned int current_page_number; /**< Current page number */ + unsigned int number_of_pages; /**< Number of pages */ + double zoom; /**< Zoom value */ + unsigned int rotate; /**< Rotation */ + void *data; /**< Custom data */ zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */ - int page_offset; /**< Page offset */ - double cell_width; /**< width of a page cell in the document (not transformed by scale and rotation) */ - double cell_height; /**< height of a page cell in the document (not transformed by scale and rotation) */ - unsigned int view_width; /**< width of current viewport */ + int page_offset; /**< Page offset */ + double cell_width; /**< width of a page cell in the document (not transformed + by scale and rotation) */ + double cell_height; /**< height of a page cell in the document (not + transformed by scale and rotation) */ + unsigned int view_width; /**< width of current viewport */ unsigned int view_height; /**< height of current viewport */ - double view_ppi; /**< PPI of the current viewport */ - zathura_device_factors_t device_factors; /**< x and y device scale factors (for e.g. HiDPI) */ - unsigned int pages_per_row; /**< number of pages in a row */ + double view_ppi; /**< PPI of the current viewport */ + zathura_device_factors_t + device_factors; /**< x and y device scale factors (for e.g. HiDPI) */ + unsigned int pages_per_row; /**< number of pages in a row */ unsigned int first_page_column; /**< column of the first page */ - unsigned int page_padding; /**< padding between pages */ - double position_x; /**< X adjustment */ - double position_y; /**< Y adjustment */ + unsigned int page_padding; /**< padding between pages */ + double position_x; /**< X adjustment */ + double position_y; /**< Y adjustment */ /** * Document pages */ - zathura_page_t** pages; + zathura_page_t **pages; /** * Used plugin */ - zathura_plugin_t* plugin; + zathura_plugin_t *plugin; }; -static void -check_set_error(zathura_error_t* error, zathura_error_t code) { +static void check_set_error(zathura_error_t *error, zathura_error_t code) { if (error != NULL) { *error = code; } } -static bool -hash_file_sha256(uint8_t* dst, const char* path) -{ - FILE* f = fopen(path, "rb"); +static bool hash_file_sha256(uint8_t *dst, const char *path) { + FILE *f = fopen(path, "rb"); if (f == NULL) { return false; } - GChecksum* checksum = g_checksum_new(G_CHECKSUM_SHA256); + GChecksum *checksum = g_checksum_new(G_CHECKSUM_SHA256); if (checksum == NULL) { fclose(f); return false; @@ -97,19 +99,18 @@ hash_file_sha256(uint8_t* dst, const char* path) return true; } -zathura_document_t* -zathura_document_open(zathura_t* zathura, const char* path, const char* uri, - const char* password, zathura_error_t* error) -{ +zathura_document_t *zathura_document_open(zathura_t *zathura, const char *path, + const char *uri, const char *password, + zathura_error_t *error) { if (zathura == NULL || path == NULL) { return NULL; } - GFile* file = g_file_new_for_path(path); - char* real_path = NULL; - char* content_type = NULL; - zathura_plugin_t* plugin = NULL; - zathura_document_t* document = NULL; + GFile *file = g_file_new_for_path(path); + char *real_path = NULL; + char *content_type = NULL; + zathura_plugin_t *plugin = NULL; + zathura_document_t *document = NULL; if (file == NULL) { girara_error("Error while handling path '%s'.", path); @@ -124,19 +125,22 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri, goto error_free; } - content_type = zathura_content_type_guess(zathura->content_type_context, real_path, zathura_plugin_manager_get_content_types(zathura->plugins.manager)); + content_type = zathura_content_type_guess( + zathura->content_type_context, real_path, + zathura_plugin_manager_get_content_types(zathura->plugins.manager)); if (content_type == NULL) { girara_error("Could not determine file type."); check_set_error(error, ZATHURA_ERROR_UNKNOWN); goto error_free; } - plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type); + plugin = + zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type); if (plugin == NULL) { girara_error("Unknown file type: '%s'", content_type); check_set_error(error, ZATHURA_ERROR_UNKNOWN); - g_free((void*)content_type); + g_free((void *)content_type); content_type = NULL; goto error_free; @@ -151,36 +155,37 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri, goto error_free; } - document->file_path = real_path; - document->uri = g_strdup(uri); + document->file_path = real_path; + document->uri = g_strdup(uri); if (document->uri == NULL) { - document->basename = g_file_get_basename(file); + document->basename = g_file_get_basename(file); } else { - GFile*gf = g_file_new_for_uri(document->uri); + GFile *gf = g_file_new_for_uri(document->uri); document->basename = g_file_get_basename(gf); g_object_unref(gf); } hash_file_sha256(document->hash_sha256, document->file_path); - document->password = password; - document->zoom = 1.0; - document->plugin = plugin; + document->password = password; + document->zoom = 1.0; + document->plugin = plugin; document->adjust_mode = ZATHURA_ADJUST_NONE; - document->cell_width = 0.0; + document->cell_width = 0.0; document->cell_height = 0.0; document->view_height = 0; - document->view_width = 0; - document->view_ppi = 0.0; + document->view_width = 0; + document->view_ppi = 0.0; document->device_factors.x = 1.0; document->device_factors.y = 1.0; - document->position_x = 0.0; - document->position_y = 0.0; + document->position_x = 0.0; + document->position_y = 0.0; real_path = NULL; g_object_unref(file); file = NULL; /* open document */ - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(plugin); if (functions->document_open == NULL) { girara_error("plugin has no open function\n"); goto error_free; @@ -194,14 +199,15 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri, } /* read all pages */ - document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); + document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t *)); if (document->pages == NULL) { check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY); goto error_free; } - for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { - zathura_page_t* page = zathura_page_new(document, page_id, NULL); + for (unsigned int page_id = 0; page_id < document->number_of_pages; + page_id++) { + zathura_page_t *page = zathura_page_new(document, page_id, NULL); if (page == NULL) { check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY); goto error_free; @@ -209,7 +215,8 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri, document->pages[page_id] = page; - /* cell_width and cell_height is the maximum of all the pages width and height */ + /* cell_width and cell_height is the maximum of all the pages width and + * height */ const double width = zathura_page_get_width(page); if (document->cell_width < width) document->cell_width = width; @@ -239,16 +246,15 @@ error_free: return NULL; } -zathura_error_t -zathura_document_free(zathura_document_t* document) -{ +zathura_error_t zathura_document_free(zathura_document_t *document) { if (document == NULL || document->plugin == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } if (document->pages != NULL) { /* free pages */ - for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { + for (unsigned int page_id = 0; page_id < document->number_of_pages; + page_id++) { zathura_page_free(document->pages[page_id]); document->pages[page_id] = NULL; } @@ -257,7 +263,8 @@ zathura_document_free(zathura_document_t* document) /* free document */ zathura_error_t error = ZATHURA_ERROR_OK; - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_free == NULL) { error = ZATHURA_ERROR_NOT_IMPLEMENTED; } else { @@ -273,9 +280,7 @@ zathura_document_free(zathura_document_t* document) return error; } -const char* -zathura_document_get_path(zathura_document_t* document) -{ +const char *zathura_document_get_path(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -283,9 +288,7 @@ zathura_document_get_path(zathura_document_t* document) return document->file_path; } -const uint8_t* -zathura_document_get_hash(zathura_document_t* document) -{ +const uint8_t *zathura_document_get_hash(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -293,9 +296,7 @@ zathura_document_get_hash(zathura_document_t* document) return document->hash_sha256; } -const char* -zathura_document_get_uri(zathura_document_t* document) -{ +const char *zathura_document_get_uri(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -303,9 +304,7 @@ zathura_document_get_uri(zathura_document_t* document) return document->uri; } -const char* -zathura_document_get_basename(zathura_document_t* document) -{ +const char *zathura_document_get_basename(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -313,9 +312,7 @@ zathura_document_get_basename(zathura_document_t* document) return document->basename; } -const char* -zathura_document_get_password(zathura_document_t* document) -{ +const char *zathura_document_get_password(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -323,19 +320,17 @@ zathura_document_get_password(zathura_document_t* document) return document->password; } -zathura_page_t* -zathura_document_get_page(zathura_document_t* document, unsigned int index) -{ - if (document == NULL || document->pages == NULL || (document->number_of_pages <= index)) { +zathura_page_t *zathura_document_get_page(zathura_document_t *document, + unsigned int index) { + if (document == NULL || document->pages == NULL || + (document->number_of_pages <= index)) { return NULL; } return document->pages[index]; } -void* -zathura_document_get_data(zathura_document_t* document) -{ +void *zathura_document_get_data(zathura_document_t *document) { if (document == NULL) { return NULL; } @@ -343,9 +338,7 @@ zathura_document_get_data(zathura_document_t* document) return document->data; } -void -zathura_document_set_data(zathura_document_t* document, void* data) -{ +void zathura_document_set_data(zathura_document_t *document, void *data) { if (document == NULL) { return; } @@ -354,8 +347,7 @@ zathura_document_set_data(zathura_document_t* document, void* data) } unsigned int -zathura_document_get_number_of_pages(zathura_document_t* document) -{ +zathura_document_get_number_of_pages(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -363,9 +355,8 @@ zathura_document_get_number_of_pages(zathura_document_t* document) return document->number_of_pages; } -void -zathura_document_set_number_of_pages(zathura_document_t* document, unsigned int number_of_pages) -{ +void zathura_document_set_number_of_pages(zathura_document_t *document, + unsigned int number_of_pages) { if (document == NULL) { return; } @@ -374,8 +365,7 @@ zathura_document_set_number_of_pages(zathura_document_t* document, unsigned int } unsigned int -zathura_document_get_current_page_number(zathura_document_t* document) -{ +zathura_document_get_current_page_number(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -383,10 +373,8 @@ zathura_document_get_current_page_number(zathura_document_t* document) return document->current_page_number; } -void -zathura_document_set_current_page_number(zathura_document_t* document, unsigned int - current_page) -{ +void zathura_document_set_current_page_number(zathura_document_t *document, + unsigned int current_page) { if (document == NULL) { return; } @@ -394,9 +382,7 @@ zathura_document_set_current_page_number(zathura_document_t* document, unsigned document->current_page_number = current_page; } -double -zathura_document_get_position_x(zathura_document_t* document) -{ +double zathura_document_get_position_x(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -404,9 +390,7 @@ zathura_document_get_position_x(zathura_document_t* document) return document->position_x; } -double -zathura_document_get_position_y(zathura_document_t* document) -{ +double zathura_document_get_position_y(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -414,9 +398,8 @@ zathura_document_get_position_y(zathura_document_t* document) return document->position_y; } -void -zathura_document_set_position_x(zathura_document_t* document, double position_x) -{ +void zathura_document_set_position_x(zathura_document_t *document, + double position_x) { if (document == NULL) { return; } @@ -424,9 +407,8 @@ zathura_document_set_position_x(zathura_document_t* document, double position_x) document->position_x = position_x; } -void -zathura_document_set_position_y(zathura_document_t* document, double position_y) -{ +void zathura_document_set_position_y(zathura_document_t *document, + double position_y) { if (document == NULL) { return; } @@ -434,9 +416,7 @@ zathura_document_set_position_y(zathura_document_t* document, double position_y) document->position_y = position_y; } -double -zathura_document_get_zoom(zathura_document_t* document) -{ +double zathura_document_get_zoom(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -444,9 +424,7 @@ zathura_document_get_zoom(zathura_document_t* document) return document->zoom; } -void -zathura_document_set_zoom(zathura_document_t* document, double zoom) -{ +void zathura_document_set_zoom(zathura_document_t *document, double zoom) { if (document == NULL) { return; } @@ -454,9 +432,7 @@ zathura_document_set_zoom(zathura_document_t* document, double zoom) document->zoom = zoom; } -double -zathura_document_get_scale(zathura_document_t* document) -{ +double zathura_document_get_scale(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -471,9 +447,7 @@ zathura_document_get_scale(zathura_document_t* document) return document->zoom * ppi / 72.0; } -unsigned int -zathura_document_get_rotation(zathura_document_t* document) -{ +unsigned int zathura_document_get_rotation(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -481,9 +455,8 @@ zathura_document_get_rotation(zathura_document_t* document) return document->rotate; } -void -zathura_document_set_rotation(zathura_document_t* document, unsigned int rotation) -{ +void zathura_document_set_rotation(zathura_document_t *document, + unsigned int rotation) { if (document == NULL) { return; } @@ -501,8 +474,7 @@ zathura_document_set_rotation(zathura_document_t* document, unsigned int rotatio } zathura_adjust_mode_t -zathura_document_get_adjust_mode(zathura_document_t* document) -{ +zathura_document_get_adjust_mode(zathura_document_t *document) { if (document == NULL) { return ZATHURA_ADJUST_NONE; } @@ -510,9 +482,8 @@ zathura_document_get_adjust_mode(zathura_document_t* document) return document->adjust_mode; } -void -zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mode_t mode) -{ +void zathura_document_set_adjust_mode(zathura_document_t *document, + zathura_adjust_mode_t mode) { if (document == NULL) { return; } @@ -520,9 +491,7 @@ zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mo document->adjust_mode = mode; } -int -zathura_document_get_page_offset(zathura_document_t* document) -{ +int zathura_document_get_page_offset(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -530,9 +499,8 @@ zathura_document_get_page_offset(zathura_document_t* document) return document->page_offset; } -void -zathura_document_set_page_offset(zathura_document_t* document, unsigned int page_offset) -{ +void zathura_document_set_page_offset(zathura_document_t *document, + unsigned int page_offset) { if (document == NULL) { return; } @@ -540,61 +508,53 @@ zathura_document_set_page_offset(zathura_document_t* document, unsigned int page document->page_offset = page_offset; } -void -zathura_document_set_viewport_width(zathura_document_t* document, unsigned int width) -{ +void zathura_document_set_viewport_width(zathura_document_t *document, + unsigned int width) { if (document == NULL) { return; } document->view_width = width; } -void -zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height) -{ +void zathura_document_set_viewport_height(zathura_document_t *document, + unsigned int height) { if (document == NULL) { return; } document->view_height = height; } -void -zathura_document_set_viewport_ppi(zathura_document_t* document, double ppi) -{ +void zathura_document_set_viewport_ppi(zathura_document_t *document, + double ppi) { if (document == NULL) { return; } document->view_ppi = ppi; } -void -zathura_document_get_viewport_size(zathura_document_t* document, - unsigned int *height, unsigned int* width) -{ +void zathura_document_get_viewport_size(zathura_document_t *document, + unsigned int *height, + unsigned int *width) { g_return_if_fail(document != NULL && height != NULL && width != NULL); *height = document->view_height; *width = document->view_width; } -double -zathura_document_get_viewport_ppi(zathura_document_t* document) -{ +double zathura_document_get_viewport_ppi(zathura_document_t *document) { if (document == NULL) { return 0.0; } return document->view_ppi; } -void -zathura_document_set_device_factors(zathura_document_t* document, - double x_factor, double y_factor) -{ +void zathura_document_set_device_factors(zathura_document_t *document, + double x_factor, double y_factor) { if (document == NULL) { return; } if (fabs(x_factor) < DBL_EPSILON || fabs(y_factor) < DBL_EPSILON) { girara_debug("Ignoring new device factors %0.2f and %0.2f: too small", - x_factor, y_factor); + x_factor, y_factor); return; } @@ -603,8 +563,7 @@ zathura_document_set_device_factors(zathura_document_t* document, } zathura_device_factors_t -zathura_document_get_device_factors(zathura_document_t* document) -{ +zathura_document_get_device_factors(zathura_document_t *document) { if (document == NULL) { /* The function is guaranteed to not return zero values */ return (zathura_device_factors_t){1.0, 1.0}; @@ -613,20 +572,17 @@ zathura_document_get_device_factors(zathura_document_t* document) return document->device_factors; } -void -zathura_document_get_cell_size(zathura_document_t* document, - unsigned int* height, unsigned int* width) -{ +void zathura_document_get_cell_size(zathura_document_t *document, + unsigned int *height, unsigned int *width) { g_return_if_fail(document != NULL && height != NULL && width != NULL); page_calc_height_width(document, document->cell_height, document->cell_width, height, width, true); } -void -zathura_document_get_document_size(zathura_document_t* document, - unsigned int* height, unsigned int* width) -{ +void zathura_document_get_document_size(zathura_document_t *document, + unsigned int *height, + unsigned int *width) { g_return_if_fail(document != NULL && height != NULL && width != NULL); const unsigned int npag = zathura_document_get_number_of_pages(document); @@ -636,22 +592,23 @@ zathura_document_get_document_size(zathura_document_t* document, return; } - const unsigned int c0 = zathura_document_get_first_page_column(document); - const unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ - const unsigned int pad = zathura_document_get_page_padding(document); + const unsigned int c0 = zathura_document_get_first_page_column(document); + const unsigned int nrow = + (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ + const unsigned int pad = zathura_document_get_page_padding(document); unsigned int cell_height = 0; - unsigned int cell_width = 0; + unsigned int cell_width = 0; zathura_document_get_cell_size(document, &cell_height, &cell_width); - *width = ncol * cell_width + (ncol - 1) * pad; + *width = ncol * cell_width + (ncol - 1) * pad; *height = nrow * cell_height + (nrow - 1) * pad; } -void -zathura_document_set_page_layout(zathura_document_t* document, unsigned int page_padding, - unsigned int pages_per_row, unsigned int first_page_column) -{ +void zathura_document_set_page_layout(zathura_document_t *document, + unsigned int page_padding, + unsigned int pages_per_row, + unsigned int first_page_column) { g_return_if_fail(document != NULL); document->page_padding = page_padding; @@ -666,18 +623,14 @@ zathura_document_set_page_layout(zathura_document_t* document, unsigned int page document->first_page_column = first_page_column; } -unsigned int -zathura_document_get_page_padding(zathura_document_t* document) -{ +unsigned int zathura_document_get_page_padding(zathura_document_t *document) { if (document == NULL) { return 0; } return document->page_padding; } -unsigned int -zathura_document_get_pages_per_row(zathura_document_t* document) -{ +unsigned int zathura_document_get_pages_per_row(zathura_document_t *document) { if (document == NULL) { return 0; } @@ -685,22 +638,21 @@ zathura_document_get_pages_per_row(zathura_document_t* document) } unsigned int -zathura_document_get_first_page_column(zathura_document_t* document) -{ +zathura_document_get_first_page_column(zathura_document_t *document) { if (document == NULL) { return 0; } return document->first_page_column; } -zathura_error_t -zathura_document_save_as(zathura_document_t* document, const char* path) -{ +zathura_error_t zathura_document_save_as(zathura_document_t *document, + const char *path) { if (document == NULL || document->plugin == NULL || path == NULL) { return ZATHURA_ERROR_UNKNOWN; } - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_save_as == NULL) { return ZATHURA_ERROR_NOT_IMPLEMENTED; } @@ -708,15 +660,16 @@ zathura_document_save_as(zathura_document_t* document, const char* path) return functions->document_save_as(document, document->data, path); } -girara_tree_node_t* -zathura_document_index_generate(zathura_document_t* document, zathura_error_t* error) -{ +girara_tree_node_t * +zathura_document_index_generate(zathura_document_t *document, + zathura_error_t *error) { if (document == NULL || document->plugin == NULL) { check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS); return NULL; } - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_index_generate == NULL) { check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED); return NULL; @@ -725,15 +678,15 @@ zathura_document_index_generate(zathura_document_t* document, zathura_error_t* e return functions->document_index_generate(document, document->data, error); } -girara_list_t* -zathura_document_attachments_get(zathura_document_t* document, zathura_error_t* error) -{ +girara_list_t *zathura_document_attachments_get(zathura_document_t *document, + zathura_error_t *error) { if (document == NULL || document->plugin == NULL) { check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS); return NULL; } - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_attachments_get == NULL) { check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED); return NULL; @@ -742,46 +695,49 @@ zathura_document_attachments_get(zathura_document_t* document, zathura_error_t* return functions->document_attachments_get(document, document->data, error); } -zathura_error_t -zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file) -{ +zathura_error_t zathura_document_attachment_save(zathura_document_t *document, + const char *attachment, + const char *file) { if (document == NULL || document->plugin == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_attachment_save == NULL) { return ZATHURA_ERROR_NOT_IMPLEMENTED; } - return functions->document_attachment_save(document, document->data, attachment, file); + return functions->document_attachment_save(document, document->data, + attachment, file); } -girara_list_t* -zathura_document_get_information(zathura_document_t* document, zathura_error_t* error) -{ +girara_list_t *zathura_document_get_information(zathura_document_t *document, + zathura_error_t *error) { if (document == NULL || document->plugin == NULL) { check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS); return NULL; } - const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin); + const zathura_plugin_functions_t *functions = + zathura_plugin_get_functions(document->plugin); if (functions->document_get_information == NULL) { check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED); return NULL; } - girara_list_t* result = functions->document_get_information(document, document->data, error); + girara_list_t *result = + functions->document_get_information(document, document->data, error); if (result != NULL) { - girara_list_set_free_function(result, (girara_free_function_t) zathura_document_information_entry_free); + girara_list_set_free_function( + result, + (girara_free_function_t)zathura_document_information_entry_free); } return result; } -zathura_plugin_t* -zathura_document_get_plugin(zathura_document_t* document) -{ +zathura_plugin_t *zathura_document_get_plugin(zathura_document_t *document) { if (document == NULL) { return NULL; } diff --git a/zathura/plugin.c b/zathura/plugin.c index 0ccbac5..7b3e754 100644 --- a/zathura/plugin.c +++ b/zathura/plugin.c @@ -336,7 +336,7 @@ zathura_plugin_free(zathura_plugin_t* plugin) if (plugin == NULL) { return; } - + if (plugin->path != NULL) { g_free(plugin->path); } diff --git a/zathura/render.c b/zathura/render.c index b5a1041..5b97552 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -1,22 +1,23 @@ /* SPDX-License-Identifier: Zlib */ -#include -#include #include #include +#include +#include -#include "render.h" #include "adjustment.h" -#include "zathura.h" #include "document.h" -#include "page.h" #include "page-widget.h" +#include "page.h" +#include "render.h" #include "utils.h" +#include "zathura.h" +#include /* private data for ZathuraRenderer */ typedef struct private_s { - GThreadPool* pool; /**< Pool of threads */ - GMutex mutex; /**< Render lock */ + GThreadPool *pool; /**< Pool of threads */ + GMutex mutex; /**< Render lock */ volatile bool about_to_close; /**< Render thread is to be freed */ /** @@ -35,61 +36,60 @@ typedef struct private_s { * page cache */ struct { - int* cache; + int *cache; size_t size; size_t num_cached_pages; } page_cache; /* render requests */ - girara_list_t* requests; + girara_list_t *requests; } ZathuraRendererPrivate; /* private data for ZathuraRenderRequest */ typedef struct request_private_s { - ZathuraRenderer* renderer; - zathura_page_t* page; + ZathuraRenderer *renderer; + zathura_page_t *page; gint64 last_view_time; - girara_list_t* active_jobs; + girara_list_t *active_jobs; GMutex jobs_mutex; bool render_plain; } ZathuraRenderRequestPrivate; /* define the two types */ -G_DEFINE_TYPE_WITH_CODE(ZathuraRenderer, zathura_renderer, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraRenderer)) -G_DEFINE_TYPE_WITH_CODE(ZathuraRenderRequest, zathura_render_request, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraRenderRequest)) +G_DEFINE_TYPE_WITH_CODE(ZathuraRenderer, zathura_renderer, G_TYPE_OBJECT, + G_ADD_PRIVATE(ZathuraRenderer)) +G_DEFINE_TYPE_WITH_CODE(ZathuraRenderRequest, zathura_render_request, + G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraRenderRequest)) /* private methods for ZathuraRenderer */ -static void renderer_finalize(GObject* object); +static void renderer_finalize(GObject *object); /* private methods for ZathuraRenderRequest */ -static void render_request_dispose(GObject* object); -static void render_request_finalize(GObject* object); +static void render_request_dispose(GObject *object); +static void render_request_finalize(GObject *object); -static void render_job(void* data, void* user_data); +static void render_job(void *data, void *user_data); static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data); -static ssize_t page_cache_lru_invalidate(ZathuraRenderer* renderer); -static void page_cache_invalidate_all(ZathuraRenderer* renderer); -static bool page_cache_is_full(ZathuraRenderer* renderer, bool* result); +static ssize_t page_cache_lru_invalidate(ZathuraRenderer *renderer); +static void page_cache_invalidate_all(ZathuraRenderer *renderer); +static bool page_cache_is_full(ZathuraRenderer *renderer, bool *result); /* job descritption for render thread */ typedef struct render_job_s { - ZathuraRenderRequest* request; + ZathuraRenderRequest *request; volatile bool aborted; } render_job_t; /* init, new and free for ZathuraRenderer */ -static void -zathura_renderer_class_init(ZathuraRendererClass* class) -{ +static void zathura_renderer_class_init(ZathuraRendererClass *class) { /* overwrite methods */ - GObjectClass* object_class = G_OBJECT_CLASS(class); - object_class->finalize = renderer_finalize; + GObjectClass *object_class = G_OBJECT_CLASS(class); + object_class->finalize = renderer_finalize; } -static void -zathura_renderer_init(ZathuraRenderer* renderer) -{ - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); +static void zathura_renderer_init(ZathuraRenderer *renderer) { + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); priv->pool = g_thread_pool_new(render_job, renderer, 1, TRUE, NULL); priv->about_to_close = false; g_thread_pool_set_sort_function(priv->pool, render_thread_sort, NULL); @@ -110,12 +110,11 @@ zathura_renderer_init(ZathuraRenderer* renderer) priv->requests = girara_list_new(); } -static bool -page_cache_init(ZathuraRenderer* renderer, size_t cache_size) -{ - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); +static bool page_cache_init(ZathuraRenderer *renderer, size_t cache_size) { + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); - priv->page_cache.size = cache_size; + priv->page_cache.size = cache_size; priv->page_cache.cache = g_try_malloc0(cache_size * sizeof(int)); if (priv->page_cache.cache == NULL) { return false; @@ -125,13 +124,11 @@ page_cache_init(ZathuraRenderer* renderer, size_t cache_size) return true; } -ZathuraRenderer* -zathura_renderer_new(size_t cache_size) -{ +ZathuraRenderer *zathura_renderer_new(size_t cache_size) { g_return_val_if_fail(cache_size > 0, NULL); - GObject* obj = g_object_new(ZATHURA_TYPE_RENDERER, NULL); - ZathuraRenderer* ret = ZATHURA_RENDERER(obj); + GObject *obj = g_object_new(ZATHURA_TYPE_RENDERER, NULL); + ZathuraRenderer *ret = ZATHURA_RENDERER(obj); if (page_cache_init(ret, cache_size) == false) { g_object_unref(obj); @@ -141,11 +138,10 @@ zathura_renderer_new(size_t cache_size) return ret; } -static void -renderer_finalize(GObject* object) -{ - ZathuraRenderer* renderer = ZATHURA_RENDERER(object); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); +static void renderer_finalize(GObject *object) { + ZathuraRenderer *renderer = ZATHURA_RENDERER(object); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); zathura_renderer_stop(renderer); if (priv->pool != NULL) { @@ -159,19 +155,17 @@ renderer_finalize(GObject* object) /* (un)register requests at the renderer */ -static void -renderer_unregister_request(ZathuraRenderer* renderer, - ZathuraRenderRequest* request) -{ - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); +static void renderer_unregister_request(ZathuraRenderer *renderer, + ZathuraRenderRequest *request) { + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); girara_list_remove(priv->requests, request); } -static void -renderer_register_request(ZathuraRenderer* renderer, - ZathuraRenderRequest* request) -{ - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); +static void renderer_register_request(ZathuraRenderer *renderer, + ZathuraRenderRequest *request) { + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); if (girara_list_contains(priv->requests, request) == false) { girara_list_append(priv->requests, request); } @@ -186,68 +180,47 @@ enum { REQUEST_LAST_SIGNAL }; -static guint request_signals[REQUEST_LAST_SIGNAL] = { 0 }; +static guint request_signals[REQUEST_LAST_SIGNAL] = {0}; static void -zathura_render_request_class_init(ZathuraRenderRequestClass* class) -{ +zathura_render_request_class_init(ZathuraRenderRequestClass *class) { /* overwrite methods */ - GObjectClass* object_class = G_OBJECT_CLASS(class); - object_class->dispose = render_request_dispose; - object_class->finalize = render_request_finalize; + GObjectClass *object_class = G_OBJECT_CLASS(class); + object_class->dispose = render_request_dispose; + object_class->finalize = render_request_finalize; - request_signals[REQUEST_COMPLETED] = g_signal_new("completed", - ZATHURA_TYPE_RENDER_REQUEST, - G_SIGNAL_RUN_LAST, - 0, - NULL, - NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); + request_signals[REQUEST_COMPLETED] = g_signal_new( + "completed", ZATHURA_TYPE_RENDER_REQUEST, G_SIGNAL_RUN_LAST, 0, NULL, + NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_POINTER); - request_signals[REQUEST_CACHE_ADDED] = g_signal_new("cache-added", - ZATHURA_TYPE_RENDER_REQUEST, - G_SIGNAL_RUN_LAST, - 0, - NULL, - NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 0); + request_signals[REQUEST_CACHE_ADDED] = g_signal_new( + "cache-added", ZATHURA_TYPE_RENDER_REQUEST, G_SIGNAL_RUN_LAST, 0, NULL, + NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0); - request_signals[REQUEST_CACHE_INVALIDATED] = g_signal_new("cache-invalidated", - ZATHURA_TYPE_RENDER_REQUEST, - G_SIGNAL_RUN_LAST, - 0, - NULL, - NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 0); + request_signals[REQUEST_CACHE_INVALIDATED] = g_signal_new( + "cache-invalidated", ZATHURA_TYPE_RENDER_REQUEST, G_SIGNAL_RUN_LAST, 0, + NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0); } -static void -zathura_render_request_init(ZathuraRenderRequest* request) -{ - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); +static void zathura_render_request_init(ZathuraRenderRequest *request) { + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); priv->renderer = NULL; priv->page = NULL; } -ZathuraRenderRequest* -zathura_render_request_new(ZathuraRenderer* renderer, zathura_page_t* page) -{ +ZathuraRenderRequest *zathura_render_request_new(ZathuraRenderer *renderer, + zathura_page_t *page) { g_return_val_if_fail(renderer != NULL && page != NULL, NULL); - GObject* obj = g_object_new(ZATHURA_TYPE_RENDER_REQUEST, NULL); + GObject *obj = g_object_new(ZATHURA_TYPE_RENDER_REQUEST, NULL); if (obj == NULL) { return NULL; } - ZathuraRenderRequest* request = ZATHURA_RENDER_REQUEST(obj); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequest *request = ZATHURA_RENDER_REQUEST(obj); + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); /* we want to make sure that renderer lives long enough */ priv->renderer = g_object_ref(renderer); priv->page = page; @@ -261,11 +234,10 @@ zathura_render_request_new(ZathuraRenderer* renderer, zathura_page_t* page) return request; } -static void -render_request_dispose(GObject* object) -{ - ZathuraRenderRequest* request = ZATHURA_RENDER_REQUEST(object); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); +static void render_request_dispose(GObject *object) { + ZathuraRenderRequest *request = ZATHURA_RENDER_REQUEST(object); + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); if (priv->renderer != NULL) { /* unregister the request */ @@ -277,11 +249,10 @@ render_request_dispose(GObject* object) G_OBJECT_CLASS(zathura_render_request_parent_class)->dispose(object); } -static void -render_request_finalize(GObject* object) -{ - ZathuraRenderRequest* request = ZATHURA_RENDER_REQUEST(object); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); +static void render_request_finalize(GObject *object) { + ZathuraRenderRequest *request = ZATHURA_RENDER_REQUEST(object); + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); if (girara_list_size(priv->active_jobs) != 0) { girara_error("This should not happen!"); @@ -294,66 +265,62 @@ render_request_finalize(GObject* object) /* renderer methods */ -bool -zathura_renderer_recolor_enabled(ZathuraRenderer* renderer) -{ +bool zathura_renderer_recolor_enabled(ZathuraRenderer *renderer) { g_return_val_if_fail(ZATHURA_IS_RENDERER(renderer), false); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); return priv->recolor.enabled; } -void -zathura_renderer_enable_recolor(ZathuraRenderer* renderer, bool enable) -{ +void zathura_renderer_enable_recolor(ZathuraRenderer *renderer, bool enable) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); priv->recolor.enabled = enable; } -bool -zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer) -{ +bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer *renderer) { g_return_val_if_fail(ZATHURA_IS_RENDERER(renderer), false); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); return priv->recolor.hue; } -void -zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, bool enable) -{ +void zathura_renderer_enable_recolor_hue(ZathuraRenderer *renderer, + bool enable) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); priv->recolor.hue = enable; } -bool -zathura_renderer_recolor_reverse_video_enabled(ZathuraRenderer* renderer) -{ +bool zathura_renderer_recolor_reverse_video_enabled(ZathuraRenderer *renderer) { g_return_val_if_fail(ZATHURA_IS_RENDERER(renderer), false); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); return priv->recolor.reverse_video; } -void -zathura_renderer_enable_recolor_reverse_video(ZathuraRenderer* renderer, bool enable) -{ +void zathura_renderer_enable_recolor_reverse_video(ZathuraRenderer *renderer, + bool enable) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); priv->recolor.reverse_video = enable; } -void -zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer, - const GdkRGBA* light, const GdkRGBA* dark) -{ +void zathura_renderer_set_recolor_colors(ZathuraRenderer *renderer, + const GdkRGBA *light, + const GdkRGBA *dark) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); if (light != NULL) { memcpy(&priv->recolor.light, light, sizeof(GdkRGBA)); } @@ -362,10 +329,9 @@ zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer, } } -void -zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer, - const char* light, const char* dark) -{ +void zathura_renderer_set_recolor_colors_str(ZathuraRenderer *renderer, + const char *light, + const char *dark) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); if (dark != NULL) { @@ -382,13 +348,12 @@ zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer, } } -void -zathura_renderer_get_recolor_colors(ZathuraRenderer* renderer, - GdkRGBA* light, GdkRGBA* dark) -{ +void zathura_renderer_get_recolor_colors(ZathuraRenderer *renderer, + GdkRGBA *light, GdkRGBA *dark) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); if (light != NULL) { memcpy(light, &priv->recolor.light, sizeof(GdkRGBA)); } @@ -397,57 +362,53 @@ zathura_renderer_get_recolor_colors(ZathuraRenderer* renderer, } } -void -zathura_renderer_lock(ZathuraRenderer* renderer) -{ +void zathura_renderer_lock(ZathuraRenderer *renderer) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); g_mutex_lock(&priv->mutex); } -void -zathura_renderer_unlock(ZathuraRenderer* renderer) -{ +void zathura_renderer_unlock(ZathuraRenderer *renderer) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); g_mutex_unlock(&priv->mutex); } -void -zathura_renderer_stop(ZathuraRenderer* renderer) -{ +void zathura_renderer_stop(ZathuraRenderer *renderer) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); priv->about_to_close = true; } - /* ZathuraRenderRequest methods */ -void -zathura_render_request(ZathuraRenderRequest* request, gint64 last_view_time) -{ +void zathura_render_request(ZathuraRenderRequest *request, + gint64 last_view_time) { g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request)); - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); g_mutex_lock(&request_priv->jobs_mutex); bool unfinished_jobs = false; /* check if there are any active jobs left */ - GIRARA_LIST_FOREACH_BODY(request_priv->active_jobs, render_job_t*, job, - if (job->aborted == false) { - unfinished_jobs = true; - break; - } - ); + GIRARA_LIST_FOREACH_BODY( + request_priv->active_jobs, render_job_t *, job, + if (job->aborted == false) { + unfinished_jobs = true; + break; + }); /* only add a new job if there are no active ones left */ if (unfinished_jobs == false) { request_priv->last_view_time = last_view_time; - render_job_t* job = g_try_malloc0(sizeof(render_job_t)); + render_job_t *job = g_try_malloc0(sizeof(render_job_t)); if (job == NULL) { return; } @@ -456,41 +417,38 @@ zathura_render_request(ZathuraRenderRequest* request, gint64 last_view_time) job->aborted = false; girara_list_append(request_priv->active_jobs, job); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(request_priv->renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(request_priv->renderer); g_thread_pool_push(priv->pool, job, NULL); } g_mutex_unlock(&request_priv->jobs_mutex); } -void -zathura_render_request_abort(ZathuraRenderRequest* request) -{ +void zathura_render_request_abort(ZathuraRenderRequest *request) { g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request)); - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); g_mutex_lock(&request_priv->jobs_mutex); - GIRARA_LIST_FOREACH_BODY(request_priv->active_jobs, render_job_t*, job, - job->aborted = true; - ); + GIRARA_LIST_FOREACH_BODY(request_priv->active_jobs, render_job_t *, job, + job->aborted = true;); g_mutex_unlock(&request_priv->jobs_mutex); } -void -zathura_render_request_update_view_time(ZathuraRenderRequest* request) -{ +void zathura_render_request_update_view_time(ZathuraRenderRequest *request) { g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request)); - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); request_priv->last_view_time = g_get_real_time(); } /* render job */ -static void -remove_job_and_free(render_job_t* job) -{ - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(job->request); +static void remove_job_and_free(render_job_t *job) { + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(job->request); g_mutex_lock(&request_priv->jobs_mutex); girara_list_remove(request_priv->active_jobs, job); @@ -500,28 +458,28 @@ remove_job_and_free(render_job_t* job) g_free(job); } -typedef struct emit_completed_signal_s -{ - render_job_t* job; - cairo_surface_t* surface; +typedef struct emit_completed_signal_s { + render_job_t *job; + cairo_surface_t *surface; } emit_completed_signal_t; -static gboolean -emit_completed_signal(void* data) -{ - emit_completed_signal_t* ecs = data; - render_job_t* job = ecs->job; - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(job->request); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(request_priv->renderer); +static gboolean emit_completed_signal(void *data) { + emit_completed_signal_t *ecs = data; + render_job_t *job = ecs->job; + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(job->request); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(request_priv->renderer); if (priv->about_to_close == false && job->aborted == false) { /* emit the signal */ girara_debug("Emitting signal for page %d", - zathura_page_get_index(request_priv->page) + 1); - g_signal_emit(job->request, request_signals[REQUEST_COMPLETED], 0, ecs->surface); + zathura_page_get_index(request_priv->page) + 1); + g_signal_emit(job->request, request_signals[REQUEST_COMPLETED], 0, + ecs->surface); } else { girara_debug("Rendering of page %d aborted", - zathura_page_get_index(request_priv->page) + 1); + zathura_page_get_index(request_priv->page) + 1); } /* mark the request as done */ remove_job_and_free(job); @@ -536,37 +494,37 @@ emit_completed_signal(void* data) /* Returns the maximum possible saturation for given h and l. Assumes that l is in the interval l1, l2 and corrects the value to force u=0 on l1 and l2 */ -static double -colorumax(const double h[3], double l, double l1, double l2) -{ - if (fabs(h[0]) <= DBL_EPSILON && fabs(h[1]) <= DBL_EPSILON && fabs(h[2]) <= DBL_EPSILON) { +static double colorumax(const double h[3], double l, double l1, double l2) { + if (fabs(h[0]) <= DBL_EPSILON && fabs(h[1]) <= DBL_EPSILON && + fabs(h[2]) <= DBL_EPSILON) { return 0; } - const double lv = (l - l1) / (l2 - l1); /* Remap l to the whole interval [0,1] */ + const double lv = + (l - l1) / (l2 - l1); /* Remap l to the whole interval [0,1] */ double u = DBL_MAX; double v = DBL_MAX; for (unsigned int k = 0; k < 3; ++k) { if (h[k] > DBL_EPSILON) { - u = fmin(fabs((1-l)/h[k]), u); - v = fmin(fabs((1-lv)/h[k]), v); + u = fmin(fabs((1 - l) / h[k]), u); + v = fmin(fabs((1 - lv) / h[k]), v); } else if (h[k] < -DBL_EPSILON) { - u = fmin(fabs(l/h[k]), u); - v = fmin(fabs(lv/h[k]), v); + u = fmin(fabs(l / h[k]), u); + v = fmin(fabs(lv / h[k]), v); } } /* rescale v according to the length of the interval [l1, l2] */ v = fabs(l2 - l1) * v; - /* forces the returned value to be 0 on l1 and l2, trying not to distort colors too much */ + /* forces the returned value to be 0 on l1 and l2, trying not to distort + * colors too much */ return fmin(u, v); } -static void -recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_width, - unsigned int page_height, cairo_surface_t* surface) -{ +static void recolor(ZathuraRendererPrivate *priv, zathura_page_t *page, + unsigned int page_width, unsigned int page_height, + cairo_surface_t *surface) { /* uses a representation of a rgb color as follows: - a lightness scalar (between 0,1), which is a weighted average of r, g, b, - a hue vector, which indicates a radian direction from the grey axis, @@ -583,8 +541,8 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi cairo_surface_flush(surface); - const int rowstride = cairo_image_surface_get_stride(surface); - unsigned char* image = cairo_image_surface_get_data(surface); + const int rowstride = cairo_image_surface_get_stride(surface); + unsigned char *image = cairo_image_surface_get_data(surface); /* RGB weights for computing lightness. Must sum to one */ static const double a[] = {0.30, 0.59, 0.11}; @@ -592,38 +550,37 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi const GdkRGBA rgb1 = priv->recolor.dark; const GdkRGBA rgb2 = priv->recolor.light; - const double l1 = a[0]*rgb1.red + a[1]*rgb1.green + a[2]*rgb1.blue; - const double l2 = a[0]*rgb2.red + a[1]*rgb2.green + a[2]*rgb2.blue; + const double l1 = a[0] * rgb1.red + a[1] * rgb1.green + a[2] * rgb1.blue; + const double l2 = a[0] * rgb2.red + a[1] * rgb2.green + a[2] * rgb2.blue; const double negalph1 = 1. - rgb1.alpha; const double negalph2 = 1. - rgb2.alpha; - const double rgb_diff[] = { - rgb2.red - rgb1.red, - rgb2.green - rgb1.green, - rgb2.blue - rgb1.blue - }; + const double rgb_diff[] = {rgb2.red - rgb1.red, rgb2.green - rgb1.green, + rgb2.blue - rgb1.blue}; const double h1[3] = { - rgb1.red*rgb1.alpha - l1, - rgb1.green*rgb1.alpha - l1, - rgb1.blue*rgb1.alpha - l1, + rgb1.red * rgb1.alpha - l1, + rgb1.green * rgb1.alpha - l1, + rgb1.blue * rgb1.alpha - l1, }; const double h2[3] = { - rgb2.red*rgb2.alpha - l2, - rgb2.green*rgb2.alpha - l2, - rgb2.blue*rgb2.alpha - l2, + rgb2.red * rgb2.alpha - l2, + rgb2.green * rgb2.alpha - l2, + rgb2.blue * rgb2.alpha - l2, }; /* Decide if we can use the older, faster formulas */ - const bool fast_formula = (!priv->recolor.hue || ( - fabs(rgb1.red - rgb1.blue) < DBL_EPSILON && fabs(rgb1.red - rgb1.green) < DBL_EPSILON && - fabs(rgb2.red - rgb2.blue) < DBL_EPSILON && fabs(rgb2.red - rgb2.green) < DBL_EPSILON - )) && (rgb1.alpha >= 1. - DBL_EPSILON && rgb2.alpha >= 1. - DBL_EPSILON); + const bool fast_formula = + (!priv->recolor.hue || (fabs(rgb1.red - rgb1.blue) < DBL_EPSILON && + fabs(rgb1.red - rgb1.green) < DBL_EPSILON && + fabs(rgb2.red - rgb2.blue) < DBL_EPSILON && + fabs(rgb2.red - rgb2.green) < DBL_EPSILON)) && + (rgb1.alpha >= 1. - DBL_EPSILON && rgb2.alpha >= 1. - DBL_EPSILON); - girara_list_t* images = NULL; - girara_list_t* rectangles = NULL; - bool found_images = false; + girara_list_t *images = NULL; + girara_list_t *rectangles = NULL; + bool found_images = false; /* If in reverse video mode retrieve images */ if (priv->recolor.reverse_video == true) { @@ -638,31 +595,29 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi if (found_images == true) { /* Get images bounding boxes */ - GIRARA_LIST_FOREACH_BODY(images, zathura_image_t*, image_it, - zathura_rectangle_t* rect = g_try_malloc(sizeof(zathura_rectangle_t)); - if (rect == NULL) { - break; - } - *rect = recalc_rectangle(page, image_it->position); - girara_list_append(rectangles, rect); - ); + GIRARA_LIST_FOREACH_BODY( + images, zathura_image_t *, image_it, + zathura_rectangle_t *rect = g_try_malloc(sizeof(zathura_rectangle_t)); + if (rect == NULL) { break; } *rect = + recalc_rectangle(page, image_it->position); + girara_list_append(rectangles, rect);); } } for (unsigned int y = 0; y < page_height; y++) { - unsigned char* data = image + y * rowstride; + unsigned char *data = image + y * rowstride; for (unsigned int x = 0; x < page_width; x++, data += 4) { /* Check if the pixel belongs to an image when in reverse video mode*/ - if (priv->recolor.reverse_video == true && found_images == true){ + if (priv->recolor.reverse_video == true && found_images == true) { bool inside_image = false; - GIRARA_LIST_FOREACH_BODY(rectangles, zathura_rectangle_t*, rect_it, - if (rect_it->x1 <= x && rect_it->x2 >= x && - rect_it->y1 <= y && rect_it->y2 >= y) { - inside_image = true; - break; - } - ); + GIRARA_LIST_FOREACH_BODY( + rectangles, zathura_rectangle_t *, rect_it, + if (rect_it->x1 <= x && rect_it->x2 >= x && rect_it->y1 <= y && + rect_it->y2 >= y) { + inside_image = true; + break; + }); /* If it's inside and image don't recolor */ if (inside_image == true) { /* It is not guaranteed that the pixel is already opaque. */ @@ -672,23 +627,15 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi } /* Careful. data color components blue, green, red. */ - const double rgb[3] = { - data[2] / 255., - data[1] / 255., - data[0] / 255. - }; + const double rgb[3] = {data[2] / 255., data[1] / 255., data[0] / 255.}; /* compute h, s, l data */ - double l = a[0]*rgb[0] + a[1]*rgb[1] + a[2]*rgb[2]; + double l = a[0] * rgb[0] + a[1] * rgb[1] + a[2] * rgb[2]; if (priv->recolor.hue == true) { /* adjusting lightness keeping hue of current color. white and black * go to grays of same ligtness as light and dark colors. */ - const double h[3] = { - rgb[0] - l, - rgb[1] - l, - rgb[2] - l - }; + const double h[3] = {rgb[0] - l, rgb[1] - l, rgb[2] - l}; /* u is the maximum possible saturation for given h and l. s is a * rescaled saturation between 0 and 1 */ @@ -703,34 +650,45 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi if (fast_formula) { data[3] = 255; - data[2] = (unsigned char)round(255.*(l + su * h[0])); - data[1] = (unsigned char)round(255.*(l + su * h[1])); - data[0] = (unsigned char)round(255.*(l + su * h[2])); + data[2] = (unsigned char)round(255. * (l + su * h[0])); + data[1] = (unsigned char)round(255. * (l + su * h[1])); + data[0] = (unsigned char)round(255. * (l + su * h[2])); } else { /* Mix lightcolor, darkcolor and the original color, according to the * minimal and maximal channel of the original color */ const double tr1 = (1. - fmax(fmax(rgb[0], rgb[1]), rgb[2])); const double tr2 = fmin(fmin(rgb[0], rgb[1]), rgb[2]); - data[3] = (unsigned char)round(255.*(1. - tr1*negalph1 - tr2*negalph2)); - data[2] = (unsigned char)round(255.*fmin(1, fmax(0, tr1*h1[0] + tr2*h2[0] + (l + su * h[0])))); - data[1] = (unsigned char)round(255.*fmin(1, fmax(0, tr1*h1[1] + tr2*h2[1] + (l + su * h[1])))); - data[0] = (unsigned char)round(255.*fmin(1, fmax(0, tr1*h1[2] + tr2*h2[2] + (l + su * h[2])))); + data[3] = (unsigned char)round( + 255. * (1. - tr1 * negalph1 - tr2 * negalph2)); + data[2] = (unsigned char)round( + 255. * + fmin(1, fmax(0, tr1 * h1[0] + tr2 * h2[0] + (l + su * h[0])))); + data[1] = (unsigned char)round( + 255. * + fmin(1, fmax(0, tr1 * h1[1] + tr2 * h2[1] + (l + su * h[1])))); + data[0] = (unsigned char)round( + 255. * + fmin(1, fmax(0, tr1 * h1[2] + tr2 * h2[2] + (l + su * h[2])))); } } else { /* linear interpolation between dark and light with color ligtness as * a parameter */ if (fast_formula) { data[3] = 255; - data[2] = (unsigned char)round(255.*(l * rgb_diff[0] + rgb1.red)); - data[1] = (unsigned char)round(255.*(l * rgb_diff[1] + rgb1.green)); - data[0] = (unsigned char)round(255.*(l * rgb_diff[2] + rgb1.blue)); + data[2] = (unsigned char)round(255. * (l * rgb_diff[0] + rgb1.red)); + data[1] = (unsigned char)round(255. * (l * rgb_diff[1] + rgb1.green)); + data[0] = (unsigned char)round(255. * (l * rgb_diff[2] + rgb1.blue)); } else { - const double f1 = 1. - (1. - fmax(fmax(rgb[0], rgb[1]), rgb[2]))*negalph1; - const double f2 = fmin(fmin(rgb[0], rgb[1]), rgb[2])*negalph2; - data[3] = (unsigned char)round(255.*(f1 - f2)); - data[2] = (unsigned char)round(255.*(l * rgb_diff[0] - f2*rgb2.red + f1*rgb1.red)); - data[1] = (unsigned char)round(255.*(l * rgb_diff[1] - f2*rgb2.green + f1*rgb1.green)); - data[0] = (unsigned char)round(255.*(l * rgb_diff[2] - f2*rgb2.blue + f1*rgb1.blue)); + const double f1 = + 1. - (1. - fmax(fmax(rgb[0], rgb[1]), rgb[2])) * negalph1; + const double f2 = fmin(fmin(rgb[0], rgb[1]), rgb[2]) * negalph2; + data[3] = (unsigned char)round(255. * (f1 - f2)); + data[2] = (unsigned char)round( + 255. * (l * rgb_diff[0] - f2 * rgb2.red + f1 * rgb1.red)); + data[1] = (unsigned char)round( + 255. * (l * rgb_diff[1] - f2 * rgb2.green + f1 * rgb1.green)); + data[0] = (unsigned char)round( + 255. * (l * rgb_diff[2] - f2 * rgb2.blue + f1 * rgb1.blue)); } } } @@ -746,15 +704,14 @@ recolor(ZathuraRendererPrivate* priv, zathura_page_t* page, unsigned int page_wi cairo_surface_mark_dirty(surface); } -static bool -invoke_completed_signal(render_job_t* job, cairo_surface_t* surface) -{ - emit_completed_signal_t* ecs = g_try_malloc0(sizeof(emit_completed_signal_t)); +static bool invoke_completed_signal(render_job_t *job, + cairo_surface_t *surface) { + emit_completed_signal_t *ecs = g_try_malloc0(sizeof(emit_completed_signal_t)); if (ecs == NULL) { return false; } - ecs->job = job; + ecs->job = job; ecs->surface = cairo_surface_reference(surface); /* emit signal from the main context, i.e. the main thread */ @@ -762,10 +719,11 @@ invoke_completed_signal(render_job_t* job, cairo_surface_t* surface) return true; } -static bool -render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraRenderer* renderer, double real_scale) -{ - cairo_t* cairo = cairo_create(surface); +static bool render_to_cairo_surface(cairo_surface_t *surface, + zathura_page_t *page, + ZathuraRenderer *renderer, + double real_scale) { + cairo_t *cairo = cairo_create(surface); if (cairo == NULL) { return false; } @@ -790,30 +748,36 @@ render_to_cairo_surface(cairo_surface_t* surface, zathura_page_t* page, ZathuraR return err == ZATHURA_ERROR_OK; } -static bool -render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* renderer) -{ - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); - zathura_page_t* page = request_priv->page; +static bool render(render_job_t *job, ZathuraRenderRequest *request, + ZathuraRenderer *renderer) { + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); + zathura_page_t *page = request_priv->page; /* create cairo surface */ - unsigned int page_width = 0; + unsigned int page_width = 0; unsigned int page_height = 0; /* page size in points */ - zathura_document_t* document = zathura_page_get_document(page); + zathura_document_t *document = zathura_page_get_document(page); const double height = zathura_page_get_height(page); const double width = zathura_page_get_width(page); - zathura_device_factors_t device_factors = { 0 }; + // @debug + fprintf(stderr, "height %f\n", height); + fprintf(stderr, "width %f\n", width); + // @ + + zathura_device_factors_t device_factors = {0}; double real_scale = 1; if (request_priv->render_plain == false) { /* page size in user pixels based on document zoom: if PPI information is * correct, 100% zoom will result in 72 documents points per inch of screen * (i.e. document size on screen matching the physical paper size). */ - real_scale = page_calc_height_width(document, height, width, - &page_height, &page_width, false); + real_scale = page_calc_height_width(document, height, width, &page_height, + &page_width, false); device_factors = zathura_document_get_device_factors(document); page_width *= device_factors.x; @@ -826,12 +790,11 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render cairo_format_t format; if (priv->recolor.enabled) { format = CAIRO_FORMAT_ARGB32; - } - else { + } else { format = CAIRO_FORMAT_RGB24; } - cairo_surface_t* surface = cairo_image_surface_create(format, - page_width, page_height); + cairo_surface_t *surface = + cairo_image_surface_create(format, page_width, page_height); if (surface == NULL) { return false; @@ -876,52 +839,52 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render return true; } -static void -render_job(void* data, void* user_data) -{ - render_job_t* job = data; - ZathuraRenderRequest* request = job->request; - ZathuraRenderer* renderer = user_data; +static void render_job(void *data, void *user_data) { + render_job_t *job = data; + ZathuraRenderRequest *request = job->request; + ZathuraRenderer *renderer = user_data; g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request)); g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); if (priv->about_to_close == true || job->aborted == true) { /* back out early */ remove_job_and_free(job); return; } - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); girara_debug("Rendering page %d ...", - zathura_page_get_index(request_priv->page) + 1); + zathura_page_get_index(request_priv->page) + 1); if (render(job, request, renderer) != true) { girara_error("Rendering failed (page %d)\n", - zathura_page_get_index(request_priv->page) + 1); + zathura_page_get_index(request_priv->page) + 1); remove_job_and_free(job); } } - -void -render_all(zathura_t* zathura) -{ +void render_all(zathura_t *zathura) { if (zathura == NULL || zathura->document == NULL) { return; } /* unmark all pages */ - const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); + const unsigned int number_of_pages = + zathura_document_get_number_of_pages(zathura->document); for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) { - zathura_page_t* page = zathura_document_get_page(zathura->document, - page_id); + zathura_page_t *page = + zathura_document_get_page(zathura->document, page_id); unsigned int page_height = 0, page_width = 0; const double height = zathura_page_get_height(page); const double width = zathura_page_get_width(page); - page_calc_height_width(zathura->document, height, width, &page_height, &page_width, true); + page_calc_height_width(zathura->document, height, width, &page_height, + &page_width, true); - girara_debug("Queuing resize for page %u to %u x %u (%0.2f x %0.2f).", page_id, page_width, page_height, width, height); - GtkWidget* widget = zathura_page_get_widget(zathura, page); + girara_debug("Queuing resize for page %u to %u x %u (%0.2f x %0.2f).", + page_id, page_width, page_height, width, height); + GtkWidget *widget = zathura_page_get_widget(zathura, page); if (widget != NULL) { gtk_widget_set_size_request(widget, page_width, page_height); gtk_widget_queue_resize(widget); @@ -929,21 +892,23 @@ render_all(zathura_t* zathura) } } -static gint -render_thread_sort(gconstpointer a, gconstpointer b, gpointer UNUSED(data)) -{ +static gint render_thread_sort(gconstpointer a, gconstpointer b, + gpointer UNUSED(data)) { if (a == NULL || b == NULL) { return 0; } - const render_job_t* job_a = a; - const render_job_t* job_b = b; + const render_job_t *job_a = a; + const render_job_t *job_b = b; if (job_a->aborted == job_b->aborted) { - ZathuraRenderRequestPrivate* priv_a = zathura_render_request_get_instance_private(job_a->request); - ZathuraRenderRequestPrivate* priv_b = zathura_render_request_get_instance_private(job_b->request); + ZathuraRenderRequestPrivate *priv_a = + zathura_render_request_get_instance_private(job_a->request); + ZathuraRenderRequestPrivate *priv_b = + zathura_render_request_get_instance_private(job_b->request); - return priv_a->last_view_time < priv_b->last_view_time ? -1 : - (priv_a->last_view_time > priv_b->last_view_time ? 1 : 0); + return priv_a->last_view_time < priv_b->last_view_time + ? -1 + : (priv_a->last_view_time > priv_b->last_view_time ? 1 : 0); } /* sort aborted entries earlier so that they are thrown out of the queue */ @@ -952,11 +917,11 @@ render_thread_sort(gconstpointer a, gconstpointer b, gpointer UNUSED(data)) /* cache functions */ -static bool -page_cache_is_cached(ZathuraRenderer* renderer, unsigned int page_index) -{ +static bool page_cache_is_cached(ZathuraRenderer *renderer, + unsigned int page_index) { g_return_val_if_fail(renderer != NULL, false); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); if (priv->page_cache.num_cached_pages != 0) { for (size_t i = 0; i < priv->page_cache.size; ++i) { @@ -972,34 +937,33 @@ page_cache_is_cached(ZathuraRenderer* renderer, unsigned int page_index) return false; } -static int -find_request_by_page_index(const void* req, const void* data) -{ - ZathuraRenderRequest* request = (void*) req; - const unsigned int page_index = *((const int*)data); +static int find_request_by_page_index(const void *req, const void *data) { + ZathuraRenderRequest *request = (void *)req; + const unsigned int page_index = *((const int *)data); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); if (zathura_page_get_index(priv->page) == page_index) { return 0; } return 1; } -static ssize_t -page_cache_lru_invalidate(ZathuraRenderer* renderer) -{ +static ssize_t page_cache_lru_invalidate(ZathuraRenderer *renderer) { g_return_val_if_fail(renderer != NULL, -1); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); g_return_val_if_fail(priv->page_cache.size != 0, -1); ssize_t lru_index = 0; gint64 lru_view_time = G_MAXINT64; - ZathuraRenderRequest* request = NULL; + ZathuraRenderRequest *request = NULL; for (size_t i = 0; i < priv->page_cache.size; ++i) { - ZathuraRenderRequest* tmp_request = girara_list_find(priv->requests, - find_request_by_page_index, &priv->page_cache.cache[i]); + ZathuraRenderRequest *tmp_request = girara_list_find( + priv->requests, find_request_by_page_index, &priv->page_cache.cache[i]); g_return_val_if_fail(tmp_request != NULL, -1); - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(tmp_request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(tmp_request); if (request_priv->last_view_time < lru_view_time) { lru_view_time = request_priv->last_view_time; @@ -1008,51 +972,49 @@ page_cache_lru_invalidate(ZathuraRenderer* renderer) } } - ZathuraRenderRequestPrivate* request_priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *request_priv = + zathura_render_request_get_instance_private(request); /* emit the signal */ g_signal_emit(request, request_signals[REQUEST_CACHE_INVALIDATED], 0); girara_debug("Invalidated page %d at cache index %zd", - zathura_page_get_index(request_priv->page) + 1, lru_index); + zathura_page_get_index(request_priv->page) + 1, lru_index); priv->page_cache.cache[lru_index] = -1; --priv->page_cache.num_cached_pages; return lru_index; } -static bool -page_cache_is_full(ZathuraRenderer* renderer, bool* result) -{ +static bool page_cache_is_full(ZathuraRenderer *renderer, bool *result) { g_return_val_if_fail(ZATHURA_IS_RENDERER(renderer) && result != NULL, false); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); *result = priv->page_cache.num_cached_pages == priv->page_cache.size; return true; } -static void -page_cache_invalidate_all(ZathuraRenderer* renderer) -{ +static void page_cache_invalidate_all(ZathuraRenderer *renderer) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); for (size_t i = 0; i < priv->page_cache.size; ++i) { priv->page_cache.cache[i] = -1; } priv->page_cache.num_cached_pages = 0; } -void -zathura_renderer_page_cache_add(ZathuraRenderer* renderer, - unsigned int page_index) -{ +void zathura_renderer_page_cache_add(ZathuraRenderer *renderer, + unsigned int page_index) { g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); if (page_cache_is_cached(renderer, page_index) == true) { return; } - ZathuraRendererPrivate* priv = zathura_renderer_get_instance_private(renderer); + ZathuraRendererPrivate *priv = + zathura_renderer_get_instance_private(renderer); bool full = false; if (page_cache_is_full(renderer, &full) == false) { return; @@ -1068,30 +1030,28 @@ zathura_renderer_page_cache_add(ZathuraRenderer* renderer, } else { priv->page_cache.cache[priv->page_cache.num_cached_pages++] = page_index; girara_debug("Page %d is cached at cache index %zu", page_index + 1, - priv->page_cache.num_cached_pages - 1); + priv->page_cache.num_cached_pages - 1); } - ZathuraRenderRequest* request = girara_list_find(priv->requests, - find_request_by_page_index, &page_index); + ZathuraRenderRequest *request = + girara_list_find(priv->requests, find_request_by_page_index, &page_index); g_return_if_fail(request != NULL); g_signal_emit(request, request_signals[REQUEST_CACHE_ADDED], 0); } -void zathura_render_request_set_render_plain(ZathuraRenderRequest* request, - bool render_plain) -{ +void zathura_render_request_set_render_plain(ZathuraRenderRequest *request, + bool render_plain) { g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request)); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); - priv->render_plain =render_plain; + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); + priv->render_plain = render_plain; } -bool -zathura_render_request_get_render_plain(ZathuraRenderRequest* request) -{ +bool zathura_render_request_get_render_plain(ZathuraRenderRequest *request) { g_return_val_if_fail(ZATHURA_IS_RENDER_REQUEST(request), false); - ZathuraRenderRequestPrivate* priv = zathura_render_request_get_instance_private(request); + ZathuraRenderRequestPrivate *priv = + zathura_render_request_get_instance_private(request); return priv->render_plain; } - diff --git a/zathura/synctex.c b/zathura/synctex.c index fb442ed..9b5d68e 100644 --- a/zathura/synctex.c +++ b/zathura/synctex.c @@ -204,7 +204,7 @@ synctex_rectangles_from_position(const char* filename, const char* input_file, girara_list_t* hitlist_flat = flatten_rectangles(hitlist); girara_list_free(hitlist); - + return hitlist_flat; } #else diff --git a/zathura/zathura.c b/zathura/zathura.c index 4185ff1..a9ca282 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -1,75 +1,74 @@ /* SPDX-License-Identifier: Zlib */ #include -#include #include +#include #include +// @debug +#include #include -#include #include -#include #include #include +#include #include -#include +#include #include +#include #ifdef GDK_WINDOWING_WAYLAND #include #endif #ifdef G_OS_UNIX -#include #include +#include #endif #include "bookmarks.h" #include "callbacks.h" -#include "config.h" #include "commands.h" +#include "config.h" #ifdef WITH_SQLITE #include "database-sqlite.h" #endif -#include "database-plain.h" -#include "document.h" -#include "shortcuts.h" -#include "zathura.h" -#include "utils.h" -#include "marks.h" -#include "render.h" -#include "page.h" -#include "page-widget.h" -#include "plugin.h" #include "adjustment.h" -#include "dbus-interface.h" -#include "resources.h" -#include "synctex.h" #include "content-type.h" +#include "database-plain.h" +#include "dbus-interface.h" +#include "document.h" +#include "marks.h" +#include "page-widget.h" +#include "page.h" +#include "plugin.h" +#include "render.h" +#include "resources.h" +#include "shortcuts.h" +#include "synctex.h" +#include "utils.h" +#include "zathura.h" #ifdef WITH_SECCOMP #include "seccomp-filters.h" #endif typedef struct zathura_document_info_s { - zathura_t* zathura; - char* path; - char* password; + zathura_t *zathura; + char *path; + char *password; int page_number; - char* mode; - char* synctex; - char* search_string; + char *mode; + char *synctex; + char *search_string; } zathura_document_info_t; - static gboolean document_info_open(gpointer data); #ifdef G_OS_UNIX static gboolean zathura_signal_sigterm(gpointer data); #endif -static void -free_document_info(zathura_document_info_t* document_info) -{ +static void free_document_info(zathura_document_info_t *document_info) { if (document_info == NULL) { return; } @@ -83,10 +82,8 @@ free_document_info(zathura_document_info_t* document_info) } /* function implementation */ -zathura_t* -zathura_create(void) -{ - zathura_t* zathura = g_try_malloc0(sizeof(zathura_t)); +zathura_t *zathura_create(void) { + zathura_t *zathura = g_try_malloc0(sizeof(zathura_t)); if (zathura == NULL) { return NULL; } @@ -112,7 +109,8 @@ zathura_create(void) #ifdef G_OS_UNIX /* signal handler */ - zathura->signals.sigterm = g_unix_signal_add(SIGTERM, zathura_signal_sigterm, zathura); + zathura->signals.sigterm = + g_unix_signal_add(SIGTERM, zathura_signal_sigterm, zathura); #endif /* MIME type detection */ @@ -129,9 +127,7 @@ error_out: return NULL; } -static void -create_directories(zathura_t* zathura) -{ +static void create_directories(zathura_t *zathura) { static const unsigned int mode = 0700; if (g_mkdir_with_parents(zathura->config.data_dir, mode) == -1) { @@ -140,26 +136,25 @@ create_directories(zathura_t* zathura) } } -void -zathura_update_view_ppi(zathura_t* zathura) -{ +void zathura_update_view_ppi(zathura_t *zathura) { if (zathura == NULL) { return; } /* get view widget GdkMonitor */ - GdkWindow* window = gtk_widget_get_window(zathura->ui.session->gtk.view); // NULL if not realized + GdkWindow *window = gtk_widget_get_window( + zathura->ui.session->gtk.view); // NULL if not realized if (window == NULL) { return; } - GdkDisplay* display = gtk_widget_get_display(zathura->ui.session->gtk.view); + GdkDisplay *display = gtk_widget_get_display(zathura->ui.session->gtk.view); if (display == NULL) { return; } double ppi = 0.0; - GdkMonitor* monitor = gdk_display_get_monitor_at_window(display, window); + GdkMonitor *monitor = gdk_display_get_monitor_at_window(display, window); if (monitor == NULL) { return; } @@ -182,21 +177,24 @@ zathura_update_view_ppi(zathura_t* zathura) /* work around apparent bug in GDK: on Wayland, monitor geometry doesn't * return values in application pixels as documented, but in device pixels. * */ - if (GDK_IS_WAYLAND_DISPLAY(display)) - { + if (GDK_IS_WAYLAND_DISPLAY(display)) { /* not using the cached value for the scale factor here to avoid issues * if this function is called before the cached value is updated */ - const int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); - girara_debug("on Wayland, correcting PPI for device scale factor = %d", device_factor); + const int device_factor = + gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); + girara_debug("on Wayland, correcting PPI for device scale factor = %d", + device_factor); if (device_factor != 0) { ppi /= device_factor; } } #endif - const double current_ppi = zathura_document_get_viewport_ppi(zathura->document); + const double current_ppi = + zathura_document_get_viewport_ppi(zathura->document); if (fabs(ppi - current_ppi) > DBL_EPSILON) { - girara_debug("monitor width: %d mm, pixels: %d, ppi: %0.2f", width_mm, monitor_geom.width, ppi); + girara_debug("monitor width: %d mm, pixels: %d, ppi: %0.2f", width_mm, + monitor_geom.width, ppi); zathura_document_set_viewport_ppi(zathura->document, ppi); adjust_view(zathura); render_all(zathura); @@ -204,34 +202,33 @@ zathura_update_view_ppi(zathura_t* zathura) } } -static bool -init_ui(zathura_t* zathura) -{ +static bool init_ui(zathura_t *zathura) { if (girara_session_init(zathura->ui.session, "zathura") == false) { girara_error("Failed to initialize girara."); return false; } /* girara events */ - zathura->ui.session->events.buffer_changed = cb_buffer_changed; + zathura->ui.session->events.buffer_changed = cb_buffer_changed; zathura->ui.session->events.unknown_command = cb_unknown_command; /* zathura signals */ zathura->signals.refresh_view = g_signal_new( - "refresh-view", GTK_TYPE_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_POINTER); + "refresh-view", GTK_TYPE_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_POINTER); g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view", G_CALLBACK(cb_refresh_view), zathura); g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), - "notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura); + "notify::scale-factor", G_CALLBACK(cb_scale_factor), + zathura); - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), - "screen-changed", G_CALLBACK(cb_widget_screen_changed), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "screen-changed", + G_CALLBACK(cb_widget_screen_changed), zathura); - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), - "configure-event", G_CALLBACK(cb_widget_configured), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "configure-event", + G_CALLBACK(cb_widget_configured), zathura); /* initialize the screen-changed handler to 0 (i.e. invalid) */ zathura->signals.monitors_changed_handler = 0; @@ -248,8 +245,8 @@ init_ui(zathura_t* zathura) g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "size-allocate", G_CALLBACK(cb_view_resized), zathura); - GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment( - GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + GtkAdjustment *hadjustment = gtk_scrolled_window_get_hadjustment( + GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); /* Connect hadjustment signals */ g_signal_connect(G_OBJECT(hadjustment), "value-changed", @@ -257,8 +254,8 @@ init_ui(zathura_t* zathura) g_signal_connect(G_OBJECT(hadjustment), "changed", G_CALLBACK(cb_view_hadjustment_changed), zathura); - GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment( + GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); /* Connect vadjustment signals */ g_signal_connect(G_OBJECT(vadjustment), "value-changed", @@ -279,21 +276,21 @@ init_ui(zathura_t* zathura) /* statusbar */ zathura->ui.statusbar.file = - girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); + girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); if (zathura->ui.statusbar.file == NULL) { girara_error("Failed to create status bar item."); return false; } zathura->ui.statusbar.buffer = - girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); if (zathura->ui.statusbar.buffer == NULL) { girara_error("Failed to create status bar item."); return false; } zathura->ui.statusbar.page_number = - girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); if (zathura->ui.statusbar.page_number == NULL) { girara_error("Failed to create status bar item."); return false; @@ -309,42 +306,36 @@ init_ui(zathura_t* zathura) return true; } -static bool -init_css(zathura_t* zathura) -{ - GiraraTemplate* csstemplate = - girara_session_get_template(zathura->ui.session); +static bool init_css(zathura_t *zathura) { + GiraraTemplate *csstemplate = + girara_session_get_template(zathura->ui.session); static const char index_settings[][16] = { - "index-fg", - "index-bg", - "index-active-fg", - "index-active-bg" - }; + "index-fg", "index-bg", "index-active-fg", "index-active-bg"}; for (size_t s = 0; s < LENGTH(index_settings); ++s) { girara_template_add_variable(csstemplate, index_settings[s]); - char* tmp_value = NULL; - GdkRGBA rgba = {0, 0, 0, 0}; + char *tmp_value = NULL; + GdkRGBA rgba = {0, 0, 0, 0}; girara_setting_get(zathura->ui.session, index_settings[s], &tmp_value); if (tmp_value != NULL) { parse_color(&rgba, tmp_value); g_free(tmp_value); } - char* color = gdk_rgba_to_string(&rgba); + char *color = gdk_rgba_to_string(&rgba); girara_template_set_variable_value(csstemplate, index_settings[s], color); g_free(color); } - GResource* css_resource = zathura_resources_get_resource(); - GBytes* css_data = g_resource_lookup_data(css_resource, - "/org/pwmt/zathura/CSS/zathura.css_t", - G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); + GResource *css_resource = zathura_resources_get_resource(); + GBytes *css_data = g_resource_lookup_data( + css_resource, "/org/pwmt/zathura/CSS/zathura.css_t", + G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); if (css_data != NULL) { - char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), - (const char*) g_bytes_get_data(css_data, NULL)); + char *css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), + (const char *)g_bytes_get_data(css_data, NULL)); girara_template_set_base(csstemplate, css); g_free(css); g_bytes_unref(css_data); @@ -355,10 +346,8 @@ init_css(zathura_t* zathura) return true; } -static void -init_database(zathura_t* zathura) -{ - char* database = NULL; +static void init_database(zathura_t *zathura) { + char *database = NULL; girara_setting_get(zathura->ui.session, "database", &database); /* create zathura data directory if database enabled */ @@ -372,8 +361,8 @@ init_database(zathura_t* zathura) #ifdef WITH_SQLITE } else if (g_strcmp0(database, "sqlite") == 0) { girara_debug("Using sqlite database backend."); - char* tmp = - g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL); + char *tmp = + g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL); zathura->database = zathura_sqldatabase_new(tmp); g_free(tmp); #endif @@ -383,43 +372,36 @@ init_database(zathura_t* zathura) if (zathura->database == NULL && g_strcmp0(database, "null") != 0) { girara_error( - "Unable to initialize database. Bookmarks won't be available."); - } - else { + "Unable to initialize database. Bookmarks won't be available."); + } else { g_object_set(G_OBJECT(zathura->ui.session->command_history), "io", zathura->database, NULL); } g_free(database); } -static void -init_jumplist(zathura_t* zathura) -{ +static void init_jumplist(zathura_t *zathura) { int jumplist_size = 20; girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size); zathura->jumplist.max_size = jumplist_size < 0 ? 0 : jumplist_size; - zathura->jumplist.list = NULL; - zathura->jumplist.size = 0; - zathura->jumplist.cur = NULL; + zathura->jumplist.list = NULL; + zathura->jumplist.size = 0; + zathura->jumplist.cur = NULL; } -static void -init_shortcut_helpers(zathura_t* zathura) -{ +static void init_shortcut_helpers(zathura_t *zathura) { zathura->shortcut.mouse.x = 0; zathura->shortcut.mouse.y = 0; zathura->shortcut.toggle_page_mode.pages = 2; - zathura->shortcut.toggle_presentation_mode.pages = 1; + zathura->shortcut.toggle_presentation_mode.pages = 1; zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL; - zathura->shortcut.toggle_presentation_mode.zoom = 1.0; + zathura->shortcut.toggle_presentation_mode.zoom = 1.0; } -bool -zathura_init(zathura_t* zathura) -{ +bool zathura_init(zathura_t *zathura) { if (zathura == NULL) { return false; } @@ -437,25 +419,25 @@ zathura_init(zathura_t* zathura) #ifdef WITH_SECCOMP /* initialize seccomp filters */ switch (zathura->global.sandbox) { - case ZATHURA_SANDBOX_NONE: - girara_debug("Sandbox deactivated."); - break; - case ZATHURA_SANDBOX_NORMAL: - girara_debug("Basic sandbox allowing normal operation."); - if (seccomp_enable_basic_filter() != 0) { - girara_error("Failed to initialize basic seccomp filter."); - goto error_free; - } - break; - case ZATHURA_SANDBOX_STRICT: - girara_debug("Strict sandbox preventing write and network access."); - if (seccomp_enable_strict_filter() != 0) { - girara_error("Failed to initialize strict seccomp filter."); - goto error_free; - } - /* unset the input method to avoid communication with external services */ - unsetenv("GTK_IM_MODULE"); - break; + case ZATHURA_SANDBOX_NONE: + girara_debug("Sandbox deactivated."); + break; + case ZATHURA_SANDBOX_NORMAL: + girara_debug("Basic sandbox allowing normal operation."); + if (seccomp_enable_basic_filter() != 0) { + girara_error("Failed to initialize basic seccomp filter."); + goto error_free; + } + break; + case ZATHURA_SANDBOX_STRICT: + girara_debug("Strict sandbox preventing write and network access."); + if (seccomp_enable_strict_filter() != 0) { + girara_error("Failed to initialize strict seccomp filter."); + goto error_free; + } + /* unset the input method to avoid communication with external services */ + unsetenv("GTK_IM_MODULE"); + break; } #endif @@ -466,15 +448,15 @@ zathura_init(zathura_t* zathura) } /* disable unsupported features in strict sandbox mode */ - if (zathura->global.sandbox != ZATHURA_SANDBOX_STRICT){ + if (zathura->global.sandbox != ZATHURA_SANDBOX_STRICT) { /* database */ init_database(zathura); } /* bookmarks */ zathura->bookmarks.bookmarks = girara_sorted_list_new2( - (girara_compare_function_t)zathura_bookmarks_compare, - (girara_free_function_t)zathura_bookmark_free); + (girara_compare_function_t)zathura_bookmarks_compare, + (girara_free_function_t)zathura_bookmark_free); /* jumplist */ init_jumplist(zathura); @@ -506,9 +488,7 @@ error_free: return false; } -void -zathura_free(zathura_t* zathura) -{ +void zathura_free(zathura_t *zathura) { if (zathura == NULL) { return; } @@ -533,7 +513,8 @@ zathura_free(zathura_t* zathura) } /* shortcut */ - if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != NULL) { + if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != + NULL) { g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list); } @@ -573,76 +554,62 @@ zathura_free(zathura_t* zathura) g_free(zathura); } -void -zathura_set_xid(zathura_t* zathura, Window xid) -{ +void zathura_set_xid(zathura_t *zathura, Window xid) { g_return_if_fail(zathura != NULL); zathura->ui.session->gtk.embed = xid; } -void -zathura_set_config_dir(zathura_t* zathura, const char* dir) -{ +void zathura_set_config_dir(zathura_t *zathura, const char *dir) { g_return_if_fail(zathura != NULL); if (dir != NULL) { zathura->config.config_dir = g_strdup(dir); } else { - gchar* path = girara_get_xdg_path(XDG_CONFIG); + gchar *path = girara_get_xdg_path(XDG_CONFIG); zathura->config.config_dir = g_build_filename(path, "zathura", NULL); g_free(path); } } -void -zathura_set_data_dir(zathura_t* zathura, const char* dir) -{ +void zathura_set_data_dir(zathura_t *zathura, const char *dir) { g_return_if_fail(zathura != NULL); if (dir != NULL) { zathura->config.data_dir = g_strdup(dir); } else { - gchar* path = girara_get_xdg_path(XDG_DATA); + gchar *path = girara_get_xdg_path(XDG_DATA); zathura->config.data_dir = g_build_filename(path, "zathura", NULL); g_free(path); } } -void -zathura_set_cache_dir(zathura_t* zathura, const char* dir) -{ +void zathura_set_cache_dir(zathura_t *zathura, const char *dir) { g_return_if_fail(zathura != NULL); if (dir != NULL) { zathura->config.cache_dir = g_strdup(dir); } else { - gchar* path = girara_get_xdg_path(XDG_CACHE); + gchar *path = girara_get_xdg_path(XDG_CACHE); zathura->config.cache_dir = g_build_filename(path, "zathura", NULL); g_free(path); } } -static void -add_dir(void* data, void* userdata) -{ - const char* path = data; - zathura_plugin_manager_t* plugin_manager = userdata; +static void add_dir(void *data, void *userdata) { + const char *path = data; + zathura_plugin_manager_t *plugin_manager = userdata; zathura_plugin_manager_add_dir(plugin_manager, path); } -static void -set_plugin_dir(zathura_t* zathura, const char* dir) -{ - girara_list_t* paths = girara_split_path_array(dir); +static void set_plugin_dir(zathura_t *zathura, const char *dir) { + girara_list_t *paths = girara_split_path_array(dir); girara_list_foreach(paths, add_dir, zathura->plugins.manager); girara_list_free(paths); } -void -zathura_set_plugin_dir(zathura_t* zathura, const char* dir) -{ +void zathura_set_plugin_dir(zathura_t *zathura, const char *dir) { g_return_if_fail(zathura != NULL); g_return_if_fail(zathura->plugins.manager != NULL); @@ -657,38 +624,35 @@ zathura_set_plugin_dir(zathura_t* zathura, const char* dir) } } -void -zathura_set_argv(zathura_t* zathura, char** argv) -{ +void zathura_set_argv(zathura_t *zathura, char **argv) { g_return_if_fail(zathura != NULL); zathura->global.arguments = argv; } -static bool -setup_renderer(zathura_t* zathura, zathura_document_t* document) -{ - /* page cache size */ +static bool setup_renderer(zathura_t *zathura, zathura_document_t *document) { + /* page cache size */ int cache_size = 0; girara_setting_get(zathura->ui.session, "page-cache-size", &cache_size); if (cache_size <= 0) { girara_warning("page-cache-size is not positive, using %d instead", - ZATHURA_PAGE_CACHE_DEFAULT_SIZE); + ZATHURA_PAGE_CACHE_DEFAULT_SIZE); cache_size = ZATHURA_PAGE_CACHE_DEFAULT_SIZE; } girara_debug("starting renderer with cache size %d", cache_size); - ZathuraRenderer* renderer = zathura_renderer_new(cache_size); + ZathuraRenderer *renderer = zathura_renderer_new(cache_size); if (renderer == NULL) { return false; } /* set up recolor info in ZathuraRenderer */ - char* recolor_dark = NULL; - char* recolor_light = NULL; + char *recolor_dark = NULL; + char *recolor_light = NULL; girara_setting_get(zathura->ui.session, "recolor-darkcolor", &recolor_dark); girara_setting_get(zathura->ui.session, "recolor-lightcolor", &recolor_light); - zathura_renderer_set_recolor_colors_str(renderer, recolor_light, recolor_dark); + zathura_renderer_set_recolor_colors_str(renderer, recolor_light, + recolor_dark); g_free(recolor_dark); g_free(recolor_light); @@ -707,8 +671,10 @@ setup_renderer(zathura_t* zathura, zathura_document_t* document) girara_setting_get(zathura->ui.session, "window-icon-document", &window_icon); if (window_icon == true) { girara_debug("starting render request for window icon"); - ZathuraRenderRequest* request = zathura_render_request_new(renderer, zathura_document_get_page(document, 0)); - g_signal_connect(request, "completed", G_CALLBACK(cb_window_update_icon), zathura); + ZathuraRenderRequest *request = zathura_render_request_new( + renderer, zathura_document_get_page(document, 0)); + g_signal_connect(request, "completed", G_CALLBACK(cb_window_update_icon), + zathura); zathura_render_request_set_render_plain(request, true); zathura_render_request(request, 0); zathura->window_icon_render_request = request; @@ -718,19 +684,17 @@ setup_renderer(zathura_t* zathura, zathura_document_t* document) } #ifdef G_OS_UNIX -static gchar* -prepare_document_open_from_stdin(const char* path) -{ +static gchar *prepare_document_open_from_stdin(const char *path) { int infileno = -1; if (g_strcmp0(path, "-") == 0) { infileno = fileno(stdin); } else if (g_str_has_prefix(path, "/proc/self/fd/") == true) { - char* begin = g_strrstr(path, "/") + 1; + char *begin = g_strrstr(path, "/") + 1; gint64 temp = g_ascii_strtoll(begin, NULL, 0); if (temp > INT_MAX || temp < 0) { return NULL; } - infileno = (int) temp; + infileno = (int)temp; } else { return NULL; } @@ -740,16 +704,15 @@ prepare_document_open_from_stdin(const char* path) return NULL; } - GInputStream* input_stream = g_unix_input_stream_new(infileno, false); + GInputStream *input_stream = g_unix_input_stream_new(infileno, false); if (input_stream == NULL) { girara_error("Can not read from file descriptor."); return NULL; - } - GFileIOStream* iostream = NULL; - GError* error = NULL; - GFile* tmpfile = g_file_new_tmp("zathura.stdin.XXXXXX", &iostream, &error); + GFileIOStream *iostream = NULL; + GError *error = NULL; + GFile *tmpfile = g_file_new_tmp("zathura.stdin.XXXXXX", &iostream, &error); if (tmpfile == NULL) { if (error != NULL) { girara_error("Can not create temporary file: %s", error->message); @@ -760,8 +723,8 @@ prepare_document_open_from_stdin(const char* path) } const ssize_t count = g_output_stream_splice( - g_io_stream_get_output_stream(G_IO_STREAM(iostream)), input_stream, - G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error); + g_io_stream_get_output_stream(G_IO_STREAM(iostream)), input_stream, + G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error); g_object_unref(input_stream); g_object_unref(iostream); if (count == -1) { @@ -774,21 +737,19 @@ prepare_document_open_from_stdin(const char* path) return NULL; } - char* file = g_file_get_path(tmpfile); + char *file = g_file_get_path(tmpfile); g_object_unref(tmpfile); return file; } #endif -static gchar* -prepare_document_open_from_gfile(GFile* source) -{ - gchar* file = NULL; - GFileIOStream* iostream = NULL; - GError* error = NULL; +static gchar *prepare_document_open_from_gfile(GFile *source) { + gchar *file = NULL; + GFileIOStream *iostream = NULL; + GError *error = NULL; - GFile* tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error); + GFile *tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error); if (tmpfile == NULL) { if (error != NULL) { girara_error("Can not create temporary file: %s", error->message); @@ -816,15 +777,13 @@ prepare_document_open_from_gfile(GFile* source) return file; } -static gboolean -document_info_open(gpointer data) -{ - zathura_document_info_t* document_info = data; +static gboolean document_info_open(gpointer data) { + zathura_document_info_t *document_info = data; g_return_val_if_fail(document_info != NULL, FALSE); - char* uri = NULL; + char *uri = NULL; if (document_info->zathura != NULL && document_info->path != NULL) { - char* file = NULL; + char *file = NULL; if (g_strcmp0(document_info->path, "-") == 0 || g_str_has_prefix(document_info->path, "/proc/self/fd/") == true) { #ifdef G_OS_UNIX @@ -832,27 +791,31 @@ document_info_open(gpointer data) #endif if (file == NULL) { girara_notify(document_info->zathura->ui.session, GIRARA_ERROR, - _("Could not read file from stdin and write it to a temporary file.")); + _("Could not read file from stdin and write it to a " + "temporary file.")); } else { document_info->zathura->stdin_support.file = g_strdup(file); } } else { /* expand ~ and ~user in paths if present */ - char* tmp_path = *document_info->path == '~' ? girara_fix_path(document_info->path) : NULL; - GFile* gf = g_file_new_for_commandline_arg(tmp_path != NULL ? tmp_path : document_info->path); + char *tmp_path = *document_info->path == '~' + ? girara_fix_path(document_info->path) + : NULL; + GFile *gf = g_file_new_for_commandline_arg( + tmp_path != NULL ? tmp_path : document_info->path); g_free(tmp_path); if (g_file_is_native(gf) == TRUE) { /* file was given as a native path */ file = g_file_get_path(gf); - } - else { + } else { /* copy file with GIO */ uri = g_file_get_uri(gf); file = prepare_document_open_from_gfile(gf); if (file == NULL) { girara_notify(document_info->zathura->ui.session, GIRARA_ERROR, - _("Could not read file from GIO and copy it to a temporary file.")); + _("Could not read file from GIO and copy it to a " + "temporary file.")); } else { document_info->zathura->stdin_support.file = g_strdup(file); } @@ -865,8 +828,8 @@ document_info_open(gpointer data) document_open_synctex(document_info->zathura, file, uri, document_info->password, document_info->synctex); } else { - document_open(document_info->zathura, file, uri, document_info->password, - document_info->page_number); + document_open(document_info->zathura, file, uri, + document_info->password, document_info->page_number); } g_free(file); g_free(uri); @@ -887,8 +850,8 @@ document_info_open(gpointer data) girara_argument_t search_arg; search_arg.n = 1; // Forward search search_arg.data = NULL; - cmd_search(document_info->zathura->ui.session, document_info->search_string, - &search_arg); + cmd_search(document_info->zathura->ui.session, + document_info->search_string, &search_arg); } } } @@ -897,38 +860,39 @@ document_info_open(gpointer data) return FALSE; } -char* -get_formatted_filename(zathura_t* zathura, bool statusbar) -{ +char *get_formatted_filename(zathura_t *zathura, bool statusbar) { bool basename_only = false; - const char* file_path = zathura_document_get_uri(zathura->document); + const char *file_path = zathura_document_get_uri(zathura->document); if (file_path == NULL) { file_path = zathura_document_get_path(zathura->document); } if (statusbar == true) { - girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only); + girara_setting_get(zathura->ui.session, "statusbar-basename", + &basename_only); } else { - girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only); + girara_setting_get(zathura->ui.session, "window-title-basename", + &basename_only); } if (basename_only == false) { bool home_tilde = false; if (statusbar) { - girara_setting_get(zathura->ui.session, "statusbar-home-tilde", &home_tilde); + girara_setting_get(zathura->ui.session, "statusbar-home-tilde", + &home_tilde); } else { - girara_setting_get(zathura->ui.session, "window-title-home-tilde", &home_tilde); + girara_setting_get(zathura->ui.session, "window-title-home-tilde", + &home_tilde); } const size_t file_path_len = file_path ? strlen(file_path) : 0; if (home_tilde == true) { - char* home = girara_get_home_directory(NULL); + char *home = girara_get_home_directory(NULL); const size_t home_len = home ? strlen(home) : 0; - if (home_len > 1 - && file_path_len >= home_len - && g_str_has_prefix(file_path, home) - && (!file_path[home_len] || file_path[home_len] == '/')) { + if (home_len > 1 && file_path_len >= home_len && + g_str_has_prefix(file_path, home) && + (!file_path[home_len] || file_path[home_len] == '/')) { g_free(home); return g_strdup_printf("~%s", &file_path[home_len]); } else { @@ -939,47 +903,46 @@ get_formatted_filename(zathura_t* zathura, bool statusbar) return g_strdup(file_path); } } else { - const char* basename = zathura_document_get_basename(zathura->document); + const char *basename = zathura_document_get_basename(zathura->document); return g_strdup(basename); } } -static gboolean -document_open_password_dialog(gpointer data) -{ - zathura_password_dialog_info_t* password_dialog_info = data; +static gboolean document_open_password_dialog(gpointer data) { + zathura_password_dialog_info_t *password_dialog_info = data; - girara_dialog(password_dialog_info->zathura->ui.session, _("Enter password:"), true, NULL, - cb_password_dialog, password_dialog_info); + girara_dialog(password_dialog_info->zathura->ui.session, _("Enter password:"), + true, NULL, cb_password_dialog, password_dialog_info); return FALSE; } -bool -document_open(zathura_t* zathura, const char* path, const char* uri, const char* password, - int page_number) -{ +bool document_open(zathura_t *zathura, const char *path, const char *uri, + const char *password, int page_number) { if (zathura == NULL || zathura->plugins.manager == NULL || path == NULL) { goto error_out; } - /* FIXME: since there are many call chains leading here, check again if we need to expand ~ or - * ~user. We should fix all call sites instead */ - char* tmp_path = *path == '~' ? girara_fix_path(path) : NULL; + /* FIXME: since there are many call chains leading here, check again if we + * need to expand ~ or ~user. We should fix all call sites instead */ + char *tmp_path = *path == '~' ? girara_fix_path(path) : NULL; zathura_error_t error = ZATHURA_ERROR_OK; - zathura_document_t* document = zathura_document_open(zathura, tmp_path != NULL ? tmp_path : path, uri, password, &error); + zathura_document_t *document = zathura_document_open( + zathura, tmp_path != NULL ? tmp_path : path, uri, password, &error); g_free(tmp_path); if (document == NULL) { if (error == ZATHURA_ERROR_INVALID_PASSWORD) { girara_debug("Invalid or no password."); - zathura_password_dialog_info_t* password_dialog_info = malloc(sizeof(zathura_password_dialog_info_t)); + zathura_password_dialog_info_t *password_dialog_info = + malloc(sizeof(zathura_password_dialog_info_t)); if (password_dialog_info != NULL) { password_dialog_info->zathura = zathura; password_dialog_info->path = g_strdup(path); password_dialog_info->uri = g_strdup(uri); if (password_dialog_info->path != NULL) { - gdk_threads_add_idle(document_open_password_dialog, password_dialog_info); + gdk_threads_add_idle(document_open_password_dialog, + password_dialog_info); goto error_out; } else { free(password_dialog_info); @@ -987,39 +950,40 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } goto error_out; } - if (error == ZATHURA_ERROR_OK ) { - girara_notify(zathura->ui.session, GIRARA_ERROR, _("Unsupported file type. Please install the necessary plugin.")); + if (error == ZATHURA_ERROR_OK) { + girara_notify( + zathura->ui.session, GIRARA_ERROR, + _("Unsupported file type. Please install the necessary plugin.")); } goto error_out; } - const char* file_path = zathura_document_get_path(document); + const char *file_path = zathura_document_get_path(document); unsigned int number_of_pages = zathura_document_get_number_of_pages(document); if (number_of_pages == 0) { girara_notify(zathura->ui.session, GIRARA_WARNING, - _("Document does not contain any pages")); + _("Document does not contain any pages")); goto error_free; } zathura->document = document; /* read history file */ - zathura_fileinfo_t file_info = { - .current_page = 0, - .page_offset = 0, - .zoom = 1, - .rotation = 0, - .pages_per_row = 0, - .first_page_column_list = NULL, - .page_right_to_left = false, - .position_x = 0, - .position_y = 0 - }; + zathura_fileinfo_t file_info = {.current_page = 0, + .page_offset = 0, + .zoom = 1, + .rotation = 0, + .pages_per_row = 0, + .first_page_column_list = NULL, + .page_right_to_left = false, + .position_x = 0, + .position_y = 0}; bool known_file = false; if (zathura->database != NULL) { - const uint8_t* file_hash = zathura_document_get_hash(document); - known_file = zathura_db_get_fileinfo(zathura->database, file_path, file_hash, &file_info); + const uint8_t *file_hash = zathura_document_get_hash(document); + known_file = zathura_db_get_fileinfo(zathura->database, file_path, + file_hash, &file_info); } /* set page offset */ @@ -1029,8 +993,8 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* if (file_info.zoom <= DBL_EPSILON) { file_info.zoom = 1; } - zathura_document_set_zoom(document, - zathura_correct_zoom_value(zathura->ui.session, file_info.zoom)); + zathura_document_set_zoom(document, zathura_correct_zoom_value( + zathura->ui.session, file_info.zoom)); /* check current page number */ /* if it wasn't specified on the command-line, get it from file_info */ @@ -1055,14 +1019,17 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* /* jump to first page if setting enabled */ bool always_first_page = false; - girara_setting_get(zathura->ui.session, "open-first-page", &always_first_page); + girara_setting_get(zathura->ui.session, "open-first-page", + &always_first_page); if (always_first_page == true) { zathura_document_set_current_page_number(document, 0); } /* apply open adjustment */ - char* adjust_open = "best-fit"; - if (known_file == false && girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) { + char *adjust_open = "best-fit"; + if (known_file == false && + girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == + true) { if (g_strcmp0(adjust_open, "best-fit") == 0) { zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_BESTFIT); } else if (g_strcmp0(adjust_open, "width") == 0) { @@ -1077,18 +1044,21 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* /* initialize bisect state */ zathura->bisect.start = 0; - zathura->bisect.last_jump = zathura_document_get_current_page_number(document); + zathura->bisect.last_jump = + zathura_document_get_current_page_number(document); zathura->bisect.end = number_of_pages - 1; /* update statusbar */ - char* filename = get_formatted_filename(zathura, true); - girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, filename); + char *filename = get_formatted_filename(zathura, true); + girara_statusbar_item_set_text(zathura->ui.session, + zathura->ui.statusbar.file, filename); g_free(filename); /* install file monitor */ if (zathura->file_monitor.monitor == NULL) { - char* filemonitor_backend = NULL; - girara_setting_get(zathura->ui.session, "filemonitor", &filemonitor_backend); + char *filemonitor_backend = NULL; + girara_setting_get(zathura->ui.session, "filemonitor", + &filemonitor_backend); zathura_filemonitor_type_t type = ZATHURA_FILEMONITOR_GLIB; if (g_strcmp0(filemonitor_backend, "noop") == 0) { type = ZATHURA_FILEMONITOR_NOOP; @@ -1120,7 +1090,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } /* create marks list */ - zathura->global.marks = girara_list_new2((girara_free_function_t) mark_free); + zathura->global.marks = girara_list_new2((girara_free_function_t)mark_free); if (zathura->global.marks == NULL) { goto error_free; } @@ -1131,38 +1101,60 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } /* get view port size */ - GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment( - GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + GtkAdjustment *hadjustment = gtk_scrolled_window_get_hadjustment( + GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment( + GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - const unsigned int view_width = floor(gtk_adjustment_get_page_size(hadjustment)); + const unsigned int view_width = + floor(gtk_adjustment_get_page_size(hadjustment)); zathura_document_set_viewport_width(zathura->document, view_width); - const unsigned int view_height = floor(gtk_adjustment_get_page_size(vadjustment)); + const unsigned int view_height = + floor(gtk_adjustment_get_page_size(vadjustment)); zathura_document_set_viewport_height(zathura->document, view_height); + // @debug + /* unsigned int h, w; */ + /* zathura_document_get_viewport_size(zathura->document, &h, &w); */ + /* fprintf(stderr, "view_width: %d\n", h); */ + /* fprintf(stderr, "view_height: %d\n", w); */ + /* zathura_document_set_viewport_width(zathura->document, 1000); */ + /* zathura_document_set_viewport_height(zathura->document, 1000); */ + /* zathura_document_get_viewport_size(zathura->document, &h, &w); */ + /* fprintf(stderr, "view_width: %d\n", h); */ + /* fprintf(stderr, "view_height: %d\n", w); */ + zathura_update_view_ppi(zathura); - /* call screen-changed callback to connect monitors-changed signal on initial screen */ + /* call screen-changed callback to connect monitors-changed signal on initial + * screen */ cb_widget_screen_changed(zathura->ui.session->gtk.view, NULL, zathura); /* get initial device scale */ - const int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); - zathura_document_set_device_factors(zathura->document, device_factor, device_factor); + const int device_factor = + gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); + zathura_document_set_device_factors(zathura->document, device_factor, + device_factor); /* create blank pages */ - zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*)); + zathura->pages = calloc(number_of_pages, sizeof(GtkWidget *)); if (zathura->pages == NULL) { goto error_free; } for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) { - zathura_page_t* page = zathura_document_get_page(document, page_id); + zathura_page_t *page = zathura_document_get_page(document, page_id); if (page == NULL) { goto error_free; } - GtkWidget* page_widget = zathura_page_widget_new(zathura, page); + // @debug + fprintf(stderr, "page %d\n", page_id); + fprintf(stderr, "page.wdith %f\n", zathura_page_get_width(page)); + fprintf(stderr, "page.height %f\n", zathura_page_get_height(page)); + fprintf(stderr, "-\n"); + + GtkWidget *page_widget = zathura_page_widget_new(zathura, page); if (page_widget == NULL) { goto error_free; } @@ -1174,24 +1166,26 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* gtk_widget_set_valign(page_widget, GTK_ALIGN_CENTER); g_signal_connect(G_OBJECT(page_widget), "text-selected", - G_CALLBACK(cb_page_widget_text_selected), zathura); + G_CALLBACK(cb_page_widget_text_selected), zathura); g_signal_connect(G_OBJECT(page_widget), "image-selected", - G_CALLBACK(cb_page_widget_image_selected), zathura); + G_CALLBACK(cb_page_widget_image_selected), zathura); g_signal_connect(G_OBJECT(page_widget), "enter-link", - G_CALLBACK(cb_page_widget_link), (gpointer) true); + G_CALLBACK(cb_page_widget_link), (gpointer) true); g_signal_connect(G_OBJECT(page_widget), "leave-link", - G_CALLBACK(cb_page_widget_link), (gpointer) false); + G_CALLBACK(cb_page_widget_link), (gpointer) false); g_signal_connect(G_OBJECT(page_widget), "scaled-button-release", - G_CALLBACK(cb_page_widget_scaled_button_release), zathura); + G_CALLBACK(cb_page_widget_scaled_button_release), zathura); } /* view mode */ unsigned int pages_per_row = 1; - char* first_page_column_list = NULL; + char *first_page_column_list = NULL; unsigned int page_padding = 1; bool page_right_to_left = false; girara_setting_get(zathura->ui.session, "page-padding", &page_padding); + // @debug + fprintf(stderr, "page padding %d\n", page_padding); if (file_info.pages_per_row > 0) { pages_per_row = file_info.pages_per_row; @@ -1200,25 +1194,38 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } /* read first_page_column list */ - if (file_info.first_page_column_list != NULL && *file_info.first_page_column_list != '\0') { + if (file_info.first_page_column_list != NULL && + *file_info.first_page_column_list != '\0') { first_page_column_list = file_info.first_page_column_list; file_info.first_page_column_list = NULL; } else { - girara_setting_get(zathura->ui.session, "first-page-column", &first_page_column_list); + girara_setting_get(zathura->ui.session, "first-page-column", + &first_page_column_list); } /* find value for first_page_column */ - unsigned int first_page_column = find_first_page_column(first_page_column_list, pages_per_row); + unsigned int first_page_column = + find_first_page_column(first_page_column_list, pages_per_row); girara_setting_set(zathura->ui.session, "pages-per-row", &pages_per_row); - girara_setting_set(zathura->ui.session, "first-page-column", first_page_column_list); + girara_setting_set(zathura->ui.session, "first-page-column", + first_page_column_list); g_free(file_info.first_page_column_list); g_free(first_page_column_list); page_right_to_left = file_info.page_right_to_left; - page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left); - zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); + page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, + page_right_to_left); + + // @debug + fprintf(stderr, "page_per_row: %d\n", pages_per_row); + fprintf(stderr, "first_page_column: %d\n", first_page_column); + page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, + true); + + zathura_document_set_page_layout(zathura->document, page_padding, + pages_per_row, first_page_column); girara_set_view(zathura->ui.session, zathura->ui.page_widget); @@ -1235,7 +1242,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } /* update title */ - char* formatted_filename = get_formatted_filename(zathura, false); + char *formatted_filename = get_formatted_filename(zathura, false); girara_set_window_title(zathura->ui.session, formatted_filename); g_free(formatted_filename); @@ -1243,17 +1250,23 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* adjust_view(zathura); for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) { /* set widget size */ - zathura_page_t* page = zathura_document_get_page(document, page_id); + zathura_page_t *page = zathura_document_get_page(document, page_id); unsigned int page_height = 0; - unsigned int page_width = 0; + unsigned int page_width = 0; /* adjust_view calls render_all in some cases and render_all calls * gtk_widget_set_size_request. To be sure that it's really called, do it * here once again. */ const double height = zathura_page_get_height(page); const double width = zathura_page_get_width(page); - page_calc_height_width(zathura->document, height, width, &page_height, &page_width, true); - gtk_widget_set_size_request(zathura->pages[page_id], page_width, page_height); + // @debug + fprintf(stderr, "height in z: %f\n", height); + fprintf(stderr, "width in z: %f\n", width); + + page_calc_height_width(zathura->document, height, width, &page_height, + &page_width, true); + gtk_widget_set_size_request(zathura->pages[page_id], page_width, + page_height); /* show widget */ gtk_widget_show(zathura->pages[page_id]); @@ -1263,7 +1276,8 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* page_set(zathura, zathura_document_get_current_page_number(document)); /* Set position (only if restoring from history file) */ - if (file_info.current_page == zathura_document_get_current_page_number(document) && + if (file_info.current_page == + zathura_document_get_current_page_number(document) && (file_info.position_x != 0 || file_info.position_y != 0)) { position_set(zathura, file_info.position_x, file_info.position_y); } @@ -1281,10 +1295,9 @@ error_out: return false; } -bool -document_open_synctex(zathura_t* zathura, const char* path, const char* uri, - const char* password, const char* synctex) -{ +bool document_open_synctex(zathura_t *zathura, const char *path, + const char *uri, const char *password, + const char *synctex) { bool ret = document_open(zathura, path, password, uri, ZATHURA_PAGE_NUMBER_UNSPECIFIED); if (ret == false) { @@ -1296,7 +1309,7 @@ document_open_synctex(zathura_t* zathura, const char* path, const char* uri, int line = 0; int column = 0; - char* input_file = NULL; + char *input_file = NULL; if (synctex_parse_input(synctex, &input_file, &line, &column) == false) { return false; } @@ -1306,30 +1319,29 @@ document_open_synctex(zathura_t* zathura, const char* path, const char* uri, return ret; } -void -document_open_idle(zathura_t* zathura, const char* path, const char* password, - int page_number, const char* mode, const char* synctex, - const char *search_string) -{ +void document_open_idle(zathura_t *zathura, const char *path, + const char *password, int page_number, const char *mode, + const char *synctex, const char *search_string) { g_return_if_fail(zathura != NULL); g_return_if_fail(path != NULL); - zathura_document_info_t* document_info = g_try_malloc0(sizeof(zathura_document_info_t)); + zathura_document_info_t *document_info = + g_try_malloc0(sizeof(zathura_document_info_t)); if (document_info == NULL) { return; } - document_info->zathura = zathura; - document_info->path = g_strdup(path); + document_info->zathura = zathura; + document_info->path = g_strdup(path); if (password != NULL) { - document_info->password = g_strdup(password); + document_info->password = g_strdup(password); } document_info->page_number = page_number; if (mode != NULL) { - document_info->mode = g_strdup(mode); + document_info->mode = g_strdup(mode); } if (synctex != NULL) { - document_info->synctex = g_strdup(synctex); + document_info->synctex = g_strdup(synctex); } if (search_string != NULL) { document_info->search_string = g_strdup(search_string); @@ -1338,58 +1350,56 @@ document_open_idle(zathura_t* zathura, const char* path, const char* password, gdk_threads_add_idle(document_info_open, document_info); } -bool -document_save(zathura_t* zathura, const char* path, bool overwrite) -{ +bool document_save(zathura_t *zathura, const char *path, bool overwrite) { g_return_val_if_fail(zathura, false); g_return_val_if_fail(zathura->document, false); g_return_val_if_fail(path, false); - gchar* file_path = girara_fix_path(path); + gchar *file_path = girara_fix_path(path); /* use current basename if path points to a directory */ if (g_file_test(file_path, G_FILE_TEST_IS_DIR) == TRUE) { - char* basename = g_path_get_basename(zathura_document_get_path(zathura->document)); - char* tmp = file_path; + char *basename = + g_path_get_basename(zathura_document_get_path(zathura->document)); + char *tmp = file_path; file_path = g_build_filename(file_path, basename, NULL); g_free(tmp); g_free(basename); } if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) { - girara_error("File already exists: %s. Use :write! to overwrite it.", file_path); + girara_error("File already exists: %s. Use :write! to overwrite it.", + file_path); g_free(file_path); return false; } - zathura_error_t error = zathura_document_save_as(zathura->document, file_path); + zathura_error_t error = + zathura_document_save_as(zathura->document, file_path); g_free(file_path); return (error == ZATHURA_ERROR_OK) ? true : false; } -static void -remove_page_from_table(GtkWidget* page, gpointer UNUSED(permanent)) -{ +static void remove_page_from_table(GtkWidget *page, + gpointer UNUSED(permanent)) { gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(page)), page); } -static void -save_fileinfo_to_db(zathura_t* zathura) -{ - const char* path = zathura_document_get_path(zathura->document); - const uint8_t* file_hash = zathura_document_get_hash(zathura->document); +static void save_fileinfo_to_db(zathura_t *zathura) { + const char *path = zathura_document_get_path(zathura->document); + const uint8_t *file_hash = zathura_document_get_hash(zathura->document); zathura_fileinfo_t file_info = { - .current_page = zathura_document_get_current_page_number(zathura->document), - .page_offset = zathura_document_get_page_offset(zathura->document), - .zoom = zathura_document_get_zoom(zathura->document), - .rotation = zathura_document_get_rotation(zathura->document), - .pages_per_row = 1, - .first_page_column_list = "1:2", - .page_right_to_left = false, - .position_x = zathura_document_get_position_x(zathura->document), - .position_y = zathura_document_get_position_y(zathura->document) - }; + .current_page = + zathura_document_get_current_page_number(zathura->document), + .page_offset = zathura_document_get_page_offset(zathura->document), + .zoom = zathura_document_get_zoom(zathura->document), + .rotation = zathura_document_get_rotation(zathura->document), + .pages_per_row = 1, + .first_page_column_list = "1:2", + .page_right_to_left = false, + .position_x = zathura_document_get_position_x(zathura->document), + .position_y = zathura_document_get_position_y(zathura->document)}; girara_setting_get(zathura->ui.session, "pages-per-row", &(file_info.pages_per_row)); @@ -1406,16 +1416,15 @@ save_fileinfo_to_db(zathura_t* zathura) g_free(file_info.first_page_column_list); } -bool -document_close(zathura_t* zathura, bool keep_monitor) -{ +bool document_close(zathura_t *zathura, bool keep_monitor) { if (zathura == NULL || zathura->document == NULL) { return false; } /* reset window icon */ - if (zathura->ui.session != NULL && zathura->window_icon_render_request != NULL) { - char* window_icon = NULL; + if (zathura->ui.session != NULL && + zathura->window_icon_render_request != NULL) { + char *window_icon = NULL; girara_setting_get(zathura->ui.session, "window-icon", &window_icon); girara_setting_set(zathura->ui.session, "window-icon", window_icon); g_free(window_icon); @@ -1457,8 +1466,10 @@ document_close(zathura_t* zathura, bool keep_monitor) g_clear_object(&zathura->sync.render_thread); /* remove widgets */ - gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL); - for (unsigned int i = 0; i < zathura_document_get_number_of_pages(zathura->document); i++) { + gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), + remove_page_from_table, NULL); + for (unsigned int i = 0; + i < zathura_document_get_number_of_pages(zathura->document); i++) { g_object_unref(zathura->pages[i]); } free(zathura->pages); @@ -1479,7 +1490,8 @@ document_close(zathura_t* zathura, bool keep_monitor) statusbar_page_number_update(zathura); if (zathura->ui.session != NULL && zathura->ui.statusbar.file != NULL) { - 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]")); } /* update title */ @@ -1488,14 +1500,12 @@ document_close(zathura_t* zathura, bool keep_monitor) return true; } -bool -page_set(zathura_t* zathura, unsigned int page_id) -{ +bool page_set(zathura_t *zathura, unsigned int page_id) { if (zathura == NULL || zathura->document == NULL) { goto error_out; } - zathura_page_t* page = zathura_document_get_page(zathura->document, page_id); + zathura_page_t *page = zathura_document_get_page(zathura->document, page_id); if (page == NULL) { goto error_out; } @@ -1503,7 +1513,8 @@ page_set(zathura_t* zathura, unsigned int page_id) zathura_document_set_current_page_number(zathura->document, page_id); bool continuous_hist_save = false; - girara_setting_get(zathura->ui.session, "continuous-hist-save", &continuous_hist_save); + girara_setting_get(zathura->ui.session, "continuous-hist-save", + &continuous_hist_save); if (continuous_hist_save) { save_fileinfo_to_db(zathura); } @@ -1515,35 +1526,41 @@ error_out: return false; } -void -statusbar_page_number_update(zathura_t* zathura) -{ +void statusbar_page_number_update(zathura_t *zathura) { if (zathura == NULL || zathura->ui.statusbar.page_number == NULL) { return; } - unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); - unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document); + unsigned int number_of_pages = + zathura_document_get_number_of_pages(zathura->document); + unsigned int current_page_number = + zathura_document_get_current_page_number(zathura->document); if (zathura->document != NULL) { - zathura_page_t* page = zathura_document_get_page(zathura->document, current_page_number); - char* page_label = zathura_page_get_label(page, NULL); + zathura_page_t *page = + zathura_document_get_page(zathura->document, current_page_number); + char *page_label = zathura_page_get_label(page, NULL); - char* page_number_text = NULL; + char *page_number_text = NULL; if (page_label != NULL) { - page_number_text = g_strdup_printf("[%s (%d/%d)]", page_label, current_page_number + 1, number_of_pages); + page_number_text = g_strdup_printf( + "[%s (%d/%d)]", page_label, current_page_number + 1, number_of_pages); g_free(page_label); } else { - page_number_text = g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages); + page_number_text = + g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages); } - girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number_text); + girara_statusbar_item_set_text(zathura->ui.session, + zathura->ui.statusbar.page_number, + page_number_text); bool page_number_in_window_title = false; - girara_setting_get(zathura->ui.session, "window-title-page", &page_number_in_window_title); + girara_setting_get(zathura->ui.session, "window-title-page", + &page_number_in_window_title); if (page_number_in_window_title == true) { - char* filename = get_formatted_filename(zathura, false); - char* title = g_strdup_printf("%s %s", filename, page_number_text); + char *filename = get_formatted_filename(zathura, false); + char *title = g_strdup_printf("%s %s", filename, page_number_text); girara_set_window_title(zathura->ui.session, title); g_free(title); g_free(filename); @@ -1551,15 +1568,15 @@ statusbar_page_number_update(zathura_t* zathura) g_free(page_number_text); } else { - girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, ""); + girara_statusbar_item_set_text(zathura->ui.session, + zathura->ui.statusbar.page_number, ""); } } -void -page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, - unsigned int pages_per_row, unsigned int first_page_column, - bool page_right_to_left) -{ +void page_widget_set_mode(zathura_t *zathura, unsigned int page_padding, + unsigned int pages_per_row, + unsigned int first_page_column, + bool page_right_to_left) { /* show at least one page */ if (pages_per_row == 0) { pages_per_row = 1; @@ -1577,9 +1594,11 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, return; } - gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL); + gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), + remove_page_from_table, NULL); - unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); + unsigned int number_of_pages = + zathura_document_get_number_of_pages(zathura->document); gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); @@ -1588,26 +1607,29 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, int x = (i + first_page_column - 1) % pages_per_row; int y = (i + first_page_column - 1) / pages_per_row; - GtkWidget* page_widget = zathura->pages[i]; + GtkWidget *page_widget = zathura->pages[i]; if (page_right_to_left) { x = pages_per_row - 1 - x; } + //@debug + fprintf(stderr, "x:: %d\n", x); + fprintf(stderr, "y:: %d\n", y); + gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1); } gtk_widget_show_all(zathura->ui.page_widget); } -bool -position_set(zathura_t* zathura, double position_x, double position_y) -{ +bool position_set(zathura_t *zathura, double position_x, double position_y) { if (zathura == NULL || zathura->document == NULL) { return false; } double comppos_x, comppos_y; - const unsigned int page_id = zathura_document_get_current_page_number(zathura->document); + const unsigned int page_id = + zathura_document_get_current_page_number(zathura->document); bool vertical_center = false; girara_setting_get(zathura->ui.session, "vertical-center", &vertical_center); @@ -1615,14 +1637,17 @@ position_set(zathura_t* zathura, double position_x, double position_y) /* xalign = 0.5: center horizontally (with the page, not the document) */ if (vertical_center == true) { /* yalign = 0.5: center vertically */ - page_number_to_position(zathura->document, page_id, 0.5, 0.5, &comppos_x, &comppos_y); + page_number_to_position(zathura->document, page_id, 0.5, 0.5, &comppos_x, + &comppos_y); } else { /* yalign = 0.0: align page an viewport edges at the top */ - page_number_to_position(zathura->document, page_id, 0.5, 0.0, &comppos_x, &comppos_y); + page_number_to_position(zathura->document, page_id, 0.5, 0.0, &comppos_x, + &comppos_y); } /* automatic horizontal adjustment */ - zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document); + zathura_adjust_mode_t adjust_mode = + zathura_document_get_adjust_mode(zathura->document); /* negative position_x mean: use the computed value */ if (position_x < 0) { @@ -1632,9 +1657,8 @@ position_set(zathura_t* zathura, double position_x, double position_y) /* center horizontally */ if (adjust_mode == ZATHURA_ADJUST_BESTFIT || - adjust_mode == ZATHURA_ADJUST_WIDTH || - zoom_center == true) { - position_x = 0.5; + adjust_mode == ZATHURA_ADJUST_WIDTH || zoom_center == true) { + position_x = 0.5; } } @@ -1645,6 +1669,9 @@ position_set(zathura_t* zathura, double position_x, double position_y) /* set the position */ zathura_document_set_position_x(zathura->document, position_x); zathura_document_set_position_y(zathura->document, position_y); + //@debug + fprintf(stderr, "position x %f\n", position_x); + fprintf(stderr, "position y %f\n", position_y); /* trigger a 'change' event for both adjustments */ refresh_view(zathura); @@ -1652,26 +1679,23 @@ position_set(zathura_t* zathura, double position_x, double position_y) return true; } -void -refresh_view(zathura_t* zathura) -{ +void refresh_view(zathura_t *zathura) { g_return_if_fail(zathura != NULL); /* emit a custom refresh-view signal */ - g_signal_emit(zathura->ui.session->gtk.view, zathura->signals.refresh_view, - 0, zathura); + g_signal_emit(zathura->ui.session->gtk.view, zathura->signals.refresh_view, 0, + zathura); } -bool -adjust_view(zathura_t* zathura) -{ +bool adjust_view(zathura_t *zathura) { g_return_val_if_fail(zathura != NULL, false); if (zathura->ui.page_widget == NULL || zathura->document == NULL) { goto error_ret; } - zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document); + zathura_adjust_mode_t adjust_mode = + zathura_document_get_adjust_mode(zathura->document); if (adjust_mode == ZATHURA_ADJUST_NONE) { /* there is nothing todo */ goto error_ret; @@ -1682,10 +1706,13 @@ adjust_view(zathura_t* zathura) unsigned int view_height = 0, view_width = 0; zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); - zathura_document_get_document_size(zathura->document, &document_height, &document_width); - zathura_document_get_viewport_size(zathura->document, &view_height, &view_width); + zathura_document_get_document_size(zathura->document, &document_height, + &document_width); + zathura_document_get_viewport_size(zathura->document, &view_height, + &view_width); - if (view_height == 0 || view_width == 0 || cell_height == 0 || cell_width == 0 || document_width == 0) { + if (view_height == 0 || view_width == 0 || cell_height == 0 || + cell_width == 0 || document_width == 0) { goto error_ret; } @@ -1706,11 +1733,12 @@ adjust_view(zathura_t* zathura) /* save new zoom and recompute cell size */ zathura_document_set_zoom(zathura->document, newzoom); unsigned int new_cell_height = 0, new_cell_width = 0; - zathura_document_get_cell_size(zathura->document, &new_cell_height, &new_cell_width); + zathura_document_get_cell_size(zathura->document, &new_cell_height, + &new_cell_width); /* - * XXX requiring a larger difference apparently circumvents #94 for some users; this is not a - * proper fix + * XXX requiring a larger difference apparently circumvents #94 for some + * users; this is not a proper fix */ static const int min_change = 2; /* if the change in zoom changes page cell dimensions, render */ @@ -1728,11 +1756,9 @@ error_ret: } #ifdef G_OS_UNIX -static gboolean -zathura_signal_sigterm(gpointer data) -{ +static gboolean zathura_signal_sigterm(gpointer data) { if (data != NULL) { - zathura_t* zathura = data; + zathura_t *zathura = data; cb_destroy(NULL, zathura); }