From f1d263de426537c5463d6b8ea38005d0ef2fc77c Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 18 Jul 2013 07:27:23 +0300 Subject: [PATCH] styling --- src/zathura.c | 1041 +++++++++++++++++++++++---------------------------------- 1 file changed, 419 insertions(+), 622 deletions(-) diff --git a/src/zathura.c b/src/zathura.c index 03f4ba8..f311696 100644 --- a/src/zathura.c +++ b/src/zathura.c @@ -30,6 +30,18 @@ #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) #define CLEAN(m) (m&~(GDK_MOD5_MASK|GDK_MOD2_MASK|GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK|GDK_BUTTON4_MASK|GDK_BUTTON5_MASK|GDK_LEAVE_NOTIFY_MASK)) +#define MTLOCK_PDFOBJ() do { g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); } while (0) +#define MTUNLOCK_PDFOBJ() do { g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); } while (0) + +#define MTLOCK_PDFLIB() do { g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); } while (0) +#define MTUNLOCK_PDFLIB() do { g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); } while (0) + +#define MTLOCK_SEARCH() do { g_static_mutex_lock(&(Zathura.Lock.search_lock)); } while (0) +#define MTUNLOCK_SEARCH() do { g_static_mutex_unlock(&(Zathura.Lock.search_lock)); } while (0) + +#define MTLOCK_SELECT() do { g_static_mutex_lock(&(Zathura.Lock.select_lock)); } while (0) +#define MTUNLOCK_SELECT() do { g_static_mutex_unlock(&(Zathura.Lock.select_lock)); } while (0) + // just remove the #if-#define-#endif block if support for poppler versions // before 0.15 is dropped @@ -646,30 +658,30 @@ void init_zathura (void) { g_static_mutex_init(&(Zathura.Lock.select_lock)); /* other */ - Zathura.Global.mode = NORMAL; - Zathura.Global.viewing_mode = NORMAL; - Zathura.Global.recolor = 0; - Zathura.Global.goto_mode = GOTO_MODE; - Zathura.Global.show_index = FALSE; - Zathura.Global.show_inputbar = TRUE; + Zathura.Global.mode = NORMAL; + Zathura.Global.viewing_mode = NORMAL; + Zathura.Global.recolor = 0; + Zathura.Global.goto_mode = GOTO_MODE; + Zathura.Global.show_index = FALSE; + Zathura.Global.show_inputbar = TRUE; Zathura.Global.show_statusbar = TRUE; - Zathura.State.pages = g_strdup(""); + Zathura.State.pages = g_strdup(""); Zathura.State.scroll_percentage = 0; - Zathura.Marker.markers = NULL; - Zathura.Marker.number_of_markers = 0; - Zathura.Marker.last = -1; + Zathura.Marker.markers = NULL; + Zathura.Marker.number_of_markers = 0; + Zathura.Marker.last = -1; Zathura.Search.results = NULL; - Zathura.Search.page = 0; - Zathura.Search.draw = FALSE; - Zathura.Search.query = NULL; + Zathura.Search.page = 0; + Zathura.Search.draw = FALSE; + Zathura.Search.query = NULL; Zathura.FileMonitor.monitor = NULL; - Zathura.FileMonitor.file = NULL; + Zathura.FileMonitor.file = NULL; - Zathura.StdinSupport.file = NULL; + Zathura.StdinSupport.file = NULL; /* window */ if (Zathura.UI.embed) { @@ -679,15 +691,15 @@ void init_zathura (void) { } /* UI */ - Zathura.UI.box = GTK_BOX(gtk_vbox_new(FALSE, 0)); - Zathura.UI.continuous = GTK_BOX(gtk_vbox_new(FALSE, 0)); - Zathura.UI.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); - Zathura.UI.viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL)); - Zathura.UI.drawing_area = gtk_drawing_area_new(); - Zathura.UI.statusbar = gtk_event_box_new(); + Zathura.UI.box = GTK_BOX(gtk_vbox_new(FALSE, 0)); + Zathura.UI.continuous = GTK_BOX(gtk_vbox_new(FALSE, 0)); + Zathura.UI.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); + Zathura.UI.viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL)); + Zathura.UI.drawing_area = gtk_drawing_area_new(); + Zathura.UI.statusbar = gtk_event_box_new(); Zathura.UI.statusbar_entries = GTK_BOX(gtk_hbox_new(FALSE, 0)); - Zathura.UI.inputbar = GTK_ENTRY(gtk_entry_new()); - Zathura.UI.document = gtk_event_box_new(); + Zathura.UI.inputbar = GTK_ENTRY(gtk_entry_new()); + Zathura.UI.document = gtk_event_box_new(); /* window */ gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura"); @@ -706,15 +718,15 @@ void init_zathura (void) { gtk_container_add(GTK_CONTAINER(Zathura.UI.document), GTK_WIDGET(Zathura.UI.drawing_area)); gtk_widget_add_events(GTK_WIDGET(Zathura.UI.document), GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK); - g_signal_connect(G_OBJECT(Zathura.UI.document), "button-press-event", G_CALLBACK(cb_view_button_pressed), NULL); + g_signal_connect(G_OBJECT(Zathura.UI.document), "button-press-event", G_CALLBACK(cb_view_button_pressed), NULL); g_signal_connect(G_OBJECT(Zathura.UI.document), "button-release-event", G_CALLBACK(cb_view_button_release), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.document), "motion-notify-event", G_CALLBACK(cb_view_motion_notify), NULL); + g_signal_connect(G_OBJECT(Zathura.UI.document), "motion-notify-event", G_CALLBACK(cb_view_motion_notify), NULL); gtk_widget_show(Zathura.UI.document); /* view */ - g_signal_connect(G_OBJECT(Zathura.UI.view), "key-press-event", G_CALLBACK(cb_view_kb_pressed), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.view), "size-allocate", G_CALLBACK(cb_view_resized), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.view), "scroll-event", G_CALLBACK(cb_view_scrolled), NULL); + g_signal_connect(G_OBJECT(Zathura.UI.view), "key-press-event", G_CALLBACK(cb_view_kb_pressed), NULL); + g_signal_connect(G_OBJECT(Zathura.UI.view), "size-allocate", G_CALLBACK(cb_view_resized), NULL); + g_signal_connect(G_OBJECT(Zathura.UI.view), "scroll-event", G_CALLBACK(cb_view_scrolled), NULL); gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport)); gtk_viewport_set_shadow_type(Zathura.UI.viewport, GTK_SHADOW_NONE); @@ -723,8 +735,8 @@ void init_zathura (void) { g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); /* statusbar */ - Zathura.Global.status_text = GTK_LABEL(gtk_label_new(NULL)); - Zathura.Global.status_state = GTK_LABEL(gtk_label_new(NULL)); + Zathura.Global.status_text = GTK_LABEL(gtk_label_new(NULL)); + Zathura.Global.status_state = GTK_LABEL(gtk_label_new(NULL)); Zathura.Global.status_buffer = GTK_LABEL(gtk_label_new(NULL)); gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_text), 0.0, 0.0); @@ -818,9 +830,9 @@ void draw (int page_id) { if (Zathura.PDF.surface) cairo_surface_destroy(Zathura.PDF.surface); Zathura.PDF.surface = NULL; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(current_page->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if (rotate == 0 || rotate == 180) { width = page_width*scale; @@ -850,9 +862,9 @@ void draw (int page_id) { if (scale != 1.0) cairo_scale(cairo, scale, scale); if (rotate != 0) cairo_rotate(cairo, rotate*G_PI/180.0); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_render(current_page->page, cairo); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); cairo_restore(cairo); cairo_destroy(cairo); @@ -923,9 +935,9 @@ void calculate_offset (GtkWidget *widget, double *offset_x, double *offset_y) { double scale = ((double)Zathura.PDF.scale/100.0); int window_x, window_y; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if (Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180) { width = page_width*scale; @@ -990,7 +1002,7 @@ void close_file (gboolean keep_monitor) { g_free(Zathura.State.filename); Zathura.State.filename = g_strdup((char *)default_text); - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); + MTLOCK_PDFOBJ(); Zathura.PDF.document = NULL; if (!keep_monitor) { @@ -1004,7 +1016,7 @@ void close_file (gboolean keep_monitor) { } Zathura.PDF.number_of_pages = 0; Zathura.PDF.page_offset = 0; - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); /* destroy index */ if (Zathura.UI.index) { @@ -1089,7 +1101,7 @@ void notify (int level, const char *message) { gboolean open_file (char *path, char *password) { - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); + MTLOCK_PDFOBJ(); /* specify path max */ size_t pm; @@ -1117,7 +1129,7 @@ gboolean open_file (char *path, char *password) { notify(ERROR, "File does not exist"); g_free(file); g_free(rpath); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); return FALSE; } g_free(rpath); @@ -1126,14 +1138,14 @@ gboolean open_file (char *path, char *password) { if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) { notify(ERROR, "File does not exist"); g_free(file); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); return FALSE; } /* close old file */ - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); close_file(FALSE); - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); + MTLOCK_PDFOBJ(); /* format path */ GError *error = NULL; @@ -1144,21 +1156,21 @@ gboolean open_file (char *path, char *password) { notify(ERROR, message); g_free(message); g_error_free(error); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); return FALSE; } /* open file */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); Zathura.PDF.document = poppler_document_new_from_file(file_uri, password, &error); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if (!Zathura.PDF.document) { if (error->code == 1) { g_free(file_uri); g_error_free(error); Zathura.PDF.file = file; - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); enter_password(); return FALSE; } else { @@ -1167,7 +1179,7 @@ gboolean open_file (char *path, char *password) { g_free(file_uri); g_free(message); g_error_free(error); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); return FALSE; } } @@ -1188,9 +1200,9 @@ gboolean open_file (char *path, char *password) { g_free(file_uri); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); Zathura.PDF.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); g_free(Zathura.PDF.file); Zathura.PDF.file = file; Zathura.PDF.scale = 100; @@ -1202,7 +1214,7 @@ gboolean open_file (char *path, char *password) { if (!Zathura.PDF.pages) out_of_memory(); /* get pages and check label mode */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); Zathura.Global.enable_labelmode = FALSE; for (int i = 0; i < Zathura.PDF.number_of_pages; ++i) { @@ -1217,7 +1229,7 @@ gboolean open_file (char *path, char *password) { int label_int = atoi(Zathura.PDF.pages[i]->label); if (label_int == 0 || label_int != i+1) Zathura.Global.enable_labelmode = TRUE; } - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); /* set correct goto mode */ if (!Zathura.Global.enable_labelmode && GOTO_MODE == GOTO_LABELS) Zathura.Global.goto_mode = GOTO_DEFAULT; @@ -1271,19 +1283,18 @@ gboolean open_file (char *path, char *password) { set_page(start_page); update_status(); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); isc_abort(NULL); return TRUE; } gboolean open_stdin (gchar *password) { - GError* error = NULL; - gchar* file = NULL; + GError *error = NULL; + gchar *file = NULL; gint handle = g_file_open_tmp("zathura.stdin.XXXXXX.pdf", &file, &error); - if (handle == -1) - { - gchar* message = g_strdup_printf("Can not create temporary file: %s", error->message); + if (handle == -1) { + gchar *message = g_strdup_printf("Can not create temporary file: %s", error->message); notify(ERROR, message); g_free(message); g_error_free(error); @@ -1292,9 +1303,8 @@ gboolean open_stdin (gchar *password) { // read from stdin and dump to temporary file int stdinfno = fileno(stdin); - if (stdinfno == -1) - { - gchar* message = g_strdup_printf("Can not read from stdin."); + if (stdinfno == -1) { + gchar *message = g_strdup_printf("Can not read from stdin."); notify(ERROR, message); g_free(message); close(handle); @@ -1306,11 +1316,9 @@ gboolean open_stdin (gchar *password) { char buffer[BUFSIZ]; ssize_t count = 0; - while ((count = read(stdinfno, buffer, BUFSIZ)) > 0) - { - if (write(handle, buffer, count) != count) - { - gchar* message = g_strdup_printf("Can not write to temporary file: %s", file); + while ((count = read(stdinfno, buffer, BUFSIZ)) > 0) { + if (write(handle, buffer, count) != count) { + gchar *message = g_strdup_printf("Can not write to temporary file: %s", file); notify(ERROR, message); g_free(message); close(handle); @@ -1321,9 +1329,8 @@ gboolean open_stdin (gchar *password) { } close(handle); - if (count != 0) - { - gchar* message = g_strdup_printf("Can not read from stdin."); + if (count != 0) { + gchar *message = g_strdup_printf("Can not read from stdin."); notify(ERROR, message); g_free(message); g_unlink(file); @@ -1332,8 +1339,7 @@ gboolean open_stdin (gchar *password) { } /* update data */ - if (Zathura.StdinSupport.file) - g_unlink(Zathura.StdinSupport.file); + if (Zathura.StdinSupport.file) g_unlink(Zathura.StdinSupport.file); g_free(Zathura.StdinSupport.file); Zathura.StdinSupport.file = file; @@ -1342,8 +1348,8 @@ gboolean open_stdin (gchar *password) { void open_uri (char *uri) { - char* escaped_uri = g_shell_quote(uri); - char* uri_cmd = g_strdup_printf(uri_command, escaped_uri); + char *escaped_uri = g_shell_quote(uri); + char *uri_cmd = g_strdup_printf(uri_command, escaped_uri); system(uri_cmd); g_free(uri_cmd); g_free(escaped_uri); @@ -1358,20 +1364,14 @@ void out_of_memory (void) { void *safe_realloc (void **ptr, size_t nmemb, size_t size) { static const size_t limit = ~((size_t)0u); - void* tmp = NULL; - + void *tmp = NULL; /* Check for overflow. */ - if(nmemb > limit / size) - goto failure; - - tmp = realloc(*ptr, nmemb * size); + if (nmemb > limit/size) goto failure; + tmp = realloc(*ptr, nmemb*size); /* Check for out of memory. */ - if(!tmp) - goto failure; - + if (!tmp) goto failure; *ptr = tmp; return *ptr; - /* Error handling. */ failure: free(*ptr); @@ -1382,23 +1382,18 @@ failure: void update_status (void) { /* update text */ - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename); - + gtk_label_set_markup((GtkLabel *)Zathura.Global.status_text, Zathura.State.filename); /* update pages */ - if( Zathura.PDF.document && Zathura.PDF.pages ) - { + if (Zathura.PDF.document && Zathura.PDF.pages) { int page = Zathura.PDF.page_number; g_free(Zathura.State.pages); - - Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages); + Zathura.State.pages = g_strdup_printf("[%i/%i]", page+1, Zathura.PDF.number_of_pages); } - /* update state */ - char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : g_strdup(""); - char* goto_mode = (Zathura.Global.goto_mode == GOTO_LABELS) ? "L" : - (Zathura.Global.goto_mode == GOTO_OFFSET) ? "O" : "D"; - char* status_text = g_strdup_printf("%s [%s] %s (%d%%)", zoom_level, goto_mode, Zathura.State.pages, Zathura.State.scroll_percentage); - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text); + char *zoom_level = (Zathura.PDF.scale != 0 ? g_strdup_printf("%d%%", Zathura.PDF.scale) : g_strdup("")); + char *goto_mode = (Zathura.Global.goto_mode == GOTO_LABELS ? "L" : (Zathura.Global.goto_mode == GOTO_OFFSET ? "O" : "D")); + char *status_text = g_strdup_printf("%s [%s] %s (%d%%)", zoom_level, goto_mode, Zathura.State.pages, Zathura.State.scroll_percentage); + gtk_label_set_markup((GtkLabel *)Zathura.Global.status_state, status_text); g_free(status_text); g_free(zoom_level); } @@ -1406,22 +1401,16 @@ void update_status (void) { void read_bookmarks_file (void) { /* free it at first */ - if (Zathura.Bookmarks.data) - g_key_file_free(Zathura.Bookmarks.data); - + if (Zathura.Bookmarks.data) g_key_file_free(Zathura.Bookmarks.data); /* create or open existing bookmark file */ Zathura.Bookmarks.data = g_key_file_new(); - if(!g_file_test(Zathura.Bookmarks.file, G_FILE_TEST_IS_REGULAR)) - { + if (!g_file_test(Zathura.Bookmarks.file, G_FILE_TEST_IS_REGULAR)) { /* file does not exist */ g_file_set_contents(Zathura.Bookmarks.file, "# Zathura bookmarks\n", -1, NULL); } - - GError* error = NULL; - if(!g_key_file_load_from_file(Zathura.Bookmarks.data, Zathura.Bookmarks.file, - G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) - { - gchar* message = g_strdup_printf("Could not load bookmark file: %s", error->message); + GError *error = NULL; + if (!g_key_file_load_from_file(Zathura.Bookmarks.data, Zathura.Bookmarks.file, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) { + gchar *message = g_strdup_printf("Could not load bookmark file: %s", error->message); notify(ERROR, message); g_free(message); } @@ -1429,83 +1418,59 @@ void read_bookmarks_file (void) { void write_bookmarks_file (void) { - if (!Zathura.Bookmarks.data) - /* nothing to do */ - return; - + if (!Zathura.Bookmarks.data) return; /* nothing to do */ /* save bookmarks */ - for(int i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file, - Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page); + for (int i = 0; i < Zathura.Bookmarks.number_of_bookmarks; ++i) { + g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file, Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page); } - /* convert file and save it */ - gchar* bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL); + gchar *bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL); g_file_set_contents(Zathura.Bookmarks.file, bookmarks, -1, NULL); g_free(bookmarks); } void free_bookmarks (void) { - for(int i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - g_free(Zathura.Bookmarks.bookmarks[i].id); - } + for (int i = 0; i < Zathura.Bookmarks.number_of_bookmarks; ++i) g_free(Zathura.Bookmarks.bookmarks[i].id); free(Zathura.Bookmarks.bookmarks); Zathura.Bookmarks.bookmarks = NULL; Zathura.Bookmarks.number_of_bookmarks = 0; } -void read_configuration_file (const char* rcfile) { - if(!rcfile) - return; - - if(!g_file_test(rcfile, G_FILE_TEST_IS_REGULAR)) - return; - - char* content = NULL; - if(g_file_get_contents(rcfile, &content, NULL, NULL)) - { +void read_configuration_file (const char *rcfile) { + if (!rcfile) return; + if (!g_file_test(rcfile, G_FILE_TEST_IS_REGULAR)) return; + char *content = NULL; + if (g_file_get_contents(rcfile, &content, NULL, NULL)) { gchar **lines = g_strsplit(content, "\n", -1); - int n = g_strv_length(lines) - 1; - - int i; - for(i = 0; i <= n; i++) - { - if(!strlen(lines[i])) - continue; - + int n = g_strv_length(lines)-1; + for (int i = 0; i <= n; ++i) { + if (!strlen(lines[i])) continue; gchar **pre_tokens = g_strsplit_set(lines[i], "\t ", -1); - int pre_length = g_strv_length(pre_tokens); - + int pre_length = g_strv_length(pre_tokens); gchar** tokens = g_malloc0(sizeof(gchar*) * (pre_length + 1)); - gchar** tokp = tokens; - int length = 0; - for (int i = 0; i != pre_length; ++i) { - if (strlen(pre_tokens[i])) { - *tokp++ = pre_tokens[i]; + gchar** tokp = tokens; + int length = 0; + for (int f = 0; f != pre_length; ++f) { + if (strlen(pre_tokens[f])) { + *tokp++ = pre_tokens[f]; ++length; } } - - if(!strcmp(tokens[0], "set")) - cmd_set(length - 1, tokens + 1); - else if(!strcmp(tokens[0], "map")) - cmd_map(length - 1, tokens + 1); - + if (!strcmp(tokens[0], "set")) cmd_set(length-1, tokens+1); + else if (!strcmp(tokens[0], "map")) cmd_map(length-1, tokens+1); g_free(tokens); } - g_strfreev(lines); g_free(content); } } + void read_configuration (void) { - char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL); + char *zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL); read_configuration_file(GLOBAL_RC); read_configuration_file(zathurarc); g_free(zathurarc); @@ -1518,140 +1483,109 @@ void recalc_rectangle (int page_id, PopplerRectangle* rectangle) { double x2 = rectangle->x2; double y1 = rectangle->y1; double y2 = rectangle->y2; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - double scale = ((double) Zathura.PDF.scale / 100.0); - + MTUNLOCK_PDFLIB(); + double scale = ((double) Zathura.PDF.scale/100.0); int rotate = Zathura.PDF.rotate; - - switch(rotate) - { + switch (rotate) { case 90: - rectangle->x1 = y2 * scale; - rectangle->y1 = x1 * scale; - rectangle->x2 = y1 * scale; - rectangle->y2 = x2 * scale; + rectangle->x1 = y2*scale; + rectangle->y1 = x1*scale; + rectangle->x2 = y1*scale; + rectangle->y2 = x2*scale; break; case 180: - rectangle->x1 = (page_width - x2) * scale; - rectangle->y1 = y2 * scale; - rectangle->x2 = (page_width - x1) * scale; - rectangle->y2 = y1 * scale; + rectangle->x1 = (page_width-x2)*scale; + rectangle->y1 = y2*scale; + rectangle->x2 = (page_width-x1)*scale; + rectangle->y2 = y1*scale; break; case 270: - rectangle->x1 = (page_height - y1) * scale; - rectangle->y1 = (page_width - x2) * scale; - rectangle->x2 = (page_height - y2) * scale; - rectangle->y2 = (page_width - x1) * scale; + rectangle->x1 = (page_height-y1)*scale; + rectangle->y1 = (page_width-x2)*scale; + rectangle->x2 = (page_height-y2)*scale; + rectangle->y2 = (page_width-x1)*scale; break; default: - rectangle->x1 = x1 * scale; - rectangle->y1 = (page_height - y1) * scale; - rectangle->x2 = x2 * scale; - rectangle->y2 = (page_height - y2) * scale; + rectangle->x1 = x1*scale; + rectangle->y1 = (page_height-y1)*scale; + rectangle->x2 = x2*scale; + rectangle->y2 = (page_height-y2)*scale; + break; } } -GtkEventBox *create_completion_row (GtkBox* results, char* command, char* description, gboolean group) { - GtkBox *col = GTK_BOX(gtk_hbox_new(FALSE, 0)); +GtkEventBox *create_completion_row (GtkBox *results, char *command, char *description, gboolean group) { + GtkBox *col = GTK_BOX(gtk_hbox_new(FALSE, 0)); GtkEventBox *row = GTK_EVENT_BOX(gtk_event_box_new()); - - GtkLabel *show_command = GTK_LABEL(gtk_label_new(NULL)); + GtkLabel *show_command = GTK_LABEL(gtk_label_new(NULL)); GtkLabel *show_description = GTK_LABEL(gtk_label_new(NULL)); - - gtk_misc_set_alignment(GTK_MISC(show_command), 0.0, 0.0); + gtk_misc_set_alignment(GTK_MISC(show_command), 0.0, 0.0); gtk_misc_set_alignment(GTK_MISC(show_description), 0.0, 0.0); - - if(group) - { - gtk_misc_set_padding(GTK_MISC(show_command), 2.0, 4.0); + if (group) { + gtk_misc_set_padding(GTK_MISC(show_command), 2.0, 4.0); gtk_misc_set_padding(GTK_MISC(show_description), 2.0, 4.0); - } - else - { - gtk_misc_set_padding(GTK_MISC(show_command), 1.0, 1.0); + } else { + gtk_misc_set_padding(GTK_MISC(show_command), 1.0, 1.0); gtk_misc_set_padding(GTK_MISC(show_description), 1.0, 1.0); } - - gtk_label_set_use_markup(show_command, TRUE); + gtk_label_set_use_markup(show_command, TRUE); gtk_label_set_use_markup(show_description, TRUE); - - gchar* c = g_markup_printf_escaped(FORMAT_COMMAND, command ? command : ""); - gchar* d = g_markup_printf_escaped(FORMAT_DESCRIPTION, description ? description : ""); - gtk_label_set_markup(show_command, c); + gchar *c = g_markup_printf_escaped(FORMAT_COMMAND, (command ? command : "")); + gchar *d = g_markup_printf_escaped(FORMAT_DESCRIPTION, (description ? description : "")); + gtk_label_set_markup(show_command, c); gtk_label_set_markup(show_description, d); g_free(c); g_free(d); - - if(group) - { - gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg)); + if (group) { + gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg)); gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_bg)); - } - else - { - gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); + gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_bg)); + } else { + gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); + gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); } - - gtk_widget_modify_font(GTK_WIDGET(show_command), Zathura.Style.font); + gtk_widget_modify_font(GTK_WIDGET(show_command), Zathura.Style.font); gtk_widget_modify_font(GTK_WIDGET(show_description), Zathura.Style.font); - - gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_command), TRUE, TRUE, 2); + gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_command), TRUE, TRUE, 2); gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_description), FALSE, FALSE, 2); - gtk_container_add(GTK_CONTAINER(row), GTK_WIDGET(col)); - gtk_box_pack_start(results, GTK_WIDGET(row), FALSE, FALSE, 0); - return row; } void set_completion_row_color (GtkBox *results, int mode, int id) { - GtkEventBox *row = (GtkEventBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(results)), id); - - if(row) - { - GtkBox *col = (GtkBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(row)), 0); - GtkLabel *cmd = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 0); - GtkLabel *cdesc = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 1); - - if(mode == NORMAL) - { - gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); + GtkEventBox *row = (GtkEventBox *)g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(results)), id); + if (row) { + GtkBox *col = (GtkBox *)g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(row)), 0); + GtkLabel *cmd = (GtkLabel *)g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 0); + GtkLabel *cdesc = (GtkLabel *)g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 1); + if (mode == NORMAL) { + gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); - } - else - { - gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg)); + gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); + } else { + gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg)); gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_bg)); + gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_bg)); } } } void set_page (int page) { - if(page >= Zathura.PDF.number_of_pages || page < 0) - { + if (page >= Zathura.PDF.number_of_pages || page < 0) { notify(WARNING, "Could not open page"); return; } - Zathura.PDF.page_number = page; - Zathura.Search.draw = FALSE; - + Zathura.Search.draw = FALSE; Argument argument; argument.n = TOP; - switch_view(Zathura.UI.document); draw(page); sc_scroll(&argument); @@ -1659,73 +1593,54 @@ void set_page (int page) { void switch_view (GtkWidget *widget) { - GtkWidget* child = gtk_bin_get_child(GTK_BIN(Zathura.UI.viewport)); - if(child == widget) - return; - if(child) - { + GtkWidget *child = gtk_bin_get_child(GTK_BIN(Zathura.UI.viewport)); + if (child == widget) return; + if (child) { g_object_ref(child); gtk_container_remove(GTK_CONTAINER(Zathura.UI.viewport), child); } - gtk_container_add(GTK_CONTAINER(Zathura.UI.viewport), GTK_WIDGET(widget)); } Completion *completion_init (void) { Completion *completion = malloc(sizeof(Completion)); - if(!completion) - out_of_memory(); - + if (!completion) out_of_memory(); completion->groups = NULL; - return completion; } CompletionGroup *completion_group_create (char *name) { - CompletionGroup* group = malloc(sizeof(CompletionGroup)); - if(!group) - out_of_memory(); - - group->value = name ? g_strdup(name) : NULL; + CompletionGroup *group = malloc(sizeof(CompletionGroup)); + if (!group) out_of_memory(); + group->value = (name ? g_strdup(name) : NULL); group->elements = NULL; - group->next = NULL; - + group->next = NULL; return group; } void completion_add_group (Completion *completion, CompletionGroup *group) { - CompletionGroup* cg = completion->groups; - - while(cg && cg->next) - cg = cg->next; - - if(cg) - cg->next = group; - else - completion->groups = group; + CompletionGroup *cg = completion->groups; + while (cg && cg->next) cg = cg->next; + if (cg) cg->next = group; else completion->groups = group; } void completion_free (Completion *completion) { - CompletionGroup* group = completion->groups; - CompletionElement *element; - - while(group) - { - element = group->elements; - while(element) - { - CompletionElement* ne = element->next; + CompletionGroup *group = completion->groups; + while (group) { + CompletionGroup *ng; + CompletionElement *element = group->elements; + while (element) { + CompletionElement *ne = element->next; g_free(element->value); g_free(element->description); free(element); element = ne; } - - CompletionGroup *ng = group->next; + ng = group->next; g_free(group->value); free(group); group = ng; @@ -1735,67 +1650,48 @@ void completion_free (Completion *completion) { void completion_group_add_element (CompletionGroup *group, char *name, char *description) { - CompletionElement* el = group->elements; - - while(el && el->next) - el = el->next; - - CompletionElement* new_element = malloc(sizeof(CompletionElement)); - if(!new_element) - out_of_memory(); - - new_element->value = name ? g_strdup(name) : NULL; - new_element->description = description ? g_strdup(description) : NULL; - new_element->next = NULL; - - if(el) - el->next = new_element; - else - group->elements = new_element; + CompletionElement *el = group->elements; + while (el && el->next) el = el->next; + CompletionElement *new_element = malloc(sizeof(CompletionElement)); + if (!new_element) out_of_memory(); + new_element->value = (name ? g_strdup(name) : NULL); + new_element->description = (description ? g_strdup(description) : NULL); + new_element->next = NULL; + if (el) el->next = new_element; else group->elements = new_element; } /* thread implementation */ void *search (void *parameter) { - Argument* argument = (Argument*) parameter; - - static char* search_item; + Argument *argument = (Argument *)parameter; + static char *search_item; static int direction; static int next_page = 0; - gchar* old_query = NULL; - GList* results = NULL; - - if(argument->n != NO_SEARCH) - { + gchar *old_query = NULL; + GList *results = NULL; + if (argument->n != NO_SEARCH) { /* search document */ - if(argument->n) - direction = (argument->n == BACKWARD) ? -1 : 1; - - if(argument->data) - { - if(search_item) - g_free(search_item); - - search_item = g_strdup((char*) argument->data); + if (argument->n) direction = (argument->n == BACKWARD ? -1 : 1); + if (argument->data) { + if (search_item) g_free(search_item); + search_item = g_strdup((char *)argument->data); } g_free(argument->data); g_free(argument); - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - if(!Zathura.PDF.document || !search_item || !strlen(search_item)) - { - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - g_static_mutex_lock(&(Zathura.Lock.search_lock)); + MTLOCK_PDFOBJ(); + if (!Zathura.PDF.document || !search_item || !strlen(search_item)) { + MTUNLOCK_PDFOBJ(); + MTLOCK_SEARCH(); Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + MTUNLOCK_SEARCH(); g_thread_exit(NULL); } old_query = Zathura.Search.query; /* delete old results */ - if(Zathura.Search.results) - { + if (Zathura.Search.results) { g_list_free(Zathura.Search.results); Zathura.Search.results = NULL; } @@ -1803,73 +1699,64 @@ void *search (void *parameter) { Zathura.Search.query = g_strdup(search_item); int number_of_pages = Zathura.PDF.number_of_pages; - int page_number = Zathura.PDF.page_number; + int page_number = Zathura.PDF.page_number; - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); - int page_counter = (g_strcmp0(old_query,search_item) == 0) ? 1 : 0; - for( ; page_counter <= number_of_pages; page_counter++) - { - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - if(Zathura.Thread.search_thread_running == FALSE) - { - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + int page_counter = (g_strcmp0(old_query,search_item) == 0 ? 1 : 0); + for( ; page_counter <= number_of_pages; ++page_counter) { + MTLOCK_SEARCH(); + if (Zathura.Thread.search_thread_running == FALSE) { + MTUNLOCK_SEARCH(); g_free(old_query); g_thread_exit(NULL); } - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + MTUNLOCK_SEARCH(); - next_page = (number_of_pages + page_number + - page_counter * direction) % number_of_pages; + next_page = (number_of_pages+page_number+page_counter*direction)%number_of_pages; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - PopplerPage* page = poppler_document_get_page(Zathura.PDF.document, next_page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); + PopplerPage *page = poppler_document_get_page(Zathura.PDF.document, next_page); + MTUNLOCK_PDFLIB(); - if(!page) - { + if (!page) { g_free(old_query); g_thread_exit(NULL); } - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); results = poppler_page_find_text(page, search_item); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); g_object_unref(page); - if(results) - break; + if (results) break; } - } - else - { + } else { Zathura.Search.draw = TRUE; g_free(argument->data); g_free(argument); } /* draw results */ - if(results) - { + if (results) { gdk_threads_enter(); set_page(next_page); - if(Zathura.Search.results) - g_list_free(Zathura.Search.results); + if (Zathura.Search.results) g_list_free(Zathura.Search.results); Zathura.Search.results = results; - Zathura.Search.page = next_page; - Zathura.Search.draw = TRUE; - Zathura.Search.query = g_strdup(search_item); + Zathura.Search.page = next_page; + Zathura.Search.draw = TRUE; + Zathura.Search.query = g_strdup(search_item); gdk_threads_leave(); } - g_static_mutex_lock(&(Zathura.Lock.search_lock)); + MTLOCK_SEARCH(); Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + MTUNLOCK_SEARCH(); g_free(old_query); g_thread_exit(NULL); @@ -1880,15 +1767,13 @@ void *search (void *parameter) { /* shortcut implementation */ void sc_abort (Argument *argument) { /* Clear buffer */ - if(Zathura.Global.buffer) - { + if (Zathura.Global.buffer) { g_string_free(Zathura.Global.buffer, TRUE); Zathura.Global.buffer = NULL; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); + gtk_label_set_markup((GtkLabel *)Zathura.Global.status_buffer, ""); } - if(!Zathura.Global.show_inputbar) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); + if (!Zathura.Global.show_inputbar) gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); /* Set back to normal mode */ change_mode(NORMAL); @@ -1897,40 +1782,36 @@ void sc_abort (Argument *argument) { void sc_adjust_window (Argument *argument) { - if(!Zathura.PDF.document) - return; - + if (!Zathura.PDF.document) return; Zathura.Global.adjust_mode = argument->n; - - GtkAdjustment* adjustment; + GtkAdjustment *adjustment; double view_size; double page_width; double page_height; - - if(argument->n == ADJUST_BESTFIT) + if (argument->n == ADJUST_BESTFIT) { adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); - else if(argument->n == ADJUST_WIDTH) + } else if (argument->n == ADJUST_WIDTH) { adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); - else + } else { return; + } + view_size = gtk_adjustment_get_page_size(adjustment); - view_size = gtk_adjustment_get_page_size(adjustment); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); - if ((Zathura.PDF.rotate == 90) || (Zathura.PDF.rotate == 270)) - { + if (Zathura.PDF.rotate == 90 || Zathura.PDF.rotate == 270) { double swap = page_width; - page_width = page_height; + page_width = page_height; page_height = swap; } - if(argument->n == ADJUST_BESTFIT) - Zathura.PDF.scale = (view_size / page_height) * 100; - else - Zathura.PDF.scale = (view_size / page_width) * 100; + if (argument->n == ADJUST_BESTFIT) { + Zathura.PDF.scale = (view_size/page_height)*100; + } else { + Zathura.PDF.scale = (view_size/page_width)*100; + } draw(Zathura.PDF.page_number); update_status(); @@ -1938,49 +1819,37 @@ void sc_adjust_window (Argument *argument) { void sc_change_buffer (Argument *argument) { - if(!Zathura.Global.buffer) - return; - + if (!Zathura.Global.buffer) return; int buffer_length = Zathura.Global.buffer->len; - - if(argument->n == DELETE_LAST) - { - if((buffer_length - 1) == 0) - { + if (argument->n == DELETE_LAST) { + if (buffer_length-1 == 0) { g_string_free(Zathura.Global.buffer, TRUE); Zathura.Global.buffer = NULL; gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); - } - else - { - GString* temp = g_string_new_len(Zathura.Global.buffer->str, buffer_length - 1); + } else { + GString *temp = g_string_new_len(Zathura.Global.buffer->str, buffer_length-1); g_string_free(Zathura.Global.buffer, TRUE); Zathura.Global.buffer = temp; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str); + gtk_label_set_markup((GtkLabel *)Zathura.Global.status_buffer, Zathura.Global.buffer->str); } } } void sc_change_mode (Argument *argument) { - if(argument) - change_mode(argument->n); + if (argument) change_mode(argument->n); } void sc_focus_inputbar (Argument *argument) { - if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.inputbar)))) - gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); - - if(argument->data) - { - char* data = argument->data; - - if(argument->n == APPEND_FILEPATH) - data = g_strdup_printf("%s%s", data, Zathura.PDF.file); - else - data = g_strdup(data); - + if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.inputbar)))) gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); + if (argument->data) { + char *data; + if (argument->n == APPEND_FILEPATH) { + data = g_strdup_printf("%s%s", (const char *)argument->data, Zathura.PDF.file); + } else { + data = g_strdup((const char *)argument->data); + } notify(DEFAULT, data); g_free(data); gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar)); @@ -1990,39 +1859,32 @@ void sc_focus_inputbar (Argument *argument) { void sc_follow (Argument *argument) { - if(!Zathura.PDF.document) - return; - - Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number]; + if (!Zathura.PDF.document) return; + Page *current_page = Zathura.PDF.pages[Zathura.PDF.page_number]; int link_id = 1; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); GList *link_list = poppler_page_get_link_mapping(current_page->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); link_list = g_list_reverse(link_list); - if(g_list_length(link_list) <= 0) - return; + if (g_list_length(link_list) <= 0) return; - GList *links; - for(links = link_list; links; links = g_list_next(links)) - { - PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data; - PopplerRectangle* link_rectangle = &link_mapping->area; - PopplerAction *action = link_mapping->action; + for (GList *links = link_list; links; links = g_list_next(links)) { + PopplerLinkMapping *link_mapping = (PopplerLinkMapping *)links->data; + PopplerRectangle *link_rectangle = &link_mapping->area; + PopplerAction *action = link_mapping->action; /* only handle URI and internal links */ - if(action->type == POPPLER_ACTION_URI || action->type == POPPLER_ACTION_GOTO_DEST) - { + if (action->type == POPPLER_ACTION_URI || action->type == POPPLER_ACTION_GOTO_DEST) { highlight_result(Zathura.PDF.page_number, link_rectangle); - /* draw text */ recalc_rectangle(Zathura.PDF.page_number, link_rectangle); cairo_t *cairo = cairo_create(Zathura.PDF.surface); cairo_select_font_face(cairo, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cairo, 10); - cairo_move_to(cairo, link_rectangle->x1 + 1, link_rectangle->y1 - 1); - char* link_number = g_strdup_printf("%i", link_id++); + cairo_move_to(cairo, link_rectangle->x1+1, link_rectangle->y1-1); + char *link_number = g_strdup_printf("%i", link_id++); cairo_show_text(cairo, link_number); cairo_destroy(cairo); g_free(link_number); @@ -2042,19 +1904,17 @@ void sc_follow (Argument *argument) { void sc_navigate (Argument *argument) { - if(!Zathura.PDF.document) - return; + if (!Zathura.PDF.document) return; int number_of_pages = Zathura.PDF.number_of_pages; int new_page = Zathura.PDF.page_number; - if(argument->n == NEXT) - new_page = scroll_wrap ? ((new_page + 1) % number_of_pages) : (new_page + 1); - else if(argument->n == PREVIOUS) - new_page = scroll_wrap ? ((new_page + number_of_pages - 1) % number_of_pages) : (new_page - 1); - - if (!scroll_wrap && (new_page < 0 || new_page >= number_of_pages)) - return; + if (argument->n == NEXT) { + new_page = (scroll_wrap ? (new_page+1)%number_of_pages : new_page+1); + } else if (argument->n == PREVIOUS) { + new_page = (scroll_wrap ? (new_page+number_of_pages-1)%number_of_pages : new_page-1); + } + if (!scroll_wrap && (new_page < 0 || new_page >= number_of_pages)) return; set_page(new_page); update_status(); @@ -2070,84 +1930,75 @@ void sc_recolor (Argument *argument) { void sc_reload (Argument *argument) { draw(Zathura.PDF.page_number); - GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); - GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); + GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); + GtkAdjustment *hadjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); /* save old information */ - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - char* path = Zathura.PDF.file ? strdup(Zathura.PDF.file) : NULL; - char* password = Zathura.PDF.password ? strdup(Zathura.PDF.password) : NULL; - int scale = Zathura.PDF.scale; - int page = Zathura.PDF.page_number; - int rotate = Zathura.PDF.rotate; - gdouble va = gtk_adjustment_get_value(vadjustment); - gdouble ha = gtk_adjustment_get_value(hadjustment); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTLOCK_PDFOBJ(); + char *path = (Zathura.PDF.file ? strdup(Zathura.PDF.file) : NULL); + char *password = (Zathura.PDF.password ? strdup(Zathura.PDF.password) : NULL); + int scale = Zathura.PDF.scale; + int page = Zathura.PDF.page_number; + int rotate = Zathura.PDF.rotate; + gdouble va = gtk_adjustment_get_value(vadjustment); + gdouble ha = gtk_adjustment_get_value(hadjustment); + MTUNLOCK_PDFOBJ(); /* reopen and restore settings */ close_file(TRUE); open_file(path, password); - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - Zathura.PDF.scale = scale; + MTLOCK_PDFOBJ(); + Zathura.PDF.scale = scale; Zathura.PDF.rotate = rotate; gtk_adjustment_set_value(vadjustment, va); gtk_adjustment_set_value(hadjustment, ha); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + MTUNLOCK_PDFOBJ(); if (Zathura.PDF.number_of_pages != 0) { - if (page >= Zathura.PDF.number_of_pages - 1) - page = Zathura.PDF.number_of_pages - 1; + if (page >= Zathura.PDF.number_of_pages-1) page = Zathura.PDF.number_of_pages-1; Zathura.PDF.page_number = page; draw(Zathura.PDF.page_number); } - if(path) - free(path); - if(password) - free(password); + if (path) free(path); + if (password) free(password); } -void sc_rotate (Argument *argument) -{ - Zathura.PDF.rotate = (Zathura.PDF.rotate + 90) % 360; +void sc_rotate (Argument *argument) { + Zathura.PDF.rotate = (Zathura.PDF.rotate+90)%360; Zathura.Search.draw = TRUE; - draw(Zathura.PDF.page_number); } -void sc_scroll (Argument *argument) -{ - GtkAdjustment* adjustment; +void sc_scroll (Argument *argument) { + GtkAdjustment *adjustment; - if( (argument->n == LEFT) || (argument->n == RIGHT) ) + if (argument->n == LEFT || argument->n == RIGHT) { adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); - else + } else { adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); + } gdouble view_size = gtk_adjustment_get_page_size(adjustment); - gdouble value = gtk_adjustment_get_value(adjustment); - gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; + gdouble value = gtk_adjustment_get_value(adjustment); + gdouble max = gtk_adjustment_get_upper(adjustment)-view_size; static gboolean ss = FALSE; - if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0) - { + if ((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0) { int old_page = Zathura.PDF.page_number; Argument arg; arg.n = PREVIOUS; sc_navigate(&arg); - if (scroll_wrap || (Zathura.PDF.page_number < old_page)) - { + if (scroll_wrap || Zathura.PDF.page_number < old_page) { arg.n = BOTTOM; ss = TRUE; sc_scroll(&arg); } return; - } - else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max) - { + } else if ((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max) { Argument arg; arg.n = NEXT; ss = TRUE; @@ -2156,35 +2007,26 @@ void sc_scroll (Argument *argument) } gdouble new_value; - if(argument->n == FULL_UP) - new_value = (value - view_size) < 0 ? 0 : (value - view_size); - else if(argument->n == FULL_DOWN) - new_value = (value + view_size) > max ? max : (value + view_size); - else if(argument->n == HALF_UP) - new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); - else if(argument->n == HALF_DOWN) - new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); - else if((argument->n == LEFT) || (argument->n == UP)) - new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); - else if(argument->n == TOP) - new_value = 0; - else if(argument->n == BOTTOM) - new_value = max; - else - new_value = (value + scroll_step) > max ? max : (value + scroll_step); + switch (argument->n) { + case FULL_UP: new_value = (value-view_size < 0 ? 0 : value-view_size); break; + case FULL_DOWN: new_value = (value+view_size > max ? max : value+view_size); break; + case HALF_UP: new_value = (value-view_size/2 < 0 ? 0 : value-view_size/2); break; + case HALF_DOWN: new_value = (value+view_size/2 > max ? max : value+view_size/2); break; + case LEFT: case UP: new_value = (value-scroll_step < 0 ? 0 : value-scroll_step); break; + case TOP: new_value = 0; break; + case BOTTOM: new_value = max; break; + default: new_value = (value+scroll_step > max ? max : value+scroll_step); break; + } - if( !((argument->n == LEFT) || (argument->n == RIGHT)) ) - Zathura.State.scroll_percentage = max == 0 ? 0 : (new_value*100/max); + if (!(argument->n == LEFT || argument->n == RIGHT)) Zathura.State.scroll_percentage = (max == 0 ? 0 : new_value*100/max); - if(smooth_scrolling && !ss) - { + if (smooth_scrolling && !ss) { gdouble i; - if(new_value > value) - for(i = value; (i + smooth_scrolling) < new_value; i += smooth_scrolling) - gtk_adjustment_set_value(adjustment, i); - else - for(i = value; (i + smooth_scrolling) > new_value; i -= smooth_scrolling) - gtk_adjustment_set_value(adjustment, i); + if (new_value > value) { + for (i = value; i+smooth_scrolling < new_value; i += smooth_scrolling) gtk_adjustment_set_value(adjustment, i); + } else { + for (i = value; i+smooth_scrolling > new_value; i -= smooth_scrolling) gtk_adjustment_set_value(adjustment, i); + } } gtk_adjustment_set_value(adjustment, new_value); @@ -2194,82 +2036,62 @@ void sc_scroll (Argument *argument) } -void sc_search (Argument *argument) -{ - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - if(Zathura.Thread.search_thread_running) - { +void sc_search (Argument *argument) { + MTLOCK_SEARCH(); + if (Zathura.Thread.search_thread_running) { Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + MTUNLOCK_SEARCH(); gdk_threads_leave(); g_thread_join(Zathura.Thread.search_thread); gdk_threads_enter(); - g_static_mutex_lock(&(Zathura.Lock.search_lock)); + MTLOCK_SEARCH(); } - Argument* newarg = g_malloc0(sizeof(Argument)); + Argument *newarg = g_malloc0(sizeof(Argument)); newarg->n = argument->n; - newarg->data = argument->data ? g_strdup(argument->data) : NULL; + newarg->data = (argument->data ? g_strdup(argument->data) : NULL); Zathura.Thread.search_thread_running = TRUE; Zathura.Thread.search_thread = g_thread_create(search, (gpointer) newarg, TRUE, NULL); - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); + MTUNLOCK_SEARCH(); } -void sc_switch_goto_mode (Argument *argument) -{ - switch(Zathura.Global.goto_mode) - { - case GOTO_LABELS: - Zathura.Global.goto_mode = GOTO_OFFSET; - break; - case GOTO_OFFSET: - Zathura.Global.goto_mode = GOTO_DEFAULT; - break; +void sc_switch_goto_mode (Argument *argument) { + switch (Zathura.Global.goto_mode) { + case GOTO_LABELS: Zathura.Global.goto_mode = GOTO_OFFSET; break; + case GOTO_OFFSET: Zathura.Global.goto_mode = GOTO_DEFAULT; break; default: - if(Zathura.Global.enable_labelmode) - Zathura.Global.goto_mode = GOTO_LABELS; - else - Zathura.Global.goto_mode = GOTO_OFFSET; + if (Zathura.Global.enable_labelmode) Zathura.Global.goto_mode = GOTO_LABELS; else Zathura.Global.goto_mode = GOTO_OFFSET; break; } - update_status(); } -gboolean cb_index_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) -{ - GtkTreeModel *model; - GtkTreeIter iter; +gboolean cb_index_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { + GtkTreeModel *model; + GtkTreeIter iter; g_object_get(treeview, "model", &model, NULL); - if(gtk_tree_model_get_iter(model, &iter, path)) - { - PopplerAction* action; - PopplerDest* destination; + if (gtk_tree_model_get_iter(model, &iter, path)) { + PopplerAction *action; + PopplerDest *destination; gtk_tree_model_get(model, &iter, 1, &action, -1); - if(!action) - return TRUE; + if (!action) return TRUE; - if(action->type == POPPLER_ACTION_GOTO_DEST) - { + if (action->type == POPPLER_ACTION_GOTO_DEST) { destination = action->goto_dest.dest; int page_number = destination->page_num; - - if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) - { - PopplerDest* d = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest); - if(d) - { + if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) { + PopplerDest *d = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest); + if (d) { page_number = d->page_num; poppler_dest_free(d); } } - - set_page(page_number - 1); + set_page(page_number-1); update_status(); Zathura.Global.show_index = FALSE; gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.document)); @@ -2283,109 +2105,88 @@ gboolean cb_index_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTr } -void sc_navigate_index (Argument *argument) -{ - if(!Zathura.UI.index) - return; +void sc_navigate_index (Argument *argument) { + if (!Zathura.UI.index) return; GtkTreeView *treeview = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.index))->data; GtkTreePath *path; gtk_tree_view_get_cursor(treeview, &path, NULL); - if(!path) - return; + if (!path) return; GtkTreeModel *model = gtk_tree_view_get_model(treeview); - GtkTreeIter iter; - GtkTreeIter child_iter; + GtkTreeIter iter; + GtkTreeIter child_iter; gboolean is_valid_path = TRUE; - switch(argument->n) - { + switch (argument->n) { case UP: - if(!gtk_tree_path_prev(path)) - is_valid_path = (gtk_tree_path_get_depth(path) > 1) && gtk_tree_path_up(path) ; - else /* row above */ - { - while(gtk_tree_view_row_expanded(treeview, path)) { + if (!gtk_tree_path_prev(path)) { + is_valid_path = (gtk_tree_path_get_depth(path) > 1 && gtk_tree_path_up(path)); + } else { + /* row above */ + while (gtk_tree_view_row_expanded(treeview, path)) { gtk_tree_model_get_iter(model, &iter, path); /* select last child */ - gtk_tree_model_iter_nth_child(model, &child_iter, &iter, - gtk_tree_model_iter_n_children(model, &iter)-1); + gtk_tree_model_iter_nth_child(model, &child_iter, &iter, gtk_tree_model_iter_n_children(model, &iter)-1); gtk_tree_path_free(path); path = gtk_tree_model_get_path(model, &child_iter); } } break; case COLLAPSE: - if(!gtk_tree_view_collapse_row(treeview, path) - && gtk_tree_path_get_depth(path) > 1) - { + if (!gtk_tree_view_collapse_row(treeview, path) && gtk_tree_path_get_depth(path) > 1) { gtk_tree_path_up(path); gtk_tree_view_collapse_row(treeview, path); } break; case DOWN: - if(gtk_tree_view_row_expanded(treeview, path)) + if (gtk_tree_view_row_expanded(treeview, path)) { gtk_tree_path_down(path); - else - { - do - { + } else { + do { gtk_tree_model_get_iter(model, &iter, path); - if (gtk_tree_model_iter_next(model, &iter)) - { + if (gtk_tree_model_iter_next(model, &iter)) { path = gtk_tree_model_get_path(model, &iter); break; } - } - while((is_valid_path = (gtk_tree_path_get_depth(path) > 1)) - && gtk_tree_path_up(path)); + } while ((is_valid_path = (gtk_tree_path_get_depth(path) > 1)) && gtk_tree_path_up(path)); } break; case EXPAND: - if(gtk_tree_view_expand_row(treeview, path, FALSE)) - gtk_tree_path_down(path); + if (gtk_tree_view_expand_row(treeview, path, FALSE)) gtk_tree_path_down(path); break; case SELECT: cb_index_row_activated(treeview, path, NULL, NULL); return; } - if (is_valid_path ) - gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); + if (is_valid_path) gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); gtk_tree_path_free(path); } -void sc_toggle_index (Argument *argument) -{ - if(!Zathura.PDF.document) - return; +void sc_toggle_index (Argument *argument) { + if (!Zathura.PDF.document) return; - GtkWidget *treeview; - GtkTreeModel *model; - GtkCellRenderer *renderer; + GtkWidget *treeview; + GtkTreeModel *model; + GtkCellRenderer *renderer; PopplerIndexIter *iter; - if(!Zathura.UI.index) - { + if (!Zathura.UI.index) { Zathura.UI.index = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - if((iter = poppler_index_iter_new(Zathura.PDF.document))) - { + if ((iter = poppler_index_iter_new(Zathura.PDF.document))) { model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER)); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); build_index(model, NULL, iter); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); poppler_index_iter_free(iter); - } - else - { + } else { notify(WARNING, "This document does not contain any index"); Zathura.UI.index = NULL; return; @@ -2394,8 +2195,7 @@ void sc_toggle_index (Argument *argument) treeview = gtk_tree_view_new_with_model (model); g_object_unref(model); renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", - renderer, "markup", 0, NULL); + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", renderer, "markup", 0, NULL); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL); @@ -2408,13 +2208,10 @@ void sc_toggle_index (Argument *argument) gtk_widget_show(Zathura.UI.index); } - if(!Zathura.Global.show_index) - { + if (!Zathura.Global.show_index) { switch_view(Zathura.UI.index); Zathura.Global.mode = INDEX; - } - else - { + } else { switch_view(Zathura.UI.document); Zathura.Global.mode = NORMAL; } @@ -3100,9 +2897,9 @@ gboolean cmd_export (int argc, char **argv) GList *images; cairo_surface_t *image; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); image_list = poppler_page_get_image_mapping(Zathura.PDF.pages[page_number]->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if(!g_list_length(image_list)) { @@ -3120,9 +2917,9 @@ gboolean cmd_export (int argc, char **argv) image_mapping = (PopplerImageMapping*) images->data; image_id = image_mapping->image_id; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); image = poppler_page_get_image(Zathura.PDF.pages[page_number]->page, image_id); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if(!image) continue; @@ -3147,16 +2944,16 @@ gboolean cmd_export (int argc, char **argv) } else if(!strcmp(argv[0], "attachments")) { - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); if(!poppler_document_has_attachments(Zathura.PDF.document)) { notify(WARNING, "PDF file has no attachments"); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); return FALSE; } GList *attachment_list = poppler_document_get_attachments(Zathura.PDF.document); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); GList *attachments; char *file; @@ -3174,9 +2971,9 @@ gboolean cmd_export (int argc, char **argv) else file = g_strdup_printf("%s%s", argv[1], attachment->name); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_attachment_save(attachment, file, NULL); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); g_free(file); } @@ -3642,7 +3439,7 @@ gboolean save_file (int argc, char **argv, gboolean overwrite) } g_free(file_path); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); /* format path */ GError* error = NULL; if (!poppler_document_save(Zathura.PDF.document, path, &error)) @@ -3652,11 +3449,11 @@ gboolean save_file (int argc, char **argv, gboolean overwrite) notify(ERROR, message); g_free(message); g_error_free(error); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); return FALSE; } - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); g_free(path); return TRUE; @@ -4098,9 +3895,9 @@ gboolean cb_draw (GtkWidget *widget, GdkEventExpose *expose, gpointer data) { double page_width, page_height, width, height; double scale = ((double) Zathura.PDF.scale / 100.0); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); if(Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180) { @@ -4298,9 +4095,9 @@ gboolean cb_inputbar_form_activate (GtkEntry *entry, gpointer data) Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number]; int number_of_links = 0, link_id = 1, new_page_id = Zathura.PDF.page_number; - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); GList *link_list = poppler_page_get_link_mapping(current_page->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); link_list = g_list_reverse(link_list); if((number_of_links = g_list_length(link_list)) <= 0) @@ -4484,10 +4281,10 @@ gboolean cb_view_button_pressed (GtkWidget *widget, GdkEventButton *event, gpoin /* clean page */ draw(Zathura.PDF.page_number); - g_static_mutex_lock(&(Zathura.Lock.select_lock)); + MTLOCK_SELECT(); Zathura.SelectPoint.x = event->x; Zathura.SelectPoint.y = event->y; - g_static_mutex_unlock(&(Zathura.Lock.select_lock)); + MTUNLOCK_SELECT(); return TRUE; } @@ -4505,10 +4302,10 @@ gboolean cb_view_button_release (GtkWidget *widget, GdkEventButton *event, gpoin rectangle.x1 = event->x; rectangle.y1 = event->y; - g_static_mutex_lock(&(Zathura.Lock.select_lock)); + MTLOCK_SELECT(); rectangle.x2 = Zathura.SelectPoint.x; rectangle.y2 = Zathura.SelectPoint.y; - g_static_mutex_unlock(&(Zathura.Lock.select_lock)); + MTUNLOCK_SELECT(); /* calculate offset */ calculate_offset(widget, &offset_x, &offset_y); @@ -4524,9 +4321,9 @@ gboolean cb_view_button_release (GtkWidget *widget, GdkEventButton *event, gpoin gtk_widget_queue_draw(Zathura.UI.drawing_area); /* resize selection rectangle to document page */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); scale = ((double) Zathura.PDF.scale / 100.0); rectangle.x1 = (rectangle.x1 - offset_x) / scale; @@ -4585,7 +4382,7 @@ gboolean cb_view_button_release (GtkWidget *widget, GdkEventButton *event, gpoin #endif /* get selected text */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); + MTLOCK_PDFLIB(); char* selected_text = poppler_page_get_selected_text( Zathura.PDF.pages[Zathura.PDF.page_number]->page,SELECTION_STYLE, &rectangle); @@ -4595,7 +4392,7 @@ gboolean cb_view_button_release (GtkWidget *widget, GdkEventButton *event, gpoin gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), selected_text, -1); g_free(selected_text); } - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); + MTUNLOCK_PDFLIB(); return TRUE; -- 2.11.4.GIT