From f107c063e79252e3c3eabbcf5615872cae25afa2 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 15 Nov 2022 03:03:49 +0100 Subject: [PATCH] Add conveniece API to set trasient-parent for Proxy Windows On macOS, a transient parant should only be set for a single child window. sibling windows to a single parent cannot be re-stacked. --- libs/gtkmm2ext/gtkmm2ext/window_proxy.h | 2 ++ libs/gtkmm2ext/window_proxy.cc | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libs/gtkmm2ext/gtkmm2ext/window_proxy.h b/libs/gtkmm2ext/gtkmm2ext/window_proxy.h index 38215b9279..19fe0ed08a 100644 --- a/libs/gtkmm2ext/gtkmm2ext/window_proxy.h +++ b/libs/gtkmm2ext/gtkmm2ext/window_proxy.h @@ -62,6 +62,8 @@ public: void drop_window (); void use_window (Gtk::Window&); + void set_transient_for (Gtk::Window&); + virtual Gtk::Window* get (bool create = false) = 0; virtual int set_state (const XMLNode&, int version); diff --git a/libs/gtkmm2ext/window_proxy.cc b/libs/gtkmm2ext/window_proxy.cc index c307b19213..d8d92db69b 100644 --- a/libs/gtkmm2ext/window_proxy.cc +++ b/libs/gtkmm2ext/window_proxy.cc @@ -409,3 +409,26 @@ WindowProxy::set_state_mask (StateMask sm) { _state_mask = sm; } + +void +WindowProxy::set_transient_for (Gtk::Window& win) +{ + /* on macOS set_transient() calls _gdk_quartz_window_attach_to_parent() + * which attaches the windows as child window to the parent. As side-effect + * the child becomes the same window-level as the parent. + * + * This makes it hard to re-order siblings of the parent without explicit call to + * re-order those (gdk_window_restack gdk_window_quartz_restack_toplevel). + * + * macOS has a rich concept of z-axis stacking per application, explict transient parents + * are not required. + * + * https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc + * https://developer.apple.com/documentation/appkit/nswindowlevel?language=objc + */ +#ifndef __APPLE__ + if (_window) { + _window->set_transient_for (win); + } +#endif +}