revery
revery copied to clipboard
createWindow with visible=false does not create a hidden window
- Operating System: macos v11.4
- Revery Version: Reproduced in revery repo examples at https://github.com/revery-ui/revery/commit/79c2572a931e1b505469092366c44c3b5091889f
- OCaml version: 4.12.0
- Native, Bytecode, or JS build: Development build
- Minimal repro
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,
- Steps to reproduce:
- Pass in
visible=false
into the Examples in this repo - see git diff in above section -
esy @examples run
- Actual Result:
App window is shown and focused
- Expected Result:
App window is hidden
- Additional Information:
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.
- Search terms used:
visible, createWindow
@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 :)
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:
- https://github.com/revery-ui/revery/blob/9ec44ff79a3e4ca75508bf53cd385d1db8b231b4/packages/reason-sdl2/src/sdl2_wrapper.cpp#L1667
- https://github.com/revery-ui/revery/blob/9ec44ff79a3e4ca75508bf53cd385d1db8b231b4/packages/reason-sdl2/src/sdl2.re#L231
(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!
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 🤝