FLTK logo

[master] fcdc2f0 - Attempt to improve fl_disable_wayland().

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] fcdc2f0 - Attempt to improve fl_disable_wayland(). "ManoloFLTK" Aug 30, 2022  
 
commit fcdc2f0e102497313232cc7c0a570cc4c524a02b
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Tue Aug 30 12:58:57 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Tue Aug 30 12:58:57 2022 +0200

    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 +
 src/drivers/Wayland/Fl_Wayland_System_Driver.cxx | 18 ++++++++++++++++++
 src/drivers/Wayland/fl_wayland_platform_init.cxx | 12 ------------
 7 files changed, 30 insertions(+), 16 deletions(-)

diff --git FL/platform.H FL/platform.H
index 834a323..81d5a73 100644
--- FL/platform.H
+++ 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 FL/wayland.H FL/wayland.H
index 66b6331..2f88ce2 100644
--- FL/wayland.H
+++ 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 src/Fl.cxx src/Fl.cxx
index 7b7cb2b..3ba27a7 100644
--- src/Fl.cxx
+++ 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 src/Fl_System_Driver.H src/Fl_System_Driver.H
index 0abab55..15d3d89 100644
--- src/Fl_System_Driver.H
+++ 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 src/drivers/Wayland/Fl_Wayland_System_Driver.H src/drivers/Wayland/Fl_Wayland_System_Driver.H
index e520358..75043cd 100644
--- src/drivers/Wayland/Fl_Wayland_System_Driver.H
+++ 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 src/drivers/Wayland/Fl_Wayland_System_Driver.cxx src/drivers/Wayland/Fl_Wayland_System_Driver.cxx
index 4b26a17..7c3cf9a 100644
--- src/drivers/Wayland/Fl_Wayland_System_Driver.cxx
+++ 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 src/drivers/Wayland/fl_wayland_platform_init.cxx src/drivers/Wayland/fl_wayland_platform_init.cxx
index 8e4f949..ffdc13a 100644
--- src/drivers/Wayland/fl_wayland_platform_init.cxx
+++ src/drivers/Wayland/fl_wayland_platform_init.cxx
@@ -35,18 +35,6 @@
 #include <stdio.h>
 
 
-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");
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.