Migrate old monitor configuration files to new system

This commit changes the new configuration system to use monitors.xml
instead of monitors-experimental.xml. When starting up and the
monitors.xml file is loaded, if a legacy monitors.xml file is
discovered (it has the version number 1), an attempt is made to migrate
the stored configuration onto the new system.

This is done in two steps:

1) Parsing and translation of the old configuration. This works by
parsing file using the mostly the old parser, but then translating the
resulting configuration structs into the new configuration system. As
the legacy configuration system doesn't carry over some state (such as
tiling and scale used), some things are not available. For tiling, the
migration paths makes an attempt to discover tiled monitors by
comparing EDID data, and guessing what the main tile is. Determination
of the scale of a migrated configuration is postponed until the
configuration is actually applied. This works by flagging the
configuration as 'migrated'.

2) Finishing the migration when applying. When a configuration with the
'migrated' flag is retrieved from the configuration store, the final
step of the migration is taken place. This involves calculating the
preferred scale given the mode configured, while making sure this
doesn't result in any overlapping logical monitor regions etc.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2017-08-10 15:12:41 +08:00
parent 27a4f9f862
commit bc3162460f
9 changed files with 1454 additions and 37 deletions

View File

@ -111,6 +111,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES = \
backends/meta-logical-monitor.h \ backends/meta-logical-monitor.h \
backends/meta-monitor-config-manager.c \ backends/meta-monitor-config-manager.c \
backends/meta-monitor-config-manager.h \ backends/meta-monitor-config-manager.h \
backends/meta-monitor-config-migration.c \
backends/meta-monitor-config-migration.h \
backends/meta-monitor-config-store.c \ backends/meta-monitor-config-store.c \
backends/meta-monitor-config-store.h \ backends/meta-monitor-config-store.h \
backends/meta-monitor.c \ backends/meta-monitor.c \

View File

@ -23,6 +23,7 @@
#include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-manager.h"
#include "backends/meta-monitor-config-migration.h"
#include "backends/meta-monitor-config-store.h" #include "backends/meta-monitor-config-store.h"
#include "backends/meta-monitor-manager-private.h" #include "backends/meta-monitor-manager-private.h"
#include "core/boxes-private.h" #include "core/boxes-private.h"
@ -361,10 +362,12 @@ create_key_for_current_state (MetaMonitorManager *monitor_manager)
MetaMonitorsConfig * MetaMonitorsConfig *
meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager) meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager)
{ {
MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
MetaMonitorsConfigKey *config_key; MetaMonitorsConfigKey *config_key;
MetaMonitorsConfig *config; MetaMonitorsConfig *config;
GError *error = NULL;
config_key = create_key_for_current_state (config_manager->monitor_manager); config_key = create_key_for_current_state (monitor_manager);
if (!config_key) if (!config_key)
return NULL; return NULL;
@ -372,6 +375,22 @@ meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager
config_key); config_key);
meta_monitors_config_key_free (config_key); meta_monitors_config_key_free (config_key);
if (!config)
return NULL;
if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
{
if (!meta_finish_monitors_config_migration (monitor_manager, config,
&error))
{
g_warning ("Failed to finish monitors config migration: %s",
error->message);
g_error_free (error);
meta_monitor_config_store_remove (config_manager->config_store, config);
return NULL;
}
}
return config; return config;
} }
@ -591,7 +610,8 @@ meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_mana
x += logical_monitor_config->layout.width; x += logical_monitor_config->layout.width;
} }
return meta_monitors_config_new (logical_monitor_configs, layout_mode); return meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
MetaMonitorsConfig * MetaMonitorsConfig *
@ -619,7 +639,8 @@ meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_ma
logical_monitor_configs = g_list_append (NULL, logical_monitor_configs = g_list_append (NULL,
primary_logical_monitor_config); primary_logical_monitor_config);
return meta_monitors_config_new (logical_monitor_configs, layout_mode); return meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
MetaMonitorsConfig * MetaMonitorsConfig *
@ -694,7 +715,8 @@ meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_m
if (!logical_monitor_configs) if (!logical_monitor_configs)
return NULL; return NULL;
return meta_monitors_config_new (logical_monitor_configs, layout_mode); return meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
static MetaMonitorsConfig * static MetaMonitorsConfig *
@ -741,7 +763,8 @@ create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
logical_monitor_config->transform = transform; logical_monitor_config->transform = transform;
return meta_monitors_config_new (g_list_append (NULL, logical_monitor_config), return meta_monitors_config_new (g_list_append (NULL, logical_monitor_config),
config_manager->current_config->layout_mode); config_manager->current_config->layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
MetaMonitorsConfig * MetaMonitorsConfig *
@ -761,6 +784,7 @@ static MetaMonitorsConfig *
create_for_switch_config_all_mirror (MetaMonitorConfigManager *config_manager) create_for_switch_config_all_mirror (MetaMonitorConfigManager *config_manager)
{ {
MetaMonitorManager *monitor_manager = config_manager->monitor_manager; MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
MetaLogicalMonitorLayoutMode layout_mode;
MetaLogicalMonitorConfig *logical_monitor_config = NULL; MetaLogicalMonitorConfig *logical_monitor_config = NULL;
GList *monitor_configs = NULL; GList *monitor_configs = NULL;
gint common_mode_w = 0, common_mode_h = 0; gint common_mode_w = 0, common_mode_h = 0;
@ -859,8 +883,10 @@ create_for_switch_config_all_mirror (MetaMonitorConfigManager *config_manager)
.monitor_configs = monitor_configs .monitor_configs = monitor_configs
}; };
layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
return meta_monitors_config_new (g_list_append (NULL, logical_monitor_config), return meta_monitors_config_new (g_list_append (NULL, logical_monitor_config),
meta_monitor_manager_get_default_layout_mode (monitor_manager)); layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
static MetaMonitorsConfig * static MetaMonitorsConfig *
@ -899,7 +925,8 @@ create_for_switch_config_external (MetaMonitorConfigManager *config_manager)
x += logical_monitor_config->layout.width; x += logical_monitor_config->layout.width;
} }
return meta_monitors_config_new (logical_monitor_configs, layout_mode); return meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
static MetaMonitorsConfig * static MetaMonitorsConfig *
@ -927,7 +954,8 @@ create_for_switch_config_builtin (MetaMonitorConfigManager *config_manager)
logical_monitor_configs = g_list_append (NULL, logical_monitor_configs = g_list_append (NULL,
primary_logical_monitor_config); primary_logical_monitor_config);
return meta_monitors_config_new (logical_monitor_configs, layout_mode); return meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
} }
MetaMonitorsConfig * MetaMonitorsConfig *
@ -1117,7 +1145,8 @@ meta_monitors_config_key_equal (gconstpointer data_a,
MetaMonitorsConfig * MetaMonitorsConfig *
meta_monitors_config_new (GList *logical_monitor_configs, meta_monitors_config_new (GList *logical_monitor_configs,
MetaLogicalMonitorLayoutMode layout_mode) MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitorsConfigFlag flags)
{ {
MetaMonitorsConfig *config; MetaMonitorsConfig *config;
@ -1125,6 +1154,7 @@ meta_monitors_config_new (GList *logical_monitor_configs,
config->logical_monitor_configs = logical_monitor_configs; config->logical_monitor_configs = logical_monitor_configs;
config->key = meta_monitors_config_key_new (logical_monitor_configs); config->key = meta_monitors_config_key_new (logical_monitor_configs);
config->layout_mode = layout_mode; config->layout_mode = layout_mode;
config->flags = flags;
return config; return config;
} }

View File

@ -51,6 +51,12 @@ typedef struct _MetaMonitorsConfigKey
GList *monitor_specs; GList *monitor_specs;
} MetaMonitorsConfigKey; } MetaMonitorsConfigKey;
typedef enum _MetaMonitorsConfigFlag
{
META_MONITORS_CONFIG_FLAG_NONE = 0,
META_MONITORS_CONFIG_FLAG_MIGRATED = (1 << 0),
} MetaMonitorsConfigFlag;
struct _MetaMonitorsConfig struct _MetaMonitorsConfig
{ {
GObject parent; GObject parent;
@ -58,6 +64,8 @@ struct _MetaMonitorsConfig
MetaMonitorsConfigKey *key; MetaMonitorsConfigKey *key;
GList *logical_monitor_configs; GList *logical_monitor_configs;
MetaMonitorsConfigFlag flags;
MetaLogicalMonitorLayoutMode layout_mode; MetaLogicalMonitorLayoutMode layout_mode;
}; };
@ -101,7 +109,8 @@ MetaMonitorsConfig * meta_monitor_config_manager_get_previous (MetaMonitorConfig
void meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager); void meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager);
MetaMonitorsConfig * meta_monitors_config_new (GList *logical_monitor_configs, MetaMonitorsConfig * meta_monitors_config_new (GList *logical_monitor_configs,
MetaLogicalMonitorLayoutMode layout_mode); MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitorsConfigFlag flags);
unsigned int meta_monitors_config_key_hash (gconstpointer config_key); unsigned int meta_monitors_config_key_hash (gconstpointer config_key);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2017 Red Hat
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef META_MONITOR_CONFIG_MIGRATION_H
#define META_MONITOR_CONFIG_MIGRATION_H
#include "backends/meta-monitor-manager-private.h"
gboolean meta_migrate_old_monitors_config (MetaMonitorConfigStore *config_store,
GFile *in_file,
GError **error);
gboolean meta_migrate_old_user_monitors_config (MetaMonitorConfigStore *config_store,
GError **error);
gboolean meta_finish_monitors_config_migration (MetaMonitorManager *monitor_manager,
MetaMonitorsConfig *config,
GError **error);
#endif /* META_MONITOR_CONFIG_MIGRATION_H */

View File

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-manager.h"
#include "backends/meta-monitor-config-migration.h"
#define MONITORS_CONFIG_XML_FORMAT_VERSION 2 #define MONITORS_CONFIG_XML_FORMAT_VERSION 2
@ -109,14 +110,27 @@ struct _MetaMonitorConfigStore
GCancellable *save_cancellable; GCancellable *save_cancellable;
GFile *user_file; GFile *user_file;
GFile *custom_file; GFile *custom_read_file;
GFile *custom_write_file;
}; };
#define META_MONITOR_CONFIG_STORE_ERROR (meta_monitor_config_store_error_quark ())
static GQuark meta_monitor_config_store_error_quark (void);
enum
{
META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION
};
G_DEFINE_QUARK (meta-monitor-config-store-error-quark,
meta_monitor_config_store_error)
typedef enum typedef enum
{ {
STATE_INITIAL, STATE_INITIAL,
STATE_MONITORS, STATE_MONITORS,
STATE_CONFIGURATION, STATE_CONFIGURATION,
STATE_MIGRATED,
STATE_LOGICAL_MONITOR, STATE_LOGICAL_MONITOR,
STATE_LOGICAL_MONITOR_X, STATE_LOGICAL_MONITOR_X,
STATE_LOGICAL_MONITOR_Y, STATE_LOGICAL_MONITOR_Y,
@ -145,6 +159,7 @@ typedef struct
ParserState state; ParserState state;
MetaMonitorConfigStore *config_store; MetaMonitorConfigStore *config_store;
gboolean current_was_migrated;
GList *current_logical_monitor_configs; GList *current_logical_monitor_configs;
MetaMonitorSpec *current_monitor_spec; MetaMonitorSpec *current_monitor_spec;
gboolean current_transform_flipped; gboolean current_transform_flipped;
@ -189,7 +204,14 @@ handle_start_element (GMarkupParseContext *context,
"Missing config file format version"); "Missing config file format version");
} }
/* TODO: Handle converting version 1 configuration files. */ if (g_str_equal (version, "1"))
{
g_set_error_literal (error,
META_MONITOR_CONFIG_STORE_ERROR,
META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION,
"monitors.xml has the old format");
return;
}
if (!g_str_equal (version, QUOTE (MONITORS_CONFIG_XML_FORMAT_VERSION))) if (!g_str_equal (version, QUOTE (MONITORS_CONFIG_XML_FORMAT_VERSION)))
{ {
@ -212,22 +234,40 @@ handle_start_element (GMarkupParseContext *context,
} }
parser->state = STATE_CONFIGURATION; parser->state = STATE_CONFIGURATION;
parser->current_was_migrated = FALSE;
return; return;
} }
case STATE_CONFIGURATION: case STATE_CONFIGURATION:
{ {
if (!g_str_equal (element_name, "logicalmonitor")) if (g_str_equal (element_name, "logicalmonitor"))
{
parser->current_logical_monitor_config =
g_new0 (MetaLogicalMonitorConfig, 1);
parser->state = STATE_LOGICAL_MONITOR;
}
else if (g_str_equal (element_name, "migrated"))
{
parser->current_was_migrated = TRUE;
parser->state = STATE_MIGRATED;
}
else
{ {
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
"Invalid configuration element '%s'", element_name); "Invalid configuration element '%s'", element_name);
return; return;
} }
parser->current_logical_monitor_config = return;
g_new0 (MetaLogicalMonitorConfig, 1); }
parser->state = STATE_LOGICAL_MONITOR; case STATE_MIGRATED:
{
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
"Unexpected element '%s'", element_name);
return; return;
} }
@ -603,7 +643,9 @@ handle_end_element (GMarkupParseContext *context,
g_assert (g_str_equal (element_name, "logicalmonitor")); g_assert (g_str_equal (element_name, "logicalmonitor"));
if (logical_monitor_config->scale == 0) if (parser->current_was_migrated)
logical_monitor_config->scale = -1;
else if (logical_monitor_config->scale == 0)
logical_monitor_config->scale = 1; logical_monitor_config->scale = 1;
parser->current_logical_monitor_configs = parser->current_logical_monitor_configs =
@ -615,17 +657,29 @@ handle_end_element (GMarkupParseContext *context,
return; return;
} }
case STATE_MIGRATED:
{
g_assert (g_str_equal (element_name, "migrated"));
parser->state = STATE_CONFIGURATION;
return;
}
case STATE_CONFIGURATION: case STATE_CONFIGURATION:
{ {
MetaMonitorConfigStore *store = parser->config_store; MetaMonitorConfigStore *store = parser->config_store;
MetaMonitorsConfig *config; MetaMonitorsConfig *config;
GList *l; GList *l;
MetaLogicalMonitorLayoutMode layout_mode; MetaLogicalMonitorLayoutMode layout_mode;
MetaMonitorsConfigFlag config_flags = META_MONITORS_CONFIG_FLAG_NONE;
g_assert (g_str_equal (element_name, "configuration")); g_assert (g_str_equal (element_name, "configuration"));
layout_mode = if (parser->current_was_migrated)
meta_monitor_manager_get_default_layout_mode (store->monitor_manager); layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
else
layout_mode =
meta_monitor_manager_get_default_layout_mode (store->monitor_manager);
for (l = parser->current_logical_monitor_configs; l; l = l->next) for (l = parser->current_logical_monitor_configs; l; l = l->next)
{ {
@ -643,9 +697,13 @@ handle_end_element (GMarkupParseContext *context,
return; return;
} }
if (parser->current_was_migrated)
config_flags |= META_MONITORS_CONFIG_FLAG_MIGRATED;
config = config =
meta_monitors_config_new (parser->current_logical_monitor_configs, meta_monitors_config_new (parser->current_logical_monitor_configs,
layout_mode); layout_mode,
config_flags);
parser->current_logical_monitor_configs = NULL; parser->current_logical_monitor_configs = NULL;
@ -785,6 +843,7 @@ handle_text (GMarkupParseContext *context,
case STATE_INITIAL: case STATE_INITIAL:
case STATE_MONITORS: case STATE_MONITORS:
case STATE_CONFIGURATION: case STATE_CONFIGURATION:
case STATE_MIGRATED:
case STATE_LOGICAL_MONITOR: case STATE_LOGICAL_MONITOR:
case STATE_MONITOR: case STATE_MONITOR:
case STATE_MONITOR_SPEC: case STATE_MONITOR_SPEC:
@ -1094,6 +1153,7 @@ append_transform (GString *buffer,
static void static void
append_logical_monitor_xml (GString *buffer, append_logical_monitor_xml (GString *buffer,
MetaMonitorsConfig *config,
MetaLogicalMonitorConfig *logical_monitor_config) MetaLogicalMonitorConfig *logical_monitor_config)
{ {
char scale_str[G_ASCII_DTOSTR_BUF_SIZE]; char scale_str[G_ASCII_DTOSTR_BUF_SIZE];
@ -1105,8 +1165,9 @@ append_logical_monitor_xml (GString *buffer,
logical_monitor_config->layout.y); logical_monitor_config->layout.y);
g_ascii_dtostr (scale_str, G_ASCII_DTOSTR_BUF_SIZE, g_ascii_dtostr (scale_str, G_ASCII_DTOSTR_BUF_SIZE,
logical_monitor_config->scale); logical_monitor_config->scale);
g_string_append_printf (buffer, " <scale>%s</scale>\n", if ((config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED) == 0)
scale_str); g_string_append_printf (buffer, " <scale>%s</scale>\n",
scale_str);
if (logical_monitor_config->is_primary) if (logical_monitor_config->is_primary)
g_string_append (buffer, " <primary>yes</primary>\n"); g_string_append (buffer, " <primary>yes</primary>\n");
if (logical_monitor_config->is_presentation) if (logical_monitor_config->is_presentation)
@ -1134,11 +1195,14 @@ generate_config_xml (MetaMonitorConfigStore *config_store)
g_string_append (buffer, " <configuration>\n"); g_string_append (buffer, " <configuration>\n");
if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
g_string_append (buffer, " <migrated/>\n");
for (l = config->logical_monitor_configs; l; l = l->next) for (l = config->logical_monitor_configs; l; l = l->next)
{ {
MetaLogicalMonitorConfig *logical_monitor_config = l->data; MetaLogicalMonitorConfig *logical_monitor_config = l->data;
append_logical_monitor_xml (buffer, logical_monitor_config); append_logical_monitor_xml (buffer, config, logical_monitor_config);
} }
g_string_append (buffer, " </configuration>\n"); g_string_append (buffer, " </configuration>\n");
@ -1204,6 +1268,31 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
.buffer = buffer .buffer = buffer
}; };
/*
* Custom write file is only ever used by the test suite, and the test suite
* will want to have be able to read back the content immediately, so for
* custom write files, do the content replacement synchronously.
*/
if (config_store->custom_write_file)
{
GError *error = NULL;
if (!g_file_replace_contents (config_store->custom_write_file,
buffer->str, buffer->len,
NULL,
FALSE,
G_FILE_CREATE_REPLACE_DESTINATION,
NULL,
NULL,
&error))
{
g_warning ("Saving monitor configuration failed: %s\n",
error->message);
g_error_free (error);
}
return;
}
g_file_replace_contents_async (config_store->user_file, g_file_replace_contents_async (config_store->user_file,
buffer->str, buffer->len, buffer->str, buffer->len,
NULL, NULL,
@ -1213,6 +1302,18 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
saved_cb, data); saved_cb, data);
} }
static void
maybe_save_configs (MetaMonitorConfigStore *config_store)
{
/*
* If a custom file is used, it means we are run by the test suite. When this
* is done, avoid replacing the user configuration file with test data,
* except if a custom write file is set as well.
*/
if (!config_store->custom_read_file || config_store->custom_write_file)
meta_monitor_config_store_save (config_store);
}
void void
meta_monitor_config_store_add (MetaMonitorConfigStore *config_store, meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config) MetaMonitorsConfig *config)
@ -1220,21 +1321,33 @@ meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
g_hash_table_replace (config_store->configs, g_hash_table_replace (config_store->configs,
config->key, g_object_ref (config)); config->key, g_object_ref (config));
if (!config_store->custom_file) maybe_save_configs (config_store);
meta_monitor_config_store_save (config_store); }
void
meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config)
{
g_hash_table_remove (config_store->configs, config->key);
maybe_save_configs (config_store);
} }
gboolean gboolean
meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store, meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
const char *path, const char *read_path,
const char *write_path,
GError **error) GError **error)
{ {
g_clear_object (&config_store->custom_file); g_clear_object (&config_store->custom_read_file);
g_clear_object (&config_store->custom_write_file);
g_hash_table_remove_all (config_store->configs); g_hash_table_remove_all (config_store->configs);
config_store->custom_file = g_file_new_for_path (path); config_store->custom_read_file = g_file_new_for_path (read_path);
if (write_path)
config_store->custom_write_file = g_file_new_for_path (write_path);
return read_config_file (config_store, config_store->custom_file, error); return read_config_file (config_store, config_store->custom_read_file, error);
} }
int int
@ -1243,6 +1356,12 @@ meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store
return (int) g_hash_table_size (config_store->configs); return (int) g_hash_table_size (config_store->configs);
} }
MetaMonitorManager *
meta_monitor_config_store_get_monitor_manager (MetaMonitorConfigStore *config_store)
{
return config_store->monitor_manager;
}
MetaMonitorConfigStore * MetaMonitorConfigStore *
meta_monitor_config_store_new (MetaMonitorManager *monitor_manager) meta_monitor_config_store_new (MetaMonitorManager *monitor_manager)
{ {
@ -1259,7 +1378,7 @@ meta_monitor_config_store_constructed (GObject *object)
GError *error = NULL; GError *error = NULL;
user_file_path = g_build_filename (g_get_user_config_dir (), user_file_path = g_build_filename (g_get_user_config_dir (),
"monitors-experimental.xml", "monitors.xml",
NULL); NULL);
config_store->user_file = g_file_new_for_path (user_file_path); config_store->user_file = g_file_new_for_path (user_file_path);
@ -1267,9 +1386,23 @@ meta_monitor_config_store_constructed (GObject *object)
{ {
if (!read_config_file (config_store, config_store->user_file, &error)) if (!read_config_file (config_store, config_store->user_file, &error))
{ {
g_warning ("Failed to read monitors config file '%s': %s", if (error->domain == META_MONITOR_CONFIG_STORE_ERROR &&
user_file_path, error->message); error->code == META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION)
g_error_free (error); {
g_clear_error (&error);
if (!meta_migrate_old_user_monitors_config (config_store, &error))
{
g_warning ("Failed to migrate old monitors config file: %s",
error->message);
g_error_free (error);
}
}
else
{
g_warning ("Failed to read monitors config file '%s': %s",
user_file_path, error->message);
g_error_free (error);
}
} }
} }
@ -1284,7 +1417,8 @@ meta_monitor_config_store_dispose (GObject *object)
g_clear_pointer (&config_store->configs, g_hash_table_destroy); g_clear_pointer (&config_store->configs, g_hash_table_destroy);
g_clear_object (&config_store->user_file); g_clear_object (&config_store->user_file);
g_clear_object (&config_store->custom_file); g_clear_object (&config_store->custom_read_file);
g_clear_object (&config_store->custom_write_file);
G_OBJECT_CLASS (meta_monitor_config_store_parent_class)->dispose (object); G_OBJECT_CLASS (meta_monitor_config_store_parent_class)->dispose (object);
} }

View File

@ -38,10 +38,16 @@ MetaMonitorsConfig * meta_monitor_config_store_lookup (MetaMonitorConfigStore *c
void meta_monitor_config_store_add (MetaMonitorConfigStore *config_store, void meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config); MetaMonitorsConfig *config);
void meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config);
gboolean meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store, gboolean meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
const char *path, const char *read_path,
const char *write_path,
GError **error); GError **error);
int meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store); int meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store);
MetaMonitorManager * meta_monitor_config_store_get_monitor_manager (MetaMonitorConfigStore *config_store);
#endif /* META_MONITOR_CONFIG_STORE_H */ #endif /* META_MONITOR_CONFIG_STORE_H */

View File

@ -429,6 +429,9 @@ meta_monitor_manager_apply_monitors_config (MetaMonitorManager *manager,
MetaMonitorManagerClass *manager_class = MetaMonitorManagerClass *manager_class =
META_MONITOR_MANAGER_GET_CLASS (manager); META_MONITOR_MANAGER_GET_CLASS (manager);
g_assert (!config ||
!(config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED));
if (!manager_class->apply_monitors_config (manager, config, method, error)) if (!manager_class->apply_monitors_config (manager, config, method, error))
return FALSE; return FALSE;
@ -1874,7 +1877,8 @@ meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skelet
logical_monitor_config); logical_monitor_config);
} }
config = meta_monitors_config_new (logical_monitor_configs, layout_mode); config = meta_monitors_config_new (logical_monitor_configs, layout_mode,
META_MONITORS_CONFIG_FLAG_NONE);
if (!meta_verify_monitors_config (config, manager, &error)) if (!meta_verify_monitors_config (config, manager, &error))
{ {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,

View File

@ -42,6 +42,7 @@ set_custom_monitor_config (const char *filename)
path = g_test_get_filename (G_TEST_DIST, "tests", "monitor-configs", path = g_test_get_filename (G_TEST_DIST, "tests", "monitor-configs",
filename, NULL); filename, NULL);
if (!meta_monitor_config_store_set_custom (config_store, path, &error)) if (!meta_monitor_config_store_set_custom (config_store, path, NULL,
&error))
g_error ("Failed to set custom config: %s", error->message); g_error ("Failed to set custom config: %s", error->message);
} }