[gtk/wip/chergert/quartz4u] macos: copy sorting design from quartz backend
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/quartz4u] macos: copy sorting design from quartz backend
- Date: Tue, 19 May 2020 02:53:19 +0000 (UTC)
commit 0cb6b73598e485a9b2de0a4e22a1dc19b36649cd
Author: Christian Hergert <chergert redhat com>
Date: Mon May 18 19:52:26 2020 -0700
macos: copy sorting design from quartz backend
gdk/macos/GdkMacosWindow.c | 2 -
gdk/macos/gdkmacosdisplay-private.h | 5 +-
gdk/macos/gdkmacosdisplay-translate.c | 5 +-
gdk/macos/gdkmacosdisplay.c | 112 +++++++++++++++++-----------------
gdk/macos/gdkmacospopupsurface.c | 4 ++
gdk/macos/gdkmacossurface.c | 8 +--
gdk/macos/gdkmacostoplevelsurface.c | 4 ++
7 files changed, 68 insertions(+), 72 deletions(-)
---
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index 0ddbd39a55..7c8db444a7 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -300,8 +300,6 @@
inShowOrHide = NO;
[self checkSendEnterNotify];
-
- _gdk_macos_display_surface_raised ([self gdkDisplay], gdk_surface);
}
-(void)hide
diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h
index d731f8dce8..9192bd967e 100644
--- a/gdk/macos/gdkmacosdisplay-private.h
+++ b/gdk/macos/gdkmacosdisplay-private.h
@@ -115,7 +115,6 @@ GdkMacosSurface *_gdk_macos_display_get_surface_at_display_coords (GdkMacosDisp
double y,
int *surface_x,
int *surface_y);
-void _gdk_macos_display_stacking_changed (GdkMacosDisplay *self);
void _gdk_macos_display_reload_monitors (GdkMacosDisplay *self);
void _gdk_macos_display_surface_removed (GdkMacosDisplay *self,
GdkMacosSurface *surface);
@@ -140,9 +139,9 @@ void _gdk_macos_display_surface_resigned_key (GdkMacosDisp
GdkMacosSurface *surface);
void _gdk_macos_display_surface_became_key (GdkMacosDisplay *self,
GdkMacosSurface *surface);
-void _gdk_macos_display_surface_raised (GdkMacosDisplay *self,
- GdkMacosSurface *surface);
int _gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self);
+void _gdk_macos_display_clear_sorting (GdkMacosDisplay *self);
+const GList *_gdk_macos_display_get_surfaces (GdkMacosDisplay *self);
G_END_DECLS
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index 2ff77c6289..9d98046536 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -1097,10 +1097,7 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
[NSApp activateIgnoringOtherApps:YES];
if (![window isKeyWindow])
- {
- [window makeKeyWindow];
- _gdk_macos_display_surface_raised (self, surface);
- }
+ [window makeKeyWindow];
}
switch ((int)event_type)
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 58740aa2d9..dc56e39a84 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -445,10 +445,10 @@ _gdk_macos_display_surface_added (GdkMacosDisplay *self,
g_assert (surface->main.data == surface);
g_assert (surface->frame.data == surface);
- g_queue_push_tail_link (&self->sorted_surfaces, &surface->sorted);
-
if (GDK_IS_TOPLEVEL (surface))
g_queue_push_tail_link (&self->main_surfaces, &surface->main);
+
+ _gdk_macos_display_clear_sorting (self);
}
void
@@ -491,8 +491,6 @@ _gdk_macos_display_surface_became_key (GdkMacosDisplay *self,
event = gdk_focus_event_new (GDK_SURFACE (surface), keyboard, NULL, TRUE);
_gdk_event_queue_append (GDK_DISPLAY (self), event);
- _gdk_macos_display_stacking_changed (self);
-
/* We just became the active window. Unlike X11, Mac OS X does
* not send us motion events while the window does not have focus
* ("is not key"). We send a dummy motion notify event now, so that
@@ -536,7 +534,7 @@ _gdk_macos_display_surface_became_main (GdkMacosDisplay *self,
g_queue_push_head_link (&self->main_surfaces, &surface->main);
- _gdk_macos_display_stacking_changed (self);
+ _gdk_macos_display_clear_sorting (self);
}
void
@@ -566,45 +564,8 @@ _gdk_macos_display_surface_resigned_main (GdkMacosDisplay *self,
}
g_queue_push_tail_link (&self->main_surfaces, &surface->main);
-}
-
-void
-_gdk_macos_display_stacking_changed (GdkMacosDisplay *self)
-{
- GDK_BEGIN_MACOS_ALLOC_POOL;
- NSArray *ordered;
- GQueue sorted = G_QUEUE_INIT;
-
- g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
-
- /* "orderedWindows" gives us the stacking order starting from front-to-back.
- * We maintain this so that we can resolve X,Y coordinates in the topmost
- * surfaces while processing GDK operations from devices, etc.
- */
-
- ordered = [NSApp orderedWindows];
-
- for (id nswindow in ordered)
- {
- GdkMacosSurface *surface;
- GList *link;
-
- if (!GDK_IS_MACOS_WINDOW (nswindow))
- continue;
-
- surface = [(GdkMacosWindow *)nswindow gdkSurface];
-
- link = &surface->sorted;
- link->prev = NULL;
- link->next = NULL;
-
- g_queue_push_tail_link (&sorted, link);
- }
-
- self->sorted_surfaces = sorted;
-
- GDK_END_MACOS_ALLOC_POOL;
+ _gdk_macos_display_clear_sorting (self);
}
static GdkSurface *
@@ -896,11 +857,15 @@ _gdk_macos_display_get_surface_at_coords (GdkMacosDisplay *self,
int *surface_x,
int *surface_y)
{
+ const GList *surfaces;
+
g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), NULL);
g_return_val_if_fail (surface_x != NULL, NULL);
g_return_val_if_fail (surface_y != NULL, NULL);
- for (const GList *iter = self->sorted_surfaces.head; iter; iter = iter->next)
+ surfaces = _gdk_macos_display_get_surfaces (self);
+
+ for (const GList *iter = surfaces; iter; iter = iter->next)
{
GdkSurface *surface = iter->data;
NSWindow *nswindow;
@@ -999,19 +964,6 @@ _gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
return NULL;
}
-void
-_gdk_macos_display_surface_raised (GdkMacosDisplay *self,
- GdkMacosSurface *surface)
-{
- g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
- g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
-
- if (queue_contains (&self->sorted_surfaces, &surface->sorted))
- g_queue_unlink (&self->sorted_surfaces, &surface->sorted);
-
- g_queue_push_head_link (&self->sorted_surfaces, &surface->sorted);
-}
-
int
_gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self)
{
@@ -1022,3 +974,49 @@ _gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self)
return ((GdkDisplayLinkSource *)self->frame_source)->refresh_rate;
}
+
+void
+_gdk_macos_display_clear_sorting (GdkMacosDisplay *self)
+{
+ g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
+
+ self->sorted_surfaces.head = NULL;
+ self->sorted_surfaces.tail = NULL;
+ self->sorted_surfaces.length = 0;
+}
+
+const GList *
+_gdk_macos_display_get_surfaces (GdkMacosDisplay *self)
+{
+ g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), NULL);
+
+ if (self->sorted_surfaces.length == 0)
+ {
+ GDK_BEGIN_MACOS_ALLOC_POOL;
+
+ NSArray *array = [NSApp orderedWindows];
+ GQueue sorted = G_QUEUE_INIT;
+
+ for (id obj in array)
+ {
+ NSWindow *nswindow = (NSWindow *)obj;
+ GdkMacosSurface *surface;
+
+ if (!GDK_IS_MACOS_WINDOW (nswindow))
+ continue;
+
+ surface = [(GdkMacosWindow *)nswindow gdkSurface];
+
+ surface->sorted.prev = NULL;
+ surface->sorted.next = NULL;
+
+ g_queue_push_tail_link (&sorted, &surface->sorted);
+ }
+
+ self->sorted_surfaces = sorted;
+
+ GDK_END_MACOS_ALLOC_POOL;
+ }
+
+ return self->sorted_surfaces.head;
+}
diff --git a/gdk/macos/gdkmacospopupsurface.c b/gdk/macos/gdkmacospopupsurface.c
index bae0fe9bff..84c0183b18 100644
--- a/gdk/macos/gdkmacospopupsurface.c
+++ b/gdk/macos/gdkmacospopupsurface.c
@@ -334,6 +334,8 @@ _gdk_macos_popup_surface_attach_to_parent (GdkMacosPopupSurface *self)
NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (self));
[parent addChildWindow:window ordered:NSWindowAbove];
+
+ _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
@@ -353,5 +355,7 @@ _gdk_macos_popup_surface_detach_from_parent (GdkMacosPopupSurface *self)
NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (self));
[parent removeChildWindow:window];
+
+ _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index f4d4046af3..7211ffee06 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -86,8 +86,6 @@ gdk_macos_surface_hide (GdkSurface *surface)
[self->window hide];
_gdk_surface_clear_update_area (surface);
-
- _gdk_macos_display_stacking_changed (GDK_MACOS_DISPLAY (surface->display));
}
static gint
@@ -719,7 +717,6 @@ _gdk_macos_surface_thaw (GdkMacosSurface *self,
void
_gdk_macos_surface_show (GdkMacosSurface *self)
{
- GdkMacosDisplay *display;
gboolean was_mapped;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
@@ -734,6 +731,8 @@ _gdk_macos_surface_show (GdkMacosSurface *self)
_gdk_surface_update_viewable (GDK_SURFACE (self));
+ _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display));
+
[self->window showAndMakeKey:YES];
[[self->window contentView] setNeedsDisplay:YES];
@@ -742,9 +741,6 @@ _gdk_macos_surface_show (GdkMacosSurface *self)
if (gdk_surface_is_viewable (GDK_SURFACE (self)))
gdk_surface_invalidate_rect (GDK_SURFACE (self), NULL);
}
-
- display = GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display);
- _gdk_macos_display_stacking_changed (display);
}
CGContextRef
diff --git a/gdk/macos/gdkmacostoplevelsurface.c b/gdk/macos/gdkmacostoplevelsurface.c
index 3c9002ca7f..594f1b7aa0 100644
--- a/gdk/macos/gdkmacostoplevelsurface.c
+++ b/gdk/macos/gdkmacostoplevelsurface.c
@@ -455,6 +455,8 @@ _gdk_macos_toplevel_surface_attach_to_parent (GdkMacosToplevelSurface *self)
if (GDK_SURFACE (self)->modal_hint)
[window setLevel:NSModalPanelWindowLevel];
+
+ _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
@@ -476,5 +478,7 @@ _gdk_macos_toplevel_surface_detach_from_parent (GdkMacosToplevelSurface *self)
[parent removeChildWindow:window];
[window setLevel:NSNormalWindowLevel];
+
+ _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]