mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 23:06:54 +08:00
Hybrid Wayland/X11 platform: improve control of chosen backend.
This commit is contained in:
@@ -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_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 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
|
/** \defgroup callback_functions Callback Function Typedefs
|
||||||
|
|
||||||
\brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters.
|
\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 Window fl_window;
|
||||||
extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
|
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_open_callback(void (*)(const char *));
|
||||||
extern FL_EXPORT void fl_disable_wayland();
|
|
||||||
|
|
||||||
#endif // !FL_PLATFORM_H
|
#endif // !FL_PLATFORM_H
|
||||||
|
|||||||
+2
-2
@@ -2016,8 +2016,8 @@ void fl_close_display()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Prevent the FLTK library from using its wayland backend.
|
/** Prevent the FLTK library from using its wayland backend.
|
||||||
Call this early in your main(), before fl_open_display() runs.
|
Call this early in your main(), before fl_open_display() runs, or any window is created, or the screen is accessed.
|
||||||
This has no effect on non-Wayland platforms.
|
This function has no effect on non-Wayland platforms.
|
||||||
*/
|
*/
|
||||||
void fl_disable_wayland()
|
void fl_disable_wayland()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ public:
|
|||||||
static FL_EXPORT struct wl_display *wl_display;
|
static FL_EXPORT struct wl_display *wl_display;
|
||||||
// use it to make sure the Wayland leg was selected and fl_open_display() has run
|
// use it to make sure the Wayland leg was selected and fl_open_display() has run
|
||||||
static struct wl_registry *wl_registry;
|
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 void insertion_point_location(int x, int y, int height);
|
||||||
static bool insertion_point_location(int *px, int *py, int *pwidth, int *pheight);
|
static bool insertion_point_location(int *px, int *py, int *pwidth, int *pheight);
|
||||||
int get_mouse_unscaled(int &xx, int &yy);
|
int get_mouse_unscaled(int &xx, int &yy);
|
||||||
@@ -176,6 +174,7 @@ public:
|
|||||||
static compositor_name compositor; // identifies the used Wayland compositor
|
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 set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win);
|
||||||
void reset_spot();
|
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;
|
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) {
|
Fl_Window *Fl_Wayland_Screen_Driver::surface_to_window(struct wl_surface *surface) {
|
||||||
if (surface) {
|
if (surface) {
|
||||||
Fl_X *xp = Fl_X::first;
|
Fl_X *xp = Fl_X::first;
|
||||||
@@ -1089,12 +1087,31 @@ Fl_Wayland_Screen_Driver::Fl_Wayland_Screen_Driver() : Fl_Screen_Driver() {
|
|||||||
reset_cursor();
|
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() {
|
void Fl_Wayland_Screen_Driver::open_display_platform() {
|
||||||
static bool beenHereDoneThat = false;
|
static bool beenHereDoneThat = false;
|
||||||
if (beenHereDoneThat)
|
if (beenHereDoneThat)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beenHereDoneThat = true;
|
beenHereDoneThat = true;
|
||||||
|
if (undo_wayland_backend_if_needed()) {
|
||||||
|
Fl::screen_driver()->open_display();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wl_display) {
|
if (!wl_display) {
|
||||||
wl_display = wl_display_connect(NULL);
|
wl_display = wl_display_connect(NULL);
|
||||||
if (!wl_display) {
|
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::add_fd(wl_display_get_fd(wl_display), FL_READ, (Fl_FD_Handler)fd_callback, wl_display);
|
||||||
fl_create_print_window();
|
fl_create_print_window();
|
||||||
|
Fl_Wayland_System_Driver::too_late_to_disable = true;
|
||||||
|
puts("Using Wayland backend");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fl_Wayland_Screen_Driver::close_display() {
|
void Fl_Wayland_Screen_Driver::close_display() {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public:
|
|||||||
int get_key(int k);
|
int get_key(int k);
|
||||||
virtual void *control_maximize_button(void *data);
|
virtual void *control_maximize_button(void *data);
|
||||||
virtual void disable_wayland();
|
virtual void disable_wayland();
|
||||||
|
static bool too_late_to_disable;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FL_WAYLAND_SYSTEM_DRIVER_H */
|
#endif /* FL_WAYLAND_SYSTEM_DRIVER_H */
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
#include "Fl_Wayland_Screen_Driver.H"
|
#include "Fl_Wayland_Screen_Driver.H"
|
||||||
#include <FL/platform.H>
|
#include <FL/platform.H>
|
||||||
#include "../../../libdecor/src/libdecor.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) {
|
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() {
|
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 "
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
setenv("FLTK_BACKEND", "x11", 1);
|
||||||
if (Fl_Wayland_Screen_Driver::wl_display) {
|
Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ Fl_System_Driver *Fl_System_Driver::newSystemDriver() {
|
|||||||
// fprintf(stderr, "FLTK_BACKEND='%s' XDG_RUNTIME_DIR='%s'\n",
|
// fprintf(stderr, "FLTK_BACKEND='%s' XDG_RUNTIME_DIR='%s'\n",
|
||||||
// backend ? backend : "", xdgrt ? xdgrt : "");
|
// backend ? backend : "", xdgrt ? xdgrt : "");
|
||||||
|
|
||||||
if (Fl_Wayland_Screen_Driver::wld_disabled ||
|
if (backend && strcmp(backend, "x11") == 0) {
|
||||||
(backend && strcmp(backend, "x11") == 0)) {
|
|
||||||
return new Fl_X11_System_Driver();
|
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_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver() {
|
||||||
|
Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed();
|
||||||
if (Fl_Wayland_Screen_Driver::wl_display) {
|
if (Fl_Wayland_Screen_Driver::wl_display) {
|
||||||
fl_graphics_driver = new Fl_Wayland_Graphics_Driver();
|
fl_graphics_driver = new Fl_Wayland_Graphics_Driver();
|
||||||
puts("using Fl_Wayland_Graphics_Driver");
|
|
||||||
} else {
|
} else {
|
||||||
fl_graphics_driver = new Fl_Display_Cairo_Graphics_Driver();
|
fl_graphics_driver = new Fl_Display_Cairo_Graphics_Driver();
|
||||||
puts("using Fl_Display_Cairo_Graphics_Driver");
|
|
||||||
}
|
}
|
||||||
return fl_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() {
|
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();
|
Fl_X11_Screen_Driver *d = new Fl_X11_Screen_Driver();
|
||||||
for (int i = 0; i < MAX_SCREENS; i++) d->screens[i].scale = 1;
|
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)
|
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);
|
if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Window_Driver(w);
|
||||||
return new Fl_X11_Window_Driver(w);
|
return new Fl_X11_Window_Driver(w);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user