Add CMake option FLTK_OPTION_PEN_SUPPORT (default: ON)

This option can be used to disable pen/tablet support if there are
build problems on a particular platform or build system (e.g. MinGW)
so users can continue to build FLTK 1.5.

Users can also choose to disable pen support if they don't need it.
This commit is contained in:
Albrecht Schlosser 2026-01-08 21:22:03 +01:00
parent 7fae181d95
commit 4908dfd72a
11 changed files with 88 additions and 18 deletions

View File

@ -468,6 +468,7 @@ option(FLTK_BUILD_SHARED_LIBS
option(FLTK_OPTION_PRINT_SUPPORT "allow print support" ON)
option(FLTK_OPTION_FILESYSTEM_SUPPORT "allow file system support" ON)
option(FLTK_OPTION_PEN_SUPPORT "include Pen/Tablet support" ON)
option(FLTK_BUILD_FORMS "Build forms compatibility library" OFF)
option(FLTK_BUILD_FLUID "Build FLUID" ON)
@ -481,12 +482,21 @@ else()
option(FLTK_BUILD_TEST "Build test/demo programs" OFF)
endif()
# set variables to generate config.h or fl_config.h
if(FLTK_BUILD_FORMS)
set(FLTK_HAVE_FORMS 1)
else()
set(FLTK_HAVE_FORMS 0)
endif()
if(FLTK_OPTION_PEN_SUPPORT)
set(FLTK_HAVE_PEN_SUPPORT 1)
else()
set(FLTK_HAVE_PEN_SUPPORT 0)
endif()
#######################################################################
if(DOXYGEN_FOUND)
option(FLTK_BUILD_HTML_DOCS "build html docs" ON)

View File

@ -397,9 +397,12 @@ fl_summary_build("Static libraries" lib TRUE "n/a")
fl_summary_build("Shared libraries" lib FLTK_BUILD_SHARED_LIBS FLTK_BUILD_SHARED_LIBS)
fl_summary_build("The forms library" lib FLTK_BUILD_FORMS FLTK_BUILD_FORMS)
fl_summary_build("The OpenGL library" lib FLTK_USE_GL FLTK_BUILD_GL)
fl_summary_build("Pen/tablet support" lib FLTK_OPTION_PEN_SUPPORT FLTK_OPTION_PEN_SUPPORT)
message(STATUS "")
fl_summary_build("fluid" bin FLTK_BUILD_FLUID FLTK_BUILD_FLUID)
fl_summary_build("fltk-options" bin FLTK_BUILD_FLTK_OPTIONS FLTK_BUILD_FLTK_OPTIONS)
fl_summary_build("Test programs" bin/test FLTK_BUILD_TEST FLTK_BUILD_TEST)
fl_summary_build("Example programs" bin/examples FLTK_BUILD_EXAMPLES FLTK_BUILD_EXAMPLES)
fl_summary_build("Screenshot programs" bin/screenshots FLTK_BUILD_SCREENSHOTS FLTK_BUILD_SCREENSHOTS)

View File

@ -285,6 +285,16 @@ FLTK_OPTION_OPTIM - default EMPTY
"-Wall -Wno-deprecated-declarations". Example:
cmake -D FLTK_BUILD_EXAMPLES=on -D FLTK_OPTION_OPTIM="-Wall -Wextra -pedantic" ..
FLTK_OPTION_PEN_SUPPORT - default ON
Pen support is relatively small and should be included by default, but
this option allows to switch it off if not needed.
Note: on some older systems or build platforms (notably "classic" MinGW)
compiling and building pen support may not be possible. As of this writing
(Jan. 2026) we don't use dynamic (CMake) tests to find out whether building
is possible or not. Instead users are encouraged to report build errors and
switch this option off to allow to proceed building FLTK 1.5.0.
Note: this option is WIP and may be removed later w/o further notice.
FLTK_OPTION_PRINT_SUPPORT - default ON
When turned off, the Fl_Printer class does nothing and the
Fl_PostScript_File_Device class cannot be used, but the FLTK library

View File

@ -356,3 +356,17 @@
*/
#cmakedefine01 HAVE_CURSOR_SHAPE
/*
* FLTK_HAVE_PEN_SUPPORT
*
* Do we have pen/tablet support for the current platform?
* See CMake option FLTK_OPTION_PEN_SUPPORT
*
* Note: this option is "hidden" in 'config.h', i.e. it's not (yet)
* publicly accessibe. Move this to 'fl_config.h' to make it public.
*
*/
#cmakedefine FLTK_HAVE_PEN_SUPPORT 1

View File

@ -241,7 +241,6 @@ if(FLTK_USE_X11 AND NOT FLTK_USE_WAYLAND)
drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
drivers/X11/fl_X11_platform_init.cxx
drivers/Base/Fl_Base_Pen_Events.cxx
Fl_x.cxx
fl_dnd_x.cxx
Fl_Native_File_Chooser_FLTK.cxx
@ -291,7 +290,6 @@ if(FLTK_USE_X11 AND NOT FLTK_USE_WAYLAND)
drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H
drivers/Xlib/Fl_Xlib_Image_Surface_Driver.H
drivers/Unix/Fl_Unix_System_Driver.H
drivers/Base/Fl_Base_Pen_Events.H
)
if(FLTK_USE_CAIRO)
set(DRIVER_HEADER_FILES ${DRIVER_HEADER_FILES}
@ -319,7 +317,6 @@ elseif(FLTK_USE_WAYLAND)
drivers/Wayland/fl_wayland_clipboard_dnd.cxx
drivers/Wayland/fl_wayland_platform_init.cxx
drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
drivers/Base/Fl_Base_Pen_Events.cxx
Fl_Native_File_Chooser_FLTK.cxx
Fl_Native_File_Chooser_GTK.cxx
)
@ -351,7 +348,6 @@ elseif(FLTK_USE_WAYLAND)
drivers/Wayland/Fl_Wayland_Copy_Surface_Driver.H
drivers/Wayland/Fl_Wayland_Image_Surface_Driver.H
drivers/Unix/Fl_Unix_System_Driver.H
drivers/Base/Fl_Base_Pen_Events.H
)
elseif(APPLE)
@ -373,7 +369,6 @@ elseif(APPLE)
drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
drivers/Posix/Fl_Posix_System_Driver.cxx
drivers/Darwin/Fl_Darwin_System_Driver.cxx
drivers/Base/Fl_Base_Pen_Events.cxx
Fl_get_key_mac.cxx
drivers/Darwin/fl_macOS_platform_init.cxx
)
@ -387,7 +382,6 @@ elseif(APPLE)
drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.H
drivers/Quartz/Fl_Font.H
drivers/Quartz/Fl_Quartz_Image_Surface_Driver.H
drivers/Base/Fl_Base_Pen_Events.H
)
else()
@ -399,7 +393,6 @@ else()
drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx
drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx
drivers/WinAPI/Fl_WinAPI_Pen_Driver.cxx
drivers/GDI/Fl_GDI_Graphics_Driver.cxx
drivers/GDI/Fl_GDI_Graphics_Driver_arci.cxx
drivers/GDI/Fl_GDI_Graphics_Driver_color.cxx
@ -410,7 +403,6 @@ else()
drivers/GDI/Fl_GDI_Graphics_Driver_vertex.cxx
drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx
drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
drivers/Base/Fl_Base_Pen_Events.cxx
Fl_win32.cxx
fl_dnd_win32.cxx
Fl_Native_File_Chooser_WIN32.cxx
@ -425,11 +417,29 @@ else()
drivers/GDI/Fl_Font.H
drivers/GDI/Fl_GDI_Copy_Surface_Driver.H
drivers/GDI/Fl_GDI_Image_Surface_Driver.H
drivers/Base/Fl_Base_Pen_Events.H
)
# Optional Pen/Tablet Support
if(FLTK_OPTION_PEN_SUPPORT)
list(APPEND DRIVER_FILES
drivers/WinAPI/Fl_WinAPI_Pen_Driver.cxx
)
endif(FLTK_OPTION_PEN_SUPPORT)
endif(FLTK_USE_X11 AND NOT FLTK_USE_WAYLAND)
# Common Pen/Tablet Support Files
if(FLTK_OPTION_PEN_SUPPORT)
list(APPEND DRIVER_FILES
drivers/Base/Fl_Base_Pen_Events.cxx
)
list(APPEND DRIVER_HEADER_FILES
drivers/Base/Fl_Base_Pen_Events.H
)
endif(FLTK_OPTION_PEN_SUPPORT)
source_group("Header Files" FILES ${HEADER_FILES})
source_group("Private Header Files" FILES ${PRIVATE_HEADER_FILES})
source_group("Driver Source Files" FILES ${DRIVER_FILES})
@ -632,10 +642,14 @@ if(APPLE AND NOT FLTK_BACKEND_X11)
set(MMFILES
Fl_cocoa.mm
drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
drivers/Cocoa/Fl_Cocoa_Pen_Events.mm
Fl_Native_File_Chooser_MAC.mm
Fl_MacOS_Sys_Menu_Bar.mm
)
if(FLTK_OPTION_PEN_SUPPORT)
list(APPEND MMFILES
drivers/Cocoa/Fl_Cocoa_Pen_Events.mm
)
endif()
source_group("ObjC Source Files" FILES ${MMFILES})
else()
set(MMFILES)

View File

@ -72,7 +72,7 @@ extern int fl_send_system_handlers(void *e);
// converting cr lf converter function
static void createAppleMenu(void);
static void cocoaMouseHandler(NSEvent *theEvent);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) && defined(FLTK_HAVE_PEN_SUPPORT)
static bool cocoaTabletHandler(NSEvent *theEvent, bool lock);
extern bool fl_cocoa_tablet_handler(NSEvent*, Fl_Window*);
#endif
@ -631,7 +631,7 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation;
#endif
- (BOOL)did_view_resolution_change;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) && defined(FLTK_HAVE_PEN_SUPPORT)
- (void)tabletProximity:(NSEvent *)theEvent;
- (void)tabletPoint:(NSEvent *)theEvent;
#endif
@ -1057,6 +1057,7 @@ static void cocoaMagnifyHandler(NSEvent *theEvent)
#endif
}
#if defined(FLTK_HAVE_PEN_SUPPORT)
static bool cocoaTabletHandler(NSEvent *theEvent, bool lock)
{
@ -1067,6 +1068,8 @@ static bool cocoaTabletHandler(NSEvent *theEvent, bool lock)
return ret;
}
#endif // FLTK_HAVE_PEN_SUPPORT
namespace Fl {
namespace Private {
// Global mouse position at mouse down event
@ -1084,6 +1087,7 @@ static void cocoaMouseHandler(NSEvent *theEvent)
fl_lock_function();
#if defined(FLTK_HAVE_PEN_SUPPORT)
// Handle tablet proximity and point subevents
if ( ([theEvent type] != NSEventTypeMouseEntered) // does not have a subtype
&& ([theEvent type] != NSEventTypeMouseExited) ) // does not have a subtype
@ -1098,6 +1102,7 @@ static void cocoaMouseHandler(NSEvent *theEvent)
// else fall through into mouse event handling
}
}
#endif // FLTK_HAVE_PEN_SUPPORT
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
if (!window || !window->shown() ) {
@ -2635,7 +2640,7 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
- (void)mouseExited:(NSEvent *)theEvent {
cocoaMouseHandler(theEvent);
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) && defined(FLTK_HAVE_PEN_SUPPORT)
- (void)tabletProximity:(NSEvent *)theEvent {
cocoaTabletHandler(theEvent, true);
}

View File

@ -14,6 +14,7 @@
// https://www.fltk.org/bugs.php
//
#include <config.h>
#include <FL/Fl.H>
#include "Fl_Screen_Driver.H"
@ -27,6 +28,8 @@
void Fl::grab(Fl_Window *win)
{
#if defined(FLTK_HAVE_PEN_SUPPORT)
Fl::Pen::release();
#endif
screen_driver()->grab(win);
}

View File

@ -1837,9 +1837,11 @@ content key keyboard layout
return 0;
default: {
#if defined(FLTK_HAVE_PEN_SUPPORT)
LRESULT ret = fl_win32_tablet_handler(fl_msg);
if (ret != -1)
return ret;
#endif
if (Fl::handle(0, 0))
return 0;
break; }

View File

@ -145,6 +145,8 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
return new Fl_Wayland_Image_Surface_Driver(w, h, high_res, off);
}
#if defined(FLTK_HAVE_PEN_SUPPORT)
namespace Fl {
namespace Pen {
Driver default_driver;
@ -152,3 +154,4 @@ Driver& driver = default_driver;
} // namespace Pen
} // namespace Fl
#endif // FLTK_HAVE_PEN_SUPPORT

View File

@ -75,9 +75,11 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
return new Fl_Xlib_Image_Surface_Driver(w, h, high_res, off);
}
#if defined(FLTK_HAVE_PEN_SUPPORT)
namespace Fl {
namespace Pen {
Driver default_driver;
Driver& driver = default_driver;
} // namespace Pen
} // namespace Fl
#endif // FLTK_HAVE_PEN_SUPPORT

View File

@ -183,7 +183,11 @@ fl_create_example(navigation navigation.cxx fltk::fltk)
fl_create_example(output output.cxx fltk::fltk)
fl_create_example(overlay overlay.cxx fltk::fltk)
fl_create_example(pack pack.cxx fltk::fltk)
fl_create_example(penpal penpal.cxx fltk::fltk)
if(FLTK_OPTION_PEN_SUPPORT)
fl_create_example(penpal penpal.cxx fltk::fltk)
endif()
fl_create_example(pixmap pixmap.cxx fltk::images)
fl_create_example(pixmap_browser pixmap_browser.cxx fltk::images)
fl_create_example(preferences preferences.fl fltk::fltk)