mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 04:56:00 +01:00
Merge branch 'dbus-variable' into 'develop'
Add $DBUS variable for exec Closes #375 See merge request pwmt/zathura!85
This commit is contained in:
commit
5012485b19
6 changed files with 47 additions and 17 deletions
|
@ -230,7 +230,8 @@ close
|
||||||
|
|
||||||
exec
|
exec
|
||||||
Execute an external command. ``$FILE`` expands to the current document path,
|
Execute an external command. ``$FILE`` expands to the current document path,
|
||||||
and ``$PAGE`` to the current page number
|
``$PAGE`` to the current page number, and ``$DBUS`` to the bus name of the
|
||||||
|
D-Bus interface
|
||||||
|
|
||||||
info
|
info
|
||||||
Show document information
|
Show document information
|
||||||
|
|
|
@ -232,7 +232,8 @@ They can also be combined with modifiers:
|
||||||
* ``exec``:
|
* ``exec``:
|
||||||
|
|
||||||
Execute an external command. ``$FILE`` expands to the current document path,
|
Execute an external command. ``$FILE`` expands to the current document path,
|
||||||
and ``$PAGE`` to the current page number.
|
``$PAGE`` to the current page number, and ``$DBUS`` to the bus name of the
|
||||||
|
D-Bus interface.
|
||||||
|
|
||||||
* ``focus_inputbar``
|
* ``focus_inputbar``
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "dbus-interface.h"
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "page-widget.h"
|
#include "page-widget.h"
|
||||||
|
@ -544,6 +545,12 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* bus_name = zathura_dbus_get_name(zathura);
|
||||||
|
GIRARA_LIST_FOREACH_BODY_WITH_ITER(
|
||||||
|
argument_list, char*, iter, value, char* s = girara_replace_substring(value, "$DBUS", bus_name); if (s != NULL) {
|
||||||
|
girara_list_iterator_set(iter, s);
|
||||||
|
});
|
||||||
|
|
||||||
if (zathura->document != NULL) {
|
if (zathura->document != NULL) {
|
||||||
const char* path = zathura_document_get_path(zathura->document);
|
const char* path = zathura_document_get_path(zathura->document);
|
||||||
unsigned int page = zathura_document_get_current_page_number(zathura->document);
|
unsigned int page = zathura_document_get_current_page_number(zathura->document);
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef struct private_s {
|
||||||
GDBusConnection* connection;
|
GDBusConnection* connection;
|
||||||
guint owner_id;
|
guint owner_id;
|
||||||
guint registration_id;
|
guint registration_id;
|
||||||
|
char* bus_name;
|
||||||
} ZathuraDbusPrivate;
|
} ZathuraDbusPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(ZathuraDbus, zathura_dbus, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraDbus))
|
G_DEFINE_TYPE_WITH_CODE(ZathuraDbus, zathura_dbus, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraDbus))
|
||||||
|
@ -71,6 +72,8 @@ finalize(GObject* object)
|
||||||
g_dbus_node_info_unref(priv->introspection_data);
|
g_dbus_node_info_unref(priv->introspection_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(priv->bus_name);
|
||||||
|
|
||||||
G_OBJECT_CLASS(zathura_dbus_parent_class)->finalize(object);
|
G_OBJECT_CLASS(zathura_dbus_parent_class)->finalize(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ zathura_dbus_init(ZathuraDbus* dbus)
|
||||||
priv->connection = NULL;
|
priv->connection = NULL;
|
||||||
priv->owner_id = 0;
|
priv->owner_id = 0;
|
||||||
priv->registration_id = 0;
|
priv->registration_id = 0;
|
||||||
|
priv->bus_name = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -168,13 +172,21 @@ zathura_dbus_new(zathura_t* zathura)
|
||||||
}
|
}
|
||||||
|
|
||||||
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, getpid());
|
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, getpid());
|
||||||
|
priv->bus_name = well_known_name;
|
||||||
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, well_known_name, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
|
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, well_known_name, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
|
||||||
name_acquired, name_lost, dbus, NULL);
|
name_acquired, name_lost, dbus, NULL);
|
||||||
g_free(well_known_name);
|
|
||||||
|
|
||||||
return dbus;
|
return dbus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
zathura_dbus_get_name(zathura_t* zathura)
|
||||||
|
{
|
||||||
|
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(zathura->dbus);
|
||||||
|
|
||||||
|
return priv->bus_name;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zathura_dbus_edit(ZathuraDbus* edit, unsigned int page, unsigned int x, unsigned int y)
|
zathura_dbus_edit(ZathuraDbus* edit, unsigned int page, unsigned int x, unsigned int y)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ struct zathura_dbus_class_s
|
||||||
GType zathura_dbus_get_type(void) G_GNUC_CONST;
|
GType zathura_dbus_get_type(void) G_GNUC_CONST;
|
||||||
|
|
||||||
ZathuraDbus* zathura_dbus_new(zathura_t* zathura);
|
ZathuraDbus* zathura_dbus_new(zathura_t* zathura);
|
||||||
|
const char* zathura_dbus_get_name(zathura_t* zathura);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit the 'Edit' signal on the D-Bus connection.
|
* Emit the 'Edit' signal on the D-Bus connection.
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
#include "shortcuts.h"
|
#include "shortcuts.h"
|
||||||
|
#include "dbus-interface.h"
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
@ -1492,33 +1493,40 @@ sc_exec(girara_session_t* session, girara_argument_t* argument, girara_event_t*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
girara_argument_t new_argument = *argument;
|
||||||
|
const char* bus_name = zathura_dbus_get_name(zathura);
|
||||||
|
char* s = girara_replace_substring(new_argument.data, "$DBUS", bus_name);
|
||||||
|
if (s == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
new_argument.data = s;
|
||||||
|
|
||||||
if (zathura->document != NULL) {
|
if (zathura->document != NULL) {
|
||||||
const char* path = zathura_document_get_path(zathura->document);
|
const char* path = zathura_document_get_path(zathura->document);
|
||||||
unsigned int page = zathura_document_get_current_page_number(zathura->document);
|
unsigned int page = zathura_document_get_current_page_number(zathura->document);
|
||||||
char page_buf[G_ASCII_DTOSTR_BUF_SIZE];
|
char page_buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||||
g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page+1);
|
g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page+1);
|
||||||
|
|
||||||
girara_argument_t new_argument = *argument;
|
s = girara_replace_substring(new_argument.data, "$FILE", path);
|
||||||
|
g_free(new_argument.data);
|
||||||
char* r = girara_replace_substring(argument->data, "$FILE", path);
|
|
||||||
if (r == NULL) {
|
if (s == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
new_argument.data = s;
|
||||||
char* s = girara_replace_substring(r, "$PAGE", page_buf);
|
|
||||||
g_free(r);
|
s = girara_replace_substring(new_argument.data, "$PAGE", page_buf);
|
||||||
|
g_free(new_argument.data);
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_argument.data = s;
|
new_argument.data = s;
|
||||||
const bool ret = girara_sc_exec(session, &new_argument, event, t);
|
|
||||||
g_free(s);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return girara_sc_exec(session, argument, event, t);
|
const bool ret = girara_sc_exec(session, &new_argument, event, t);
|
||||||
|
g_free(new_argument.data);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue