Commit d5941a6f authored by Sebastian Ramacher's avatar Sebastian Ramacher

Add SynctaxView method

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent 44480523
......@@ -34,5 +34,15 @@
<arg type='u' name='line' direction='out' />
<arg type='u' name='column' direction='out' />
</signal>
<!--
Go to a page and highlight rectangles there based on the information
SyncTeX provides for the given input file, line and column.
-->
<method name='SynctexView'>
<arg type='s' name='input' direction='in' />
<arg type='u' name='line' direction='in' />
<arg type='u' name='column' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
</interface>
</node>
......@@ -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);
}
}
......
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