Skip to content

Commit b60fd0f

Browse files
committed
update native linux entry point
1 parent 384e140 commit b60fd0f

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

scripts/app_config/templates/linux/my_application.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ struct _MyApplication {
1414

1515
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
1616

17+
// Called when first Flutter frame received.
18+
static void first_frame_cb(MyApplication* self, FlView *view)
19+
{
20+
gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));
21+
}
22+
1723
// Implements GApplication::activate.
1824
static void my_application_activate(GApplication* application) {
1925
MyApplication* self = MY_APPLICATION(application);
@@ -54,9 +60,18 @@ static void my_application_activate(GApplication* application) {
5460
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
5561

5662
FlView* view = fl_view_new(project);
63+
GdkRGBA background_color;
64+
// Background defaults to black, override it here if necessary, e.g. #00000000 for transparent.
65+
gdk_rgba_parse(&background_color, "#000000");
66+
fl_view_set_background_color(view, &background_color);
5767
gtk_widget_show(GTK_WIDGET(view));
5868
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
5969

70+
// Show the window when Flutter renders.
71+
// Requires the view to be realized so we can start rendering.
72+
g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), self);
73+
gtk_widget_realize(GTK_WIDGET(view));
74+
6075
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
6176

6277
gtk_widget_grab_focus(GTK_WIDGET(view));
@@ -81,6 +96,24 @@ static gboolean my_application_local_command_line(GApplication* application, gch
8196
return TRUE;
8297
}
8398

99+
// Implements GApplication::startup.
100+
static void my_application_startup(GApplication* application) {
101+
//MyApplication* self = MY_APPLICATION(object);
102+
103+
// Perform any actions required at application startup.
104+
105+
G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
106+
}
107+
108+
// Implements GApplication::shutdown.
109+
static void my_application_shutdown(GApplication* application) {
110+
//MyApplication* self = MY_APPLICATION(object);
111+
112+
// Perform any actions required at application shutdown.
113+
114+
G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
115+
}
116+
84117
// Implements GObject::dispose.
85118
static void my_application_dispose(GObject* object) {
86119
MyApplication* self = MY_APPLICATION(object);
@@ -91,12 +124,20 @@ static void my_application_dispose(GObject* object) {
91124
static void my_application_class_init(MyApplicationClass* klass) {
92125
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93126
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
127+
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
128+
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
94129
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95130
}
96131

97132
static void my_application_init(MyApplication* self) {}
98133

99134
MyApplication* my_application_new() {
135+
// Set the program name to the application ID, which helps various systems
136+
// like GTK and desktop environments map this running application to its
137+
// corresponding .desktop file. This ensures better integration by allowing
138+
// the application to be recognized beyond its binary name.
139+
g_set_prgname(APPLICATION_ID);
140+
100141
return MY_APPLICATION(g_object_new(my_application_get_type(),
101142
"application-id", APPLICATION_ID,
102143
"flags", G_APPLICATION_NON_UNIQUE,

0 commit comments

Comments
 (0)