Skip to content

Commit d8a57c6

Browse files
Add windowing channel support to Linux embedder (#163180)
Implement flutter/windowing for the Linux embedder.
1 parent 11d33f2 commit d8a57c6

File tree

15 files changed

+1486
-10
lines changed

15 files changed

+1486
-10
lines changed

engine/src/flutter/ci/licenses_golden/licenses_flutter

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43869,6 +43869,11 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_view_test.cc + ../../../flutter
4386943869
ORIGIN: ../../../flutter/shell/platform/linux/fl_window_state_monitor.cc + ../../../flutter/LICENSE
4387043870
ORIGIN: ../../../flutter/shell/platform/linux/fl_window_state_monitor.h + ../../../flutter/LICENSE
4387143871
ORIGIN: ../../../flutter/shell/platform/linux/fl_window_state_monitor_test.cc + ../../../flutter/LICENSE
43872+
ORIGIN: ../../../flutter/shell/platform/linux/fl_windowing_channel.cc + ../../../flutter/LICENSE
43873+
ORIGIN: ../../../flutter/shell/platform/linux/fl_windowing_channel.h + ../../../flutter/LICENSE
43874+
ORIGIN: ../../../flutter/shell/platform/linux/fl_windowing_handler.cc + ../../../flutter/LICENSE
43875+
ORIGIN: ../../../flutter/shell/platform/linux/fl_windowing_handler.h + ../../../flutter/LICENSE
43876+
ORIGIN: ../../../flutter/shell/platform/linux/fl_windowing_handler_test.cc + ../../../flutter/LICENSE
4387243877
ORIGIN: ../../../flutter/shell/platform/linux/key_mapping.g.cc + ../../../flutter/LICENSE
4387343878
ORIGIN: ../../../flutter/shell/platform/linux/key_mapping.h + ../../../flutter/LICENSE
4387443879
ORIGIN: ../../../flutter/shell/platform/linux/key_mapping_test.cc + ../../../flutter/LICENSE
@@ -46813,6 +46818,11 @@ FILE: ../../../flutter/shell/platform/linux/fl_view_test.cc
4681346818
FILE: ../../../flutter/shell/platform/linux/fl_window_state_monitor.cc
4681446819
FILE: ../../../flutter/shell/platform/linux/fl_window_state_monitor.h
4681546820
FILE: ../../../flutter/shell/platform/linux/fl_window_state_monitor_test.cc
46821+
FILE: ../../../flutter/shell/platform/linux/fl_windowing_channel.cc
46822+
FILE: ../../../flutter/shell/platform/linux/fl_windowing_channel.h
46823+
FILE: ../../../flutter/shell/platform/linux/fl_windowing_handler.cc
46824+
FILE: ../../../flutter/shell/platform/linux/fl_windowing_handler.h
46825+
FILE: ../../../flutter/shell/platform/linux/fl_windowing_handler_test.cc
4681646826
FILE: ../../../flutter/shell/platform/linux/key_mapping.g.cc
4681746827
FILE: ../../../flutter/shell/platform/linux/key_mapping.h
4681846828
FILE: ../../../flutter/shell/platform/linux/key_mapping_test.cc

engine/src/flutter/shell/platform/linux/.clang-tidy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
InheritParentConfig: true
22

33
# EnumCastOutOfRange warns about some common usages of GTK macros
4+
# Malloc generates false positives with g_autofree usage.
45
Checks: >-
5-
-clang-analyzer-optin.core.EnumCastOutOfRange
6+
-clang-analyzer-optin.core.EnumCastOutOfRange,
7+
-clang-analyzer-unix.Malloc
68
79
CheckOptions:
810
- key: readability-identifier-naming.EnumConstantCase

engine/src/flutter/shell/platform/linux/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ source_set("flutter_linux_sources") {
158158
"fl_view.cc",
159159
"fl_view_accessible.cc",
160160
"fl_window_state_monitor.cc",
161+
"fl_windowing_channel.cc",
162+
"fl_windowing_handler.cc",
161163
"key_mapping.g.cc",
162164
]
163165

@@ -248,6 +250,7 @@ executable("flutter_linux_unittests") {
248250
"fl_view_accessible_test.cc",
249251
"fl_view_test.cc",
250252
"fl_window_state_monitor_test.cc",
253+
"fl_windowing_handler_test.cc",
251254
"key_mapping_test.cc",
252255
"testing/fl_mock_binary_messenger.cc",
253256
"testing/fl_test.cc",

engine/src/flutter/shell/platform/linux/fl_application.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <gdk/gdkx.h>
1010
#endif
1111

12+
#include "flutter/shell/platform/linux/fl_engine_private.h"
1213
#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
1314
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"
1415
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
@@ -31,6 +32,15 @@ G_DEFINE_TYPE_WITH_CODE(FlApplication,
3132
GTK_TYPE_APPLICATION,
3233
G_ADD_PRIVATE(FlApplication))
3334

35+
// Called when the platform creates a window.
36+
static GtkWindow* create_window_cb(FlApplication* self, FlView* view) {
37+
GtkWindow* window;
38+
g_signal_emit(self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view,
39+
&window);
40+
41+
return window;
42+
}
43+
3444
// Called when the first frame is received.
3545
static void first_frame_cb(FlApplication* self, FlView* view) {
3646
GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
@@ -94,6 +104,11 @@ static void fl_application_activate(GApplication* application) {
94104
self);
95105
gtk_widget_show(GTK_WIDGET(view));
96106

107+
FlWindowingHandler* windowing_handler =
108+
fl_engine_get_windowing_handler(fl_view_get_engine(view));
109+
g_signal_connect_swapped(windowing_handler, "create_window",
110+
G_CALLBACK(create_window_cb), self);
111+
97112
GtkWindow* window;
98113
g_signal_emit(self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view,
99114
&window);

engine/src/flutter/shell/platform/linux/fl_engine.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "flutter/shell/platform/linux/fl_settings_handler.h"
2525
#include "flutter/shell/platform/linux/fl_texture_gl_private.h"
2626
#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
27+
#include "flutter/shell/platform/linux/fl_windowing_handler.h"
2728
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"
2829

2930
// Unique number associated with platform tasks.
@@ -58,6 +59,9 @@ struct _FlEngine {
5859
// Implements the flutter/platform channel.
5960
FlPlatformHandler* platform_handler;
6061

62+
// Implements the flutter/windowing channel.
63+
FlWindowingHandler* windowing_handler;
64+
6165
// Process keyboard events.
6266
FlKeyboardManager* keyboard_manager;
6367

@@ -487,6 +491,7 @@ static void fl_engine_dispose(GObject* object) {
487491
g_clear_object(&self->binary_messenger);
488492
g_clear_object(&self->settings_handler);
489493
g_clear_object(&self->platform_handler);
494+
g_clear_object(&self->windowing_handler);
490495
g_clear_object(&self->keyboard_manager);
491496
g_clear_object(&self->text_input_handler);
492497
g_clear_object(&self->keyboard_handler);
@@ -702,6 +707,7 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
702707
fl_settings_handler_start(self->settings_handler, settings);
703708

704709
self->platform_handler = fl_platform_handler_new(self->binary_messenger);
710+
self->windowing_handler = fl_windowing_handler_new(self);
705711

706712
setup_keyboard(self);
707713

@@ -1295,6 +1301,11 @@ void fl_engine_request_app_exit(FlEngine* self) {
12951301
fl_platform_handler_request_app_exit(self->platform_handler);
12961302
}
12971303

1304+
FlWindowingHandler* fl_engine_get_windowing_handler(FlEngine* self) {
1305+
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
1306+
return self->windowing_handler;
1307+
}
1308+
12981309
FlKeyboardManager* fl_engine_get_keyboard_manager(FlEngine* self) {
12991310
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
13001311
return self->keyboard_manager;

engine/src/flutter/shell/platform/linux/fl_engine_private.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "flutter/shell/platform/linux/fl_renderer.h"
1515
#include "flutter/shell/platform/linux/fl_task_runner.h"
1616
#include "flutter/shell/platform/linux/fl_text_input_handler.h"
17+
#include "flutter/shell/platform/linux/fl_windowing_handler.h"
1718
#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
1819
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
1920

@@ -576,13 +577,23 @@ void fl_engine_update_accessibility_features(FlEngine* engine, int32_t flags);
576577
*/
577578
void fl_engine_request_app_exit(FlEngine* engine);
578579

580+
/**
581+
* fl_engine_get_windowing_handler:
582+
* @engine: an #FlEngine.
583+
*
584+
* Gets the windowing handler used by this engine.
585+
*
586+
* Returns: an #FlWindowingHandler.
587+
*/
588+
FlWindowingHandler* fl_engine_get_windowing_handler(FlEngine* engine);
589+
579590
/**
580591
* fl_engine_get_keyboard_manager:
581592
* @engine: an #FlEngine.
582593
*
583594
* Gets the keyboard manager used by this engine.
584595
*
585-
* Returns: a #FlKeyboardManager.
596+
* Returns: an #FlKeyboardManager.
586597
*/
587598
FlKeyboardManager* fl_engine_get_keyboard_manager(FlEngine* engine);
588599

@@ -592,7 +603,7 @@ FlKeyboardManager* fl_engine_get_keyboard_manager(FlEngine* engine);
592603
*
593604
* Gets the text input handler used by this engine.
594605
*
595-
* Returns: a #FlTextInputHandler.
606+
* Returns: an #FlTextInputHandler.
596607
*/
597608
FlTextInputHandler* fl_engine_get_text_input_handler(FlEngine* engine);
598609

@@ -602,7 +613,7 @@ FlTextInputHandler* fl_engine_get_text_input_handler(FlEngine* engine);
602613
*
603614
* Gets the mouse cursor handler used by this engine.
604615
*
605-
* Returns: a #FlMouseCursorHandler.
616+
* Returns: an #FlMouseCursorHandler.
606617
*/
607618
FlMouseCursorHandler* fl_engine_get_mouse_cursor_handler(FlEngine* engine);
608619

engine/src/flutter/shell/platform/linux/fl_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ G_MODULE_EXPORT FlView* fl_view_new(FlDartProject* project) {
765765
fl_engine_set_update_semantics_handler(self->engine, update_semantics_cb,
766766
self, nullptr);
767767
self->on_pre_engine_restart_cb_id =
768-
g_signal_connect_swapped(engine, "on-pre-engine-restart",
768+
g_signal_connect_swapped(self->engine, "on-pre-engine-restart",
769769
G_CALLBACK(on_pre_engine_restart_cb), self);
770770

771771
g_signal_connect_swapped(self->gl_area, "create-context",
@@ -790,7 +790,7 @@ G_MODULE_EXPORT FlView* fl_view_new_for_engine(FlEngine* engine) {
790790
g_signal_connect_swapped(engine, "on-pre-engine-restart",
791791
G_CALLBACK(on_pre_engine_restart_cb), self);
792792

793-
self->view_id = fl_engine_add_view(self->engine, 1, 1, 1.0, self->cancellable,
793+
self->view_id = fl_engine_add_view(engine, 1, 1, 1.0, self->cancellable,
794794
view_added_cb, self);
795795
fl_renderer_add_renderable(FL_RENDERER(self->renderer), self->view_id,
796796
FL_RENDERABLE(self));

engine/src/flutter/shell/platform/linux/fl_view_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "flutter/shell/platform/linux/fl_engine_private.h"
88
#include "flutter/shell/platform/linux/testing/fl_test.h"
99
#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
10+
#include "flutter/shell/platform/linux/testing/mock_window.h"
1011

1112
#include "gtest/gtest.h"
1213

@@ -136,8 +137,8 @@ TEST(FlViewTest, ViewDestroy) {
136137
int64_t implicit_view_id = fl_view_get_id(implicit_view);
137138
int64_t secondary_view_id = fl_view_get_id(secondary_view);
138139

139-
gtk_widget_destroy(GTK_WIDGET(secondary_view));
140-
gtk_widget_destroy(GTK_WIDGET(implicit_view));
140+
fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
141+
fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
141142

142143
EXPECT_EQ(removed_views->len, 2u);
143144
EXPECT_EQ(GPOINTER_TO_INT(g_ptr_array_index(removed_views, 0)),
@@ -165,6 +166,6 @@ TEST(FlViewTest, ViewDestroyError) {
165166

166167
FlView* secondary_view = fl_view_new_for_engine(engine);
167168

168-
gtk_widget_destroy(GTK_WIDGET(secondary_view));
169-
gtk_widget_destroy(GTK_WIDGET(implicit_view));
169+
fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
170+
fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
170171
}

0 commit comments

Comments
 (0)