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

Commit 6b52610

Browse files
committed
Map pointer type on Linux
1 parent 8639505 commit 6b52610

File tree

8 files changed

+61
-19
lines changed

8 files changed

+61
-19
lines changed

shell/platform/linux/fl_engine.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void fl_engine_send_mouse_pointer_event(FlEngine* self,
712712
size_t timestamp,
713713
double x,
714714
double y,
715+
FlutterPointerDeviceKind device_kind,
715716
double scroll_delta_x,
716717
double scroll_delta_y,
717718
int64_t buttons) {
@@ -732,7 +733,7 @@ void fl_engine_send_mouse_pointer_event(FlEngine* self,
732733
}
733734
fl_event.scroll_delta_x = scroll_delta_x;
734735
fl_event.scroll_delta_y = scroll_delta_y;
735-
fl_event.device_kind = kFlutterPointerDeviceKindMouse;
736+
fl_event.device_kind = device_kind;
736737
fl_event.buttons = buttons;
737738
fl_event.device = kMousePointerDeviceId;
738739
self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);

shell/platform/linux/fl_engine_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ void fl_engine_send_window_metrics_event(FlEngine* engine,
174174
* @timestamp: time when event occurred in microseconds.
175175
* @x: x location of mouse cursor.
176176
* @y: y location of mouse cursor.
177+
* @device_kind: kind of pointing device.
177178
* @scroll_delta_x: x offset of scroll.
178179
* @scroll_delta_y: y offset of scroll.
179180
* @buttons: buttons that are pressed.
@@ -185,6 +186,7 @@ void fl_engine_send_mouse_pointer_event(FlEngine* engine,
185186
size_t timestamp,
186187
double x,
187188
double y,
189+
FlutterPointerDeviceKind device_kind,
188190
double scroll_delta_x,
189191
double scroll_delta_y,
190192
int64_t buttons);

shell/platform/linux/fl_engine_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ TEST(FlEngineTest, MousePointer) {
6868
g_autoptr(GError) error = nullptr;
6969
EXPECT_TRUE(fl_engine_start(engine, &error));
7070
EXPECT_EQ(error, nullptr);
71-
fl_engine_send_mouse_pointer_event(engine, kDown, 1234567890, 800, 600, 1.2,
72-
-3.4, kFlutterPointerButtonMouseSecondary);
71+
fl_engine_send_mouse_pointer_event(engine, kDown, 1234567890, 800, 600,
72+
kFlutterPointerDeviceKindMouse, 1.2, -3.4,
73+
kFlutterPointerButtonMouseSecondary);
7374

7475
EXPECT_TRUE(called);
7576
}

shell/platform/linux/fl_scrolling_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void fl_scrolling_manager_handle_scroll_event(FlScrollingManager* self,
123123
this is a discrete scroll event */
124124
,
125125
event->time * kMicrosecondsPerMillisecond, event->x * scale_factor,
126-
event->y * scale_factor, scroll_delta_x, scroll_delta_y, 0);
126+
event->y * scale_factor, kFlutterPointerDeviceKindMouse, scroll_delta_x,
127+
scroll_delta_y, 0);
127128
}
128129
}
129130

shell/platform/linux/fl_scrolling_manager_test.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ typedef std::function<void(FlutterPointerPhase phase,
1313
size_t timestamp,
1414
double x,
1515
double y,
16+
FlutterPointerDeviceKind device_kind,
1617
double scroll_delta_x,
1718
double scroll_delta_y,
1819
int64_t buttons)>
@@ -32,6 +33,7 @@ typedef struct {
3233
size_t timestamp;
3334
double x;
3435
double y;
36+
FlutterPointerDeviceKind device_kind;
3537
double scroll_delta_x;
3638
double scroll_delta_y;
3739
int64_t buttons;
@@ -95,12 +97,13 @@ static void fl_mock_view_send_mouse_pointer_event(
9597
size_t timestamp,
9698
double x,
9799
double y,
100+
FlutterPointerDeviceKind device_kind,
98101
double scroll_delta_x,
99102
double scroll_delta_y,
100103
int64_t buttons) {
101104
FlMockScrollingViewDelegate* self = FL_MOCK_SCROLLING_VIEW_DELEGATE(delegate);
102-
self->mouse_handler(phase, timestamp, x, y, scroll_delta_x, scroll_delta_y,
103-
buttons);
105+
self->mouse_handler(phase, timestamp, x, y, device_kind, scroll_delta_x,
106+
scroll_delta_y, buttons);
104107
}
105108

106109
static void fl_mock_view_send_pointer_pan_zoom_event(
@@ -155,7 +158,8 @@ class ScrollingTester {
155158
fl_mock_scrolling_view_set_mouse_handler(
156159
view_,
157160
[](FlutterPointerPhase phase, size_t timestamp, double x, double y,
158-
double scroll_delta_x, double scroll_delta_y, int64_t buttons) {
161+
FlutterPointerDeviceKind device_kind, double scroll_delta_x,
162+
double scroll_delta_y, int64_t buttons) {
159163
// do nothing
160164
});
161165
fl_mock_scrolling_view_set_pan_zoom_handler(
@@ -177,13 +181,15 @@ class ScrollingTester {
177181
std::vector<MousePointerEventRecord>& storage) {
178182
fl_mock_scrolling_view_set_mouse_handler(
179183
view_, [&storage](FlutterPointerPhase phase, size_t timestamp, double x,
180-
double y, double scroll_delta_x,
181-
double scroll_delta_y, int64_t buttons) {
184+
double y, FlutterPointerDeviceKind device_kind,
185+
double scroll_delta_x, double scroll_delta_y,
186+
int64_t buttons) {
182187
storage.push_back(MousePointerEventRecord{
183188
.phase = phase,
184189
.timestamp = timestamp,
185190
.x = x,
186191
.y = y,
192+
.device_kind = device_kind,
187193
.scroll_delta_x = scroll_delta_x,
188194
.scroll_delta_y = scroll_delta_y,
189195
.buttons = buttons,
@@ -249,6 +255,7 @@ TEST(FlScrollingManagerTest, DiscreteDirectionional) {
249255
EXPECT_EQ(mouse_records.size(), 1u);
250256
EXPECT_EQ(mouse_records[0].x, 4.0);
251257
EXPECT_EQ(mouse_records[0].y, 8.0);
258+
EXPECT_EQ(mouse_records[0].device_kind, kFlutterPointerDeviceKindMouse);
252259
EXPECT_EQ(mouse_records[0].timestamp,
253260
1000lu); // Milliseconds -> Microseconds
254261
EXPECT_EQ(mouse_records[0].scroll_delta_x, 0);
@@ -259,6 +266,7 @@ TEST(FlScrollingManagerTest, DiscreteDirectionional) {
259266
EXPECT_EQ(mouse_records.size(), 2u);
260267
EXPECT_EQ(mouse_records[1].x, 4.0);
261268
EXPECT_EQ(mouse_records[1].y, 8.0);
269+
EXPECT_EQ(mouse_records[1].device_kind, kFlutterPointerDeviceKindMouse);
262270
EXPECT_EQ(mouse_records[1].timestamp,
263271
1000lu); // Milliseconds -> Microseconds
264272
EXPECT_EQ(mouse_records[1].scroll_delta_x, 0);
@@ -269,6 +277,7 @@ TEST(FlScrollingManagerTest, DiscreteDirectionional) {
269277
EXPECT_EQ(mouse_records.size(), 3u);
270278
EXPECT_EQ(mouse_records[2].x, 4.0);
271279
EXPECT_EQ(mouse_records[2].y, 8.0);
280+
EXPECT_EQ(mouse_records[2].device_kind, kFlutterPointerDeviceKindMouse);
272281
EXPECT_EQ(mouse_records[2].timestamp,
273282
1000lu); // Milliseconds -> Microseconds
274283
EXPECT_EQ(mouse_records[2].scroll_delta_x, 53 * -1.0);
@@ -279,6 +288,7 @@ TEST(FlScrollingManagerTest, DiscreteDirectionional) {
279288
EXPECT_EQ(mouse_records.size(), 4u);
280289
EXPECT_EQ(mouse_records[3].x, 4.0);
281290
EXPECT_EQ(mouse_records[3].y, 8.0);
291+
EXPECT_EQ(mouse_records[3].device_kind, kFlutterPointerDeviceKindMouse);
282292
EXPECT_EQ(mouse_records[3].timestamp,
283293
1000lu); // Milliseconds -> Microseconds
284294
EXPECT_EQ(mouse_records[3].scroll_delta_x, 53 * 1.0);
@@ -305,6 +315,7 @@ TEST(FlScrollingManagerTest, DiscreteScrolling) {
305315
EXPECT_EQ(mouse_records.size(), 1u);
306316
EXPECT_EQ(mouse_records[0].x, 4.0);
307317
EXPECT_EQ(mouse_records[0].y, 8.0);
318+
EXPECT_EQ(mouse_records[0].device_kind, kFlutterPointerDeviceKindMouse);
308319
EXPECT_EQ(mouse_records[0].timestamp,
309320
1000lu); // Milliseconds -> Microseconds
310321
EXPECT_EQ(mouse_records[0].scroll_delta_x, 53 * 1.0);

shell/platform/linux/fl_scrolling_view_delegate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ void fl_scrolling_view_delegate_send_mouse_pointer_event(
1717
size_t timestamp,
1818
double x,
1919
double y,
20+
FlutterPointerDeviceKind device_kind,
2021
double scroll_delta_x,
2122
double scroll_delta_y,
2223
int64_t buttons) {
2324
g_return_if_fail(FL_IS_SCROLLING_VIEW_DELEGATE(self));
2425

2526
FL_SCROLLING_VIEW_DELEGATE_GET_IFACE(self)->send_mouse_pointer_event(
26-
self, phase, timestamp, x, y, scroll_delta_x, scroll_delta_y, buttons);
27+
self, phase, timestamp, x, y, device_kind, scroll_delta_x, scroll_delta_y,
28+
buttons);
2729
}
2830
void fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
2931
FlScrollingViewDelegate* self,

shell/platform/linux/fl_scrolling_view_delegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct _FlScrollingViewDelegateInterface {
3838
size_t timestamp,
3939
double x,
4040
double y,
41+
FlutterPointerDeviceKind device_kind,
4142
double scroll_delta_x,
4243
double scroll_delta_y,
4344
int64_t buttons);
@@ -59,6 +60,7 @@ void fl_scrolling_view_delegate_send_mouse_pointer_event(
5960
size_t timestamp,
6061
double x,
6162
double y,
63+
FlutterPointerDeviceKind device_kind,
6264
double scroll_delta_x,
6365
double scroll_delta_y,
6466
int64_t buttons);

shell/platform/linux/fl_view.cc

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ static void init_scrolling(FlView* self) {
114114
fl_scrolling_manager_new(FL_SCROLLING_VIEW_DELEGATE(self));
115115
}
116116

117+
static FlutterPointerDeviceKind get_device_kind(GdkEvent* event) {
118+
GdkDevice* device = gdk_event_get_source_device(event);
119+
GdkInputSource source = gdk_device_get_source(device);
120+
switch (source) {
121+
case GDK_SOURCE_PEN:
122+
case GDK_SOURCE_ERASER:
123+
case GDK_SOURCE_CURSOR:
124+
case GDK_SOURCE_TABLET_PAD:
125+
return kFlutterPointerDeviceKindStylus;
126+
case GDK_SOURCE_TOUCHSCREEN:
127+
return kFlutterPointerDeviceKindTouch;
128+
case GDK_SOURCE_TOUCHPAD: // trackpad device type is reserved for gestures
129+
case GDK_SOURCE_TRACKPOINT:
130+
case GDK_SOURCE_KEYBOARD:
131+
case GDK_SOURCE_MOUSE:
132+
return kFlutterPointerDeviceKindMouse;
133+
}
134+
}
135+
117136
// Converts a GDK button event into a Flutter event and sends it to the engine.
118137
static gboolean send_pointer_button_event(FlView* self, GdkEventButton* event) {
119138
int64_t button;
@@ -160,8 +179,8 @@ static gboolean send_pointer_button_event(FlView* self, GdkEventButton* event) {
160179
event->y * scale_factor);
161180
fl_engine_send_mouse_pointer_event(
162181
self->engine, phase, event->time * kMicrosecondsPerMillisecond,
163-
event->x * scale_factor, event->y * scale_factor, 0, 0,
164-
self->button_state);
182+
event->x * scale_factor, event->y * scale_factor,
183+
get_device_kind((GdkEvent*)event), 0, 0, self->button_state);
165184

166185
return TRUE;
167186
}
@@ -178,7 +197,8 @@ static void check_pointer_inside(FlView* view, GdkEvent* event) {
178197
fl_engine_send_mouse_pointer_event(
179198
view->engine, kAdd,
180199
gdk_event_get_time(event) * kMicrosecondsPerMillisecond,
181-
x * scale_factor, y * scale_factor, 0, 0, view->button_state);
200+
x * scale_factor, y * scale_factor, get_device_kind(event), 0, 0,
201+
view->button_state);
182202
}
183203
}
184204
}
@@ -311,13 +331,14 @@ static void fl_view_scrolling_delegate_iface_init(
311331
FlScrollingViewDelegateInterface* iface) {
312332
iface->send_mouse_pointer_event =
313333
[](FlScrollingViewDelegate* view_delegate, FlutterPointerPhase phase,
314-
size_t timestamp, double x, double y, double scroll_delta_x,
334+
size_t timestamp, double x, double y,
335+
FlutterPointerDeviceKind device_kind, double scroll_delta_x,
315336
double scroll_delta_y, int64_t buttons) {
316337
FlView* self = FL_VIEW(view_delegate);
317338
if (self->engine != nullptr) {
318339
fl_engine_send_mouse_pointer_event(self->engine, phase, timestamp, x,
319-
y, scroll_delta_x, scroll_delta_y,
320-
buttons);
340+
y, device_kind, scroll_delta_x,
341+
scroll_delta_y, buttons);
321342
}
322343
};
323344
iface->send_pointer_pan_zoom_event =
@@ -384,7 +405,8 @@ static gboolean motion_notify_event_cb(GtkWidget* widget,
384405
fl_engine_send_mouse_pointer_event(
385406
view->engine, view->button_state != 0 ? kMove : kHover,
386407
event->time * kMicrosecondsPerMillisecond, event->x * scale_factor,
387-
event->y * scale_factor, 0, 0, view->button_state);
408+
event->y * scale_factor, get_device_kind((GdkEvent*)event), 0, 0,
409+
view->button_state);
388410

389411
return TRUE;
390412
}
@@ -417,8 +439,8 @@ static gboolean leave_notify_event_cb(GtkWidget* widget,
417439
gint scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(view));
418440
fl_engine_send_mouse_pointer_event(
419441
view->engine, kRemove, event->time * kMicrosecondsPerMillisecond,
420-
event->x * scale_factor, event->y * scale_factor, 0, 0,
421-
view->button_state);
442+
event->x * scale_factor, event->y * scale_factor,
443+
get_device_kind((GdkEvent*)event), 0, 0, view->button_state);
422444
view->pointer_inside = FALSE;
423445
}
424446

0 commit comments

Comments
 (0)