Skip to content

Commit

Permalink
fix(Windows): ensure WS_CAPTION is set on undecorated windows (revery…
Browse files Browse the repository at this point in the history
…-ui#862)

* Native: add initWindow, rename init -> initApp

* Formatting

* Revery_Native: add clarifying comment

* Window: move where Maximize is placed so flag is set
  • Loading branch information
zbaylin authored May 26, 2020
1 parent 019771a commit bd3d702
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Core/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions src/Core/Window.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Native/Initialization.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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);
23 changes: 21 additions & 2 deletions src/Native/Revery_Native.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#ifdef WIN32
#include "ReveryWin32.h"
#include <combaseapi.h>
#include <windows.h>
#elif __APPLE__
#include "ReveryCocoa.h"
#import "ReveryAppDelegate.h"
#else
#include "ReveryGtk.h"
#endif

CAMLprim value revery_initialize() {
CAMLprim value revery_initializeApp() {
#ifdef __APPLE__
SDLAppDelegate *sdlDelegate = [NSApp delegate];
ReveryAppDelegate *delegate = [ReveryAppDelegate newWithSDLDelegate:sdlDelegate];
Expand All @@ -32,9 +33,27 @@ 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
/* 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);
#else
UNUSED(win);
#endif
CAMLreturn(Val_unit);
}

0 comments on commit bd3d702

Please sign in to comment.