1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#include "tilda-dbus-actions.h"
#include "key_grabber.h"
#include "tilda-dbus.h"
#define TILDA_DBUS_ACTIONS_BUS_NAME "com.github.lanoxx.tilda.Actions"
#define TILDA_DBUS_ACTIONS_OBJECT_PATH "/com/github/lanoxx/tilda/Actions"
static gchar *
tilda_dbus_actions_get_bus_name_for_instance (int instance_id);
static gchar *
tilda_dbus_actions_get_object_path (tilda_window *window);
static gchar *
tilda_dbus_actions_get_object_path_for_instance (int instance_id);
static gboolean
on_handle_toggle (TildaDbusActions *skeleton,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
tilda_window *window;
window = user_data;
pull (window, PULL_TOGGLE, FALSE);
tilda_dbus_actions_complete_toggle (skeleton, invocation);
return GDK_EVENT_STOP;
}
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer window)
{
TildaDbusActions *actions;
tilda_window *tw;
GError *error;
gchar *path;
tw = window;
g_debug ("TildaDbusActions: Name acquired: %s", name);
error = NULL;
actions = tilda_dbus_actions_skeleton_new ();
g_signal_connect (actions, "handle-toggle",G_CALLBACK (on_handle_toggle), window);
path = tilda_dbus_actions_get_object_path (tw);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (actions),
connection,
path,
&error);
if (error)
{
g_error ("Error while exporting object path of DBus interface %s: %s",
TILDA_DBUS_ACTIONS_OBJECT_PATH, error->message);
}
g_free (path);
}
guint
tilda_dbus_actions_init (tilda_window *window)
{
guint bus_identifier;
gchar *name;
name = tilda_dbus_actions_get_bus_name (window);
bus_identifier = g_bus_own_name (G_BUS_TYPE_SESSION,
name,
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
on_name_acquired,
NULL, window, NULL);
g_free (name);
return bus_identifier;
}
void tilda_dbus_actions_toggle (gint instance_id)
{
GDBusConnection *conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
GError * error = NULL;
if (!conn)
{
return;
}
gchar * name = tilda_dbus_actions_get_bus_name_for_instance (instance_id);
gchar * path = tilda_dbus_actions_get_object_path_for_instance (instance_id);
GVariant * result;
result = g_dbus_connection_call_sync (conn, name, path,
"com.github.lanoxx.tilda.Actions", "Toggle",
NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (error != NULL)
{
g_printerr ("Failed to toggle visibility for instance %d: %s\n",
instance_id, error->message);
g_error_free (error);
} else {
g_variant_unref (result);
}
g_free (name);
g_free (path);
g_object_unref (conn);
}
gchar *
tilda_dbus_actions_get_bus_name (tilda_window *window)
{
return tilda_dbus_actions_get_bus_name_for_instance (window->instance);
}
void
tilda_dbus_actions_finish (guint bus_identifier)
{
g_bus_unown_name (bus_identifier);
}
static gchar *
tilda_dbus_actions_get_bus_name_for_instance (int instance_id) {
return g_strdup_printf ("%s%d", TILDA_DBUS_ACTIONS_BUS_NAME, instance_id);
}
static gchar *
tilda_dbus_actions_get_object_path (tilda_window *window)
{
return tilda_dbus_actions_get_object_path_for_instance (window->instance);
}
static gchar *
tilda_dbus_actions_get_object_path_for_instance (int instance_id)
{
return g_strdup_printf ("%s%d", TILDA_DBUS_ACTIONS_OBJECT_PATH, instance_id);
}
|