Commit 71d9f6a5 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Use SynctexView for --synctex-forward

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent d5941a6f
...@@ -504,9 +504,9 @@ static const GDBusInterfaceVTable interface_vtable = ...@@ -504,9 +504,9 @@ static const GDBusInterfaceVTable interface_vtable =
static const unsigned int TIMEOUT = 3000; static const unsigned int TIMEOUT = 3000;
static bool static bool
call_hightlight_rects(GDBusConnection* connection, const char* filename, call_synctex_view(GDBusConnection* connection, const char* filename,
const char* name, unsigned int page, const char* name, const char* input_file, unsigned int line,
girara_list_t* rectangles, girara_list_t* secondary_rects) unsigned int column)
{ {
GError* error = NULL; GError* error = NULL;
GVariant* vfilename = g_dbus_connection_call_sync( GVariant* vfilename = g_dbus_connection_call_sync(
...@@ -534,30 +534,12 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename, ...@@ -534,30 +534,12 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
g_free(remote_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( GVariant* ret = g_dbus_connection_call_sync(
connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects", connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "SynctexView",
g_variant_new("(ua(dddd)a(udddd))", page, builder, second_builder), g_variant_new("(suu)", input_file, line, column),
G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error); G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
g_variant_builder_unref(builder);
if (ret == NULL) { 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); error->message);
g_error_free(error); g_error_free(error);
return false; return false;
...@@ -567,10 +549,10 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename, ...@@ -567,10 +549,10 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
return true; return true;
} }
bool static bool
zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, iterate_instances_call_synctex_view(const char* filename,
girara_list_t* rectangles, const char* input_file, unsigned int line,
girara_list_t* secondary_rects, pid_t hint) unsigned int column, pid_t hint)
{ {
if (filename == NULL) { if (filename == NULL) {
return false; return false;
...@@ -587,9 +569,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, ...@@ -587,9 +569,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
if (hint != -1) { if (hint != -1) {
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint); char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint);
const bool ret = call_hightlight_rects(connection, filename, const bool ret = call_synctex_view(connection, filename, well_known_name,
well_known_name, page, rectangles, input_file, line, column);
secondary_rects);
g_free(well_known_name); g_free(well_known_name);
return ret; return ret;
} }
...@@ -616,8 +597,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page, ...@@ -616,8 +597,8 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
} }
girara_debug("Found name: %s", name); girara_debug("Found name: %s", name);
if (call_hightlight_rects(connection, filename, name, page, rectangles, if (call_synctex_view(connection, filename, name, input_file, line, column)
secondary_rects) == true) { == true) {
found_one = true; found_one = true;
} }
} }
...@@ -632,22 +613,10 @@ bool ...@@ -632,22 +613,10 @@ bool
zathura_dbus_synctex_position(const char* filename, const char* input_file, zathura_dbus_synctex_position(const char* filename, const char* input_file,
int line, int column, pid_t hint) 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; return false;
} }
unsigned int page = 0; return iterate_instances_call_synctex_view(filename, input_file, line, column, hint);
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;
} }
...@@ -52,21 +52,10 @@ ZathuraDbus* zathura_dbus_new(zathura_t* zathura); ...@@ -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); 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 * Highlight rectangles in a zathura instance that has filename open.
* and highlight rectangles on the given page * input_file, line and column determine the rectangles to display and are
* * passed to SyncTeX.
* @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
*/ */
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, bool zathura_dbus_synctex_position(const char* filename, const char* input_file,
int line, int column, pid_t hint); int line, int column, pid_t hint);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment