Make hybrid Wayland/X11 platform.

This commit is contained in:
ManoloFLTK
2022-03-15 06:42:06 +01:00
parent 28981f6fd3
commit c720aae515
93 changed files with 1310 additions and 529 deletions
+1 -1
View File
@@ -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.
+2
View File
@@ -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.
@@ -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();
};
+3 -2
View File
@@ -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();
+4
View File
@@ -82,6 +82,7 @@ public:
int printable_rect(int *w, int *h);
Fl_Offscreen offscreen();
void rescale();
Fl_Image_Surface *as_image_surface();
};
@@ -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;
@@ -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.
+13
View File
@@ -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;
@@ -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
+2 -2
View File
@@ -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;
@@ -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)
+45 -57
View File
@@ -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
@@ -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)
----------------------------------------------------------
@@ -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;
#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__ */
/* 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
#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 */
+30 -11
View File
@@ -1,7 +1,7 @@
//
// Wayland platform header file for the Fast Light Tool Kit (FLTK).
// Wayland/X11 hybrid platform header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2021 by Bill Spitzak and others.
// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -18,16 +18,35 @@
# error "Never use <FL/wayland.H> directly; include <FL/platform.H> instead."
#endif // !FL_PLATFORM_H
typedef struct wld_window *Window;
/** \file
Definitions of functions specific to the Wayland platform.
*/
struct flCairoRegion {
int count;
struct _cairo_rectangle *rects;
}; // a region is the union of a series of rectangles
// *********** for Wayland component ***********
#include <stdint.h>
typedef struct _cairo cairo_t;
FL_EXPORT struct wl_display *fl_wl_display();
FL_EXPORT struct wl_surface *fl_wl_surface(Window xid);
FL_EXPORT cairo_t *fl_wl_cairo();
/** Returns the Wayland display in use */
extern FL_EXPORT struct wl_display *fl_wl_display();
/** Returns the wl_surface associated to a shown window */
extern FL_EXPORT struct wl_surface *fl_wl_surface(struct wld_window *xid);
/** Returns a platform-specific reference associated to a shown window */
extern FL_EXPORT struct wld_window *fl_wl_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to a given the platform-specific window reference */
extern FL_EXPORT Fl_Window *fl_wl_find(struct wld_window *);
/** Returns the cairo context associated to the current window*/
extern FL_EXPORT cairo_t *fl_wl_cairo();
typedef void *EGLContext;
/** Returns the EGLContext corresponding to the given GLContext */
extern FL_EXPORT EGLContext fl_wl_glcontext(GLContext rc);
/** Prevent the FLTK library from using its wayland backend.
Call this early in your main(), before fl_open_display() runs. */
extern FL_EXPORT void fl_disable_wayland();
#ifndef FL_DOXYGEN
// *********** for X11 component ***********
# include "x11.H"
#endif // FL_DOXYGEN
+26 -1
View File
@@ -18,7 +18,25 @@
// include this file if _WIN32 is defined. This is to encourage
// portability of even the system-specific code...
#ifndef FL_DOXYGEN
#ifdef FL_DOXYGEN
/** \file
Definitions of functions specific to the Windows platform.
*/
/** Returns the Windows-specific window reference corresponding to the given Fl_Window object */
extern HWND fl_win32_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to the given Windows-specific window reference */
extern Fl_Window *fl_win32_find(HWND);
/** Returns the Windows-specific GL rendering context corresponding to the given GLContext */
extern HGLRC fl_win32_glcontext(GLContext rc);
/** Returns the Windows-specific graphics context for the current window */
extern HDC fl_win32_gc();
/** Returns the Windows-specific display in use */
extern HINSTANCE fl_win32_display();
#else
#ifndef FL_PLATFORM_H
# error "Never use <FL/win32.H> directly; include <FL/platform.H> instead."
#endif // !FL_PLATFORM_H
@@ -26,6 +44,11 @@
#include <windows.h>
typedef HWND Window;
typedef struct HGLRC__ *HGLRC;
extern FL_EXPORT HGLRC fl_win32_glcontext(GLContext rc);
extern FL_EXPORT HWND fl_win32_xid(const Fl_Window *win);
extern FL_EXPORT Fl_Window *fl_win32_find(HWND);
// this part is included only when compiling the FLTK library or if requested explicitly
#if defined(FL_LIBRARY) || defined(FL_INTERNALS)
@@ -60,7 +83,9 @@ FL_EXPORT HBRUSH fl_brush(); // allocates a brush if necessary
FL_EXPORT HBRUSH fl_brush_action(int); // now does the real work
extern FL_EXPORT HINSTANCE fl_display;
extern FL_EXPORT HINSTANCE fl_win32_display();
extern FL_EXPORT HDC fl_gc;
extern FL_EXPORT HDC fl_win32_gc();
extern FL_EXPORT MSG fl_msg;
extern FL_EXPORT HDC fl_GetDC(Window);
extern FL_EXPORT HDC fl_makeDC(HBITMAP);
+23 -1
View File
@@ -18,7 +18,22 @@
// include this file if FLTK_USE_X11 is defined. This is to encourage
// portability of even the system-specific code...
#ifndef FL_DOXYGEN
#ifdef FL_DOXYGEN
/** \file
Definitions of functions specific to the X11 platform.
*/
/** Returns the X11 Display in use */
extern Display *fl_x11_display();
/** Returns the Window reference for the given Fl_Window, or zero if not \c shown(). */
extern Window fl_x11_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to the given Window reference. */
extern Fl_Window *fl_x11_find(Window xid);
/** Returns the X11-specific currently active graphics context. */
extern GC fl_x11_gc();
#else // ! FL_DOXYGEN
#ifndef FL_PLATFORM_H
# error "Never use <FL/x11.H> directly; include <FL/platform.H> instead."
@@ -36,14 +51,21 @@
#endif
#include <X11/Xatom.h>
typedef struct __GLXcontextRec *GLXContext;
extern GLXContext fl_x11_glcontext(GLContext rc);
// constant info about the X server connection:
extern FL_EXPORT Display *fl_display;
extern FL_EXPORT Display *fl_x11_display();
extern FL_EXPORT Window fl_x11_xid(const Fl_Window *win);
extern FL_EXPORT Fl_Window *fl_x11_find(Window);
extern FL_EXPORT int fl_screen;
extern FL_EXPORT XVisualInfo *fl_visual;
extern FL_EXPORT Colormap fl_colormap;
// drawing functions:
extern FL_EXPORT GC fl_gc;
extern FL_EXPORT GC fl_x11_gc();
FL_EXPORT ulong fl_xpixel(Fl_Color i);
FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);