mirror of https://github.com/fltk/fltk
Hybrid Wayland/X11 platform: improve control of chosen backend.
This commit is contained in:
parent
fcdc2f0e10
commit
07fd2628fe
2
FL/Fl.H
2
FL/Fl.H
|
@ -61,6 +61,8 @@ extern FL_EXPORT const char* fl_local_ctrl; ///< string pointer used in shortcu
|
|||
extern FL_EXPORT const char* fl_local_meta; ///< string pointer used in shortcuts, you can change it to another language
|
||||
extern FL_EXPORT const char* fl_local_shift; ///< string pointer used in shortcuts, you can change it to another language
|
||||
|
||||
extern FL_EXPORT void fl_disable_wayland();
|
||||
|
||||
/** \defgroup callback_functions Callback Function Typedefs
|
||||
|
||||
\brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters.
|
||||
|
|
|
@ -76,6 +76,5 @@ 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
|
||||
|
|
|
@ -2016,8 +2016,8 @@ void fl_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.
|
||||
Call this early in your main(), before fl_open_display() runs, or any window is created, or the screen is accessed.
|
||||
This function has no effect on non-Wayland platforms.
|
||||
*/
|
||||
void fl_disable_wayland()
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue