Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ragnar-H opened this issue May 31, 2021 · 3 comments
Open

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

Ragnar-H opened this issue May 31, 2021 · 3 comments

Comments

@Ragnar-H
Copy link

Ragnar-H commented May 31, 2021

  • Operating System: macos v11.4
  • Revery Version: Reproduced in revery repo examples at 79c2572
  • 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:
  1. Pass in visible=false into the Examples in this repo - see git diff in above section
  2. 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

@Ragnar-H
Copy link
Author

@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
Copy link
Member

bryphe commented Jun 3, 2021

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:

CAMLprim value resdl_SDL_CreateWindow(value vName, value vX, value vY,

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:

SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE));

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
Copy link
Author

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 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants