From e3055bccc7eb59ed898bffa260986c19b6285783 Mon Sep 17 00:00:00 2001 From: Antonio Fernandez Date: Wed, 24 Oct 2012 17:17:27 +0100 Subject: Added missing files for HUD awareness support. Change-Id: If3544734e8c4a1c632a24976e9340ef84869d22a --- vcl/inc/unx/gtk/hudawareness.h | 45 +++++++++++ vcl/unx/gtk/window/hudawareness.cxx | 126 +++++++++++++++++++++++++++++++ vcl/unx/gtk3/window/gtk3hudawareness.cxx | 1 + 3 files changed, 172 insertions(+) create mode 100644 vcl/inc/unx/gtk/hudawareness.h create mode 100644 vcl/unx/gtk/window/hudawareness.cxx create mode 100644 vcl/unx/gtk3/window/gtk3hudawareness.cxx (limited to 'vcl') diff --git a/vcl/inc/unx/gtk/hudawareness.h b/vcl/inc/unx/gtk/hudawareness.h new file mode 100644 index 000000000000..47c5f902ba5d --- /dev/null +++ b/vcl/inc/unx/gtk/hudawareness.h @@ -0,0 +1,45 @@ +/* + * 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 + */ + +#ifndef _hudawareness_h_ +#define _hudawareness_h_ + +#include + +G_BEGIN_DECLS + +typedef void (* HudAwarenessCallback) (gboolean hud_active, + gpointer user_data); + + +guint hud_awareness_register (GDBusConnection *connection, + const gchar *object_path, + HudAwarenessCallback callback, + gpointer user_data, + GDestroyNotify notify, + GError **error); + +void hud_awareness_unregister (GDBusConnection *connection, + guint awareness_id); + +G_END_DECLS + +#endif /* _hudawareness_h_ */ 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 + */ + +#include + +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 ("" + "" + "" + "" + "" + "" + "" + "", + &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); +} diff --git a/vcl/unx/gtk3/window/gtk3hudawareness.cxx b/vcl/unx/gtk3/window/gtk3hudawareness.cxx new file mode 100644 index 000000000000..1a22211cf3d1 --- /dev/null +++ b/vcl/unx/gtk3/window/gtk3hudawareness.cxx @@ -0,0 +1 @@ +#include "../../gtk/window/hudawareness.cxx" -- cgit