From 34598c29022c31efaeadcd30a7337c2088f9b29c Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Tue, 26 May 2020 14:23:48 -0500 Subject: [PATCH 1/4] Native: add initWindow, rename init -> initApp --- src/Core/App.re | 4 ++-- src/Core/Window.re | 2 ++ src/Native/Initialization.re | 6 ++++-- src/Native/Revery_Native.c | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Core/App.re b/src/Core/App.re index e15c86d7b..720c9a4b4 100644 --- a/src/Core/App.re +++ b/src/Core/App.re @@ -48,7 +48,7 @@ let quit = (~askNicely=false, ~code=0, app: t) => { }; if (Hashtbl.length(app.windows) == 0 || !askNicely) { - Revery_Native.uninit(); + Revery_Native.uninitApp(); // Verify [quit] wasn't called recursively from a beforeQuit handler if (!app.isQuitting) { @@ -253,7 +253,7 @@ let start = init => { let dispatchFileOpen = Event.dispatch(appInstance.onFileOpen); Callback.register("revery_dispatchFileOpen", dispatchFileOpen); - Revery_Native.init(); + Revery_Native.initApp(); let appLoop = () => { _flushEvents(); diff --git a/src/Core/Window.re b/src/Core/Window.re index eb36a6452..1152599b0 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -628,6 +628,8 @@ let create = (name: string, options: WindowCreateOptions.t) => { Internal.updateMetrics(window); + Revery_Native.initWindow(sdlWindow); + window; }; diff --git a/src/Native/Initialization.re b/src/Native/Initialization.re index 904bceebf..c669f3d19 100644 --- a/src/Native/Initialization.re +++ b/src/Native/Initialization.re @@ -1,3 +1,5 @@ -external init: unit => unit = "revery_initialize"; +external initApp: unit => unit = "revery_initializeApp"; +external uninitApp: unit => unit = "revery_uninitializeApp"; -external uninit: unit => unit = "revery_uninitialize"; +external _initWindow: Sdl2.Window.nativeWindow => unit = "revery_initializeWindow"; +let initWindow = (w: Sdl2.Window.t) => _initWindow(w |> Sdl2.Window.getNativeWindow); diff --git a/src/Native/Revery_Native.c b/src/Native/Revery_Native.c index 73a93b100..690b62e91 100644 --- a/src/Native/Revery_Native.c +++ b/src/Native/Revery_Native.c @@ -11,6 +11,7 @@ #ifdef WIN32 #include "ReveryWin32.h" #include +#include #elif __APPLE__ #include "ReveryCocoa.h" #import "ReveryAppDelegate.h" @@ -18,7 +19,7 @@ #include "ReveryGtk.h" #endif -CAMLprim value revery_initialize() { +CAMLprim value revery_initializeApp() { #ifdef __APPLE__ SDLAppDelegate *sdlDelegate = [NSApp delegate]; ReveryAppDelegate *delegate = [ReveryAppDelegate newWithSDLDelegate:sdlDelegate]; @@ -32,9 +33,23 @@ CAMLprim value revery_initialize() { return Val_unit; } -CAMLprim value revery_uninitialize() { +CAMLprim value revery_uninitializeApp() { #ifdef WIN32 CoUninitialize(); #endif return Val_unit; } + + +CAMLprim value revery_initializeWindow(value vWin) { + CAMLparam1(vWin); + void *win = (void *)vWin; +#ifdef WIN32 + HWND window = (HWND)win; + int current_style = GetWindowLong(window, GWL_STYLE); + SetWindowLong(window, GWL_STYLE, current_style | WS_CAPTION); +#else + UNUSED(win); +#endif + CAMLreturn(Val_unit); +} From 72ee94963138f0390c3e74400623a3998ac67a0f Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Tue, 26 May 2020 15:29:23 -0400 Subject: [PATCH 2/4] Formatting --- src/Native/Initialization.re | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Native/Initialization.re b/src/Native/Initialization.re index c669f3d19..e61654912 100644 --- a/src/Native/Initialization.re +++ b/src/Native/Initialization.re @@ -1,5 +1,7 @@ external initApp: unit => unit = "revery_initializeApp"; external uninitApp: unit => unit = "revery_uninitializeApp"; -external _initWindow: Sdl2.Window.nativeWindow => unit = "revery_initializeWindow"; -let initWindow = (w: Sdl2.Window.t) => _initWindow(w |> Sdl2.Window.getNativeWindow); +external _initWindow: Sdl2.Window.nativeWindow => unit = + "revery_initializeWindow"; +let initWindow = (w: Sdl2.Window.t) => + _initWindow(w |> Sdl2.Window.getNativeWindow); From 956503a01bd556ec6772b93bf9a9711c9854f89e Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Tue, 26 May 2020 15:53:21 -0400 Subject: [PATCH 3/4] Revery_Native: add clarifying comment --- src/Native/Revery_Native.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Native/Revery_Native.c b/src/Native/Revery_Native.c index 690b62e91..8f4639e04 100644 --- a/src/Native/Revery_Native.c +++ b/src/Native/Revery_Native.c @@ -45,6 +45,10 @@ CAMLprim value revery_initializeWindow(value vWin) { CAMLparam1(vWin); void *win = (void *)vWin; #ifdef WIN32 + /* This flag often gets unset when the window decoration is removed. + This Chromium comment is the source of this fix: + https://chromium.googlesource.com/chromium/src.git/+/46.0.2478.0/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc#71 + */ HWND window = (HWND)win; int current_style = GetWindowLong(window, GWL_STYLE); SetWindowLong(window, GWL_STYLE, current_style | WS_CAPTION); From f745e36dd85cce60c4d673d0155b69c9f39fd1ec Mon Sep 17 00:00:00 2001 From: Zach Baylin Date: Tue, 26 May 2020 14:23:48 -0500 Subject: [PATCH 4/4] Window: move where Maximize is placed so flag is set --- src/Core/Window.re | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/Window.re b/src/Core/Window.re index 1152599b0..4ab008547 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -600,10 +600,6 @@ let create = (name: string, options: WindowCreateOptions.t) => { setSize(~width, ~height, window); setVsync(window, options.vsync); - if (options.maximized) { - Sdl2.Window.maximize(sdlWindow); - }; - if (!options.decorated) { Sdl2.Window.setBordered(sdlWindow, false); }; @@ -621,6 +617,12 @@ let create = (name: string, options: WindowCreateOptions.t) => { | Transparent => Internal.setTitlebarTransparent(sdlWindow) }; + Revery_Native.initWindow(sdlWindow); + + if (options.maximized) { + Sdl2.Window.maximize(sdlWindow); + }; + // onivim/oni2#791 // Set a minimum size for the window // TODO: Make configurable @@ -628,8 +630,6 @@ let create = (name: string, options: WindowCreateOptions.t) => { Internal.updateMetrics(window); - Revery_Native.initWindow(sdlWindow); - window; };