monitor-config-store: Read system wide config files
Before introducing the new config store, the old monitor configuration system read system wide monitor configuration files. Add back that feature. https://gitlab.gnome.org/GNOME/mutter/merge_requests/253
This commit is contained in:
parent
c010a3b195
commit
9e75ce2ad7
@ -55,6 +55,7 @@ typedef enum _MetaMonitorsConfigFlag
|
|||||||
{
|
{
|
||||||
META_MONITORS_CONFIG_FLAG_NONE = 0,
|
META_MONITORS_CONFIG_FLAG_NONE = 0,
|
||||||
META_MONITORS_CONFIG_FLAG_MIGRATED = (1 << 0),
|
META_MONITORS_CONFIG_FLAG_MIGRATED = (1 << 0),
|
||||||
|
META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG = (1 << 1),
|
||||||
} MetaMonitorsConfigFlag;
|
} MetaMonitorsConfigFlag;
|
||||||
|
|
||||||
struct _MetaMonitorsConfig
|
struct _MetaMonitorsConfig
|
||||||
|
@ -179,6 +179,8 @@ typedef struct
|
|||||||
MetaMonitorConfig *current_monitor_config;
|
MetaMonitorConfig *current_monitor_config;
|
||||||
MetaLogicalMonitorConfig *current_logical_monitor_config;
|
MetaLogicalMonitorConfig *current_logical_monitor_config;
|
||||||
GList *current_disabled_monitor_specs;
|
GList *current_disabled_monitor_specs;
|
||||||
|
|
||||||
|
MetaMonitorsConfigFlag extra_config_flags;
|
||||||
} ConfigParser;
|
} ConfigParser;
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
|
G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
|
||||||
@ -766,6 +768,8 @@ handle_end_element (GMarkupParseContext *context,
|
|||||||
if (parser->current_was_migrated)
|
if (parser->current_was_migrated)
|
||||||
config_flags |= META_MONITORS_CONFIG_FLAG_MIGRATED;
|
config_flags |= META_MONITORS_CONFIG_FLAG_MIGRATED;
|
||||||
|
|
||||||
|
config_flags |= parser->extra_config_flags;
|
||||||
|
|
||||||
config =
|
config =
|
||||||
meta_monitors_config_new_full (parser->current_logical_monitor_configs,
|
meta_monitors_config_new_full (parser->current_logical_monitor_configs,
|
||||||
parser->current_disabled_monitor_specs,
|
parser->current_disabled_monitor_specs,
|
||||||
@ -1078,9 +1082,10 @@ static const GMarkupParser config_parser = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
read_config_file (MetaMonitorConfigStore *config_store,
|
read_config_file (MetaMonitorConfigStore *config_store,
|
||||||
GFile *file,
|
GFile *file,
|
||||||
GError **error)
|
MetaMonitorsConfigFlag extra_config_flags,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
gsize size;
|
gsize size;
|
||||||
@ -1092,7 +1097,8 @@ read_config_file (MetaMonitorConfigStore *config_store,
|
|||||||
|
|
||||||
parser = (ConfigParser) {
|
parser = (ConfigParser) {
|
||||||
.state = STATE_INITIAL,
|
.state = STATE_INITIAL,
|
||||||
.config_store = config_store
|
.config_store = config_store,
|
||||||
|
.extra_config_flags = extra_config_flags,
|
||||||
};
|
};
|
||||||
|
|
||||||
parse_context = g_markup_parse_context_new (&config_parser,
|
parse_context = g_markup_parse_context_new (&config_parser,
|
||||||
@ -1274,6 +1280,9 @@ generate_config_xml (MetaMonitorConfigStore *config_store)
|
|||||||
{
|
{
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
|
if (config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG)
|
||||||
|
continue;
|
||||||
|
|
||||||
g_string_append (buffer, " <configuration>\n");
|
g_string_append (buffer, " <configuration>\n");
|
||||||
|
|
||||||
if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
|
if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
|
||||||
@ -1425,6 +1434,12 @@ maybe_save_configs (MetaMonitorConfigStore *config_store)
|
|||||||
meta_monitor_config_store_save (config_store);
|
meta_monitor_config_store_save (config_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
is_system_config (MetaMonitorsConfig *config)
|
||||||
|
{
|
||||||
|
return !!(config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
|
meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
|
||||||
MetaMonitorsConfig *config)
|
MetaMonitorsConfig *config)
|
||||||
@ -1432,7 +1447,8 @@ 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));
|
||||||
|
|
||||||
maybe_save_configs (config_store);
|
if (!is_system_config (config))
|
||||||
|
maybe_save_configs (config_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1441,7 +1457,8 @@ meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
|
|||||||
{
|
{
|
||||||
g_hash_table_remove (config_store->configs, config->key);
|
g_hash_table_remove (config_store->configs, config->key);
|
||||||
|
|
||||||
maybe_save_configs (config_store);
|
if (!is_system_config (config))
|
||||||
|
maybe_save_configs (config_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -1458,7 +1475,10 @@ meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
|
|||||||
if (write_path)
|
if (write_path)
|
||||||
config_store->custom_write_file = g_file_new_for_path (write_path);
|
config_store->custom_write_file = g_file_new_for_path (write_path);
|
||||||
|
|
||||||
return read_config_file (config_store, config_store->custom_read_file, error);
|
return read_config_file (config_store,
|
||||||
|
config_store->custom_read_file,
|
||||||
|
META_MONITORS_CONFIG_FLAG_NONE,
|
||||||
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1485,9 +1505,42 @@ static void
|
|||||||
meta_monitor_config_store_constructed (GObject *object)
|
meta_monitor_config_store_constructed (GObject *object)
|
||||||
{
|
{
|
||||||
MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
|
MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
|
||||||
|
const char * const *system_dirs;
|
||||||
char *user_file_path;
|
char *user_file_path;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
for (system_dirs = g_get_system_config_dirs ();
|
||||||
|
system_dirs && *system_dirs;
|
||||||
|
system_dirs++)
|
||||||
|
{
|
||||||
|
g_autofree char *system_file_path = NULL;
|
||||||
|
|
||||||
|
system_file_path = g_build_filename (*system_dirs, "monitors.xml", NULL);
|
||||||
|
if (g_file_test (system_file_path, G_FILE_TEST_EXISTS))
|
||||||
|
{
|
||||||
|
g_autoptr (GFile) system_file = NULL;
|
||||||
|
|
||||||
|
system_file = g_file_new_for_path (system_file_path);
|
||||||
|
if (!read_config_file (config_store,
|
||||||
|
system_file,
|
||||||
|
META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG,
|
||||||
|
&error))
|
||||||
|
{
|
||||||
|
if (g_error_matches (error,
|
||||||
|
META_MONITOR_CONFIG_STORE_ERROR,
|
||||||
|
META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION))
|
||||||
|
g_warning ("System monitor configuration file (%s) is "
|
||||||
|
"incompatible; ask your administrator to migrate "
|
||||||
|
"the system monitor configuation.",
|
||||||
|
system_file_path);
|
||||||
|
else
|
||||||
|
g_warning ("Failed to read monitors config file '%s': %s",
|
||||||
|
system_file_path, error->message);
|
||||||
|
g_clear_error (&error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user_file_path = g_build_filename (g_get_user_config_dir (),
|
user_file_path = g_build_filename (g_get_user_config_dir (),
|
||||||
"monitors.xml",
|
"monitors.xml",
|
||||||
NULL);
|
NULL);
|
||||||
@ -1495,7 +1548,10 @@ meta_monitor_config_store_constructed (GObject *object)
|
|||||||
|
|
||||||
if (g_file_test (user_file_path, G_FILE_TEST_EXISTS))
|
if (g_file_test (user_file_path, G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
if (!read_config_file (config_store, config_store->user_file, &error))
|
if (!read_config_file (config_store,
|
||||||
|
config_store->user_file,
|
||||||
|
META_MONITORS_CONFIG_FLAG_NONE,
|
||||||
|
&error))
|
||||||
{
|
{
|
||||||
if (error->domain == META_MONITOR_CONFIG_STORE_ERROR &&
|
if (error->domain == META_MONITOR_CONFIG_STORE_ERROR &&
|
||||||
error->code == META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION)
|
error->code == META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION)
|
||||||
|
Loading…
Reference in New Issue
Block a user