| Flutter Linux Embedder |

Classes | Functions | Variables
fl_touch_manager.cc File Reference
`#include "flutter/shell/platform/linux/fl_touch_manager.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`

Go to the source code of this file.

## Classes
struct | _FlTouchManager

## Functions
| G_DEFINE_TYPE (FlTouchManager, fl_touch_manager, G_TYPE_OBJECT)
static void | fl_touch_manager_dispose (GObject *object)
static void | fl_touch_manager_class_init (FlTouchManagerClass *klass)
static void | fl_touch_manager_init (FlTouchManager *self)
FlTouchManager * | fl_touch_manager_new (FlEngine *engine, FlutterViewId view_id)
static void | ensure_touch_added (_FlTouchManager *self, guint event_time, gdouble x, gdouble y, int32_t touch_id, int32_t device_id)
static uint32_t | get_generated_id (_FlTouchManager *self, uint32_t number)
static void | release_number (_FlTouchManager *self, uint32_t number)
void | fl_touch_manager_handle_touch_event (FlTouchManager *self, GdkEventTouch *touch_event, gint scale_factor)

## Variables
static constexpr int | kMicrosecondsPerMillisecond = 1000
static const int | kMinTouchDeviceId = 0
static const int | kMaxTouchDeviceId = 128

## Function Documentation

## ◆ ensure_touch_added()

static void ensure_touch_added | ( | _FlTouchManager * | self,
|  | guint | event_time,
|  | gdouble | x,
|  | gdouble | y,
|  | int32_t | touch_id,
|  | int32_t | device_id
| ) |  |
| static

Definition at line 66 of file fl_touch_manager.cc.

71 {
72 // Check if we need to send a touch add event.
73 if (g_list_find(self->added_touch_devices, GINT_TO_POINTER(touch_id)) !=
74 nullptr) {
75 return;
76 }
77
78 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
79 if (engine == nullptr) {
80 return;
81 }
82
83 fl_engine_send_touch_add_event(engine, self->view_id,
84 event_time * kMicrosecondsPerMillisecond, x, y,
85 device_id);
86
87 self->added_touch_devices =
88 g_list_append(self->added_touch_devices, GINT_TO_POINTER(touch_id));
89 }
g_autoptr
g_autoptr(FlEngine) engine
fl_engine_send_touch_add_event
void fl_engine_send_touch_add_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1260
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_touch_manager.cc:8
_FlTouchManager::engine
GWeakRef engine
Definition: fl_touch_manager.cc:15
_FlTouchManager::added_touch_devices
GList * added_touch_devices
Definition: fl_touch_manager.cc:20
_FlTouchManager::view_id
FlutterViewId view_id
Definition: fl_touch_manager.cc:17

References fl_engine_send_touch_add_event(), g_autoptr(), and kMicrosecondsPerMillisecond.

Referenced by fl_touch_manager_handle_touch_event().

## ◆ fl_touch_manager_class_init()

static void fl_touch_manager_class_init | ( | FlTouchManagerClass * | klass | ) |
| static

Definition at line 42 of file fl_touch_manager.cc.

42 {
43 G_OBJECT_CLASS(klass)->dispose = fl_touch_manager_dispose;
44 }
fl_touch_manager_dispose
static void fl_touch_manager_dispose(GObject *object)
Definition: fl_touch_manager.cc:30

References fl_touch_manager_dispose().

## ◆ fl_touch_manager_dispose()

static void fl_touch_manager_dispose | ( | GObject * | object | ) |
| static

Definition at line 30 of file fl_touch_manager.cc.

30 {
31 FlTouchManager* self = FL_TOUCH_MANAGER(object);
32
33 g_weak_ref_clear(&self->engine);
34
35 g_list_free(self->added_touch_devices);
36
37 g_clear_pointer(&self->number_to_id, g_hash_table_unref);
38
39 G_OBJECT_CLASS(fl_touch_manager_parent_class)->dispose(object);
40 }

Referenced by fl_touch_manager_class_init().

## ◆ fl_touch_manager_handle_touch_event()

void fl_touch_manager_handle_touch_event | ( | FlTouchManager * | manager,
|  | GdkEventTouch * | event,
|  | gint | scale_factor
| ) |  |

fl_touch_manager_handle_touch_event: @manager: an #FlTouchManager. @event: the touch event. @scale_factor: the GTK scaling factor of the window.

Definition at line 131 of file fl_touch_manager.cc.

133 {
134 g_return_if_fail(FL_IS_TOUCH_MANAGER(self));
135
136 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
137 if (engine == nullptr) {
138 return;
139 }
140
141 GdkEvent* event = reinterpret_cast<GdkEvent*>(touch_event);
142 // get sequence id from GdkEvent
143 GdkEventSequence* seq = gdk_event_get_event_sequence(event);
144 // cast pointer to int to get unique id
145 uint32_t id = reinterpret_cast<uint64_t>(seq);
146 // generate touch id from unique id
147 auto touch_id = get_generated_id(self, id);
148 // get device id
149 auto device_id =
150 static_cast<int32_t>(kFlutterPointerDeviceKindTouch) << 28 | touch_id;
151
152 gdouble event_x = 0.0, event_y = 0.0;
153 gdk_event_get_coords(event, &event_x, &event_y);
154
155 double x = event_x * scale_factor;
156 double y = event_y * scale_factor;
157
158 guint event_time = gdk_event_get_time(event);
159
160 ensure_touch_added(self, event_time, x, y, touch_id, device_id);
161
162 GdkEventType touch_event_type = gdk_event_get_event_type(event);
163
164 switch (touch_event_type) {
165 case GDK_TOUCH_BEGIN:
166 fl_engine_send_touch_down_event(engine, self->view_id,
167 event_time * kMicrosecondsPerMillisecond,
168 x, y, device_id);
169 break;
170 case GDK_TOUCH_UPDATE:
171 fl_engine_send_touch_move_event(engine, self->view_id,
172 event_time * kMicrosecondsPerMillisecond,
173 x, y, device_id);
174 break;
175 case GDK_TOUCH_END:
176 fl_engine_send_touch_up_event(engine, self->view_id,
177 event_time * kMicrosecondsPerMillisecond, x,
178 y, device_id);
179
180 fl_engine_send_touch_remove_event(
181 engine, self->view_id, event_time * kMicrosecondsPerMillisecond, x, y,
182 device_id);
183 release_number(self, id);
184 self->added_touch_devices =
185 g_list_remove(self->added_touch_devices, GINT_TO_POINTER(touch_id));
186 break;
187 default:
188 break;
189 }
190 }
fl_engine_send_touch_up_event
void fl_engine_send_touch_up_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1173
fl_engine_send_touch_move_event
void fl_engine_send_touch_move_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1231
fl_engine_send_touch_remove_event
void fl_engine_send_touch_remove_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1289
fl_engine_send_touch_down_event
void fl_engine_send_touch_down_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
Definition: fl_engine.cc:1202
release_number
static void release_number(_FlTouchManager *self, uint32_t number)
Definition: fl_touch_manager.cc:121
ensure_touch_added
static void ensure_touch_added(_FlTouchManager *self, guint event_time, gdouble x, gdouble y, int32_t touch_id, int32_t device_id)
Definition: fl_touch_manager.cc:66
get_generated_id
static uint32_t get_generated_id(_FlTouchManager *self, uint32_t number)
Definition: fl_touch_manager.cc:93

References ensure_touch_added(), fl_engine_send_touch_down_event(), fl_engine_send_touch_move_event(), fl_engine_send_touch_remove_event(), fl_engine_send_touch_up_event(), g_autoptr(), get_generated_id(), kMicrosecondsPerMillisecond, and release_number().

Referenced by TEST(), and touch_event_cb().

## ◆ fl_touch_manager_init()

static void fl_touch_manager_init | ( | FlTouchManager * | self | ) |
| static

Definition at line 46 of file fl_touch_manager.cc.

46 {}

## ◆ fl_touch_manager_new()

FlTouchManager* fl_touch_manager_new | ( | FlEngine * | engine,
|  | FlutterViewId | view_id
| ) |  |

fl_touch_manager_new: @engine: an #FlEngine. @view_id: the view being managed.

Create a new #FlTouchManager.

Returns: a new #FlTouchManager.

Definition at line 48 of file fl_touch_manager.cc.

48 {
49 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
50
51 FlTouchManager* self =
52 FL_TOUCH_MANAGER(g_object_new(fl_touch_manager_get_type(), nullptr));
53
54 g_weak_ref_init(&self->engine, engine);
55 self->view_id = view_id;
56
57 self->number_to_id =
58 g_hash_table_new_full(g_direct_hash, g_direct_equal, nullptr, nullptr);
59
60 self->min_touch_device_id = kMinTouchDeviceId;
61
62 return self;
63 }
kMinTouchDeviceId
static const int kMinTouchDeviceId
Definition: fl_touch_manager.cc:9
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49

References kMinTouchDeviceId, and view_id.

Referenced by init_touch(), and TEST().

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlTouchManager | ,
|  | fl_touch_manager | ,
|  | G_TYPE_OBJECT |
| ) |  |

## ◆ get_generated_id()

static uint32_t get_generated_id | ( | _FlTouchManager * | self,
|  | uint32_t | number
| ) |  |
| static

Definition at line 93 of file fl_touch_manager.cc.

93 {
94 gpointer value;
95 if (g_hash_table_lookup_extended(self->number_to_id, GUINT_TO_POINTER(number),
96 nullptr, &value)) {
97 uint32_t id;
98 if (value == nullptr) {
99 id = 0;
100 } else {
101 id = GPOINTER_TO_UINT(value);
102 }
103 return id;
104 }
105 auto values = g_hash_table_get_values(self->number_to_id);
106 while (values != nullptr &&
107 g_list_find(values, GUINT_TO_POINTER(self->min_touch_device_id)) !=
108 nullptr &&
109 self->min_touch_device_id < kMaxTouchDeviceId) {
110 ++self->min_touch_device_id;
111 }
112 if (self->min_touch_device_id >= kMaxTouchDeviceId) {
113 self->min_touch_device_id = kMinTouchDeviceId;
114 }
115
116 g_hash_table_insert(self->number_to_id, GUINT_TO_POINTER(number),
117 GUINT_TO_POINTER(self->min_touch_device_id));
118 return self->min_touch_device_id;
119 }
id
int64_t id
Definition: fl_pixel_buffer_texture.cc:28
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
kMaxTouchDeviceId
static const int kMaxTouchDeviceId
Definition: fl_touch_manager.cc:10
_FlTouchManager::min_touch_device_id
guint min_touch_device_id
Definition: fl_touch_manager.cc:25
_FlTouchManager::number_to_id
GHashTable * number_to_id
Definition: fl_touch_manager.cc:22

References id, kMaxTouchDeviceId, kMinTouchDeviceId, and value.

Referenced by fl_touch_manager_handle_touch_event().

## ◆ release_number()

static void release_number | ( | _FlTouchManager * | self,
|  | uint32_t | number
| ) |  |
| static

Definition at line 121 of file fl_touch_manager.cc.

121 {
122 if (g_hash_table_contains(self->number_to_id, GINT_TO_POINTER(number))) {
123 auto id = g_hash_table_lookup(self->number_to_id, GINT_TO_POINTER(number));
124 if (GPOINTER_TO_UINT(id) < self->min_touch_device_id) {
125 self->min_touch_device_id = GPOINTER_TO_UINT(id);
126 }
127 g_hash_table_remove(self->number_to_id, GINT_TO_POINTER(number));
128 }
129 }

Referenced by fl_touch_manager_handle_touch_event().

## Variable Documentation

## ◆ kMaxTouchDeviceId

const int kMaxTouchDeviceId = 128
| static

Definition at line 10 of file fl_touch_manager.cc.

Referenced by get_generated_id().

## ◆ kMicrosecondsPerMillisecond

constexpr int kMicrosecondsPerMillisecond = 1000
| static constexpr

Definition at line 8 of file fl_touch_manager.cc.

Referenced by ensure_touch_added(), and fl_touch_manager_handle_touch_event().

## ◆ kMinTouchDeviceId

const int kMinTouchDeviceId = 0
| static

Definition at line 9 of file fl_touch_manager.cc.

Referenced by fl_touch_manager_new(), and get_generated_id().