Move logical monitor neighbor API into monitor manager

Move the last piece of monitor grid getter API to the monitor manager
away from MetaScreen. The public facing API are still there, but are
thin wrappers around the MetaMonitorManager API.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-12-01 15:15:52 +08:00
parent 98ee85ce82
commit a422d6fe08
8 changed files with 84 additions and 63 deletions

View File

@ -380,6 +380,10 @@ MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_at (MetaMonitorMana
MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
MetaRectangle *rect);
MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager,
MetaLogicalMonitor *logical_monitor,
MetaScreenDirection direction);
MetaOutput *meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
unsigned int *n_outputs);

View File

@ -1386,6 +1386,53 @@ meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
return best_logical_monitor;
}
MetaLogicalMonitor *
meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager,
MetaLogicalMonitor *logical_monitor,
MetaScreenDirection direction)
{
unsigned int i;
for (i = 0; i < manager->n_logical_monitors; i++)
{
MetaLogicalMonitor *other = &manager->logical_monitors[i];
switch (direction)
{
case META_SCREEN_RIGHT:
if (other->rect.x == (logical_monitor->rect.x +
logical_monitor->rect.width) &&
meta_rectangle_vert_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_LEFT:
if (logical_monitor->rect.x == (other->rect.x +
other->rect.width) &&
meta_rectangle_vert_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_UP:
if (logical_monitor->rect.y == (other->rect.y +
other->rect.height) &&
meta_rectangle_horiz_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
case META_SCREEN_DOWN:
if (other->rect.y == (logical_monitor->rect.y +
logical_monitor->rect.height) &&
meta_rectangle_horiz_overlap (&other->rect,
&logical_monitor->rect))
return other;
break;
}
}
return NULL;
}
MetaOutput *
meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
unsigned int *n_outputs)

View File

@ -3154,11 +3154,15 @@ handle_move_to_monitor (MetaDisplay *display,
MetaKeyBinding *binding,
gpointer dummy)
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
gint which = binding->handler->data;
const MetaLogicalMonitor *current, *new;
MetaLogicalMonitor *current, *new;
current = window->monitor;
new = meta_screen_get_monitor_neighbor (screen, current->number, which);
new = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
current, which);
if (new == NULL)
return;

View File

@ -130,10 +130,6 @@ void meta_screen_hide_tile_preview (MetaScreen *screen);
MetaWindow* meta_screen_get_mouse_window (MetaScreen *screen,
MetaWindow *not_this_one);
MetaLogicalMonitor * meta_screen_get_monitor_neighbor (MetaScreen *screen,
int which_monitor,
MetaScreenDirection dir);
void meta_screen_update_workspace_layout (MetaScreen *screen);
void meta_screen_update_workspace_names (MetaScreen *screen);
void meta_screen_queue_workarea_recalc (MetaScreen *screen);

View File

@ -1415,60 +1415,24 @@ meta_screen_get_monitor_index_for_rect (MetaScreen *screen,
return logical_monitor->number;
}
MetaLogicalMonitor *
meta_screen_get_monitor_neighbor (MetaScreen *screen,
int
meta_screen_get_monitor_neighbor_index (MetaScreen *screen,
int which_monitor,
MetaScreenDirection direction)
{
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;
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 = &logical_monitors[i];
if ((direction == META_SCREEN_RIGHT &&
current->rect.x == input->rect.x + input->rect.width &&
meta_rectangle_vert_overlap(&current->rect, &input->rect)) ||
(direction == META_SCREEN_LEFT &&
input->rect.x == current->rect.x + current->rect.width &&
meta_rectangle_vert_overlap(&current->rect, &input->rect)) ||
(direction == META_SCREEN_UP &&
input->rect.y == current->rect.y + current->rect.height &&
meta_rectangle_horiz_overlap(&current->rect, &input->rect)) ||
(direction == META_SCREEN_DOWN &&
current->rect.y == input->rect.y + input->rect.height &&
meta_rectangle_horiz_overlap(&current->rect, &input->rect)))
{
return current;
}
}
return NULL;
}
int
meta_screen_get_monitor_neighbor_index (MetaScreen *screen,
int which_monitor,
MetaScreenDirection direction)
{
MetaLogicalMonitor *logical_monitor;
MetaLogicalMonitor *neighbor;
logical_monitor = meta_screen_get_monitor_neighbor (screen,
which_monitor,
logical_monitor =
meta_monitor_manager_get_logical_monitor_from_number (monitor_manager,
which_monitor);
neighbor = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
logical_monitor,
direction);
return logical_monitor ? logical_monitor->number : -1;
return neighbor ? neighbor->number : -1;
}
/**

View File

@ -135,7 +135,7 @@ struct _MetaWindow
MetaDisplay *display;
MetaScreen *screen;
guint64 stamp;
const MetaLogicalMonitor *monitor;
MetaLogicalMonitor *monitor;
MetaWorkspace *workspace;
MetaWindowClientType client_type;
MetaWaylandSurface *surface;

View File

@ -965,37 +965,43 @@ meta_workspace_set_builtin_struts (MetaWorkspace *workspace,
{
MetaStrut *strut = l->data;
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)
{
case META_SIDE_TOP:
if (meta_screen_get_monitor_neighbor (screen, idx, META_SCREEN_UP))
if (meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
logical_monitor,
META_SCREEN_UP))
continue;
strut->rect.height += strut->rect.y;
strut->rect.y = 0;
break;
case META_SIDE_BOTTOM:
if (meta_screen_get_monitor_neighbor (screen, idx, META_SCREEN_DOWN))
if (meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
logical_monitor,
META_SCREEN_DOWN))
continue;
strut->rect.height = screen->rect.height - strut->rect.y;
break;
case META_SIDE_LEFT:
if (meta_screen_get_monitor_neighbor (screen, idx, META_SCREEN_LEFT))
if (meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
logical_monitor,
META_SCREEN_LEFT))
continue;
strut->rect.width += strut->rect.x;
strut->rect.x = 0;
break;
case META_SIDE_RIGHT:
if (meta_screen_get_monitor_neighbor (screen, idx, META_SCREEN_RIGHT))
if (meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager,
logical_monitor,
META_SCREEN_RIGHT))
continue;
strut->rect.width = screen->rect.width - strut->rect.x;

View File

@ -339,9 +339,9 @@ meta_window_wayland_update_main_monitor (MetaWindow *window)
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaWindow *toplevel_window;
const MetaLogicalMonitor *from;
const MetaLogicalMonitor *to;
const MetaLogicalMonitor *scaled_new;
MetaLogicalMonitor *from;
MetaLogicalMonitor *to;
MetaLogicalMonitor *scaled_new;
float scale;
MetaRectangle rect;