monitor-manager: Split logical monitor creation

Split up logical monitor cration into derived (when derived from
current underlying configuration) and non-derived (when creating from a
logical monitor configuration). This avoids that type of logic in the
logical monitor creation function.

https://bugzilla.gnome.org/show_bug.cgi?id=779745
This commit is contained in:
Jonas Ådahl 2017-03-07 12:34:38 +08:00
parent df068a3649
commit 615587cd06
5 changed files with 154 additions and 113 deletions

View File

@ -21,54 +21,97 @@
#include "config.h"
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
G_DEFINE_TYPE (MetaLogicalMonitor, meta_logical_monitor, G_TYPE_OBJECT)
static MetaMonitor *
get_first_monitor (MetaMonitorManager *monitor_manager,
GList *monitor_configs)
{
MetaMonitorConfig *first_monitor_config;
MetaMonitorSpec *first_monitor_spec;
first_monitor_config = g_list_first (monitor_configs)->data;
first_monitor_spec = first_monitor_config->monitor_spec;
return meta_monitor_manager_get_monitor_from_spec (monitor_manager,
first_monitor_spec);
}
typedef struct
{
MetaMonitorManager *monitor_manager;
MetaLogicalMonitor *logical_monitor;
} AddMonitorFromConfigData;
static void
add_monitor_from_config (MetaMonitorConfig *monitor_config,
AddMonitorFromConfigData *data)
{
MetaMonitorSpec *monitor_spec;
MetaMonitor *monitor;
monitor_spec = monitor_config->monitor_spec;
monitor = meta_monitor_manager_get_monitor_from_spec (data->monitor_manager,
monitor_spec);
meta_logical_monitor_add_monitor (data->logical_monitor, monitor);
}
MetaLogicalMonitor *
meta_logical_monitor_new (MetaMonitor *monitor,
int x,
int y,
int number)
meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
MetaLogicalMonitorConfig *logical_monitor_config,
int monitor_number)
{
MetaLogicalMonitor *logical_monitor;
GList *monitor_configs;
MetaMonitor *first_monitor;
MetaOutput *main_output;
logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
monitor_configs = logical_monitor_config->monitor_configs;
first_monitor = get_first_monitor (monitor_manager, monitor_configs);
main_output = meta_monitor_get_main_output (first_monitor);
logical_monitor->number = monitor_number;
logical_monitor->winsys_id = main_output->winsys_id;
logical_monitor->scale = main_output->scale;
logical_monitor->in_fullscreen = -1;
logical_monitor->rect = logical_monitor_config->layout;
logical_monitor->is_presentation = TRUE;
g_list_foreach (monitor_configs, (GFunc) add_monitor_from_config,
&(AddMonitorFromConfigData) {
.monitor_manager = monitor_manager,
.logical_monitor = logical_monitor
});
return logical_monitor;
}
MetaLogicalMonitor *
meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
MetaRectangle *layout,
int monitor_number)
{
MetaLogicalMonitor *logical_monitor;
MetaOutput *main_output;
GList *outputs;
GList *l;
gboolean is_presentation;
g_assert (meta_monitor_is_active (monitor));
logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
main_output = meta_monitor_get_main_output (monitor);
logical_monitor->number = number;
logical_monitor->number = monitor_number;
logical_monitor->winsys_id = main_output->winsys_id;
logical_monitor->scale = main_output->scale;
logical_monitor->in_fullscreen = -1;
logical_monitor->rect = *layout;
logical_monitor->rect.x = x;
logical_monitor->rect.y = y;
meta_monitor_get_dimensions (monitor,
&logical_monitor->rect.width,
&logical_monitor->rect.height);
is_presentation = TRUE;
outputs = meta_monitor_get_outputs (monitor);
for (l = outputs; l; l = l->next)
{
MetaOutput *output = l->data;
if (output->crtc)
output->crtc->logical_monitor = logical_monitor;
is_presentation = is_presentation && output->is_presentation;
}
logical_monitor->is_presentation = is_presentation;
logical_monitor->monitors = g_list_append (logical_monitor->monitors,
monitor);
logical_monitor->is_presentation = TRUE;
meta_logical_monitor_add_monitor (logical_monitor, monitor);
return logical_monitor;
}

View File

@ -25,6 +25,7 @@
#include <glib-object.h>
#include "backends/meta-monitor.h"
#include "backends/meta-monitor-config-manager.h"
#include "backends/meta-monitor-manager-private.h"
#include "meta/boxes.h"
@ -59,10 +60,14 @@ G_DECLARE_FINAL_TYPE (MetaLogicalMonitor, meta_logical_monitor,
META, LOGICAL_MONITOR,
GObject)
MetaLogicalMonitor * meta_logical_monitor_new (MetaMonitor *monitor,
int x,
int y,
int number);
MetaLogicalMonitor * meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
MetaLogicalMonitorConfig *logical_monitor_config,
int monitor_number);
MetaLogicalMonitor * meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
MetaRectangle *layout,
int monitor_number);
void meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
MetaMonitor *monitor);

View File

@ -108,47 +108,6 @@ logical_monitor_from_layout (MetaMonitorManager *manager,
return NULL;
}
static MetaLogicalMonitor *
create_logical_monitor_from_config (MetaMonitorManager *manager,
MetaLogicalMonitorConfig *logical_monitor_config,
int monitor_number)
{
MetaLogicalMonitor *logical_monitor;
GList *monitor_configs;
MetaMonitorConfig *first_monitor_config;
MetaMonitorSpec *first_monitor_spec;
MetaMonitor *first_monitor;
GList *l;
monitor_configs = logical_monitor_config->monitor_configs;
first_monitor_config = g_list_first (monitor_configs)->data;
first_monitor_spec = first_monitor_config->monitor_spec;
first_monitor =
meta_monitor_manager_get_monitor_from_spec (manager, first_monitor_spec);
/* Create logical monitor from the first monitor. */
logical_monitor = meta_logical_monitor_new (first_monitor,
logical_monitor_config->layout.x,
logical_monitor_config->layout.y,
monitor_number);
/* Add the other monitors. */
for (l = monitor_configs->next; l; l = l->next)
{
MetaMonitorConfig *monitor_config = l->data;
MetaMonitorSpec *monitor_spec;
MetaMonitor *monitor;
monitor_spec = monitor_config->monitor_spec;
monitor = meta_monitor_manager_get_monitor_from_spec (manager,
monitor_spec);
meta_logical_monitor_add_monitor (logical_monitor, monitor);
}
return logical_monitor;
}
static void
meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager,
MetaMonitorsConfig *config)
@ -165,10 +124,9 @@ meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager,
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
MetaLogicalMonitor *logical_monitor;
logical_monitor =
create_logical_monitor_from_config (manager,
logical_monitor_config,
monitor_number);
logical_monitor = meta_logical_monitor_new (manager,
logical_monitor_config,
monitor_number);
monitor_number++;
if (logical_monitor_config->is_primary)
@ -190,16 +148,16 @@ meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager,
}
static void
derive_monitor_position (MetaMonitor *monitor,
int *x,
int *y)
derive_monitor_layout (MetaMonitor *monitor,
MetaRectangle *layout)
{
MetaOutput *main_output;
main_output = meta_monitor_get_main_output (monitor);
layout->x = main_output->crtc->rect.x;
layout->y = main_output->crtc->rect.y;
*x = main_output->crtc->rect.x;
*y = main_output->crtc->rect.y;
meta_monitor_derive_dimensions (monitor, &layout->width, &layout->height);
}
static void
@ -221,8 +179,7 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manag
if (!meta_monitor_is_active (monitor))
continue;
derive_monitor_position (monitor, &layout.x, &layout.y);
meta_monitor_get_dimensions (monitor, &layout.width, &layout.height);
derive_monitor_layout (monitor, &layout);
logical_monitor = logical_monitor_from_layout (manager, logical_monitors,
&layout);
if (logical_monitor)
@ -231,12 +188,10 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manag
}
else
{
int x, y;
derive_monitor_position (monitor, &x, &y);
logical_monitor = meta_logical_monitor_new (monitor,
x, y,
monitor_number);
logical_monitor = meta_logical_monitor_new_derived (manager,
monitor,
&layout,
monitor_number);
logical_monitors = g_list_append (logical_monitors, logical_monitor);
monitor_number++;
}

View File

@ -215,11 +215,22 @@ meta_monitor_is_laptop_panel (MetaMonitor *monitor)
}
void
meta_monitor_get_dimensions (MetaMonitor *monitor,
int *width,
int *height)
meta_monitor_get_current_resolution (MetaMonitor *monitor,
int *width,
int *height)
{
META_MONITOR_GET_CLASS (monitor)->get_dimensions (monitor, width, height);
MetaMonitorMode *mode = meta_monitor_get_current_mode (monitor);
*width = mode->spec.width;
*height = mode->spec.height;
}
void
meta_monitor_derive_dimensions (MetaMonitor *monitor,
int *width,
int *height)
{
META_MONITOR_GET_CLASS (monitor)->derive_dimensions (monitor, width, height);
}
void
@ -362,9 +373,9 @@ meta_monitor_normal_get_main_output (MetaMonitor *monitor)
}
static void
meta_monitor_normal_get_dimensions (MetaMonitor *monitor,
int *width,
int *height)
meta_monitor_normal_derive_dimensions (MetaMonitor *monitor,
int *width,
int *height)
{
MetaOutput *output;
@ -384,7 +395,7 @@ meta_monitor_normal_class_init (MetaMonitorNormalClass *klass)
MetaMonitorClass *monitor_class = META_MONITOR_CLASS (klass);
monitor_class->get_main_output = meta_monitor_normal_get_main_output;
monitor_class->get_dimensions = meta_monitor_normal_get_dimensions;
monitor_class->derive_dimensions = meta_monitor_normal_derive_dimensions;
}
uint32_t
@ -684,11 +695,34 @@ meta_monitor_tiled_get_main_output (MetaMonitor *monitor)
}
static void
meta_monitor_tiled_get_dimensions (MetaMonitor *monitor,
int *width,
int *height)
meta_monitor_tiled_derive_dimensions (MetaMonitor *monitor,
int *out_width,
int *out_height)
{
meta_monitor_tiled_calculate_tiled_size (monitor, width, height);
MetaMonitorPrivate *monitor_priv =
meta_monitor_get_instance_private (monitor);
GList *l;
int width;
int height;
width = 0;
height = 0;
for (l = monitor_priv->outputs; l; l = l->next)
{
MetaOutput *output = l->data;
if (!output->crtc)
continue;
if (output->tile_info.loc_v_tile == 0)
width += output->crtc->rect.width;
if (output->tile_info.loc_h_tile == 0)
height += output->crtc->rect.height;
}
*out_width = width;
*out_height = height;
}
static void
@ -717,7 +751,7 @@ meta_monitor_tiled_class_init (MetaMonitorTiledClass *klass)
object_class->finalize = meta_monitor_tiled_finalize;
monitor_class->get_main_output = meta_monitor_tiled_get_main_output;
monitor_class->get_dimensions = meta_monitor_tiled_get_dimensions;
monitor_class->derive_dimensions = meta_monitor_tiled_derive_dimensions;
}
static void

View File

@ -65,9 +65,9 @@ struct _MetaMonitorClass
GObjectClass parent_class;
MetaOutput * (* get_main_output) (MetaMonitor *monitor);
void (* get_dimensions) (MetaMonitor *monitor,
int *width,
int *height);
void (* derive_dimensions) (MetaMonitor *monitor,
int *width,
int *height);
};
#define META_TYPE_MONITOR_NORMAL (meta_monitor_normal_get_type ())
@ -99,9 +99,13 @@ gboolean meta_monitor_is_laptop_panel (MetaMonitor *monitor);
GList * meta_monitor_get_outputs (MetaMonitor *monitor);
void meta_monitor_get_dimensions (MetaMonitor *monitor,
int *width,
int *height);
void meta_monitor_get_current_resolution (MetaMonitor *monitor,
int *width,
int *height);
void meta_monitor_derive_dimensions (MetaMonitor *monitor,
int *width,
int *height);
void meta_monitor_get_physical_dimensions (MetaMonitor *monitor,
int *width_mm,