New OPTION_WAYLAND_ONLY for CMake to build pure Wayland platform.

This commit is contained in:
ManoloFLTK 2022-09-09 15:19:15 +02:00
parent 1b0f21cc8f
commit 203e7b7098
12 changed files with 101 additions and 35 deletions

View File

@ -194,10 +194,18 @@ set (HAVE_LIBPNG 1)
if (UNIX)
option (OPTION_CREATE_LINKS "create backwards compatibility links" OFF)
list (APPEND FLTK_LDLIBS -lm)
option (OPTION_USE_WAYLAND "use Wayland" OFF)
option (OPTION_USE_WAYLAND "support Wayland and X11 backends" OFF)
if (OPTION_USE_WAYLAND)
option (OPTION_WAYLAND_ONLY "support Wayland backend only" OFF)
set (FLTK_USE_WAYLAND 1)
set (FLTK_USE_X11 1) # to build a hybrid Wayland/X11 library
if (NOT OPTION_WAYLAND_ONLY)
include (FindX11)
endif (NOT OPTION_WAYLAND_ONLY)
if (X11_FOUND)
set (FLTK_USE_X11 1) # to build a hybrid Wayland/X11 library
else ()
set (FLTK_USE_X11 0) # to build a Wayland-only library
endif (X11_FOUND)
unset (OPTION_USE_CAIRO CACHE)
set (OPTION_USE_CAIRO TRUE CACHE BOOL "all drawing to X11 windows uses Cairo")
option (OPTION_USE_SYSTEM_LIBDECOR "use libdecor from the system" OFF)
@ -206,11 +214,13 @@ if (UNIX)
unset (OPTION_USE_XFT CACHE)
unset (OPTION_USE_XCURSOR CACHE)
unset (OPTION_USE_XFIXES CACHE)
if (X11_FOUND)
set (HAVE_XFIXES 1)
set (HAVE_XRENDER 1)
set (USE_XFT 1)
set (HAVE_XCURSOR 1)
set (HAVE_XINERAMA 1)
endif (X11_FOUND)
unset (OPTION_USE_PANGO CACHE)
set (OPTION_USE_PANGO TRUE CACHE BOOL "use lib Pango")
if (OPTION_USE_SYSTEM_LIBDECOR)

View File

@ -39,6 +39,9 @@ class Fl_Window;
# include "mac.H"
# elif defined(FLTK_USE_WAYLAND)
# include "wayland.H"
# if !FLTK_USE_X11
typedef struct wld_window *Window;
# endif
# elif defined(FLTK_USE_X11)
# include "x11.H"
# endif // _WIN32
@ -58,7 +61,7 @@ public:
// static variables, static functions and member functions
static Fl_X* first;
static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;}
# if defined(FLTK_USE_X11) // for backward compatibility
# if defined(FLTK_USE_X11) && FLTK_USE_X11 // for backward compatibility
static void make_xid(Fl_Window*, XVisualInfo* =fl_visual, Colormap=fl_colormap);
static Fl_X* set_xid(Fl_Window*, Window);
# endif

View File

@ -42,7 +42,9 @@ extern FL_EXPORT EGLContext fl_wl_glcontext(GLContext rc);
#ifndef FL_DOXYGEN
# if FLTK_USE_X11
// *********** for X11 component ***********
# include "x11.H"
# include "x11.H"
# endif
#endif // FL_DOXYGEN

View File

@ -108,13 +108,6 @@ extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
#if USE_PANGO
struct flCairoRegion {
int count;
struct _cairo_rectangle *rects;
}; // a region is the union of a series of rectangles
#endif
#endif // FL_LIBRARY || FL_INTERNALS
#endif // FL_DOXYGEN

View File

@ -175,6 +175,10 @@ OPTION_USE_WAYLAND - default OFF
and use X11 for their window operations otherwise, but keep using
Cairo and Pango - see README.Wayland.txt.
OPTION_WAYLAND_ONLY - default OFF
In conjunction with OPTION_USE_WAYLAND, restricts FLTK to support the
Wayland backend only.
OPTION_ABI_VERSION - default EMPTY
Use a numeric value corresponding to the FLTK ABI version you want to
build in the form 1xxyy for FLTK 1.x.y (xx and yy with leading zeroes).

View File

@ -282,19 +282,23 @@ elseif (OPTION_USE_WAYLAND)
drivers/Wayland/fl_wayland_clipboard_dnd.cxx
drivers/Wayland/fl_wayland_platform_init.cxx
drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
drivers/Cairo/Fl_Display_Cairo_Graphics_Driver.cxx
Fl_Native_File_Chooser_FLTK.cxx
Fl_Native_File_Chooser_GTK.cxx
Fl_Native_File_Chooser_Kdialog.cxx
drivers/X11/Fl_X11_Screen_Driver.cxx
drivers/X11/Fl_X11_Window_Driver.cxx
drivers/X11/Fl_X11_System_Driver.cxx
drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
Fl_x.cxx
fl_dnd_x.cxx
Fl_get_key.cxx
)
)
if (FLTK_USE_X11)
list (APPEND DRIVER_FILES
drivers/Cairo/Fl_Display_Cairo_Graphics_Driver.cxx
drivers/X11/Fl_X11_Screen_Driver.cxx
drivers/X11/Fl_X11_Window_Driver.cxx
drivers/X11/Fl_X11_System_Driver.cxx
drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
Fl_x.cxx
fl_dnd_x.cxx
Fl_get_key.cxx
)
endif (FLTK_USE_X11)
set (DRIVER_HEADER_FILES
drivers/Posix/Fl_Posix_System_Driver.H
drivers/Wayland/Fl_Wayland_System_Driver.H
@ -426,9 +430,12 @@ set (GL_DRIVER_FILES
if (OPTION_USE_WAYLAND)
set (GL_DRIVER_FILES ${GL_DRIVER_FILES}
drivers/Wayland/Fl_Wayland_Gl_Window_Driver.cxx
drivers/X11/Fl_X11_Gl_Window_Driver.cxx
drivers/Wayland/fl_wayland_gl_platform_init.cxx)
set (GL_DRIVER_HEADER_FILES drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H drivers/X11/Fl_X11_Gl_Window_Driver.H)
set (GL_DRIVER_HEADER_FILES drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H)
if (FLTK_USE_X11)
list (APPEND GL_DRIVER_FILES drivers/X11/Fl_X11_Gl_Window_Driver.cxx)
list (APPEND GL_DRIVER_HEADER_FILES drivers/X11/Fl_X11_Gl_Window_Driver.H)
endif (FLTK_USE_X11)
elseif (FLTK_USE_X11)
set (GL_DRIVER_FILES ${GL_DRIVER_FILES} drivers/X11/Fl_X11_Gl_Window_Driver.cxx drivers/X11/fl_X11_gl_platform_init.cxx)
set (GL_DRIVER_HEADER_FILES drivers/X11/Fl_X11_Gl_Window_Driver.H)
@ -511,12 +518,14 @@ if (OPTION_USE_WAYLAND)
endif (GTK_FOUND)
list (APPEND CFILES
xutf8/keysym2Ucs.c
scandir_posix.c
../libdecor/src/cursor-settings.c
../libdecor/src/os-compatibility.c
../libdecor/build/fl_libdecor-plugins.c
)
if (FLTK_USE_X11)
list (APPEND CFILES xutf8/keysym2Ucs.c)
endif (FLTK_USE_X11)
if (NOT OPTION_USE_SYSTEM_LIBDECOR)
list (APPEND CFILES
../libdecor/build/fl_libdecor.c

View File

@ -28,6 +28,12 @@ typedef struct _PangoLayout PangoLayout;
typedef struct _PangoContext PangoContext;
typedef struct _PangoFontDescription PangoFontDescription;
#if USE_PANGO
struct flCairoRegion {
int count;
struct _cairo_rectangle *rects;
}; // a region is the union of a series of rectangles
#endif
class Fl_Cairo_Font_Descriptor : public Fl_Font_Descriptor {
public:

View File

@ -174,7 +174,9 @@ 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();
#if FLTK_USE_X11
static bool undo_wayland_backend_if_needed(const char *backend = NULL);
#endif
};

View File

@ -18,7 +18,9 @@
#include "Fl_Wayland_Screen_Driver.H"
#include "Fl_Wayland_Window_Driver.H"
#include "Fl_Wayland_System_Driver.H"
#include "../X11/Fl_X11_System_Driver.H"
#if FLTK_USE_X11
# include "../X11/Fl_X11_System_Driver.H"
#endif
#include "Fl_Wayland_Graphics_Driver.H"
#include <wayland-cursor.h>
#include "../../../libdecor/src/libdecor.h"
@ -1090,6 +1092,7 @@ Fl_Wayland_Screen_Driver::Fl_Wayland_Screen_Driver() : Fl_Screen_Driver() {
}
#if FLTK_USE_X11
bool Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(const char *backend) {
if (!backend) backend = getenv("FLTK_BACKEND");
if (wl_display && backend && strcmp(backend, "x11") == 0) {
@ -1101,6 +1104,7 @@ bool Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed(const char *backen
}
return false;
}
#endif
void Fl_Wayland_Screen_Driver::open_display_platform() {
@ -1109,10 +1113,12 @@ void Fl_Wayland_Screen_Driver::open_display_platform() {
return;
beenHereDoneThat = true;
#if FLTK_USE_X11
if (undo_wayland_backend_if_needed()) {
Fl::screen_driver()->open_display();
return;
}
#endif
if (!wl_display) {
wl_display = wl_display_connect(NULL);

View File

@ -95,6 +95,7 @@ void *Fl_Wayland_System_Driver::control_maximize_button(void *data) {
void Fl_Wayland_System_Driver::disable_wayland() {
#if FLTK_USE_X11
if (too_late_to_disable) {
fprintf(stderr, "Error: fl_disable_wayland() cannot be called "
"after the Wayland display was opened\n"
@ -102,4 +103,5 @@ void Fl_Wayland_System_Driver::disable_wayland() {
exit(1);
}
Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed("x11");
#endif
}

View File

@ -17,11 +17,16 @@
#include "Fl_Wayland_Gl_Window_Driver.H"
#include "Fl_Wayland_Screen_Driver.H"
#if FLTK_USE_X11
#include "../X11/Fl_X11_Gl_Window_Driver.H"
#endif
Fl_Gl_Window_Driver *Fl_Gl_Window_Driver::newGlWindowDriver(Fl_Gl_Window *w)
{
#if FLTK_USE_X11
if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Gl_Window_Driver(w);
return new Fl_X11_Gl_Window_Driver(w);
#else
return new Fl_Wayland_Gl_Window_Driver(w);
#endif
}

View File

@ -21,21 +21,22 @@
#include "Fl_Wayland_System_Driver.H"
#include "Fl_Wayland_Window_Driver.H"
#include "Fl_Wayland_Image_Surface_Driver.H"
#include "../Xlib/Fl_Xlib_Copy_Surface_Driver.H"
#include <cairo-xlib.h>
#include "../Cairo/Fl_Display_Cairo_Graphics_Driver.H"
#include "../X11/Fl_X11_Screen_Driver.H"
#include "../X11/Fl_X11_System_Driver.H"
#include "../X11/Fl_X11_Window_Driver.H"
#include "../Xlib/Fl_Xlib_Image_Surface_Driver.H"
#if FLTK_USE_X11
# include "../Xlib/Fl_Xlib_Copy_Surface_Driver.H"
# include <cairo-xlib.h>
# include "../Cairo/Fl_Display_Cairo_Graphics_Driver.H"
# include "../X11/Fl_X11_Screen_Driver.H"
# include "../X11/Fl_X11_System_Driver.H"
# include "../X11/Fl_X11_Window_Driver.H"
# include "../Xlib/Fl_Xlib_Image_Surface_Driver.H"
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Fl_System_Driver *Fl_System_Driver::newSystemDriver() {
#if FLTK_USE_X11
const char *backend = ::getenv("FLTK_BACKEND");
const char *xdgrt = ::getenv("XDG_RUNTIME_DIR");
// fprintf(stderr, "FLTK_BACKEND='%s' XDG_RUNTIME_DIR='%s'\n",
@ -72,6 +73,9 @@ Fl_System_Driver *Fl_System_Driver::newSystemDriver() {
fprintf(stderr, "Error: unexpected value of FLTK_BACKEND: '%s'\n", backend);
exit(1);
return NULL;
#else
return new Fl_Wayland_System_Driver();
#endif
}
@ -99,6 +103,7 @@ FL_EXPORT Fl_Fontdesc *fl_fonts = built_in_table;
Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver() {
#if FLTK_USE_X11
Fl_Wayland_Screen_Driver::undo_wayland_backend_if_needed();
if (Fl_Wayland_Screen_Driver::wl_display) {
fl_graphics_driver = new Fl_Wayland_Graphics_Driver();
@ -106,16 +111,24 @@ Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver() {
fl_graphics_driver = new Fl_Display_Cairo_Graphics_Driver();
}
return fl_graphics_driver;
#else
return new Fl_Wayland_Graphics_Driver();
#endif
}
Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int h) {
#if FLTK_USE_X11
if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Copy_Surface_Driver(w, h);
return new Fl_Xlib_Copy_Surface_Driver(w, h);
#else
return new Fl_Wayland_Copy_Surface_Driver(w, h);
#endif
}
Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() {
#if FLTK_USE_X11
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) {
@ -127,11 +140,15 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() {
for (int i = 0; i < MAX_SCREENS; i++) d->screens[i].scale = 1;
d->current_xft_dpi = 0.; // means the value of the Xft.dpi resource is still unknown
return d;
#else
return new Fl_Wayland_Screen_Driver();
#endif
}
Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
{
#if FLTK_USE_X11
if (!Fl_Screen_Driver::system_driver) Fl::system_driver();
static bool been_here = false;
if (!been_here) {
@ -141,11 +158,18 @@ Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
}
if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Window_Driver(w);
return new Fl_X11_Window_Driver(w);
#else
return new Fl_Wayland_Window_Driver(w);
#endif
}
Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off)
{
#if FLTK_USE_X11
if (Fl_Wayland_Screen_Driver::wl_display) return new Fl_Wayland_Image_Surface_Driver(w, h, high_res, off);
return new Fl_Xlib_Image_Surface_Driver(w, h, high_res, off);
#else
return new Fl_Wayland_Image_Surface_Driver(w, h, high_res, off);
#endif
}