Fix Windows: fullscreen_off does not correctly preserve window size (#1116)

This commit is contained in:
ManoloFLTK 2024-11-09 15:35:06 +01:00
parent 85c23539fd
commit 018c3b19f5

View File

@ -577,24 +577,32 @@ void Fl_WinAPI_Window_Driver::fullscreen_on() {
} }
static void delayed_maximize(Fl_Window *win){
Fl::remove_check((Fl_Timeout_Handler)delayed_maximize, win);
win->un_maximize();
win->maximize();
}
void Fl_WinAPI_Window_Driver::fullscreen_off(int X, int Y, int W, int H) { void Fl_WinAPI_Window_Driver::fullscreen_off(int X, int Y, int W, int H) {
pWindow->_clear_fullscreen(); pWindow->_clear_fullscreen();
DWORD style = GetWindowLong(fl_xid(pWindow), GWL_STYLE); DWORD style = GetWindowLong(fl_xid(pWindow), GWL_STYLE);
if (pWindow->border()) style |= WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_CAPTION;
// Remove the xid temporarily so that Fl_WinAPI_Window_Driver::fake_X_wm() behaves like it // Remove the xid temporarily so that Fl_WinAPI_Window_Driver::fake_X_wm() behaves like it
// does in Fl_WinAPI_Window_Driver::makeWindow(). // does in Fl_WinAPI_Window_Driver::makeWindow().
HWND xid = fl_xid(pWindow); HWND xid = fl_xid(pWindow);
Fl_X::flx(pWindow)->xid = 0; Fl_X::flx(pWindow)->xid = 0;
int wx, wy, bt, bx, by; int wx, wy, bt, bx, by;
switch (fake_X_wm(wx, wy, bt, bx, by)) { switch (fake_X_wm(wx, wy, bt, bx, by, style)) {
case 0: case 0:
break; break;
case 1: case 1:
style |= WS_CAPTION; style |= WS_CAPTION;
break; break;
case 2: case 2:
if (border()) { /*if (border()) {
style |= WS_THICKFRAME | WS_CAPTION; style |= WS_THICKFRAME | WS_CAPTION;
} }*/
break; break;
} }
Fl_X::flx(pWindow)->xid = (fl_uintptr_t)xid; Fl_X::flx(pWindow)->xid = (fl_uintptr_t)xid;
@ -610,10 +618,10 @@ void Fl_WinAPI_Window_Driver::fullscreen_off(int X, int Y, int W, int H) {
scaledW += bx*2; scaledW += bx*2;
scaledH += by*2+bt; scaledH += by*2+bt;
SetWindowLong(fl_xid(pWindow), GWL_STYLE, style); SetWindowLong(fl_xid(pWindow), GWL_STYLE, style);
if (pWindow->maximize_active()) return this->maximize();
SetWindowPos(fl_xid(pWindow), 0, scaledX, scaledY, scaledW, scaledH, SetWindowPos(fl_xid(pWindow), 0, scaledX, scaledY, scaledW, scaledH,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED); SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
Fl::handle(FL_FULLSCREEN, pWindow); Fl::handle(FL_FULLSCREEN, pWindow);
if (pWindow->maximize_active()) Fl::add_check((Fl_Timeout_Handler)delayed_maximize, pWindow);
} }