summaryrefslogtreecommitdiff
path: root/vcl/unx/gtk/window
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-10-24 17:17:27 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:59 +0100
commite3055bccc7eb59ed898bffa260986c19b6285783 (patch)
tree10a0b9a69904a474d690f942cde694e4b3f4c693 /vcl/unx/gtk/window
parent5339d69bbcebc1d438c3e520acaacada32ace7ab (diff)
Added missing files for HUD awareness support.
Change-Id: If3544734e8c4a1c632a24976e9340ef84869d22a
Diffstat (limited to 'vcl/unx/gtk/window')
-rw-r--r--vcl/unx/gtk/window/hudawareness.cxx126
1 files changed, 126 insertions, 0 deletions
diff --git a/vcl/unx/gtk/window/hudawareness.cxx b/vcl/unx/gtk/window/hudawareness.cxx
new file mode 100644
index 000000000000..b36f553bc656
--- /dev/null
+++ b/vcl/unx/gtk/window/hudawareness.cxx
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2012 Canonical Ltd.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * licence, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * Author: Ryan Lortie <desrt@desrt.ca>
+ */
+
+#include <unx/gtk/hudawareness.h>
+
+typedef struct
+{
+ GDBusConnection *connection;
+ HudAwarenessCallback callback;
+ gpointer user_data;
+ GDestroyNotify notify;
+} HudAwarenessHandle;
+
+static void
+hud_awareness_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ HudAwarenessHandle *handle = (HudAwarenessHandle*) user_data;
+
+ if (g_str_equal (method_name, "HudActiveChanged"))
+ {
+ gboolean active;
+
+ g_variant_get (parameters, "(b)", &active);
+
+ (* handle->callback) (active, handle->user_data);
+ }
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+}
+
+static void
+hud_awareness_handle_free (gpointer data)
+{
+ HudAwarenessHandle *handle = (HudAwarenessHandle*) data;
+
+ g_object_unref (handle->connection);
+
+ if (handle->notify)
+ (* handle->notify) (handle->user_data);
+
+ g_slice_free (HudAwarenessHandle, handle);
+}
+
+guint
+hud_awareness_register (GDBusConnection *connection,
+ const gchar *object_path,
+ HudAwarenessCallback callback,
+ gpointer user_data,
+ GDestroyNotify notify,
+ GError **error)
+{
+ static GDBusInterfaceInfo *iface;
+ GDBusInterfaceVTable vtable = {
+ hud_awareness_method_call
+ };
+ HudAwarenessHandle *handle;
+ guint object_id;
+
+ if G_UNLIKELY (iface == NULL)
+ {
+ GError *error = NULL;
+ GDBusNodeInfo *info;
+
+ info = g_dbus_node_info_new_for_xml ("<node>"
+ "<interface name='com.canonical.hud.Awareness'>"
+ "<method name='CheckAwareness'/>"
+ "<method name='HudActiveChanged'>"
+ "<arg type='b'/>"
+ "</method>"
+ "</interface>"
+ "</node>",
+ &error);
+ g_assert_no_error (error);
+ iface = g_dbus_node_info_lookup_interface (info, "com.canonical.hud.Awareness");
+ g_assert (iface != NULL);
+ }
+
+ handle = g_slice_new (HudAwarenessHandle);
+
+ object_id = g_dbus_connection_register_object (connection, object_path, iface, &vtable, handle, NULL, error);
+
+ if (object_id == 0)
+ {
+ g_slice_free (HudAwarenessHandle, handle);
+ return 0;
+ }
+
+ handle->connection = (GDBusConnection*) g_object_ref (connection);
+ handle->callback = callback;
+ handle->user_data = user_data;
+ handle->notify = notify;
+
+ return object_id;
+}
+
+void
+hud_awareness_unregister (GDBusConnection *connection,
+ guint subscription_id)
+{
+ g_dbus_connection_unregister_object (connection, subscription_id);
+}