diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index c07cc88e4..0920da9ae 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -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); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index aeede6eaf..da52478d8 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -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) diff --git a/src/core/constraints.c b/src/core/constraints.c index f3078664b..7ccce5171 100644 --- a/src/core/constraints.c +++ b/src/core/constraints.c @@ -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, diff --git a/src/core/screen-private.h b/src/core/screen-private.h index a1ebc99f0..e9eb7aa67 100644 --- a/src/core/screen-private.h +++ b/src/core/screen-private.h @@ -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); diff --git a/src/core/screen.c b/src/core/screen.c index 0f14d18ab..bbea61fa7 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -44,6 +44,7 @@ #include "core.h" #include "meta-cursor-tracker-private.h" #include "boxes-private.h" +#include "backends/meta-backend-private.h" #include #include @@ -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 * diff --git a/src/core/workspace.c b/src/core/workspace.c index 1633c80c3..ea465a7c3 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -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) { diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 20d2c0692..9ac45734b 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -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;