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.

Fl_Window produces an actual window that can be a main window with borders and title bar, or a subwindow inside another window. Once created, add child widgets using window->add(child). The window’s callback is called when the user tries to close the window. The default callback calls hide().

Constructors

Fl_Window(int w, int h, const char *title = 0);
Fl_Window(int x, int y, int w, int h, const char *title = 0);
w, h
int
required
Width and height of the window in pixels
x, y
int
Position of the window (for positioned constructor)
title
const char*
Window title bar text (optional)
Description:
  • The (w, h) form creates a top-level window and asks the window manager to position it.
  • The (x, y, w, h) form creates a window at the specified location.
Example:
// Let window manager position it
Fl_Window *win1 = new Fl_Window(400, 300, "My Window");

// Position at (100, 100)
Fl_Window *win2 = new Fl_Window(100, 100, 400, 300, "Positioned");

Display Methods

show()

Displays the window on screen.
virtual void show();
void show(int argc, char **argv);
argc
int
Command-line argument count
argv
char**
Command-line argument vector
Description:
  • show() displays the window. If already shown, it is restored and raised to top.
  • show(argc, argv) is used for top-level windows and parses command-line arguments.
Example:
window->show();
return Fl::run();

hide()

Removes the window from the screen.
virtual void hide() override;
Description: If the window is already hidden or not shown, this does nothing.

shown()

Checks if window has been shown.
int shown() const;
Returns: Non-zero if show() has been called (but not hide()) Note: You can tell if a window is iconified with (w->shown() && !w->visible()).

iconize()

Iconifies the window.
void iconize();
Description: Minimizes the window. Call show() to restore it.

Size and Position

resize()

Changes window size and/or position.
void resize(int X, int Y, int W, int H) override;
X, Y
int
required
New position
W, H
int
required
New size
Description: For shown windows, changes are communicated to the window server. Window managers may refuse the size/position.

position()

Sets window position.
void position(int X, int Y);
X, Y
int
required
New window position
Description: Inherited from Fl_Widget, shortcut for resize(X, Y, w(), h()).

hotspot()

Positions window with mouse at specified point.
void hotspot(int x, int y, int offscreen = 0);
void hotspot(const Fl_Widget* widget, int offscreen = 0);
x, y
int
required
Position where mouse should point
widget
const Fl_Widget*
Widget to center mouse on
offscreen
int
Allow window to extend offscreen if non-zero

size_range()

Sets minimum and maximum window size.
void size_range(int minw, int minh, int maxw=0, int maxh=0, 
                int dw=0, int dh=0, int aspect=0);
minw, minh
int
required
Minimum width and height
maxw, maxh
int
Maximum width and height (0 = unlimited)
dw, dh
int
Width and height step increments
aspect
int
Flag to keep aspect ratio
Example:
window->size_range(300, 200, 800, 600);  // Min 300x200, max 800x600

Fullscreen

fullscreen()

Makes window fullscreen.
void fullscreen();
Description: Makes the window fill one or more screens without window manager borders.

fullscreen_off()

Returns from fullscreen mode.
void fullscreen_off();
void fullscreen_off(int X, int Y, int W, int H);
X, Y, W, H
int
Window dimensions to restore to (optional)

fullscreen_active()

Checks if fullscreen is active.
unsigned int fullscreen_active() const;
Returns: Non-zero if window is fullscreen

fullscreen_screens()

Sets which screens to use in fullscreen.
void fullscreen_screens(int top, int bottom, int left, int right);
top, bottom, left, right
int
required
Screen indices for each edge

Maximize

maximize()

Maximizes the window.
void maximize();
Description: Maximizes the window to fill available screen space.

un_maximize()

Restores window from maximized state.
void un_maximize();

maximize_active()

Checks if window is maximized.
unsigned int maximize_active() const;
Returns: Non-zero if window is maximized

Window Properties

label()

Gets or sets window title.
const char* label() const;
void label(const char* title);
void label(const char* label, const char* iconlabel);
title
const char*
required
Window title bar text
iconlabel
const char*
Text for iconified window

iconlabel()

Gets or sets icon label.
const char* iconlabel() const;
void iconlabel(const char* label);
label
const char*
required
Label for iconified window

xclass()

Gets or sets X11 class hint.
const char* xclass() const;
void xclass(const char* c);
c
const char*
required
X11 window class name

Window Icons

icon()

Sets the window icon.
void icon(const Fl_RGB_Image* img);
img
const Fl_RGB_Image*
required
Image to use as window icon

icons()

Sets multiple window icons.
void icons(const Fl_RGB_Image*[] images, int count);
images
const Fl_RGB_Image*[]
required
Array of icon images at different sizes
count
int
required
Number of images in array

Window Borders

border()

Gets or sets window border.
unsigned int border() const;
void border(int b);
b
int
required
1 to show border, 0 to hide
Description: Controls whether window manager border is shown. Must be called before show().

clear_border()

Turns off window border.
void clear_border();
Description: Fast inline function. Only works before show() is called.

set_override()

Activates override redirect.
void set_override();
Description: Sets NOBORDER and OVERRIDE flags for popup windows. Checks if window is modal.
unsigned int modal() const;
Returns: Non-zero if window is modal

set_modal()

Makes window modal.
void set_modal();
Description: Modal windows prevent events to other windows and remain on top.

non_modal()

Checks if window is non-modal.
unsigned int non_modal() const;
Returns: Non-zero if window is modal or non-modal

set_non_modal()

Makes window non-modal.
void set_non_modal();
Description: Non-modal windows stay on top but don’t block events to other windows.

clear_modal_states()

Clears modal and non-modal flags.
void clear_modal_states();
Description: Converts modal or non-modal window back to normal. Call hide() first, then change state, then show().

Special Window Types

set_menu_window()

Marks window as a menu window.
void set_menu_window();
Description: For internal use. Must be called before show(). Checks if window is a menu window.
unsigned int menu_window() const;
Returns: Non-zero if window is a menu window

set_tooltip_window()

Marks window as a tooltip window.
void set_tooltip_window();
Description: For internal use. Must be called before show().

tooltip_window()

Checks if window is a tooltip window.
unsigned int tooltip_window() const;
Returns: Non-zero if window is a tooltip window

Rendering

make_current()

Sets this window as the current drawing context.
void make_current();
Description: Sets up drawing functions to draw into this window. Useful for incremental updates.

current()

Gets the current window.
static Fl_Window *current();
Returns: Pointer to window that was last made current

flush()

Forces window to redraw.
virtual void flush();
Description: Forces the window to be drawn and makes it current.

Screen Information

screen_num()

Gets or sets which screen the window is on.
int screen_num() const;
void screen_num(int screen_num);
screen_num
int
required
Screen number to use

decorated_w(), decorated_h()

Gets window size including decorations.
int decorated_w() const;
int decorated_h() const;
Returns: Window width/height including title bar and borders Description: Returns same as w() or h() if window is not yet mapped.

Position Helper

x_root(), y_root()

Gets absolute screen position.
int x_root() const;
int y_root() const;
Returns: X or Y coordinate relative to screen origin

Cursor

cursor()

Sets the cursor for this window.
void cursor(Fl_Cursor cursor);
void cursor(const Fl_RGB_Image* img, int hotx, int hoty);
cursor
Fl_Cursor
required
Standard cursor type (FL_CURSOR_ARROW, FL_CURSOR_WAIT, etc.)
img
const Fl_RGB_Image*
Custom cursor image
hotx, hoty
int
Hot spot coordinates for custom cursor

default_cursor()

Sets the default cursor.
void default_cursor(Fl_Cursor cursor);
cursor
Fl_Cursor
required
Default cursor to use

Window Callbacks

default_callback()

Default callback for windows.
static void default_callback(Fl_Window* window, void* v);
window
Fl_Window*
required
Window receiving callback
v
void*
User data
Description: Default callback calls hide() on the window.

Type Checking

as_window()

Returns this as an Fl_Window pointer.
Fl_Window* as_window() override;
Returns: Pointer to this window

Example

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>

void button_callback(Fl_Widget*, void*) {
  printf("Button clicked!\n");
}

int main() {
  Fl_Window *window = new Fl_Window(400, 300, "My Application");
  window->begin();
  
  Fl_Button *button = new Fl_Button(150, 125, 100, 50, "Click Me");
  button->callback(button_callback);
  
  window->end();
  window->show();
  
  return Fl::run();
}