From 44480523ac9188b023ce6ed5c763c710e8ac9d43 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 21 Oct 2014 17:51:20 +0200 Subject: [PATCH 1/6] Pass actual event instead of NULL pointer to sc_scroll --- shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shortcuts.c b/shortcuts.c index 3e1f792..210852c 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -286,7 +286,7 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e case GIRARA_EVENT_SCROLL_LEFT: case GIRARA_EVENT_SCROLL_RIGHT: case GIRARA_EVENT_SCROLL_BIDIRECTIONAL: - return sc_scroll(session, argument, NULL, t); + return sc_scroll(session, argument, event, t); /* drag */ case GIRARA_EVENT_BUTTON_PRESS: From d5941a6f14b3699293f06238775eafb269542942 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 21 Oct 2014 20:57:12 +0200 Subject: [PATCH 2/6] Add SynctaxView method Signed-off-by: Sebastian Ramacher --- data/org.pwmt.zathura.xml | 10 +++++++++ dbus-interface.c | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/data/org.pwmt.zathura.xml b/data/org.pwmt.zathura.xml index b4d2b9a..945f6b4 100644 --- a/data/org.pwmt.zathura.xml +++ b/data/org.pwmt.zathura.xml @@ -34,5 +34,15 @@ + + + + + + + diff --git a/dbus-interface.c b/dbus-interface.c index 0cee730..3eafd4b 100644 --- a/dbus-interface.c +++ b/dbus-interface.c @@ -421,6 +421,50 @@ handle_method_call(GDBusConnection* UNUSED(connection), GVariant* result = g_variant_new("(b)", true); g_dbus_method_invocation_return_value(invocation, result); + } else if (g_strcmp0(method_name, "SynctexView") == 0) { + gchar* input_file = NULL; + guint line = 0; + guint column = 0; + g_variant_get(parameters, "(suu)", &input_file, &line, &column); + + unsigned int page = 0; + girara_list_t* secondary_rects = NULL; + girara_list_t* rectangles = synctex_rectangles_from_position( + zathura_document_get_path(priv->zathura->document), input_file, line, + column, &page, &secondary_rects); + g_free(input_file); + + if (rectangles == NULL) { + GVariant* result = g_variant_new("(b)", false); + g_dbus_method_invocation_return_value(invocation, result); + return; + } + + girara_list_t** all_rectangles = g_try_malloc0(number_of_pages * sizeof(girara_list_t*)); + for (unsigned int p = 0; p != number_of_pages; ++p) { + if (p == page) { + all_rectangles[p] = rectangles; + } else { + all_rectangles[p] = girara_list_new2(g_free); + } + } + + if (secondary_rects != NULL) { + GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect) + zathura_rectangle_t* newrect = g_try_malloc0(sizeof(zathura_rectangle_t)); + *newrect = rect->rect; + girara_list_append(all_rectangles[rect->page], newrect); + GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect); + } + + highlight_rects(priv->zathura, page, all_rectangles); + + girara_list_free(secondary_rects); + g_free(all_rectangles); + + GVariant* result = g_variant_new("(b)", true); + g_dbus_method_invocation_return_value(invocation, result); + } } From 71d9f6a546919c5247ec09cf43b00d56642ee4ec Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 21 Oct 2014 21:12:23 +0200 Subject: [PATCH 3/6] Use SynctexView for --synctex-forward Signed-off-by: Sebastian Ramacher --- dbus-interface.c | 65 +++++++++++++----------------------------------- dbus-interface.h | 17 +++---------- 2 files changed, 20 insertions(+), 62 deletions(-) diff --git a/dbus-interface.c b/dbus-interface.c index 3eafd4b..cfc785e 100644 --- a/dbus-interface.c +++ b/dbus-interface.c @@ -504,9 +504,9 @@ static const GDBusInterfaceVTable interface_vtable = static const unsigned int TIMEOUT = 3000; static bool -call_hightlight_rects(GDBusConnection* connection, const char* filename, - const char* name, unsigned int page, - girara_list_t* rectangles, girara_list_t* secondary_rects) +call_synctex_view(GDBusConnection* connection, const char* filename, + const char* name, const char* input_file, unsigned int line, + unsigned int column) { GError* error = NULL; GVariant* vfilename = g_dbus_connection_call_sync( @@ -534,30 +534,12 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename, g_free(remote_filename); - GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(dddd)")); - if (rectangles != NULL) { - GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect) - g_variant_builder_add(builder, "(dddd)", rect->x1, rect->x2, rect->y1, - rect->y2); - GIRARA_LIST_FOREACH_END(rectangles, zathura_rectangle_t*, iter, rect); - } - - GVariantBuilder* second_builder = g_variant_builder_new(G_VARIANT_TYPE("a(udddd)")); - if (secondary_rects != NULL) { - GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect) - g_variant_builder_add(second_builder, "(udddd)", rect->page, - rect->rect.x1, rect->rect.x2, rect->rect.y1, - rect->rect.y2); - GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect); - } - GVariant* ret = g_dbus_connection_call_sync( - connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects", - g_variant_new("(ua(dddd)a(udddd))", page, builder, second_builder), + connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "SynctexView", + g_variant_new("(suu)", input_file, line, column), G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error); - g_variant_builder_unref(builder); if (ret == NULL) { - girara_error("Failed to run HighlightRects on '%s': %s", name, + girara_error("Failed to run SynctexView on '%s': %s", name, error->message); g_error_free(error); return false; @@ -567,10 +549,10 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename, return true; } -bool -zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, - girara_list_t* rectangles, - girara_list_t* secondary_rects, pid_t hint) +static bool +iterate_instances_call_synctex_view(const char* filename, + const char* input_file, unsigned int line, + unsigned int column, pid_t hint) { if (filename == NULL) { return false; @@ -587,9 +569,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, if (hint != -1) { char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint); - const bool ret = call_hightlight_rects(connection, filename, - well_known_name, page, rectangles, - secondary_rects); + const bool ret = call_synctex_view(connection, filename, well_known_name, + input_file, line, column); g_free(well_known_name); return ret; } @@ -616,8 +597,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, } girara_debug("Found name: %s", name); - if (call_hightlight_rects(connection, filename, name, page, rectangles, - secondary_rects) == true) { + if (call_synctex_view(connection, filename, name, input_file, line, column) + == true) { found_one = true; } } @@ -632,22 +613,10 @@ bool zathura_dbus_synctex_position(const char* filename, const char* input_file, int line, int column, pid_t hint) { - if (filename == NULL || input_file == NULL) { + if (filename == NULL || input_file == NULL || line < 0 || column < 0) { return false; } - unsigned int page = 0; - girara_list_t* secondary_rects = NULL; - girara_list_t* rectangles = synctex_rectangles_from_position( - filename, input_file, line, column, &page, &secondary_rects); - if (rectangles == NULL) { - return false; - } - - const bool ret = zathura_dbus_goto_page_and_highlight(filename, page, - rectangles, - secondary_rects, hint); - girara_list_free(rectangles); - girara_list_free(secondary_rects); - return ret; + return iterate_instances_call_synctex_view(filename, input_file, line, column, hint); } + diff --git a/dbus-interface.h b/dbus-interface.h index 3edc3a2..bed36b8 100644 --- a/dbus-interface.h +++ b/dbus-interface.h @@ -52,21 +52,10 @@ ZathuraDbus* zathura_dbus_new(zathura_t* zathura); void zathura_dbus_edit(ZathuraDbus* dbus, unsigned int page, unsigned int x, unsigned int y); /** - * Look for zathura instance having filename open and cause it to open give page - * and highlight rectangles on the given page - * - * @param filename filename - * @param page page number - * @param rectangles list of rectangles to highlight - * @param secondary_rects list of synctex_page_rect_ts for rectangles not on the - * page given by page - * @returns true if a instance was found that has the given filename open, false - * otherwise + * Highlight rectangles in a zathura instance that has filename open. + * input_file, line and column determine the rectangles to display and are + * passed to SyncTeX. */ -bool zathura_dbus_goto_page_and_highlight(const char* filename, - unsigned int page, girara_list_t* rectangles, girara_list_t* secondary_rects, - pid_t pidhint); - bool zathura_dbus_synctex_position(const char* filename, const char* input_file, int line, int column, pid_t hint); From d2a1a2d6d079ec5f55f07a24aed26f05ce0391b2 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 21 Oct 2014 21:17:59 +0200 Subject: [PATCH 4/6] Adjust for different indices in SyncTex Signed-off-by: Sebastian Ramacher --- main.c | 12 ++++++++++-- synctex.c | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index fb0ab64..839ff5c 100644 --- a/main.c +++ b/main.c @@ -118,8 +118,16 @@ main(int argc, char* argv[]) return -1; } - const int line = MIN(INT_MAX, g_ascii_strtoll(split_fwd[0], NULL, 10)); - const int column = MIN(INT_MAX, g_ascii_strtoll(split_fwd[1], NULL, 10)); + int line = MIN(INT_MAX, g_ascii_strtoll(split_fwd[0], NULL, 10)); + int column = MIN(INT_MAX, g_ascii_strtoll(split_fwd[1], NULL, 10)); + /* SyncTeX starts indexing at 1, but we use 0 */ + if (line > 0) { + --line; + } + if (column > 0) { + --column; + } + const bool ret = zathura_dbus_synctex_position(real_path, split_fwd[2], line, column, synctex_pid); g_strfreev(split_fwd); diff --git a/synctex.c b/synctex.c index cbc53fa..0486539 100644 --- a/synctex.c +++ b/synctex.c @@ -122,6 +122,10 @@ synctex_rectangles_from_position(const char* filename, const char* input_file, return NULL; } + /* We use indexes starting at 0 but SyncTeX uses 1 */ + ++line; + ++column; + synctex_scanner_t scanner = synctex_scanner_new_with_output_file(filename, NULL, 1); if (scanner == NULL) { girara_debug("Failed to create synctex scanner."); @@ -187,3 +191,4 @@ synctex_rectangles_from_position(const char* filename, const char* input_file, return hitlist; } + From 93edb66fef2c2d04b0229981003716fd1f811255 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 21 Oct 2014 21:20:29 +0200 Subject: [PATCH 5/6] Some documentation Signed-off-by: Sebastian Ramacher --- dbus-interface.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dbus-interface.h b/dbus-interface.h index bed36b8..2a7c728 100644 --- a/dbus-interface.h +++ b/dbus-interface.h @@ -55,6 +55,12 @@ void zathura_dbus_edit(ZathuraDbus* dbus, unsigned int page, unsigned int x, uns * Highlight rectangles in a zathura instance that has filename open. * input_file, line and column determine the rectangles to display and are * passed to SyncTeX. + * + * @param filename path of the document + * @param input_file path of the input file + * @param line line index (starts at 0) + * @param column column index (starts at 0) + * @param hint zathura process ID that has filename open */ bool zathura_dbus_synctex_position(const char* filename, const char* input_file, int line, int column, pid_t hint); From a567383e525c5414914f3a6d3b72e858b1778f37 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 22 Oct 2014 22:08:12 +0200 Subject: [PATCH 6/6] Version 0.3.1 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index d082fc8..aa6a943 100644 --- a/config.mk +++ b/config.mk @@ -6,7 +6,7 @@ PROJECT = zathura ZATHURA_VERSION_MAJOR = 0 ZATHURA_VERSION_MINOR = 3 -ZATHURA_VERSION_REV = 0 +ZATHURA_VERSION_REV = 1 # If the API changes, the API version and the ABI version have to be bumped. ZATHURA_API_VERSION = 2 # If the ABI breaks for any reason, this has to be bumped.