[gnome-settings-daemon/randr-rotate-wacom-tablet: 5/6] Find the rotation to use for the tablet



commit 468cc243a5f9589e9fd79c638ccd2e9300134385
Author: Federico Mena Quintero <federico novell com>
Date:   Mon Nov 30 14:41:22 2009 -0600

    Find the rotation to use for the tablet
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 plugins/xrandr/gsd-xrandr-manager.c |   49 ++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index 7b175a8..61ed6ac 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -167,10 +167,57 @@ show_timestamps_dialog (GsdXrandrManager *manager, const char *msg)
 #endif
 }
 
+static GnomeRRRotation
+find_rotation_for_tablet (GnomeRRConfig *configuration)
+{
+        int i;
+
+        /* The stupid heuristic is to find the first rotated output, and use its rotation.
+         * The rationale is:
+         *
+         * - If you have a built-in tablet (like a tablet PC), then you want the
+         *   stylus to match the built-in monitor's orientation.  Your external
+         *   monitor has no relationship to your stylus.
+         *
+         * - If you have a single swivel monitor, that's the one which corresponds to
+         *   your external tablet.
+         *
+         * - If you have two swivel monitors, well, I want your setup at my home, too.
+         */
+
+        for (i = 0; configuration->outputs[i] != NULL; i++) {
+                GnomeOutputInfo *output;
+
+                output = configuration->outputs[i];
+                if (output->on && output->connected && output->rotation != GNOME_RR_ROTATION_0)
+                        return output->rotation;
+        }
+
+        return GNOME_RR_ROTATION_0;
+}
+
 static void
 handle_tablet_rotation (GsdXrandrManager *manager)
 {
-        /* FMQ: implement */
+        struct GsdXrandrManagerPrivate *priv = manager->priv;
+        GnomeRRConfig *configuration;
+        GnomeRRRotation rotation;
+
+        if (!gconf_client_get_bool (priv->client, CONF_KEY_ROTATE_TABLET_WITH_MONITOR, NULL)) {
+                rotate_tablet (manager, GNOME_RR_ROTATION_0); /* un-rotate the tablet when the GConf key is turned off */
+                return;
+        }
+
+        /* Re-creating the current configuration is probably not the most
+         * efficient thing, but it should give us an accurate view of the world.
+         */
+        configuration = gnome_rr_config_new_current (priv->rw_screen);
+
+        rotation = find_rotation_for_tablet (configuration);
+
+        gnome_rr_config_free (configuration);
+
+        rotate_tablet (manager, rotation);
 }
 
 /* This function centralizes the use of gnome_rr_config_apply_from_filename_with_time().



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]