Commit b3c2327f authored by Sebastian Ramacher's avatar Sebastian Ramacher

Make synctex_view available

Also fix argv handling.
Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent 3dcae960
...@@ -52,7 +52,6 @@ static GScannerConfig scanner_config = { ...@@ -52,7 +52,6 @@ static GScannerConfig scanner_config = {
static void synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool first); static void synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool first);
static double scan_float(GScanner* scanner); static double scan_float(GScanner* scanner);
static bool synctex_view(zathura_t* zathura, char* position);
void void
synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y) synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
...@@ -71,18 +70,19 @@ synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y) ...@@ -71,18 +70,19 @@ synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
return; return;
} }
int page_idx = zathura_page_get_index(page); char** argv = g_malloc0(sizeof(char*) * (zathura->synctex.editor != NULL ?
char *buffer = g_strdup_printf("%d:%d:%d:%s", page_idx + 1, x, y, filename); 6 : 4));
argv[0] = g_strdup("synctex");
argv[1] = g_strdup("edit");
argv[2] = g_strdup("-o");
argv[3] = g_strdup_printf("%d:%d:%d:%s", zathura_page_get_index(page) + 1, x, y, filename);
if (zathura->synctex.editor != NULL) { if (zathura->synctex.editor != NULL) {
char* argv[] = {"synctex", "edit", "-o", buffer, "-x", zathura->synctex.editor, NULL}; argv[4] = g_strdup("-x");
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); argv[5] = g_strdup(zathura->synctex.editor);
} else {
char* argv[] = {"synctex", "edit", "-o", buffer, NULL};
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
} }
g_free(buffer); g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
g_strfreev(argv);
} }
static void static void
...@@ -96,7 +96,7 @@ synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool ...@@ -96,7 +96,7 @@ synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool
g_object_set(page_widget, "draw-links", FALSE, NULL); g_object_set(page_widget, "draw-links", FALSE, NULL);
g_object_set(page_widget, "search-results", hits, NULL); g_object_set(page_widget, "search-results", hits, NULL);
if (first) { if (first == true) {
page_set(zathura, zathura_page_get_index(page)); page_set(zathura, zathura_page_get_index(page));
g_object_set(page_widget, "search-current", 0, NULL); g_object_set(page_widget, "search-current", 0, NULL);
} }
...@@ -115,15 +115,26 @@ scan_float(GScanner* scanner) ...@@ -115,15 +115,26 @@ scan_float(GScanner* scanner)
} }
} }
static bool bool
synctex_view(zathura_t* zathura, char* position) synctex_view(zathura_t* zathura, const char* position)
{ {
char* filename = g_strdup(zathura_document_get_path(zathura->document)); if (zathura->document == NULL) {
char* argv[] = {"synctex", "view", "-i", position, "-o", filename, NULL}; return false;
gint output; }
char** argv = g_malloc0(sizeof(char*) * 6);
argv[0] = g_strdup("synctex");
argv[1] = g_strdup("view");
argv[2] = g_strdup("-i");
argv[3] = g_strdup(position);
argv[4] = g_strdup("-o");
argv[5] = g_strdup(zathura_document_get_path(zathura->document));
bool ret = g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, &output, NULL, NULL); gint output;
g_free(filename); bool ret = g_spawn_async_with_pipes(NULL, argv, NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL,
&output, NULL, NULL);
g_strfreev(argv);
if (ret == false) { if (ret == false) {
return false; return false;
......
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
#include "types.h" #include "types.h"
void synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y); void synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y);
bool synctex_view(zathura_t* zathura, const char* position);
#endif #endif
...@@ -33,7 +33,7 @@ typedef struct zathura_plugin_manager_s zathura_plugin_manager_t; ...@@ -33,7 +33,7 @@ typedef struct zathura_plugin_manager_s zathura_plugin_manager_t;
/** /**
* Renderer * Renderer
*/ */
typedef struct zathura_renderer_s ZathuraRenderer; typedef struct zathura_renderer_s ZathuraRenderer;
/** /**
* Error types * Error types
......
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