summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-04-25 09:07:56 -0400
committerMatthias Clasen <mclasen@redhat.com>2016-04-25 09:09:21 -0400
commitf672a788f9b3199b0e6456de0293152f00a5697e (patch)
tree8518c52c1d39c28b25668e7e7ac15bb60a06e68f
parenta4a5a4807f16fd31ebbe776e3227342ffa2ff153 (diff)
downloadgtk+-wip/matthiasc/monitor.tar.gz
Add a fallback for unconverted backendswip/matthiasc/monitor
If the monitor vfuncs are not implemented in a display class, fall back to providing a single monitor object representing the entire screen. This is not meant to be 'good enough', it is just to provide some implementation until the last backends implement the monitor vfuncs. When that is the case, the fallback should be removed.
-rw-r--r--gdk/gdkdisplay.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index d932b50fd9..f26dd7e9f8 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -33,6 +33,7 @@
#include "gdkinternals.h"
#include "gdkmarshalers.h"
#include "gdkscreen.h"
+#include "gdkmonitorprivate.h"
#include <math.h>
#include <glib.h>
@@ -2520,9 +2521,38 @@ gdk_display_get_n_monitors (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
+ if (GDK_DISPLAY_GET_CLASS (display)->get_n_monitors == NULL)
+ return 1;
+
return GDK_DISPLAY_GET_CLASS (display)->get_n_monitors (display);
}
+static GdkMonitor *
+get_fallback_monitor (GdkDisplay *display)
+{
+ static GdkMonitor *monitor = NULL;
+ GdkScreen *screen;
+
+ if (monitor == NULL)
+ {
+ g_warning ("%s does not implement the monitor vfuncs", G_OBJECT_TYPE_NAME (display));
+ monitor = gdk_monitor_new (display);
+ gdk_monitor_set_manufacturer (monitor, "fallback");
+ gdk_monitor_set_position (monitor, 0, 0);
+ gdk_monitor_set_scale_factor (monitor, 1);
+ }
+
+ screen = gdk_display_get_default_screen (display);
+ gdk_monitor_set_size (monitor,
+ gdk_screen_get_width (screen),
+ gdk_screen_get_height (screen));
+ gdk_monitor_set_physical_size (monitor,
+ gdk_screen_get_width_mm (screen),
+ gdk_screen_get_height_mm (screen));
+
+ return monitor;
+}
+
/**
* gdk_display_get_monitor:
* @display: a #GdkDisplay
@@ -2540,6 +2570,9 @@ gdk_display_get_monitor (GdkDisplay *display,
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+ if (GDK_DISPLAY_GET_CLASS (display)->get_monitor == NULL)
+ return get_fallback_monitor (display);
+
return GDK_DISPLAY_GET_CLASS (display)->get_monitor (display, monitor_num);
}