1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/* -*- 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.
*/
#include "config.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-backend-private.h"
#include "backends/meta-crtc.h"
#include "backends/meta-output.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 (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 = logical_monitor_config->scale;
logical_monitor->transform = logical_monitor_config->transform;
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;
}
static MetaMonitorTransform
derive_monitor_transform (MetaMonitor *monitor)
{
MetaOutput *main_output;
MetaMonitorTransform transform;
main_output = meta_monitor_get_main_output (monitor);
transform = meta_output_get_assigned_crtc (main_output)->transform;
return meta_monitor_crtc_to_logical_transform (monitor, transform);
}
MetaLogicalMonitor *
meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
MetaRectangle *layout,
float scale,
int monitor_number)
{
MetaLogicalMonitor *logical_monitor;
MetaOutput *main_output;
MetaMonitorTransform transform;
logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
transform = derive_monitor_transform (monitor);
main_output = meta_monitor_get_main_output (monitor);
logical_monitor->number = monitor_number;
logical_monitor->winsys_id = main_output->winsys_id;
logical_monitor->scale = scale;
logical_monitor->transform = transform;
logical_monitor->in_fullscreen = -1;
logical_monitor->rect = *layout;
logical_monitor->is_presentation = TRUE;
meta_logical_monitor_add_monitor (logical_monitor, monitor);
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,
g_object_ref (monitor));
for (l = logical_monitor->monitors; l; l = l->next)
{
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;
MetaCrtc *crtc;
is_presentation = is_presentation && output->is_presentation;
crtc = meta_output_get_assigned_crtc (output);
if (crtc)
crtc->logical_monitor = logical_monitor;
}
}
logical_monitor->is_presentation = is_presentation;
}
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;
}
float
meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor)
{
return logical_monitor->scale;
}
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;
}
GList *
meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor)
{
return logical_monitor->monitors;
}
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,
meta_output_get_assigned_crtc (monitor_crtc_mode->output),
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);
}
}
static void
meta_logical_monitor_init (MetaLogicalMonitor *logical_monitor)
{
}
static void
meta_logical_monitor_dispose (GObject *object)
{
MetaLogicalMonitor *logical_monitor = META_LOGICAL_MONITOR (object);
if (logical_monitor->monitors)
{
g_list_free_full (logical_monitor->monitors, g_object_unref);
logical_monitor->monitors = NULL;
}
G_OBJECT_CLASS (meta_logical_monitor_parent_class)->dispose (object);
}
static void
meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = meta_logical_monitor_dispose;
}
gboolean
meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
MetaLogicalMonitor *neighbor,
MetaDisplayDirection neighbor_direction)
{
switch (neighbor_direction)
{
case META_DISPLAY_RIGHT:
if (neighbor->rect.x == (logical_monitor->rect.x +
logical_monitor->rect.width) &&
meta_rectangle_vert_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_DISPLAY_LEFT:
if (logical_monitor->rect.x == (neighbor->rect.x +
neighbor->rect.width) &&
meta_rectangle_vert_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_DISPLAY_UP:
if (logical_monitor->rect.y == (neighbor->rect.y +
neighbor->rect.height) &&
meta_rectangle_horiz_overlap (&neighbor->rect,
&logical_monitor->rect))
return TRUE;
break;
case META_DISPLAY_DOWN:
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;
}
|