[gtk+/wip/matthiasc/monitor] Some major reshuffling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/monitor] Some major reshuffling
- Date: Sun, 3 Apr 2016 14:51:29 +0000 (UTC)
commit ab4c086baf9901b78678da1405dc113afd85a300
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Apr 2 19:00:31 2016 -0400
Some major reshuffling
Switch to array-based api in GdkDisplay, add monitor vfuncs in GdkDisplay,
and do away with the monitor vfuncs in GdkScreen.
gdk/gdkdisplay.c | 18 +++-
gdk/gdkdisplay.h | 6 +-
gdk/gdkdisplayprivate.h | 4 +
gdk/gdkmonitor.c | 1 +
gdk/gdkmonitor.h | 1 -
gdk/gdkmonitorprivate.h | 4 +-
gdk/gdkscreen.c | 182 +++++++++++++-------------------------
gdk/wayland/gdkdisplay-wayland.c | 10 ++
gdk/wayland/gdkprivate-wayland.h | 3 +
gdk/wayland/gdkscreen-wayland.c | 138 +++++++++++------------------
10 files changed, 155 insertions(+), 212 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index c3979de..c68579f 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -2482,12 +2482,24 @@ gdk_display_list_seats (GdkDisplay *display)
return g_list_copy (display->seats);
}
-GList *
-gdk_display_list_monitors (GdkDisplay *display)
+GdkMonitor **
+gdk_display_get_monitors (GdkDisplay *display,
+ gint *n_monitors)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+
+ return GDK_DISPLAY_GET_CLASS (display)->get_monitors (display, n_monitors);
+}
+
+GdkMonitor *
+gdk_display_get_primary_monitor (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- return g_list_copy (display->monitors);
+ if (GDK_DISPLAY_GET_CLASS (display)->get_primary_monitor)
+ return GDK_DISPLAY_GET_CLASS (display)->get_primary_monitor (display);
+
+ return NULL;
}
void
diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h
index 270aef7..e0adfa3 100644
--- a/gdk/gdkdisplay.h
+++ b/gdk/gdkdisplay.h
@@ -31,6 +31,7 @@
#include <gdk/gdkevents.h>
#include <gdk/gdkdevicemanager.h>
#include <gdk/gdkseat.h>
+#include <gdk/gdkmonitor.h>
G_BEGIN_DECLS
@@ -179,7 +180,10 @@ GDK_AVAILABLE_IN_3_20
GList * gdk_display_list_seats (GdkDisplay *display);
GDK_AVAILABLE_IN_3_22
-GList * gdk_display_list_monitors (GdkDisplay *display);
+GdkMonitor ** gdk_display_get_monitors (GdkDisplay *display,
+ int *n_monitors);
+GDK_AVAILABLE_IN_3_22
+GdkMonitor * gdk_display_get_primary_monitor (GdkDisplay *display);
G_END_DECLS
diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h
index 3be1988..a058368 100644
--- a/gdk/gdkdisplayprivate.h
+++ b/gdk/gdkdisplayprivate.h
@@ -243,6 +243,10 @@ struct _GdkDisplayClass
GdkSeat * (*get_default_seat) (GdkDisplay *display);
+ GdkMonitor ** (*get_monitors) (GdkDisplay *display,
+ int *n_monitors);
+ GdkMonitor * (*get_primary_monitor) (GdkDisplay *display);
+
/* Signals */
void (*opened) (GdkDisplay *display);
void (*closed) (GdkDisplay *display,
diff --git a/gdk/gdkmonitor.c b/gdk/gdkmonitor.c
index 5a1ef6c..f432790 100644
--- a/gdk/gdkmonitor.c
+++ b/gdk/gdkmonitor.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "gdkmonitorprivate.h"
+#include "gdkdisplay.h"
#include "gdkenumtypes.h"
/*
diff --git a/gdk/gdkmonitor.h b/gdk/gdkmonitor.h
index e1f8e84..1540427 100644
--- a/gdk/gdkmonitor.h
+++ b/gdk/gdkmonitor.h
@@ -28,7 +28,6 @@
#include <gdk/gdkversionmacros.h>
#include <gdk/gdkrectangle.h>
-#include <gdk/gdkdisplay.h>
#include <gdk/gdktypes.h>
G_BEGIN_DECLS
diff --git a/gdk/gdkmonitorprivate.h b/gdk/gdkmonitorprivate.h
index ae5e86d..d0f7e40 100644
--- a/gdk/gdkmonitorprivate.h
+++ b/gdk/gdkmonitorprivate.h
@@ -24,6 +24,8 @@
#include "gdkmonitor.h"
+G_BEGIN_DECLS
+
struct _GdkMonitor {
GObject parent;
@@ -42,8 +44,6 @@ struct _GdkMonitorClass {
GObjectClass parent_class;
};
-G_BEGIN_DECLS
-
GdkMonitor * gdk_monitor_new (GdkDisplay *display);
void gdk_monitor_set_manufacturer (GdkMonitor *monitor,
diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c
index 1927734..30a9471 100644
--- a/gdk/gdkscreen.c
+++ b/gdk/gdkscreen.c
@@ -57,21 +57,6 @@ static void gdk_screen_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
-static gint gdk_screen_real_get_n_monitors (GdkScreen *screen);
-static gint gdk_screen_real_get_primary_monitor (GdkScreen *screen);
-static gint gdk_screen_real_get_monitor_width_mm (GdkScreen *screen,
- gint monitor_num);
-static gint gdk_screen_real_get_monitor_height_mm (GdkScreen *screen,
- gint monitor_num);
-static gchar * gdk_screen_real_get_monitor_plug_name (GdkScreen *screen,
- gint monitor_num);
-static void gdk_screen_real_get_monitor_geometry (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest);
-static void gdk_screen_real_get_monitor_workarea (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest);
-
enum
{
PROP_0,
@@ -100,14 +85,6 @@ gdk_screen_class_init (GdkScreenClass *klass)
object_class->set_property = gdk_screen_set_property;
object_class->get_property = gdk_screen_get_property;
- klass->get_n_monitors = gdk_screen_real_get_n_monitors;
- klass->get_primary_monitor = gdk_screen_real_get_primary_monitor;
- klass->get_monitor_width_mm = gdk_screen_real_get_monitor_width_mm;
- klass->get_monitor_height_mm = gdk_screen_real_get_monitor_height_mm;
- klass->get_monitor_plug_name = gdk_screen_real_get_monitor_plug_name;
- klass->get_monitor_geometry = gdk_screen_real_get_monitor_geometry;
- klass->get_monitor_workarea = gdk_screen_real_get_monitor_workarea;
-
g_object_class_install_property (object_class,
PROP_FONT_OPTIONS,
g_param_spec_pointer ("font-options",
@@ -731,89 +708,16 @@ get_monitor (GdkScreen *screen,
gint n)
{
GdkDisplay *display;
- GdkMonitor *monitor;
- GList *list;
+ GdkMonitor **monitors;
+ gint n_monitors;
display = gdk_screen_get_display (screen);
- list = gdk_display_list_monitors (display);
- monitor = g_list_nth_data (list, n);
- g_list_free (list);
-
- return monitor;
-}
-
-static gint
-gdk_screen_real_get_n_monitors (GdkScreen *screen)
-{
- GdkDisplay *display;
- GList *list;
- gint length;
-
- display = gdk_screen_get_display (screen);
- list = gdk_display_list_monitors (display);
- length = g_list_length (list);
- g_list_free (list);
- return length;
-}
-
-static gint
-gdk_screen_real_get_primary_monitor (GdkScreen *screen)
-{
- /* FIXME */
- return 0;
-}
-
-static gint
-gdk_screen_real_get_monitor_width_mm (GdkScreen *screen,
- gint monitor_num)
-{
- GdkMonitor *monitor;
-
- monitor = get_monitor (screen, monitor_num);
- return gdk_monitor_get_width_mm (monitor);
-}
-
-static gint
-gdk_screen_real_get_monitor_height_mm (GdkScreen *screen,
- gint monitor_num)
-{
- GdkMonitor *monitor;
-
- monitor = get_monitor (screen, monitor_num);
- return gdk_monitor_get_height_mm (monitor);
-}
-
-static gchar *
-gdk_screen_real_get_monitor_plug_name (GdkScreen *screen,
- gint monitor_num)
-{
- GdkMonitor *monitor;
-
- monitor = get_monitor (screen, monitor_num);
- return g_strdup (gdk_monitor_get_model (monitor));
-}
-
-static void
-gdk_screen_real_get_monitor_geometry (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest)
-{
- GdkMonitor *monitor;
-
- monitor = get_monitor (screen, monitor_num);
- gdk_monitor_get_geometry (monitor, dest);
-}
+ monitors = gdk_display_get_monitors (display, &n_monitors);
-static void
-gdk_screen_real_get_monitor_workarea (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest)
-{
- GdkMonitor *monitor;
+ if (0 <= n && n < n_monitors)
+ return monitors[n];
- monitor = get_monitor (screen, monitor_num);
- /* FIXME */
- gdk_monitor_get_geometry (monitor, dest);
+ return NULL;
}
/**
@@ -829,9 +733,15 @@ gdk_screen_real_get_monitor_workarea (GdkScreen *screen,
gint
gdk_screen_get_n_monitors (GdkScreen *screen)
{
+ GdkDisplay *display;
+ int n_monitors;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
- return GDK_SCREEN_GET_CLASS (screen)->get_n_monitors (screen);
+ display = gdk_screen_get_display (screen);
+ gdk_display_get_monitors (display, &n_monitors);
+
+ return n_monitors;
}
/**
@@ -854,9 +764,22 @@ gdk_screen_get_n_monitors (GdkScreen *screen)
gint
gdk_screen_get_primary_monitor (GdkScreen *screen)
{
+ GdkDisplay *display;
+ GdkMonitor **monitors, *primary;
+ int n_monitors, i;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
- return GDK_SCREEN_GET_CLASS (screen)->get_primary_monitor (screen);
+ 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;
+ }
+
+ return 0;
}
/**
@@ -874,11 +797,15 @@ gint
gdk_screen_get_monitor_width_mm (GdkScreen *screen,
gint monitor_num)
{
+ GdkMonitor *monitor;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
- g_return_val_if_fail (monitor_num >= 0, -1);
- g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), -1);
- return GDK_SCREEN_GET_CLASS (screen)->get_monitor_width_mm (screen, monitor_num);
+ monitor = get_monitor (screen, monitor_num);
+
+ g_return_val_if_fail (monitor != NULL, -1);
+
+ return gdk_monitor_get_width_mm (monitor);
}
/**
@@ -896,11 +823,15 @@ gint
gdk_screen_get_monitor_height_mm (GdkScreen *screen,
gint monitor_num)
{
+ GdkMonitor *monitor;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
- g_return_val_if_fail (monitor_num >= 0, -1);
- g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), -1);
- return GDK_SCREEN_GET_CLASS (screen)->get_monitor_height_mm (screen, monitor_num);
+ monitor = get_monitor (screen, monitor_num);
+
+ g_return_val_if_fail (monitor != NULL, -1);
+
+ return gdk_monitor_get_height_mm (monitor);
}
/**
@@ -921,11 +852,15 @@ gchar *
gdk_screen_get_monitor_plug_name (GdkScreen *screen,
gint monitor_num)
{
+ GdkMonitor *monitor;
+
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
- g_return_val_if_fail (monitor_num >= 0, NULL);
- g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), NULL);
- return GDK_SCREEN_GET_CLASS (screen)->get_monitor_plug_name (screen, monitor_num);
+ monitor = get_monitor (screen, monitor_num);
+
+ g_return_val_if_fail (monitor != NULL, NULL);
+
+ return g_strdup (gdk_monitor_get_model (monitor));
}
/**
@@ -953,11 +888,15 @@ gdk_screen_get_monitor_geometry (GdkScreen *screen,
gint monitor_num,
GdkRectangle *dest)
{
+ GdkMonitor *monitor;
+
g_return_if_fail (GDK_IS_SCREEN (screen));
- g_return_if_fail (monitor_num >= 0);
- g_return_if_fail (monitor_num < gdk_screen_get_n_monitors (screen));
- GDK_SCREEN_GET_CLASS(screen)->get_monitor_geometry (screen, monitor_num, dest);
+ monitor = get_monitor (screen, monitor_num);
+
+ g_return_if_fail (monitor != NULL);
+
+ gdk_monitor_get_geometry (monitor, dest);
}
/**
@@ -990,11 +929,16 @@ gdk_screen_get_monitor_workarea (GdkScreen *screen,
gint monitor_num,
GdkRectangle *dest)
{
+ GdkMonitor *monitor;
+
g_return_if_fail (GDK_IS_SCREEN (screen));
- g_return_if_fail (monitor_num >= 0);
- g_return_if_fail (monitor_num < gdk_screen_get_n_monitors (screen));
- GDK_SCREEN_GET_CLASS (screen)->get_monitor_workarea (screen, monitor_num, dest);
+ monitor = get_monitor (screen, monitor_num);
+
+ g_return_if_fail (monitor != NULL);
+
+ /* FIXME */
+ gdk_monitor_get_geometry (monitor, dest);
}
/**
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index ef06394..270738e 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -805,6 +805,14 @@ gdk_wayland_display_pop_error_trap (GdkDisplay *display,
return 0;
}
+static GdkMonitor **
+gdk_wayland_display_get_monitors (GdkDisplay *display,
+ int *n_monitors)
+{
+ return gdk_wayland_screen_get_monitors (GDK_WAYLAND_DISPLAY (display)->screen,
+ n_monitors);
+}
+
static void
gdk_wayland_display_class_init (GdkWaylandDisplayClass *class)
{
@@ -856,6 +864,8 @@ gdk_wayland_display_class_init (GdkWaylandDisplayClass *class)
display_class->utf8_to_string_target = _gdk_wayland_display_utf8_to_string_target;
display_class->make_gl_context_current = gdk_wayland_display_make_gl_context_current;
+
+ display_class->get_monitors = gdk_wayland_display_get_monitors;
}
static void
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index cb2c29a..15e5843 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -272,4 +272,7 @@ EGLSurface gdk_wayland_window_get_dummy_egl_surface (GdkWindow *window,
void gdk_wayland_seat_set_global_cursor (GdkSeat *seat,
GdkCursor *cursor);
+GdkMonitor **gdk_wayland_screen_get_monitors (GdkScreen *screen,
+ int *n_monitors);
+
#endif /* __GDK_PRIVATE_WAYLAND_H__ */
diff --git a/gdk/wayland/gdkscreen-wayland.c b/gdk/wayland/gdkscreen-wayland.c
index 0d839aa..d4297e8 100644
--- a/gdk/wayland/gdkscreen-wayland.c
+++ b/gdk/wayland/gdkscreen-wayland.c
@@ -85,7 +85,6 @@ gdk_wayland_monitor_class_init (GdkWaylandMonitorClass *class)
G_OBJECT_CLASS (class)->finalize = gdk_wayland_monitor_finalize;
}
-
struct _GdkWaylandScreen
{
GdkScreen parent_instance;
@@ -123,35 +122,6 @@ GType _gdk_wayland_screen_get_type (void);
G_DEFINE_TYPE (GdkWaylandScreen, _gdk_wayland_screen, GDK_TYPE_SCREEN)
static void
-free_monitor (gpointer data)
-{
- GdkWaylandMonitor *monitor = data;
-
- if (monitor == NULL)
- return;
-
- g_object_unref (monitor);
-}
-
-static void
-deinit_multihead (GdkScreen *screen)
-{
- GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
-
- g_ptr_array_free (screen_wayland->monitors, TRUE);
-
- screen_wayland->monitors = NULL;
-}
-
-static void
-init_multihead (GdkScreen *screen)
-{
- GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
-
- screen_wayland->monitors = g_ptr_array_new_with_free_func (free_monitor);
-}
-
-static void
gdk_wayland_screen_dispose (GObject *object)
{
GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (object);
@@ -172,7 +142,7 @@ gdk_wayland_screen_finalize (GObject *object)
g_object_unref (screen_wayland->visual);
- deinit_multihead (GDK_SCREEN (object));
+ g_ptr_array_free (screen_wayland->monitors, TRUE);
g_hash_table_destroy (screen_wayland->settings);
@@ -905,7 +875,7 @@ _gdk_wayland_screen_new (GdkDisplay *display)
screen_wayland->visual = gdk_wayland_visual_new (screen);
- init_multihead (screen);
+ screen_wayland->monitors = g_ptr_array_new_with_free_func (g_object_unref);
screen_wayland->root_window =
_gdk_wayland_screen_create_root_window (screen,
@@ -960,18 +930,16 @@ _gdk_wayland_screen_init (GdkWaylandScreen *screen_wayland)
static void
update_screen_size (GdkWaylandScreen *screen_wayland)
{
- GdkDisplay *display = gdk_screen_get_display (GDK_SCREEN (screen_wayland));
gboolean emit_changed = FALSE;
gint width, height;
gint width_mm, height_mm;
- GList *list, *l;
+ int i;
width = height = 0;
width_mm = height_mm = 0;
- list = gdk_display_list_monitors (display);
- for (l = list; l; l = l->next)
+ for (i = 0; i < screen_wayland->monitors->len; i++)
{
- GdkMonitor *monitor = l->data;
+ GdkMonitor *monitor = screen_wayland->monitors->pdata[i];
/* XXX: Largely assuming here that monitor areas
* are contiguous and never overlap.
@@ -989,7 +957,6 @@ update_screen_size (GdkWaylandScreen *screen_wayland)
width = MAX (width, monitor->geometry.x + monitor->geometry.width);
height = MAX (height, monitor->geometry.y + monitor->geometry.height);
}
- g_list_free (list);
if (screen_wayland->width_mm != width_mm ||
screen_wayland->height_mm != height_mm)
@@ -1100,7 +1067,7 @@ output_handle_done (void *data,
{
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)data;
GdkDisplay *display = gdk_monitor_get_display (GDK_MONITOR (monitor));
- GdkWaylandScreen *screen = GDK_WAYLAND_SCREEN (gdk_display_get_default_screen (display));
+ GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (gdk_display_get_default_screen (display));
GDK_NOTE (MISC,
g_message ("handle done output %d", monitor->id));
@@ -1108,11 +1075,12 @@ output_handle_done (void *data,
if (!monitor->added)
{
monitor->added = TRUE;
+ g_ptr_array_add (screen_wayland->monitors, monitor);
gdk_display_add_monitor (display, GDK_MONITOR (monitor));
}
- g_signal_emit_by_name (screen, "monitors-changed");
- update_screen_size (screen);
+ g_signal_emit_by_name (screen_wayland, "monitors-changed");
+ update_screen_size (screen_wayland);
}
static void
@@ -1129,8 +1097,7 @@ output_handle_scale (void *data,
if (GDK_MONITOR (monitor)->geometry.width != 0 && monitor->version < OUTPUT_VERSION_WITH_DONE)
{
- GdkDisplay *display = GDK_MONITOR (monitor)->display;
- GdkWaylandScreen *screen = GDK_WAYLAND_SCREEN (gdk_display_get_default_screen (display));
+ GdkScreen *screen = gdk_display_get_default_screen (GDK_MONITOR (monitor)->display);
g_signal_emit_by_name (screen, "monitors-changed");
}
}
@@ -1157,10 +1124,9 @@ output_handle_mode (void *data,
if (width != 0 && monitor->version < OUTPUT_VERSION_WITH_DONE)
{
- GdkDisplay *display = GDK_MONITOR (monitor)->display;
- GdkWaylandScreen *screen = GDK_WAYLAND_SCREEN (gdk_display_get_default_screen (display));
+ GdkScreen *screen = gdk_display_get_default_screen (GDK_MONITOR (monitor)->display);
g_signal_emit_by_name (screen, "monitors-changed");
- update_screen_size (screen);
+ update_screen_size (GDK_WAYLAND_SCREEN (screen));
}
}
@@ -1190,7 +1156,10 @@ _gdk_wayland_screen_add_output (GdkScreen *screen,
monitor->version = version;
if (monitor->version < OUTPUT_VERSION_WITH_DONE)
- gdk_display_add_monitor (display, GDK_MONITOR (monitor));
+ {
+ g_ptr_array_add (GDK_WAYLAND_SCREEN (screen)->monitors, monitor);
+ gdk_display_add_monitor (display, GDK_MONITOR (monitor));
+ }
wl_output_add_listener (output, &output_listener, monitor);
}
@@ -1199,65 +1168,46 @@ struct wl_output *
_gdk_wayland_screen_get_wl_output (GdkScreen *screen,
gint monitor_num)
{
- GList *list;
- GdkDisplay *display = gdk_screen_get_display (screen);
+ GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
GdkWaylandMonitor *monitor;
- list = gdk_display_list_monitors (display);
- monitor = g_list_nth_data (list, monitor_num);
- g_list_free (list);
+ monitor = screen_wayland->monitors->pdata[monitor_num];
return monitor->output;
}
static GdkWaylandMonitor *
-get_monitor_for_id (GdkScreen *screen,
- guint32 id)
+get_monitor_for_id (GdkWaylandScreen *screen_wayland,
+ guint32 id)
{
- GdkDisplay *display = gdk_screen_get_display (screen);
- GdkWaylandMonitor *monitor;
- GList *list, *l;
+ int i;
- monitor = NULL;
- list = gdk_display_list_monitors (display);
- for (l = list; l; l = l->next)
+ for (i = 0; i < screen_wayland->monitors->len; i++)
{
- GdkWaylandMonitor *m = l->data;
+ GdkWaylandMonitor *monitor = screen_wayland->monitors->pdata[i];
- if (m->id == id)
- {
- monitor = m;
- break;
- }
+ if (monitor->id == id)
+ return monitor;
}
- g_list_free (list);
- return monitor;
+ return NULL;
}
static GdkWaylandMonitor *
-get_monitor_for_output (GdkScreen *screen,
+get_monitor_for_output (GdkWaylandScreen *screen_wayland,
struct wl_output *output)
{
- GdkDisplay *display = gdk_screen_get_display (screen);
- GdkWaylandMonitor *monitor;
- GList *list, *l;
+ int i;
- monitor = NULL;
- list = gdk_display_list_monitors (display);
- for (l = list; l; l = l->next)
+ for (i = 0; i < screen_wayland->monitors->len; i++)
{
- GdkWaylandMonitor *m = l->data;
+ GdkWaylandMonitor *monitor = screen_wayland->monitors->pdata[i];
- if (m->output == output)
- {
- monitor = m;
- break;
- }
+ if (monitor->output == output)
+ return monitor;
}
- g_list_free (list);
- return monitor;
+ return NULL;
}
void
@@ -1268,10 +1218,13 @@ _gdk_wayland_screen_remove_output (GdkScreen *screen,
GdkDisplay *display = gdk_screen_get_display (screen);
GdkWaylandMonitor *monitor;
- monitor = get_monitor_for_id (screen, id);
+ monitor = get_monitor_for_id (screen_wayland, id);
if (monitor != NULL)
{
+ g_object_ref (monitor);
+ g_ptr_array_remove (screen_wayland->monitors, monitor);
gdk_display_remove_monitor (display, GDK_MONITOR (monitor));
+ g_object_unref (monitor);
g_signal_emit_by_name (screen_wayland, "monitors-changed");
update_screen_size (screen_wayland);
}
@@ -1281,9 +1234,10 @@ int
_gdk_wayland_screen_get_output_refresh_rate (GdkScreen *screen,
struct wl_output *output)
{
+ GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
GdkWaylandMonitor *monitor;
- monitor = get_monitor_for_output (screen, output);
+ monitor = get_monitor_for_output (screen_wayland, output);
if (monitor != NULL)
return gdk_monitor_get_refresh_rate (GDK_MONITOR (monitor));
@@ -1294,11 +1248,23 @@ guint32
_gdk_wayland_screen_get_output_scale (GdkScreen *screen,
struct wl_output *output)
{
+ GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
GdkWaylandMonitor *monitor;
- monitor = get_monitor_for_output (screen, output);
+ monitor = get_monitor_for_output (screen_wayland, output);
if (monitor != NULL)
return gdk_monitor_get_scale_factor (GDK_MONITOR (monitor));
return 0;
}
+
+GdkMonitor **
+gdk_wayland_screen_get_monitors (GdkScreen *screen,
+ int *n_monitors)
+{
+ GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
+
+ *n_monitors = screen_wayland->monitors->len;
+
+ return (GdkMonitor **)screen_wayland->monitors->pdata;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]