1
0
Fork 0

monitor-config-store: Store and load layout mode for each configuration

Store and load the layout mode for each logical monitor configuration in
monitors.xml by introducing a new <layoutmode> element. The value of the
element can be either "logical" or "physical". The layout mode is also
made part of the monitor configuration key.

Right now this isn't doing a lot:

When no <layoutmode> is found on the config (this is the case with all
existing configs), we'll keep using the layout mode expected by the system,
without updating the config file.

When changing an existing, or introducing a new configuration, we'll now
store the current layout mode with the config though, and load it again
on the next start of mutter. This is still not problematic as long as
mutters expected layout mode doesn't change (eg. by turning on/off
"scale-monitor-framebuffers").

When the expected layout mode of mutter switches between
restarts, the monitor config is now still loaded but remains unused,
and mutter will create (and store) a new one with the other layout mode.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3596>
This commit is contained in:
Jonas Dreßler 2024-02-16 20:32:55 +01:00 committed by Marge Bot
parent de56634fd0
commit 076b3664a3
39 changed files with 128 additions and 10 deletions

View file

@ -493,7 +493,8 @@ meta_create_monitors_config_key_for_current_state (MetaMonitorManager *monitor_m
config_key = g_new0 (MetaMonitorsConfigKey, 1);
*config_key = (MetaMonitorsConfigKey) {
.monitor_specs = monitor_specs
.monitor_specs = monitor_specs,
.layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager),
};
return config_key;
@ -1521,8 +1522,9 @@ meta_logical_monitor_config_free (MetaLogicalMonitorConfig *logical_monitor_conf
}
static MetaMonitorsConfigKey *
meta_monitors_config_key_new (GList *logical_monitor_configs,
GList *disabled_monitor_specs)
meta_monitors_config_key_new (GList *logical_monitor_configs,
GList *disabled_monitor_specs,
MetaLogicalMonitorLayoutMode layout_mode)
{
MetaMonitorsConfigKey *config_key;
GList *monitor_specs;
@ -1557,7 +1559,8 @@ meta_monitors_config_key_new (GList *logical_monitor_configs,
config_key = g_new0 (MetaMonitorsConfigKey, 1);
*config_key = (MetaMonitorsConfigKey) {
.monitor_specs = monitor_specs
.monitor_specs = monitor_specs,
.layout_mode = layout_mode
};
return config_key;
@ -1578,7 +1581,7 @@ meta_monitors_config_key_hash (gconstpointer data)
GList *l;
unsigned long hash;
hash = 0;
hash = config_key->layout_mode;
for (l = config_key->monitor_specs; l; l = l->next)
{
MetaMonitorSpec *monitor_spec = l->data;
@ -1600,6 +1603,9 @@ meta_monitors_config_key_equal (gconstpointer data_a,
const MetaMonitorsConfigKey *config_key_b = data_b;
GList *l_a, *l_b;
if (config_key_a->layout_mode != config_key_b->layout_mode)
return FALSE;
for (l_a = config_key_a->monitor_specs, l_b = config_key_b->monitor_specs;
l_a && l_b;
l_a = l_a->next, l_b = l_b->next)
@ -1651,9 +1657,11 @@ meta_monitors_config_new_full (GList *logical_monitor_con
config = g_object_new (META_TYPE_MONITORS_CONFIG, NULL);
config->logical_monitor_configs = logical_monitor_configs;
config->disabled_monitor_specs = disabled_monitor_specs;
config->key = meta_monitors_config_key_new (logical_monitor_configs,
disabled_monitor_specs);
config->layout_mode = layout_mode;
config->key = meta_monitors_config_key_new (logical_monitor_configs,
disabled_monitor_specs,
layout_mode);
config->flags = flags;
config->switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;

View file

@ -49,6 +49,7 @@ typedef struct _MetaLogicalMonitorConfig
typedef struct _MetaMonitorsConfigKey
{
GList *monitor_specs;
MetaLogicalMonitorLayoutMode layout_mode;
} MetaMonitorsConfigKey;
enum _MetaMonitorsConfigFlag

View file

@ -131,6 +131,7 @@ typedef enum
STATE_UNKNOWN,
STATE_MONITORS,
STATE_CONFIGURATION,
STATE_LAYOUT_MODE,
STATE_LOGICAL_MONITOR,
STATE_LOGICAL_MONITOR_X,
STATE_LOGICAL_MONITOR_Y,
@ -172,6 +173,8 @@ typedef struct
ParserState monitor_spec_parent_state;
gboolean is_current_layout_mode_valid;
MetaLogicalMonitorLayoutMode current_layout_mode;
GList *current_logical_monitor_configs;
MetaMonitorSpec *current_monitor_spec;
gboolean current_transform_flipped;
@ -279,6 +282,7 @@ handle_start_element (GMarkupParseContext *context,
if (g_str_equal (element_name, "configuration"))
{
parser->state = STATE_CONFIGURATION;
parser->is_current_layout_mode_valid = FALSE;
}
else if (g_str_equal (element_name, "policy"))
{
@ -319,6 +323,10 @@ handle_start_element (GMarkupParseContext *context,
parser->state = STATE_LOGICAL_MONITOR;
}
else if (g_str_equal (element_name, "layoutmode"))
{
parser->state = STATE_LAYOUT_MODE;
}
else if (g_str_equal (element_name, "disabled"))
{
parser->state = STATE_DISABLED;
@ -332,6 +340,13 @@ handle_start_element (GMarkupParseContext *context,
return;
}
case STATE_LAYOUT_MODE:
{
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
"Unexpected element '%s'", element_name);
return;
}
case STATE_LOGICAL_MONITOR:
{
if (g_str_equal (element_name, "x"))
@ -884,6 +899,12 @@ handle_end_element (GMarkupParseContext *context,
return;
}
case STATE_LAYOUT_MODE:
{
parser->state = STATE_CONFIGURATION;
return;
}
case STATE_DISABLED:
{
g_assert (g_str_equal (element_name, "disabled"));
@ -897,12 +918,13 @@ handle_end_element (GMarkupParseContext *context,
MetaMonitorConfigStore *store = parser->config_store;
MetaMonitorsConfig *config;
GList *l;
MetaLogicalMonitorLayoutMode layout_mode;
MetaLogicalMonitorLayoutMode layout_mode = parser->current_layout_mode;
MetaMonitorsConfigFlag config_flags = META_MONITORS_CONFIG_FLAG_NONE;
g_assert (g_str_equal (element_name, "configuration"));
layout_mode = meta_monitor_manager_get_default_layout_mode (store->monitor_manager);
if (!parser->is_current_layout_mode_valid)
layout_mode = meta_monitor_manager_get_default_layout_mode (store->monitor_manager);
for (l = parser->current_logical_monitor_configs; l; l = l->next)
{
@ -1174,6 +1196,27 @@ handle_text (GMarkupParseContext *context,
return;
}
case STATE_LAYOUT_MODE:
{
if (text_equals (text, text_len, "logical"))
{
parser->current_layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
parser->is_current_layout_mode_valid = TRUE;
}
else if (text_equals (text, text_len, "physical"))
{
parser->current_layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
parser->is_current_layout_mode_valid = TRUE;
}
else
{
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
"Invalid layout mode %.*s", (int)text_len, text);
}
return;
}
case STATE_MONITOR_SPEC_CONNECTOR:
{
parser->current_monitor_spec->connector = g_strndup (text, text_len);
@ -1688,6 +1731,16 @@ generate_config_xml (MetaMonitorConfigStore *config_store)
g_string_append (buffer, " <configuration>\n");
switch (config->layout_mode)
{
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
g_string_append (buffer, " <layout_mode>logical</layout_mode>\n");
break;
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
g_string_append (buffer, " <layout_mode>physical</layout_mode>\n");
break;
}
for (l = config->logical_monitor_configs; l; l = l->next)
{
MetaLogicalMonitorConfig *logical_monitor_config = l->data;

View file

@ -11,6 +11,7 @@
+-----+-----+ +-----+-----+
-->
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>
@ -41,6 +42,7 @@
</logicalmonitor>
</configuration>
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>
@ -65,6 +67,7 @@
</logicalmonitor>
</configuration>
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>
@ -21,6 +22,7 @@
</configuration>
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>100</y>

View file

@ -5,6 +5,7 @@
</stores>
</policy>
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>256</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>256</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -5,6 +5,7 @@
</stores>
</policy>
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -3,6 +3,7 @@
<anotherlevel>text</anotherlevel>
</unknownundermonitors>
<configuration>
<layoutmode>logical</layoutmode>
<unknownunderconfiguration>
<anotherlevel>text</anotherlevel>
</unknownunderconfiguration>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -1,5 +1,6 @@
<monitors version="2">
<configuration>
<layoutmode>logical</layoutmode>
<logicalmonitor>
<x>0</x>
<y>0</y>

View file

@ -66,6 +66,7 @@ typedef struct _MonitorStoreTestCaseLogicalMonitor
typedef struct _MonitorStoreTestConfiguration
{
MetaLogicalMonitorLayoutMode layout_mode;
MonitorStoreTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS];
int n_logical_monitors;
} MonitorStoreTestConfiguration;
@ -112,7 +113,8 @@ create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config)
config_key = g_new0 (MetaMonitorsConfigKey, 1);
*config_key = (MetaMonitorsConfigKey) {
.monitor_specs = monitor_specs
.monitor_specs = monitor_specs,
.layout_mode = expect_config->layout_mode,
};
return config_key;
@ -240,6 +242,7 @@ meta_test_monitor_store_single (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -285,6 +288,7 @@ meta_test_monitor_store_vertical (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -356,6 +360,7 @@ meta_test_monitor_store_primary (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -427,6 +432,7 @@ meta_test_monitor_store_underscanning (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -473,6 +479,7 @@ meta_test_monitor_store_refresh_rate_mode_fixed (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -519,6 +526,7 @@ meta_test_monitor_store_refresh_rate_mode_variable (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -565,6 +573,7 @@ meta_test_monitor_store_max_bpc (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -611,6 +620,7 @@ meta_test_monitor_store_rgb_range (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -656,6 +666,7 @@ meta_test_monitor_store_scale (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -701,6 +712,7 @@ meta_test_monitor_store_fractional_scale (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -746,6 +758,7 @@ meta_test_monitor_store_high_precision_fractional_scale (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -791,6 +804,7 @@ meta_test_monitor_store_mirrored (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -847,6 +861,7 @@ meta_test_monitor_store_first_rotated (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -920,6 +935,7 @@ meta_test_monitor_store_second_rotated (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -993,6 +1009,7 @@ meta_test_monitor_store_interlaced (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {
@ -1039,6 +1056,7 @@ meta_test_monitor_store_unknown_elements (void)
MonitorStoreTestExpect expect = {
.configurations = {
{
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
.logical_monitors = {
{
.layout = {