fltk/src/Fl_Window_fullscreen.cxx
ManoloFLTK 6e922b8005 macOS: Fix "Full screen broken on macOS in FLTK 1.3.10 (regression)" (#1192)
FLTK now supports 2 types of fullscreen modes under macOS:
1) normal macOS fullscreen mode where the menubar and titlebar appear when mouse is moved to top of screen
and the window covers one screen only;
2) multiple-screen mode that requires calling Fl_Window::fullscreen_screens() before.

This commit fixes all possible transitions between these fullscreen modes and normal window mode.
2025-01-30 11:14:17 +01:00

90 lines
2.6 KiB
C++

//
// Fullscreen window support for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 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
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
#include <FL/Fl_Window.H>
#include "Fl_Window_Driver.H"
void Fl_Window::border(int b) {
if (b) {
if (border()) return;
clear_flag(NOBORDER);
} else {
if (!border()) return;
set_flag(NOBORDER);
}
pWindowDriver->use_border();
}
/* Note: The previous implementation toggled border(). With this new
implementation this is not necessary. Additionally, if we do that,
the application may lose focus when switching out of fullscreen
mode with some window managers. Besides, the API does not say that
the FLTK border state should be toggled; it only says that the
borders should not be *visible*.
*/
void Fl_Window::fullscreen() {
if (!is_resizable()) return;
if (!maximize_active()) {
no_fullscreen_x = x();
no_fullscreen_y = y();
no_fullscreen_w = w();
no_fullscreen_h = h();
}
if (shown() && !(flags() & Fl_Widget::FULLSCREEN)) {
pWindowDriver->fullscreen_on();
} else {
set_flag(FULLSCREEN);
}
}
void Fl_Window::fullscreen_off(int X,int Y,int W,int H) {
if (shown() && (flags() & Fl_Widget::FULLSCREEN)) {
pWindowDriver->fullscreen_off(X, Y, W, H);
} else {
clear_flag(FULLSCREEN);
}
if (!maximize_active())
no_fullscreen_x = no_fullscreen_y = no_fullscreen_w = no_fullscreen_h = 0;
}
void Fl_Window::fullscreen_off() {
if (!no_fullscreen_x && !no_fullscreen_y) {
// Window was initially created fullscreen - default to current monitor
no_fullscreen_x = x();
no_fullscreen_y = y();
}
fullscreen_off(no_fullscreen_x, no_fullscreen_y, no_fullscreen_w, no_fullscreen_h);
}
void Fl_Window::fullscreen_screens(int top, int bottom, int left, int right) {
if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
fullscreen_screen_top = -1;
fullscreen_screen_bottom = -1;
fullscreen_screen_left = -1;
fullscreen_screen_right = -1;
pWindowDriver->fullscreen_screens(false);
} else {
fullscreen_screen_top = top;
fullscreen_screen_bottom = bottom;
fullscreen_screen_left = left;
fullscreen_screen_right = right;
pWindowDriver->fullscreen_screens(true);
}
if (shown() && fullscreen_active())
pWindowDriver->fullscreen_on();
}