monitor-conifig-manager: Generate primary monitor config with others

Primary monitor is just the same of the other monitors, but it has a
primary monitor flag. Since the computation of the scaling isn't
dependent anymore on the computed configuration we can now generate the
primary monitor config together with the others.

However, we've to ensure that the primary monitor is the first of the
configs list in order to properly compute the positioning.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/522>
This commit is contained in:
Marco Trevisan (Treviño) 2019-04-03 16:25:10 +02:00 committed by Marge Bot
parent e8b84441a4
commit e59da5ad83

View File

@ -588,7 +588,8 @@ monitor_matches_rule (MetaMonitor *monitor,
static GList * static GList *
find_monitors (MetaMonitorManager *monitor_manager, find_monitors (MetaMonitorManager *monitor_manager,
MonitorMatchRule match_rule) MonitorMatchRule match_rule,
MetaMonitor *not_this_one)
{ {
GList *result = NULL; GList *result = NULL;
GList *monitors, *l; GList *monitors, *l;
@ -598,6 +599,9 @@ find_monitors (MetaMonitorManager *monitor_manager,
{ {
MetaMonitor *monitor = l->data; MetaMonitor *monitor = l->data;
if (not_this_one && monitor == not_this_one)
continue;
if (monitor_matches_rule (monitor, monitor_manager, match_rule)) if (monitor_matches_rule (monitor, monitor_manager, match_rule))
result = g_list_prepend (result, monitor); result = g_list_prepend (result, monitor);
} }
@ -614,7 +618,7 @@ find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_mana
int largest_area = 0; int largest_area = 0;
MetaMonitor *largest_monitor = NULL; MetaMonitor *largest_monitor = NULL;
monitors = find_monitors (monitor_manager, match_rule); monitors = find_monitors (monitor_manager, match_rule, NULL);
for (l = monitors; l; l = l->next) for (l = monitors; l; l = l->next)
{ {
MetaMonitor *monitor = l->data; MetaMonitor *monitor = l->data;
@ -850,8 +854,6 @@ create_monitors_config (MetaMonitorConfigManager *config_manager,
g_autolist (MetaLogicalMonitorConfig) logical_monitor_configs = NULL; g_autolist (MetaLogicalMonitorConfig) logical_monitor_configs = NULL;
MetaMonitor *primary_monitor; MetaMonitor *primary_monitor;
MetaLogicalMonitorLayoutMode layout_mode; MetaLogicalMonitorLayoutMode layout_mode;
MetaLogicalMonitorConfig *primary_logical_monitor_config;
gboolean has_suggested_position;
float scale; float scale;
GList *l; GList *l;
int x, y; int x, y;
@ -861,41 +863,22 @@ create_monitors_config (MetaMonitorConfigManager *config_manager,
if (!primary_monitor) if (!primary_monitor)
return NULL; return NULL;
x = y = 0;
layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager); layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
switch (positioning)
{
case MONITOR_POSITIONING_LINEAR:
x = y = 0;
break;
case MONITOR_POSITIONING_SUGGESTED:
has_suggested_position =
meta_monitor_get_suggested_position (primary_monitor, &x, &y);
g_assert (has_suggested_position);
break;
}
scale = compute_scale_for_monitor (monitor_manager, primary_monitor, NULL);
primary_logical_monitor_config =
create_preferred_logical_monitor_config (monitor_manager,
primary_monitor,
x, y, scale,
layout_mode);
primary_logical_monitor_config->is_primary = TRUE;
logical_monitor_configs = g_list_append (NULL,
primary_logical_monitor_config);
if (!(match_rule & MONITOR_MATCH_PRIMARY)) if (!(match_rule & MONITOR_MATCH_PRIMARY))
monitors = find_monitors (monitor_manager, match_rule); monitors = find_monitors (monitor_manager, match_rule, primary_monitor);
/* The primary monitor needs to be at the head of the list for the
* linear positioning to be correct.
*/
monitors = g_list_prepend (monitors, primary_monitor);
x = primary_logical_monitor_config->layout.width;
for (l = monitors; l; l = l->next) for (l = monitors; l; l = l->next)
{ {
MetaMonitor *monitor = l->data; MetaMonitor *monitor = l->data;
MetaLogicalMonitorConfig *logical_monitor_config; MetaLogicalMonitorConfig *logical_monitor_config;
gboolean has_suggested_position;
if (monitor == primary_monitor)
continue;
switch (positioning) switch (positioning)
{ {
@ -915,6 +898,7 @@ create_monitors_config (MetaMonitorConfigManager *config_manager,
monitor, monitor,
x, y, scale, x, y, scale,
layout_mode); layout_mode);
logical_monitor_config->is_primary = (monitor == primary_monitor);
logical_monitor_configs = g_list_append (logical_monitor_configs, logical_monitor_configs = g_list_append (logical_monitor_configs,
logical_monitor_config); logical_monitor_config);