From d137859d1293e0bfe65c56044bf38b6317a7f83e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 21 Jun 2021 16:54:33 +1000 Subject: [PATCH] [windows] Support fullscreen config + api & unfullscreen api --- v2/internal/ffenestri/ffenestri_windows.cpp | 44 +++++++++++++++++++ v2/internal/ffenestri/ffenestri_windows.h | 7 +++ v2/internal/ffenestri/wv2ComHandler_windows.h | 7 ++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/v2/internal/ffenestri/ffenestri_windows.cpp b/v2/internal/ffenestri/ffenestri_windows.cpp index f1243722..41027715 100644 --- a/v2/internal/ffenestri/ffenestri_windows.cpp +++ b/v2/internal/ffenestri/ffenestri_windows.cpp @@ -85,6 +85,9 @@ struct Application *NewApplication(const char *title, int width, int height, int // Startup url result->startupURL = nullptr; + // Used to remember the window location when going fullscreen + result->previousPlacement = { sizeof(result->previousPlacement) }; + return result; } @@ -460,6 +463,10 @@ void Run(struct Application* app, int argc, char **argv) { return; } + if ( app->fullscreen ) { + fullscreen(app); + } + // Credit: https://stackoverflow.com/a/35482689 if( app->disableWindowIcon && app->frame == 1 ) { int extendedStyle = GetWindowLong(app->window, GWL_EXSTYLE); @@ -742,10 +749,47 @@ void SetTitle(struct Application* app, const char *title) { ); } +void fullscreen(struct Application* app) { + + // Ensure we aren't in fullscreen + if (app->isFullscreen) return; + + app->isFullscreen = true; + app->previousWindowStyle = GetWindowLong(app->window, GWL_STYLE); + MONITORINFO mi = { sizeof(mi) }; + if (GetWindowPlacement(app->window, &(app->previousPlacement)) && GetMonitorInfo(MonitorFromWindow(app->window, MONITOR_DEFAULTTOPRIMARY), &mi)) { + SetWindowLong(app->window, GWL_STYLE, app->previousWindowStyle & ~WS_OVERLAPPEDWINDOW); + SetWindowPos(app->window, HWND_TOP, + mi.rcMonitor.left, + mi.rcMonitor.top, + mi.rcMonitor.right - mi.rcMonitor.left, + mi.rcMonitor.bottom - mi.rcMonitor.top, + SWP_NOOWNERZORDER | SWP_FRAMECHANGED); + } +} + void Fullscreen(struct Application* app) { + ON_MAIN_THREAD( + fullscreen(app); + show(app); + ); +} + +void unfullscreen(struct Application* app) { + if (app->isFullscreen) { + SetWindowLong(app->window, GWL_STYLE, app->previousWindowStyle); + SetWindowPlacement(app->window, &(app->previousPlacement)); + SetWindowPos(app->window, NULL, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | + SWP_NOOWNERZORDER | SWP_FRAMECHANGED); + app->isFullscreen = false; + } } void UnFullscreen(struct Application* app) { + ON_MAIN_THREAD( + unfullscreen(app); + ); } void ToggleFullscreen(struct Application* app) { diff --git a/v2/internal/ffenestri/ffenestri_windows.h b/v2/internal/ffenestri/ffenestri_windows.h index 1da22dc9..5147b1f0 100644 --- a/v2/internal/ffenestri/ffenestri_windows.h +++ b/v2/internal/ffenestri/ffenestri_windows.h @@ -47,6 +47,11 @@ struct Application{ COREWEBVIEW2_COLOR backgroundColour; bool disableWindowIcon; + // Used by fullscreen/unfullscreen + bool isFullscreen; + WINDOWPLACEMENT previousPlacement; + DWORD previousWindowStyle; + // placeholders char* bindings; char* initialCode; @@ -60,6 +65,8 @@ typedef std::function comHandlerCallback; void center(struct Application*); void setTitle(struct Application* app, const char *title); +void fullscreen(struct Application* app); +void unfullscreen(struct Application* app); char* LPWSTRToCstr(LPWSTR input); // called when the DOM is ready diff --git a/v2/internal/ffenestri/wv2ComHandler_windows.h b/v2/internal/ffenestri/wv2ComHandler_windows.h index 22d81e8c..d2817c91 100644 --- a/v2/internal/ffenestri/wv2ComHandler_windows.h +++ b/v2/internal/ffenestri/wv2ComHandler_windows.h @@ -71,8 +71,11 @@ class wv2ComHandler return S_OK; } else if (strcmp(m, "wails-drag") == 0) { - ReleaseCapture(); - SendMessage(this->window, WM_NCLBUTTONDOWN, HTCAPTION, 0); + // We don't drag in fullscreen mode + if (!app->isFullscreen) { + ReleaseCapture(); + SendMessage(this->window, WM_NCLBUTTONDOWN, HTCAPTION, 0); + } return S_OK; } else {