2016-12-13 02:37:11 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-19 07:15:54 +00:00
|
|
|
/**
|
|
|
|
* SECTION:meta-logical-monitor
|
|
|
|
* @title: MetaLogicalMonitor
|
|
|
|
* @short_description: An abstraction for a monitor(set) and its configuration.
|
|
|
|
*
|
|
|
|
* A logical monitor is a group of one or more physical monitors that
|
|
|
|
* must behave and be treated as single one. This happens, for example,
|
|
|
|
* when 2 monitors are mirrored. Each physical monitor is represented
|
|
|
|
* by a #MetaMonitor.
|
|
|
|
*
|
|
|
|
* #MetaLogicalMonitor has a single viewport, with its owns transformations
|
|
|
|
* (such as scaling), that are applied to all the #MetaMonitor<!-- -->s that
|
|
|
|
* are grouped by it.
|
|
|
|
*
|
|
|
|
* #MetaLogicalMonitor provides an abstraction that makes it easy to handle
|
|
|
|
* the specifics of setting up different #MetaMonitor<!-- -->s. It then can
|
|
|
|
* be used more easily by #MetaRendererView.
|
|
|
|
*/
|
|
|
|
|
2016-12-13 02:37:11 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/meta-logical-monitor.h"
|
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
2017-03-28 04:35:19 +00:00
|
|
|
#include "backends/meta-crtc.h"
|
2017-03-24 09:35:51 +00:00
|
|
|
#include "backends/meta-output.h"
|
|
|
|
|
2016-12-13 02:37:11 +00:00
|
|
|
G_DEFINE_TYPE (MetaLogicalMonitor, meta_logical_monitor, G_TYPE_OBJECT)
|
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-12-13 03:03:22 +00:00
|
|
|
MetaLogicalMonitor *
|
2017-03-07 04:34:38 +00:00
|
|
|
meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
|
|
|
|
MetaLogicalMonitorConfig *logical_monitor_config,
|
|
|
|
int monitor_number)
|
2016-12-13 03:03:22 +00:00
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
2017-03-07 04:34:38 +00:00
|
|
|
GList *monitor_configs;
|
|
|
|
MetaMonitor *first_monitor;
|
2016-12-13 03:03:22 +00:00
|
|
|
MetaOutput *main_output;
|
|
|
|
|
|
|
|
logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
|
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
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;
|
2020-02-25 15:13:52 +00:00
|
|
|
logical_monitor->winsys_id = meta_output_get_id (main_output);
|
2017-02-24 10:10:52 +00:00
|
|
|
logical_monitor->scale = logical_monitor_config->scale;
|
2017-03-21 06:17:18 +00:00
|
|
|
logical_monitor->transform = logical_monitor_config->transform;
|
2016-12-13 03:03:22 +00:00
|
|
|
logical_monitor->in_fullscreen = -1;
|
2017-03-07 04:34:38 +00:00
|
|
|
logical_monitor->rect = logical_monitor_config->layout;
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
logical_monitor->is_presentation = TRUE;
|
|
|
|
g_list_foreach (monitor_configs, (GFunc) add_monitor_from_config,
|
|
|
|
&(AddMonitorFromConfigData) {
|
|
|
|
.monitor_manager = monitor_manager,
|
|
|
|
.logical_monitor = logical_monitor
|
|
|
|
});
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
return logical_monitor;
|
|
|
|
}
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2017-03-17 08:33:18 +00:00
|
|
|
static MetaMonitorTransform
|
|
|
|
derive_monitor_transform (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *main_output;
|
2020-02-26 09:37:53 +00:00
|
|
|
MetaCrtc *crtc;
|
|
|
|
const MetaCrtcConfig *crtc_config;
|
2017-11-03 10:25:30 +00:00
|
|
|
MetaMonitorTransform transform;
|
2017-03-17 08:33:18 +00:00
|
|
|
|
|
|
|
main_output = meta_monitor_get_main_output (monitor);
|
2020-02-26 09:37:53 +00:00
|
|
|
crtc = meta_output_get_assigned_crtc (main_output);
|
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
|
|
|
transform = crtc_config->transform;
|
2017-03-17 08:33:18 +00:00
|
|
|
|
2017-11-03 10:25:30 +00:00
|
|
|
return meta_monitor_crtc_to_logical_transform (monitor, transform);
|
2017-03-17 08:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
MetaLogicalMonitor *
|
|
|
|
meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaRectangle *layout,
|
2017-05-25 08:12:51 +00:00
|
|
|
float scale,
|
2017-03-07 04:34:38 +00:00
|
|
|
int monitor_number)
|
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
MetaOutput *main_output;
|
2017-03-17 08:33:18 +00:00
|
|
|
MetaMonitorTransform transform;
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
|
2016-12-13 13:44:16 +00:00
|
|
|
|
2017-03-17 08:33:18 +00:00
|
|
|
transform = derive_monitor_transform (monitor);
|
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
main_output = meta_monitor_get_main_output (monitor);
|
|
|
|
logical_monitor->number = monitor_number;
|
2020-02-25 15:13:52 +00:00
|
|
|
logical_monitor->winsys_id = meta_output_get_id (main_output);
|
2017-01-20 07:07:12 +00:00
|
|
|
logical_monitor->scale = scale;
|
2017-03-17 08:33:18 +00:00
|
|
|
logical_monitor->transform = transform;
|
2017-03-07 04:34:38 +00:00
|
|
|
logical_monitor->in_fullscreen = -1;
|
|
|
|
logical_monitor->rect = *layout;
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2017-03-07 04:34:38 +00:00
|
|
|
logical_monitor->is_presentation = TRUE;
|
|
|
|
meta_logical_monitor_add_monitor (logical_monitor, monitor);
|
2016-12-13 03:03:22 +00:00
|
|
|
|
|
|
|
return logical_monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
|
|
|
|
MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
gboolean is_presentation;
|
|
|
|
|
|
|
|
is_presentation = logical_monitor->is_presentation;
|
|
|
|
logical_monitor->monitors = g_list_append (logical_monitor->monitors,
|
2017-11-03 10:27:57 +00:00
|
|
|
g_object_ref (monitor));
|
2016-12-13 03:03:22 +00:00
|
|
|
|
2016-12-13 13:44:16 +00:00
|
|
|
for (l = logical_monitor->monitors; l; l = l->next)
|
2016-12-13 03:03:22 +00:00
|
|
|
{
|
2016-12-13 13:44:16 +00:00
|
|
|
MetaMonitor *monitor = l->data;
|
|
|
|
GList *outputs;
|
|
|
|
GList *l_output;
|
|
|
|
|
|
|
|
outputs = meta_monitor_get_outputs (monitor);
|
|
|
|
for (l_output = outputs; l_output; l_output = l_output->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l_output->data;
|
|
|
|
|
2020-02-25 17:37:21 +00:00
|
|
|
is_presentation = (is_presentation &&
|
|
|
|
meta_output_is_presentation (output));
|
2016-12-13 13:44:16 +00:00
|
|
|
}
|
2016-12-13 03:03:22 +00:00
|
|
|
}
|
2016-12-13 13:44:16 +00:00
|
|
|
|
2016-12-13 03:03:22 +00:00
|
|
|
logical_monitor->is_presentation = is_presentation;
|
2020-01-16 09:10:42 +00:00
|
|
|
|
|
|
|
meta_monitor_set_logical_monitor (monitor, logical_monitor);
|
2016-12-13 03:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_logical_monitor_is_primary (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
return logical_monitor->is_primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
logical_monitor->is_primary = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-05-25 08:12:51 +00:00
|
|
|
float
|
2016-12-22 07:24:02 +00:00
|
|
|
meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
return logical_monitor->scale;
|
|
|
|
}
|
|
|
|
|
2017-08-11 07:02:43 +00:00
|
|
|
MetaMonitorTransform
|
|
|
|
meta_logical_monitor_get_transform (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
return logical_monitor->transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaRectangle
|
|
|
|
meta_logical_monitor_get_layout (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
return logical_monitor->rect;
|
|
|
|
}
|
|
|
|
|
2016-12-13 13:44:16 +00:00
|
|
|
GList *
|
|
|
|
meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
return logical_monitor->monitors;
|
|
|
|
}
|
|
|
|
|
2017-03-27 15:45:28 +00:00
|
|
|
typedef struct _ForeachCrtcData
|
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
MetaLogicalMonitorCrtcFunc func;
|
|
|
|
gpointer user_data;
|
|
|
|
} ForeachCrtcData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
foreach_crtc (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode,
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ForeachCrtcData *data = user_data;
|
|
|
|
|
|
|
|
data->func (data->logical_monitor,
|
2020-01-15 16:17:33 +00:00
|
|
|
monitor,
|
2019-04-04 16:43:09 +00:00
|
|
|
monitor_crtc_mode->output,
|
2017-11-03 10:25:30 +00:00
|
|
|
meta_output_get_assigned_crtc (monitor_crtc_mode->output),
|
2017-03-27 15:45:28 +00:00
|
|
|
data->user_data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_logical_monitor_foreach_crtc (MetaLogicalMonitor *logical_monitor,
|
|
|
|
MetaLogicalMonitorCrtcFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = logical_monitor->monitors; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = l->data;
|
|
|
|
MetaMonitorMode *mode;
|
|
|
|
ForeachCrtcData data = {
|
|
|
|
.logical_monitor = logical_monitor,
|
|
|
|
.func = func,
|
|
|
|
.user_data = user_data
|
|
|
|
};
|
|
|
|
|
|
|
|
mode = meta_monitor_get_current_mode (monitor);
|
|
|
|
meta_monitor_mode_foreach_crtc (monitor, mode, foreach_crtc, &data, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:37:11 +00:00
|
|
|
static void
|
|
|
|
meta_logical_monitor_init (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-20 04:53:58 +00:00
|
|
|
static void
|
2017-11-03 10:27:57 +00:00
|
|
|
meta_logical_monitor_dispose (GObject *object)
|
2017-10-20 04:53:58 +00:00
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor = META_LOGICAL_MONITOR (object);
|
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
if (logical_monitor->monitors)
|
|
|
|
{
|
|
|
|
g_list_free_full (logical_monitor->monitors, g_object_unref);
|
|
|
|
logical_monitor->monitors = NULL;
|
|
|
|
}
|
2017-10-20 04:53:58 +00:00
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
G_OBJECT_CLASS (meta_logical_monitor_parent_class)->dispose (object);
|
2017-10-20 04:53:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:37:11 +00:00
|
|
|
static void
|
|
|
|
meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass)
|
|
|
|
{
|
2017-10-20 04:53:58 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
object_class->dispose = meta_logical_monitor_dispose;
|
2016-12-13 02:37:11 +00:00
|
|
|
}
|
2017-03-24 14:46:32 +00:00
|
|
|
|
|
|
|
gboolean
|
2017-08-26 19:22:34 +00:00
|
|
|
meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
|
|
|
|
MetaLogicalMonitor *neighbor,
|
|
|
|
MetaDisplayDirection neighbor_direction)
|
2017-03-24 14:46:32 +00:00
|
|
|
{
|
|
|
|
switch (neighbor_direction)
|
|
|
|
{
|
2017-08-26 19:22:34 +00:00
|
|
|
case META_DISPLAY_RIGHT:
|
2017-03-24 14:46:32 +00:00
|
|
|
if (neighbor->rect.x == (logical_monitor->rect.x +
|
|
|
|
logical_monitor->rect.width) &&
|
|
|
|
meta_rectangle_vert_overlap (&neighbor->rect,
|
|
|
|
&logical_monitor->rect))
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2017-08-26 19:22:34 +00:00
|
|
|
case META_DISPLAY_LEFT:
|
2017-03-24 14:46:32 +00:00
|
|
|
if (logical_monitor->rect.x == (neighbor->rect.x +
|
|
|
|
neighbor->rect.width) &&
|
|
|
|
meta_rectangle_vert_overlap (&neighbor->rect,
|
|
|
|
&logical_monitor->rect))
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2017-08-26 19:22:34 +00:00
|
|
|
case META_DISPLAY_UP:
|
2017-03-24 14:46:32 +00:00
|
|
|
if (logical_monitor->rect.y == (neighbor->rect.y +
|
|
|
|
neighbor->rect.height) &&
|
|
|
|
meta_rectangle_horiz_overlap (&neighbor->rect,
|
|
|
|
&logical_monitor->rect))
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2017-08-26 19:22:34 +00:00
|
|
|
case META_DISPLAY_DOWN:
|
2017-03-24 14:46:32 +00:00
|
|
|
if (neighbor->rect.y == (logical_monitor->rect.y +
|
|
|
|
logical_monitor->rect.height) &&
|
|
|
|
meta_rectangle_horiz_overlap (&neighbor->rect,
|
|
|
|
&logical_monitor->rect))
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|