summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-02-25 15:49:50 +0000
committerMatthias Clasen <mclasen@redhat.com>2022-02-25 15:49:50 +0000
commit7d8b3357a5ad94232b98c580a75f14c532c1c17b (patch)
treebfb134bb85af67d72ad233461b9bcd8d7857d943
parente0b98bc7de9c741370daa68c241ecaecf23267c6 (diff)
parentc111e633e9f400f3312174d7446e42888fdf18ab (diff)
downloadgtk+-7d8b3357a5ad94232b98c580a75f14c532c1c17b.tar.gz
Merge branch 'wip/chergert/better-positioning' into 'main'
macos: fix positioning of popover tails See merge request GNOME/gtk!4516
-rw-r--r--gdk/macos/gdkmacosdisplay-wm.c41
-rw-r--r--gdk/macos/gdkmacossurface-private.h1
2 files changed, 39 insertions, 3 deletions
diff --git a/gdk/macos/gdkmacosdisplay-wm.c b/gdk/macos/gdkmacosdisplay-wm.c
index a0dd6dddae..7b508a4a9e 100644
--- a/gdk/macos/gdkmacosdisplay-wm.c
+++ b/gdk/macos/gdkmacosdisplay-wm.c
@@ -24,6 +24,9 @@
#include "gdkmacossurface-private.h"
#include "gdkmacostoplevelsurface-private.h"
+#define WARP_OFFSET_X 15
+#define WARP_OFFSET_Y 15
+
static void
_gdk_macos_display_position_toplevel_with_parent (GdkMacosDisplay *self,
GdkMacosSurface *surface,
@@ -79,6 +82,22 @@ _gdk_macos_display_position_toplevel_with_parent (GdkMacosDisplay *self,
*y = surface_rect.y - surface->shadow_top;
}
+static inline gboolean
+has_surface_at_origin (const GList *surfaces,
+ int x,
+ int y)
+{
+ for (const GList *iter = surfaces; iter; iter = iter->next)
+ {
+ GdkMacosSurface *surface = iter->data;
+
+ if (surface->root_x == x && surface->root_y == y)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
_gdk_macos_display_position_toplevel (GdkMacosDisplay *self,
GdkMacosSurface *surface,
@@ -87,6 +106,7 @@ _gdk_macos_display_position_toplevel (GdkMacosDisplay *self,
{
cairo_rectangle_int_t surface_rect;
GdkRectangle workarea;
+ const GList *surfaces;
GdkMonitor *monitor;
CGPoint mouse;
@@ -109,10 +129,27 @@ _gdk_macos_display_position_toplevel (GdkMacosDisplay *self,
if (surface_rect.y < workarea.y)
surface_rect.y = workarea.y;
- /* TODO: If there is another window at this same position, perhaps we should move it */
-
*x = surface_rect.x - surface->shadow_left;
*y = surface_rect.y - surface->shadow_top;
+
+ /* Try to see if there are any other surfaces at this origin and if so,
+ * adjust until we get something better.
+ */
+ surfaces = _gdk_macos_display_get_surfaces (self);
+ while (has_surface_at_origin (surfaces, *x, *y))
+ {
+ *x += WARP_OFFSET_X;
+ *y += WARP_OFFSET_Y;
+
+ /* If we reached the bottom right, just bail and try the workspace origin */
+ if (*x + surface->shadow_left + WARP_OFFSET_X > workarea.x + workarea.width ||
+ *y + surface->shadow_top + WARP_OFFSET_Y > workarea.y + workarea.height)
+ {
+ *x = workarea.x - surface->shadow_left;
+ *y = workarea.y - surface->shadow_top;
+ return;
+ }
+ }
}
/*<private>
diff --git a/gdk/macos/gdkmacossurface-private.h b/gdk/macos/gdkmacossurface-private.h
index 2abc199698..08947f1ce3 100644
--- a/gdk/macos/gdkmacossurface-private.h
+++ b/gdk/macos/gdkmacossurface-private.h
@@ -116,7 +116,6 @@ void _gdk_macos_surface_resize (GdkMacosSurface
int width,
int height);
void _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self);
-void _gdk_macos_surface_update_position (GdkMacosSurface *self);
void _gdk_macos_surface_show (GdkMacosSurface *self);
void _gdk_macos_surface_publish_timings (GdkMacosSurface *self,
gint64 predicted_presentation_time,