Add a fallback for unconverted backends

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 all backends
implement the monitor vfuncs. When that is the case, the
fallback should be removed.
This commit is contained in:
Matthias Clasen 2016-04-25 09:07:56 -04:00
parent 9d719b9989
commit b6c4ba0e2a

View File

@ -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);
}