From ebd0c81f7e5745d58e11846a695fe5842245c627 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Fri, 14 Jan 2022 19:25:08 +0100 Subject: [PATCH] Move make_transient() to Fl_Posix_System_Driver from Fl_Screen_Driver --- src/Fl_Native_File_Chooser_GTK.cxx | 3 +- src/Fl_Screen_Driver.H | 1 + src/drivers/Posix/Fl_Posix_System_Driver.H | 1 - src/drivers/X11/Fl_X11_Screen_Driver.H | 4 +++ src/drivers/X11/Fl_X11_Screen_Driver.cxx | 40 ++++++++++++++++++++++ src/drivers/X11/Fl_X11_System_Driver.H | 1 - src/drivers/X11/Fl_X11_System_Driver.cxx | 40 ---------------------- 7 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/Fl_Native_File_Chooser_GTK.cxx b/src/Fl_Native_File_Chooser_GTK.cxx index a161da77d..976d6f993 100644 --- a/src/Fl_Native_File_Chooser_GTK.cxx +++ b/src/Fl_Native_File_Chooser_GTK.cxx @@ -29,6 +29,7 @@ #include #include // for dlopen et al #include "drivers/X11/Fl_X11_System_Driver.H" +#include "Fl_Screen_Driver.H" /* --------------------- Type definitions from GLIB and GTK --------------------- */ /* all of this is from the public gnome API, so unlikely to change */ @@ -761,7 +762,7 @@ int Fl_GTK_Native_File_Chooser_Driver::fl_gtk_chooser_wrapper() Fl_Window* firstw = Fl::first_window(); fl_gtk_widget_show_now(gtkw_ptr); // map the GTK window on screen if (firstw) { - ((Fl_Posix_System_Driver*)Fl::system_driver())->make_transient(Fl_Posix_System_Driver::ptr_gtk, gtkw_ptr, firstw); + Fl::screen_driver()->make_transient(Fl_Posix_System_Driver::ptr_gtk, gtkw_ptr, firstw); } gboolean state = fl_gtk_file_chooser_get_show_hidden((GtkFileChooser *)gtkw_ptr); fl_gtk_toggle_button_set_active((GtkToggleButton *)show_hidden_button, state); diff --git a/src/Fl_Screen_Driver.H b/src/Fl_Screen_Driver.H index d6baf775f..e33950b8a 100644 --- a/src/Fl_Screen_Driver.H +++ b/src/Fl_Screen_Driver.H @@ -206,6 +206,7 @@ public: virtual APP_SCALING_CAPABILITY rescalable() { return NO_APP_SCALING; } // supports Fl_Window::default_icons() virtual void default_icons(const Fl_RGB_Image *icons[], int count); + virtual void make_transient(void *, void *, Fl_Window *) {} }; #endif // !FL_SCREEN_DRIVER_H diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index 8206871e6..9d2c0fa23 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -88,7 +88,6 @@ public: virtual void lock_ring(); virtual void unlock_ring(); #endif - virtual void make_transient(void */*ptr_gtk*/, void */*gtk_window*/, Fl_Window *) {} virtual void emulate_modal_dialog() {} }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 6fb8330f5..8a82486fa 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -23,6 +23,7 @@ #ifndef FL_X11_SCREEN_DRIVER_H #define FL_X11_SCREEN_DRIVER_H +#include #include "../../Fl_Screen_Driver.H" @@ -102,6 +103,9 @@ public: // --- compute dimensions of an Fl_Offscreen virtual void offscreen_size(Fl_Offscreen o, int &width, int &height); virtual void default_icons(const Fl_RGB_Image *icons[], int count); +#if HAVE_DLSYM && HAVE_DLFCN_H + virtual void make_transient(void *ptr_gtk, void *gtk_window, Fl_Window *win); +#endif }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index ed8c54dfa..717132d1c 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -1399,3 +1399,43 @@ void Fl_X11_Screen_Driver::desktop_scale_factor() } #endif // USE_XFT + +#if HAVE_DLSYM && HAVE_DLFCN_H +void Fl_X11_Screen_Driver::make_transient(void *ptr_gtk, void *gtkw_window, Fl_Window *win) { + typedef int gboolean; + typedef struct _GdkDrawable GdkWindow; + typedef struct _GtkWidget GtkWidget; + + typedef unsigned long (*XX_gdk_x11_window_get_type)(); + static XX_gdk_x11_window_get_type fl_gdk_x11_window_get_type = NULL; + + typedef gboolean (*XX_g_type_check_instance_is_a)(void *type_instance, unsigned long iface_type); + static XX_g_type_check_instance_is_a fl_g_type_check_instance_is_a = NULL; + + typedef Window (*gdk_to_X11_t)(GdkWindow*); + static gdk_to_X11_t fl_gdk_to_X11 = NULL; + + typedef GdkWindow* (*XX_gtk_widget_get_window)(GtkWidget *); + static XX_gtk_widget_get_window fl_gtk_widget_get_window = NULL; + + if (!fl_gdk_to_X11) { + fl_gdk_to_X11 = (gdk_to_X11_t)dlsym(ptr_gtk, "gdk_x11_drawable_get_xid"); + if (!fl_gdk_to_X11) fl_gdk_to_X11 = (gdk_to_X11_t)dlsym(ptr_gtk, "gdk_x11_window_get_xid"); + if (!fl_gdk_to_X11) return; + fl_gdk_x11_window_get_type = (XX_gdk_x11_window_get_type)dlsym(ptr_gtk, "gdk_x11_window_get_type"); + fl_g_type_check_instance_is_a = (XX_g_type_check_instance_is_a)dlsym(ptr_gtk, "g_type_check_instance_is_a"); + fl_gtk_widget_get_window = (XX_gtk_widget_get_window)dlsym(ptr_gtk, "gtk_widget_get_window"); + if (!fl_gtk_widget_get_window) return; + } + GdkWindow* gdkw = fl_gtk_widget_get_window((GtkWidget*)gtkw_window); + + // Make sure the Dialog is an X11 window because it's not on Wayland. + // Until we find how to make a wayland window transient for an X11 window, + // we make the GTK window transient only when it's X11-based. + if ( (!fl_gdk_x11_window_get_type) || (!fl_g_type_check_instance_is_a) || + fl_g_type_check_instance_is_a(gdkw, fl_gdk_x11_window_get_type()) ) { + Window xw = fl_gdk_to_X11(gdkw); // get the X11 ref of the GTK window + if (xw) XSetTransientForHint(fl_display, xw, fl_xid(win)); // set the GTK window transient for the last FLTK win + } +} +#endif //HAVE_DLSYM && HAVE_DLFCN_H diff --git a/src/drivers/X11/Fl_X11_System_Driver.H b/src/drivers/X11/Fl_X11_System_Driver.H index f95fb6b41..69649bc36 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.H +++ b/src/drivers/X11/Fl_X11_System_Driver.H @@ -64,7 +64,6 @@ public: virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0); virtual void remove_fd(int, int when); virtual void remove_fd(int); - virtual void make_transient(void *ptr_gtk, void *gtk_window, Fl_Window *win); virtual void emulate_modal_dialog(); }; diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 405be9e91..30dfe8bcf 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -619,46 +619,6 @@ void Fl_X11_System_Driver::own_colormap() { } -void Fl_X11_System_Driver::make_transient(void *ptr_gtk, void *gtkw_window, Fl_Window *win) { -#if HAVE_DLSYM && HAVE_DLFCN_H - typedef int gboolean; - typedef struct _GdkDrawable GdkWindow; - typedef struct _GtkWidget GtkWidget; - - typedef unsigned long (*XX_gdk_x11_window_get_type)(); - static XX_gdk_x11_window_get_type fl_gdk_x11_window_get_type = NULL; - - typedef gboolean (*XX_g_type_check_instance_is_a)(void *type_instance, unsigned long iface_type); - static XX_g_type_check_instance_is_a fl_g_type_check_instance_is_a = NULL; - - typedef Window (*gdk_to_X11_t)(GdkWindow*); - static gdk_to_X11_t fl_gdk_to_X11 = NULL; - - typedef GdkWindow* (*XX_gtk_widget_get_window)(GtkWidget *); - static XX_gtk_widget_get_window fl_gtk_widget_get_window = NULL; - - if (!fl_gdk_to_X11) { - fl_gdk_to_X11 = (gdk_to_X11_t)dlsym(ptr_gtk, "gdk_x11_drawable_get_xid"); - if (!fl_gdk_to_X11) fl_gdk_to_X11 = (gdk_to_X11_t)dlsym(ptr_gtk, "gdk_x11_window_get_xid"); - if (!fl_gdk_to_X11) return; - fl_gdk_x11_window_get_type = (XX_gdk_x11_window_get_type)dlsym(ptr_gtk, "gdk_x11_window_get_type"); - fl_g_type_check_instance_is_a = (XX_g_type_check_instance_is_a)dlsym(ptr_gtk, "g_type_check_instance_is_a"); - fl_gtk_widget_get_window = (XX_gtk_widget_get_window)dlsym(ptr_gtk, "gtk_widget_get_window"); - if (!fl_gtk_widget_get_window) return; - } - GdkWindow* gdkw = fl_gtk_widget_get_window((GtkWidget*)gtkw_window); - - // Make sure the Dialog is an X11 window because it's not on Wayland. - // Until we find how to make a wayland window transient for an X11 window, - // we make the GTK window transient only when it's X11-based. - if ( (!fl_gdk_x11_window_get_type) || (!fl_g_type_check_instance_is_a) || - fl_g_type_check_instance_is_a(gdkw, fl_gdk_x11_window_get_type()) ) { - Window xw = fl_gdk_to_X11(gdkw); // get the X11 ref of the GTK window - if (xw) XSetTransientForHint(fl_display, xw, fl_xid(win)); // set the GTK window transient for the last FLTK win - } -#endif //HAVE_DLSYM && HAVE_DLFCN_H -} - void Fl_X11_System_Driver::emulate_modal_dialog() { while (XEventsQueued(fl_display, QueuedAfterReading)) { // emulate modal dialog XEvent xevent;