From b48e20dde74897461bd0914bfb8cef9a9eaa296e Mon Sep 17 00:00:00 2001 From: infirit Date: Fri, 7 Nov 2014 23:30:28 +0100 Subject: rr: add api for ensuring a primary display is set in config Based on gnome-desktop commit: f632805c549053a548877785e3e624b1fe687f23 From: William Jon McCann --- libmate-desktop/mate-rr-config.c | 64 ++++++++++++++++++++++++++++++++++++++++ libmate-desktop/mate-rr-config.h | 1 + 2 files changed, 65 insertions(+) (limited to 'libmate-desktop') diff --git a/libmate-desktop/mate-rr-config.c b/libmate-desktop/mate-rr-config.c index 27ecd1a..c9cd85c 100644 --- a/libmate-desktop/mate-rr-config.c +++ b/libmate-desktop/mate-rr-config.c @@ -1068,6 +1068,69 @@ mate_rr_config_sanitize (MateRRConfig *config) } } +static gboolean +output_info_is_laptop (MateOutputInfo *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 +mate_rr_config_ensure_primary (MateRRConfig *configuration) +{ + int i; + MateOutputInfo *laptop; + MateOutputInfo *top_left; + gboolean found; + + laptop = NULL; + top_left = NULL; + found = FALSE; + + for (i = 0; configuration->outputs[i] != NULL; ++i) { + MateOutputInfo *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 mate_rr_config_save (MateRRConfig *configuration, GError **error) @@ -1359,6 +1422,7 @@ mate_rr_config_apply_from_filename_with_time (MateRRScreen *screen, const char * { gboolean result; + mate_rr_config_ensure_primary (stored); result = mate_rr_config_apply_with_time (stored, screen, timestamp, error); mate_rr_config_free (stored); diff --git a/libmate-desktop/mate-rr-config.h b/libmate-desktop/mate-rr-config.h index edceb49..2216eda 100644 --- a/libmate-desktop/mate-rr-config.h +++ b/libmate-desktop/mate-rr-config.h @@ -93,6 +93,7 @@ gboolean mate_rr_config_equal (MateRRConfig *config1, gboolean mate_rr_config_save (MateRRConfig *configuration, GError **error); void mate_rr_config_sanitize (MateRRConfig *configuration); +gboolean mate_rr_config_ensure_primary (MateRRConfig *configuration); #ifndef MATE_DISABLE_DEPRECATED gboolean mate_rr_config_apply (MateRRConfig *configuration, -- cgit v1.2.1