[gnome-settings-daemon] common: Add orientation plugin
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] common: Add orientation plugin
- Date: Wed, 1 Jun 2011 15:53:34 +0000 (UTC)
commit ae54b4931ac4f8e8078a1ba8904c713a6634e75e
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jun 1 16:48:12 2011 +0100
common: Add orientation plugin
Not fully implemented yet, but will detect accelerometers, and
listen for events on the device itself. We still need to try and
open the device to get its current orientation.
configure.ac | 1 +
data/Makefile.am | 16 ++-
...gs-daemon.plugins.orientation.gschema.xml.in.in | 14 ++
plugins/Makefile.am | 6 +
plugins/orientation/gsd-orientation-manager.c | 199 ++++++++++++++++++++
plugins/orientation/gsd-orientation-manager.h | 58 ++++++
plugins/orientation/gsd-orientation-plugin.c | 111 +++++++++++
plugins/orientation/gsd-orientation-plugin.h | 60 ++++++
.../orientation.gnome-settings-plugin.in | 8 +
9 files changed, 470 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 75b4582..ac17144 100644
--- a/configure.ac
+++ b/configure.ac
@@ -558,6 +558,7 @@ plugins/keyboard/Makefile
plugins/media-keys/Makefile
plugins/media-keys/cut-n-paste/Makefile
plugins/mouse/Makefile
+plugins/orientation/Makefile
plugins/print-notifications/Makefile
plugins/smartcard/Makefile
plugins/sound/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index a3af382..43ba27c 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -19,8 +19,18 @@ gsettings_SCHEMAS = \
org.gnome.settings-daemon.peripherals.wacom.gschema.xml \
org.gnome.settings-daemon.plugins.xrandr.gschema.xml
+all_schemas = $(gsettings_SCHEMAS)
+
if HAVE_PACKAGEKIT
gsettings_SCHEMAS += org.gnome.settings-daemon.plugins.updates.gschema.xml
+else
+all_schemas += org.gnome.settings-daemon.plugins.updates.gschema.xml
+endif
+
+if HAVE_GUDEV
+gsettings_SCHEMAS += org.gnome.settings-daemon.plugins.orientation.gschema.xml
+else
+all_schemas += org.gnome.settings-daemon.plugins.orientation.gschema.xml
endif
@INTLTOOL_XML_NOMERGE_RULE@
@@ -52,7 +62,7 @@ man_MANS = gnome-settings-daemon.1
EXTRA_DIST = \
$(man_MANS) \
$(convert_DATA) \
- $(gsettings_SCHEMAS:.xml=.xml.in.in) \
+ $(all_schemas:.xml=.xml.in.in) \
$(service_in_files) \
$(desktop_in_files) \
$(gsettings_ENUM_FILES) \
@@ -61,7 +71,7 @@ EXTRA_DIST = \
$(NULL)
DISTCLEANFILES = \
- $(gsettings_SCHEMAS) \
+ $(all_schemas) \
$(service_DATA) \
$(desktop_DATA) \
$(NULL)
@@ -69,4 +79,4 @@ DISTCLEANFILES = \
MAINTAINERCLEANFILES = \
*~ \
Makefile.in \
- $(gsettings_SCHEMAS:.xml=.valid)
+ $(all_schemas:.xml=.valid)
diff --git a/data/org.gnome.settings-daemon.plugins.orientation.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.orientation.gschema.xml.in.in
new file mode 100644
index 0000000..9e2504e
--- /dev/null
+++ b/data/org.gnome.settings-daemon.plugins.orientation.gschema.xml.in.in
@@ -0,0 +1,14 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.plugins.orientation" path="/org/gnome/settings-daemon/plugins/orientation/">
+ <key name="active" type="b">
+ <default>true</default>
+ <_summary>Activation of this plugin</_summary>
+ <_description>Whether this plugin would be activated by gnome-settings-daemon or not</_description>
+ </key>
+ <key name="priority" type="i">
+ <default>1</default>
+ <_summary>Priority to use for this plugin</_summary>
+ <_description>Priority to use for this plugin in gnome-settings-daemon startup queue</_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 9242062..4436a42 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -40,6 +40,12 @@ else
disabled_plugins += smartcard
endif
+if HAVE_GUDEV
+enabled_plugins += orientation
+else
+disabled_plugins += orientation
+endif
+
if BUILD_PRINT_NOTIFICATIONS
enabled_plugins += print-notifications
else
diff --git a/plugins/orientation/gsd-orientation-manager.c b/plugins/orientation/gsd-orientation-manager.c
new file mode 100644
index 0000000..6b5e6e2
--- /dev/null
+++ b/plugins/orientation/gsd-orientation-manager.c
@@ -0,0 +1,199 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2010,2011 Red Hat, Inc.
+ *
+ * Author: Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <gudev/gudev.h>
+
+#include "gsd-input-helper.h"
+#include "gnome-settings-profile.h"
+#include "gsd-orientation-manager.h"
+
+#define GSD_ORIENTATION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerPrivate))
+
+struct GsdOrientationManagerPrivate
+{
+ guint start_idle_id;
+ char *device_node;
+ int device_id;
+ GUdevClient *client;
+};
+
+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);
+
+G_DEFINE_TYPE (GsdOrientationManager, gsd_orientation_manager, G_TYPE_OBJECT)
+
+static gpointer manager_object = NULL;
+
+static GObject *
+gsd_orientation_manager_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GsdOrientationManager *orientation_manager;
+
+ orientation_manager = GSD_ORIENTATION_MANAGER (G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_properties));
+
+ return G_OBJECT (orientation_manager);
+}
+
+static void
+gsd_orientation_manager_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->dispose (object);
+}
+
+static void
+gsd_orientation_manager_class_init (GsdOrientationManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructor = gsd_orientation_manager_constructor;
+ object_class->dispose = gsd_orientation_manager_dispose;
+ object_class->finalize = gsd_orientation_manager_finalize;
+
+ g_type_class_add_private (klass, sizeof (GsdOrientationManagerPrivate));
+}
+
+static void
+gsd_orientation_manager_init (GsdOrientationManager *manager)
+{
+ manager->priv = GSD_ORIENTATION_MANAGER_GET_PRIVATE (manager);
+}
+
+static void
+client_uevent_cb (GUdevClient *client,
+ gchar *action,
+ GUdevDevice *device,
+ GsdOrientationManager *manager)
+{
+ const char *device_node;
+
+ device_node = g_udev_device_get_device_file (device);
+ g_debug ("Received uevent '%s' from '%s'", action, device_node);
+
+ if (g_str_equal (action, "change") == FALSE)
+ return;
+
+ if (g_strcmp0 (manager->priv->device_node, device_node) != 0)
+ return;
+
+ g_debug ("Received an event from the accelerometer");
+
+ /* FIXME open the device, and read its orientation */
+}
+
+static gboolean
+gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
+{
+ const char * const subsystems[] = { "input", NULL };
+
+ gnome_settings_profile_start (NULL);
+
+ if (!accelerometer_is_present (&manager->priv->device_node,
+ &manager->priv->device_id)) {
+ g_debug ("Did not find an accelerometer");
+ return FALSE;
+ }
+ g_debug ("Found accelerometer at '%s' (%d)",
+ manager->priv->device_node,
+ manager->priv->device_id);
+
+ manager->priv->client = g_udev_client_new (subsystems);
+ g_signal_connect (G_OBJECT (manager->priv->client), "uevent",
+ G_CALLBACK (client_uevent_cb), manager);
+
+ return FALSE;
+}
+
+gboolean
+gsd_orientation_manager_start (GsdOrientationManager *manager,
+ GError **error)
+{
+ gnome_settings_profile_start (NULL);
+
+ manager->priv->start_idle_id = g_idle_add ((GSourceFunc) gsd_orientation_manager_idle_cb, manager);
+
+ gnome_settings_profile_end (NULL);
+
+ return TRUE;
+}
+
+void
+gsd_orientation_manager_stop (GsdOrientationManager *manager)
+{
+ GsdOrientationManagerPrivate *p = manager->priv;
+
+ g_debug ("Stopping orientation manager");
+
+ if (p->device_node) {
+ g_free (p->device_node);
+ p->device_node = NULL;
+ }
+
+ p->device_id = -1;
+
+ if (p->client) {
+ g_object_unref (p->client);
+ p->client = NULL;
+ }
+}
+
+static void
+gsd_orientation_manager_finalize (GObject *object)
+{
+ GsdOrientationManager *orientation_manager;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GSD_IS_ORIENTATION_MANAGER (object));
+
+ orientation_manager = GSD_ORIENTATION_MANAGER (object);
+
+ g_return_if_fail (orientation_manager->priv != NULL);
+
+ if (orientation_manager->priv->start_idle_id != 0)
+ g_source_remove (orientation_manager->priv->start_idle_id);
+
+ G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->finalize (object);
+}
+
+GsdOrientationManager *
+gsd_orientation_manager_new (void)
+{
+ if (manager_object != NULL) {
+ g_object_ref (manager_object);
+ } else {
+ manager_object = g_object_new (GSD_TYPE_ORIENTATION_MANAGER, NULL);
+ g_object_add_weak_pointer (manager_object,
+ (gpointer *) &manager_object);
+ }
+
+ return GSD_ORIENTATION_MANAGER (manager_object);
+}
diff --git a/plugins/orientation/gsd-orientation-manager.h b/plugins/orientation/gsd-orientation-manager.h
new file mode 100644
index 0000000..0b637a2
--- /dev/null
+++ b/plugins/orientation/gsd-orientation-manager.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_ORIENTATION_MANAGER_H
+#define __GSD_ORIENTATION_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_ORIENTATION_MANAGER (gsd_orientation_manager_get_type ())
+#define GSD_ORIENTATION_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManager))
+#define GSD_ORIENTATION_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerClass))
+#define GSD_IS_ORIENTATION_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_ORIENTATION_MANAGER))
+#define GSD_IS_ORIENTATION_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_ORIENTATION_MANAGER))
+#define GSD_ORIENTATION_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerClass))
+
+typedef struct GsdOrientationManagerPrivate GsdOrientationManagerPrivate;
+
+typedef struct
+{
+ GObject parent;
+ GsdOrientationManagerPrivate *priv;
+} GsdOrientationManager;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} GsdOrientationManagerClass;
+
+GType gsd_orientation_manager_get_type (void);
+
+GsdOrientationManager * gsd_orientation_manager_new (void);
+gboolean gsd_orientation_manager_start (GsdOrientationManager *manager,
+ GError **error);
+void gsd_orientation_manager_stop (GsdOrientationManager *manager);
+
+G_END_DECLS
+
+#endif /* __GSD_ORIENTATION_MANAGER_H */
diff --git a/plugins/orientation/gsd-orientation-plugin.c b/plugins/orientation/gsd-orientation-plugin.c
new file mode 100644
index 0000000..5fffa57
--- /dev/null
+++ b/plugins/orientation/gsd-orientation-plugin.c
@@ -0,0 +1,111 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gmodule.h>
+
+#include "gnome-settings-plugin.h"
+#include "gsd-orientation-plugin.h"
+#include "gsd-orientation-manager.h"
+
+struct GsdOrientationPluginPrivate {
+ GsdOrientationManager *manager;
+};
+
+#define GSD_ORIENTATION_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_ORIENTATION_PLUGIN, GsdOrientationPluginPrivate))
+
+GNOME_SETTINGS_PLUGIN_REGISTER (GsdOrientationPlugin, gsd_orientation_plugin)
+
+static void
+gsd_orientation_plugin_init (GsdOrientationPlugin *plugin)
+{
+ plugin->priv = GSD_ORIENTATION_PLUGIN_GET_PRIVATE (plugin);
+
+ g_debug ("GsdOrientationPlugin initializing");
+
+ plugin->priv->manager = gsd_orientation_manager_new ();
+}
+
+static void
+gsd_orientation_plugin_finalize (GObject *object)
+{
+ GsdOrientationPlugin *plugin;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GSD_IS_ORIENTATION_PLUGIN (object));
+
+ g_debug ("GsdOrientationPlugin finalizing");
+
+ plugin = GSD_ORIENTATION_PLUGIN (object);
+
+ g_return_if_fail (plugin->priv != NULL);
+
+ if (plugin->priv->manager != NULL) {
+ g_object_unref (plugin->priv->manager);
+ }
+
+ G_OBJECT_CLASS (gsd_orientation_plugin_parent_class)->finalize (object);
+}
+
+static void
+impl_activate (GnomeSettingsPlugin *plugin)
+{
+ gboolean res;
+ GError *error;
+
+ g_debug ("Activating orientation plugin");
+
+ error = NULL;
+ res = gsd_orientation_manager_start (GSD_ORIENTATION_PLUGIN (plugin)->priv->manager, &error);
+ if (! res) {
+ g_warning ("Unable to start orientation manager: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+impl_deactivate (GnomeSettingsPlugin *plugin)
+{
+ g_debug ("Deactivating orientation plugin");
+ gsd_orientation_manager_stop (GSD_ORIENTATION_PLUGIN (plugin)->priv->manager);
+}
+
+static void
+gsd_orientation_plugin_class_init (GsdOrientationPluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
+
+ object_class->finalize = gsd_orientation_plugin_finalize;
+
+ plugin_class->activate = impl_activate;
+ plugin_class->deactivate = impl_deactivate;
+
+ g_type_class_add_private (klass, sizeof (GsdOrientationPluginPrivate));
+}
+
+static void
+gsd_orientation_plugin_class_finalize (GsdOrientationPluginClass *klass)
+{
+}
+
diff --git a/plugins/orientation/gsd-orientation-plugin.h b/plugins/orientation/gsd-orientation-plugin.h
new file mode 100644
index 0000000..dffcb71
--- /dev/null
+++ b/plugins/orientation/gsd-orientation-plugin.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_ORIENTATION_PLUGIN_H__
+#define __GSD_ORIENTATION_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+
+#include "gnome-settings-plugin.h"
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_ORIENTATION_PLUGIN (gsd_orientation_plugin_get_type ())
+#define GSD_ORIENTATION_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_ORIENTATION_PLUGIN, GsdOrientationPlugin))
+#define GSD_ORIENTATION_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_ORIENTATION_PLUGIN, GsdOrientationPluginClass))
+#define GSD_IS_ORIENTATION_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_ORIENTATION_PLUGIN))
+#define GSD_IS_ORIENTATION_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_ORIENTATION_PLUGIN))
+#define GSD_ORIENTATION_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_ORIENTATION_PLUGIN, GsdOrientationPluginClass))
+
+typedef struct GsdOrientationPluginPrivate GsdOrientationPluginPrivate;
+
+typedef struct
+{
+ GnomeSettingsPlugin parent;
+ GsdOrientationPluginPrivate *priv;
+} GsdOrientationPlugin;
+
+typedef struct
+{
+ GnomeSettingsPluginClass parent_class;
+} GsdOrientationPluginClass;
+
+GType gsd_orientation_plugin_get_type (void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GSD_ORIENTATION_PLUGIN_H__ */
diff --git a/plugins/orientation/orientation.gnome-settings-plugin.in b/plugins/orientation/orientation.gnome-settings-plugin.in
new file mode 100644
index 0000000..1438632
--- /dev/null
+++ b/plugins/orientation/orientation.gnome-settings-plugin.in
@@ -0,0 +1,8 @@
+[GNOME Settings Plugin]
+Module=orientation
+IAge=0
+_Name=Orientation
+_Description=Orientation plugin
+Authors=Peter Hutterer
+Copyright=Copyright © 2010
+Website=
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]