[windows] Support fullscreen config + api & unfullscreen api

This commit is contained in:
Lea Anthony
2021-06-21 16:54:33 +10:00
parent 09cf223aa2
commit d137859d12
3 changed files with 56 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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<void(ICoreWebView2Controller *)> 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

View File

@@ -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 {