[gnome-settings-daemon] orientation: Add D-Bus interface, and calls
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] orientation: Add D-Bus interface, and calls
- Date: Fri, 3 Jun 2011 14:50:41 +0000 (UTC)
commit 92b409b5adb96cf7e4db4f59246df0e740753e84
Author: Bastien Nocera <hadess hadess net>
Date: Fri Jun 3 15:49:15 2011 +0100
orientation: Add D-Bus interface, and calls
Add a org.gnome.SettingsDaemon.Orientation object with no
methods on D-Bus, to advertise the availability of automatic
rotation.
Also add code to call into the XRandR plugin when orientation
changes.
plugins/orientation/gsd-orientation-manager.c | 136 ++++++++++++++++++++++++-
1 files changed, 135 insertions(+), 1 deletions(-)
---
diff --git a/plugins/orientation/gsd-orientation-manager.c b/plugins/orientation/gsd-orientation-manager.c
index 2debf7b..fdf4689 100644
--- a/plugins/orientation/gsd-orientation-manager.c
+++ b/plugins/orientation/gsd-orientation-manager.c
@@ -48,6 +48,12 @@ struct GsdOrientationManagerPrivate
char *sysfs_path;
int device_id;
+ /* DBus */
+ GDBusNodeInfo *introspection_data;
+ GDBusConnection *connection;
+ GDBusProxy *xrandr_proxy;
+ GCancellable *cancellable;
+
/* Notifications */
GUdevClient *client;
GSettings *settings;
@@ -67,6 +73,16 @@ struct GsdOrientationManagerPrivate
#define CONF_SCHEMA "org.gnome.settings-daemon.peripherals.touchscreen"
#define ORIENTATION_LOCK_KEY "orientation-lock"
+#define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
+#define GSD_ORIENTATION_DBUS_PATH GSD_DBUS_PATH "/Orientation"
+
+static const gchar introspection_xml[] =
+"<node>"
+" <interface name='org.gnome.SettingsDaemon.Orientation'>"
+" <annotation name='org.freedesktop.DBus.GLib.CSymbol' value='gsd_orientation_manager'/>"
+" </interface>"
+"</node>";
+
static void gsd_orientation_manager_class_init (GsdOrientationManagerClass *klass);
static void gsd_orientation_manager_init (GsdOrientationManager *orientation_manager);
static void gsd_orientation_manager_finalize (GObject *object);
@@ -132,6 +148,60 @@ orientation_to_rotation (OrientationUp orientation)
}
}
+static void
+on_xrandr_action_call_finished (GObject *source_object,
+ GAsyncResult *res,
+ GsdOrientationManager *manager)
+{
+ GError *error = NULL;
+ GVariant *variant;
+
+ variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
+
+ g_object_unref (manager->priv->cancellable);
+ manager->priv->cancellable = NULL;
+
+ if (error != NULL) {
+ g_warning ("Unable to call 'RotateTo': %s", error->message);
+ g_error_free (error);
+ } else {
+ g_variant_unref (variant);
+ }
+}
+
+static void
+do_xrandr_action (GsdOrientationManager *manager,
+ GnomeRRRotation rotation)
+{
+ GsdOrientationManagerPrivate *priv = manager->priv;
+ GTimeVal tv;
+ gint64 timestamp;
+
+ if (priv->connection == NULL || priv->xrandr_proxy == NULL) {
+ g_warning ("No existing D-Bus connection trying to handle XRANDR keys");
+ return;
+ }
+
+ if (priv->cancellable != NULL) {
+ g_debug ("xrandr action already in flight");
+ return;
+ }
+
+ g_get_current_time (&tv);
+ timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+
+ priv->cancellable = g_cancellable_new ();
+
+ g_dbus_proxy_call (priv->xrandr_proxy,
+ "RotateTo",
+ g_variant_new ("(ix)", rotation, timestamp),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ priv->cancellable,
+ (GAsyncReadyCallback) on_xrandr_action_call_finished,
+ manager);
+}
+
static gboolean
get_current_values (GsdOrientationManager *manager,
int *x,
@@ -203,7 +273,8 @@ do_rotation (GsdOrientationManager *manager)
}
rotation = orientation_to_rotation (manager->priv->prev_orientation);
- /* FIXME: call into XRandR plugin */
+
+ do_xrandr_action (manager, rotation);
}
static gboolean
@@ -331,6 +402,55 @@ orientation_lock_changed_cb (GSettings *settings,
}
}
+static void
+xrandr_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ GsdOrientationManager *manager)
+{
+ GError *error = NULL;
+
+ manager->priv->xrandr_proxy = g_dbus_proxy_new_finish (res, &error);
+ if (manager->priv->xrandr_proxy == NULL) {
+ g_warning ("Failed to get proxy for XRandR operations: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+on_bus_gotten (GObject *source_object,
+ GAsyncResult *res,
+ GsdOrientationManager *manager)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ connection = g_bus_get_finish (res, &error);
+ if (connection == NULL) {
+ g_warning ("Could not get session bus: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ manager->priv->connection = connection;
+
+ g_dbus_connection_register_object (connection,
+ GSD_ORIENTATION_DBUS_PATH,
+ manager->priv->introspection_data->interfaces[0],
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+
+ g_dbus_proxy_new (manager->priv->connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.gnome.SettingsDaemon",
+ "/org/gnome/SettingsDaemon/XRANDR",
+ "org.gnome.SettingsDaemon.XRANDR_2",
+ NULL,
+ (GAsyncReadyCallback) xrandr_ready_cb,
+ manager);
+}
+
static gboolean
gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
{
@@ -353,6 +473,12 @@ gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
device_node,
manager->priv->device_id);
+ /* Start process of owning a D-Bus name */
+ g_bus_get (G_BUS_TYPE_SESSION,
+ NULL,
+ (GAsyncReadyCallback) on_bus_gotten,
+ manager);
+
manager->priv->client = g_udev_client_new (subsystems);
manager->priv->sysfs_path = get_sysfs_path (manager, device_node);
@@ -381,6 +507,9 @@ gsd_orientation_manager_start (GsdOrientationManager *manager,
manager->priv->start_idle_id = g_idle_add ((GSourceFunc) gsd_orientation_manager_idle_cb, manager);
+ manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+ g_assert (manager->priv->introspection_data != NULL);
+
gnome_settings_profile_end (NULL);
return TRUE;
@@ -413,6 +542,11 @@ gsd_orientation_manager_stop (GsdOrientationManager *manager)
p->device_id = -1;
}
+ if (p->introspection_data) {
+ g_dbus_node_info_unref (p->introspection_data);
+ p->introspection_data = NULL;
+ }
+
if (p->client) {
g_object_unref (p->client);
p->client = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]