[gtk+] quartz: add support for Gtk+4
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] quartz: add support for Gtk+4
- Date: Sat, 1 Apr 2017 20:46:17 +0000 (UTC)
commit 758d26738aff4b719ed0929d5521258dd7e3b7c7
Author: Tom Schoonjans <Tom Schoonjans diamond ac uk>
Date: Mon Feb 27 21:38:46 2017 +0000
quartz: add support for Gtk+4
The addition of GdkMonitor broke the quartz backend. This patch restores
that support by adding a new class GdkQuartzMonitor, and by modifying
the existing classes GdkQuartzDisplay and GdkQuartzScreen where
necessary.
It should be noted that this patch is essentially a refactor as no new
functionality that will impact the user has been added or removed.
https://bugzilla.gnome.org/show_bug.cgi?id=779184
gdk/quartz/Makefile.am | 4 +
gdk/quartz/gdkdisplay-quartz.c | 51 +++++++--
gdk/quartz/gdkdisplay-quartz.h | 235 ++++++++++++++++++++++++++++++++++++++++
gdk/quartz/gdkmonitor-quartz.c | 89 +++++++++++++++
gdk/quartz/gdkmonitor-quartz.h | 44 ++++++++
gdk/quartz/gdkprivate-quartz.h | 67 ------------
gdk/quartz/gdkquartz.h | 1 +
gdk/quartz/gdkquartzmonitor.h | 45 ++++++++
gdk/quartz/gdkscreen-quartz.c | 177 +++++++------------------------
gdk/quartz/gdkscreen-quartz.h | 3 -
10 files changed, 497 insertions(+), 219 deletions(-)
---
diff --git a/gdk/quartz/Makefile.am b/gdk/quartz/Makefile.am
index 43b8eee..66ebbb5 100644
--- a/gdk/quartz/Makefile.am
+++ b/gdk/quartz/Makefile.am
@@ -29,6 +29,7 @@ libgdk_quartz_la_SOURCES = \
gdkdevicemanager-core-quartz.c \
gdkdevicemanager-core-quartz.h \
gdkdisplay-quartz.c \
+ gdkdisplay-quartz.h \
gdkdisplaymanager-quartz.c \
gdkdnd-quartz.c \
gdkdnd-quartz.h \
@@ -38,6 +39,8 @@ libgdk_quartz_la_SOURCES = \
gdkglcontext-quartz.h \
gdkglobals-quartz.c \
gdkkeys-quartz.c \
+ gdkmonitor-quartz.c \
+ gdkmonitor-quartz.h \
gdkprivate-quartz.h \
gdkproperty-quartz.c \
gdkquartz.h \
@@ -60,6 +63,7 @@ libgdkquartzinclude_HEADERS = \
gdkquartzdisplaymanager.h \
gdkquartzdnd.h \
gdkquartzkeys.h \
+ gdkquartzmonitor.h \
gdkquartzscreen.h \
gdkquartzutils.h \
gdkquartzwindow.h
diff --git a/gdk/quartz/gdkdisplay-quartz.c b/gdk/quartz/gdkdisplay-quartz.c
index ebef514..19be436 100644
--- a/gdk/quartz/gdkdisplay-quartz.c
+++ b/gdk/quartz/gdkdisplay-quartz.c
@@ -26,18 +26,11 @@
#include "gdkquartzwindow.h"
#include "gdkquartzdisplay.h"
#include "gdkquartzdevicemanager-core.h"
+#include "gdkscreen.h"
+#include "gdkmonitorprivate.h"
+#include "gdkdisplay-quartz.h"
-struct _GdkQuartzDisplay
-{
- GdkDisplay display;
-};
-
-struct _GdkQuartzDisplayClass
-{
- GdkDisplayClass display_class;
-};
-
static GdkWindow *
gdk_quartz_display_get_default_group (GdkDisplay *display)
{
@@ -187,12 +180,45 @@ gdk_quartz_display_notify_startup_complete (GdkDisplay *display,
/* FIXME: Implement? */
}
+static int
+gdk_quartz_display_get_n_monitors (GdkDisplay *display)
+{
+ GdkQuartzDisplay *quartz_display = GDK_QUARTZ_DISPLAY (display);
+
+ return quartz_display->monitors->len;
+}
+
+
+static GdkMonitor *
+gdk_quartz_display_get_monitor (GdkDisplay *display,
+ int monitor_num)
+{
+ GdkQuartzDisplay *quartz_display = GDK_QUARTZ_DISPLAY (display);
+
+ if (0 <= monitor_num || monitor_num < quartz_display->monitors->len)
+ return (GdkMonitor *)quartz_display->monitors->pdata[monitor_num];
+
+ return NULL;
+}
+
+static GdkMonitor *
+gdk_quartz_display_get_primary_monitor (GdkDisplay *display)
+{
+ GdkQuartzDisplay *quartz_display = GDK_QUARTZ_DISPLAY (display);
+
+ return quartz_display->monitors->pdata[0];
+}
G_DEFINE_TYPE (GdkQuartzDisplay, gdk_quartz_display, GDK_TYPE_DISPLAY)
static void
gdk_quartz_display_init (GdkQuartzDisplay *display)
{
+ GDK_QUARTZ_ALLOC_POOL;
+
+ display->monitors = g_ptr_array_new_with_free_func (g_object_unref);
+
+ GDK_QUARTZ_RELEASE_POOL;
}
static void
@@ -200,6 +226,8 @@ gdk_quartz_display_dispose (GObject *object)
{
GdkQuartzDisplay *display_quartz = GDK_QUARTZ_DISPLAY (object);
+ g_ptr_array_free (display_quartz->monitors, TRUE);
+
G_OBJECT_CLASS (gdk_quartz_display_parent_class)->dispose (object);
}
@@ -256,6 +284,9 @@ gdk_quartz_display_class_init (GdkQuartzDisplayClass *class)
display_class->convert_selection = _gdk_quartz_display_convert_selection;
display_class->text_property_to_utf8_list = _gdk_quartz_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_quartz_display_utf8_to_string_target;
+ display_class->get_n_monitors = gdk_quartz_display_get_n_monitors;
+ display_class->get_monitor = gdk_quartz_display_get_monitor;
+ display_class->get_primary_monitor = gdk_quartz_display_get_primary_monitor;
ProcessSerialNumber psn = { 0, kCurrentProcess };
diff --git a/gdk/quartz/gdkdisplay-quartz.h b/gdk/quartz/gdkdisplay-quartz.h
new file mode 100644
index 0000000..ea02558
--- /dev/null
+++ b/gdk/quartz/gdkdisplay-quartz.h
@@ -0,0 +1,235 @@
+/*
+ * gdkdisplay-quartz.h
+ *
+ * Copyright 2017 Tom Schoonjans
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_QUARTZ_DISPLAY__
+#define __GDK_QUARTZ_DISPLAY__
+
+#include "gdkdisplayprivate.h"
+#include "gdkkeys.h"
+#include "gdkwindow.h"
+#include "gdkinternals.h"
+#include "gdkmain.h"
+
+G_BEGIN_DECLS
+
+
+struct _GdkQuartzDisplay
+{
+ GdkDisplay parent_instance;
+ /*Display *xdisplay;
+ GdkScreen *screen;
+ GList *screens;
+
+ GSource *event_source;
+
+ gint grab_count;
+ */
+ /* Visual infos for creating Windows */
+ /*int window_depth;
+ Visual *window_visual;
+ Colormap window_colormap;
+ */
+ /* Keyboard related information */
+ /*gint xkb_event_type;
+ gboolean use_xkb;
+ */
+ /* Whether we were able to turn on detectable-autorepeat using
+ * XkbSetDetectableAutorepeat. If FALSE, we'll fall back
+ * to checking the next event with XPending().
+ */
+ /*gboolean have_xkb_autorepeat;
+
+ GdkKeymap *keymap;
+ guint keymap_serial;
+
+ gboolean have_xfixes;
+ gint xfixes_event_base;
+
+ gboolean have_xcomposite;
+ gboolean have_xdamage;
+ gint xdamage_event_base;
+
+ gboolean have_randr12;
+ gboolean have_randr13;
+ gboolean have_randr15;
+ gint xrandr_event_base;
+ */
+ /* If the SECURITY extension is in place, whether this client holds
+ * a trusted authorization and so is allowed to make various requests
+ * (grabs, properties etc.) Otherwise always TRUE.
+ */
+ /*gboolean trusted_client;
+ */
+ /* drag and drop information */
+ /*GdkDragContext *current_dest_drag;
+ */
+ /* Mapping to/from virtual atoms */
+ /*GHashTable *atom_from_virtual;
+ GHashTable *atom_to_virtual;
+ */
+ /* Session Management leader window see ICCCM */
+ /*Window leader_window;
+ GdkWindow *leader_gdk_window;
+ gboolean leader_window_title_set;
+ */
+ /* List of functions to go from extension event => X window */
+ /*GSList *event_types;
+ */
+ /* X ID hashtable */
+ /*GHashTable *xid_ht;
+ */
+ /* translation queue */
+ /*GQueue *translate_queue;
+ */
+ /* input GdkWindow list */
+ /*GList *input_windows;
+ */
+ GPtrArray *monitors;
+
+ /* Startup notification */
+ /*gchar *startup_notification_id;
+ */
+ /* Time of most recent user interaction. */
+ /*gulong user_time;
+ */
+ /* Sets of atoms for DND */
+ /*guint base_dnd_atoms_precached : 1;
+ guint xdnd_atoms_precached : 1;
+ guint motif_atoms_precached : 1;
+ guint use_sync : 1;
+
+ guint have_shapes : 1;
+ guint have_input_shapes : 1;
+ gint shape_event_base;
+
+ GSList *error_traps;
+
+ gint wm_moveresize_button;
+ */
+ /* GLX information */
+ /*gint glx_version;
+ gint glx_error_base;
+ gint glx_event_base;
+ */
+ /* Translation between X server time and system-local monotonic time */
+ /*gint64 server_time_query_time;
+ gint64 server_time_offset;
+ */
+ /*guint server_time_is_monotonic_time : 1;
+
+ guint have_glx : 1;
+ */
+ /* GLX extensions we check */
+ /*guint has_glx_swap_interval : 1;
+ guint has_glx_create_context : 1;
+ guint has_glx_texture_from_pixmap : 1;
+ guint has_glx_video_sync : 1;
+ guint has_glx_buffer_age : 1;
+ guint has_glx_sync_control : 1;
+ guint has_glx_multisample : 1;
+ guint has_glx_visual_rating : 1;
+ guint has_glx_create_es2_context : 1;*/
+};
+
+struct _GdkQuartzDisplayClass
+{
+ GdkDisplayClass parent_class;
+};
+
+/* Display methods - events */
+void _gdk_quartz_display_queue_events (GdkDisplay *display);
+gboolean _gdk_quartz_display_has_pending (GdkDisplay *display);
+
+void _gdk_quartz_display_event_data_copy (GdkDisplay *display,
+ const GdkEvent *src,
+ GdkEvent *dst);
+void _gdk_quartz_display_event_data_free (GdkDisplay *display,
+ GdkEvent *event);
+
+/* Display methods - cursor */
+GdkCursor *_gdk_quartz_display_get_cursor_for_type (GdkDisplay *display,
+ GdkCursorType type);
+GdkCursor *_gdk_quartz_display_get_cursor_for_name (GdkDisplay *display,
+ const gchar *name);
+GdkCursor *_gdk_quartz_display_get_cursor_for_surface (GdkDisplay *display,
+ cairo_surface_t *surface,
+ gdouble x,
+ gdouble y);
+gboolean _gdk_quartz_display_supports_cursor_alpha (GdkDisplay *display);
+gboolean _gdk_quartz_display_supports_cursor_color (GdkDisplay *display);
+void _gdk_quartz_display_get_default_cursor_size (GdkDisplay *display,
+ guint *width,
+ guint *height);
+void _gdk_quartz_display_get_maximal_cursor_size (GdkDisplay *display,
+ guint *width,
+ guint *height);
+
+/* Display methods - window */
+void _gdk_quartz_display_before_process_all_updates (GdkDisplay *display);
+void _gdk_quartz_display_after_process_all_updates (GdkDisplay *display);
+void _gdk_quartz_display_create_window_impl (GdkDisplay *display,
+ GdkWindow *window,
+ GdkWindow *real_parent,
+ GdkScreen *screen,
+ GdkEventMask event_mask,
+ GdkWindowAttr *attributes);
+
+/* Display methods - keymap */
+GdkKeymap * _gdk_quartz_display_get_keymap (GdkDisplay *display);
+
+/* Display methods - selection */
+gboolean _gdk_quartz_display_set_selection_owner (GdkDisplay *display,
+ GdkWindow *owner,
+ GdkAtom selection,
+ guint32 time,
+ gboolean send_event);
+GdkWindow * _gdk_quartz_display_get_selection_owner (GdkDisplay *display,
+ GdkAtom selection);
+gint _gdk_quartz_display_get_selection_property (GdkDisplay *display,
+ GdkWindow *requestor,
+ guchar **data,
+ GdkAtom *ret_type,
+ gint *ret_format);
+void _gdk_quartz_display_convert_selection (GdkDisplay *display,
+ GdkWindow *requestor,
+ GdkAtom selection,
+ GdkAtom target,
+ guint32 time);
+gint _gdk_quartz_display_text_property_to_utf8_list (GdkDisplay *display,
+ GdkAtom encoding,
+ gint format,
+ const guchar *text,
+ gint length,
+ gchar ***list);
+gchar * _gdk_quartz_display_utf8_to_string_target (GdkDisplay *displayt,
+ const gchar *str);
+/*
+GdkScreen *_gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
+ Window xrootwin);
+void _gdk_x11_display_error_event (GdkDisplay *display,
+ XErrorEvent *error);
+
+GdkFilterReturn _gdk_wm_protocols_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+*/
+G_END_DECLS
+
+#endif /* __GDK_QUARTZ_DISPLAY__ */
+
diff --git a/gdk/quartz/gdkmonitor-quartz.c b/gdk/quartz/gdkmonitor-quartz.c
new file mode 100644
index 0000000..824d80f
--- /dev/null
+++ b/gdk/quartz/gdkmonitor-quartz.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright © 2017 Tom Schoonjans
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "gdkmonitor-quartz.h"
+#include "gdkscreen-quartz.h"
+
+
+G_DEFINE_TYPE (GdkQuartzMonitor, gdk_quartz_monitor, GDK_TYPE_MONITOR)
+
+static gboolean
+gdk_monitor_has_fullscreen_window (GdkMonitor *monitor)
+{
+ GdkScreen *screen = gdk_display_get_default_screen (monitor->display);
+ GList *toplevels, *l;
+ GdkWindow *window;
+ gboolean has_fullscreen;
+
+ toplevels = gdk_screen_get_toplevel_windows (screen);
+
+ has_fullscreen = FALSE;
+ for (l = toplevels; l; l = l->next)
+ {
+ window = l->data;
+
+ if ((gdk_window_get_state (window) & GDK_WINDOW_STATE_FULLSCREEN) == 0)
+ continue;
+
+ if (gdk_window_get_fullscreen_mode (window) == GDK_FULLSCREEN_ON_ALL_MONITORS ||
+ gdk_display_get_monitor_at_window (monitor->display, window) == monitor)
+ {
+ has_fullscreen = TRUE;
+ break;
+ }
+ }
+
+ g_list_free (toplevels);
+
+ return has_fullscreen;
+}
+
+static void
+gdk_quartz_monitor_get_workarea (GdkMonitor *monitor,
+ GdkRectangle *dest)
+{
+ GdkQuartzScreen *quartz_screen = GDK_QUARTZ_SCREEN(gdk_display_get_default_screen (monitor->display));
+ GdkQuartzMonitor *quartz_monitor = GDK_QUARTZ_MONITOR(monitor);
+
+ GDK_QUARTZ_ALLOC_POOL;
+
+ NSRect rect = [quartz_monitor->nsscreen visibleFrame];
+
+ dest->x = rect.origin.x - quartz_screen->min_x;
+ dest->y = quartz_screen->height - (rect.origin.y + rect.size.height) + quartz_screen->min_y;
+ dest->width = rect.size.width;
+ dest->height = rect.size.height;
+
+ GDK_QUARTZ_RELEASE_POOL;
+}
+
+static void
+gdk_quartz_monitor_init (GdkQuartzMonitor *monitor)
+{
+}
+
+static void
+gdk_quartz_monitor_class_init (GdkQuartzMonitorClass *class)
+{
+ GDK_MONITOR_CLASS (class)->get_workarea = gdk_quartz_monitor_get_workarea;
+}
+
diff --git a/gdk/quartz/gdkmonitor-quartz.h b/gdk/quartz/gdkmonitor-quartz.h
new file mode 100644
index 0000000..e076ed2
--- /dev/null
+++ b/gdk/quartz/gdkmonitor-quartz.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2017 Tom Schoonjans
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_QUARTZ_MONITOR_PRIVATE_H__
+#define __GDK_QUARTZ_MONITOR_PRIVATE_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "gdkmonitorprivate.h"
+
+#include "gdkquartzmonitor.h"
+#include "gdkprivate-quartz.h"
+
+struct _GdkQuartzMonitor
+{
+ GdkMonitor parent;
+
+ //guint add : 1;
+ //guint remove : 1;
+ NSScreen *nsscreen;
+ int index;
+};
+
+struct _GdkQuartzMonitorClass {
+ GdkMonitorClass parent_class;
+};
+
+#endif
+
diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h
index 576cac9..b6a6999 100644
--- a/gdk/quartz/gdkprivate-quartz.h
+++ b/gdk/quartz/gdkprivate-quartz.h
@@ -88,73 +88,6 @@ GdkDragContext * _gdk_quartz_window_drag_begin (GdkWindow *window,
GdkDisplay * _gdk_quartz_display_open (const gchar *name);
-/* Display methods - events */
-void _gdk_quartz_display_queue_events (GdkDisplay *display);
-gboolean _gdk_quartz_display_has_pending (GdkDisplay *display);
-
-void _gdk_quartz_display_event_data_copy (GdkDisplay *display,
- const GdkEvent *src,
- GdkEvent *dst);
-void _gdk_quartz_display_event_data_free (GdkDisplay *display,
- GdkEvent *event);
-
-/* Display methods - cursor */
-GdkCursor *_gdk_quartz_display_get_cursor_for_type (GdkDisplay *display,
- GdkCursorType type);
-GdkCursor *_gdk_quartz_display_get_cursor_for_name (GdkDisplay *display,
- const gchar *name);
-GdkCursor *_gdk_quartz_display_get_cursor_for_surface (GdkDisplay *display,
- cairo_surface_t *surface,
- gdouble x,
- gdouble y);
-gboolean _gdk_quartz_display_supports_cursor_alpha (GdkDisplay *display);
-gboolean _gdk_quartz_display_supports_cursor_color (GdkDisplay *display);
-void _gdk_quartz_display_get_default_cursor_size (GdkDisplay *display,
- guint *width,
- guint *height);
-void _gdk_quartz_display_get_maximal_cursor_size (GdkDisplay *display,
- guint *width,
- guint *height);
-
-/* Display methods - window */
-void _gdk_quartz_display_before_process_all_updates (GdkDisplay *display);
-void _gdk_quartz_display_after_process_all_updates (GdkDisplay *display);
-void _gdk_quartz_display_create_window_impl (GdkDisplay *display,
- GdkWindow *window,
- GdkWindow *real_parent,
- GdkScreen *screen,
- GdkEventMask event_mask,
- GdkWindowAttr *attributes);
-
-/* Display methods - keymap */
-GdkKeymap * _gdk_quartz_display_get_keymap (GdkDisplay *display);
-
-/* Display methods - selection */
-gboolean _gdk_quartz_display_set_selection_owner (GdkDisplay *display,
- GdkWindow *owner,
- GdkAtom selection,
- guint32 time,
- gboolean send_event);
-GdkWindow * _gdk_quartz_display_get_selection_owner (GdkDisplay *display,
- GdkAtom selection);
-gint _gdk_quartz_display_get_selection_property (GdkDisplay *display,
- GdkWindow *requestor,
- guchar **data,
- GdkAtom *ret_type,
- gint *ret_format);
-void _gdk_quartz_display_convert_selection (GdkDisplay *display,
- GdkWindow *requestor,
- GdkAtom selection,
- GdkAtom target,
- guint32 time);
-gint _gdk_quartz_display_text_property_to_utf8_list (GdkDisplay *display,
- GdkAtom encoding,
- gint format,
- const guchar *text,
- gint length,
- gchar ***list);
-gchar * _gdk_quartz_display_utf8_to_string_target (GdkDisplay *displayt,
- const gchar *str);
/* Screen */
GdkScreen *_gdk_quartz_screen_new (void);
diff --git a/gdk/quartz/gdkquartz.h b/gdk/quartz/gdkquartz.h
index 4ef3bd7..2b2daa9 100644
--- a/gdk/quartz/gdkquartz.h
+++ b/gdk/quartz/gdkquartz.h
@@ -75,6 +75,7 @@ G_END_DECLS
#include <gdk/quartz/gdkquartzdisplaymanager.h>
#include <gdk/quartz/gdkquartzdnd.h>
#include <gdk/quartz/gdkquartzkeys.h>
+#include <gdk/quartz/gdkquartzmonitor.h>
#include <gdk/quartz/gdkquartzscreen.h>
#include <gdk/quartz/gdkquartzutils.h>
#include <gdk/quartz/gdkquartzwindow.h>
diff --git a/gdk/quartz/gdkquartzmonitor.h b/gdk/quartz/gdkquartzmonitor.h
new file mode 100644
index 0000000..d8fe957
--- /dev/null
+++ b/gdk/quartz/gdkquartzmonitor.h
@@ -0,0 +1,45 @@
+/*
+ * gdkquartzmonitor.h
+ *
+ * Copyright 2017 Tom Schoonjans
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_QUARTZ_MONITOR_H__
+#define __GDK_QUARTZ_MONITOR_H__
+
+#if !defined (__GDKQUARTZ_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdkquartz.h> can be included directly."
+#endif
+
+#include <gdk/gdkmonitor.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_QUARTZ_MONITOR (gdk_quartz_monitor_get_type ())
+#define GDK_QUARTZ_MONITOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_QUARTZ_MONITOR,
GdkQuartzMonitor))
+#define GDK_IS_QUARTZ_MONITOR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_QUARTZ_MONITOR))
+
+typedef struct _GdkQuartzMonitor GdkQuartzMonitor;
+typedef struct _GdkQuartzMonitorClass GdkQuartzMonitorClass;
+
+GDK_AVAILABLE_IN_3_90
+GType gdk_quartz_monitor_get_type (void) G_GNUC_CONST;
+
+
+G_END_DECLS
+
+#endif /* __GDK_QUARTZ_MONITOR_H__ */
+
diff --git a/gdk/quartz/gdkscreen-quartz.c b/gdk/quartz/gdkscreen-quartz.c
index 05add3d..4f5713d 100644
--- a/gdk/quartz/gdkscreen-quartz.c
+++ b/gdk/quartz/gdkscreen-quartz.c
@@ -22,6 +22,8 @@
#include <gdk/gdk.h>
#include "gdkprivate-quartz.h"
+#include "gdkdisplay-quartz.h"
+#include "gdkmonitor-quartz.h"
/* A couple of notes about this file are in order. In GDK, a
@@ -66,6 +68,8 @@ static void display_reconfiguration_callback (CGDirectDisplayID displ
CGDisplayChangeSummaryFlags flags,
void *userInfo);
+static gint get_mm_from_pixels (NSScreen *screen, int pixels);
+
G_DEFINE_TYPE (GdkQuartzScreen, gdk_quartz_screen, GDK_TYPE_SCREEN);
static void
@@ -104,20 +108,17 @@ gdk_quartz_screen_dispose (GObject *object)
}
static void
-gdk_quartz_screen_screen_rects_free (GdkQuartzScreen *screen)
-{
- screen->n_screens = 0;
- g_clear_pointer (&screen->screen_rects, g_free);
-}
-
-static void
gdk_quartz_screen_finalize (GObject *object)
{
GdkQuartzScreen *screen = GDK_QUARTZ_SCREEN (object);
- gdk_quartz_screen_screen_rects_free (screen);
+ G_OBJECT_CLASS (gdk_quartz_screen_parent_class)->finalize (object);
}
+/* Protocol to build cleanly for OSX < 10.7 */
+@protocol ScaleFactor
+- (CGFloat) backingScaleFactor;
+@end
static void
gdk_quartz_screen_calculate_layout (GdkQuartzScreen *screen)
@@ -125,10 +126,13 @@ gdk_quartz_screen_calculate_layout (GdkQuartzScreen *screen)
NSArray *array;
int i;
int max_x, max_y;
+ GdkDisplay *display = gdk_screen_get_display (GDK_SCREEN (screen));
+ GdkQuartzDisplay *display_quartz = GDK_QUARTZ_DISPLAY (display);
- GDK_QUARTZ_ALLOC_POOL;
+ g_ptr_array_free (display_quartz->monitors, TRUE);
+ display_quartz->monitors = g_ptr_array_new_with_free_func (g_object_unref);
- gdk_quartz_screen_screen_rects_free (screen);
+ GDK_QUARTZ_ALLOC_POOL;
array = [NSScreen screens];
@@ -144,6 +148,13 @@ gdk_quartz_screen_calculate_layout (GdkQuartzScreen *screen)
*/
for (i = 0; i < [array count]; i++)
{
+ GdkQuartzMonitor *monitor = g_object_new (GDK_TYPE_QUARTZ_MONITOR,
+ "display", display,
+ NULL);
+ g_ptr_array_add (display_quartz->monitors, monitor);
+ monitor->nsscreen = [array objectAtIndex:i];
+ monitor->index = i;
+
NSRect rect = [[array objectAtIndex:i] frame];
screen->min_x = MIN (screen->min_x, rect.origin.x);
@@ -156,22 +167,31 @@ gdk_quartz_screen_calculate_layout (GdkQuartzScreen *screen)
screen->width = max_x - screen->min_x;
screen->height = max_y - screen->min_y;
- screen->n_screens = [array count];
- screen->screen_rects = g_new0 (GdkRectangle, screen->n_screens);
-
- for (i = 0; i < screen->n_screens; i++)
+ for (i = 0; i < [array count] ; i++)
{
NSScreen *nsscreen;
NSRect rect;
+ GdkMonitor *monitor;
+ monitor = GDK_MONITOR(display_quartz->monitors->pdata[i]);
nsscreen = [array objectAtIndex:i];
rect = [nsscreen frame];
- screen->screen_rects[i].x = rect.origin.x - screen->min_x;
- screen->screen_rects[i].y
+ monitor->geometry.x = rect.origin.x - screen->min_x;
+ monitor->geometry.y
= screen->height - (rect.origin.y + rect.size.height) + screen->min_y;
- screen->screen_rects[i].width = rect.size.width;
- screen->screen_rects[i].height = rect.size.height;
+ monitor->geometry.width = rect.size.width;
+ monitor->geometry.height = rect.size.height;
+ if (gdk_quartz_osx_version() >= GDK_OSX_LION)
+ monitor->scale_factor = [(id <ScaleFactor>) nsscreen backingScaleFactor];
+ else
+ monitor->scale_factor = 1;
+ monitor->width_mm = get_mm_from_pixels(nsscreen, monitor->geometry.width);
+ monitor->height_mm = get_mm_from_pixels(nsscreen, monitor->geometry.height);
+ monitor->refresh_rate = 0; // unknown
+ monitor->manufacturer = NULL; // unknown
+ monitor->model = NULL; // unknown
+ monitor->subpixel_layout = GDK_SUBPIXEL_LAYOUT_UNKNOWN; // unknown
}
GDK_QUARTZ_RELEASE_POOL;
@@ -298,119 +318,6 @@ get_mm_from_pixels (NSScreen *screen, int pixels)
return (pixels / dpi) * 25.4;
}
-static NSScreen *
-get_nsscreen_for_monitor (gint monitor_num)
-{
- NSArray *array;
- NSScreen *screen;
-
- GDK_QUARTZ_ALLOC_POOL;
-
- array = [NSScreen screens];
- screen = [array objectAtIndex:monitor_num];
-
- GDK_QUARTZ_RELEASE_POOL;
-
- return screen;
-}
-
-static gint
-gdk_quartz_screen_get_n_monitors (GdkScreen *screen)
-{
- return GDK_QUARTZ_SCREEN (screen)->n_screens;
-}
-
-static gint
-gdk_quartz_screen_get_primary_monitor (GdkScreen *screen)
-{
- return 0;
-}
-
-static gint
-gdk_quartz_screen_get_monitor_width_mm (GdkScreen *screen,
- gint monitor_num)
-{
- return get_mm_from_pixels (get_nsscreen_for_monitor (monitor_num),
- GDK_QUARTZ_SCREEN (screen)->screen_rects[monitor_num].width);
-}
-
-static gint
-gdk_quartz_screen_get_monitor_height_mm (GdkScreen *screen,
- gint monitor_num)
-{
- return get_mm_from_pixels (get_nsscreen_for_monitor (monitor_num),
- GDK_QUARTZ_SCREEN (screen)->screen_rects[monitor_num].height);
-}
-
-static gchar *
-gdk_quartz_screen_get_monitor_plug_name (GdkScreen *screen,
- gint monitor_num)
-{
- /* FIXME: Is there some useful name we could use here? */
- return NULL;
-}
-
-static void
-gdk_quartz_screen_get_monitor_geometry (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest)
-{
- *dest = GDK_QUARTZ_SCREEN (screen)->screen_rects[monitor_num];
-}
-
-static void
-gdk_quartz_screen_get_monitor_workarea (GdkScreen *screen,
- gint monitor_num,
- GdkRectangle *dest)
-{
- GdkQuartzScreen *quartz_screen = GDK_QUARTZ_SCREEN (screen);
- NSArray *array;
- NSScreen *nsscreen;
- NSRect rect;
-
- GDK_QUARTZ_ALLOC_POOL;
-
- array = [NSScreen screens];
- nsscreen = [array objectAtIndex:monitor_num];
- rect = [nsscreen visibleFrame];
-
- dest->x = rect.origin.x - quartz_screen->min_x;
- dest->y = quartz_screen->height - (rect.origin.y + rect.size.height) + quartz_screen->min_y;
- dest->width = rect.size.width;
- dest->height = rect.size.height;
-
- GDK_QUARTZ_RELEASE_POOL;
-}
-
-/* Protocol to build cleanly for OSX < 10.7 */
-@protocol ScaleFactor
-- (CGFloat) backingScaleFactor;
-@end
-
-gint
-_gdk_quartz_screen_get_monitor_scale_factor (GdkScreen *screen,
- gint monitor_num)
-{
- GdkQuartzScreen *quartz_screen;
- NSArray *array;
- NSScreen *nsscreen;
- gint scale_factor = 1;
-
- quartz_screen = GDK_QUARTZ_SCREEN (screen);
-
- GDK_QUARTZ_ALLOC_POOL;
-
- array = [NSScreen screens];
- nsscreen = [array objectAtIndex:monitor_num];
-
- if (gdk_quartz_osx_version() >= GDK_OSX_LION)
- scale_factor = [(id <ScaleFactor>) nsscreen backingScaleFactor];
-
- GDK_QUARTZ_RELEASE_POOL;
-
- return scale_factor;
-}
-
static void
gdk_quartz_screen_class_init (GdkQuartzScreenClass *klass)
{
@@ -422,13 +329,5 @@ gdk_quartz_screen_class_init (GdkQuartzScreenClass *klass)
screen_class->get_display = gdk_quartz_screen_get_display;
screen_class->get_root_window = gdk_quartz_screen_get_root_window;
- screen_class->get_n_monitors = gdk_quartz_screen_get_n_monitors;
- screen_class->get_primary_monitor = gdk_quartz_screen_get_primary_monitor;
- screen_class->get_monitor_width_mm = gdk_quartz_screen_get_monitor_width_mm;
- screen_class->get_monitor_height_mm = gdk_quartz_screen_get_monitor_height_mm;
- screen_class->get_monitor_plug_name = gdk_quartz_screen_get_monitor_plug_name;
- screen_class->get_monitor_geometry = gdk_quartz_screen_get_monitor_geometry;
- screen_class->get_monitor_workarea = gdk_quartz_screen_get_monitor_workarea;
screen_class->get_setting = _gdk_quartz_screen_get_setting;
- screen_class->get_monitor_scale_factor = _gdk_quartz_screen_get_monitor_scale_factor;
}
diff --git a/gdk/quartz/gdkscreen-quartz.h b/gdk/quartz/gdkscreen-quartz.h
index fb4e4b2..5a1cfa3 100644
--- a/gdk/quartz/gdkscreen-quartz.h
+++ b/gdk/quartz/gdkscreen-quartz.h
@@ -36,9 +36,6 @@ struct _GdkQuartzScreen
gint width;
gint height;
- int n_screens;
- GdkRectangle *screen_rects;
-
guint screen_changed_id;
guint emit_monitors_changed : 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]