From 7f19db1f7b4b148e6771c97038cd55c8d43e043e Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Fri, 30 Jan 2015 14:54:09 +0100 Subject: [PATCH] monitor-manager: Expose a method to get a monitor from an output This method will be used by gnome-shell to resolve an output ID (exposed from the org.gnome.Mutter.DisplayConfig DBus API) to a logical monitor. https://bugzilla.gnome.org/show_bug.cgi?id=743745 --- src/backends/meta-monitor-manager.c | 30 +++++++++++++++++++++++++++++ src/meta/meta-monitor-manager.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index d955af7fd..0276ba564 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -1338,3 +1338,33 @@ meta_monitor_manager_get_monitor_matrix (MetaMonitorManager *manager, matrix); return TRUE; } + +/** + * meta_monitor_manager_get_output_geometry: + * @manager: A #MetaMonitorManager + * @id: A valid #MetaOutput id + * + * Returns: The monitor index or -1 if @id isn't valid or the output + * isn't associated with a logical monitor. + */ +gint +meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager, + guint id) +{ + MetaOutput *output; + guint i; + + g_return_val_if_fail (META_IS_MONITOR_MANAGER (manager), -1); + g_return_val_if_fail (id < manager->n_outputs, -1); + + output = &manager->outputs[id]; + if (!output || !output->crtc) + return -1; + + for (i = 0; i < manager->n_monitor_infos; i++) + if (meta_rectangle_contains_rect (&manager->monitor_infos[i].rect, + &output->crtc->rect)) + return i; + + return -1; +} diff --git a/src/meta/meta-monitor-manager.h b/src/meta/meta-monitor-manager.h index 84f77fb7d..5a6604c3f 100644 --- a/src/meta/meta-monitor-manager.h +++ b/src/meta/meta-monitor-manager.h @@ -31,4 +31,7 @@ GType meta_monitor_manager_get_type (void); MetaMonitorManager *meta_monitor_manager_get (void); +gint meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager, + guint id); + #endif /* META_MONITOR_MANAGER_H */