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

How to hide window on startup? #206

Closed
prateekmedia opened this issue Aug 23, 2022 · 6 comments
Closed

How to hide window on startup? #206

prateekmedia opened this issue Aug 23, 2022 · 6 comments

Comments

@prateekmedia
Copy link
Contributor

Is there any way to hide window on startup for linux?

@FeodorFitsner
Copy link

Maybe I've found the solution.

Open linux\my_application.cc for editing and find the following lines:

  gtk_window_set_default_size(window, 1280, 720);
  gtk_widget_show(GTK_WIDGET(window));

add gtk_widget_hide(GTK_WIDGET(window)); below that block:

  gtk_window_set_default_size(window, 1280, 720);
  gtk_widget_show(GTK_WIDGET(window));
  gtk_widget_hide(GTK_WIDGET(window));

I'm testing on WSL and it kind of works. :)

@prateekmedia
Copy link
Contributor Author

@FeodorFitsner I tried it but it messes up the size of the window :(

@FeodorFitsner
Copy link

Alright, let's wait for an official solution then? 🤷🏻‍♂️

@alexmercerind
Copy link

alexmercerind commented Aug 28, 2022

I'm having same problem. That period of "2 seconds with no paint" at start-up is driving me crazy.

The FlView from Flutter seems to be very tightly coupled with GTK.
GTK does not render frames when it is hidden.

In essence, what an approach should be that window launches without any visibility at startup & then Dart-VM/Flutter notifies back to GTK through platform channels that "first frame has been rasterized, now we're ready to actually show the window.".
waitUntilFirstFrameRasterized can be used for this.

But since, when window is hidden (using gtk_widget_hide or gtk_widget_set_visible), no frames ever get drawn & waitUntilFirstFrameRasterized itself never gets invoked.

So, an another approach to make window invisible is using:

  • gtk_window_iconify (make it minimized)
  • gtk_widget_set_opacity (make it invisible using opacity as 0.0)
  • gtk_widget_set_sensitive (make it un-clickable with false)

By this, waitUntilFirstFrameRasterized actually gets called & Flutter gets rendered. Once, waitUntilFirstFrameRasterized is received notify back GTK with:

  • gtk_window_deiconify (restore window)
  • gtk_widget_hide (on window object)
  • gtk_widget_set_opacity (make it visible again using opacity as 1.0)
  • gtk_widget_set_sensitive (make it clickable again with true)
  • gtk_widget_show (on window object)

Having gtk_widget_hide & gtk_widget_show makes window to show actual "open animation" (as configured by the window manager or desktop-environment) because just changing opacity will just make window appear instantly.

The problem still with this is that, we'll still have a window (though invisible, non-clickable & completely undetectable) during that "2 seconds with no paint", which can result in some weird situations for some things like tiling window managers, I guess.

This is the only solution, otherwise I just feel Flutter will need changes in flutter/engine itself.


P.S. I have tested it.

@Merrit
Copy link
Contributor

Merrit commented Aug 28, 2022

Have you tried gtk_widget_realize?

  /// Hide window by default so we can manipulate size, frame, etc and 
  /// then show the window when we are ready.
  ///
  /// `gtk_widget_realize` will create the window without showing it, 
  /// then the Dart code can call `windowManager.show();`.
  // gtk_widget_show(GTK_WIDGET(window));   <-- Previous implementation.
  gtk_widget_realize(GTK_WIDGET(window));

@lijy91
Copy link
Member

lijy91 commented Aug 29, 2022

@Merrit Thanks a lot for the info, I'll add it to the readme

FeodorFitsner added a commit to flet-dev/flet that referenced this issue Sep 1, 2022
FeodorFitsner added a commit to flet-dev/flet that referenced this issue Sep 2, 2022
* A few server-side tests

* FilePicker without upload

* Allow multiple copies of Flet window on macOS

Fix #249

* Upload dir on Python side, upload URL gen

* FilePicker with upload

* Upload progress complete

* offstage -> overlay

* Disable CORS

* FilePicker methods with parameters

* Renamed again

* gtk_widget_realize()

Based on leanflutter/window_manager#206
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

5 participants