From ca36537f145f9427598e0e3be1db8388e77df14c Mon Sep 17 00:00:00 2001 From: Fabio Lagalla Date: Wed, 26 Jun 2024 15:53:49 +0200 Subject: [PATCH] gdk: Implement fullscreen on selected monitor on macos The feature was apparently missing, as monitors were always fullscreened at the surface best monitor. Keep using best monitor if the selected monitor is not specified, otherwise move the window to the selected monitor before going fullscreen. --- gdk/macos/gdkmacosdisplay-private.h | 1 + gdk/macos/gdkmacosdisplay-wm.c | 12 +++++++++--- gdk/macos/gdkmacostoplevelsurface.c | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h index 592e2ceff3..a14ba7c983 100644 --- a/gdk/macos/gdkmacosdisplay-private.h +++ b/gdk/macos/gdkmacosdisplay-private.h @@ -176,6 +176,7 @@ void _gdk_macos_display_set_drop (GdkMacosDisp GdkDrop *drop); void _gdk_macos_display_position_surface (GdkMacosDisplay *self, GdkMacosSurface *surface, + GdkMonitor *monitor, int *x, int *y); diff --git a/gdk/macos/gdkmacosdisplay-wm.c b/gdk/macos/gdkmacosdisplay-wm.c index dfe1d86499..5903654386 100644 --- a/gdk/macos/gdkmacosdisplay-wm.c +++ b/gdk/macos/gdkmacosdisplay-wm.c @@ -82,6 +82,7 @@ has_surface_at_origin (const GList *surfaces, static void _gdk_macos_display_position_toplevel (GdkMacosDisplay *self, GdkMacosSurface *surface, + GdkMonitor *selected_monitor, int *x, int *y) { @@ -95,7 +96,11 @@ _gdk_macos_display_position_toplevel (GdkMacosDisplay *self, g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface)); mouse = [NSEvent mouseLocation]; - monitor = _gdk_macos_display_get_monitor_at_display_coords (self, mouse.x, mouse.y); + if (!selected_monitor) + monitor = _gdk_macos_display_get_monitor_at_display_coords (self, mouse.x, mouse.y); + else + monitor = selected_monitor; + gdk_macos_monitor_get_workarea (monitor, &workarea); /* First place at top-left of current monitor */ @@ -104,7 +109,7 @@ _gdk_macos_display_position_toplevel (GdkMacosDisplay *self, surface_rect.x = workarea.x + ((workarea.width - surface_rect.width) / 2); surface_rect.y = workarea.y + ((workarea.height - surface_rect.height) / 2); - _gdk_macos_monitor_clamp (GDK_MACOS_MONITOR (surface->best_monitor), &surface_rect); + _gdk_macos_monitor_clamp (GDK_MACOS_MONITOR (selected_monitor ? selected_monitor : surface->best_monitor), &surface_rect); *x = surface_rect.x; *y = surface_rect.y; @@ -138,6 +143,7 @@ _gdk_macos_display_position_toplevel (GdkMacosDisplay *self, void _gdk_macos_display_position_surface (GdkMacosDisplay *self, GdkMacosSurface *surface, + GdkMonitor *monitor, int *x, int *y) { @@ -151,5 +157,5 @@ _gdk_macos_display_position_surface (GdkMacosDisplay *self, if (transient_for != NULL) _gdk_macos_display_position_toplevel_with_parent (self, surface, GDK_MACOS_SURFACE (transient_for), x, y); else - _gdk_macos_display_position_toplevel (self, surface, x, y); + _gdk_macos_display_position_toplevel (self, surface, monitor, x, y); } diff --git a/gdk/macos/gdkmacostoplevelsurface.c b/gdk/macos/gdkmacostoplevelsurface.c index 6b4916a62c..e454c977af 100644 --- a/gdk/macos/gdkmacostoplevelsurface.c +++ b/gdk/macos/gdkmacostoplevelsurface.c @@ -261,7 +261,30 @@ _gdk_macos_toplevel_surface_present (GdkToplevel *toplevel, if (gdk_toplevel_layout_get_fullscreen (layout, &fullscreen)) { if (fullscreen) - _gdk_macos_toplevel_surface_fullscreen (self); + { + GdkMonitor *fullscreen_monitor = + gdk_toplevel_layout_get_fullscreen_monitor (layout); + + if (fullscreen_monitor) + { + int x = 0, y = 0; + + _gdk_macos_display_position_surface (GDK_MACOS_DISPLAY (display), + GDK_MACOS_SURFACE (self), + fullscreen_monitor, + &x, &y); + + GDK_DEBUG (MISC, "Moving toplevel \"%s\" to %d,%d", + GDK_MACOS_SURFACE (self)->title ? + GDK_MACOS_SURFACE (self)->title : + "untitled", + x, y); + + _gdk_macos_surface_move (GDK_MACOS_SURFACE (self), x, y); + } + + _gdk_macos_toplevel_surface_fullscreen (self); + } else _gdk_macos_toplevel_surface_unfullscreen (self); } @@ -274,6 +297,7 @@ _gdk_macos_toplevel_surface_present (GdkToplevel *toplevel, _gdk_macos_display_position_surface (GDK_MACOS_DISPLAY (display), GDK_MACOS_SURFACE (self), + gdk_toplevel_layout_get_fullscreen_monitor (layout), &x, &y); GDK_DEBUG (MISC, "Placing new toplevel \"%s\" at %d,%d", @@ -657,6 +681,7 @@ _gdk_macos_toplevel_surface_attach_to_parent (GdkMacosToplevelSurface *self) _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display)); _gdk_macos_display_position_surface (GDK_MACOS_DISPLAY (surface->display), GDK_MACOS_SURFACE (surface), + NULL, &x, &y); _gdk_macos_surface_move (GDK_MACOS_SURFACE (surface), x, y); }