summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2011-06-02 18:13:02 +0100
committerBastien Nocera <hadess@hadess.net>2011-06-02 18:13:02 +0100
commite8cba576a6f71dc4bcffc645780e66d432beae1d (patch)
tree273c60f8d7560945b6d7cde68f3f6f961c02a27d
parent5f5a2ae48995893d2b0a062afc76f9179698ef70 (diff)
downloadgnome-settings-daemon-e8cba576a6f71dc4bcffc645780e66d432beae1d.tar.gz
orientation: Check the current orientation on startup
-rw-r--r--plugins/orientation/gsd-orientation-manager.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/plugins/orientation/gsd-orientation-manager.c b/plugins/orientation/gsd-orientation-manager.c
index 5e21a1df..ae179819 100644
--- a/plugins/orientation/gsd-orientation-manager.c
+++ b/plugins/orientation/gsd-orientation-manager.c
@@ -90,6 +90,7 @@ static void
gsd_orientation_manager_init (GsdOrientationManager *manager)
{
manager->priv = GSD_ORIENTATION_MANAGER_GET_PRIVATE (manager);
+ manager->priv->prev_orientation = ORIENTATION_UNDEFINED;
}
static gboolean
@@ -127,15 +128,42 @@ get_current_values (GsdOrientationManager *manager,
return TRUE;
}
+static gboolean
+update_current_orientation (GsdOrientationManager *manager)
+{
+ OrientationUp orientation;
+ int x, y, z;
+
+ if (get_current_values (manager, &x, &y, &z) == FALSE) {
+ g_warning ("Failed to get X/Y/Z values from device '%d'", manager->priv->device_id);
+ return FALSE;
+ }
+ g_debug ("Got values: %d, %d, %d", x, y, z);
+
+ orientation = gsd_orientation_calc (manager->priv->prev_orientation,
+ x, y, z);
+ g_debug ("New orientation: %s (prev: %s)",
+ gsd_orientation_to_string (orientation),
+ gsd_orientation_to_string (manager->priv->prev_orientation));
+
+ if (orientation == manager->priv->prev_orientation)
+ return FALSE;
+
+ manager->priv->prev_orientation = orientation;
+
+ g_debug ("Orientation changed to '%s', switching screen rotation",
+ gsd_orientation_to_string (manager->priv->prev_orientation));
+
+ return TRUE;
+}
+
static void
client_uevent_cb (GUdevClient *client,
gchar *action,
GUdevDevice *device,
GsdOrientationManager *manager)
{
- OrientationUp orientation;
const char *device_node;
- int x, y, z;
device_node = g_udev_device_get_device_file (device);
g_debug ("Received uevent '%s' from '%s'", action, device_node);
@@ -153,27 +181,10 @@ client_uevent_cb (GUdevClient *client,
return;
}
- if (get_current_values (manager, &x, &y, &z) == FALSE) {
- g_warning ("Failed to get X/Y/Z values from device '%d'", manager->priv->device_id);
- goto out;
- }
- g_debug ("Got values: %d, %d, %d", x, y, z);
-
- orientation = gsd_orientation_calc (manager->priv->prev_orientation,
- x, y, z);
- g_debug ("New orientation: %s (prev: %s)",
- gsd_orientation_to_string (orientation),
- gsd_orientation_to_string (manager->priv->prev_orientation));
-
- if (orientation != manager->priv->prev_orientation) {
- manager->priv->prev_orientation = orientation;
-
- g_debug ("Orientation changed to '%s', switching screen rotation",
- gsd_orientation_to_string (manager->priv->prev_orientation));
+ if (update_current_orientation (manager)) {
/* FIXME: call into XRandR plugin */
}
-out:
set_device_enabled (manager->priv->device_id, FALSE);
}
@@ -184,8 +195,6 @@ gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
gnome_settings_profile_start (NULL);
- manager->priv->prev_orientation = ORIENTATION_UNDEFINED;
-
if (!accelerometer_is_present (&manager->priv->device_node,
&manager->priv->device_id)) {
g_debug ("Did not find an accelerometer");
@@ -195,6 +204,8 @@ gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
manager->priv->device_node,
manager->priv->device_id);
+ update_current_orientation (manager);
+
set_device_enabled (manager->priv->device_id, FALSE);
manager->priv->client = g_udev_client_new (subsystems);