MetaMonitorManager: Track primary monitor by pointer instead of index
Instead of keeping an index in an array to keep track of the current primary logical monitor, just keep a pointer instead. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
parent
e22bbd4b14
commit
c936056663
@ -115,16 +115,11 @@ center_pointer (MetaBackend *backend)
|
||||
{
|
||||
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
||||
MetaMonitorManager *monitor_manager = priv->monitor_manager;
|
||||
MetaLogicalMonitor *logical_monitors, *primary;
|
||||
unsigned int n_logical_monitors;
|
||||
int primary_monitor_index;
|
||||
MetaLogicalMonitor *primary;
|
||||
|
||||
primary =
|
||||
meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
|
||||
|
||||
logical_monitors =
|
||||
meta_monitor_manager_get_logical_monitors (monitor_manager,
|
||||
&n_logical_monitors);
|
||||
primary_monitor_index =
|
||||
meta_monitor_manager_get_primary_index (monitor_manager);
|
||||
primary = &logical_monitors[primary_monitor_index];
|
||||
meta_backend_warp_pointer (backend,
|
||||
primary->rect.x + primary->rect.width / 2,
|
||||
primary->rect.y + primary->rect.height / 2);
|
||||
|
@ -306,7 +306,7 @@ struct _MetaMonitorManager
|
||||
|
||||
MetaLogicalMonitor *logical_monitors;
|
||||
unsigned int n_logical_monitors;
|
||||
int primary_monitor_index;
|
||||
MetaLogicalMonitor *primary_logical_monitor;
|
||||
|
||||
int dbus_name_id;
|
||||
|
||||
@ -368,6 +368,8 @@ int meta_monitor_manager_get_num_logical_monitors (MetaMonitorMa
|
||||
MetaLogicalMonitor *meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager,
|
||||
unsigned int *n_logical_monitors);
|
||||
|
||||
MetaLogicalMonitor *meta_monitor_manager_get_primary_logical_monitor (MetaMonitorManager *manager);
|
||||
|
||||
MetaOutput *meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
|
||||
unsigned int *n_outputs);
|
||||
|
||||
@ -379,8 +381,6 @@ void meta_monitor_manager_get_resources (MetaMonitorManager
|
||||
MetaOutput **outputs,
|
||||
unsigned int *n_outputs);
|
||||
|
||||
int meta_monitor_manager_get_primary_index (MetaMonitorManager *manager);
|
||||
|
||||
void meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
|
||||
int *width,
|
||||
int *height);
|
||||
|
@ -247,6 +247,7 @@ make_logical_config (MetaMonitorManager *manager)
|
||||
/* Now walk the list of outputs applying extended properties (primary
|
||||
and presentation)
|
||||
*/
|
||||
manager->primary_logical_monitor = NULL;
|
||||
for (i = 0; i < manager->n_outputs; i++)
|
||||
{
|
||||
MetaOutput *output;
|
||||
@ -283,12 +284,20 @@ make_logical_config (MetaMonitorManager *manager)
|
||||
logical_monitor->winsys_id = output->winsys_id;
|
||||
|
||||
if (logical_monitor->is_primary)
|
||||
manager->primary_monitor_index = logical_monitor->number;
|
||||
manager->primary_logical_monitor = logical_monitor;
|
||||
}
|
||||
|
||||
manager->n_logical_monitors = logical_monitors->len;
|
||||
manager->logical_monitors = (void*)g_array_free (logical_monitors, FALSE);
|
||||
|
||||
/*
|
||||
* If no monitor was marked as primary, fall back on marking the first
|
||||
* logical monitor the primary one.
|
||||
*/
|
||||
if (!manager->primary_logical_monitor &&
|
||||
manager->n_logical_monitors > 0)
|
||||
manager->primary_logical_monitor = &manager->logical_monitors[0];
|
||||
|
||||
if (manager_class->add_monitor)
|
||||
for (i = 0; i < manager->n_logical_monitors; i++)
|
||||
manager_class->add_monitor (manager, &manager->logical_monitors[i]);
|
||||
@ -1305,6 +1314,12 @@ meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager,
|
||||
return manager->logical_monitors;
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_monitor_manager_get_primary_logical_monitor (MetaMonitorManager *manager)
|
||||
{
|
||||
return manager->primary_logical_monitor;
|
||||
}
|
||||
|
||||
MetaOutput *
|
||||
meta_monitor_manager_get_outputs (MetaMonitorManager *manager,
|
||||
unsigned int *n_outputs)
|
||||
@ -1339,12 +1354,6 @@ meta_monitor_manager_get_resources (MetaMonitorManager *manager,
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
meta_monitor_manager_get_primary_index (MetaMonitorManager *manager)
|
||||
{
|
||||
return manager->primary_monitor_index;
|
||||
}
|
||||
|
||||
void
|
||||
meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
|
||||
int *width,
|
||||
|
@ -1732,10 +1732,16 @@ meta_screen_get_primary_monitor (MetaScreen *screen)
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
g_return_val_if_fail (META_IS_SCREEN (screen), 0);
|
||||
|
||||
return meta_monitor_manager_get_primary_index (monitor_manager);
|
||||
logical_monitor =
|
||||
meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
|
||||
if (logical_monitor)
|
||||
return logical_monitor->number;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3565,9 +3565,6 @@ 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;
|
||||
|
||||
if (window->fullscreen_monitors[0] != -1)
|
||||
@ -3588,15 +3585,9 @@ meta_window_update_for_monitors_changed (MetaWindow *window)
|
||||
if (!new)
|
||||
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 */
|
||||
if (!new)
|
||||
new = &logical_monitors[primary_monitor_index];
|
||||
new = meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
|
||||
|
||||
if (window->tile_mode != META_TILE_NONE)
|
||||
window->tile_monitor_number = new->number;
|
||||
|
Loading…
Reference in New Issue
Block a user