From fcdc2f0e102497313232cc7c0a570cc4c524a02b Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 30 Aug 2022 12:58:57 +0200 Subject: [PATCH] Attempt to improve fl_disable_wayland(). --- FL/platform.H | 1 + FL/wayland.H | 4 ---- src/Fl.cxx | 9 +++++++++ src/Fl_System_Driver.H | 1 + src/drivers/Wayland/Fl_Wayland_System_Driver.H | 1 + .../Wayland/Fl_Wayland_System_Driver.cxx | 18 ++++++++++++++++++ .../Wayland/fl_wayland_platform_init.cxx | 12 ------------ 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/FL/platform.H b/FL/platform.H index 834a32392..81d5a737a 100644 --- a/FL/platform.H +++ b/FL/platform.H @@ -76,5 +76,6 @@ extern FL_EXPORT void fl_close_display(); extern FL_EXPORT Window fl_window; extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b); extern FL_EXPORT void fl_open_callback(void (*)(const char *)); +extern FL_EXPORT void fl_disable_wayland(); #endif // !FL_PLATFORM_H diff --git a/FL/wayland.H b/FL/wayland.H index 66b633182..2f88ce2e9 100644 --- a/FL/wayland.H +++ b/FL/wayland.H @@ -39,10 +39,6 @@ extern FL_EXPORT cairo_t *fl_wl_cairo(); typedef void *EGLContext; /** Returns the EGLContext corresponding to the given GLContext */ extern FL_EXPORT EGLContext fl_wl_glcontext(GLContext rc); -/** Prevent the FLTK library from using its wayland backend. - Call this early in your main(), before fl_open_display() runs. */ -extern FL_EXPORT void fl_disable_wayland(); - #ifndef FL_DOXYGEN diff --git a/src/Fl.cxx b/src/Fl.cxx index 7b7cb2b7e..3ba27a703 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -2015,6 +2015,15 @@ void fl_close_display() Fl::screen_driver()->close_display(); } +/** Prevent the FLTK library from using its wayland backend. + Call this early in your main(), before fl_open_display() runs. + This has no effect on non-Wayland platforms. + */ +void fl_disable_wayland() +{ + Fl::system_driver()->disable_wayland(); +} + FL_EXPORT Window fl_xid_(const Fl_Window *w) { Fl_X *temp = Fl_X::i(w); return temp ? (Window)temp->xid : 0; diff --git a/src/Fl_System_Driver.H b/src/Fl_System_Driver.H index 0abab55df..15d3d89e5 100644 --- a/src/Fl_System_Driver.H +++ b/src/Fl_System_Driver.H @@ -255,6 +255,7 @@ public: virtual void unlock_ring() {} virtual double wait(double); // must override virtual int ready() { return 0; } // must override + virtual void disable_wayland() {} }; #endif // FL_SYSTEM_DRIVER_H diff --git a/src/drivers/Wayland/Fl_Wayland_System_Driver.H b/src/drivers/Wayland/Fl_Wayland_System_Driver.H index e5203581e..75043cd04 100644 --- a/src/drivers/Wayland/Fl_Wayland_System_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_System_Driver.H @@ -26,6 +26,7 @@ public: int event_key(int k); int get_key(int k); virtual void *control_maximize_button(void *data); + virtual void disable_wayland(); }; #endif /* FL_WAYLAND_SYSTEM_DRIVER_H */ diff --git a/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx index 4b26a17ea..7c3cf9aa8 100644 --- a/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx @@ -88,3 +88,21 @@ void *Fl_Wayland_System_Driver::control_maximize_button(void *data) { return NULL; } } + + +void Fl_Wayland_System_Driver::disable_wayland() { + if (fl_wl_display()) { + fprintf(stderr, "Error: fl_disable_wayland() cannot be called " + "after the Wayland display was opened\n"); + exit(1); + } + + if (Fl_Wayland_Screen_Driver::wl_display) { + wl_display_disconnect(Fl_Wayland_Screen_Driver::wl_display); + Fl_Wayland_Screen_Driver::wl_display = NULL; + delete Fl_Screen_Driver::system_driver; + Fl_Screen_Driver::system_driver = NULL; + } + Fl_Wayland_Screen_Driver::wld_disabled = true; + Fl::system_driver(); +} diff --git a/src/drivers/Wayland/fl_wayland_platform_init.cxx b/src/drivers/Wayland/fl_wayland_platform_init.cxx index 8e4f949f7..ffdc13a69 100644 --- a/src/drivers/Wayland/fl_wayland_platform_init.cxx +++ b/src/drivers/Wayland/fl_wayland_platform_init.cxx @@ -35,18 +35,6 @@ #include -void fl_disable_wayland() { - if (Fl_Wayland_Screen_Driver::wl_display) { - wl_display_disconnect(Fl_Wayland_Screen_Driver::wl_display); - Fl_Wayland_Screen_Driver::wl_display = NULL; - delete Fl_Screen_Driver::system_driver; - Fl_Screen_Driver::system_driver = NULL; - } - Fl_Wayland_Screen_Driver::wld_disabled = true; - Fl::system_driver(); -} - - Fl_System_Driver *Fl_System_Driver::newSystemDriver() { const char *backend = ::getenv("FLTK_BACKEND"); const char *xdgrt = ::getenv("XDG_RUNTIME_DIR");