revery-ui / revery

:zap: Native, high-performance, cross-platform desktop apps - built with Reason!
https://www.outrunlabs.com/revery/
MIT License
8.07k stars 196 forks source link

createWindow with visible=false does not create a hidden window #1081

Open Ragnar-H opened 3 years ago

Ragnar-H commented 3 years ago

I'm happy to create a dedicated repo for this if that's needed. This can be reproduced in the Examples in this repo which seemed easiest :)

diff --git a/examples/Examples.re b/examples/Examples.re
index f0d567a2..b942e896 100644
--- a/examples/Examples.re
+++ b/examples/Examples.re
@@ -347,6 +347,7 @@ let init = app => {
     App.createWindow(
       ~createOptions=
         WindowCreateOptions.create(
+          ~visible=false,
           ~width=windowWidth,
           ~height=windowHeight,
           ~maximized,
  1. Pass in visible=false into the Examples in this repo - see git diff in above section
  2. esy @examples run

App window is shown and focused

App window is hidden

In Window.create we've got a guard for calling .show() on Sdl2 window however we probably want to pass in SDL_WINDOW_HIDDEN to the Sdl2.Window.create. I suspect Sdl2 has the sane default of windows being visible.

visible, createWindow

Ragnar-H commented 3 years ago

@bryphe I suspect the solution is to expose the SDL_WINDOWFLAGS to the Sdl2.Window.create call in Window.re

I'm happy to take this on, although I expect I'll need some help since there's some C plumbing I'm not immediately familiar with :)

bryphe commented 3 years ago

Hi @Ragnar-H ,

Thanks for logging the issue and all the details! This would certainly be a nice improvement - it can help reduce flicker when starting up apps to start them hidden, and then show them once everything has been loaded / setup.

The simplest fix would probably be to add a flag here: https://github.com/revery-ui/revery/blob/9ec44ff79a3e4ca75508bf53cd385d1db8b231b4/packages/reason-sdl2/src/sdl2_wrapper.cpp#L1574

These places would also need to be updated:

(and then, validating that the window can be shown after being hidden is important - I think the current SDL_ShowWindow is the right thing for that, though).

A larger, but more flexible, fix would be as you suggested - expose the SDL_WINDOWFLAGS as something we can build and pass from Reason to the C stubs. We have the flags hard-coded here: https://github.com/revery-ui/revery/blob/9ec44ff79a3e4ca75508bf53cd385d1db8b231b4/packages/reason-sdl2/src/sdl2_wrapper.cpp#L1641

One idea would be to pass a uint to our CreateWindow API, and have a module like WindowFlags that can be used with that API, like:

module WindowFlags: {
   // Internally, this would be a uint
   type t;

   type flags = 
   | Hidden
   | OpenGL
   | Fullscreen
   | ...;

   // The default set of flags we use currently - OpenGL, HighDPI, Resizable
   let default: t;

   let make: list(flags) => t;
}
...

module Window: {
   let create: (~flags=WindowFlags.default, ...);
}

Hope that helps give some ideas!

Ragnar-H commented 3 years ago

Thanks @bryphe!

My time contributing to OSS is very sporadic but let's see if I can get to this :) I'll drop a comment if I start digging into this.

If anyone else is reading this and is missing the functionality feel free to jump on this 🤝