mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 11:32:04 +00:00
Move more logical monitor getters from the screen to the monitor manager
Turning a rectangle into a logical monitor also has nothing to do with the screen (MetaScreen) so move it to MetaMonitorManager which has that information. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
parent
f5b2d79f3b
commit
af616c96d4
@ -377,6 +377,9 @@ MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_at (MetaMonitorMana
|
||||
int x,
|
||||
int y);
|
||||
|
||||
MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
|
||||
MetaRectangle *rect);
|
||||
|
||||
MetaOutput *meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
|
||||
unsigned int *n_outputs);
|
||||
|
||||
|
@ -1345,6 +1345,47 @@ meta_monitor_manager_get_logical_monitor_at (MetaMonitorManager *manager,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
|
||||
MetaRectangle *rect)
|
||||
{
|
||||
MetaLogicalMonitor *best_logical_monitor;
|
||||
int best_logical_monitor_area;
|
||||
unsigned int i;
|
||||
|
||||
best_logical_monitor = NULL;
|
||||
best_logical_monitor_area = 0;
|
||||
|
||||
for (i = 0; i < manager->n_logical_monitors; i++)
|
||||
{
|
||||
MetaLogicalMonitor *logical_monitor = &manager->logical_monitors[i];
|
||||
MetaRectangle intersection;
|
||||
int intersection_area;
|
||||
|
||||
if (!meta_rectangle_intersect (&logical_monitor->rect,
|
||||
rect,
|
||||
&intersection))
|
||||
continue;
|
||||
|
||||
intersection_area = meta_rectangle_area (&intersection);
|
||||
|
||||
if (intersection_area > best_logical_monitor_area)
|
||||
{
|
||||
best_logical_monitor = logical_monitor;
|
||||
best_logical_monitor_area = intersection_area;
|
||||
}
|
||||
}
|
||||
|
||||
if (!best_logical_monitor && (rect->width == 0 || rect->height == 0))
|
||||
best_logical_monitor =
|
||||
meta_monitor_manager_get_logical_monitor_at (manager, rect->x, rect->y);
|
||||
|
||||
if (!best_logical_monitor)
|
||||
best_logical_monitor = manager->primary_logical_monitor;
|
||||
|
||||
return best_logical_monitor;
|
||||
}
|
||||
|
||||
MetaOutput *
|
||||
meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
|
||||
unsigned int *n_outputs)
|
||||
|
@ -330,7 +330,10 @@ setup_constraint_info (ConstraintInfo *info,
|
||||
const MetaRectangle *orig,
|
||||
MetaRectangle *new)
|
||||
{
|
||||
const MetaLogicalMonitor *logical_monitor;
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
MetaWorkspace *cur_workspace;
|
||||
|
||||
info->orig = *orig;
|
||||
@ -379,10 +382,11 @@ setup_constraint_info (ConstraintInfo *info,
|
||||
info->fixed_directions = FIXED_DIRECTION_NONE;
|
||||
|
||||
logical_monitor =
|
||||
meta_screen_get_logical_monitor_for_rect (window->screen, &info->current);
|
||||
meta_window_get_work_area_for_monitor (window,
|
||||
logical_monitor->number,
|
||||
&info->work_area_monitor);
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager,
|
||||
&info->current);
|
||||
meta_window_get_work_area_for_logical_monitor (window,
|
||||
logical_monitor,
|
||||
&info->work_area_monitor);
|
||||
|
||||
if (!window->fullscreen || !meta_window_has_fullscreen_monitors (window))
|
||||
{
|
||||
@ -459,10 +463,13 @@ place_window_if_needed(MetaWindow *window,
|
||||
!window->minimized &&
|
||||
!window->fullscreen)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaRectangle orig_rect;
|
||||
MetaRectangle placed_rect;
|
||||
MetaWorkspace *cur_workspace;
|
||||
const MetaLogicalMonitor *logical_monitor;
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
placed_rect = (MetaRectangle) {
|
||||
.x = window->rect.x,
|
||||
@ -481,11 +488,12 @@ place_window_if_needed(MetaWindow *window,
|
||||
* new monitor and update the ConstraintInfo
|
||||
*/
|
||||
logical_monitor =
|
||||
meta_screen_get_logical_monitor_for_rect (window->screen, &placed_rect);
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager,
|
||||
&placed_rect);
|
||||
info->entire_monitor = logical_monitor->rect;
|
||||
meta_window_get_work_area_for_monitor (window,
|
||||
logical_monitor->number,
|
||||
&info->work_area_monitor);
|
||||
meta_window_get_work_area_for_logical_monitor (window,
|
||||
logical_monitor,
|
||||
&info->work_area_monitor);
|
||||
cur_workspace = window->screen->active_workspace;
|
||||
info->usable_monitor_region =
|
||||
meta_workspace_get_onmonitor_region (cur_workspace,
|
||||
|
@ -137,8 +137,6 @@ MetaLogicalMonitor * meta_screen_get_current_logical_monitor (MetaScreen *scr
|
||||
MetaLogicalMonitor * meta_screen_get_current_logical_monitor_for_pos (MetaScreen *screen,
|
||||
int x,
|
||||
int y);
|
||||
MetaLogicalMonitor * meta_screen_get_logical_monitor_for_rect (MetaScreen *screen,
|
||||
MetaRectangle *rect);
|
||||
MetaLogicalMonitor * meta_screen_calculate_logical_monitor_for_window (MetaScreen *screen,
|
||||
MetaWindow *window);
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "core.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "boxes-private.h"
|
||||
#include "backends/meta-backend-private.h"
|
||||
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <X11/extensions/Xcomposite.h>
|
||||
@ -1403,77 +1404,32 @@ meta_screen_get_mouse_window (MetaScreen *screen,
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_screen_get_logical_monitor_for_rect (MetaScreen *screen,
|
||||
MetaRectangle *rect)
|
||||
meta_screen_calculate_logical_monitor_for_window (MetaScreen *screen,
|
||||
MetaWindow *window)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitors;
|
||||
unsigned int n_logical_monitors;
|
||||
unsigned int i, best_monitor;
|
||||
int monitor_score, rect_area;
|
||||
|
||||
logical_monitors =
|
||||
meta_monitor_manager_get_logical_monitors (monitor_manager,
|
||||
&n_logical_monitors);
|
||||
|
||||
if (n_logical_monitors == 1)
|
||||
return &logical_monitors[0];
|
||||
|
||||
best_monitor = 0;
|
||||
monitor_score = -1;
|
||||
|
||||
rect_area = meta_rectangle_area (rect);
|
||||
for (i = 0; i < n_logical_monitors; i++)
|
||||
{
|
||||
gboolean result;
|
||||
int cur;
|
||||
|
||||
if (rect_area > 0)
|
||||
{
|
||||
MetaRectangle dest;
|
||||
result = meta_rectangle_intersect (&logical_monitors[i].rect,
|
||||
rect,
|
||||
&dest);
|
||||
cur = meta_rectangle_area (&dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = meta_rectangle_contains_rect (&logical_monitors[i].rect,
|
||||
rect);
|
||||
cur = rect_area;
|
||||
}
|
||||
|
||||
if (result && cur > monitor_score)
|
||||
{
|
||||
monitor_score = cur;
|
||||
best_monitor = i;
|
||||
}
|
||||
}
|
||||
|
||||
return &logical_monitors[best_monitor];
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_screen_calculate_logical_monitor_for_window (MetaScreen *screen,
|
||||
MetaWindow *window)
|
||||
{
|
||||
MetaRectangle window_rect;
|
||||
|
||||
meta_window_get_frame_rect (window, &window_rect);
|
||||
|
||||
return meta_screen_get_logical_monitor_for_rect (screen, &window_rect);
|
||||
return meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager,
|
||||
&window_rect);
|
||||
}
|
||||
|
||||
int
|
||||
meta_screen_get_monitor_index_for_rect (MetaScreen *screen,
|
||||
MetaRectangle *rect)
|
||||
{
|
||||
MetaLogicalMonitor *monitor;
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
monitor = meta_screen_get_logical_monitor_for_rect (screen, rect);
|
||||
return monitor->number;
|
||||
logical_monitor =
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager, rect);
|
||||
return logical_monitor->number;
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
|
@ -955,13 +955,22 @@ void
|
||||
meta_workspace_set_builtin_struts (MetaWorkspace *workspace,
|
||||
GSList *struts)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaScreen *screen = workspace->screen;
|
||||
GSList *l;
|
||||
|
||||
for (l = struts; l; l = l->next)
|
||||
{
|
||||
MetaStrut *strut = l->data;
|
||||
int idx = meta_screen_get_monitor_index_for_rect (screen, &strut->rect);
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
int idx;
|
||||
|
||||
logical_monitor =
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager,
|
||||
&strut->rect);
|
||||
idx = logical_monitor->number;
|
||||
|
||||
switch (strut->side)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "meta-wayland-private.h"
|
||||
#include "meta-wayland-surface.h"
|
||||
#include "meta-wayland-xdg-shell.h"
|
||||
#include "backends/meta-backend-private.h"
|
||||
#include "compositor/meta-surface-actor-wayland.h"
|
||||
|
||||
struct _MetaWindowWayland
|
||||
@ -334,6 +335,9 @@ scale_rect_size (MetaRectangle *rect,
|
||||
static void
|
||||
meta_window_wayland_update_main_monitor (MetaWindow *window)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaWindow *toplevel_window;
|
||||
const MetaLogicalMonitor *from;
|
||||
const MetaLogicalMonitor *to;
|
||||
@ -376,7 +380,8 @@ meta_window_wayland_update_main_monitor (MetaWindow *window)
|
||||
scale = (float)to->scale / from->scale;
|
||||
rect = window->rect;
|
||||
scale_rect_size (&rect, scale);
|
||||
scaled_new = meta_screen_get_logical_monitor_for_rect (window->screen, &rect);
|
||||
scaled_new =
|
||||
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager, &rect);
|
||||
if (to != scaled_new)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user