window: Keep track of fullscreen monitors directly

Instead of keeping around array indexes, keep track of them by storing
a pointer instead. This also changes from using an array (imitating the
X11 behaviour) to more explicit storing.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-11-29 17:50:17 +08:00
parent 0a4fb008f3
commit ecf796f82b
6 changed files with 93 additions and 93 deletions

View File

@ -384,31 +384,22 @@ setup_constraint_info (ConstraintInfo *info,
logical_monitor->number,
&info->work_area_monitor);
if (!window->fullscreen || window->fullscreen_monitors[0] == -1)
if (!window->fullscreen || !meta_window_has_fullscreen_monitors (window))
{
info->entire_monitor = logical_monitor->rect;
}
else
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitors;
int i = 0;
long monitor;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager, NULL);
monitor = window->fullscreen_monitors[i];
info->entire_monitor = logical_monitors[monitor].rect;
for (i = 1; i <= 3; i++)
{
monitor = window->fullscreen_monitors[i];
meta_rectangle_union (&info->entire_monitor,
&logical_monitors[monitor].rect,
&info->entire_monitor);
}
info->entire_monitor = window->fullscreen_monitors.top->rect;
meta_rectangle_union (&info->entire_monitor,
&window->fullscreen_monitors.bottom->rect,
&info->entire_monitor);
meta_rectangle_union (&info->entire_monitor,
&window->fullscreen_monitors.left->rect,
&info->entire_monitor);
meta_rectangle_union (&info->entire_monitor,
&window->fullscreen_monitors.right->rect,
&info->entire_monitor);
}
cur_workspace = window->screen->active_workspace;

View File

@ -205,9 +205,10 @@ void meta_screen_create_guard_window (MetaScreen *screen);
gboolean meta_screen_handle_xevent (MetaScreen *screen,
XEvent *xevent);
int meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
int index);
int meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen,
int index);
MetaLogicalMonitor * meta_screen_xinerama_index_to_logical_monitor (MetaScreen *screen,
int index);
int meta_screen_logical_monitor_to_xinerama_index (MetaScreen *screen,
MetaLogicalMonitor *logical_monitor);
#endif

View File

@ -384,31 +384,19 @@ meta_screen_ensure_xinerama_indices (MetaScreen *screen)
}
int
meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen,
int index)
meta_screen_logical_monitor_to_xinerama_index (MetaScreen *screen,
MetaLogicalMonitor *logical_monitor)
{
#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);
g_return_val_if_fail (logical_monitor, -1);
meta_screen_ensure_xinerama_indices (screen);
return logical_monitors[index].xinerama_index;
return logical_monitor->xinerama_index;
}
int
meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
int index)
MetaLogicalMonitor *
meta_screen_xinerama_index_to_logical_monitor (MetaScreen *screen,
int xinerama_index)
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
@ -424,10 +412,10 @@ meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
&n_logical_monitors);
for (i = 0; i < n_logical_monitors; i++)
if (logical_monitors[i].xinerama_index == index)
return i;
if (logical_monitors[i].xinerama_index == xinerama_index)
return &logical_monitors[i];
return -1;
return NULL;
}
static void

View File

@ -221,7 +221,12 @@ struct _MetaWindow
* been overridden (via a client message), the window will cover the union of
* these monitors. If not, this is the single monitor which the window's
* origin is on. */
gint fullscreen_monitors[4];
struct {
MetaLogicalMonitor *top;
MetaLogicalMonitor *bottom;
MetaLogicalMonitor *left;
MetaLogicalMonitor *right;
} fullscreen_monitors;
/* Whether we're trying to constrain the window to be fully onscreen */
guint require_fully_onscreen : 1;
@ -574,11 +579,13 @@ void meta_window_maximize_internal (MetaWindow *window,
MetaRectangle *saved_rect);
void meta_window_make_fullscreen_internal (MetaWindow *window);
void meta_window_update_fullscreen_monitors (MetaWindow *window,
unsigned long top,
unsigned long bottom,
unsigned long left,
unsigned long right);
void meta_window_update_fullscreen_monitors (MetaWindow *window,
MetaLogicalMonitor *top,
MetaLogicalMonitor *bottom,
MetaLogicalMonitor *left,
MetaLogicalMonitor *right);
gboolean meta_window_has_fullscreen_monitors (MetaWindow *window);
void meta_window_resize_frame_with_gravity (MetaWindow *window,
gboolean user_op,

View File

@ -927,7 +927,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->maximize_vertically_after_placement = FALSE;
window->minimize_after_placement = FALSE;
window->fullscreen = FALSE;
window->fullscreen_monitors[0] = -1;
window->require_fully_onscreen = TRUE;
window->require_on_single_monitor = TRUE;
window->require_titlebar_visible = TRUE;
@ -3279,32 +3278,32 @@ meta_window_unmake_fullscreen (MetaWindow *window)
}
}
void
meta_window_update_fullscreen_monitors (MetaWindow *window,
unsigned long top,
unsigned long bottom,
unsigned long left,
unsigned long right)
static void
meta_window_clear_fullscreen_monitors (MetaWindow *window)
{
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);
window->fullscreen_monitors.top = NULL;
window->fullscreen_monitors.bottom = NULL;
window->fullscreen_monitors.left = NULL;
window->fullscreen_monitors.right = NULL;
}
if ((int) top < n_logical_monitors &&
(int) bottom < n_logical_monitors &&
(int) left < n_logical_monitors &&
(int) right < n_logical_monitors)
void
meta_window_update_fullscreen_monitors (MetaWindow *window,
MetaLogicalMonitor *top,
MetaLogicalMonitor *bottom,
MetaLogicalMonitor *left,
MetaLogicalMonitor *right)
{
if (top && bottom && left && right)
{
window->fullscreen_monitors[0] = top;
window->fullscreen_monitors[1] = bottom;
window->fullscreen_monitors[2] = left;
window->fullscreen_monitors[3] = right;
window->fullscreen_monitors.top = top;
window->fullscreen_monitors.bottom = bottom;
window->fullscreen_monitors.left = left;
window->fullscreen_monitors.right = right;
}
else
{
window->fullscreen_monitors[0] = -1;
meta_window_clear_fullscreen_monitors (window);
}
if (window->fullscreen)
@ -3313,6 +3312,12 @@ meta_window_update_fullscreen_monitors (MetaWindow *window,
}
}
gboolean
meta_window_has_fullscreen_monitors (MetaWindow *window)
{
return window->fullscreen_monitors.top != NULL;
}
void
meta_window_shade (MetaWindow *window,
guint32 timestamp)
@ -3567,8 +3572,8 @@ meta_window_update_for_monitors_changed (MetaWindow *window)
meta_backend_get_monitor_manager (backend);
const MetaLogicalMonitor *old, *new;
if (window->fullscreen_monitors[0] != -1)
window->fullscreen_monitors[0] = -1;
if (meta_window_has_fullscreen_monitors (window))
meta_window_clear_fullscreen_monitors (window);
if (window->override_redirect || window->type == META_WINDOW_DESKTOP)
{

View File

@ -1612,16 +1612,20 @@ meta_window_x11_set_net_wm_state (MetaWindow *window)
if (window->fullscreen)
{
if (window->fullscreen_monitors[0] >= 0)
if (meta_window_has_fullscreen_monitors (window))
{
data[0] = meta_screen_monitor_index_to_xinerama_index (window->screen,
window->fullscreen_monitors[0]);
data[1] = meta_screen_monitor_index_to_xinerama_index (window->screen,
window->fullscreen_monitors[1]);
data[2] = meta_screen_monitor_index_to_xinerama_index (window->screen,
window->fullscreen_monitors[2]);
data[3] = meta_screen_monitor_index_to_xinerama_index (window->screen,
window->fullscreen_monitors[3]);
data[0] =
meta_screen_logical_monitor_to_xinerama_index (window->screen,
window->fullscreen_monitors.top);
data[1] =
meta_screen_logical_monitor_to_xinerama_index (window->screen,
window->fullscreen_monitors.bottom);
data[2] =
meta_screen_logical_monitor_to_xinerama_index (window->screen,
window->fullscreen_monitors.left);
data[3] =
meta_screen_logical_monitor_to_xinerama_index (window->screen,
window->fullscreen_monitors.right);
meta_verbose ("Setting _NET_WM_FULLSCREEN_MONITORS\n");
meta_error_trap_push (window->display);
@ -2668,19 +2672,23 @@ meta_window_x11_client_message (MetaWindow *window,
else if (event->xclient.message_type ==
display->atom__NET_WM_FULLSCREEN_MONITORS)
{
gulong top, bottom, left, right;
MetaLogicalMonitor *top, *bottom, *left, *right;
meta_verbose ("_NET_WM_FULLSCREEN_MONITORS request for window '%s'\n",
window->desc);
top = meta_screen_xinerama_index_to_monitor_index (window->screen,
event->xclient.data.l[0]);
bottom = meta_screen_xinerama_index_to_monitor_index (window->screen,
event->xclient.data.l[1]);
left = meta_screen_xinerama_index_to_monitor_index (window->screen,
event->xclient.data.l[2]);
right = meta_screen_xinerama_index_to_monitor_index (window->screen,
event->xclient.data.l[3]);
top =
meta_screen_xinerama_index_to_logical_monitor (window->screen,
event->xclient.data.l[0]);
bottom =
meta_screen_xinerama_index_to_logical_monitor (window->screen,
event->xclient.data.l[1]);
left =
meta_screen_xinerama_index_to_logical_monitor (window->screen,
event->xclient.data.l[2]);
right =
meta_screen_xinerama_index_to_logical_monitor (window->screen,
event->xclient.data.l[3]);
/* source_indication = event->xclient.data.l[4]; */
meta_window_update_fullscreen_monitors (window, top, bottom, left, right);