Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0b34fae

Browse files
authored
[Linux] Add Multi-Touch Support for Linux (#54214)
This draft PR aims to address the lack of multi-touch support under Linux, leveraging the existing implementation used for Windows. As I am not an expert in this domain, I would greatly appreciate feedback on the implementation. flutter/flutter#133239 flutter/flutter#52202 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent b8034f1 commit 0b34fae

File tree

8 files changed

+593
-1
lines changed

8 files changed

+593
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45153,6 +45153,9 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_texture_private.h + ../../../fl
4515345153
ORIGIN: ../../../flutter/shell/platform/linux/fl_texture_registrar.cc + ../../../flutter/LICENSE
4515445154
ORIGIN: ../../../flutter/shell/platform/linux/fl_texture_registrar_private.h + ../../../flutter/LICENSE
4515545155
ORIGIN: ../../../flutter/shell/platform/linux/fl_texture_registrar_test.cc + ../../../flutter/LICENSE
45156+
ORIGIN: ../../../flutter/shell/platform/linux/fl_touch_manager.cc + ../../../flutter/LICENSE
45157+
ORIGIN: ../../../flutter/shell/platform/linux/fl_touch_manager.h + ../../../flutter/LICENSE
45158+
ORIGIN: ../../../flutter/shell/platform/linux/fl_touch_manager_test.cc + ../../../flutter/LICENSE
4515645159
ORIGIN: ../../../flutter/shell/platform/linux/fl_value.cc + ../../../flutter/LICENSE
4515745160
ORIGIN: ../../../flutter/shell/platform/linux/fl_value_test.cc + ../../../flutter/LICENSE
4515845161
ORIGIN: ../../../flutter/shell/platform/linux/fl_view.cc + ../../../flutter/LICENSE
@@ -48115,6 +48118,9 @@ FILE: ../../../flutter/shell/platform/linux/fl_texture_private.h
4811548118
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar.cc
4811648119
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_private.h
4811748120
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_test.cc
48121+
FILE: ../../../flutter/shell/platform/linux/fl_touch_manager.cc
48122+
FILE: ../../../flutter/shell/platform/linux/fl_touch_manager.h
48123+
FILE: ../../../flutter/shell/platform/linux/fl_touch_manager_test.cc
4811848124
FILE: ../../../flutter/shell/platform/linux/fl_value.cc
4811948125
FILE: ../../../flutter/shell/platform/linux/fl_value_test.cc
4812048126
FILE: ../../../flutter/shell/platform/linux/fl_view.cc

shell/platform/linux/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ source_set("flutter_linux_sources") {
157157
"fl_texture.cc",
158158
"fl_texture_gl.cc",
159159
"fl_texture_registrar.cc",
160+
"fl_touch_manager.cc",
160161
"fl_value.cc",
161162
"fl_view.cc",
162163
"fl_view_accessible.cc",
@@ -245,6 +246,7 @@ executable("flutter_linux_unittests") {
245246
"fl_text_input_handler_test.cc",
246247
"fl_texture_gl_test.cc",
247248
"fl_texture_registrar_test.cc",
249+
"fl_touch_manager_test.cc",
248250
"fl_value_test.cc",
249251
"fl_view_accessible_test.cc",
250252
"fl_view_test.cc",

shell/platform/linux/fl_engine.cc

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,136 @@ void fl_engine_send_mouse_pointer_event(FlEngine* self,
933933
self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
934934
}
935935

936+
void fl_engine_send_touch_up_event(FlEngine* self,
937+
FlutterViewId view_id,
938+
size_t timestamp,
939+
double x,
940+
double y,
941+
int32_t device) {
942+
g_return_if_fail(FL_IS_ENGINE(self));
943+
944+
if (self->engine == nullptr) {
945+
return;
946+
}
947+
948+
FlutterPointerEvent event;
949+
event.timestamp = timestamp;
950+
event.x = x;
951+
event.y = y;
952+
event.device_kind = kFlutterPointerDeviceKindTouch;
953+
event.device = device;
954+
event.buttons = 0;
955+
event.view_id = view_id;
956+
event.phase = FlutterPointerPhase::kUp;
957+
event.struct_size = sizeof(event);
958+
959+
self->embedder_api.SendPointerEvent(self->engine, &event, 1);
960+
}
961+
962+
void fl_engine_send_touch_down_event(FlEngine* self,
963+
FlutterViewId view_id,
964+
size_t timestamp,
965+
double x,
966+
double y,
967+
int32_t device) {
968+
g_return_if_fail(FL_IS_ENGINE(self));
969+
970+
if (self->engine == nullptr) {
971+
return;
972+
}
973+
974+
FlutterPointerEvent event;
975+
event.timestamp = timestamp;
976+
event.x = x;
977+
event.y = y;
978+
event.device_kind = kFlutterPointerDeviceKindTouch;
979+
event.device = device;
980+
event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
981+
event.view_id = view_id;
982+
event.phase = FlutterPointerPhase::kDown;
983+
event.struct_size = sizeof(event);
984+
985+
self->embedder_api.SendPointerEvent(self->engine, &event, 1);
986+
}
987+
988+
void fl_engine_send_touch_move_event(FlEngine* self,
989+
FlutterViewId view_id,
990+
size_t timestamp,
991+
double x,
992+
double y,
993+
int32_t device) {
994+
g_return_if_fail(FL_IS_ENGINE(self));
995+
996+
if (self->engine == nullptr) {
997+
return;
998+
}
999+
1000+
FlutterPointerEvent event;
1001+
event.timestamp = timestamp;
1002+
event.x = x;
1003+
event.y = y;
1004+
event.device_kind = kFlutterPointerDeviceKindTouch;
1005+
event.device = device;
1006+
event.buttons = FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary;
1007+
event.view_id = view_id;
1008+
event.phase = FlutterPointerPhase::kMove;
1009+
event.struct_size = sizeof(event);
1010+
1011+
self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1012+
}
1013+
1014+
void fl_engine_send_touch_add_event(FlEngine* self,
1015+
FlutterViewId view_id,
1016+
size_t timestamp,
1017+
double x,
1018+
double y,
1019+
int32_t device) {
1020+
g_return_if_fail(FL_IS_ENGINE(self));
1021+
1022+
if (self->engine == nullptr) {
1023+
return;
1024+
}
1025+
1026+
FlutterPointerEvent event;
1027+
event.timestamp = timestamp;
1028+
event.x = x;
1029+
event.y = y;
1030+
event.device_kind = kFlutterPointerDeviceKindTouch;
1031+
event.device = device;
1032+
event.buttons = 0;
1033+
event.view_id = view_id;
1034+
event.phase = FlutterPointerPhase::kAdd;
1035+
event.struct_size = sizeof(event);
1036+
1037+
self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1038+
}
1039+
1040+
void fl_engine_send_touch_remove_event(FlEngine* self,
1041+
FlutterViewId view_id,
1042+
size_t timestamp,
1043+
double x,
1044+
double y,
1045+
int32_t device) {
1046+
g_return_if_fail(FL_IS_ENGINE(self));
1047+
1048+
if (self->engine == nullptr) {
1049+
return;
1050+
}
1051+
1052+
FlutterPointerEvent event;
1053+
event.timestamp = timestamp;
1054+
event.x = x;
1055+
event.y = y;
1056+
event.device_kind = kFlutterPointerDeviceKindTouch;
1057+
event.device = device;
1058+
event.buttons = 0;
1059+
event.view_id = view_id;
1060+
event.phase = FlutterPointerPhase::kRemove;
1061+
event.struct_size = sizeof(event);
1062+
1063+
self->embedder_api.SendPointerEvent(self->engine, &event, 1);
1064+
}
1065+
9361066
void fl_engine_send_pointer_pan_zoom_event(FlEngine* self,
9371067
FlutterViewId view_id,
9381068
size_t timestamp,

shell/platform/linux/fl_engine_private.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,95 @@ void fl_engine_send_mouse_pointer_event(FlEngine* engine,
252252
double scroll_delta_y,
253253
int64_t buttons);
254254

255+
/**
256+
* fl_engine_send_touch_up_event:
257+
* @engine: an #FlEngine.
258+
* @view_id: the view that the event occured on.
259+
* @timestamp: time when event occurred in microseconds.
260+
* @x: x location of mouse cursor.
261+
* @y: y location of mouse cursor.
262+
* @device: device id.
263+
*
264+
* Sends a touch up event to the engine.
265+
*/
266+
void fl_engine_send_touch_up_event(FlEngine* engine,
267+
FlutterViewId view_id,
268+
size_t timestamp,
269+
double x,
270+
double y,
271+
int32_t device);
272+
273+
/**
274+
* fl_engine_send_touch_down_event:
275+
* @engine: an #FlEngine.
276+
* @view_id: the view that the event occured on.
277+
* @timestamp: time when event occurred in microseconds.
278+
* @x: x location of mouse cursor.
279+
* @y: y location of mouse cursor.
280+
* @device: device id.
281+
*
282+
* Sends a touch down event to the engine.
283+
*/
284+
void fl_engine_send_touch_down_event(FlEngine* engine,
285+
FlutterViewId view_id,
286+
size_t timestamp,
287+
double x,
288+
double y,
289+
int32_t device);
290+
/**
291+
* fl_engine_send_touch_move_event:
292+
* @engine: an #FlEngine.
293+
* @view_id: the view that the event occured on.
294+
* @timestamp: time when event occurred in microseconds.
295+
* @x: x location of mouse cursor.
296+
* @y: y location of mouse cursor.
297+
* @device: device id.
298+
*
299+
* Sends a touch move event to the engine.
300+
*/
301+
void fl_engine_send_touch_move_event(FlEngine* engine,
302+
FlutterViewId view_id,
303+
size_t timestamp,
304+
double x,
305+
double y,
306+
int32_t device);
307+
308+
/**
309+
* fl_engine_send_touch_add_event:
310+
* @engine: an #FlEngine.
311+
* @view_id: the view that the event occured on.
312+
* @timestamp: time when event occurred in microseconds.
313+
* @x: x location of mouse cursor.
314+
* @y: y location of mouse cursor.
315+
* @device: device id.
316+
*
317+
* Sends a touch add event to the engine.
318+
*/
319+
void fl_engine_send_touch_add_event(FlEngine* engine,
320+
FlutterViewId view_id,
321+
size_t timestamp,
322+
double x,
323+
double y,
324+
int32_t device);
325+
326+
/**
327+
* fl_engine_send_touch_remove_event:
328+
* @engine: an #FlEngine.
329+
* @view_id: the view that the event occured on.
330+
* @timestamp: time when event occurred in microseconds.
331+
* @x: x location of mouse cursor.
332+
* @y: y location of mouse cursor.
333+
* @device: device id.
334+
*
335+
* Sends a touch remove event to the engine.
336+
*/
337+
void fl_engine_send_touch_remove_event(FlEngine* engine,
338+
FlutterViewId view_id,
339+
size_t timestamp,
340+
double x,
341+
double y,
342+
int32_t device);
343+
255344
/**
256345
* fl_engine_send_pointer_pan_zoom_event:
257346
* @engine: an #FlEngine.

0 commit comments

Comments
 (0)