mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 15:26:01 +01:00
Merge branch 'release/0.3.1'
This commit is contained in:
commit
00f90abb3d
6 changed files with 95 additions and 64 deletions
|
@ -6,7 +6,7 @@ PROJECT = zathura
|
||||||
|
|
||||||
ZATHURA_VERSION_MAJOR = 0
|
ZATHURA_VERSION_MAJOR = 0
|
||||||
ZATHURA_VERSION_MINOR = 3
|
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.
|
# If the API changes, the API version and the ABI version have to be bumped.
|
||||||
ZATHURA_API_VERSION = 2
|
ZATHURA_API_VERSION = 2
|
||||||
# If the ABI breaks for any reason, this has to be bumped.
|
# If the ABI breaks for any reason, this has to be bumped.
|
||||||
|
|
|
@ -34,5 +34,15 @@
|
||||||
<arg type='u' name='line' direction='out' />
|
<arg type='u' name='line' direction='out' />
|
||||||
<arg type='u' name='column' direction='out' />
|
<arg type='u' name='column' direction='out' />
|
||||||
</signal>
|
</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>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
|
107
dbus-interface.c
107
dbus-interface.c
|
@ -421,6 +421,50 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
|
|
||||||
GVariant* result = g_variant_new("(b)", true);
|
GVariant* result = g_variant_new("(b)", true);
|
||||||
g_dbus_method_invocation_return_value(invocation, result);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,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(
|
||||||
|
@ -490,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;
|
||||||
|
@ -523,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;
|
||||||
|
@ -543,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;
|
||||||
}
|
}
|
||||||
|
@ -572,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,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,16 @@ 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 filename path of the document
|
||||||
* @param page page number
|
* @param input_file path of the input file
|
||||||
* @param rectangles list of rectangles to highlight
|
* @param line line index (starts at 0)
|
||||||
* @param secondary_rects list of synctex_page_rect_ts for rectangles not on the
|
* @param column column index (starts at 0)
|
||||||
* page given by page
|
* @param hint zathura process ID that has filename open
|
||||||
* @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);
|
||||||
|
|
||||||
|
|
12
main.c
12
main.c
|
@ -118,8 +118,16 @@ main(int argc, char* argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int line = MIN(INT_MAX, g_ascii_strtoll(split_fwd[0], NULL, 10));
|
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 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);
|
const bool ret = zathura_dbus_synctex_position(real_path, split_fwd[2], line, column, synctex_pid);
|
||||||
g_strfreev(split_fwd);
|
g_strfreev(split_fwd);
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,10 @@ synctex_rectangles_from_position(const char* filename, const char* input_file,
|
||||||
return NULL;
|
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);
|
synctex_scanner_t scanner = synctex_scanner_new_with_output_file(filename, NULL, 1);
|
||||||
if (scanner == NULL) {
|
if (scanner == NULL) {
|
||||||
girara_debug("Failed to create synctex scanner.");
|
girara_debug("Failed to create synctex scanner.");
|
||||||
|
@ -187,3 +191,4 @@ synctex_rectangles_from_position(const char* filename, const char* input_file,
|
||||||
|
|
||||||
return hitlist;
|
return hitlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue