MetaScreen: Remove redundant copy of logical monitors array

It was just pointer to the actual list; having to synchronize a list of
logical monitors with the actual monitors managed by the backend is
unnecessary.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-11-28 20:11:24 +08:00
parent 103df63023
commit e22bbd4b14
8 changed files with 320 additions and 108 deletions

View File

@ -363,6 +363,8 @@ struct _MetaMonitorManagerClass
void meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager); void meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager);
int meta_monitor_manager_get_num_logical_monitors (MetaMonitorManager *manager);
MetaLogicalMonitor *meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager, MetaLogicalMonitor *meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager,
unsigned int *n_logical_monitors); unsigned int *n_logical_monitors);

View File

@ -1290,11 +1290,18 @@ meta_monitor_manager_get (void)
return meta_backend_get_monitor_manager (backend); return meta_backend_get_monitor_manager (backend);
} }
int
meta_monitor_manager_get_num_logical_monitors (MetaMonitorManager *manager)
{
return (int) manager->n_logical_monitors;
}
MetaLogicalMonitor * MetaLogicalMonitor *
meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager, meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager,
unsigned int *n_logical_monitors) unsigned int *n_logical_monitors)
{ {
*n_logical_monitors = manager->n_logical_monitors; if (n_logical_monitors)
*n_logical_monitors = manager->n_logical_monitors;
return manager->logical_monitors; return manager->logical_monitors;
} }

View File

@ -27,6 +27,8 @@
#include "workspace-private.h" #include "workspace-private.h"
#include "place.h" #include "place.h"
#include <meta/prefs.h> #include <meta/prefs.h>
#include "backends/meta-backend-private.h"
#include "backends/meta-monitor-manager-private.h"
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
@ -388,17 +390,23 @@ setup_constraint_info (ConstraintInfo *info,
} }
else else
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
int i = 0; int i = 0;
long monitor; long monitor;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager, NULL);
monitor = window->fullscreen_monitors[i]; monitor = window->fullscreen_monitors[i];
info->entire_monitor = info->entire_monitor = logical_monitors[monitor].rect;
window->screen->logical_monitors[monitor].rect;
for (i = 1; i <= 3; i++) for (i = 1; i <= 3; i++)
{ {
monitor = window->fullscreen_monitors[i]; monitor = window->fullscreen_monitors[i];
meta_rectangle_union (&info->entire_monitor, meta_rectangle_union (&info->entire_monitor,
&window->screen->logical_monitors[monitor].rect, &logical_monitors[monitor].rect,
&info->entire_monitor); &info->entire_monitor);
} }
} }
@ -1441,6 +1449,10 @@ constrain_to_single_monitor (MetaWindow *window,
ConstraintPriority priority, ConstraintPriority priority,
gboolean check_only) gboolean check_only)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
if (priority > PRIORITY_ENTIRELY_VISIBLE_ON_SINGLE_MONITOR) if (priority > PRIORITY_ENTIRELY_VISIBLE_ON_SINGLE_MONITOR)
return TRUE; return TRUE;
@ -1451,7 +1463,7 @@ constrain_to_single_monitor (MetaWindow *window,
*/ */
if (window->type == META_WINDOW_DESKTOP || if (window->type == META_WINDOW_DESKTOP ||
window->type == META_WINDOW_DOCK || window->type == META_WINDOW_DOCK ||
window->screen->n_logical_monitors == 1 || meta_monitor_manager_get_num_logical_monitors (monitor_manager) == 1 ||
!window->require_on_single_monitor || !window->require_on_single_monitor ||
!window->frame || !window->frame ||
info->is_user_action || info->is_user_action ||

View File

@ -26,6 +26,8 @@
#include "boxes-private.h" #include "boxes-private.h"
#include "place.h" #include "place.h"
#include "backends/meta-backend-private.h"
#include <meta/meta-backend.h>
#include <meta/workspace.h> #include <meta/workspace.h>
#include <meta/prefs.h> #include <meta/prefs.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
@ -516,8 +518,16 @@ find_first_fit (MetaWindow *window,
#ifdef WITH_VERBOSE_MODE #ifdef WITH_VERBOSE_MODE
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
char monitor_location_string[RECT_LENGTH]; char monitor_location_string[RECT_LENGTH];
meta_rectangle_to_string (&window->screen->logical_monitors[monitor].rect,
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager, NULL);
meta_rectangle_to_string (&logical_monitors[monitor].rect,
monitor_location_string); monitor_location_string);
meta_topic (META_DEBUG_XINERAMA, meta_topic (META_DEBUG_XINERAMA,
"Natural monitor is %s\n", "Natural monitor is %s\n",

View File

@ -75,9 +75,6 @@ struct _MetaScreen
Atom wm_sn_atom; Atom wm_sn_atom;
guint32 wm_sn_timestamp; guint32 wm_sn_timestamp;
MetaLogicalMonitor *logical_monitors;
int n_logical_monitors;
int primary_monitor_index;
gboolean has_xinerama_indices; gboolean has_xinerama_indices;
/* Cache the current monitor */ /* Cache the current monitor */

View File

@ -340,8 +340,14 @@ set_wm_icon_size_hint (MetaScreen *screen)
static void static void
meta_screen_ensure_xinerama_indices (MetaScreen *screen) meta_screen_ensure_xinerama_indices (MetaScreen *screen)
{ {
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;
XineramaScreenInfo *infos; XineramaScreenInfo *infos;
int n_infos, i, j; int n_infos, j;
if (screen->has_xinerama_indices) if (screen->has_xinerama_indices)
return; return;
@ -358,15 +364,19 @@ meta_screen_ensure_xinerama_indices (MetaScreen *screen)
return; return;
} }
for (i = 0; i < screen->n_logical_monitors; ++i) logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
for (i = 0; i < n_logical_monitors; ++i)
{ {
for (j = 0; j < n_infos; ++j) for (j = 0; j < n_infos; ++j)
{ {
if (screen->logical_monitors[i].rect.x == infos[j].x_org && if (logical_monitors[i].rect.x == infos[j].x_org &&
screen->logical_monitors[i].rect.y == infos[j].y_org && logical_monitors[i].rect.y == infos[j].y_org &&
screen->logical_monitors[i].rect.width == infos[j].width && logical_monitors[i].rect.width == infos[j].width &&
screen->logical_monitors[i].rect.height == infos[j].height) logical_monitors[i].rect.height == infos[j].height)
screen->logical_monitors[i].xinerama_index = j; logical_monitors[i].xinerama_index = j;
} }
} }
@ -377,23 +387,44 @@ int
meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen, meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen,
int index) int index)
{ {
g_return_val_if_fail (index >= 0 && index < screen->n_logical_monitors, -1); #ifndef G_DISABLE_CHECKS
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
#endif
g_return_val_if_fail (index >= 0 && index < (int) n_logical_monitors, -1);
meta_screen_ensure_xinerama_indices (screen); meta_screen_ensure_xinerama_indices (screen);
return screen->logical_monitors[index].xinerama_index; return logical_monitors[index].xinerama_index;
} }
int int
meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen, meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
int index) int index)
{ {
int i; 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;
meta_screen_ensure_xinerama_indices (screen); meta_screen_ensure_xinerama_indices (screen);
for (i = 0; i < screen->n_logical_monitors; i++) logical_monitors =
if (screen->logical_monitors[i].xinerama_index == index) meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
for (i = 0; i < n_logical_monitors; i++)
if (logical_monitors[i].xinerama_index == index)
return i; return i;
return -1; return -1;
@ -403,8 +434,6 @@ static void
reload_logical_monitors (MetaScreen *screen) reload_logical_monitors (MetaScreen *screen)
{ {
GList *l; GList *l;
MetaMonitorManager *manager;
unsigned int n_logical_monitors;
for (l = screen->workspaces; l != NULL; l = l->next) for (l = screen->workspaces; l != NULL; l = l->next)
{ {
@ -412,18 +441,9 @@ reload_logical_monitors (MetaScreen *screen)
meta_workspace_invalidate_work_area (space); meta_workspace_invalidate_work_area (space);
} }
/* Any previous screen->logical_monitors or screen->outputs is freed by the caller */
screen->last_monitor_index = 0; screen->last_monitor_index = 0;
screen->has_xinerama_indices = FALSE; screen->has_xinerama_indices = FALSE;
screen->display->monitor_cache_invalidated = TRUE; screen->display->monitor_cache_invalidated = TRUE;
manager = meta_monitor_manager_get ();
screen->logical_monitors =
meta_monitor_manager_get_logical_monitors (manager, &n_logical_monitors);
screen->n_logical_monitors = (unsigned int) n_logical_monitors;
screen->primary_monitor_index = meta_monitor_manager_get_primary_index (manager);
} }
/* The guard window allows us to leave minimized windows mapped so /* The guard window allows us to leave minimized windows mapped so
@ -807,8 +827,6 @@ meta_screen_free (MetaScreen *screen,
if (screen->check_fullscreen_later != 0) if (screen->check_fullscreen_later != 0)
meta_later_remove (screen->check_fullscreen_later); meta_later_remove (screen->check_fullscreen_later);
g_free (screen->logical_monitors);
if (screen->tile_preview_timeout_id) if (screen->tile_preview_timeout_id)
g_source_remove (screen->tile_preview_timeout_id); g_source_remove (screen->tile_preview_timeout_id);
@ -1394,17 +1412,26 @@ const MetaLogicalMonitor *
meta_screen_get_logical_monitor_for_rect (MetaScreen *screen, meta_screen_get_logical_monitor_for_rect (MetaScreen *screen,
MetaRectangle *rect) MetaRectangle *rect)
{ {
int i; MetaBackend *backend = meta_get_backend ();
int best_monitor, monitor_score, rect_area; 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;
if (screen->n_logical_monitors == 1) logical_monitors =
return &screen->logical_monitors[0]; meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
if (n_logical_monitors == 1)
return &logical_monitors[0];
best_monitor = 0; best_monitor = 0;
monitor_score = -1; monitor_score = -1;
rect_area = meta_rectangle_area (rect); rect_area = meta_rectangle_area (rect);
for (i = 0; i < screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
{ {
gboolean result; gboolean result;
int cur; int cur;
@ -1412,14 +1439,14 @@ meta_screen_get_logical_monitor_for_rect (MetaScreen *screen,
if (rect_area > 0) if (rect_area > 0)
{ {
MetaRectangle dest; MetaRectangle dest;
result = meta_rectangle_intersect (&screen->logical_monitors[i].rect, result = meta_rectangle_intersect (&logical_monitors[i].rect,
rect, rect,
&dest); &dest);
cur = meta_rectangle_area (&dest); cur = meta_rectangle_area (&dest);
} }
else else
{ {
result = meta_rectangle_contains_rect (&screen->logical_monitors[i].rect, result = meta_rectangle_contains_rect (&logical_monitors[i].rect,
rect); rect);
cur = rect_area; cur = rect_area;
} }
@ -1431,7 +1458,7 @@ meta_screen_get_logical_monitor_for_rect (MetaScreen *screen,
} }
} }
return &screen->logical_monitors[best_monitor]; return &logical_monitors[best_monitor];
} }
const MetaLogicalMonitor * const MetaLogicalMonitor *
@ -1460,15 +1487,24 @@ meta_screen_get_logical_monitor_for_point (MetaScreen *screen,
int x, int x,
int y) int y)
{ {
int i; 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;
if (screen->n_logical_monitors == 1) logical_monitors =
return &screen->logical_monitors[0]; meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
for (i = 0; i < screen->n_logical_monitors; i++) if (n_logical_monitors == 1)
return &logical_monitors[0];
for (i = 0; i < n_logical_monitors; i++)
{ {
if (POINT_IN_RECT (x, y, screen->logical_monitors[i].rect)) if (POINT_IN_RECT (x, y, logical_monitors[i].rect))
return &screen->logical_monitors[i]; return &logical_monitors[i];
} }
return NULL; return NULL;
@ -1479,13 +1515,23 @@ meta_screen_get_monitor_neighbor (MetaScreen *screen,
int which_monitor, int which_monitor,
MetaScreenDirection direction) MetaScreenDirection direction)
{ {
MetaLogicalMonitor *input = screen->logical_monitors + which_monitor; 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;
MetaLogicalMonitor *input;
MetaLogicalMonitor *current; MetaLogicalMonitor *current;
int i;
for (i = 0; i < screen->n_logical_monitors; i++) logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
input = &logical_monitors[which_monitor];
for (i = 0; i < n_logical_monitors; i++)
{ {
current = screen->logical_monitors + i; current = &logical_monitors[i];
if ((direction == META_SCREEN_RIGHT && if ((direction == META_SCREEN_RIGHT &&
current->rect.x == input->rect.x + input->rect.width && current->rect.x == input->rect.x + input->rect.width &&
@ -1523,10 +1569,19 @@ meta_screen_get_monitor_neighbor_index (MetaScreen *screen,
const MetaLogicalMonitor * const MetaLogicalMonitor *
meta_screen_get_current_logical_monitor (MetaScreen *screen) meta_screen_get_current_logical_monitor (MetaScreen *screen)
{ {
int monitor_index; MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
int monitor_index;
monitor_index = meta_screen_get_current_monitor (screen); logical_monitors =
return &screen->logical_monitors[monitor_index]; meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
monitor_index = meta_screen_get_current_monitor (screen);
return &logical_monitors[monitor_index];
} }
const MetaLogicalMonitor * const MetaLogicalMonitor *
@ -1534,10 +1589,19 @@ meta_screen_get_current_logical_monitor_for_pos (MetaScreen *screen,
int x, int x,
int y) int y)
{ {
int monitor_index; MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
int monitor_index;
monitor_index = meta_screen_get_current_monitor_for_pos (screen, x, y); logical_monitors =
return &screen->logical_monitors[monitor_index]; meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
monitor_index = meta_screen_get_current_monitor_for_pos (screen, x, y);
return &logical_monitors[monitor_index];
} }
@ -1556,11 +1620,21 @@ meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
int x, int x,
int y) int y)
{ {
if (screen->n_logical_monitors == 1) MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
if (n_logical_monitors == 1)
return 0; return 0;
else if (screen->display->monitor_cache_invalidated) else if (screen->display->monitor_cache_invalidated)
{ {
int i; unsigned int i;
MetaRectangle pointer_position; MetaRectangle pointer_position;
pointer_position.x = x; pointer_position.x = x;
pointer_position.y = y; pointer_position.y = y;
@ -1569,9 +1643,9 @@ meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
screen->display->monitor_cache_invalidated = FALSE; screen->display->monitor_cache_invalidated = FALSE;
screen->last_monitor_index = 0; screen->last_monitor_index = 0;
for (i = 0; i < screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
{ {
if (meta_rectangle_contains_rect (&screen->logical_monitors[i].rect, if (meta_rectangle_contains_rect (&logical_monitors[i].rect,
&pointer_position)) &pointer_position))
{ {
screen->last_monitor_index = i; screen->last_monitor_index = i;
@ -1600,9 +1674,14 @@ meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
int int
meta_screen_get_current_monitor (MetaScreen *screen) meta_screen_get_current_monitor (MetaScreen *screen)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (screen); MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (screen);
int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
if (screen->n_logical_monitors == 1) if (n_logical_monitors == 1)
return 0; return 0;
/* Sadly, we have to do it this way. Yuck. /* Sadly, we have to do it this way. Yuck.
@ -1630,9 +1709,13 @@ meta_screen_get_current_monitor (MetaScreen *screen)
int int
meta_screen_get_n_monitors (MetaScreen *screen) meta_screen_get_n_monitors (MetaScreen *screen)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
g_return_val_if_fail (META_IS_SCREEN (screen), 0); g_return_val_if_fail (META_IS_SCREEN (screen), 0);
return screen->n_logical_monitors; return meta_monitor_manager_get_num_logical_monitors (monitor_manager);
} }
/** /**
@ -1646,9 +1729,13 @@ meta_screen_get_n_monitors (MetaScreen *screen)
int int
meta_screen_get_primary_monitor (MetaScreen *screen) meta_screen_get_primary_monitor (MetaScreen *screen)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
g_return_val_if_fail (META_IS_SCREEN (screen), 0); g_return_val_if_fail (META_IS_SCREEN (screen), 0);
return screen->primary_monitor_index; return meta_monitor_manager_get_primary_index (monitor_manager);
} }
/** /**
@ -1664,11 +1751,23 @@ meta_screen_get_monitor_geometry (MetaScreen *screen,
int monitor, int monitor,
MetaRectangle *geometry) MetaRectangle *geometry)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
#ifndef G_DISABLE_CHECKS
int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
#endif
g_return_if_fail (META_IS_SCREEN (screen)); g_return_if_fail (META_IS_SCREEN (screen));
g_return_if_fail (monitor >= 0 && monitor < screen->n_logical_monitors); g_return_if_fail (monitor >= 0 && monitor < n_logical_monitors);
g_return_if_fail (geometry != NULL); g_return_if_fail (geometry != NULL);
*geometry = screen->logical_monitors[monitor].rect; logical_monitors = meta_monitor_manager_get_logical_monitors (monitor_manager,
NULL);
*geometry = logical_monitors[monitor].rect;
} }
#define _NET_WM_ORIENTATION_HORZ 0 #define _NET_WM_ORIENTATION_HORZ 0
@ -2721,14 +2820,23 @@ static gboolean
check_fullscreen_func (gpointer data) check_fullscreen_func (gpointer data)
{ {
MetaScreen *screen = data; MetaScreen *screen = data;
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;
MetaWindow *window; MetaWindow *window;
GSList *fullscreen_monitors = NULL; GSList *fullscreen_monitors = NULL;
GSList *obscured_monitors = NULL; GSList *obscured_monitors = NULL;
gboolean in_fullscreen_changed = FALSE; gboolean in_fullscreen_changed = FALSE;
int i;
screen->check_fullscreen_later = 0; screen->check_fullscreen_later = 0;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
/* We consider a monitor in fullscreen if it contains a fullscreen window; /* We consider a monitor in fullscreen if it contains a fullscreen window;
* however we make an exception for maximized windows above the fullscreen * however we make an exception for maximized windows above the fullscreen
* one, as in that case window+chrome fully obscure the fullscreen window. * one, as in that case window+chrome fully obscure the fullscreen window.
@ -2788,9 +2896,9 @@ check_fullscreen_func (gpointer data)
g_slist_free (obscured_monitors); g_slist_free (obscured_monitors);
for (i = 0; i < screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
{ {
MetaLogicalMonitor *logical_monitor = &screen->logical_monitors[i]; MetaLogicalMonitor *logical_monitor = &logical_monitors[i];
gboolean in_fullscreen = g_slist_find (fullscreen_monitors, GINT_TO_POINTER (i + 1)) != NULL; gboolean in_fullscreen = g_slist_find (fullscreen_monitors, GINT_TO_POINTER (i + 1)) != NULL;
if (in_fullscreen != logical_monitor->in_fullscreen) if (in_fullscreen != logical_monitor->in_fullscreen)
{ {
@ -2842,12 +2950,24 @@ gboolean
meta_screen_get_monitor_in_fullscreen (MetaScreen *screen, meta_screen_get_monitor_in_fullscreen (MetaScreen *screen,
int monitor) int monitor)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
#ifndef G_DISABLE_CHECKS
int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
#endif
g_return_val_if_fail (META_IS_SCREEN (screen), FALSE); g_return_val_if_fail (META_IS_SCREEN (screen), FALSE);
g_return_val_if_fail (monitor >= 0 && g_return_val_if_fail (monitor >= 0 &&
monitor < screen->n_logical_monitors, FALSE); monitor < n_logical_monitors, FALSE);
logical_monitors = meta_monitor_manager_get_logical_monitors (monitor_manager,
NULL);
/* We use -1 as a flag to mean "not known yet" for notification purposes */ /* We use -1 as a flag to mean "not known yet" for notification purposes */
return screen->logical_monitors[monitor].in_fullscreen == TRUE; return logical_monitors[monitor].in_fullscreen == TRUE;
} }
gboolean gboolean

View File

@ -2798,16 +2798,25 @@ meta_window_is_fullscreen (MetaWindow *window)
gint * gint *
meta_window_get_all_monitors (MetaWindow *window, gsize *length) meta_window_get_all_monitors (MetaWindow *window, gsize *length)
{ {
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;
GArray *monitors; GArray *monitors;
MetaRectangle window_rect; MetaRectangle window_rect;
int i;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
monitors = g_array_new (FALSE, FALSE, sizeof (int)); monitors = g_array_new (FALSE, FALSE, sizeof (int));
meta_window_get_frame_rect (window, &window_rect); meta_window_get_frame_rect (window, &window_rect);
for (i = 0; i < window->screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
{ {
MetaRectangle *monitor_rect = &window->screen->logical_monitors[i].rect; MetaRectangle *monitor_rect = &logical_monitors[i].rect;
if (meta_rectangle_overlap (&window_rect, monitor_rect)) if (meta_rectangle_overlap (&window_rect, monitor_rect))
g_array_append_val (monitors, i); g_array_append_val (monitors, i);
@ -3277,10 +3286,16 @@ meta_window_update_fullscreen_monitors (MetaWindow *window,
unsigned long left, unsigned long left,
unsigned long right) unsigned long right)
{ {
if ((int) top < window->screen->n_logical_monitors && MetaBackend *backend = meta_get_backend ();
(int) bottom < window->screen->n_logical_monitors && MetaMonitorManager *monitor_manager =
(int) left < window->screen->n_logical_monitors && meta_backend_get_monitor_manager (backend);
(int) right < window->screen->n_logical_monitors) int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
if ((int) top < n_logical_monitors &&
(int) bottom < n_logical_monitors &&
(int) left < n_logical_monitors &&
(int) right < n_logical_monitors)
{ {
window->fullscreen_monitors[0] = top; window->fullscreen_monitors[0] = top;
window->fullscreen_monitors[1] = bottom; window->fullscreen_monitors[1] = bottom;
@ -3520,11 +3535,20 @@ static MetaLogicalMonitor *
find_monitor_by_winsys_id (MetaWindow *window, find_monitor_by_winsys_id (MetaWindow *window,
guint winsys_id) guint winsys_id)
{ {
int i; 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;
for (i = 0; i < window->screen->n_logical_monitors; i++) logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
for (i = 0; i < n_logical_monitors; i++)
{ {
MetaLogicalMonitor *logical_monitor = &window->screen->logical_monitors[i]; MetaLogicalMonitor *logical_monitor = &logical_monitors[i];
if (logical_monitor->winsys_id == winsys_id) if (logical_monitor->winsys_id == winsys_id)
return logical_monitor; return logical_monitor;
@ -3538,6 +3562,12 @@ find_monitor_by_winsys_id (MetaWindow *window,
void void
meta_window_update_for_monitors_changed (MetaWindow *window) meta_window_update_for_monitors_changed (MetaWindow *window)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
int primary_monitor_index;
const MetaLogicalMonitor *old, *new; const MetaLogicalMonitor *old, *new;
if (window->fullscreen_monitors[0] != -1) if (window->fullscreen_monitors[0] != -1)
@ -3558,9 +3588,15 @@ meta_window_update_for_monitors_changed (MetaWindow *window)
if (!new) if (!new)
new = find_monitor_by_winsys_id (window, old->winsys_id); new = find_monitor_by_winsys_id (window, old->winsys_id);
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager,
&n_logical_monitors);
primary_monitor_index =
meta_monitor_manager_get_primary_index (monitor_manager);
/* Fall back to primary if everything else failed */ /* Fall back to primary if everything else failed */
if (!new) if (!new)
new = &window->screen->logical_monitors[window->screen->primary_monitor_index]; new = &logical_monitors[primary_monitor_index];
if (window->tile_mode != META_TILE_NONE) if (window->tile_mode != META_TILE_NONE)
window->tile_monitor_number = new->number; window->tile_monitor_number = new->number;
@ -5690,14 +5726,20 @@ update_move (MetaWindow *window,
else if ((window->shaken_loose || META_WINDOW_MAXIMIZED (window)) && else if ((window->shaken_loose || META_WINDOW_MAXIMIZED (window)) &&
window->tile_mode != META_TILE_LEFT && window->tile_mode != META_TILE_RIGHT) window->tile_mode != META_TILE_LEFT && window->tile_mode != META_TILE_RIGHT)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
int n_logical_monitors;
const MetaLogicalMonitor *wmonitor; const MetaLogicalMonitor *wmonitor;
MetaRectangle work_area; MetaRectangle work_area;
int monitor; int monitor;
window->tile_mode = META_TILE_NONE; window->tile_mode = META_TILE_NONE;
wmonitor = window->monitor; wmonitor = window->monitor;
n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
for (monitor = 0; monitor < window->screen->n_logical_monitors; monitor++) for (monitor = 0; monitor < n_logical_monitors; monitor++)
{ {
meta_window_get_work_area_for_monitor (window, monitor, &work_area); meta_window_get_work_area_for_monitor (window, monitor, &work_area);
@ -6067,12 +6109,19 @@ get_work_area_monitor (MetaWindow *window,
MetaRectangle *area, MetaRectangle *area,
int which_monitor) int which_monitor)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
GList *tmp; GList *tmp;
g_assert (which_monitor >= 0); g_assert (which_monitor >= 0);
logical_monitors = meta_monitor_manager_get_logical_monitors (monitor_manager,
NULL);
/* Initialize to the whole monitor */ /* Initialize to the whole monitor */
*area = window->screen->logical_monitors[which_monitor].rect; *area = logical_monitors[which_monitor].rect;
tmp = meta_window_get_workspaces (window); tmp = meta_window_get_workspaces (window);
while (tmp != NULL) while (tmp != NULL)

View File

@ -32,6 +32,7 @@
*/ */
#include <config.h> #include <config.h>
#include "backends/meta-backend-private.h"
#include "screen-private.h" #include "screen-private.h"
#include <meta/workspace.h> #include <meta/workspace.h>
#include "workspace-private.h" #include "workspace-private.h"
@ -265,15 +266,10 @@ assert_workspace_empty (MetaWorkspace *workspace)
void void
meta_workspace_remove (MetaWorkspace *workspace) meta_workspace_remove (MetaWorkspace *workspace)
{ {
MetaScreen *screen;
int i;
g_return_if_fail (workspace != workspace->screen->active_workspace); g_return_if_fail (workspace != workspace->screen->active_workspace);
assert_workspace_empty (workspace); assert_workspace_empty (workspace);
screen = workspace->screen;
workspace->screen->workspaces = workspace->screen->workspaces =
g_list_remove (workspace->screen->workspaces, workspace); g_list_remove (workspace->screen->workspaces, workspace);
@ -293,8 +289,10 @@ meta_workspace_remove (MetaWorkspace *workspace)
if (!workspace->work_areas_invalid) if (!workspace->work_areas_invalid)
{ {
int i;
workspace_free_all_struts (workspace); workspace_free_all_struts (workspace);
for (i = 0; i < screen->n_logical_monitors; i++) for (i = 0; i < workspace->n_monitor_regions; i++)
meta_rectangle_free_list_and_elements (workspace->monitor_region[i]); meta_rectangle_free_list_and_elements (workspace->monitor_region[i]);
g_free (workspace->monitor_region); g_free (workspace->monitor_region);
meta_rectangle_free_list_and_elements (workspace->screen_region); meta_rectangle_free_list_and_elements (workspace->screen_region);
@ -679,8 +677,8 @@ meta_workspace_list_windows (MetaWorkspace *workspace)
void void
meta_workspace_invalidate_work_area (MetaWorkspace *workspace) meta_workspace_invalidate_work_area (MetaWorkspace *workspace)
{ {
GList *windows, *l;
int i; int i;
GList *windows, *l;
if (workspace->work_areas_invalid) if (workspace->work_areas_invalid)
{ {
@ -704,7 +702,7 @@ meta_workspace_invalidate_work_area (MetaWorkspace *workspace)
workspace_free_all_struts (workspace); workspace_free_all_struts (workspace);
for (i = 0; i < workspace->screen->n_logical_monitors; i++) for (i = 0; i < workspace->n_monitor_regions; i++)
meta_rectangle_free_list_and_elements (workspace->monitor_region[i]); meta_rectangle_free_list_and_elements (workspace->monitor_region[i]);
g_free (workspace->monitor_region); g_free (workspace->monitor_region);
meta_rectangle_free_list_and_elements (workspace->screen_region); meta_rectangle_free_list_and_elements (workspace->screen_region);
@ -751,10 +749,15 @@ copy_strut_list(GSList *original)
static void static void
ensure_work_areas_validated (MetaWorkspace *workspace) ensure_work_areas_validated (MetaWorkspace *workspace)
{ {
GList *windows; MetaBackend *backend = meta_get_backend ();
GList *tmp; MetaMonitorManager *monitor_manager =
MetaRectangle work_area; meta_backend_get_monitor_manager (backend);
int i; /* C89 absolutely sucks... */ GList *windows;
GList *tmp;
MetaLogicalMonitor *logical_monitors;
unsigned int n_logical_monitors;
unsigned int i;
MetaRectangle work_area;
if (!workspace->work_areas_invalid) if (!workspace->work_areas_invalid)
return; return;
@ -788,15 +791,20 @@ ensure_work_areas_validated (MetaWorkspace *workspace)
g_assert (workspace->monitor_region == NULL); g_assert (workspace->monitor_region == NULL);
g_assert (workspace->screen_region == NULL); g_assert (workspace->screen_region == NULL);
workspace->monitor_region = g_new (GList*, logical_monitors =
workspace->screen->n_logical_monitors); meta_monitor_manager_get_logical_monitors (monitor_manager,
for (i = 0; i < workspace->screen->n_logical_monitors; i++) &n_logical_monitors);
workspace->monitor_region = g_new (GList*, n_logical_monitors);
for (i = 0; i < n_logical_monitors; i++)
{ {
workspace->monitor_region[i] = workspace->monitor_region[i] =
meta_rectangle_get_minimal_spanning_set_for_region ( meta_rectangle_get_minimal_spanning_set_for_region (
&workspace->screen->logical_monitors[i].rect, &logical_monitors[i].rect,
workspace->all_struts); workspace->all_struts);
} }
workspace->n_monitor_regions = (int) n_logical_monitors;
workspace->screen_region = workspace->screen_region =
meta_rectangle_get_minimal_spanning_set_for_region ( meta_rectangle_get_minimal_spanning_set_for_region (
&workspace->screen->rect, &workspace->screen->rect,
@ -860,12 +868,11 @@ ensure_work_areas_validated (MetaWorkspace *workspace)
/* Now find the work areas for each monitor */ /* Now find the work areas for each monitor */
g_free (workspace->work_area_monitor); g_free (workspace->work_area_monitor);
workspace->work_area_monitor = g_new (MetaRectangle, workspace->work_area_monitor = g_new (MetaRectangle, n_logical_monitors);
workspace->screen->n_logical_monitors);
for (i = 0; i < workspace->screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
{ {
work_area = workspace->screen->logical_monitors[i].rect; work_area = logical_monitors[i].rect;
if (workspace->monitor_region[i] == NULL) if (workspace->monitor_region[i] == NULL)
/* FIXME: constraints.c untested with this, but it might be nice for /* FIXME: constraints.c untested with this, but it might be nice for
@ -907,8 +914,8 @@ ensure_work_areas_validated (MetaWorkspace *workspace)
meta_rectangle_find_onscreen_edges (&workspace->screen->rect, meta_rectangle_find_onscreen_edges (&workspace->screen->rect,
workspace->all_struts); workspace->all_struts);
tmp = NULL; tmp = NULL;
for (i = 0; i < workspace->screen->n_logical_monitors; i++) for (i = 0; i < n_logical_monitors; i++)
tmp = g_list_prepend (tmp, &workspace->screen->logical_monitors[i].rect); tmp = g_list_prepend (tmp, &logical_monitors[i].rect);
workspace->monitor_edges = workspace->monitor_edges =
meta_rectangle_find_nonintersected_monitor_edges (tmp, meta_rectangle_find_nonintersected_monitor_edges (tmp,
workspace->all_struts); workspace->all_struts);
@ -1013,10 +1020,18 @@ meta_workspace_get_work_area_for_monitor (MetaWorkspace *workspace,
int which_monitor, int which_monitor,
MetaRectangle *area) MetaRectangle *area)
{ {
#ifndef G_DISABLE_ASSERT
MetaBackend *backend = meta_get_backend();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
#endif
g_assert (which_monitor >= 0); g_assert (which_monitor >= 0);
ensure_work_areas_validated (workspace); ensure_work_areas_validated (workspace);
g_assert (which_monitor < workspace->screen->n_logical_monitors); g_assert (which_monitor < n_logical_monitors);
*area = workspace->work_area_monitor[which_monitor]; *area = workspace->work_area_monitor[which_monitor];
} }