diff options
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Screen_Driver.H | 3 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx | 23 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_System_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_System_Driver.cxx | 20 | ||||
| -rw-r--r-- | src/drivers/Wayland/fl_wayland_platform_init.cxx | 20 |
5 files changed, 47 insertions, 20 deletions
diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H index 64aae8593..d5196b557 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H @@ -66,8 +66,6 @@ public: static FL_EXPORT struct wl_display *wl_display; // use it to make sure the Wayland leg was selected and fl_open_display() has run static struct wl_registry *wl_registry; - // true when an app is forbidden to use its Wayland leg - static bool wld_disabled; static void insertion_point_location(int x, int y, int height); static bool insertion_point_location(int *px, int *py, int *pwidth, int *pheight); int get_mouse_unscaled(int &xx, int &yy); @@ -176,6 +174,7 @@ public: static compositor_name compositor; // identifies the used Wayland compositor void set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win); void reset_spot(); + static bool undo_wayland_backend_if_needed(); }; diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx index cdfc88e80..cc6d1b4ce 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx @@ -230,8 +230,6 @@ struct wl_display *Fl_Wayland_Screen_Driver::wl_display = NULL; struct wl_registry *Fl_Wayland_Screen_Driver::wl_registry = NULL; -bool Fl_Wayland_Screen_Driver::wld_disabled = false; - Fl_Window *Fl_Wayland_Screen_Driver::surface_to_window(struct wl_surface *surface) { if (surface) { Fl_X *xp = Fl_X::first; @@ -1089,12 +1087,31 @@ Fl_Wayland_Screen_Driver::Fl_Wayland_Screen_Driver() : Fl_Screen_Driver() { reset_cursor(); } + +bool Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed() { + const char *backend = getenv("FLTK_BACKEND"); + if (wl_display && backend && strcmp(backend, "x11") == 0) { + wl_display_disconnect(wl_display); + wl_display = NULL; + delete Fl_Screen_Driver::system_driver; + Fl_Screen_Driver::system_driver = NULL; + return true; + } + return false; +} + + void Fl_Wayland_Screen_Driver::open_display_platform() { static bool beenHereDoneThat = false; if (beenHereDoneThat) return; beenHereDoneThat = true; + if (undo_wayland_backend_if_needed()) { + Fl::screen_driver()->open_display(); + return; + } + if (!wl_display) { wl_display = wl_display_connect(NULL); if (!wl_display) { @@ -1116,6 +1133,8 @@ void Fl_Wayland_Screen_Driver::open_display_platform() { }*/ Fl::add_fd(wl_display_get_fd(wl_display), FL_READ, (Fl_FD_Handler)fd_callback, wl_display); fl_create_print_window(); + Fl_Wayland_System_Driver::too_late_to_disable = true; +puts("Using Wayland backend"); } void Fl_Wayland_Screen_Driver::close_display() { diff --git a/src/drivers/Wayland/Fl_Wayland_System_Driver.H b/src/drivers/Wayland/Fl_Wayland_System_Driver.H index 75043cd04..d363aa1d0 100644 --- a/src/drivers/Wayland/Fl_Wayland_System_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_System_Driver.H @@ -27,6 +27,7 @@ public: int get_key(int k); virtual void *control_maximize_button(void *data); virtual void disable_wayland(); + static bool too_late_to_disable; }; #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 7c3cf9aa8..158c5619a 100644 --- a/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_System_Driver.cxx @@ -21,6 +21,10 @@ #include "Fl_Wayland_Screen_Driver.H" #include <FL/platform.H> #include "../../../libdecor/src/libdecor.h" +#include <stdlib.h> + + +bool Fl_Wayland_System_Driver::too_late_to_disable = false; int Fl_Wayland_System_Driver::event_key(int k) { @@ -91,18 +95,12 @@ void *Fl_Wayland_System_Driver::control_maximize_button(void *data) { void Fl_Wayland_System_Driver::disable_wayland() { - if (fl_wl_display()) { + if (too_late_to_disable) { fprintf(stderr, "Error: fl_disable_wayland() cannot be called " - "after the Wayland display was opened\n"); + "after the Wayland display was opened\n" + "or a Wayland window was created or the Wayland screen was accessed\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(); + setenv("FLTK_BACKEND", "x11", 1); + Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(); } diff --git a/src/drivers/Wayland/fl_wayland_platform_init.cxx b/src/drivers/Wayland/fl_wayland_platform_init.cxx index ffdc13a69..c1536680c 100644 --- a/src/drivers/Wayland/fl_wayland_platform_init.cxx +++ b/src/drivers/Wayland/fl_wayland_platform_init.cxx @@ -41,8 +41,7 @@ Fl_System_Driver *Fl_System_Driver::newSystemDriver() { // fprintf(stderr, "FLTK_BACKEND='%s' XDG_RUNTIME_DIR='%s'\n", // backend ? backend : "", xdgrt ? xdgrt : ""); - if (Fl_Wayland_Screen_Driver::wld_disabled || - (backend && strcmp(backend, "x11") == 0)) { + if (backend && strcmp(backend, "x11") == 0) { return new Fl_X11_System_Driver(); } @@ -100,12 +99,11 @@ FL_EXPORT Fl_Fontdesc *fl_fonts = built_in_table; Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver() { + Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(); if (Fl_Wayland_Screen_Driver::wl_display) { fl_graphics_driver = new Fl_Wayland_Graphics_Driver(); -puts("using Fl_Wayland_Graphics_Driver"); } else { fl_graphics_driver = new Fl_Display_Cairo_Graphics_Driver(); -puts("using Fl_Display_Cairo_Graphics_Driver"); } return fl_graphics_driver; } @@ -118,7 +116,12 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() { - if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Screen_Driver(); + if (!Fl_Screen_Driver::system_driver) Fl::system_driver(); + Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(); + if (Fl_Wayland_Screen_Driver::wl_display) { + Fl_Wayland_System_Driver::too_late_to_disable = true; + return new Fl_Wayland_Screen_Driver(); + } Fl_X11_Screen_Driver *d = new Fl_X11_Screen_Driver(); for (int i = 0; i < MAX_SCREENS; i++) d->screens[i].scale = 1; @@ -129,6 +132,13 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() { Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w) { + if (!Fl_Screen_Driver::system_driver) Fl::system_driver(); + static bool been_here = false; + if (!been_here) { + been_here = true; + Fl_Wayland_System_Driver::too_late_to_disable = true; + Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(); + } if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Window_Driver(w); return new Fl_X11_Window_Driver(w); } |
