42 FlTouchManager*
self = FL_TOUCH_MANAGER(
object);
44 g_weak_ref_clear(&self->engine);
46 g_clear_pointer(&self->added_touch_devices, g_hash_table_unref);
48 g_clear_pointer(&self->number_to_id, g_hash_table_unref);
50 G_OBJECT_CLASS(fl_touch_manager_parent_class)->dispose(
object);
60 g_return_val_if_fail(FL_IS_ENGINE(engine),
nullptr);
62 FlTouchManager*
self =
63 FL_TOUCH_MANAGER(g_object_new(fl_touch_manager_get_type(),
nullptr));
65 g_weak_ref_init(&self->engine, engine);
69 g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr,
nullptr);
71 self->added_touch_devices =
72 g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr, g_free);
89 self->added_touch_devices, GINT_TO_POINTER(touch_id)));
90 if (point !=
nullptr) {
96 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
97 if (engine ==
nullptr) {
109 g_hash_table_insert(self->added_touch_devices, GINT_TO_POINTER(touch_id),
117 if (g_hash_table_lookup_extended(self->number_to_id, GUINT_TO_POINTER(number),
120 if (
value ==
nullptr) {
123 id = GPOINTER_TO_UINT(
value);
127 g_autoptr(GList) values = g_hash_table_get_values(self->number_to_id);
128 while (values !=
nullptr &&
129 g_list_find(values, GUINT_TO_POINTER(self->min_touch_device_id)) !=
132 ++
self->min_touch_device_id;
138 g_hash_table_insert(self->number_to_id, GUINT_TO_POINTER(number),
139 GUINT_TO_POINTER(self->min_touch_device_id));
140 return self->min_touch_device_id;
144 if (g_hash_table_contains(self->number_to_id, GINT_TO_POINTER(number))) {
145 auto id = g_hash_table_lookup(self->number_to_id, GINT_TO_POINTER(number));
146 if (GPOINTER_TO_UINT(
id) < self->min_touch_device_id) {
147 self->min_touch_device_id = GPOINTER_TO_UINT(
id);
149 g_hash_table_remove(self->number_to_id, GINT_TO_POINTER(number));
158 g_hash_table_remove(self->added_touch_devices, GINT_TO_POINTER(touch_id));
162 GdkEventTouch* touch_event,
164 g_return_if_fail(FL_IS_TOUCH_MANAGER(
self));
166 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
167 if (engine ==
nullptr) {
171 GdkEvent*
event =
reinterpret_cast<GdkEvent*
>(touch_event);
173 GdkEventSequence* seq = gdk_event_get_event_sequence(event);
175 uint32_t
id =
reinterpret_cast<uint64_t
>(seq);
180 static_cast<int32_t
>(kFlutterPointerDeviceKindTouch) << 28 | touch_id;
182 gdouble event_x = 0.0, event_y = 0.0;
183 gdk_event_get_coords(event, &event_x, &event_y);
185 double x = event_x * scale_factor;
186 double y = event_y * scale_factor;
188 guint event_time = gdk_event_get_time(event);
192 GdkEventType touch_event_type = gdk_event_get_event_type(event);
194 switch (touch_event_type) {
195 case GDK_TOUCH_BEGIN:
200 case GDK_TOUCH_UPDATE:
215 case GDK_TOUCH_CANCEL:
234 g_return_if_fail(FL_IS_TOUCH_MANAGER(
self));
236 if (g_hash_table_size(self->added_touch_devices) == 0) {
240 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
241 if (engine ==
nullptr) {
246 g_hash_table_iter_init(&iter, self->added_touch_devices);
248 while (g_hash_table_iter_next(&iter, &key, &
value)) {
249 uint32_t touch_id = GPOINTER_TO_UINT(key);
252 static_cast<int32_t
>(kFlutterPointerDeviceKindTouch) << 28 | touch_id;
256 point->
x, point->
y, device_id);
260 point->
x, point->
y, device_id);
266 g_hash_table_remove_all(self->added_touch_devices);
g_autoptr(FlEngine) engine
void fl_engine_send_touch_up_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
void fl_engine_send_touch_move_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
void fl_engine_send_touch_add_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
void fl_engine_send_touch_remove_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
void fl_engine_send_touch_cancel_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
void fl_engine_send_touch_down_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, int32_t device)
static void fl_touch_manager_class_init(FlTouchManagerClass *klass)
static void release_number(_FlTouchManager *self, uint32_t number)
static void fl_touch_manager_init(FlTouchManager *self)
static const int kMaxTouchDeviceId
G_DEFINE_TYPE(FlTouchManager, fl_touch_manager, G_TYPE_OBJECT)
void fl_touch_manager_cancel_input(FlTouchManager *self, guint event_time)
void fl_touch_manager_handle_touch_event(FlTouchManager *self, GdkEventTouch *touch_event, gint scale_factor)
static void ensure_touch_added(_FlTouchManager *self, guint event_time, gdouble x, gdouble y, uint32_t number, int32_t touch_id, int32_t device_id)
static const int kMinTouchDeviceId
static constexpr int kMicrosecondsPerMillisecond
static uint32_t get_generated_id(_FlTouchManager *self, uint32_t number)
static void fl_touch_manager_dispose(GObject *object)
static void remove_touch_point(_FlTouchManager *self, uint32_t number, uint32_t touch_id)
FlTouchManager * fl_touch_manager_new(FlEngine *engine, FlutterViewId view_id)
G_BEGIN_DECLS FlutterViewId view_id
GHashTable * added_touch_devices
guint min_touch_device_id
GHashTable * number_to_id