Skip to content

Commit

Permalink
Make hybrid Wayland/X11 platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
ManoloFLTK committed Aug 29, 2022
1 parent 28981f6 commit c720aae
Show file tree
Hide file tree
Showing 93 changed files with 1,311 additions and 530 deletions.
48 changes: 42 additions & 6 deletions CMake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,20 @@ if (UNIX)
option (OPTION_USE_WAYLAND "use Wayland" OFF)
if (OPTION_USE_WAYLAND)
set (FLTK_USE_WAYLAND 1)
set (FLTK_USE_X11 1) # to build a hybrid Wayland/X11 library
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)
unset (OPTION_USE_XRENDER CACHE)
unset (OPTION_USE_XINERAMA CACHE)
unset (OPTION_USE_XFT CACHE)
unset (OPTION_USE_XCURSOR CACHE)
unset (OPTION_USE_XFIXES CACHE)
set (HAVE_XFIXES 1)
set (HAVE_XRENDER 1)
set (USE_XFT 1)
set (HAVE_XCURSOR 1)
set (HAVE_XINERAMA 1)
unset (OPTION_USE_PANGO CACHE)
set (OPTION_USE_PANGO TRUE CACHE BOOL "use lib Pango")
if (OPTION_USE_SYSTEM_LIBDECOR)
Expand All @@ -211,6 +219,9 @@ if (UNIX)
set (OPTION_USE_SYSTEM_LIBDECOR OFF)
endif (NOT SYSTEM_LIBDECOR_FOUND)
endif (OPTION_USE_SYSTEM_LIBDECOR)

option (OPTION_ALLOW_GTK_PLUGIN "Allow to use libdecor's GTK plugin" ON)

endif (OPTION_USE_WAYLAND)
endif (UNIX)

Expand Down Expand Up @@ -311,7 +322,7 @@ endif (OPTION_BUILD_HTML_DOCUMENTATION OR OPTION_BUILD_PDF_DOCUMENTATION)
# Include optional Cairo support
#######################################################################

option (OPTION_CAIRO "use lib Cairo" OFF)
option (OPTION_CAIRO "add support for Fl_Cairo_Window" OFF)
option (OPTION_CAIROEXT
"use FLTK code instrumentation for Cairo extended use" OFF
)
Expand Down Expand Up @@ -556,8 +567,17 @@ endif (OPTION_USE_XCURSOR)
if (X11_Xft_FOUND)
option (OPTION_USE_XFT "use lib Xft" ON)
option (OPTION_USE_PANGO "use lib Pango" OFF)
if (NOT OPTION_USE_WAYLAND)
option (OPTION_USE_CAIRO "all drawing to X11 windows uses Cairo" OFF)
endif (NOT OPTION_USE_WAYLAND)
endif (X11_Xft_FOUND)

# test option compatibility: Cairo for Xlib requires Pango
if (OPTION_USE_CAIRO)
unset (OPTION_USE_PANGO CACHE)
set (OPTION_USE_PANGO TRUE CACHE BOOL "use lib Pango")
endif (OPTION_USE_CAIRO)

# test option compatibility: Pango requires Xft
if (OPTION_USE_PANGO AND NOT OPTION_USE_WAYLAND)
if (NOT X11_Xft_FOUND)
Expand Down Expand Up @@ -654,14 +674,30 @@ if ((X11_Xft_FOUND OR OPTION_USE_WAYLAND) AND OPTION_USE_PANGO)
endif (HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT)
endif (PANGOXFT_FOUND AND PANGOCAIRO_FOUND AND CAIRO_FOUND)

if (USE_PANGO AND (OPTION_USE_CAIRO OR OPTION_USE_WAYLAND))
set (FLTK_USE_CAIRO 1)
# fl_debug_var (FLTK_USE_CAIRO)
endif (USE_PANGO AND (OPTION_USE_CAIRO OR OPTION_USE_WAYLAND))

endif ((X11_Xft_FOUND OR OPTION_USE_WAYLAND) AND OPTION_USE_PANGO)

if (OPTION_USE_WAYLAND AND NOT OPTION_USE_SYSTEM_LIBDECOR)
pkg_check_modules(GTK gtk+-3.0)
# set (GTK_FOUND 0) # use this to get cairo titlebars rather than GTK
if (GTK_FOUND)
include_directories (${GTK_INCLUDE_DIRS})
endif (GTK_FOUND)

# Note: Disable OPTION_ALLOW_GTK_PLUGIN to get cairo titlebars rather than GTK
# FIXME: This needs to be redesigned! Forcing GTK_FOUND to 0 (NO) is a bad
# FIXME: idea because there could be unwanted side effects. AlbrechtS
if (OPTION_ALLOW_GTK_PLUGIN)
pkg_check_modules(GTK gtk+-3.0)
if (GTK_FOUND)
include_directories (${GTK_INCLUDE_DIRS})
endif (GTK_FOUND)
else ()
if (GTK_FOUND)
message (STATUS "*** FIXME: Disable GTK plugin by forcing GTK_FOUND to 0 ***")
set (GTK_FOUND 0)
endif (GTK_FOUND)
endif (OPTION_ALLOW_GTK_PLUGIN)

endif (OPTION_USE_WAYLAND AND NOT OPTION_USE_SYSTEM_LIBDECOR)

if (OPTION_USE_XFT)
Expand Down
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,30 +241,36 @@ endif ()
if (UNIX)

if (OPTION_USE_WAYLAND)
message (STATUS "Use Wayland: Yes")
message (STATUS "Use Wayland: Yes (when available at run-time)")
else ()
message (STATUS "Use Wayland: No")
message (STATUS "Use Wayland: No (therefore, X11 is used)")
endif ()

if (FLTK_USE_CAIRO)
message (STATUS "All drawing uses Cairo: Yes")
else ()
message (STATUS "All drawing uses Cairo: No")
endif ()

if (USE_PANGO)
message (STATUS "Use Pango: Yes")
message (STATUS "Use Pango: Yes")
else (USE_PANGO)
message (STATUS "Use Pango: No")
message (STATUS "Use Pango: No")
if (USE_XFT)
message (STATUS "Use Xft: Yes")
message (STATUS "Use Xft: Yes")
else ()
message (STATUS "Use Xft: No")
message (STATUS "Use Xft: No")
endif (USE_XFT)
endif (USE_PANGO)

endif (UNIX)

if (FLTK_HAVE_CAIROEXT)
message (STATUS "Cairo support: Yes (extended)")
message (STATUS "Fl_Cairo_Window support: Yes (extended)")
elseif (FLTK_HAVE_CAIRO)
message (STATUS "Cairo support: Yes (standard)")
message (STATUS "Fl_Cairo_Window support: Yes (standard)")
else ()
message (STATUS "Cairo support: No")
message (STATUS "Fl_Cairo_Window support: No")
endif ()

message ("")
Expand Down
2 changes: 1 addition & 1 deletion FL/Fl_Cairo_Window.H
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
\see examples/cairo-draw-x.cxx
\see test/cairo_test.cxx
\note Class Fl_Cairo_Window requires the FLTK library to have been built with
CMake option OPTION_CAIRO or configure --enable-cairo.
Expand Down
2 changes: 2 additions & 0 deletions FL/Fl_Device.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class Fl_Graphics_Driver;
class Fl_RGB_Image;
class Fl_Widget;
class Fl_Image_Surface;

/**
A drawing surface that's susceptible to receive graphical output.
Expand Down Expand Up @@ -91,6 +92,7 @@ public:
}
/** \brief The destructor. */
virtual ~Fl_Surface_Device();
virtual Fl_Image_Surface *as_image_surface();
static void push_current(Fl_Surface_Device *new_current);
static Fl_Surface_Device *pop_current();
};
Expand Down
5 changes: 3 additions & 2 deletions FL/Fl_Gl_Window.H
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ public:
and may be followed by adequate attribute values.
*/
int mode(const int *a) {return mode(0, a);}
/** Returns a pointer to the GLContext that this window is using.
\see void context(GLContext c, int destroy_flag) */
/** Returns a pointer to the window's OpenGL rendering context.
\see void context(GLContext c, int destroy_flag)
*/
GLContext context() const {return context_;}
void context(GLContext, int destroy_flag = 0);
void make_current();
Expand Down
4 changes: 4 additions & 0 deletions FL/Fl_Image_Surface.H
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public:
int printable_rect(int *w, int *h);
Fl_Offscreen offscreen();
void rescale();
Fl_Image_Surface *as_image_surface();
};


Expand All @@ -98,6 +99,8 @@ public:
*/
class Fl_Image_Surface_Driver : public Fl_Widget_Surface {
friend class Fl_Image_Surface;
private:
Fl_Image_Surface *image_surface_;
protected:
int width;
int height;
Expand All @@ -110,6 +113,7 @@ protected:
virtual void untranslate() = 0;
int printable_rect(int *w, int *h);
virtual Fl_RGB_Image *image() = 0;
virtual Fl_Image_Surface *as_image_surface();
/** Each platform implements this function its own way.
It returns an object implementing all virtual functions
of class Fl_Image_Surface_Driver for the plaform.
Expand Down
13 changes: 13 additions & 0 deletions FL/mac.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
# error "Never use <FL/mac.H> directly; include <FL/platform.H> instead."
#endif // !FL_PLATFORM_H

#ifdef __OBJC__
@class NSOpenGLContext;
#elif defined(__cplusplus)
class NSOpenGLContext;
#endif /* __OBJC__ */
extern NSOpenGLContext *fl_mac_glcontext(GLContext rc);

#ifdef __OBJC__
@class FLWindow; // a subclass of the NSWindow Cocoa class
typedef FLWindow *Window;
Expand Down Expand Up @@ -125,6 +132,12 @@ extern CGContextRef fl_gc;
*/
void fl_mac_set_about(Fl_Callback *cb, void *user_data, int shortcut = 0);

/** Returns the macOS-specific graphics context for the current window */
extern CGContextRef fl_mac_gc();
/** Returns the macOS-specific window reference corresponding to the given Fl_Window object */
extern FLWindow *fl_mac_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to the given macOS-specific window reference */
extern Fl_Window *fl_mac_find(FLWindow *);

/** The version number of the running Mac OS X (e.g., 100604 for 10.6.4, 101300 for 10.13).
FLTK initializes this global variable before main() begins running. If
Expand Down
4 changes: 2 additions & 2 deletions FL/platform.H
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Fl_Window;

class FL_EXPORT Fl_X {
public:
Window xid;
fl_uintptr_t xid;
Fl_Window* w;
Fl_Region region;
Fl_X *next;
Expand All @@ -64,7 +64,7 @@ public:
# endif
};

inline Window fl_xid(const Fl_Window* w) { Fl_X *xTemp = Fl_X::i(w); return xTemp ? xTemp->xid : 0; }
inline Window fl_xid(const Fl_Window* w) { Fl_X *xTemp = Fl_X::i(w); return xTemp ? (Window)xTemp->xid : 0; }
#else
extern FL_EXPORT Window fl_xid_(const Fl_Window* w);
# define fl_xid(w) fl_xid_(w)
Expand Down
104 changes: 46 additions & 58 deletions FL/platform_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,40 @@ typedef opaque fl_intptr_t;
A variable of type fl_uintptr_t can also store an unsigned long int value. */
typedef opaque fl_uintptr_t;

typedef opaque Fl_Offscreen; /**< an offscreen drawing buffer */
typedef opaque Fl_Region; /**< a region made of several rectangles */
/**
Platform-specific value representing an offscreen drawing buffer.
\note This value can be safely cast to these types on each platform:
\li X11: Pixmap
\li Wayland: struct fl_wld_buffer *
\li Windows: HBITMAP
\li macOS: CGContextRef
*/
typedef opaque Fl_Offscreen;

/**
Pointer to a platform-specific structure representing a collection of rectangles.
\note This pointer can be safely cast to these types on each platform:
\li X11: Region as defined by X11
\li Wayland: struct flCairoRegion *
\li Windows: HRGN
\li macOS: struct flCocoaRegion *
*/
typedef struct opaque *Fl_Region;
typedef opaque FL_SOCKET; /**< socket or file descriptor */
typedef opaque GLContext; /**< an OpenGL graphics context, into which all OpenGL calls are rendered */
/**
Pointer to a platform-specific structure representing the window's OpenGL rendering context.
\note This pointer can be safely cast to these types on each platform:
\li X11: GLXContext
\li Wayland: EGLContext
\li Windows: HGLRC
\li macOS: NSOpenGLContext *
*/
typedef struct opaque *GLContext;

# define FL_COMMAND opaque /**< An alias for FL_CTRL on Windows and X11, or FL_META on MacOS X */
# define FL_CONTROL opaque /**< An alias for FL_META on Windows and X11, or FL_CTRL on MacOS X */

#else
#else /* FL_DOXYGEN */

#ifndef FL_PLATFORM_TYPES_H
#define FL_PLATFORM_TYPES_H
Expand All @@ -49,8 +74,7 @@ typedef opaque GLContext; /**< an OpenGL graphics context, into which all OpenGL

/* Platform-dependent types are defined here.
These types must be defined by any platform:
Fl_Offscreen, Fl_Region, FL_SOCKET, GLContext, struct dirent, struct stat,
fl_intptr_t, fl_uintptr_t
FL_SOCKET, struct dirent, fl_intptr_t, fl_uintptr_t
NOTE: *FIXME* AlbrechtS 13 Apr 2016 (concerning FL_SOCKET)
----------------------------------------------------------
Expand Down Expand Up @@ -78,65 +102,29 @@ typedef unsigned long fl_uintptr_t;

#endif /* _WIN64 */

typedef void *GLContext;
typedef void *Fl_Region;
typedef fl_uintptr_t Fl_Offscreen;

/* Allows all hybrid combinations except WIN32 + X11 with MSVC */
#if defined(_WIN32) && !defined(__MINGW32__)
struct dirent {char d_name[1];};
#else
# include <dirent.h>
#endif

#ifdef __APPLE__
typedef struct CGContext* Fl_Offscreen;
typedef struct flCocoaRegion* Fl_Region;
typedef int FL_SOCKET;
#ifdef __OBJC__
@class NSOpenGLContext;
typedef NSOpenGLContext* GLContext;
#elif defined(__cplusplus)
typedef class NSOpenGLContext* GLContext;
#endif /* __OBJC__ */

#include <sys/types.h>
#include <dirent.h>
# define FL_COMMAND FL_META
# define FL_CONTROL FL_CTRL

#elif defined(_WIN32)
typedef struct HBITMAP__ *HBITMAP;
typedef HBITMAP Fl_Offscreen;
typedef struct HRGN__ *Fl_Region;
# if defined(_WIN64) && defined(_MSC_VER)
typedef unsigned __int64 FL_SOCKET; /* *FIXME* - FL_SOCKET (see above) */
# else
typedef int FL_SOCKET;
# endif
typedef struct HGLRC__ *GLContext;
#ifdef __MINGW32__
# include <dirent.h>
#else
struct dirent {char d_name[1];};
#endif

#elif defined(FLTK_USE_WAYLAND)
typedef struct fl_wld_buffer *Fl_Offscreen; /**< an offscreen drawing buffer */
typedef struct flCairoRegion* Fl_Region;
typedef int FL_SOCKET; /**< socket or file descriptor */
typedef void *EGLContext;
typedef EGLContext GLContext;
#include <sys/types.h>
#include <dirent.h>

#elif defined(FLTK_USE_X11)

typedef unsigned long Fl_Offscreen;
typedef struct _XRegion *Fl_Region;
typedef int FL_SOCKET;
typedef struct __GLXcontextRec *GLContext;
#include <sys/types.h>
#include <dirent.h>

#endif /* __APPLE__ */


#ifndef __APPLE__
# define FL_COMMAND FL_CTRL /**< An alias for FL_CTRL on Windows and X11, or FL_META on MacOS X */
# define FL_CONTROL FL_META /**< An alias for FL_META on Windows and X11, or FL_CTRL on MacOS X */
#endif
#include <FL/Fl_Export.H>
extern FL_EXPORT int fl_command_modifier();
extern FL_EXPORT int fl_control_modifier();
# define FL_COMMAND fl_command_modifier()
# define FL_CONTROL fl_control_modifier()

#endif /* FL_PLATFORM_TYPES_H */

#endif // FL_DOXYGEN
#endif /* FL_DOXYGEN */
Loading

0 comments on commit c720aae

Please sign in to comment.