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

Automate "linux/my_application.cc" modification #14

Open
larsb24 opened this issue Dec 27, 2022 · 4 comments
Open

Automate "linux/my_application.cc" modification #14

larsb24 opened this issue Dec 27, 2022 · 4 comments

Comments

@larsb24
Copy link

larsb24 commented Dec 27, 2022

Hey,

I was thinking about automating the required modification in linux/my_application.cc for easier use.
Do you think having the change (switching the lines) can do any potential harm to an application that don't use handy_window?
Because otherwise the easiest way to do that is probably just changing the default my_application.cc

@jpnurmi
Copy link
Member

jpnurmi commented Dec 28, 2022

Technically, it should be enough to move gtk_widget_show(window) after fl_register_plugins() and this is the change I originally planned to propose to the Flutter app template:

diff --git a/linux/my_application.cc b/linux/my_application.cc
index 6f18193..6900d28 100644
--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -48,7 +48,6 @@ static void my_application_activate(GApplication* application) {
   }
 
   gtk_window_set_default_size(window, 1280, 720);
-  gtk_widget_show(GTK_WIDGET(window));
 
   g_autoptr(FlDartProject) project = fl_dart_project_new();
   fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
@@ -59,6 +58,7 @@ static void my_application_activate(GApplication* application) {
 
   fl_register_plugins(FL_PLUGIN_REGISTRY(view));
 
+  gtk_widget_show(GTK_WIDGET(window));
   gtk_widget_grab_focus(GTK_WIDGET(view));
 }
 

However, the FlView implementation assumes that GtkWidget::size-allocate and GtkWidget::realize get called in a specific order. While the above patch works by coincidence with handy_window, a vanilla Flutter/GTK window stays empty on startup until e.g. resized.

As a workaround, moving gtk_widget_show(view) after gtk_widget_show(window) helps to restore the desired order for size-allocate and realize. This is also what's currently proposed in the README file to make sure that the vanilla Flutter/GTK window doesn't show up empty if a Handy window cannot be set up for one reason or another.

diff --git a/linux/my_application.cc b/linux/my_application.cc
index 6f18193..3e5ee2b 100644
--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -48,17 +48,17 @@ static void my_application_activate(GApplication* application) {
   }
 
   gtk_window_set_default_size(window, 1280, 720);
-  gtk_widget_show(GTK_WIDGET(window));
 
   g_autoptr(FlDartProject) project = fl_dart_project_new();
   fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
 
   FlView* view = fl_view_new(project);
-  gtk_widget_show(GTK_WIDGET(view));
   gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
 
   fl_register_plugins(FL_PLUGIN_REGISTRY(view));
 
+  gtk_widget_show(GTK_WIDGET(window));
+  gtk_widget_show(GTK_WIDGET(view));
   gtk_widget_grab_focus(GTK_WIDGET(view));
 }
 

I somehow didn't feel like this was a pretty enough solution for proposing a change to the official Flutter app template. I'd much rather fix FlView so that it works with the original proposal...

@larsb24
Copy link
Author

larsb24 commented Dec 28, 2022

Hmm okay, understandable.
So FLView would need a fix for moving only gtk_widget_show(window) down, because the default embedder wouldn't load properly, is what I understand from that.
I personally don't really have enough experience with the embedder for that, tbh. I just thought that maybe it would be enough to PR the change that moves both gtk_widget_show(GTK_WIDGET(window)) and gtk_widget_show(GTK_WIDGET(view)) down into the template, as it technically works for both the default and the handy_window embedder.

@jpnurmi
Copy link
Member

jpnurmi commented Dec 29, 2022

I have a fix proposal that feels reasonable: jpnurmi/engine@cf68162. It's probably going to be more effort to write a PR description. :)

@jpnurmi
Copy link
Member

jpnurmi commented Jan 10, 2023

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