mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 22:25:59 +01:00
Synctex backwards synchronization
Thanks to Roland Schatz for the patch.
This commit is contained in:
parent
79cdc73951
commit
49116a0834
5 changed files with 84 additions and 19 deletions
|
@ -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,29 +612,38 @@ 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);
|
||||||
zathura_rectangle_t tmp = priv->mouse.selection;
|
|
||||||
|
|
||||||
double scale = zathura_document_get_scale(document);
|
if (priv->zathura->synctex.enabled && button->state & GDK_CONTROL_MASK) {
|
||||||
tmp.x1 /= scale;
|
/* synctex backwards sync */
|
||||||
tmp.x2 /= scale;
|
double scale = zathura_document_get_scale(document);
|
||||||
tmp.y1 /= scale;
|
int x = button->x / scale, y = button->y / scale;
|
||||||
tmp.y2 /= scale;
|
|
||||||
|
|
||||||
char* text = zathura_page_get_text(priv->page, tmp, NULL);
|
synctex_edit(priv->zathura, priv->page, x, y);
|
||||||
if (text != NULL) {
|
} else {
|
||||||
if (strlen(text) > 0) {
|
zathura_rectangle_t tmp = priv->mouse.selection;
|
||||||
/* copy to clipboard */
|
|
||||||
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), text, -1);
|
double scale = zathura_document_get_scale(document);
|
||||||
|
tmp.x1 /= scale;
|
||||||
|
tmp.x2 /= scale;
|
||||||
|
tmp.y1 /= scale;
|
||||||
|
tmp.y2 /= scale;
|
||||||
|
|
||||||
|
char* text = zathura_page_get_text(priv->page, tmp, NULL);
|
||||||
|
if (text != NULL) {
|
||||||
|
if (strlen(text) > 0) {
|
||||||
|
/* copy to clipboard */
|
||||||
|
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), text, -1);
|
||||||
|
|
||||||
|
|
||||||
if (priv->page != NULL && document != NULL && priv->zathura != NULL) {
|
if (priv->page != NULL && document != NULL && priv->zathura != NULL) {
|
||||||
char* stripped_text = g_strdelimit(g_strdup(text), "\n\t\r\n", ' ');
|
char* stripped_text = g_strdelimit(g_strdup(text), "\n\t\r\n", ' ');
|
||||||
girara_notify(priv->zathura->ui.session, GIRARA_INFO, _("Copied selected text to clipboard: %s"), stripped_text);
|
girara_notify(priv->zathura->ui.session, GIRARA_INFO, _("Copied selected text to clipboard: %s"), stripped_text);
|
||||||
g_free(stripped_text);
|
g_free(stripped_text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
g_free(text);
|
g_free(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
synctex.c
Normal file
31
synctex.c
Normal 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
10
synctex.h
Normal 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
|
12
zathura.c
12
zathura.c
|
@ -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);
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
Loading…
Reference in a new issue