| Flutter Linux Embedder |

Functions
fl_touch_manager.h File Reference
`#include <gdk/gdk.h>`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`

Go to the source code of this file.

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlTouchManager, fl_touch_manager, FL, TOUCH_MANAGER, GObject)
FlTouchManager * | fl_touch_manager_new (FlEngine *engine, FlutterViewId view_id)
void | fl_touch_manager_handle_touch_event (FlTouchManager *manager, GdkEventTouch *event, gint scale_factor)

## Function Documentation

## ◆ 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 }
g_autoptr
g_autoptr(FlEngine) engine
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
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_touch_manager.cc:8
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_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_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlTouchManager | ,
|  | fl_touch_manager | ,
|  | FL | ,
|  | TOUCH_MANAGER | ,
|  | GObject |
| ) |  |