diff --git a/data/org.gnome.mutter.gschema.xml.in b/data/org.gnome.mutter.gschema.xml.in index 7fad66145..6cbd9c1b5 100644 --- a/data/org.gnome.mutter.gschema.xml.in +++ b/data/org.gnome.mutter.gschema.xml.in @@ -103,7 +103,7 @@ - ['monitor-config-manager'] + [] Enable experimental features To enable experimental features, add the feature keyword to the list. @@ -114,22 +114,12 @@ Currently possible keywords: - • “monitor-config-manager” — use the new monitor configuration - system, aimed to replace the old one. - This enables a higher level configuration - API to be used by configuration - applications, as well as the ability to - configure per logical monitor scale. • “scale-monitor-framebuffer” — makes mutter default to layout logical monitors in a logical pixel coordinate space, while scaling monitor framebuffers instead of window content, to manage HiDPI monitors. Does not require a restart. - - Also enabling “monitor-config-manager” - is required for this feature to be - enabled. diff --git a/src/Makefile.am b/src/Makefile.am index 88b83374a..d39b73b26 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -109,8 +109,6 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES = \ backends/meta-input-settings-private.h \ backends/meta-logical-monitor.c \ backends/meta-logical-monitor.h \ - backends/meta-monitor-config.c \ - backends/meta-monitor-config.h \ backends/meta-monitor-config-manager.c \ backends/meta-monitor-config-manager.h \ backends/meta-monitor-config-store.c \ diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 382c939f0..33b9e69a1 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -102,8 +102,6 @@ struct _MetaBackendClass void meta_init_backend (GType backend_gtype); -void meta_backend_x11_display_opened (MetaBackend *backend); - ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend); MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend, diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 573666de4..85baf1c3d 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -52,7 +52,6 @@ enum KEYMAP_CHANGED, KEYMAP_LAYOUT_GROUP_CHANGED, LAST_DEVICE_CHANGED, - X11_DISPLAY_OPENED, N_SIGNALS }; @@ -499,13 +498,6 @@ meta_backend_class_init (MetaBackendClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_INT); - signals[X11_DISPLAY_OPENED] = - g_signal_new ("x11-display-opened", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 0); mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS"); stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0; @@ -944,12 +936,6 @@ meta_clutter_init (void) meta_backend_post_init (_backend); } -void -meta_backend_x11_display_opened (MetaBackend *backend) -{ - g_signal_emit (backend, signals[X11_DISPLAY_OPENED], 0); -} - gboolean meta_is_stage_views_enabled (void) { diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c index 6180b4e91..90514b6a9 100644 --- a/src/backends/meta-monitor-config-manager.c +++ b/src/backends/meta-monitor-config-manager.c @@ -45,6 +45,12 @@ G_DEFINE_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager, G_DEFINE_TYPE (MetaMonitorsConfig, meta_monitors_config, G_TYPE_OBJECT) +static void +meta_crtc_info_free (MetaCrtcInfo *info); + +static void +meta_output_info_free (MetaOutputInfo *info); + MetaMonitorConfigManager * meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager) { @@ -1146,6 +1152,19 @@ meta_monitors_config_class_init (MetaMonitorsConfigClass *klass) object_class->finalize = meta_monitors_config_finalize; } +static void +meta_crtc_info_free (MetaCrtcInfo *info) +{ + g_ptr_array_free (info->outputs, TRUE); + g_slice_free (MetaCrtcInfo, info); +} + +static void +meta_output_info_free (MetaOutputInfo *info) +{ + g_slice_free (MetaOutputInfo, info); +} + gboolean meta_verify_monitor_mode_spec (MetaMonitorModeSpec *monitor_mode_spec, GError **error) diff --git a/src/backends/meta-monitor-config.c b/src/backends/meta-monitor-config.c deleted file mode 100644 index 3ef3c626a..000000000 --- a/src/backends/meta-monitor-config.c +++ /dev/null @@ -1,2315 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2001, 2002 Havoc Pennington - * Copyright (C) 2002, 2003 Red Hat Inc. - * Some ICCCM manager selection code derived from fvwm2, - * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team - * Copyright (C) 2003 Rob Adams - * Copyright (C) 2004-2006 Elijah Newren - * Copyright (C) 2013 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, see . - */ - -/* - * Portions of this file are derived from gnome-desktop/libgnome-desktop/gnome-rr-config.c - * - * Copyright 2007, 2008, Red Hat, Inc. - * Copyright 2010 Giovanni Campagna - * - * Author: Soren Sandmann - */ - -#include "config.h" - -#include "boxes-private.h" -#include "meta-monitor-config.h" -#include "meta-backend-private.h" - -#include -#include - -#include -#include - -/* These structures represent the intended/persistent configuration, - as stored in the monitors.xml file. -*/ - -typedef struct { - char *connector; - char *vendor; - char *product; - char *serial; -} MetaOutputKey; - -/* Keep this structure packed, so that we - can use memcmp */ -typedef struct { - gboolean enabled; - MetaRectangle rect; - float refresh_rate; - MetaMonitorTransform transform; - - gboolean is_primary; - gboolean is_presentation; - gboolean is_underscanning; -} MetaOutputConfig; - -typedef struct { - guint refcount; - MetaOutputKey *keys; - MetaOutputConfig *outputs; - unsigned int n_outputs; -} MetaConfiguration; - -struct _MetaMonitorConfig { - GObject parent_instance; - - GHashTable *configs; - MetaConfiguration *current; - gboolean current_is_for_laptop_lid; - MetaConfiguration *previous; - - GFile *user_file; - GFile *system_file; - GCancellable *save_cancellable; - - gboolean lid_is_closed; -}; - -G_DEFINE_TYPE (MetaMonitorConfig, meta_monitor_config, G_TYPE_OBJECT); - -static gboolean meta_monitor_config_assign_crtcs (MetaConfiguration *config, - MetaMonitorManager *manager, - GPtrArray *crtcs, - GPtrArray *outputs); - -static void -free_output_key (MetaOutputKey *key) -{ - g_free (key->connector); - g_free (key->vendor); - g_free (key->product); - g_free (key->serial); -} - -static void -config_clear (MetaConfiguration *config) -{ - unsigned int i; - - for (i = 0; i < config->n_outputs; i++) - free_output_key (&config->keys[i]); - - g_free (config->keys); - g_free (config->outputs); -} - -static MetaConfiguration * -config_ref (MetaConfiguration *config) -{ - config->refcount++; - return config; -} - -static void -config_unref (MetaConfiguration *config) -{ - if (--config->refcount == 0) - { - config_clear (config); - g_slice_free (MetaConfiguration, config); - } -} - -static MetaConfiguration * -config_new (void) -{ - MetaConfiguration *config = g_slice_new0 (MetaConfiguration); - config->refcount = 1; - return config; -} - -static MetaConfiguration * -config_copy (MetaConfiguration *config) -{ - MetaConfiguration *new = config_new (); - guint i; - - new->n_outputs = config->n_outputs; - - new->keys = g_malloc (sizeof (MetaOutputKey) * config->n_outputs); - for (i = 0; i < config->n_outputs; i++) - { - new->keys[i].connector = g_strdup (config->keys[i].connector); - new->keys[i].vendor = g_strdup (config->keys[i].vendor); - new->keys[i].product = g_strdup (config->keys[i].product); - new->keys[i].serial = g_strdup (config->keys[i].serial); - } - - new->outputs = g_memdup (config->outputs, sizeof (MetaOutputConfig) * config->n_outputs); - - return new; -} - -static unsigned long -output_key_hash (const MetaOutputKey *key) -{ - return g_str_hash (key->connector) ^ - g_str_hash (key->vendor) ^ - g_str_hash (key->product) ^ - g_str_hash (key->serial); -} - -static gboolean -output_key_equal (const MetaOutputKey *one, - const MetaOutputKey *two) -{ - return strcmp (one->connector, two->connector) == 0 && - strcmp (one->vendor, two->vendor) == 0 && - strcmp (one->product, two->product) == 0 && - strcmp (one->serial, two->serial) == 0; -} - -static gboolean -output_config_equal (const MetaOutputConfig *one, - const MetaOutputConfig *two) -{ - return memcmp (one, two, sizeof (MetaOutputConfig)) == 0; -} - -static unsigned int -config_hash (gconstpointer data) -{ - const MetaConfiguration *config = data; - unsigned int i, hash; - - hash = 0; - for (i = 0; i < config->n_outputs; i++) - hash ^= output_key_hash (&config->keys[i]); - - return hash; -} - -static gboolean -config_equal (gconstpointer one, - gconstpointer two) -{ - const MetaConfiguration *c_one = one; - const MetaConfiguration *c_two = two; - unsigned int i; - gboolean ok; - - if (c_one->n_outputs != c_two->n_outputs) - return FALSE; - - ok = TRUE; - for (i = 0; i < c_one->n_outputs && ok; i++) - ok = output_key_equal (&c_one->keys[i], - &c_two->keys[i]); - - return ok; -} - -static gboolean -config_equal_full (gconstpointer one, - gconstpointer two) -{ - const MetaConfiguration *c_one = one; - const MetaConfiguration *c_two = two; - unsigned int i; - gboolean ok; - - if (c_one->n_outputs != c_two->n_outputs) - return FALSE; - - ok = TRUE; - for (i = 0; i < c_one->n_outputs && ok; i++) - { - ok = output_key_equal (&c_one->keys[i], - &c_two->keys[i]); - ok = ok && output_config_equal (&c_one->outputs[i], - &c_two->outputs[i]); - } - - return ok; -} - -static void -meta_monitor_config_init (MetaMonitorConfig *self) -{ - const char *filename; - char *path; - const char * const *system_dirs; - - self->configs = g_hash_table_new_full (config_hash, config_equal, NULL, (GDestroyNotify) config_unref); - - filename = g_getenv ("MUTTER_MONITOR_FILENAME"); - if (filename == NULL) - filename = "monitors.xml"; - - path = g_build_filename (g_get_user_config_dir (), filename, NULL); - self->user_file = g_file_new_for_path (path); - g_free (path); - - for (system_dirs = g_get_system_config_dirs (); !self->system_file && *system_dirs; system_dirs++) - { - path = g_build_filename (*system_dirs, filename, NULL); - if (g_file_test (path, G_FILE_TEST_EXISTS)) - self->system_file = g_file_new_for_path (path); - g_free (path); - } -} - -static void -meta_monitor_config_finalize (GObject *object) -{ - MetaMonitorConfig *self = META_MONITOR_CONFIG (object); - - g_hash_table_destroy (self->configs); - - G_OBJECT_CLASS (meta_monitor_config_parent_class)->finalize (object); -} - -static void -meta_monitor_config_class_init (MetaMonitorConfigClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = meta_monitor_config_finalize; -} - -typedef enum { - STATE_INITIAL, - STATE_MONITORS, - STATE_CONFIGURATION, - STATE_OUTPUT, - STATE_OUTPUT_FIELD, - STATE_CLONE -} ParserState; - -typedef struct { - MetaMonitorConfig *config; - ParserState state; - int unknown_count; - - GArray *key_array; - GArray *output_array; - MetaOutputKey key; - MetaOutputConfig output; - - char *output_field; -} ConfigParser; - -static void -handle_start_element (GMarkupParseContext *context, - const char *element_name, - const char **attribute_names, - const char **attribute_values, - gpointer user_data, - GError **error) -{ - ConfigParser *parser = user_data; - - switch (parser->state) - { - case STATE_INITIAL: - { - char *version; - - if (strcmp (element_name, "monitors") != 0) - { - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, - "Invalid document element %s", element_name); - return; - } - - if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, - error, - G_MARKUP_COLLECT_STRING, "version", &version, - G_MARKUP_COLLECT_INVALID)) - return; - - if (strcmp (version, "1") != 0) - { - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Invalid or unsupported version %s", version); - return; - } - - parser->state = STATE_MONITORS; - return; - } - - case STATE_MONITORS: - { - if (strcmp (element_name, "configuration") != 0) - { - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, - "Invalid toplevel element %s", element_name); - return; - } - - parser->key_array = g_array_new (FALSE, FALSE, sizeof (MetaOutputKey)); - parser->output_array = g_array_new (FALSE, FALSE, sizeof (MetaOutputConfig)); - parser->state = STATE_CONFIGURATION; - return; - } - - case STATE_CONFIGURATION: - { - if (strcmp (element_name, "clone") == 0 && parser->unknown_count == 0) - { - parser->state = STATE_CLONE; - } - else if (strcmp (element_name, "output") == 0 && parser->unknown_count == 0) - { - char *name; - - if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, - error, - G_MARKUP_COLLECT_STRING, "name", &name, - G_MARKUP_COLLECT_INVALID)) - return; - - memset (&parser->key, 0, sizeof (MetaOutputKey)); - memset (&parser->output, 0, sizeof (MetaOutputConfig)); - - parser->key.connector = g_strdup (name); - parser->state = STATE_OUTPUT; - } - else - { - parser->unknown_count++; - } - - return; - } - - case STATE_OUTPUT: - { - if ((strcmp (element_name, "vendor") == 0 || - strcmp (element_name, "product") == 0 || - strcmp (element_name, "serial") == 0 || - strcmp (element_name, "width") == 0 || - strcmp (element_name, "height") == 0 || - strcmp (element_name, "rate") == 0 || - strcmp (element_name, "x") == 0 || - strcmp (element_name, "y") == 0 || - strcmp (element_name, "rotation") == 0 || - strcmp (element_name, "reflect_x") == 0 || - strcmp (element_name, "reflect_y") == 0 || - strcmp (element_name, "primary") == 0 || - strcmp (element_name, "presentation") == 0 || - strcmp (element_name, "underscanning") == 0) && parser->unknown_count == 0) - { - parser->state = STATE_OUTPUT_FIELD; - - parser->output_field = g_strdup (element_name); - } - else - { - parser->unknown_count++; - } - - return; - } - - case STATE_CLONE: - case STATE_OUTPUT_FIELD: - { - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Unexpected element %s", element_name); - return; - } - - default: - g_assert_not_reached (); - } -} - -static void -handle_end_element (GMarkupParseContext *context, - const char *element_name, - gpointer user_data, - GError **error) -{ - ConfigParser *parser = user_data; - - switch (parser->state) - { - case STATE_MONITORS: - { - parser->state = STATE_INITIAL; - return; - } - - case STATE_CONFIGURATION: - { - if (strcmp (element_name, "configuration") == 0 && parser->unknown_count == 0) - { - MetaConfiguration *config = config_new (); - - g_assert (parser->key_array->len == parser->output_array->len); - - config->n_outputs = parser->key_array->len; - config->keys = (void*)g_array_free (parser->key_array, FALSE); - config->outputs = (void*)g_array_free (parser->output_array, FALSE); - - g_hash_table_replace (parser->config->configs, config, config); - - parser->key_array = NULL; - parser->output_array = NULL; - parser->state = STATE_MONITORS; - } - else - { - parser->unknown_count--; - - g_assert (parser->unknown_count >= 0); - } - - return; - } - - case STATE_OUTPUT: - { - if (strcmp (element_name, "output") == 0 && parser->unknown_count == 0) - { - if (parser->key.vendor == NULL || - parser->key.product == NULL || - parser->key.serial == NULL) - { - /* Disconnected output, ignore */ - free_output_key (&parser->key); - } - else - { - if (parser->output.rect.width == 0 || - parser->output.rect.height == 0) - parser->output.enabled = FALSE; - else - parser->output.enabled = TRUE; - - g_array_append_val (parser->key_array, parser->key); - g_array_append_val (parser->output_array, parser->output); - } - - memset (&parser->key, 0, sizeof (MetaOutputKey)); - memset (&parser->output, 0, sizeof (MetaOutputConfig)); - - parser->state = STATE_CONFIGURATION; - } - else - { - parser->unknown_count--; - - g_assert (parser->unknown_count >= 0); - } - - return; - } - - case STATE_CLONE: - { - parser->state = STATE_CONFIGURATION; - return; - } - - case STATE_OUTPUT_FIELD: - { - g_free (parser->output_field); - parser->output_field = NULL; - - parser->state = STATE_OUTPUT; - return; - } - - case STATE_INITIAL: - default: - g_assert_not_reached (); - } -} - -static void -read_int (const char *text, - gsize text_len, - gint *field, - GError **error) -{ - char buf[64]; - gint64 v; - char *end; - - strncpy (buf, text, text_len); - buf[MIN (63, text_len)] = 0; - - v = g_ascii_strtoll (buf, &end, 10); - - /* Limit reasonable values (actual limits are a lot smaller that these) */ - if (*end || v < 0 || v > G_MAXINT16) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Expected a number, got %s", buf); - else - *field = v; -} - -static void -read_float (const char *text, - gsize text_len, - gfloat *field, - GError **error) -{ - char buf[64]; - gfloat v; - char *end; - - strncpy (buf, text, text_len); - buf[MIN (63, text_len)] = 0; - - v = g_ascii_strtod (buf, &end); - - /* Limit reasonable values (actual limits are a lot smaller that these) */ - if (*end) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Expected a number, got %s", buf); - else - *field = v; -} - -static gboolean -read_bool (const char *text, - gsize text_len, - GError **error) -{ - if (strncmp (text, "no", text_len) == 0) - return FALSE; - else if (strncmp (text, "yes", text_len) == 0) - return TRUE; - else - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Invalid boolean value %.*s", (int)text_len, text); - - return FALSE; -} - -static gboolean -is_all_whitespace (const char *text, - gsize text_len) -{ - gsize i; - - for (i = 0; i < text_len; i++) - if (!g_ascii_isspace (text[i])) - return FALSE; - - return TRUE; -} - -static void -handle_text (GMarkupParseContext *context, - const gchar *text, - gsize text_len, - gpointer user_data, - GError **error) -{ - ConfigParser *parser = user_data; - - switch (parser->state) - { - case STATE_MONITORS: - { - if (!is_all_whitespace (text, text_len)) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Unexpected content at this point"); - return; - } - - case STATE_CONFIGURATION: - { - if (parser->unknown_count == 0) - { - if (!is_all_whitespace (text, text_len)) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Unexpected content at this point"); - } - else - { - /* Handling unknown element, ignore */ - } - - return; - } - - case STATE_OUTPUT: - { - if (parser->unknown_count == 0) - { - if (!is_all_whitespace (text, text_len)) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Unexpected content at this point"); - } - else - { - /* Handling unknown element, ignore */ - } - return; - } - - case STATE_CLONE: - { - /* Ignore the clone flag */ - return; - } - - case STATE_OUTPUT_FIELD: - { - if (strcmp (parser->output_field, "vendor") == 0) - parser->key.vendor = g_strndup (text, text_len); - else if (strcmp (parser->output_field, "product") == 0) - parser->key.product = g_strndup (text, text_len); - else if (strcmp (parser->output_field, "serial") == 0) - parser->key.serial = g_strndup (text, text_len); - else if (strcmp (parser->output_field, "width") == 0) - read_int (text, text_len, &parser->output.rect.width, error); - else if (strcmp (parser->output_field, "height") == 0) - read_int (text, text_len, &parser->output.rect.height, error); - else if (strcmp (parser->output_field, "rate") == 0) - read_float (text, text_len, &parser->output.refresh_rate, error); - else if (strcmp (parser->output_field, "x") == 0) - read_int (text, text_len, &parser->output.rect.x, error); - else if (strcmp (parser->output_field, "y") == 0) - read_int (text, text_len, &parser->output.rect.y, error); - else if (strcmp (parser->output_field, "rotation") == 0) - { - if (strncmp (text, "normal", text_len) == 0) - parser->output.transform = META_MONITOR_TRANSFORM_NORMAL; - else if (strncmp (text, "left", text_len) == 0) - parser->output.transform = META_MONITOR_TRANSFORM_90; - else if (strncmp (text, "upside_down", text_len) == 0) - parser->output.transform = META_MONITOR_TRANSFORM_180; - else if (strncmp (text, "right", text_len) == 0) - parser->output.transform = META_MONITOR_TRANSFORM_270; - else - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Invalid rotation type %.*s", (int)text_len, text); - } - else if (strcmp (parser->output_field, "reflect_x") == 0) - parser->output.transform += read_bool (text, text_len, error) ? - META_MONITOR_TRANSFORM_FLIPPED : 0; - else if (strcmp (parser->output_field, "reflect_y") == 0) - { - /* FIXME (look at the rotation map in monitor.c) */ - if (read_bool (text, text_len, error)) - g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "Y reflection is not supported"); - } - else if (strcmp (parser->output_field, "primary") == 0) - parser->output.is_primary = read_bool (text, text_len, error); - else if (strcmp (parser->output_field, "presentation") == 0) - parser->output.is_presentation = read_bool (text, text_len, error); - else if (strcmp (parser->output_field, "underscanning") == 0) - parser->output.is_underscanning = read_bool (text, text_len, error); - else - g_assert_not_reached (); - return; - } - - case STATE_INITIAL: - default: - g_assert_not_reached (); - } -} - -static const GMarkupParser config_parser = { - .start_element = handle_start_element, - .end_element = handle_end_element, - .text = handle_text, -}; - -static gboolean -load_config_file (MetaMonitorConfig *self, GFile *file) -{ - char *contents; - gsize size; - gboolean ok; - GError *error; - GMarkupParseContext *context; - ConfigParser parser; - - /* Note: we're explicitly loading this file synchronously because - we don't want to leave the default configuration on for even a frame, ie we - want atomic modeset as much as possible. - - This function is called only at early initialization anyway, before - we connect to X or create the wayland socket. - */ - - error = NULL; - ok = g_file_load_contents (file, NULL, &contents, &size, NULL, &error); - if (!ok) - { - - g_error_free (error); - return FALSE; - } - - memset (&parser, 0, sizeof (ConfigParser)); - parser.config = self; - parser.state = STATE_INITIAL; - - context = g_markup_parse_context_new (&config_parser, - G_MARKUP_TREAT_CDATA_AS_TEXT | - G_MARKUP_PREFIX_ERROR_POSITION, - &parser, NULL); - ok = g_markup_parse_context_parse (context, contents, size, &error); - - if (!ok) - { - meta_warning ("Failed to parse stored monitor configuration: %s\n", error->message); - - g_error_free (error); - - if (parser.key_array) - g_array_free (parser.key_array, TRUE); - if (parser.output_array) - g_array_free (parser.output_array, TRUE); - - free_output_key (&parser.key); - } - - g_markup_parse_context_free (context); - g_free (contents); - - return ok; -} - -static void -meta_monitor_config_load (MetaMonitorConfig *self) -{ - if (self->user_file && load_config_file (self, self->user_file)) - return; - if (self->system_file && load_config_file (self, self->system_file)) - return; -} - -MetaMonitorConfig * -meta_monitor_config_new (MetaMonitorManager *manager) -{ - MetaMonitorConfig *self; - - self = g_object_new (META_TYPE_MONITOR_CONFIG, NULL); - - self->lid_is_closed = meta_monitor_manager_is_lid_closed (manager); - - meta_monitor_config_load (self); - - return self; -} - -static void -init_key_from_output (MetaOutputKey *key, - MetaOutput *output) -{ - key->connector = g_strdup (output->name); - key->product = g_strdup (output->product); - key->vendor = g_strdup (output->vendor); - key->serial = g_strdup (output->serial); -} - -static void -make_config_key (MetaConfiguration *key, - MetaOutput *outputs, - unsigned n_outputs, - unsigned skip) -{ - unsigned int o, i; - - key->outputs = NULL; - key->keys = g_new0 (MetaOutputKey, n_outputs); - - for (o = 0, i = 0; i < n_outputs; o++, i++) - if (i == skip) - o--; - else - init_key_from_output (&key->keys[o], &outputs[i]); - - key->n_outputs = o; -} - -static MetaConfiguration * -meta_monitor_config_get_stored (MetaMonitorConfig *self, - MetaOutput *outputs, - unsigned n_outputs) -{ - MetaConfiguration key; - MetaConfiguration *stored; - - if (n_outputs == 0) - return NULL; - - make_config_key (&key, outputs, n_outputs, -1); - stored = g_hash_table_lookup (self->configs, &key); - - config_clear (&key); - return stored; -} - -static void -set_current (MetaMonitorConfig *self, - MetaConfiguration *config) -{ - g_clear_pointer (&self->previous, (GDestroyNotify) config_unref); - self->previous = self->current; - self->current = config_ref (config); -} - -static gboolean -apply_configuration (MetaMonitorConfig *self, - MetaConfiguration *config, - MetaMonitorManager *manager) -{ - g_autoptr(GPtrArray) crtcs = NULL; - g_autoptr(GPtrArray) outputs = NULL; - - crtcs = g_ptr_array_new_full (config->n_outputs, (GDestroyNotify)meta_crtc_info_free); - outputs = g_ptr_array_new_full (config->n_outputs, (GDestroyNotify)meta_output_info_free); - - if (!meta_monitor_config_assign_crtcs (config, manager, crtcs, outputs)) - return FALSE; - - meta_monitor_manager_apply_configuration (manager, - (MetaCrtcInfo**)crtcs->pdata, crtcs->len, - (MetaOutputInfo**)outputs->pdata, outputs->len); - - set_current (self, config); - - /* If true, we'll be overridden at the end of this call - * inside turn_off_laptop_display / apply_configuration_with_lid */ - self->current_is_for_laptop_lid = FALSE; - - return TRUE; -} - -static gboolean -key_is_laptop (MetaOutputKey *key) -{ - /* FIXME: extend with better heuristics */ - return g_str_has_prefix (key->connector, "LVDS") || - g_str_has_prefix (key->connector, "lvds") || - g_str_has_prefix (key->connector, "Lvds") || - g_str_has_prefix (key->connector, "LCD") || /* some versions of fglrx, sigh */ - g_str_has_prefix (key->connector, "DSI") || - g_str_has_prefix (key->connector, "eDP"); -} - -static gboolean -laptop_display_is_on (MetaConfiguration *config) -{ - unsigned int i; - - for (i = 0; i < config->n_outputs; i++) - { - MetaOutputKey *key = &config->keys[i]; - MetaOutputConfig *output = &config->outputs[i]; - - if (key_is_laptop (key) && output->enabled) - return TRUE; - } - - return FALSE; -} - -static gboolean -multiple_outputs_are_enabled (MetaConfiguration *config) -{ - unsigned int i, enabled; - - enabled = 0; - for (i = 0; i < config->n_outputs; i++) - if (config->outputs[i].enabled) - enabled++; - - return enabled > 1; -} - -static MetaConfiguration * -make_laptop_lid_config (MetaConfiguration *reference) -{ - MetaConfiguration *new; - unsigned int i; - gboolean has_primary; - int x_after, y_after; - int x_offset, y_offset; - - g_assert (multiple_outputs_are_enabled (reference)); - - new = config_new (); - new->n_outputs = reference->n_outputs; - new->keys = g_new0 (MetaOutputKey, reference->n_outputs); - new->outputs = g_new0 (MetaOutputConfig, reference->n_outputs); - - x_after = G_MAXINT; y_after = G_MAXINT; - x_offset = 0; y_offset = 0; - for (i = 0; i < new->n_outputs; i++) - { - MetaOutputKey *current_key = &reference->keys[i]; - MetaOutputConfig *current_output = &reference->outputs[i]; - - new->keys[i].connector = g_strdup (current_key->connector); - new->keys[i].vendor = g_strdup (current_key->vendor); - new->keys[i].product = g_strdup (current_key->product); - new->keys[i].serial = g_strdup (current_key->serial); - - if (key_is_laptop (current_key)) - { - new->outputs[i].enabled = FALSE; - x_after = current_output->rect.x; - y_after = current_output->rect.y; - x_offset = current_output->rect.width; - y_offset = current_output->rect.height; - } - else - new->outputs[i] = *current_output; - } - for (i = 0; i < new->n_outputs; i++) - { - if (new->outputs[i].enabled) - { - if (new->outputs[i].rect.x > x_after) - new->outputs[i].rect.x -= x_offset; - if (new->outputs[i].rect.y > y_after) - new->outputs[i].rect.y -= y_offset; - } - } - - has_primary = FALSE; - for (i = 0; i < new->n_outputs; i++) - { - if (new->outputs[i].is_primary) - { - has_primary = TRUE; - break; - } - } - - if (!has_primary) - { - for (i = 0; i < new->n_outputs; i++) - { - if (new->outputs[i].enabled) - { - new->outputs[i].is_primary = TRUE; - break; - } - } - } - - return new; -} - -static gboolean -apply_configuration_with_lid (MetaMonitorConfig *self, - MetaConfiguration *config, - MetaMonitorManager *manager) -{ - if (self->lid_is_closed && - multiple_outputs_are_enabled (config) && - laptop_display_is_on (config)) - { - MetaConfiguration *laptop_lid_config = make_laptop_lid_config (config); - if (apply_configuration (self, laptop_lid_config, manager)) - { - self->current_is_for_laptop_lid = TRUE; - config_unref (laptop_lid_config); - return TRUE; - } - else - { - config_unref (laptop_lid_config); - return FALSE; - } - } - else - return apply_configuration (self, config, manager); -} - -gboolean -meta_monitor_config_get_is_builtin_display_on (MetaMonitorConfig *self) -{ - g_return_val_if_fail (META_IS_MONITOR_CONFIG (self), FALSE); - - if (self->current) - return laptop_display_is_on (self->current); - - return FALSE; -} - -gboolean -meta_monitor_config_apply_stored (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - MetaOutput *outputs; - MetaConfiguration *stored; - unsigned n_outputs; - - outputs = meta_monitor_manager_get_outputs (manager, &n_outputs); - stored = meta_monitor_config_get_stored (self, outputs, n_outputs); - - if (stored) - return apply_configuration_with_lid (self, stored, manager); - else - return FALSE; -} - -/* - * Tries to find the primary output according to the current layout, - * or failing that, an output that is good to be a primary (LVDS or eDP, - * which are internal monitors), or failing that, the one with the - * best resolution - */ -static int -find_primary_output (MetaOutput *outputs, - unsigned n_outputs) -{ - unsigned i; - int best; - int best_width, best_height; - - g_assert (n_outputs >= 1); - - for (i = 0; i < n_outputs; i++) - { - if (outputs[i].is_primary) - return i; - } - - for (i = 0; i < n_outputs; i++) - { - if (meta_output_is_laptop (&outputs[i])) - return i; - } - - best = -1; - best_width = 0; best_height = 0; - for (i = 0; i < n_outputs; i++) - { - if (outputs[i].tile_info.group_id && - (outputs[i].tile_info.loc_h_tile != 0 || - outputs[i].tile_info.loc_v_tile != 0)) - continue; - - if (outputs[i].preferred_mode->width * outputs[i].preferred_mode->height > - best_width * best_height) - { - best = i; - best_width = outputs[i].preferred_mode->width; - best_height = outputs[i].preferred_mode->height; - } - } - - return best; -} - -static void -init_config_from_preferred_mode (MetaOutputConfig *config, - MetaOutput *output) -{ - config->enabled = TRUE; - config->rect.x = 0; - config->rect.y = 0; - config->rect.width = output->preferred_mode->width; - config->rect.height = output->preferred_mode->height; - config->refresh_rate = output->preferred_mode->refresh_rate; - config->transform = META_MONITOR_TRANSFORM_NORMAL; - config->is_primary = FALSE; - config->is_presentation = FALSE; - config->is_underscanning = output->is_underscanning; -} - -/* This function handles configuring the outputs when the driver provides a - * suggested layout position for each output. This is done in recent versions - * of qxl and allows displays to be aligned on the guest in the same order as - * they are aligned on the client. - */ -static gboolean -make_suggested_config (MetaMonitorConfig *self, - MetaOutput *outputs, - unsigned n_outputs, - int max_width, - int max_height, - MetaConfiguration *config) -{ - unsigned int i; - int primary; - GList *region = NULL; - - g_return_val_if_fail (config != NULL, FALSE); - primary = find_primary_output (outputs, n_outputs); - - for (i = 0; i < n_outputs; i++) - { - gboolean is_primary = ((int)i == primary); - - if (outputs[i].suggested_x < 0 || outputs[i].suggested_y < 0) - return FALSE; - - init_config_from_preferred_mode (&config->outputs[i], &outputs[i]); - config->outputs[i].is_primary = is_primary; - - config->outputs[i].rect.x = outputs[i].suggested_x; - config->outputs[i].rect.y = outputs[i].suggested_y; - - /* Reject the configuration if the suggested positions result in - * overlapping displays */ - if (meta_rectangle_overlaps_with_region (region, &config->outputs[i].rect)) - { - g_warning ("Overlapping outputs, rejecting suggested configuration"); - g_list_free (region); - return FALSE; - } - - region = g_list_prepend (region, &config->outputs[i].rect); - } - - g_list_free (region); - return TRUE; -} - -static void -config_one_untiled_output (MetaOutput *outputs, - MetaConfiguration *config, - int idx, gboolean is_primary, - int *x, unsigned long *output_configured_bitmap) -{ - MetaOutput *output = &outputs[idx]; - - if (*output_configured_bitmap & (1 << idx)) - return; - - init_config_from_preferred_mode (&config->outputs[idx], output); - config->outputs[idx].is_primary = is_primary; - config->outputs[idx].rect.x = *x; - *x += config->outputs[idx].rect.width; - *output_configured_bitmap |= (1 << idx); -} - -static void -config_one_tiled_group (MetaOutput *outputs, - MetaConfiguration *config, - int base_idx, gboolean is_primary, - int n_outputs, - int *x, unsigned long *output_configured_bitmap) -{ - guint32 num_h_tile, num_v_tile, ht, vt; - int j; - int cur_x, cur_y, addx = 0; - - if (*output_configured_bitmap & (1 << base_idx)) - return; - - if (outputs[base_idx].tile_info.group_id == 0) - return; - - cur_x = cur_y = 0; - num_h_tile = outputs[base_idx].tile_info.max_h_tiles; - num_v_tile = outputs[base_idx].tile_info.max_v_tiles; - - /* iterate over horizontal tiles */ - cur_x = *x; - for (ht = 0; ht < num_h_tile; ht++) - { - cur_y = 0; - addx = 0; - for (vt = 0; vt < num_v_tile; vt++) - { - for (j = 0; j < n_outputs; j++) - { - if (outputs[j].tile_info.group_id != outputs[base_idx].tile_info.group_id) - continue; - - if (outputs[j].tile_info.loc_h_tile != ht || - outputs[j].tile_info.loc_v_tile != vt) - continue; - - init_config_from_preferred_mode (&config->outputs[j], &outputs[j]); - config->outputs[j].rect.x = cur_x; - config->outputs[j].rect.y = cur_y; - - if (ht == 0 && vt == 0 && is_primary) - config->outputs[j].is_primary = TRUE; - - *output_configured_bitmap |= (1 << j); - cur_y += outputs[j].tile_info.tile_h; - if (vt == 0) - addx += outputs[j].tile_info.tile_w; - } - } - cur_x += addx; - } - *x = cur_x; - -} - -static void -make_linear_config (MetaMonitorConfig *self, - MetaOutput *outputs, - unsigned n_outputs, - int max_width, - int max_height, - MetaConfiguration *config, - unsigned long output_configured_bitmap) -{ - unsigned i; - int x; - int primary; - - g_return_if_fail (config != NULL); - - primary = find_primary_output (outputs, n_outputs); - - x = 0; - /* set the primary up first at 0 */ - if (outputs[primary].tile_info.group_id) - { - config_one_tiled_group (outputs, config, primary, TRUE, n_outputs, - &x, &output_configured_bitmap); - } - else - { - config_one_untiled_output (outputs, config, primary, TRUE, - &x, &output_configured_bitmap); - } - - /* then add other tiled monitors */ - for (i = 0; i < n_outputs; i++) - { - config_one_tiled_group (outputs, config, i, FALSE, n_outputs, - &x, &output_configured_bitmap); - } - - /* then add remaining monitors */ - for (i = 0; i < n_outputs; i++) - { - config_one_untiled_output (outputs, config, i, FALSE, - &x, &output_configured_bitmap); - - } -} - -/* Search for a configuration that includes one less screen, then add the new - * one as a presentation screen in preferred mode. - * - * XXX: but presentation mode is not implemented in the control-center or in - * mutter core, so let's do extended for now. - */ -static gboolean -extend_stored_config (MetaMonitorConfig *self, - MetaOutput *outputs, - unsigned n_outputs, - int max_width, - int max_height, - MetaConfiguration *config) -{ - int x, y; - unsigned i, j; - - x = 0; - y = 0; - for (i = 0; i < n_outputs; i++) - { - MetaConfiguration key; - MetaConfiguration *ref; - - make_config_key (&key, outputs, n_outputs, i); - ref = g_hash_table_lookup (self->configs, &key); - config_clear (&key); - - if (ref) - { - for (j = 0; j < n_outputs; j++) - { - if (j < i) - { - g_assert (output_key_equal (&config->keys[j], &ref->keys[j])); - config->outputs[j] = ref->outputs[j]; - x = MAX (x, ref->outputs[j].rect.x + ref->outputs[j].rect.width); - y = MAX (y, ref->outputs[j].rect.y + ref->outputs[j].rect.height); - } - else if (j > i) - { - g_assert (output_key_equal (&config->keys[j], &ref->keys[j - 1])); - config->outputs[j] = ref->outputs[j - 1]; - x = MAX (x, ref->outputs[j - 1].rect.x + ref->outputs[j - 1].rect.width); - y = MAX (y, ref->outputs[j - 1].rect.y + ref->outputs[j - 1].rect.height); - } - else - { - init_config_from_preferred_mode (&config->outputs[j], &outputs[0]); - } - } - - /* Place the new output at the right end of the screen, if it fits, - otherwise below it, otherwise disable it (or apply_configuration will fail) */ - if (x + config->outputs[i].rect.width <= max_width) - config->outputs[i].rect.x = x; - else if (y + config->outputs[i].rect.height <= max_height) - config->outputs[i].rect.y = y; - else - config->outputs[i].enabled = FALSE; - - return TRUE; - } - } - - return FALSE; -} - -static MetaConfiguration * -make_default_config (MetaMonitorConfig *self, - MetaOutput *outputs, - unsigned n_outputs, - int max_width, - int max_height, - gboolean use_stored_config) -{ - MetaConfiguration *ret = NULL; - unsigned i; - - ret = config_new (); - make_config_key (ret, outputs, n_outputs, -1); - ret->outputs = g_new0 (MetaOutputConfig, n_outputs); - - /* Special case the simple case: one output, primary at preferred mode, - nothing else to do */ - if (n_outputs == 1) - { - init_config_from_preferred_mode (&ret->outputs[0], &outputs[0]); - ret->outputs[0].is_primary = TRUE; - goto check_limits; - } - - if (make_suggested_config (self, outputs, n_outputs, max_width, max_height, ret)) - goto check_limits; - - if (use_stored_config && - extend_stored_config (self, outputs, n_outputs, max_width, max_height, ret)) - goto check_limits; - - make_linear_config (self, outputs, n_outputs, max_width, max_height, ret, 0); - -check_limits: - /* Disable outputs that would go beyond framebuffer limits */ - for (i = 0; i < n_outputs; i++) - { - if ((ret->outputs[i].rect.x + ret->outputs[i].rect.width > max_width) - || (ret->outputs[i].rect.y + ret->outputs[i].rect.height > max_height)) - ret->outputs[i].enabled = FALSE; - } - - return ret; -} - -static gboolean -ensure_at_least_one_output (MetaMonitorConfig *self, - MetaMonitorManager *manager, - MetaOutput *outputs, - unsigned n_outputs) -{ - MetaConfiguration *config; - int primary; - unsigned i; - - /* Check that we have at least one active output */ - for (i = 0; i < n_outputs; i++) - if (outputs[i].crtc != NULL) - return TRUE; - - /* Oh no, we don't! Activate the primary one and disable everything else */ - - config = config_new (); - make_config_key (config, outputs, n_outputs, -1); - config->outputs = g_new0 (MetaOutputConfig, n_outputs); - - primary = find_primary_output (outputs, n_outputs); - - for (i = 0; i < n_outputs; i++) - { - gboolean is_primary = ((int)i == primary); - - if (is_primary) - { - init_config_from_preferred_mode (&config->outputs[i], &outputs[0]); - config->outputs[i].is_primary = TRUE; - } - else - { - config->outputs[i].enabled = FALSE; - } - } - - apply_configuration (self, config, manager); - config_unref (config); - return FALSE; -} - -void -meta_monitor_config_make_default (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - MetaOutput *outputs; - MetaConfiguration *default_config; - unsigned n_outputs; - gboolean ok = FALSE; - int max_width, max_height; - gboolean use_stored_config; - - outputs = meta_monitor_manager_get_outputs (manager, &n_outputs); - if (!meta_monitor_manager_get_max_screen_size (manager, &max_width, &max_height)) - { - /* No max screen size, just pretend it's something large. */ - max_width = 65535; - max_height = 65535; - } - - if (n_outputs == 0) - { - meta_verbose ("No output connected, not applying configuration\n"); - return; - } - - /* if the device has hotplug_mode_update, it's possible that the - * current display configuration does not match a stored configuration. - * Since extend_existing_config() tries to build a configuration that is - * based on a previously-stored configuration, it's quite likely that the - * resulting config will fail. Even if it doesn't fail, it may result in - * an unexpected configuration, so don't attempt to use a stored config - * in this situation. */ - use_stored_config = !meta_monitor_manager_has_hotplug_mode_update (manager); - default_config = make_default_config (self, outputs, n_outputs, max_width, max_height, use_stored_config); - - if (default_config != NULL) - { - ok = apply_configuration_with_lid (self, default_config, manager); - config_unref (default_config); - } - - if (!ok) - { - meta_warning ("Could not make default configuration for current output layout, leaving unconfigured\n"); - if (ensure_at_least_one_output (self, manager, outputs, n_outputs)) - meta_monitor_config_update_current (self, manager); - } -} - -static void -init_config_from_output (MetaOutputConfig *config, - MetaOutput *output) -{ - config->enabled = (output->crtc != NULL); - - if (!config->enabled) - return; - - config->rect = output->crtc->rect; - config->refresh_rate = output->crtc->current_mode->refresh_rate; - config->transform = output->crtc->transform; - config->is_primary = output->is_primary; - config->is_presentation = output->is_presentation; - config->is_underscanning = output->is_underscanning; -} - -void -meta_monitor_config_update_current (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - MetaOutput *outputs; - unsigned n_outputs; - MetaConfiguration *current; - unsigned int i; - - outputs = meta_monitor_manager_get_outputs (manager, &n_outputs); - - current = config_new (); - current->n_outputs = n_outputs; - current->outputs = g_new0 (MetaOutputConfig, n_outputs); - current->keys = g_new0 (MetaOutputKey, n_outputs); - - for (i = 0; i < current->n_outputs; i++) - { - init_key_from_output (¤t->keys[i], &outputs[i]); - init_config_from_output (¤t->outputs[i], &outputs[i]); - } - - if (self->current && config_equal_full (current, self->current)) - { - config_unref (current); - return; - } - - set_current (self, current); -} - -void -meta_monitor_config_restore_previous (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - if (self->previous) - { - /* The user chose to restore the previous configuration. In this - * case, restore the previous configuration. */ - MetaConfiguration *prev_config = config_ref (self->previous); - gboolean ok = apply_configuration (self, prev_config, manager); - config_unref (prev_config); - - /* After this, self->previous contains the rejected configuration. - * Since it was rejected, nuke it. */ - g_clear_pointer (&self->previous, (GDestroyNotify) config_unref); - - if (ok) - return; - } - - if (!meta_monitor_config_apply_stored (self, manager)) - meta_monitor_config_make_default (self, manager); -} - -static void -turn_off_laptop_display (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - MetaConfiguration *new; - - if (!multiple_outputs_are_enabled (self->current)) - return; - - new = make_laptop_lid_config (self->current); - apply_configuration (self, new, manager); - config_unref (new); - self->current_is_for_laptop_lid = TRUE; -} - -void -meta_monitor_config_lid_is_closed_changed (MetaMonitorConfig *self, - MetaMonitorManager *manager) -{ - gboolean is_closed; - - is_closed = meta_monitor_manager_is_lid_closed (manager); - - if (is_closed != self->lid_is_closed) - { - self->lid_is_closed = is_closed; - - if (is_closed) - turn_off_laptop_display (self, manager); - else if (self->current_is_for_laptop_lid) - meta_monitor_config_restore_previous (self, manager); - } -} - -static void -do_builtin_display_rotation (MetaMonitorConfig *self, - gboolean rotate, - MetaMonitorTransform transform) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - MetaConfiguration *new_config; - MetaOutputConfig *output_config; - guint i; - - if (!self->current) - return; - - if (multiple_outputs_are_enabled (self->current) || - !laptop_display_is_on (self->current)) - return; - - new_config = config_copy (self->current); - - output_config = NULL; - for (i = 0; i < new_config->n_outputs; i++) - if (new_config->outputs[i].enabled) - { - output_config = &new_config->outputs[i]; - break; - } - g_assert (output_config); - - if (rotate) - transform = (output_config->transform + 1) % META_MONITOR_TRANSFORM_FLIPPED; - - if (output_config->transform != transform) - { - output_config->transform = transform; - apply_configuration (self, new_config, monitor_manager); - } - - config_unref (new_config); -} - -void -meta_monitor_config_orientation_changed (MetaMonitorConfig *self, - MetaMonitorTransform transform) -{ - do_builtin_display_rotation (self, FALSE, transform); -} - -void -meta_monitor_config_rotate_monitor (MetaMonitorConfig *self) -{ - do_builtin_display_rotation (self, TRUE, META_MONITOR_TRANSFORM_NORMAL); -} - -static MetaConfiguration * -make_all_mirror_config (MetaMonitorConfig *self, - MetaOutput *outputs, - guint n_outputs) -{ - MetaConfiguration *config; - gint common_width = 0; - gint common_height = 0; - guint i, j, k; - - if (n_outputs < 2) - return NULL; - - for (i = 0; i < outputs[0].n_modes; i++) - { - gboolean common_mode_size = TRUE; - - for (j = 1; j < n_outputs; j++) - { - gboolean have_same_mode_size = FALSE; - - for (k = 0; k < outputs[j].n_modes; k++) - { - if (outputs[j].modes[k]->width == outputs[0].modes[i]->width && - outputs[j].modes[k]->height == outputs[0].modes[i]->height) - { - have_same_mode_size = TRUE; - break; - } - } - - if (!have_same_mode_size) - { - common_mode_size = FALSE; - break; - } - } - - if (common_mode_size && - common_width * common_height < outputs[0].modes[i]->width * outputs[0].modes[i]->height) - { - common_width = outputs[0].modes[i]->width; - common_height = outputs[0].modes[i]->height; - } - } - - if (common_width == 0 || common_height == 0) - return NULL; - - config = config_new (); - make_config_key (config, outputs, n_outputs, -1); - config->outputs = g_new0 (MetaOutputConfig, n_outputs); - - for (i = 0; i < n_outputs; i++) - { - init_config_from_preferred_mode (&config->outputs[i], &outputs[i]); - config->outputs[i].rect.width = common_width; - config->outputs[i].rect.height = common_height; - config->outputs[i].is_primary = TRUE; - } - - return config; -} - -static MetaConfiguration * -make_all_linear_config (MetaMonitorConfig *self, - MetaOutput *outputs, - guint n_outputs, - gint max_width, - gint max_height) -{ - MetaConfiguration *config; - - config = config_new (); - make_config_key (config, outputs, n_outputs, -1); - config->outputs = g_new0 (MetaOutputConfig, n_outputs); - - make_linear_config (self, outputs, n_outputs, max_width, max_height, config, 0); - - return config; -} - -static MetaConfiguration * -make_external_config (MetaMonitorConfig *self, - MetaOutput *outputs, - guint n_outputs, - gint max_width, - gint max_height) -{ - MetaConfiguration *config; - gulong bitmap; - guint i; - - config = config_new (); - make_config_key (config, outputs, n_outputs, -1); - config->outputs = g_new0 (MetaOutputConfig, n_outputs); - - bitmap = 0; - for (i = 0; i < n_outputs; i++) - if (meta_output_is_laptop (&outputs[i])) - { - bitmap = 1 << i; - break; - } - - make_linear_config (self, outputs, n_outputs, max_width, max_height, config, bitmap); - - return config; -} - -static MetaConfiguration * -make_builtin_config (MetaMonitorConfig *self, - MetaOutput *outputs, - guint n_outputs) -{ - MetaConfiguration *config; - gboolean have_builtin = FALSE; - guint i; - - config = config_new (); - make_config_key (config, outputs, n_outputs, -1); - config->outputs = g_new0 (MetaOutputConfig, n_outputs); - - for (i = 0; i < n_outputs; i++) - { - if (meta_output_is_laptop (&outputs[i])) - { - init_config_from_preferred_mode (&config->outputs[i], &outputs[i]); - config->outputs[i].is_primary = TRUE; - have_builtin = TRUE; - } - else - { - config->outputs[i].enabled = FALSE; - } - } - - if (have_builtin) - return config; - - config_unref (config); - return NULL; -} - -gboolean -meta_monitor_config_switch_config (MetaMonitorConfig *self, - MetaMonitorSwitchConfigType config_type) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - MetaConfiguration *new_config = NULL; - MetaOutput *outputs; - gint max_width, max_height; - guint n_outputs; - gboolean success; - - if (!meta_monitor_manager_can_switch_config (monitor_manager)) - return FALSE; - - outputs = meta_monitor_manager_get_outputs (monitor_manager, &n_outputs); - - if (!meta_monitor_manager_get_max_screen_size (monitor_manager, &max_width, &max_height)) - { - max_width = 65535; - max_height = 65535; - } - - switch (config_type) - { - case META_MONITOR_SWITCH_CONFIG_ALL_MIRROR: - new_config = make_all_mirror_config (self, outputs, n_outputs); - break; - case META_MONITOR_SWITCH_CONFIG_ALL_LINEAR: - new_config = make_all_linear_config (self, outputs, n_outputs, max_width, max_height); - break; - case META_MONITOR_SWITCH_CONFIG_EXTERNAL: - new_config = make_external_config (self, outputs, n_outputs, max_width, max_height); - break; - case META_MONITOR_SWITCH_CONFIG_BUILTIN: - new_config = make_builtin_config (self, outputs, n_outputs); - break; - case META_MONITOR_SWITCH_CONFIG_UNKNOWN: - g_warn_if_reached (); - break; - } - - if (!new_config) - return FALSE; - - success = apply_configuration (self, new_config, monitor_manager); - config_unref (new_config); - - return success; -} - -typedef struct { - MetaMonitorConfig *config; - GString *buffer; -} SaveClosure; - -static void -saved_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SaveClosure *closure = user_data; - GError *error; - gboolean ok; - - error = NULL; - ok = g_file_replace_contents_finish (G_FILE (object), result, NULL, &error); - if (!ok) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - meta_warning ("Saving monitor configuration failed: %s\n", error->message); - - g_error_free (error); - } - - g_clear_object (&closure->config->save_cancellable); - g_object_unref (closure->config); - g_string_free (closure->buffer, TRUE); - - g_slice_free (SaveClosure, closure); -} - -static void -meta_monitor_config_save (MetaMonitorConfig *self) -{ - static const char * const rotation_map[4] = { - "normal", - "left", - "upside_down", - "right" - }; - SaveClosure *closure; - GString *buffer; - GHashTableIter iter; - MetaConfiguration *config; - unsigned int i; - - if (self->save_cancellable) - { - g_cancellable_cancel (self->save_cancellable); - g_object_unref (self->save_cancellable); - self->save_cancellable = NULL; - } - - self->save_cancellable = g_cancellable_new (); - - buffer = g_string_new ("\n"); - - g_hash_table_iter_init (&iter, self->configs); - while (g_hash_table_iter_next (&iter, (gpointer*) &config, NULL)) - { - /* Note: we don't distinguish clone vs non-clone here, that's - something for the UI (ie gnome-control-center) to handle, - and our configurations are more complex anyway. - */ - - g_string_append (buffer, - " \n" - " no\n"); - - for (i = 0; i < config->n_outputs; i++) - { - MetaOutputKey *key = &config->keys[i]; - MetaOutputConfig *output = &config->outputs[i]; - - g_string_append_printf (buffer, - " \n" - " %s\n" - " %s\n" - " %s\n", - key->connector, key->vendor, - key->product, key->serial); - - if (output->enabled) - { - char refresh_rate[G_ASCII_DTOSTR_BUF_SIZE]; - - g_ascii_dtostr (refresh_rate, sizeof (refresh_rate), output->refresh_rate); - g_string_append_printf (buffer, - " %d\n" - " %d\n" - " %s\n" - " %d\n" - " %d\n" - " %s\n" - " %s\n" - " no\n" - " %s\n" - " %s\n" - " %s\n", - output->rect.width, - output->rect.height, - refresh_rate, - output->rect.x, - output->rect.y, - rotation_map[output->transform & 0x3], - output->transform >= META_MONITOR_TRANSFORM_FLIPPED ? "yes" : "no", - output->is_primary ? "yes" : "no", - output->is_presentation ? "yes" : "no", - output->is_underscanning ? "yes" : "no"); - } - - g_string_append (buffer, " \n"); - } - - g_string_append (buffer, " \n"); - } - - g_string_append (buffer, "\n"); - - closure = g_slice_new (SaveClosure); - closure->config = g_object_ref (self); - closure->buffer = buffer; - - g_file_replace_contents_async (self->user_file, - buffer->str, buffer->len, - NULL, /* etag */ - TRUE, - G_FILE_CREATE_REPLACE_DESTINATION, - self->save_cancellable, - saved_cb, closure); -} - -void -meta_monitor_config_make_persistent (MetaMonitorConfig *self) -{ - g_hash_table_replace (self->configs, self->current, config_ref (self->current)); - meta_monitor_config_save (self); -} - -/* - * CRTC assignment - */ -typedef struct -{ - MetaConfiguration *config; - MetaMonitorManager *manager; - GHashTable *info; -} CrtcAssignment; - -static gboolean -output_can_clone (MetaOutput *output, - MetaOutput *clone) -{ - unsigned int i; - - for (i = 0; i < output->n_possible_clones; i++) - if (output->possible_clones[i] == clone) - return TRUE; - - return FALSE; -} - -static gboolean -can_clone (MetaCrtcInfo *info, - MetaOutput *output) -{ - unsigned int i; - - for (i = 0; i < info->outputs->len; ++i) - { - MetaOutput *clone = info->outputs->pdata[i]; - - if (!output_can_clone (clone, output)) - return FALSE; - } - - return TRUE; -} - -static gboolean -crtc_can_drive_output (MetaCrtc *crtc, - MetaOutput *output) -{ - unsigned int i; - - for (i = 0; i < output->n_possible_crtcs; i++) - if (output->possible_crtcs[i] == crtc) - return TRUE; - - return FALSE; -} - -static gboolean -crtc_assignment_assign (CrtcAssignment *assign, - MetaCrtc *crtc, - MetaCrtcMode *mode, - int x, - int y, - MetaMonitorTransform transform, - MetaOutput *output) -{ - MetaCrtcInfo *info = g_hash_table_lookup (assign->info, crtc); - - if (!crtc_can_drive_output (crtc, output)) - return FALSE; - - if ((crtc->all_transforms & (1 << transform)) == 0) - return FALSE; - - if (info) - { - if (!(info->mode == mode && - info->x == x && - info->y == y && - info->transform == transform)) - return FALSE; - - if (!can_clone (info, output)) - return FALSE; - - g_ptr_array_add (info->outputs, output); - return TRUE; - } - else - { - info = g_slice_new0 (MetaCrtcInfo); - - info->crtc = crtc; - info->mode = mode; - info->x = x; - info->y = y; - info->transform = transform; - info->outputs = g_ptr_array_new (); - - g_ptr_array_add (info->outputs, output); - g_hash_table_insert (assign->info, crtc, info); - - return TRUE; - } -} - -static void -crtc_assignment_unassign (CrtcAssignment *assign, - MetaCrtc *crtc, - MetaOutput *output) -{ - MetaCrtcInfo *info = g_hash_table_lookup (assign->info, crtc); - - if (info) - { - g_ptr_array_remove (info->outputs, output); - - if (info->outputs->len == 0) - g_hash_table_remove (assign->info, crtc); - } -} - -static MetaOutput * -find_output_by_key (MetaOutput *outputs, - unsigned int n_outputs, - MetaOutputKey *key) -{ - unsigned int i; - - for (i = 0; i < n_outputs; i++) - { - if (strcmp (outputs[i].name, key->connector) == 0) - { - /* This should be checked a lot earlier! */ - - g_warn_if_fail (strcmp (outputs[i].vendor, key->vendor) == 0 && - strcmp (outputs[i].product, key->product) == 0 && - strcmp (outputs[i].serial, key->serial) == 0); - return &outputs[i]; - } - } - - /* Just to satisfy GCC - this is a fatal error if occurs */ - return NULL; -} - -/* Check whether the given set of settings can be used - * at the same time -- ie. whether there is an assignment - * of CRTC's to outputs. - * - * Brute force - the number of objects involved is small - * enough that it doesn't matter. - */ -static gboolean -real_assign_crtcs (CrtcAssignment *assignment, - unsigned int output_num) -{ - MetaCrtc *crtcs; - MetaOutput *outputs; - unsigned int n_crtcs, n_outputs; - MetaOutputKey *output_key; - MetaOutputConfig *output_config; - unsigned int i; - - if (output_num == assignment->config->n_outputs) - return TRUE; - - output_key = &assignment->config->keys[output_num]; - output_config = &assignment->config->outputs[output_num]; - - /* It is always allowed for an output to be turned off */ - if (!output_config->enabled) - return real_assign_crtcs (assignment, output_num + 1); - - meta_monitor_manager_get_resources (assignment->manager, - NULL, NULL, - &crtcs, &n_crtcs, - &outputs, &n_outputs); - - for (i = 0; i < n_crtcs; i++) - { - MetaCrtc *crtc = &crtcs[i]; - unsigned int pass; - - /* Make two passes, one where frequencies must match, then - * one where they don't have to - */ - for (pass = 0; pass < 2; pass++) - { - MetaOutput *output = find_output_by_key (outputs, n_outputs, output_key); - unsigned int j; - - for (j = 0; j < output->n_modes; j++) - { - MetaCrtcMode *mode = output->modes[j]; - int width, height; - - if (meta_monitor_transform_is_rotated (output_config->transform)) - { - width = mode->height; - height = mode->width; - } - else - { - width = mode->width; - height = mode->height; - } - - if (width == output_config->rect.width && - height == output_config->rect.height && - (pass == 1 || mode->refresh_rate == output_config->refresh_rate)) - { - meta_verbose ("CRTC %ld: trying mode %dx%d@%fHz with output at %dx%d@%fHz (transform %d) (pass %d)\n", - crtc->crtc_id, - mode->width, mode->height, mode->refresh_rate, - output_config->rect.width, output_config->rect.height, output_config->refresh_rate, - output_config->transform, - pass); - - if (crtc_assignment_assign (assignment, crtc, mode, - output_config->rect.x, output_config->rect.y, - output_config->transform, - output)) - { - if (real_assign_crtcs (assignment, output_num + 1)) - return TRUE; - - crtc_assignment_unassign (assignment, crtc, output); - } - } - } - } - } - - return FALSE; -} - -static gboolean -meta_monitor_config_assign_crtcs (MetaConfiguration *config, - MetaMonitorManager *manager, - GPtrArray *crtcs, - GPtrArray *outputs) -{ - CrtcAssignment assignment; - GHashTableIter iter; - MetaCrtc *crtc; - MetaCrtcInfo *info; - unsigned int i; - MetaOutput *all_outputs; - unsigned int n_outputs; - - assignment.config = config; - assignment.manager = manager; - assignment.info = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)meta_crtc_info_free); - - if (!real_assign_crtcs (&assignment, 0)) - { - meta_warning ("Could not assign CRTC to outputs, ignoring configuration\n"); - - g_hash_table_destroy (assignment.info); - return FALSE; - } - - g_hash_table_iter_init (&iter, assignment.info); - while (g_hash_table_iter_next (&iter, (void**)&crtc, (void**)&info)) - { - g_hash_table_iter_steal (&iter); - g_ptr_array_add (crtcs, info); - } - - all_outputs = meta_monitor_manager_get_outputs (manager, - &n_outputs); - if (n_outputs != config->n_outputs) - { - g_hash_table_destroy (assignment.info); - return FALSE; - } - - for (i = 0; i < n_outputs; i++) - { - MetaOutputInfo *output_info = g_slice_new (MetaOutputInfo); - MetaOutputConfig *output_config = &config->outputs[i]; - - output_info->output = find_output_by_key (all_outputs, n_outputs, - &config->keys[i]); - output_info->is_primary = output_config->is_primary; - output_info->is_presentation = output_config->is_presentation; - output_info->is_underscanning = output_config->is_underscanning; - - g_ptr_array_add (outputs, output_info); - } - - g_hash_table_destroy (assignment.info); - return TRUE; -} - -void -meta_crtc_info_free (MetaCrtcInfo *info) -{ - g_ptr_array_free (info->outputs, TRUE); - g_slice_free (MetaCrtcInfo, info); -} - -void -meta_output_info_free (MetaOutputInfo *info) -{ - g_slice_free (MetaOutputInfo, info); -} diff --git a/src/backends/meta-monitor-config.h b/src/backends/meta-monitor-config.h deleted file mode 100644 index 86450dc7e..000000000 --- a/src/backends/meta-monitor-config.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2001 Havoc Pennington - * Copyright (C) 2003 Rob Adams - * Copyright (C) 2004-2006 Elijah Newren - * Copyright (C) 2013 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, see . - */ - -#ifndef META_MONITOR_CONFIG_H -#define META_MONITOR_CONFIG_H - -#include "meta-monitor-manager-private.h" - -#define META_TYPE_MONITOR_CONFIG (meta_monitor_config_get_type ()) -G_DECLARE_FINAL_TYPE (MetaMonitorConfig, meta_monitor_config, - META, MONITOR_CONFIG, GObject) - -MetaMonitorConfig *meta_monitor_config_new (MetaMonitorManager *manager); - -gboolean meta_monitor_config_apply_stored (MetaMonitorConfig *config, - MetaMonitorManager *manager); - -void meta_monitor_config_make_default (MetaMonitorConfig *config, - MetaMonitorManager *manager); - -void meta_monitor_config_update_current (MetaMonitorConfig *config, - MetaMonitorManager *manager); -void meta_monitor_config_make_persistent (MetaMonitorConfig *config); - -void meta_monitor_config_restore_previous (MetaMonitorConfig *config, - MetaMonitorManager *manager); - -gboolean meta_monitor_config_get_is_builtin_display_on (MetaMonitorConfig *config); - -void meta_monitor_config_lid_is_closed_changed (MetaMonitorConfig *self, - MetaMonitorManager *manager); - -void meta_monitor_config_orientation_changed (MetaMonitorConfig *self, - MetaMonitorTransform transform); - -void meta_monitor_config_rotate_monitor (MetaMonitorConfig *self); - -gboolean meta_monitor_config_switch_config (MetaMonitorConfig *self, - MetaMonitorSwitchConfigType config_type); - -#endif /* META_MONITOR_CONFIG_H */ diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c index a8c2098aa..b45922b57 100644 --- a/src/backends/meta-monitor-manager-dummy.c +++ b/src/backends/meta-monitor-manager-dummy.c @@ -350,10 +350,8 @@ meta_monitor_manager_dummy_ensure_initial_config (MetaMonitorManager *manager) config = meta_monitor_manager_ensure_configured (manager); - if (meta_is_monitor_config_manager_enabled ()) - { - meta_monitor_manager_update_logical_state (manager, config); - } + if (meta_is_stage_views_enabled ()) + meta_monitor_manager_update_logical_state (manager, config); else { MetaMonitorManagerDeriveFlag flags = @@ -541,41 +539,6 @@ meta_monitor_manager_dummy_apply_monitors_config (MetaMonitorManager *manag return TRUE; } -static void -legacy_calculate_screen_size (MetaMonitorManager *manager) -{ - unsigned int i; - int width = 0, height = 0; - - for (i = 0; i < manager->n_crtcs; i++) - { - MetaCrtc *crtc = &manager->crtcs[i]; - - width = MAX (width, crtc->rect.x + crtc->rect.width); - height = MAX (height, crtc->rect.y + crtc->rect.height); - } - - manager->screen_width = width; - manager->screen_height = height; -} - -static void -meta_monitor_manager_dummy_apply_config (MetaMonitorManager *manager, - MetaCrtcInfo **crtcs, - unsigned int n_crtcs, - MetaOutputInfo **outputs, - unsigned int n_outputs) -{ - MetaMonitorManagerDeriveFlag flags = - META_MONITOR_MANAGER_DERIVE_FLAG_NONE; - - apply_crtc_assignments (manager, crtcs, n_crtcs, outputs, n_outputs); - - legacy_calculate_screen_size (manager); - - meta_monitor_manager_rebuild_derived (manager, flags); -} - static gboolean meta_monitor_manager_dummy_is_transform_handled (MetaMonitorManager *manager, MetaCrtc *crtc, @@ -687,7 +650,6 @@ meta_monitor_manager_dummy_class_init (MetaMonitorManagerDummyClass *klass) manager_class->read_current = meta_monitor_manager_dummy_read_current; manager_class->ensure_initial_config = meta_monitor_manager_dummy_ensure_initial_config; manager_class->apply_monitors_config = meta_monitor_manager_dummy_apply_monitors_config; - manager_class->apply_configuration = meta_monitor_manager_dummy_apply_config; manager_class->is_transform_handled = meta_monitor_manager_dummy_is_transform_handled; manager_class->calculate_monitor_mode_scale = meta_monitor_manager_dummy_calculate_monitor_mode_scale; manager_class->calculate_supported_scales = meta_monitor_manager_dummy_calculate_supported_scales; diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index 3ba74f31d..4d079bec7 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -48,7 +48,6 @@ #include "meta-dbus-display-config.h" #include "meta-cursor.h" -typedef struct _MetaMonitorConfig MetaMonitorConfig; typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager; typedef struct _MetaMonitorConfigStore MetaMonitorConfigStore; typedef struct _MetaMonitorsConfig MetaMonitorsConfig; @@ -261,11 +260,9 @@ struct _MetaCrtcMode /* * MetaCrtcInfo: - * This represents the writable part of a CRTC, as deserialized from DBus - * or built by MetaMonitorConfig * - * Note: differently from the other structures in this file, MetaCrtcInfo - * is handled by pointer. This is to accomodate the usage in MetaMonitorConfig + * A representation of a CRTC configuration, generated by + * MetaMonitorConfigManager. */ struct _MetaCrtcInfo { @@ -279,7 +276,9 @@ struct _MetaCrtcInfo /* * MetaOutputInfo: - * this is the same as MetaCrtcInfo, but for outputs + * + * A representation of a connector configuration, generated by + * MetaMonitorConfigManager. */ struct _MetaOutputInfo { @@ -289,12 +288,6 @@ struct _MetaOutputInfo gboolean is_underscanning; }; -typedef enum _MetaMonitorConfigSystem -{ - META_MONITOR_CONFIG_SYSTEM_LEGACY, - META_MONITOR_CONFIG_SYSTEM_MANAGER -} MetaMonitorConfigSystem; - #define META_TYPE_MONITOR_MANAGER (meta_monitor_manager_get_type ()) #define META_MONITOR_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_MONITOR_MANAGER, MetaMonitorManager)) #define META_MONITOR_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_MONITOR_MANAGER, MetaMonitorManagerClass)) @@ -343,11 +336,8 @@ struct _MetaMonitorManager int dbus_name_id; - MetaMonitorConfigSystem pending_persistent_system; int persistent_timeout_id; - MetaMonitorConfig *legacy_config; - MetaMonitorConfigManager *config_manager; GnomePnpIds *pnp_ids; @@ -378,12 +368,6 @@ struct _MetaMonitorManagerClass MetaMonitorsConfigMethod , GError **); - void (*apply_configuration) (MetaMonitorManager *, - MetaCrtcInfo **, - unsigned int , - MetaOutputInfo **, - unsigned int); - void (*set_power_save_mode) (MetaMonitorManager *, MetaPowerSave); @@ -433,8 +417,6 @@ struct _MetaMonitorManagerClass MetaLogicalMonitorLayoutMode (*get_default_layout_mode) (MetaMonitorManager *); }; -gboolean meta_is_monitor_config_manager_enabled (void); - void meta_monitor_manager_rebuild (MetaMonitorManager *manager, MetaMonitorsConfig *config); void meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager, @@ -484,12 +466,6 @@ void meta_monitor_manager_get_screen_size (MetaMonitorManager * int *width, int *height); -void meta_monitor_manager_apply_configuration (MetaMonitorManager *manager, - MetaCrtcInfo **crtcs, - unsigned int n_crtcs, - MetaOutputInfo **outputs, - unsigned int n_outputs); - void meta_monitor_manager_confirm_configuration (MetaMonitorManager *manager, gboolean ok); @@ -497,9 +473,6 @@ void meta_output_parse_edid (MetaOutput *output, GBytes *edid); gboolean meta_output_is_laptop (MetaOutput *output); -void meta_crtc_info_free (MetaCrtcInfo *info); -void meta_output_info_free (MetaOutputInfo *info); - gboolean meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager); void meta_monitor_manager_read_current_state (MetaMonitorManager *manager); void meta_monitor_manager_on_hotplug (MetaMonitorManager *manager); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 13acf059a..f029d68ce 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -36,7 +36,6 @@ #include "util-private.h" #include #include "edid.h" -#include "meta-monitor-config.h" #include "backends/meta-logical-monitor.h" #include "backends/meta-monitor.h" #include "backends/meta-monitor-config-manager.h" @@ -77,17 +76,6 @@ meta_monitor_manager_init (MetaMonitorManager *manager) { } -gboolean -meta_is_monitor_config_manager_enabled (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaSettings *settings = meta_backend_get_settings (backend); - - return meta_settings_is_experimental_feature_enabled ( - settings, - META_EXPERIMENTAL_FEATURE_MONITOR_CONFIG_MANAGER); -} - static void meta_monitor_manager_set_primary_logical_monitor (MetaMonitorManager *manager, MetaLogicalMonitor *logical_monitor) @@ -332,10 +320,7 @@ power_save_mode_changed (MetaMonitorManager *manager, void meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager) { - if (meta_is_monitor_config_manager_enabled ()) - meta_monitor_manager_ensure_configured (manager); - else - meta_monitor_config_lid_is_closed_changed (manager->legacy_config, manager); + meta_monitor_manager_ensure_configured (manager); } static void @@ -483,13 +468,6 @@ should_use_stored_config (MetaMonitorManager *manager) !meta_monitor_manager_has_hotplug_mode_update (manager)); } -static void -legacy_ensure_configured (MetaMonitorManager *manager) -{ - if (!meta_monitor_config_apply_stored (manager->legacy_config, manager)) - meta_monitor_config_make_default (manager->legacy_config, manager); -} - MetaMonitorsConfig * meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) { @@ -500,12 +478,6 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) MetaMonitorsConfigMethod fallback_method = META_MONITORS_CONFIG_METHOD_TEMPORARY; - if (!meta_is_monitor_config_manager_enabled ()) - { - legacy_ensure_configured (manager); - return NULL; - } - use_stored_config = should_use_stored_config (manager); if (use_stored_config) method = META_MONITORS_CONFIG_METHOD_PERSISTENT; @@ -612,6 +584,8 @@ orientation_changed (MetaOrientationManager *orientation_manager, MetaMonitorManager *manager) { MetaMonitorTransform transform; + GError *error = NULL; + MetaMonitorsConfig *config; switch (meta_orientation_manager_get_orientation (orientation_manager)) { @@ -633,30 +607,22 @@ orientation_changed (MetaOrientationManager *orientation_manager, return; } - if (!meta_is_monitor_config_manager_enabled ()) - { - meta_monitor_config_orientation_changed (manager->legacy_config, transform); - } - else - { - GError *error = NULL; - MetaMonitorsConfig *config = - meta_monitor_config_manager_create_for_orientation (manager->config_manager, - transform); - if (!config) - return; + config = + meta_monitor_config_manager_create_for_orientation (manager->config_manager, + transform); + if (!config) + return; - if (!meta_monitor_manager_apply_monitors_config (manager, - config, - META_MONITORS_CONFIG_METHOD_TEMPORARY, - &error)) - { - g_warning ("Failed to use orientation monitor configuration: %s", - error->message); - g_error_free (error); - } - g_object_unref (config); + if (!meta_monitor_manager_apply_monitors_config (manager, + config, + META_MONITORS_CONFIG_METHOD_TEMPORARY, + &error)) + { + g_warning ("Failed to use orientation monitor configuration: %s", + error->message); + g_error_free (error); } + g_object_unref (config); } static void @@ -664,21 +630,10 @@ experimental_features_changed (MetaSettings *settings, MetaExperimentalFeature old_experimental_features, MetaMonitorManager *manager) { - MetaDBusDisplayConfig *skeleton = META_DBUS_DISPLAY_CONFIG (manager); - gboolean was_config_manager_enabled; gboolean was_stage_views_scaled; - gboolean is_config_manager_enabled; gboolean is_stage_views_scaled; gboolean should_reconfigure = FALSE; - is_config_manager_enabled = meta_is_monitor_config_manager_enabled (); - was_config_manager_enabled = - meta_dbus_display_config_get_is_experimental_api_enabled (skeleton); - - if (was_config_manager_enabled != is_config_manager_enabled) - meta_dbus_display_config_set_is_experimental_api_enabled ( - skeleton, is_config_manager_enabled); - was_stage_views_scaled = !!(old_experimental_features & META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); @@ -687,8 +642,7 @@ experimental_features_changed (MetaSettings *settings, settings, META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); - if (is_config_manager_enabled != was_config_manager_enabled || - is_stage_views_scaled != was_stage_views_scaled) + if (is_stage_views_scaled != was_stage_views_scaled) should_reconfigure = TRUE; if (should_reconfigure) @@ -701,7 +655,6 @@ static void meta_monitor_manager_constructed (GObject *object) { MetaMonitorManager *manager = META_MONITOR_MANAGER (object); - MetaDBusDisplayConfig *skeleton = META_DBUS_DISPLAY_CONFIG (manager); MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_GET_CLASS (manager); MetaBackend *backend = meta_get_backend (); @@ -723,10 +676,6 @@ meta_monitor_manager_constructed (GObject *object) g_signal_connect_object (manager, "notify::power-save-mode", G_CALLBACK (power_save_mode_changed), manager, 0); - meta_dbus_display_config_set_is_experimental_api_enabled ( - skeleton, - meta_is_monitor_config_manager_enabled ()); - g_signal_connect_object (meta_backend_get_orientation_manager (backend), "orientation-changed", G_CALLBACK (orientation_changed), @@ -735,12 +684,7 @@ meta_monitor_manager_constructed (GObject *object) manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN; manager->in_init = TRUE; - /* - * MetaMonitorConfigManager will only be used if the corresponding - * experimental feature is enabled. - */ manager->config_manager = meta_monitor_config_manager_new (manager); - manager->legacy_config = meta_monitor_config_new (manager); meta_monitor_manager_read_current_state (manager); @@ -1157,61 +1101,6 @@ meta_monitor_manager_handle_get_resources (MetaDBusDisplayConfig *skeleton, return TRUE; } -static gboolean -output_can_config (MetaOutput *output, - MetaCrtc *crtc, - MetaCrtcMode *mode) -{ - unsigned int i; - gboolean ok = FALSE; - - for (i = 0; i < output->n_possible_crtcs && !ok; i++) - ok = output->possible_crtcs[i] == crtc; - - if (!ok) - return FALSE; - - if (mode == NULL) - return TRUE; - - ok = FALSE; - for (i = 0; i < output->n_modes && !ok; i++) - ok = output->modes[i] == mode; - - return ok; -} - -static gboolean -output_can_clone (MetaOutput *output, - MetaOutput *clone) -{ - unsigned int i; - gboolean ok = FALSE; - - for (i = 0; i < output->n_possible_clones && !ok; i++) - ok = output->possible_clones[i] == clone; - - return ok; -} - -void -meta_monitor_manager_apply_configuration (MetaMonitorManager *manager, - MetaCrtcInfo **crtcs, - unsigned int n_crtcs, - MetaOutputInfo **outputs, - unsigned int n_outputs) -{ - META_MONITOR_MANAGER_GET_CLASS (manager)->apply_configuration (manager, - crtcs, n_crtcs, - outputs, n_outputs); -} - -static void -legacy_restore_previous_config (MetaMonitorManager *manager) -{ - meta_monitor_config_restore_previous (manager->legacy_config, manager); -} - static void restore_previous_config (MetaMonitorManager *manager) { @@ -1258,17 +1147,9 @@ save_config_timeout (gpointer user_data) { MetaMonitorManager *manager = user_data; - switch (manager->pending_persistent_system) - { - case META_MONITOR_CONFIG_SYSTEM_LEGACY: - legacy_restore_previous_config (manager); - break; - case META_MONITOR_CONFIG_SYSTEM_MANAGER: - restore_previous_config (manager); - break; - } - + restore_previous_config (manager); manager->persistent_timeout_id = 0; + return G_SOURCE_REMOVE; } @@ -1280,10 +1161,8 @@ cancel_persistent_confirmation (MetaMonitorManager *manager) } static void -request_persistent_confirmation (MetaMonitorManager *manager, - MetaMonitorConfigSystem system) +request_persistent_confirmation (MetaMonitorManager *manager) { - manager->pending_persistent_system = system; manager->persistent_timeout_id = g_timeout_add_seconds (meta_monitor_manager_get_display_configuration_timeout (), save_config_timeout, manager); @@ -1293,250 +1172,6 @@ request_persistent_confirmation (MetaMonitorManager *manager, g_signal_emit (manager, signals[CONFIRM_DISPLAY_CHANGE], 0); } -static gboolean -meta_monitor_manager_legacy_handle_apply_configuration (MetaDBusDisplayConfig *skeleton, - GDBusMethodInvocation *invocation, - guint serial, - gboolean persistent, - GVariant *crtcs, - GVariant *outputs) -{ - MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton); - GVariantIter crtc_iter, output_iter, *nested_outputs; - GVariant *properties; - guint crtc_id; - int new_mode, x, y; - int new_screen_width, new_screen_height; - guint transform; - guint output_index; - GPtrArray *crtc_infos, *output_infos; - - if (meta_monitor_config_manager_get_current (manager->config_manager)) - meta_monitor_config_manager_set_current (manager->config_manager, NULL); - - if (serial != manager->serial) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_ACCESS_DENIED, - "The requested configuration is based on stale information"); - return TRUE; - } - - crtc_infos = g_ptr_array_new_full (g_variant_n_children (crtcs), - (GDestroyNotify) meta_crtc_info_free); - output_infos = g_ptr_array_new_full (g_variant_n_children (outputs), - (GDestroyNotify) meta_output_info_free); - - /* Validate all arguments */ - new_screen_width = 0; new_screen_height = 0; - g_variant_iter_init (&crtc_iter, crtcs); - while (g_variant_iter_loop (&crtc_iter, "(uiiiuaua{sv})", - &crtc_id, &new_mode, &x, &y, &transform, - &nested_outputs, NULL)) - { - MetaCrtcInfo *crtc_info; - MetaOutput *first_output; - MetaCrtc *crtc; - MetaCrtcMode *mode; - - crtc_info = g_slice_new (MetaCrtcInfo); - crtc_info->outputs = g_ptr_array_new (); - - if (crtc_id >= manager->n_crtcs) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid CRTC id"); - return TRUE; - } - crtc = &manager->crtcs[crtc_id]; - crtc_info->crtc = crtc; - - if (new_mode != -1 && (new_mode < 0 || (unsigned)new_mode >= manager->n_modes)) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid mode id"); - return TRUE; - } - mode = new_mode != -1 ? &manager->modes[new_mode] : NULL; - crtc_info->mode = mode; - - if (mode) - { - int width, height; - int max_screen_width, max_screen_height; - - if (meta_monitor_transform_is_rotated (transform)) - { - width = mode->height; - height = mode->width; - } - else - { - width = mode->width; - height = mode->height; - } - - if (x < 0 || y < 0) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid CRTC geometry"); - return TRUE; - } - - if (meta_monitor_manager_get_max_screen_size (manager, - &max_screen_width, - &max_screen_height)) - { - if (x + width > max_screen_width || - y + height > max_screen_height) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid CRTC geometry"); - return TRUE; - } - } - - new_screen_width = MAX (new_screen_width, x + width); - new_screen_height = MAX (new_screen_height, y + height); - crtc_info->x = x; - crtc_info->y = y; - } - else - { - crtc_info->x = 0; - crtc_info->y = 0; - } - - if (transform > META_MONITOR_TRANSFORM_FLIPPED_270 || - ((crtc->all_transforms & (1 << transform)) == 0)) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid transform"); - return TRUE; - } - crtc_info->transform = transform; - - first_output = NULL; - while (g_variant_iter_loop (nested_outputs, "u", &output_index)) - { - MetaOutput *output; - - if (output_index >= manager->n_outputs) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid output id"); - return TRUE; - } - output = &manager->outputs[output_index]; - - if (!output_can_config (output, crtc, mode)) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Output cannot be assigned to this CRTC or mode"); - return TRUE; - } - g_ptr_array_add (crtc_info->outputs, output); - - if (first_output) - { - if (!output_can_clone (output, first_output)) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Outputs cannot be cloned"); - return TRUE; - } - } - else - first_output = output; - } - - if (!first_output && mode) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Mode specified without outputs?"); - return TRUE; - } - - g_ptr_array_add (crtc_infos, crtc_info); - } - - if (new_screen_width == 0 || new_screen_height == 0) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Refusing to disable all outputs"); - return TRUE; - } - - g_variant_iter_init (&output_iter, outputs); - while (g_variant_iter_loop (&output_iter, "(u@a{sv})", &output_index, &properties)) - { - MetaOutputInfo *output_info; - gboolean primary, presentation, underscanning; - - if (output_index >= manager->n_outputs) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_INVALID_ARGS, - "Invalid output id"); - return TRUE; - } - - output_info = g_slice_new0 (MetaOutputInfo); - output_info->output = &manager->outputs[output_index]; - - if (g_variant_lookup (properties, "primary", "b", &primary)) - output_info->is_primary = primary; - - if (g_variant_lookup (properties, "presentation", "b", &presentation)) - output_info->is_presentation = presentation; - - if (g_variant_lookup (properties, "underscanning", "b", &underscanning)) - output_info->is_underscanning = underscanning; - - g_ptr_array_add (output_infos, output_info); - } - - /* If we were in progress of making a persistent change and we see a - new request, it's likely that the old one failed in some way, so - don't save it, but also don't queue for restoring it. - */ - if (manager->persistent_timeout_id && persistent) - cancel_persistent_confirmation (manager); - - meta_monitor_manager_apply_configuration (manager, - (MetaCrtcInfo**)crtc_infos->pdata, - crtc_infos->len, - (MetaOutputInfo**)output_infos->pdata, - output_infos->len); - - g_ptr_array_unref (crtc_infos); - g_ptr_array_unref (output_infos); - - /* Update MetaMonitorConfig data structures immediately so that we - don't revert the change at the next XRandR event, then ask the plugin - manager (through MetaScreen) to confirm the display change with the - appropriate UI. Then wait 20 seconds and if not confirmed, revert the - configuration. - */ - meta_monitor_config_update_current (manager->legacy_config, manager); - if (persistent) - request_persistent_confirmation (manager, - META_MONITOR_CONFIG_SYSTEM_LEGACY); - - meta_dbus_display_config_complete_apply_configuration (skeleton, invocation); - return TRUE; -} - #define META_DISPLAY_CONFIG_MODE_FLAGS_PREFERRED (1 << 0) #define META_DISPLAY_CONFIG_MODE_FLAGS_CURRENT (1 << 1) @@ -1563,14 +1198,6 @@ meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton, MetaMonitorManagerCapability capabilities; int max_screen_width, max_screen_height; - if (!meta_is_monitor_config_manager_enabled ()) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_ACCESS_DENIED, - "This experimental API is currently not enabled"); - return TRUE; - } - g_variant_builder_init (&monitors_builder, G_VARIANT_TYPE (MONITORS_FORMAT)); g_variant_builder_init (&logical_monitors_builder, @@ -2175,14 +1802,6 @@ meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skelet GList *logical_monitor_configs = NULL; GError *error = NULL; - if (!meta_is_monitor_config_manager_enabled ()) - { - g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, - G_DBUS_ERROR_ACCESS_DENIED, - "This experimental API is currently not enabled"); - return TRUE; - } - if (serial != manager->serial) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -2293,9 +1912,7 @@ meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skelet } if (method == META_MONITORS_CONFIG_METHOD_PERSISTENT) - request_persistent_confirmation (manager, - META_MONITOR_CONFIG_SYSTEM_MANAGER); - + request_persistent_confirmation (manager); meta_dbus_display_config_complete_apply_monitors_config (skeleton, invocation); @@ -2307,16 +1924,6 @@ meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skelet #undef MONITOR_CONFIGS_FORMAT #undef LOGICAL_MONITOR_CONFIG_FORMAT -static void -legacy_confirm_configuration (MetaMonitorManager *manager, - gboolean confirmed) -{ - if (confirmed) - meta_monitor_config_make_persistent (manager->legacy_config); - else - meta_monitor_config_restore_previous (manager->legacy_config, manager); -} - static void confirm_configuration (MetaMonitorManager *manager, gboolean confirmed) @@ -2338,15 +1945,7 @@ meta_monitor_manager_confirm_configuration (MetaMonitorManager *manager, } cancel_persistent_confirmation (manager); - switch (manager->pending_persistent_system) - { - case META_MONITOR_CONFIG_SYSTEM_LEGACY: - legacy_confirm_configuration (manager, ok); - break; - case META_MONITOR_CONFIG_SYSTEM_MANAGER: - confirm_configuration (manager, ok); - break; - } + confirm_configuration (manager, ok); } static gboolean @@ -2506,7 +2105,6 @@ meta_monitor_manager_handle_set_crtc_gamma (MetaDBusDisplayConfig *skeleton, klass = META_MONITOR_MANAGER_GET_CLASS (manager); if (klass->set_crtc_gamma) klass->set_crtc_gamma (manager, crtc, size, red, green, blue); - meta_dbus_display_config_complete_set_crtc_gamma (skeleton, invocation); g_bytes_unref (red_bytes); @@ -2520,7 +2118,6 @@ static void meta_monitor_manager_display_config_init (MetaDBusDisplayConfigIface *iface) { iface->handle_get_resources = meta_monitor_manager_handle_get_resources; - iface->handle_apply_configuration = meta_monitor_manager_legacy_handle_apply_configuration; iface->handle_change_backlight = meta_monitor_manager_handle_change_backlight; iface->handle_get_crtc_gamma = meta_monitor_manager_handle_get_crtc_gamma; iface->handle_set_crtc_gamma = meta_monitor_manager_handle_set_crtc_gamma; @@ -3079,35 +2676,9 @@ meta_output_is_laptop (MetaOutput *output) } } -static void -legacy_on_hotplug (MetaMonitorManager *manager) -{ - gboolean applied_config = FALSE; - - /* If the monitor has hotplug_mode_update (which is used by VMs), don't bother - * applying our stored configuration, because it's likely the user just resizing - * the window. - */ - if (!meta_monitor_manager_has_hotplug_mode_update (manager)) - { - if (meta_monitor_config_apply_stored (manager->legacy_config, manager)) - applied_config = TRUE; - } - - /* If we haven't applied any configuration, apply the default configuration. */ - if (!applied_config) - meta_monitor_config_make_default (manager->legacy_config, manager); -} - void meta_monitor_manager_on_hotplug (MetaMonitorManager *manager) { - if (!meta_is_monitor_config_manager_enabled ()) - { - legacy_on_hotplug (manager); - return; - } - meta_monitor_manager_ensure_configured (manager); } @@ -3244,67 +2815,54 @@ meta_monitor_manager_get_is_builtin_display_on (MetaMonitorManager *manager) void meta_monitor_manager_rotate_monitor (MetaMonitorManager *manager) { - if (!meta_is_monitor_config_manager_enabled ()) - { - meta_monitor_config_rotate_monitor (manager->legacy_config); - } - else - { - GError *error = NULL; - MetaMonitorsConfig *config = - meta_monitor_config_manager_create_for_rotate_monitor (manager->config_manager); + GError *error = NULL; + MetaMonitorsConfig *config = + meta_monitor_config_manager_create_for_rotate_monitor (manager->config_manager); - if (!config) - return; + if (!config) + return; - if (!meta_monitor_manager_apply_monitors_config (manager, - config, - META_MONITORS_CONFIG_METHOD_TEMPORARY, - &error)) - { - g_warning ("Failed to use rotate monitor configuration: %s", - error->message); - g_error_free (error); - } - g_object_unref (config); + if (!meta_monitor_manager_apply_monitors_config (manager, + config, + META_MONITORS_CONFIG_METHOD_TEMPORARY, + &error)) + { + g_warning ("Failed to use rotate monitor configuration: %s", + error->message); + g_error_free (error); } + g_object_unref (config); } void meta_monitor_manager_switch_config (MetaMonitorManager *manager, MetaMonitorSwitchConfigType config_type) { + GError *error = NULL; + MetaMonitorsConfig *config; + g_return_if_fail (config_type != META_MONITOR_SWITCH_CONFIG_UNKNOWN); - if (!meta_is_monitor_config_manager_enabled ()) + config = + meta_monitor_config_manager_create_for_switch_config (manager->config_manager, + config_type); + if (!config) + return; + + if (!meta_monitor_manager_apply_monitors_config (manager, + config, + META_MONITORS_CONFIG_METHOD_TEMPORARY, + &error)) { - if (meta_monitor_config_switch_config (manager->legacy_config, config_type)) - manager->current_switch_config = config_type; + g_warning ("Failed to use switch monitor configuration: %s", + error->message); + g_error_free (error); } else { - GError *error = NULL; - MetaMonitorsConfig *config = - meta_monitor_config_manager_create_for_switch_config (manager->config_manager, - config_type); - if (!config) - return; - - if (!meta_monitor_manager_apply_monitors_config (manager, - config, - META_MONITORS_CONFIG_METHOD_TEMPORARY, - &error)) - { - g_warning ("Failed to use switch monitor configuration: %s", - error->message); - g_error_free (error); - } - else - { - manager->current_switch_config = config_type; - } - g_object_unref (config); + manager->current_switch_config = config_type; } + g_object_unref (config); } gboolean diff --git a/src/backends/meta-settings-private.h b/src/backends/meta-settings-private.h index 4e13edcd5..494112bf7 100644 --- a/src/backends/meta-settings-private.h +++ b/src/backends/meta-settings-private.h @@ -31,7 +31,6 @@ typedef enum _MetaExperimentalFeature { META_EXPERIMENTAL_FEATURE_NONE = 0, META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER = (1 << 0), - META_EXPERIMENTAL_FEATURE_MONITOR_CONFIG_MANAGER = (1 << 1) } MetaExperimentalFeature; #define META_TYPE_SETTINGS (meta_settings_get_type ()) diff --git a/src/backends/meta-settings.c b/src/backends/meta-settings.c index 4b7df5f9a..b7c4a96d4 100644 --- a/src/backends/meta-settings.c +++ b/src/backends/meta-settings.c @@ -86,37 +86,15 @@ calculate_ui_scaling_factor (MetaSettings *settings) return (int) max_scale; } -static int -get_xsettings_scaling_factor (void) -{ - GdkScreen *screen; - GValue value = G_VALUE_INIT; - - g_value_init (&value, G_TYPE_INT); - - screen = gdk_screen_get_default (); - if (gdk_screen_get_setting (screen, "gdk-window-scaling-factor", &value)) - return g_value_get_int (&value); - else - return 1; -} - static gboolean update_ui_scaling_factor (MetaSettings *settings) { int ui_scaling_factor; if (meta_is_stage_views_scaled ()) - { - ui_scaling_factor = 1; - } + ui_scaling_factor = 1; else - { - if (meta_is_monitor_config_manager_enabled ()) - ui_scaling_factor = calculate_ui_scaling_factor (settings); - else - ui_scaling_factor = get_xsettings_scaling_factor (); - } + ui_scaling_factor = calculate_ui_scaling_factor (settings); if (settings->ui_scaling_factor != ui_scaling_factor) { @@ -129,34 +107,6 @@ update_ui_scaling_factor (MetaSettings *settings) } } -static void -xft_dpi_changed (GtkSettings *gtk_settings, - GParamSpec *pspec, - MetaSettings *settings) -{ - /* This only matters when we rely on XSettings. */ - if (meta_is_monitor_config_manager_enabled ()) - return; - - meta_settings_update_ui_scaling_factor (settings); -} - -static void -x11_display_opened (MetaBackend *backend, - MetaSettings *settings) -{ - /* - * gdk-window-scaling-factor is not exported to gtk-settings - * because it is handled inside gdk, so we use gtk-xft-dpi instead - * which also changes when the scale factor changes. - * - * TODO: Only rely on our own configured scale when we only have - * MetaMonitorConfigManager. - */ - g_signal_connect (gtk_settings_get_default (), "notify::gtk-xft-dpi", - G_CALLBACK (xft_dpi_changed), settings); -} - void meta_settings_update_ui_scaling_factor (MetaSettings *settings) { @@ -312,8 +262,6 @@ experimental_features_handler (GVariant *features_variant, /* So far no experimental features defined. */ if (g_str_equal (feature, "scale-monitor-framebuffer")) features |= META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER; - else if (g_str_equal (feature, "monitor-config-manager")) - features |= META_EXPERIMENTAL_FEATURE_MONITOR_CONFIG_MANAGER; else g_info ("Unknown experimental feature '%s'\n", feature); } @@ -364,10 +312,6 @@ meta_settings_new (MetaBackend *backend) settings = g_object_new (META_TYPE_SETTINGS, NULL); settings->backend = backend; - g_signal_connect (backend, "x11-display-opened", - G_CALLBACK (x11_display_opened), - settings); - return settings; } diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index d1cd46ee1..2cb145fb0 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -24,7 +24,6 @@ #include "config.h" #include "meta-monitor-manager-kms.h" -#include "meta-monitor-config.h" #include "meta-monitor-config-manager.h" #include "meta-backend-private.h" #include "meta-renderer-native.h" @@ -1253,17 +1252,7 @@ meta_monitor_manager_kms_ensure_initial_config (MetaMonitorManager *manager) config = meta_monitor_manager_ensure_configured (manager); - if (meta_is_monitor_config_manager_enabled ()) - { - meta_monitor_manager_update_logical_state (manager, config); - } - else - { - MetaMonitorManagerDeriveFlag flags = - META_MONITOR_MANAGER_DERIVE_FLAG_NONE; - - meta_monitor_manager_update_logical_state_derived (manager, flags); - } + meta_monitor_manager_update_logical_state (manager, config); } static void @@ -1469,40 +1458,6 @@ meta_monitor_manager_kms_apply_monitors_config (MetaMonitorManager *manager return TRUE; } -static void -legacy_calculate_screen_size (MetaMonitorManager *manager) -{ - unsigned int i; - int width = 0, height = 0; - - for (i = 0; i < manager->n_crtcs; i++) - { - MetaCrtc *crtc = &manager->crtcs[i]; - - width = MAX (width, crtc->rect.x + crtc->rect.width); - height = MAX (height, crtc->rect.y + crtc->rect.height); - } - - manager->screen_width = width; - manager->screen_height = height; -} - -static void -meta_monitor_manager_kms_apply_configuration (MetaMonitorManager *manager, - MetaCrtcInfo **crtcs, - unsigned int n_crtcs, - MetaOutputInfo **outputs, - unsigned int n_outputs) -{ - MetaMonitorManagerDeriveFlag flags = - META_MONITOR_MANAGER_DERIVE_FLAG_NONE; - - apply_crtc_assignments (manager, crtcs, n_crtcs, outputs, n_outputs); - - legacy_calculate_screen_size (manager); - meta_monitor_manager_rebuild_derived (manager, flags); -} - static void meta_monitor_manager_kms_get_crtc_gamma (MetaMonitorManager *manager, MetaCrtc *crtc, @@ -1961,7 +1916,6 @@ meta_monitor_manager_kms_class_init (MetaMonitorManagerKmsClass *klass) manager_class->read_edid = meta_monitor_manager_kms_read_edid; manager_class->ensure_initial_config = meta_monitor_manager_kms_ensure_initial_config; manager_class->apply_monitors_config = meta_monitor_manager_kms_apply_monitors_config; - manager_class->apply_configuration = meta_monitor_manager_kms_apply_configuration; manager_class->set_power_save_mode = meta_monitor_manager_kms_set_power_save_mode; manager_class->get_crtc_gamma = meta_monitor_manager_kms_get_crtc_gamma; manager_class->set_crtc_gamma = meta_monitor_manager_kms_set_crtc_gamma; diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c index 1d1bc6e8f..ed4b841de 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -43,7 +43,6 @@ #include "meta-backend-x11.h" #include #include -#include "meta-monitor-config.h" #include "backends/meta-monitor-config-manager.h" #include "backends/meta-logical-monitor.h" @@ -1465,8 +1464,7 @@ apply_crtc_assignments (MetaMonitorManager *manager, static void meta_monitor_manager_xrandr_ensure_initial_config (MetaMonitorManager *manager) { - MetaMonitorManagerDeriveFlag flags = - META_MONITOR_MANAGER_DERIVE_FLAG_NONE; + MetaMonitorManagerDeriveFlag flags; meta_monitor_manager_ensure_configured (manager); @@ -1477,9 +1475,7 @@ meta_monitor_manager_xrandr_ensure_initial_config (MetaMonitorManager *manager) */ meta_monitor_manager_read_current_state (manager); - if (meta_is_monitor_config_manager_enabled ()) - flags |= META_MONITOR_MANAGER_DERIVE_FLAG_CONFIGURED_SCALE; - + flags = META_MONITOR_MANAGER_DERIVE_FLAG_CONFIGURED_SCALE; meta_monitor_manager_update_logical_state_derived (manager, flags); } @@ -1545,16 +1541,6 @@ meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager *mana return TRUE; } -static void -meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager, - MetaCrtcInfo **crtcs, - unsigned int n_crtcs, - MetaOutputInfo **outputs, - unsigned int n_outputs) -{ - apply_crtc_assignments (manager, FALSE, crtcs, n_crtcs, outputs, n_outputs); -} - static void meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager, MetaOutput *output, @@ -1909,7 +1895,6 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass) manager_class->read_edid = meta_monitor_manager_xrandr_read_edid; manager_class->ensure_initial_config = meta_monitor_manager_xrandr_ensure_initial_config; manager_class->apply_monitors_config = meta_monitor_manager_xrandr_apply_monitors_config; - manager_class->apply_configuration = meta_monitor_manager_xrandr_apply_configuration; manager_class->set_power_save_mode = meta_monitor_manager_xrandr_set_power_save_mode; manager_class->change_backlight = meta_monitor_manager_xrandr_change_backlight; manager_class->get_crtc_gamma = meta_monitor_manager_xrandr_get_crtc_gamma; diff --git a/src/core/display.c b/src/core/display.c index c2dbe7e7e..dc4d8dfe5 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -963,8 +963,6 @@ meta_display_open (void) meta_screen_init_workspaces (screen); - meta_backend_x11_display_opened (meta_get_backend ()); - enable_compositor (display); meta_screen_create_guard_window (screen); diff --git a/src/org.gnome.Mutter.DisplayConfig.xml b/src/org.gnome.Mutter.DisplayConfig.xml index 015face14..aab2e0faf 100644 --- a/src/org.gnome.Mutter.DisplayConfig.xml +++ b/src/org.gnome.Mutter.DisplayConfig.xml @@ -291,17 +291,6 @@ --> - - -