Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt

Use this file to discover all available pages before exploring further.

The Fl namespace is the FLTK global namespace containing state information and global methods for the current application. It provides the event loop, display management, timing functions, and other system-level functionality.

Event Loop Methods

These methods control the main event loop and application execution.

run()

Runs the main event loop.
int Fl::run();
Returns: 0 if all windows are closed, non-zero otherwise Description: Waits for and processes events until all windows are closed. This is the normal way to start event processing. Example:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>

int main() {
  Fl_Window *window = new Fl_Window(300, 200);
  window->show();
  return Fl::run();
}

wait()

Waits for an event and processes it.
int Fl::wait();
double Fl::wait(double time);
time
double
Maximum time to wait in seconds (optional)
Returns:
  • For wait(): non-zero if any windows are displayed
  • For wait(double): the time remaining (negative if time expired)
Description: Waits for events and processes them. Use this for more fine-grained control over event processing compared to run().

check()

Checks for events without waiting.
int Fl::check();
Returns: Same as wait() but returns immediately Description: Processes all pending events and returns immediately. This is useful for updating the display while performing a long operation. Example:
for (int i = 0; i < 1000; i++) {
  // Do some work
  Fl::check();  // Keep GUI responsive
}

ready()

Checks if there are pending events.
int Fl::ready();
Returns: True if there are events to be processed

Timeout and Idle Callbacks

Methods for scheduling deferred and repeated callbacks.

add_timeout()

Adds a one-shot timer callback.
void Fl::add_timeout(double t, Fl_Timeout_Handler cb, void *data = 0);
t
double
required
Time in seconds before callback is called
cb
Fl_Timeout_Handler
required
Function to call when timeout expires
data
void*
User data passed to callback (optional)
Example:
void timeout_callback(void* data) {
  printf("Timeout fired!\n");
  Fl::redraw();
}

Fl::add_timeout(1.0, timeout_callback);

repeat_timeout()

Reschedules a timeout for repeated callbacks.
void Fl::repeat_timeout(double t, Fl_Timeout_Handler cb, void *data = 0);
t
double
required
Time in seconds before callback is called again
cb
Fl_Timeout_Handler
required
Function to call when timeout expires
data
void*
User data passed to callback
Description: Call this from inside a timeout callback to reschedule it.

remove_timeout()

Removes a timeout callback.
void Fl::remove_timeout(Fl_Timeout_Handler cb, void *data = 0);
cb
Fl_Timeout_Handler
required
Callback function to remove
data
void*
User data associated with the callback

add_idle()

Adds an idle callback.
void Fl::add_idle(Fl_Idle_Handler cb, void* data = 0);
cb
Fl_Idle_Handler
required
Function to call when idle
data
void*
User data passed to callback
Description: Idle callbacks are called when there are no pending events. They run continuously when the application is idle.

remove_idle()

Removes an idle callback.
void Fl::remove_idle(Fl_Idle_Handler cb, void* data = 0);

Screen and Display Methods

screen_count()

Returns the number of screens.
int Fl::screen_count();
Returns: Number of available screens

screen_xywh()

Gets screen dimensions.
void Fl::screen_xywh(int &X, int &Y, int &W, int &H);
void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n);
void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
X, Y, W, H
int&
required
Output parameters for screen position and size
n
int
Screen number (optional)
mx, my
int
Mouse position to determine which screen (optional)

screen_scale()

Gets or sets screen scaling factor.
float Fl::screen_scale(int n);
void Fl::screen_scale(int n, float factor);
n
int
required
Screen number
factor
float
Scaling factor to set (for setter)
Description: Screen scaling supports high-DPI displays. The scaling factor is initialized from the OS and can be adjusted programmatically.

redraw()

Schedules all windows for redrawing.
void Fl::redraw();
Description: Marks all windows as needing to be redrawn on the next wait() or flush().

flush()

Forces all pending drawing to be completed.
void Fl::flush();
Description: Causes all windows to be redrawn if they need it, and empties the display queue.

Color Methods

set_color()

Sets an entry in the color map.
void Fl::set_color(Fl_Color i, uchar r, uchar g, uchar b);
void Fl::set_color(Fl_Color i, unsigned c);
i
Fl_Color
required
Color index to set
r, g, b
uchar
required
RGB color components (0-255)
c
unsigned
RGB color as 32-bit value

get_color()

Gets a color from the color map.
unsigned Fl::get_color(Fl_Color i);
void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
i
Fl_Color
required
Color index to get
red, green, blue
uchar&
Output parameters for RGB components

Scheme Methods

scheme()

Gets or sets the current widget scheme.
const char* Fl::scheme();
int Fl::scheme(const char *name);
name
const char*
Scheme name: “none”, “base”, “gtk+”, “gleam”, “plastic”, or “oxy”
Returns:
  • Getter: Current scheme name or NULL for default
  • Setter: 1 if successful, 0 if scheme not found
Example:
Fl::scheme("gtk+");  // Use GTK+ style

is_scheme()

Checks if a specific scheme is active.
int Fl::is_scheme(const char *name);
name
const char*
required
Lowercase scheme name to check
Returns: 1 if the scheme is active, 0 otherwise

Font Methods

set_fonts()

Enumerates available system fonts.
Fl_Font Fl::set_fonts(const char* xfontname = 0);
xfontname
const char*
X11 font pattern (platform-specific)
Returns: Number of fonts in the table

get_font()

Gets the name of a font.
const char* Fl::get_font(Fl_Font font);
font
Fl_Font
required
Font index
Returns: Font name

set_font()

Changes a font in the table.
void Fl::set_font(Fl_Font font, const char* name);
void Fl::set_font(Fl_Font font, Fl_Font from);
font
Fl_Font
required
Font index to change
name
const char*
New font name
from
Fl_Font
Copy font from this index

Window Management

first_window()

Gets the first top-level window.
Fl_Window* Fl::first_window();
Returns: Pointer to first window or NULL

next_window()

Gets the next window in the window list.
Fl_Window* Fl::next_window(const Fl_Window* window);
window
const Fl_Window*
required
Current window
Returns: Pointer to next window or NULL Gets the current modal window.
Fl_Window* Fl::modal();
Returns: The topmost modal window or NULL

grab()

Gets or sets the window grabbing all events.
Fl_Window* Fl::grab();
void Fl::grab(Fl_Window* window);
window
Fl_Window*
Window to grab events, or NULL to release
Description: When grab is active, all events go to the grabbed window regardless of pointer or focus location.

Clipboard Methods

copy()

Copies data to clipboard or selection.
void Fl::copy(const char *stuff, int len, int destination = 0,
              const char *type = Fl::clipboard_plain_text);
stuff
const char*
required
Text data to copy
len
int
required
Length of data in bytes
destination
int
0 = selection buffer, 1 = clipboard, 2 = both
type
const char*
Data type (usually clipboard_plain_text)

paste()

Pastes data from clipboard or selection.
void Fl::paste(Fl_Widget &receiver, int source,
               const char *type = Fl::clipboard_plain_text);
receiver
Fl_Widget&
required
Widget that will receive FL_PASTE event
source
int
required
0 = selection buffer, 1 = clipboard
type
const char*
Requested data type

Version Information

api_version()

Returns the API version number.
int Fl::api_version();
Returns: API version as integer (e.g., 10400 for 1.4.0)

abi_version()

Returns the ABI version number.
int Fl::abi_version();
Returns: ABI version of the linked library

abi_check()

Checks if ABI version is compatible.
int Fl::abi_check(const int val = FL_ABI_VERSION);
val
int
ABI version to check against
Returns: 1 if compatible, 0 otherwise