[gtk+/wip/matthiasc/monitor] Redo display monitor api once more
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/monitor] Redo display monitor api once more
- Date: Tue, 5 Apr 2016 03:36:51 +0000 (UTC)
commit a4929f0d28422c1cacd66214631ab349f4191b39
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Apr 4 23:02:06 2016 -0400
Redo display monitor api once more
Don't return an array.
gdk/gdkdisplay.c | 58 +++++++++++++++++++++++++++++++---------------
gdk/gdkdisplay.h | 14 ++++++-----
gdk/gdkdisplayprivate.h | 5 ++-
gdk/gdkscreen.c | 30 +++++------------------
4 files changed, 57 insertions(+), 50 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index f4288aa..c89049b 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -2504,25 +2504,43 @@ gdk_display_list_seats (GdkDisplay *display)
}
/**
- * gdk_display_get_monitors:
+ * gdk_display_get_n_monitors:
* @display: a #GdkDisplay
- * @n_monitors: (out): Return location for the length of the returned array
*
- * Gets the monitors associated with this display. The array will only be
- * valid until the next emission of the #GdkDisplay::monitor-added or
- * #GdkDisplay::monitor-removed signal.
+ * Gets the number of monitors that belong to @display.
*
- * Returns: (transfer none) (element-type GdkMonitor): an array of #GdkMonitor
- * objects
+ * The returned number is valid until the next emission of the
+ * #GdkDisplay::monitor-added or #GdkDisplay::monitor-removed signal.
+ *
+ * Returns: the number of monitors
* Since: 3.22
*/
-GdkMonitor **
-gdk_display_get_monitors (GdkDisplay *display,
- gint *n_monitors)
+int
+gdk_display_get_n_monitors (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
+
+ return GDK_DISPLAY_GET_CLASS (display)->get_n_monitors (display);
+}
+
+/**
+ * gdk_display_get_monitor:
+ * @display: a #GdkDisplay
+ * @monitor_num: number of the monitor
+ *
+ * Gets a monitor associated with this display.
+ *
+ * Returns: (transfer none): the #GdkMonitor, or %NULL if
+ * @monitor_num is not a valid monitor number
+ * Since: 3.22
+ */
+GdkMonitor *
+gdk_display_get_monitor (GdkDisplay *display,
+ gint monitor_num)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- return GDK_DISPLAY_GET_CLASS (display)->get_monitors (display, n_monitors);
+ return GDK_DISPLAY_GET_CLASS (display)->get_monitor (display, monitor_num);
}
/**
@@ -2568,20 +2586,21 @@ gdk_display_get_monitor_at_point (GdkDisplay *display,
int x,
int y)
{
- GdkMonitor **monitors;
GdkMonitor *nearest;
int nearest_dist = G_MAXINT;
int n_monitors, i;
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- monitors = gdk_display_get_monitors (display, &n_monitors);
+ n_monitors = gdk_display_get_n_monitors (display);
for (i = 0; i < n_monitors; i++)
{
+ GdkMonitor *monitor;
GdkRectangle geometry;
int dist_x, dist_y, dist;
- gdk_monitor_get_geometry (monitors[i], &geometry);
+ monitor = gdk_display_get_monitor (display, i);
+ gdk_monitor_get_geometry (monitor, &geometry);
if (x < geometry.x)
dist_x = geometry.x - x;
@@ -2601,7 +2620,7 @@ gdk_display_get_monitor_at_point (GdkDisplay *display,
if (dist < nearest_dist)
{
nearest_dist = dist;
- nearest = monitors[i];
+ nearest = monitor;
}
if (nearest_dist == 0)
@@ -2628,7 +2647,6 @@ gdk_display_get_monitor_at_window (GdkDisplay *display,
GdkWindow *window)
{
GdkRectangle win;
- GdkMonitor **monitors;
int n_monitors, i;
int area = 0;
GdkMonitor *best = NULL;
@@ -2638,19 +2656,21 @@ gdk_display_get_monitor_at_window (GdkDisplay *display,
gdk_window_get_geometry (window, &win.x, &win.y, &win.width, &win.height);
gdk_window_get_origin (window, &win.x, &win.y);
- monitors = gdk_display_get_monitors (display, &n_monitors);
+ n_monitors = gdk_display_get_n_monitors (display);
for (i = 0; i < n_monitors; i++)
{
+ GdkMonitor *monitor;
GdkRectangle mon, intersect;
int overlap;
- gdk_monitor_get_geometry (monitors[i], &mon);
+ monitor = gdk_display_get_monitor (display, i);
+ gdk_monitor_get_geometry (monitor, &mon);
gdk_rectangle_intersect (&win, &mon, &intersect);
overlap = intersect.width *intersect.height;
if (overlap > area)
{
area = overlap;
- best = monitors[i];
+ best = monitor;
}
}
diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h
index ac50639..197b95f 100644
--- a/gdk/gdkdisplay.h
+++ b/gdk/gdkdisplay.h
@@ -180,17 +180,19 @@ GDK_AVAILABLE_IN_3_20
GList * gdk_display_list_seats (GdkDisplay *display);
GDK_AVAILABLE_IN_3_22
-GdkMonitor ** gdk_display_get_monitors (GdkDisplay *display,
- int *n_monitors);
+int gdk_display_get_n_monitors (GdkDisplay *display);
GDK_AVAILABLE_IN_3_22
-GdkMonitor * gdk_display_get_primary_monitor (GdkDisplay *display);
+GdkMonitor * gdk_display_get_monitor (GdkDisplay *display,
+ int monitor_num);
GDK_AVAILABLE_IN_3_22
-GdkMonitor * gdk_display_get_monitor_at_point (GdkDisplay *display,
+GdkMonitor * gdk_display_get_primary_monitor (GdkDisplay *display);
+GDK_AVAILABLE_IN_3_22
+GdkMonitor * gdk_display_get_monitor_at_point (GdkDisplay *display,
int x,
int y);
GDK_AVAILABLE_IN_3_22
-GdkMonitor * gdk_display_get_monitor_at_window (GdkDisplay *dsplay,
- GdkWindow *window);
+GdkMonitor * gdk_display_get_monitor_at_window (GdkDisplay *dsplay,
+ GdkWindow *window);
G_END_DECLS
diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h
index 859938f..c8bc712 100644
--- a/gdk/gdkdisplayprivate.h
+++ b/gdk/gdkdisplayprivate.h
@@ -242,8 +242,9 @@ struct _GdkDisplayClass
GdkSeat * (*get_default_seat) (GdkDisplay *display);
- GdkMonitor ** (*get_monitors) (GdkDisplay *display,
- int *n_monitors);
+ int (*get_n_monitors) (GdkDisplay *display);
+ GdkMonitor * (*get_monitor) (GdkDisplay *display,
+ int index);
GdkMonitor * (*get_primary_monitor) (GdkDisplay *display);
/* Signals */
diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c
index 7fba30b..85cb93f 100644
--- a/gdk/gdkscreen.c
+++ b/gdk/gdkscreen.c
@@ -198,14 +198,13 @@ static int
get_monitor_num (GdkMonitor *monitor)
{
GdkDisplay *display;
- GdkMonitor **monitors;
int n_monitors, i;
display = gdk_monitor_get_display (monitor);
- monitors = gdk_display_get_monitors (display, &n_monitors);
+ n_monitors = gdk_display_get_n_monitors (display);
for (i = 0; i < n_monitors; i++)
{
- if (monitors[i] == monitor)
+ if (gdk_display_get_monitor (display, i) == monitor)
return i;
}
return -1;
@@ -645,16 +644,9 @@ get_monitor (GdkScreen *screen,
gint n)
{
GdkDisplay *display;
- GdkMonitor **monitors;
- gint n_monitors;
display = gdk_screen_get_display (screen);
- monitors = gdk_display_get_monitors (display, &n_monitors);
-
- if (0 <= n && n < n_monitors)
- return monitors[n];
-
- return NULL;
+ return gdk_display_get_monitor (display, n);
}
/**
@@ -671,14 +663,11 @@ gint
gdk_screen_get_n_monitors (GdkScreen *screen)
{
GdkDisplay *display;
- int n_monitors;
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
display = gdk_screen_get_display (screen);
- gdk_display_get_monitors (display, &n_monitors);
-
- return n_monitors;
+ return gdk_display_get_n_monitors (display);
}
/**
@@ -702,19 +691,14 @@ gint
gdk_screen_get_primary_monitor (GdkScreen *screen)
{
GdkDisplay *display;
- GdkMonitor **monitors, *primary;
- int n_monitors, i;
+ GdkMonitor *primary;
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
display = gdk_screen_get_display (screen);
- monitors = gdk_display_get_monitors (display, &n_monitors);
primary = gdk_display_get_primary_monitor (display);
- for (i = 0; i < n_monitors; i++)
- {
- if (monitors[i] == primary)
- return i;
- }
+ if (primary)
+ return get_monitor_num (primary);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]