From 8188cddcf7a4079924923a1d0885c2e5a8d581f3 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 27 Mar 2015 15:48:49 +0100 Subject: [PATCH] backends: Add meta_monitor_manager_get_monitor_at_point() This function returns the monitor_info index corresponding to the given coordinates, or -1 if none is found at that point. The native backend has been changed in places where it could make use of this function. https://bugzilla.gnome.org/show_bug.cgi?id=746896 --- src/backends/meta-monitor-manager-private.h | 4 +++ src/backends/meta-monitor-manager.c | 24 ++++++++++++++++ src/backends/native/meta-backend-native.c | 31 ++------------------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index bbfaf5889..5a6740c90 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -370,6 +370,10 @@ gboolean meta_monitor_manager_get_monitor_matrix (MetaMonitorManager * MetaOutput *output, gfloat matrix[6]); +gint meta_monitor_manager_get_monitor_at_point (MetaMonitorManager *manager, + gfloat x, + gfloat y); + /* Returns true if transform causes width and height to be inverted This is true for the odd transforms in the enum */ static inline gboolean diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 0276ba564..7fa513965 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -1368,3 +1368,27 @@ meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager, return -1; } + +gint +meta_monitor_manager_get_monitor_at_point (MetaMonitorManager *manager, + gfloat x, + gfloat y) +{ + unsigned int i; + + for (i = 0; i < manager->n_monitor_infos; i++) + { + MetaMonitorInfo *monitor = &manager->monitor_infos[i]; + int left, right, top, bottom; + + left = monitor->rect.x; + right = left + monitor->rect.width; + top = monitor->rect.y; + bottom = top + monitor->rect.height; + + if ((x >= left) && (x < right) && (y >= top) && (y < bottom)) + return i; + } + + return -1; +} diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index b820bc800..9f2cb9b19 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -84,31 +84,6 @@ constrain_to_barriers (ClutterInputDevice *device, * */ -static gboolean -check_all_screen_monitors(MetaMonitorInfo *monitors, - unsigned n_monitors, - float x, - float y) -{ - unsigned int i; - - for (i = 0; i < n_monitors; i++) - { - MetaMonitorInfo *monitor = &monitors[i]; - int left, right, top, bottom; - - left = monitor->rect.x; - right = left + monitor->rect.width; - top = monitor->rect.y; - bottom = top + monitor->rect.height; - - if ((x >= left) && (x < right) && (y >= top) && (y < bottom)) - return TRUE; - } - - return FALSE; -} - static void constrain_all_screen_monitors (ClutterInputDevice *device, MetaMonitorInfo *monitors, @@ -162,7 +137,6 @@ pointer_constrain_callback (ClutterInputDevice *device, MetaMonitorManager *monitor_manager; MetaMonitorInfo *monitors; unsigned int n_monitors; - gboolean ret; /* Constrain to barriers */ constrain_to_barriers (device, time, new_x, new_y); @@ -171,8 +145,7 @@ pointer_constrain_callback (ClutterInputDevice *device, monitors = meta_monitor_manager_get_monitor_infos (monitor_manager, &n_monitors); /* if we're moving inside a monitor, we're fine */ - ret = check_all_screen_monitors(monitors, n_monitors, *new_x, *new_y); - if (ret == TRUE) + if (meta_monitor_manager_get_monitor_at_point (monitor_manager, *new_x, *new_y) >= 0) return; /* if we're trying to escape, clamp to the CRTC we're coming from */ @@ -195,7 +168,7 @@ on_monitors_changed (MetaMonitorManager *monitor_manager, monitors = meta_monitor_manager_get_monitor_infos (monitor_manager, &n_monitors); /* if we're inside a monitor, we're fine */ - if (check_all_screen_monitors (monitors, n_monitors, point.x, point.y)) + if (meta_monitor_manager_get_monitor_at_point (monitor_manager, point.x, point.y) >= 0) return; /* warp the pointer to the primary monitor so it isn't lost */