Add DBus method to execute commands on the inputbar

This commit is contained in:
Sebastian Ramacher 2020-09-06 19:24:04 +02:00
parent dc5ade9aeb
commit 22580f24bf
2 changed files with 22 additions and 1 deletions

View file

@ -44,5 +44,10 @@
<arg type='u' name='column' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
<!-- Execute a command as if entered in the inputbar. -->
<method name='ExecuteCommand'>
<arg type='s' name='input' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
</interface>
</node>

View file

@ -12,6 +12,7 @@
#include <girara/session.h>
#include <girara/utils.h>
#include <girara/settings.h>
#include <girara/commands.h>
#include <gio/gio.h>
#include <sys/types.h>
#include <string.h>
@ -379,6 +380,20 @@ handle_synctex_view(zathura_t* zathura, GVariant* parameters,
g_dbus_method_invocation_return_value(invocation, result);
}
static void
handle_execute_command(zathura_t* zathura, GVariant* parameters,
GDBusMethodInvocation* invocation)
{
gchar* input = NULL;
g_variant_get(parameters, "(s)", &input);
const bool ret = girara_command_run(zathura->ui.session, input);
g_free(input);
GVariant* result = g_variant_new("(b)", ret);
g_dbus_method_invocation_return_value(invocation, result);
}
static void
handle_method_call(GDBusConnection* UNUSED(connection),
const gchar* UNUSED(sender), const gchar* object_path,
@ -402,7 +417,8 @@ handle_method_call(GDBusConnection* UNUSED(connection),
{ "CloseDocument", handle_close_document, false, false },
{ "GotoPage", handle_goto_page, true, true },
{ "HighlightRects", handle_highlight_rects, true, true },
{ "SynctexView", handle_synctex_view, true, true }
{ "SynctexView", handle_synctex_view, true, true },
{ "ExecuteCommand", handle_execute_command, false, false }
};
for (size_t idx = 0; idx != sizeof(handlers) / sizeof(handlers[0]); ++idx) {