Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_application.cc File Reference

Go to the source code of this file.

Classes

struct  FlApplicationPrivate
 

Macros

#define FL_APPLICATION_GET_PRIVATE(app)
 

Enumerations

enum  {
  SIGNAL_REGISTER_PLUGINS ,
  SIGNAL_CREATE_WINDOW ,
  LAST_SIGNAL
}
 

Functions

 G_DEFINE_TYPE_WITH_CODE (FlApplication, fl_application, GTK_TYPE_APPLICATION, G_ADD_PRIVATE(FlApplication)) static void first_frame_cb(FlApplication *self
 
 if (window !=nullptr &&GTK_IS_WINDOW(window))
 
static void fl_application_register_plugins (FlApplication *self, FlPluginRegistry *registry)
 
static GtkWindow * fl_application_create_window (FlApplication *self, FlView *view)
 
static void fl_application_activate (GApplication *application)
 
static gboolean fl_application_local_command_line (GApplication *application, gchar ***arguments, int *exit_status)
 
static void fl_application_dispose (GObject *object)
 
static void fl_application_class_init (FlApplicationClass *klass)
 
static void fl_application_init (FlApplication *self)
 
G_MODULE_EXPORT FlApplication * fl_application_new (const gchar *application_id, GApplicationFlags flags)
 

Variables

static guint fl_application_signals [LAST_SIGNAL]
 
FlView * view
 

Macro Definition Documentation

◆ FL_APPLICATION_GET_PRIVATE

#define FL_APPLICATION_GET_PRIVATE (   app)
Value:
((FlApplicationPrivate*)fl_application_get_instance_private( \
FL_APPLICATION(app)))

Definition at line 22 of file fl_application.cc.

26
28
29G_DEFINE_TYPE_WITH_CODE(FlApplication,
30 fl_application,
31 GTK_TYPE_APPLICATION,
32 G_ADD_PRIVATE(FlApplication))
33
34// Called when the first frame is received.
35static void first_frame_cb(FlApplication* self, FlView* view) {
36 GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
37
38 // Show the main window.
39 if (window != nullptr && GTK_IS_WINDOW(window)) {
40 gtk_window_present(GTK_WINDOW(window));
41 }
42}
43
44// Default implementation of FlApplication::register_plugins
45static void fl_application_register_plugins(FlApplication* self,
46 FlPluginRegistry* registry) {}
47
48// Default implementation of FlApplication::create_window
49static GtkWindow* fl_application_create_window(FlApplication* self,
50 FlView* view) {
51 GtkApplicationWindow* window =
52 GTK_APPLICATION_WINDOW(gtk_application_window_new(GTK_APPLICATION(self)));
53
54 // Use a header bar when running in GNOME as this is the common style used
55 // by applications and is the setup most users will be using (e.g. Ubuntu
56 // desktop).
57 // If running on X and not using GNOME then just use a traditional title bar
58 // in case the window manager does more exotic layout, e.g. tiling.
59 // If running on Wayland assume the header bar will work (may need changing
60 // if future cases occur).
61 gboolean use_header_bar = TRUE;
62#ifdef GDK_WINDOWING_X11
63 GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
64 if (GDK_IS_X11_SCREEN(screen)) {
65 const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
66 if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
67 use_header_bar = FALSE;
68 }
69 }
70#endif
71 if (use_header_bar) {
72 GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
73 gtk_widget_show(GTK_WIDGET(header_bar));
74 gtk_header_bar_set_show_close_button(header_bar, TRUE);
75 gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header_bar));
76 }
77
78 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
79
80 return GTK_WINDOW(window);
81}
82
83// Implements GApplication::activate.
84static void fl_application_activate(GApplication* application) {
85 FlApplication* self = FL_APPLICATION(application);
87
88 g_autoptr(FlDartProject) project = fl_dart_project_new();
90 project, priv->dart_entrypoint_arguments);
91
92 FlView* view = fl_view_new(project);
93 g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),
94 self);
95 gtk_widget_show(GTK_WIDGET(view));
96
97 GtkWindow* window;
98 g_signal_emit(self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view,
99 &window);
100
101 // Make the resources for the view so rendering can start.
102 // We'll show the view when we have the first frame.
103 gtk_widget_realize(GTK_WIDGET(view));
104
105 g_signal_emit(self, fl_application_signals[SIGNAL_REGISTER_PLUGINS], 0,
106 FL_PLUGIN_REGISTRY(view));
107}
108
109// Implements GApplication::local_command_line.
110static gboolean fl_application_local_command_line(GApplication* application,
111 gchar*** arguments,
112 int* exit_status) {
113 FlApplication* self = FL_APPLICATION(application);
115
116 // Strip out the first argument as it is the binary name.
117 priv->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
118
119 g_autoptr(GError) error = nullptr;
120 if (!g_application_register(application, nullptr, &error)) {
121 g_warning("Failed to register: %s", error->message);
122 *exit_status = 1;
123 return TRUE;
124 }
125
126 // This will only run on the primary instance or this instance with
127 // G_APPLICATION_NON_UNIQUE
128 g_application_activate(application);
129 *exit_status = 0;
130
131 return TRUE;
132}
133
134// Implements GObject::dispose.
135static void fl_application_dispose(GObject* object) {
136 FlApplication* self = FL_APPLICATION(object);
138
139 g_clear_pointer(&priv->dart_entrypoint_arguments, g_strfreev);
140
141 G_OBJECT_CLASS(fl_application_parent_class)->dispose(object);
142}
143
144static void fl_application_class_init(FlApplicationClass* klass) {
145 G_APPLICATION_CLASS(klass)->activate = fl_application_activate;
146 G_APPLICATION_CLASS(klass)->local_command_line =
148 G_OBJECT_CLASS(klass)->dispose = fl_application_dispose;
149
150 klass->register_plugins = fl_application_register_plugins;
151 klass->create_window = fl_application_create_window;
152
154 "register-plugins", fl_application_get_type(), G_SIGNAL_RUN_LAST,
155 G_STRUCT_OFFSET(FlApplicationClass, register_plugins), nullptr, nullptr,
156 nullptr, G_TYPE_NONE, 1, fl_plugin_registry_get_type());
158 "create-window", fl_application_get_type(), G_SIGNAL_RUN_LAST,
159 G_STRUCT_OFFSET(FlApplicationClass, create_window),
160 g_signal_accumulator_first_wins, nullptr, nullptr, GTK_TYPE_WINDOW, 1,
161 fl_view_get_type());
162}
163
164static void fl_application_init(FlApplication* self) {}
165
166G_MODULE_EXPORT
167FlApplication* fl_application_new(const gchar* application_id,
168 GApplicationFlags flags) {
169 return FL_APPLICATION(g_object_new(fl_application_get_type(),
170 "application-id", application_id, "flags",
171 flags, nullptr));
172}
GLFWwindow * window
Definition main.cc:60
g_autoptr(FlEngine) engine
FlAccessibilityHandlerPrivate * priv
FlView * view
G_MODULE_EXPORT FlApplication * fl_application_new(const gchar *application_id, GApplicationFlags flags)
static void fl_application_dispose(GObject *object)
static void fl_application_init(FlApplication *self)
static GtkWindow * fl_application_create_window(FlApplication *self, FlView *view)
static guint fl_application_signals[LAST_SIGNAL]
@ LAST_SIGNAL
@ SIGNAL_CREATE_WINDOW
@ SIGNAL_REGISTER_PLUGINS
static gboolean fl_application_local_command_line(GApplication *application, gchar ***arguments, int *exit_status)
#define FL_APPLICATION_GET_PRIVATE(app)
static void fl_application_register_plugins(FlApplication *self, FlPluginRegistry *registry)
static void fl_application_class_init(FlApplicationClass *klass)
static void fl_application_activate(GApplication *application)
G_DEFINE_TYPE_WITH_CODE(FlApplication, fl_application, GTK_TYPE_APPLICATION, G_ADD_PRIVATE(FlApplication)) static void first_frame_cb(FlApplication *self
return TRUE
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition fl_view.cc:763
void gtk_widget_show(GtkWidget *widget)
Definition mock_gtk.cc:257
GtkWidget * gtk_widget_get_toplevel(GtkWidget *widget)
Definition mock_gtk.cc:294
void gtk_widget_realize(GtkWidget *widget)
Definition mock_gtk.cc:253

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SIGNAL_REGISTER_PLUGINS 
SIGNAL_CREATE_WINDOW 
LAST_SIGNAL 

Definition at line 26 of file fl_application.cc.

Function Documentation

◆ fl_application_activate()

static void fl_application_activate ( GApplication *  application)
static

Definition at line 85 of file fl_application.cc.

85 {
86 FlApplication* self = FL_APPLICATION(application);
88
89 g_autoptr(FlDartProject) project = fl_dart_project_new();
91 project, priv->dart_entrypoint_arguments);
92
93 FlView* view = fl_view_new(project);
94 g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),
95 self);
96 gtk_widget_show(GTK_WIDGET(view));
97
98 GtkWindow* window;
100 &window);
101
102 // Make the resources for the view so rendering can start.
103 // We'll show the view when we have the first frame.
104 gtk_widget_realize(GTK_WIDGET(view));
105
107 FL_PLUGIN_REGISTRY(view));
108}

References FL_APPLICATION_GET_PRIVATE, fl_application_signals, fl_dart_project_new(), fl_dart_project_set_dart_entrypoint_arguments(), fl_view_new(), g_autoptr(), gtk_widget_realize(), gtk_widget_show(), priv, self, SIGNAL_CREATE_WINDOW, SIGNAL_REGISTER_PLUGINS, view, and window.

Referenced by fl_application_class_init().

◆ fl_application_class_init()

static void fl_application_class_init ( FlApplicationClass *  klass)
static

Definition at line 145 of file fl_application.cc.

145 {
146 G_APPLICATION_CLASS(klass)->activate = fl_application_activate;
147 G_APPLICATION_CLASS(klass)->local_command_line =
149 G_OBJECT_CLASS(klass)->dispose = fl_application_dispose;
150
151 klass->register_plugins = fl_application_register_plugins;
152 klass->create_window = fl_application_create_window;
153
155 "register-plugins", fl_application_get_type(), G_SIGNAL_RUN_LAST,
156 G_STRUCT_OFFSET(FlApplicationClass, register_plugins), nullptr, nullptr,
157 nullptr, G_TYPE_NONE, 1, fl_plugin_registry_get_type());
159 "create-window", fl_application_get_type(), G_SIGNAL_RUN_LAST,
160 G_STRUCT_OFFSET(FlApplicationClass, create_window),
161 g_signal_accumulator_first_wins, nullptr, nullptr, GTK_TYPE_WINDOW, 1,
162 fl_view_get_type());
163}

References fl_application_activate(), fl_application_create_window(), fl_application_dispose(), fl_application_local_command_line(), fl_application_register_plugins(), fl_application_signals, SIGNAL_CREATE_WINDOW, and SIGNAL_REGISTER_PLUGINS.

◆ fl_application_create_window()

static GtkWindow * fl_application_create_window ( FlApplication *  self,
FlView *  view 
)
static

Definition at line 50 of file fl_application.cc.

51 {
52 GtkApplicationWindow* window =
53 GTK_APPLICATION_WINDOW(gtk_application_window_new(GTK_APPLICATION(self)));
54
55 // Use a header bar when running in GNOME as this is the common style used
56 // by applications and is the setup most users will be using (e.g. Ubuntu
57 // desktop).
58 // If running on X and not using GNOME then just use a traditional title bar
59 // in case the window manager does more exotic layout, e.g. tiling.
60 // If running on Wayland assume the header bar will work (may need changing
61 // if future cases occur).
62 gboolean use_header_bar = TRUE;
63#ifdef GDK_WINDOWING_X11
64 GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
65 if (GDK_IS_X11_SCREEN(screen)) {
66 const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
67 if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
68 use_header_bar = FALSE;
69 }
70 }
71#endif
72 if (use_header_bar) {
73 GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
74 gtk_widget_show(GTK_WIDGET(header_bar));
75 gtk_header_bar_set_show_close_button(header_bar, TRUE);
76 gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header_bar));
77 }
78
79 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
80
81 return GTK_WINDOW(window);
82}

References gtk_widget_show(), self, TRUE, view, and window.

Referenced by fl_application_class_init().

◆ fl_application_dispose()

static void fl_application_dispose ( GObject *  object)
static

Definition at line 136 of file fl_application.cc.

136 {
137 FlApplication* self = FL_APPLICATION(object);
139
140 g_clear_pointer(&priv->dart_entrypoint_arguments, g_strfreev);
141
142 G_OBJECT_CLASS(fl_application_parent_class)->dispose(object);
143}

References FL_APPLICATION_GET_PRIVATE, priv, and self.

Referenced by fl_application_class_init().

◆ fl_application_init()

static void fl_application_init ( FlApplication *  self)
static

Definition at line 165 of file fl_application.cc.

165{}

◆ fl_application_local_command_line()

static gboolean fl_application_local_command_line ( GApplication *  application,
gchar ***  arguments,
int *  exit_status 
)
static

Definition at line 111 of file fl_application.cc.

113 {
114 FlApplication* self = FL_APPLICATION(application);
116
117 // Strip out the first argument as it is the binary name.
118 priv->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
119
120 g_autoptr(GError) error = nullptr;
121 if (!g_application_register(application, nullptr, &error)) {
122 g_warning("Failed to register: %s", error->message);
123 *exit_status = 1;
124 return TRUE;
125 }
126
127 // This will only run on the primary instance or this instance with
128 // G_APPLICATION_NON_UNIQUE
129 g_application_activate(application);
130 *exit_status = 0;
131
132 return TRUE;
133}

References error, FL_APPLICATION_GET_PRIVATE, g_autoptr(), priv, self, and TRUE.

Referenced by fl_application_class_init().

◆ fl_application_new()

G_MODULE_EXPORT FlApplication * fl_application_new ( const gchar *  application_id,
GApplicationFlags  flags 
)

FlApplication:

#Flutter-based application with the GTK embedder.

Provides default behaviour for basic Flutter applications. fl_application_new: @application_id: (allow-none): The application ID or NULL. @flags: The application flags.

Creates a new Flutter-based application.

Returns: a new #FlApplication

Definition at line 168 of file fl_application.cc.

169 {
170 return FL_APPLICATION(g_object_new(fl_application_get_type(),
171 "application-id", application_id, "flags",
172 flags, nullptr));
173}

Referenced by TEST().

◆ fl_application_register_plugins()

static void fl_application_register_plugins ( FlApplication *  self,
FlPluginRegistry *  registry 
)
static

Definition at line 46 of file fl_application.cc.

47 {}

Referenced by fl_application_class_init().

◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE ( FlApplication  ,
fl_application  ,
GTK_TYPE_APPLICATION  ,
G_ADD_PRIVATE(FlApplication)   
)

◆ if()

if ( window = nullptr && GTK_IS_WINDOW(window))

Definition at line 40 of file fl_application.cc.

40 {
41 gtk_window_present(GTK_WINDOW(window));
42 }

References window.

Variable Documentation

◆ fl_application_signals

guint fl_application_signals[LAST_SIGNAL]
static

Definition at line 28 of file fl_application.cc.

Referenced by fl_application_activate(), and fl_application_class_init().

◆ view

FlView* view
Initial value:
{
GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view))

Definition at line 36 of file fl_application.cc.

Referenced by fl_application_activate(), and fl_application_create_window().