[gtk+/wip/otte/gtk4: 2/127] display: Don't return NULL in get_primary_monitor()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/gtk4: 2/127] display: Don't return NULL in get_primary_monitor()
- Date: Sat, 8 Oct 2016 03:32:54 +0000 (UTC)
commit 0170c31022c460c0eef88c8461736a47baf8979e
Author: Benjamin Otte <otte redhat com>
Date: Sat Sep 3 18:33:30 2016 +0200
display: Don't return NULL in get_primary_monitor()
Nobody ever does a NULL check there so all that causes is crashes. So
we better return a non-primary monitor than NULL.
Fixes gdk-wayland always returning NULL.
gdk/gdkdisplay.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index ed0e65f..5d49aad 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -143,6 +143,12 @@ gdk_display_real_get_default_seat (GdkDisplay *display)
return display->seats->data;
}
+static GdkMonitor *
+gdk_display_real_get_primary_monitor (GdkDisplay *display)
+{
+ return gdk_display_get_monitor (display, 0);
+}
+
static void
gdk_display_class_init (GdkDisplayClass *class)
{
@@ -160,6 +166,8 @@ gdk_display_class_init (GdkDisplayClass *class)
class->event_data_free = gdk_display_real_event_data_free;
class->get_default_seat = gdk_display_real_get_default_seat;
+ class->get_primary_monitor = gdk_display_real_get_primary_monitor;
+
/**
* GdkDisplay::opened:
* @display: the object on which the signal is emitted
@@ -2597,8 +2605,13 @@ gdk_display_get_monitor (GdkDisplay *display,
* manager to place the windows, specialized desktop applications
* such as panels should place themselves on the primary monitor.
*
- * Returns: (nullable) (transfer none): the primary monitor, or %NULL if no primary
- * monitor is configured by the user
+ * If no monitor is the designated primary monitor, any monitor
+ * (usually the first) may be returned. To make sure there is a dedicated
+ * primary monitor, use gdk_monitor_is_primary() on the returned monitor.
+ *
+ * Returns: (transfer none): the primary monitor, or any monitor if no
+ * primary monitor is configured by the user
+ *
* Since: 3.22
*/
GdkMonitor *
@@ -2606,10 +2619,7 @@ gdk_display_get_primary_monitor (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- if (GDK_DISPLAY_GET_CLASS (display)->get_primary_monitor)
- return GDK_DISPLAY_GET_CLASS (display)->get_primary_monitor (display);
-
- return NULL;
+ return GDK_DISPLAY_GET_CLASS (display)->get_primary_monitor (display);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]