monitor-manager: Add public API to get logical monitor from connector

This adds a function to be used by gnome-shell to get the logical
monitor given a connector name. For now, use the same index integer
method to reference a logical monitor, but this should be revisited by
providing a better API later.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2017-04-06 13:15:45 +08:00
parent 5b4a96e3a3
commit 1caa7f7627
2 changed files with 32 additions and 0 deletions

View File

@ -2909,6 +2909,35 @@ meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager,
return -1;
}
/**
* meta_monitor_manager_get_monitor_for_connector:
* @manager: A #MetaMonitorManager
* @connector: A valid connector name
*
* Returns: The monitor index or -1 if @id isn't valid or the connector
* isn't associated with a logical monitor.
*/
gint
meta_monitor_manager_get_monitor_for_connector (MetaMonitorManager *manager,
const char *connector)
{
GList *l;
for (l = manager->monitors; l; l = l->next)
{
MetaMonitor *monitor = l->data;
if (g_str_equal (connector, meta_monitor_get_connector (monitor)))
{
MetaOutput *main_output = meta_monitor_get_main_output (monitor);
return main_output->crtc->logical_monitor->number;
}
}
return -1;
}
gboolean
meta_monitor_manager_get_is_builtin_display_on (MetaMonitorManager *manager)
{

View File

@ -34,6 +34,9 @@ MetaMonitorManager *meta_monitor_manager_get (void);
gint meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager,
guint id);
gint meta_monitor_manager_get_monitor_for_connector (MetaMonitorManager *manager,
const char *connector);
gboolean meta_monitor_manager_get_is_builtin_display_on (MetaMonitorManager *manager);
#endif /* META_MONITOR_MANAGER_H */