summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2010-11-22 21:39:30 -0500
committerWilliam Jon McCann <jmccann@redhat.com>2010-11-22 21:39:30 -0500
commitf632805c549053a548877785e3e624b1fe687f23 (patch)
treea96270cbf967c7fec0e5456a6eedd326bc259118
parentde76dea67cd85ca4643225c87e84464653f562f6 (diff)
downloadgnome-desktop-f632805c549053a548877785e3e624b1fe687f23.tar.gz
rr: add api for ensuring a primary display is set in config
https://bugzilla.gnome.org/show_bug.cgi?id=635455
-rw-r--r--libgnome-desktop/gnome-rr-config.c64
-rw-r--r--libgnome-desktop/gnome-rr-config.h1
2 files changed, 65 insertions, 0 deletions
diff --git a/libgnome-desktop/gnome-rr-config.c b/libgnome-desktop/gnome-rr-config.c
index daf626d5..f5fe251b 100644
--- a/libgnome-desktop/gnome-rr-config.c
+++ b/libgnome-desktop/gnome-rr-config.c
@@ -1059,6 +1059,69 @@ gnome_rr_config_sanitize (GnomeRRConfig *config)
}
}
+static gboolean
+output_info_is_laptop (GnomeOutputInfo *info)
+{
+ if (info->name
+ && (strstr (info->name, "lvds") || /* Most drivers use an "LVDS" prefix... */
+ strstr (info->name, "LVDS") ||
+ strstr (info->name, "Lvds") ||
+ strstr (info->name, "LCD"))) /* ... but fglrx uses "LCD" in some versions. Shoot me now, kthxbye. */
+ return TRUE;
+
+ return FALSE;
+}
+
+gboolean
+gnome_rr_config_ensure_primary (GnomeRRConfig *configuration)
+{
+ int i;
+ GnomeOutputInfo *laptop;
+ GnomeOutputInfo *top_left;
+ gboolean found;
+
+ laptop = NULL;
+ top_left = NULL;
+ found = FALSE;
+
+ for (i = 0; configuration->outputs[i] != NULL; ++i) {
+ GnomeOutputInfo *info = configuration->outputs[i];
+
+ if (! info->on)
+ continue;
+
+ /* ensure only one */
+ if (info->primary) {
+ if (found) {
+ info->primary = FALSE;
+ } else {
+ found = TRUE;
+ }
+ }
+
+ if (top_left == NULL
+ || (info->x < top_left->x
+ && info->y < top_left->y)) {
+ top_left = info;
+ }
+ if (laptop == NULL
+ && output_info_is_laptop (info)) {
+ /* shame we can't find the connector type
+ as with gnome_rr_output_is_laptop */
+ laptop = info;
+ }
+ }
+
+ if (! found) {
+ if (laptop != NULL) {
+ laptop->primary = TRUE;
+ } else {
+ top_left->primary = TRUE;
+ }
+ }
+
+ return !found;
+}
gboolean
gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
@@ -1349,6 +1412,7 @@ gnome_rr_config_apply_from_filename_with_time (GnomeRRScreen *screen, const char
{
gboolean result;
+ gnome_rr_config_ensure_primary (stored);
result = gnome_rr_config_apply_with_time (stored, screen, timestamp, error);
gnome_rr_config_free (stored);
diff --git a/libgnome-desktop/gnome-rr-config.h b/libgnome-desktop/gnome-rr-config.h
index 6c3aa227..f2303370 100644
--- a/libgnome-desktop/gnome-rr-config.h
+++ b/libgnome-desktop/gnome-rr-config.h
@@ -88,6 +88,7 @@ gboolean gnome_rr_config_equal (GnomeRRConfig *config1,
gboolean gnome_rr_config_save (GnomeRRConfig *configuration,
GError **error);
void gnome_rr_config_sanitize (GnomeRRConfig *configuration);
+gboolean gnome_rr_config_ensure_primary (GnomeRRConfig *configuration);
#ifndef GNOME_DISABLE_DEPRECATED
gboolean gnome_rr_config_apply (GnomeRRConfig *configuration,