mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 08:36:01 +01:00
Auto start instance if --synctex-forward is passed but no instance exists
This commit is contained in:
parent
264aaed0bd
commit
1652c2aab3
5 changed files with 70 additions and 22 deletions
|
@ -445,13 +445,13 @@ call_synctex_view(GDBusConnection* connection, const char* filename,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
static int
|
||||
iterate_instances_call_synctex_view(const char* filename,
|
||||
const char* input_file, unsigned int line,
|
||||
unsigned int column, pid_t hint)
|
||||
{
|
||||
if (filename == NULL) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
GError* error = NULL;
|
||||
|
@ -460,7 +460,7 @@ iterate_instances_call_synctex_view(const char* filename,
|
|||
if (connection == NULL) {
|
||||
girara_error("Could not connect to session bus: %s", error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hint != -1) {
|
||||
|
@ -468,7 +468,7 @@ iterate_instances_call_synctex_view(const char* filename,
|
|||
const bool ret = call_synctex_view(connection, filename, well_known_name,
|
||||
input_file, line, column);
|
||||
g_free(well_known_name);
|
||||
return ret;
|
||||
return ret ? 1 : 0;
|
||||
}
|
||||
|
||||
GVariant* vnames = g_dbus_connection_call_sync(
|
||||
|
@ -479,7 +479,7 @@ iterate_instances_call_synctex_view(const char* filename,
|
|||
girara_error("Could not list available names: %s", error->message);
|
||||
g_error_free(error);
|
||||
g_object_unref(connection);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
GVariantIter* iter = NULL;
|
||||
|
@ -487,25 +487,22 @@ iterate_instances_call_synctex_view(const char* filename,
|
|||
|
||||
gchar* name = NULL;
|
||||
bool found_one = false;
|
||||
while (g_variant_iter_loop(iter, "s", &name) == TRUE) {
|
||||
while (found_one == false && g_variant_iter_loop(iter, "s", &name) == TRUE) {
|
||||
if (g_str_has_prefix(name, "org.pwmt.zathura.PID") == FALSE) {
|
||||
continue;
|
||||
}
|
||||
girara_debug("Found name: %s", name);
|
||||
|
||||
if (call_synctex_view(connection, filename, name, input_file, line, column)
|
||||
== true) {
|
||||
found_one = true;
|
||||
}
|
||||
found_one = call_synctex_view(connection, filename, name, input_file, line, column);
|
||||
}
|
||||
g_variant_iter_free(iter);
|
||||
g_variant_unref(vnames);
|
||||
g_object_unref(connection);
|
||||
|
||||
return found_one;
|
||||
return found_one ? 1 : 0;
|
||||
}
|
||||
|
||||
bool
|
||||
int
|
||||
zathura_dbus_synctex_position(const char* filename, const char* input_file,
|
||||
int line, int column, pid_t hint)
|
||||
{
|
||||
|
|
|
@ -62,7 +62,7 @@ void zathura_dbus_edit(ZathuraDbus* dbus, unsigned int page, unsigned int x, uns
|
|||
* @param column column index (starts at 0)
|
||||
* @param hint zathura process ID that has filename open
|
||||
*/
|
||||
bool zathura_dbus_synctex_position(const char* filename, const char* input_file,
|
||||
int zathura_dbus_synctex_position(const char* filename, const char* input_file,
|
||||
int line, int column, pid_t hint);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -127,12 +127,16 @@ main(int argc, char* argv[])
|
|||
g_free(input_file);
|
||||
g_free(real_path);
|
||||
|
||||
if (ret == false) {
|
||||
girara_error("Could not find open instance for '%s' or got no usable data from synctex.", real_path);
|
||||
if (ret == -1) {
|
||||
/* D-Bus or SyncTeX failed */
|
||||
girara_error("Got no usable data from SyncTeX or D-Bus failed in some way.");
|
||||
return -1;
|
||||
} else if (ret == 1) {
|
||||
/* Found a instance */
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_free(real_path);
|
||||
return ret == true ? 0 : -1;
|
||||
girara_debug("No instance found. Starting new one.");
|
||||
}
|
||||
|
||||
/* check mode */
|
||||
|
@ -195,7 +199,7 @@ main(int argc, char* argv[])
|
|||
if (argc > 1) {
|
||||
if (page_number > 0)
|
||||
--page_number;
|
||||
document_open_idle(zathura, argv[1], password, page_number, mode);
|
||||
document_open_idle(zathura, argv[1], password, page_number, mode, synctex_fwd);
|
||||
|
||||
/* open additional files */
|
||||
for (int i = 2; i < argc; i++) {
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "adjustment.h"
|
||||
#include "dbus-interface.h"
|
||||
#include "css-definitions.h"
|
||||
#include "synctex.h"
|
||||
|
||||
typedef struct zathura_document_info_s {
|
||||
zathura_t* zathura;
|
||||
|
@ -48,6 +49,7 @@ typedef struct zathura_document_info_s {
|
|||
const char* password;
|
||||
int page_number;
|
||||
const char* mode;
|
||||
const char* synctex;
|
||||
} zathura_document_info_t;
|
||||
|
||||
|
||||
|
@ -524,8 +526,13 @@ document_info_open(gpointer data)
|
|||
}
|
||||
|
||||
if (file != NULL) {
|
||||
document_open(document_info->zathura, file, document_info->password,
|
||||
document_info->page_number);
|
||||
if (document_info->synctex != NULL) {
|
||||
document_open_synctex(document_info->zathura, file,
|
||||
document_info->password, document_info->synctex);
|
||||
} else {
|
||||
document_open(document_info->zathura, file, document_info->password,
|
||||
document_info->page_number);
|
||||
}
|
||||
g_free(file);
|
||||
|
||||
if (document_info->mode != NULL) {
|
||||
|
@ -929,9 +936,34 @@ error_out:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
document_open_synctex(zathura_t* zathura, const char* path,
|
||||
const char* password, const char* synctex)
|
||||
{
|
||||
bool ret = document_open(zathura, path, password,
|
||||
ZATHURA_PAGE_NUMBER_UNSPECIFIED);
|
||||
if (ret == false) {
|
||||
return false;
|
||||
}
|
||||
if (synctex == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
char* input_file = NULL;
|
||||
if (synctex_parse_input(synctex, &input_file, &line, &column) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = synctex_view(zathura, input_file, line, column);
|
||||
g_free(input_file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
document_open_idle(zathura_t* zathura, const char* path, const char* password,
|
||||
int page_number, const char* mode)
|
||||
int page_number, const char* mode, const char* synctex)
|
||||
{
|
||||
if (zathura == NULL || path == NULL) {
|
||||
return;
|
||||
|
@ -947,6 +979,7 @@ document_open_idle(zathura_t* zathura, const char* path, const char* password,
|
|||
document_info->password = password;
|
||||
document_info->page_number = page_number;
|
||||
document_info->mode = mode;
|
||||
document_info->synctex = synctex;
|
||||
|
||||
gdk_threads_add_idle(document_info_open, document_info);
|
||||
}
|
||||
|
|
|
@ -291,6 +291,19 @@ void zathura_set_argv(zathura_t* zathura, char** argv);
|
|||
bool document_open(zathura_t* zathura, const char* path, const char* password,
|
||||
int page_number);
|
||||
|
||||
/**
|
||||
* Opens a file
|
||||
*
|
||||
* @param zathura The zathura session
|
||||
* @param path The path to the file
|
||||
* @param password The password of the file
|
||||
* @param synctex Open at the given SyncTeX string
|
||||
*
|
||||
* @return If no error occured true, otherwise false, is returned.
|
||||
*/
|
||||
bool document_open_synctex(zathura_t* zathura, const char* path,
|
||||
const char* password, const char* synctex);
|
||||
|
||||
/**
|
||||
* Opens a file (idle)
|
||||
*
|
||||
|
@ -299,10 +312,11 @@ bool document_open(zathura_t* zathura, const char* path, const char* password,
|
|||
* @param password The password of the file
|
||||
* @param page_number Open given page number
|
||||
* @param mode Open in given page mode
|
||||
* @param synctex SyncTeX string
|
||||
*/
|
||||
void document_open_idle(zathura_t* zathura, const char* path,
|
||||
const char* password, int page_number,
|
||||
const char* mode);
|
||||
const char* mode, const char* synctex);
|
||||
|
||||
/**
|
||||
* Save a open file
|
||||
|
|
Loading…
Reference in a new issue