Synctex backwards synchronization

Thanks to Roland Schatz for the patch.
This commit is contained in:
Sebastian Ramacher 2012-07-13 15:39:16 +02:00
parent 79cdc73951
commit 49116a0834
5 changed files with 84 additions and 19 deletions

View file

@ -13,6 +13,7 @@
#include "render.h" #include "render.h"
#include "utils.h" #include "utils.h"
#include "shortcuts.h" #include "shortcuts.h"
#include "synctex.h"
G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA) G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA)
@ -611,6 +612,14 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
} }
} else { } else {
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection); redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
if (priv->zathura->synctex.enabled && button->state & GDK_CONTROL_MASK) {
/* synctex backwards sync */
double scale = zathura_document_get_scale(document);
int x = button->x / scale, y = button->y / scale;
synctex_edit(priv->zathura, priv->page, x, y);
} else {
zathura_rectangle_t tmp = priv->mouse.selection; zathura_rectangle_t tmp = priv->mouse.selection;
double scale = zathura_document_get_scale(document); double scale = zathura_document_get_scale(document);
@ -636,6 +645,7 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
g_free(text); g_free(text);
} }
} }
}
priv->mouse.selection_basepoint.x = -1; priv->mouse.selection_basepoint.x = -1;
priv->mouse.selection_basepoint.y = -1; priv->mouse.selection_basepoint.y = -1;

31
synctex.c Normal file
View file

@ -0,0 +1,31 @@
/* See LICENSE file for license and copyright information */
#include "synctex.h"
#include "zathura.h"
#include "page.h"
#include "document.h"
#include <glib.h>
void
synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
{
zathura_document_t* doc = zathura_page_get_document(page);
const char *filename = zathura_document_get_path(doc);
int pageIdx = zathura_page_get_index(page);
char *buffer = g_strdup_printf("%d:%d:%d:%s", pageIdx+1, x, y, filename);
if (buffer == NULL)
return;
if (zathura->synctex.editor) {
char* argv[] = {"synctex", "edit", "-o", buffer, "-x", zathura->synctex.editor, NULL};
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
} 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);
}

10
synctex.h Normal file
View file

@ -0,0 +1,10 @@
/* See LICENSE file for license and copyright information */
#ifndef SYNCTEX_H
#define SYNCTEX_H
#include "types.h"
void synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y);
#endif

View file

@ -66,8 +66,8 @@ zathura_init(int argc, char* argv[])
Window embed = 0; Window embed = 0;
#endif #endif
gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL, *password = NULL; gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL, *password = NULL, *synctex_editor = NULL;
bool forkback = false, print_version = false; bool forkback = false, print_version = false, synctex = false;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{ "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" }, { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" },
@ -78,6 +78,8 @@ zathura_init(int argc, char* argv[])
{ "password", 'w', 0, G_OPTION_ARG_STRING, &password, _("Document password"), "password" }, { "password", 'w', 0, G_OPTION_ARG_STRING, &password, _("Document password"), "password" },
{ "debug", 'l', 0, G_OPTION_ARG_STRING, &loglevel, _("Log level (debug, info, warning, error)"), "level" }, { "debug", 'l', 0, G_OPTION_ARG_STRING, &loglevel, _("Log level (debug, info, warning, error)"), "level" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &print_version, _("Print version information"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &print_version, _("Print version information"), NULL },
{ "synctex", 's', 0, G_OPTION_ARG_NONE, &synctex, _("Enable synctex support"), NULL },
{ "editor-command", 'x', 0, G_OPTION_ARG_STRING, &synctex_editor, _("Synctex editor (this flag is forwarded to the synctex command)"), "cmd" },
{ NULL, '\0', 0, 0, NULL, NULL, NULL } { NULL, '\0', 0, 0, NULL, NULL, NULL }
}; };
@ -144,6 +146,12 @@ zathura_init(int argc, char* argv[])
g_free(path); g_free(path);
} }
/* synctex */
zathura->synctex.enabled = synctex;
if (synctex_editor) {
zathura->synctex.editor = g_strdup(synctex_editor);
}
/* create zathura (config/data) directory */ /* create zathura (config/data) directory */
g_mkdir_with_parents(zathura->config.config_dir, 0771); g_mkdir_with_parents(zathura->config.config_dir, 0771);
g_mkdir_with_parents(zathura->config.data_dir, 0771); g_mkdir_with_parents(zathura->config.data_dir, 0771);

View file

@ -66,6 +66,12 @@ struct zathura_s
gchar* data_dir; /**< Path to the data directory */ gchar* data_dir; /**< Path to the data directory */
} config; } config;
struct
{
bool enabled;
gchar* editor;
} synctex;
struct struct
{ {
GtkPrintSettings* settings; /**< Print settings */ GtkPrintSettings* settings; /**< Print settings */