Flutter Linux Embedder
fl_pointer_manager.h File Reference
#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 (FlPointerManager, fl_pointer_manager, FL, POINTER_MANAGER, GObject)
 
FlPointerManager * fl_pointer_manager_new (FlutterViewId view_id, FlEngine *engine)
 
gboolean fl_pointer_manager_handle_button_press (FlPointerManager *manager, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_button, gdouble rotation, gdouble pressure)
 
gboolean fl_pointer_manager_handle_button_release (FlPointerManager *manager, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_button, gdouble rotation, gdouble pressure)
 
gboolean fl_pointer_manager_handle_motion (FlPointerManager *manager, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, gdouble rotation, gdouble pressure)
 
gboolean fl_pointer_manager_handle_enter (FlPointerManager *manager, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_state, gdouble rotation, gdouble pressure)
 
gboolean fl_pointer_manager_handle_leave (FlPointerManager *manager, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, gdouble rotation, gdouble pressure)
 
gboolean fl_pointer_manager_cancel_input (FlPointerManager *manager, guint event_time)
 

Function Documentation

◆ fl_pointer_manager_cancel_input()

gboolean fl_pointer_manager_cancel_input ( FlPointerManager *  manager,
guint  event_time 
)

fl_pointer_manager_cancel_input: @manager: an #FlPointerManager. @event_time: time event occurred in milliseconds.

Handle the release of any buttons Flutter believes are pressed never being delivered, e.g. because the window system took the pointer to move or resize the window. Those buttons are cancelled.

Returns: TRUE if the event was handled.

Definition at line 345 of file fl_pointer_manager.cc.

346  {
347  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
348 
349  // Nothing to do if no buttons are pressed.
350  if (self->button_state == 0) {
351  return FALSE;
352  }
353 
354  self->button_state = 0;
355 
356  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
357  if (engine == nullptr) {
358  return FALSE;
359  }
360 
362  engine, self->view_id, kCancel, event_time * kMicrosecondsPerMillisecond,
363  self->last_x, self->last_y, self->last_device_kind, 0, 0,
364  self->button_state, self->last_rotation, self->last_pressure);
365 
366  // The pointer left the view while the button was down, so the remove event
367  // was delayed until the button was released. That release will never
368  // arrive, so remove the pointer now.
369  if (self->leave_pending) {
371  engine, self->view_id, kRemove,
372  event_time * kMicrosecondsPerMillisecond, self->last_x, self->last_y,
373  self->last_device_kind, 0, 0, self->button_state, self->last_rotation,
374  self->last_pressure);
375  self->pointer_inside = FALSE;
376  self->leave_pending = FALSE;
377  }
378 
379  return TRUE;
380 }
g_autoptr(FlEngine) engine
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterViewId view_id, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons, double rotation, double pressure)
Definition: fl_engine.cc:1229
static constexpr int kMicrosecondsPerMillisecond

References fl_engine_send_mouse_pointer_event(), g_autoptr(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by cancel_input(), fl_pointer_manager_handle_button_press(), fl_pointer_manager_handle_enter(), and TEST_F().

◆ fl_pointer_manager_handle_button_press()

gboolean fl_pointer_manager_handle_button_press ( FlPointerManager *  manager,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y,
guint  gdk_button,
gdouble  rotation,
gdouble  pressure 
)

fl_pointer_manager_handle_button_press: @manager: an #FlPointerManager. @event_time: event time in milliseconds. @device_kind: kind of device generating the event. @x: x co-ordinate of event. @y: y co-ordinate of event. @gdk_button: button being pressed. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Returns TRUE if this event was handled.

Definition at line 172 of file fl_pointer_manager.cc.

180  {
181  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
182 
183  int64_t button;
184  if (!get_button(device_kind, gdk_button, &button)) {
185  return FALSE;
186  }
187 
188  ensure_pointer_added(self, event_time, device_kind, x, y, rotation, pressure);
189 
190  // GDK never sends two presses of the same button without a release in
191  // between, so if Flutter thinks this button is already down then the release
192  // was lost, e.g. it was delivered to the window manager because it ended an
193  // interactive move or resize. Cancel the stale press so this one is not
194  // dropped.
195  if ((self->button_state & button) != 0) {
196  fl_pointer_manager_cancel_input(self, event_time);
197  }
198 
199  int old_button_state = self->button_state;
200  FlutterPointerPhase phase = kMove;
201  self->button_state ^= button;
202  phase = old_button_state == 0 ? kDown : kMove;
203 
204  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
205  if (engine == nullptr) {
206  return FALSE;
207  }
208 
210  engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
211  y, device_kind, 0, 0, self->button_state, rotation, pressure);
212 
213  return TRUE;
214 }
static gboolean get_button(FlutterPointerDeviceKind device_kind, guint gdk_button, int64_t *button)
static void ensure_pointer_added(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, gdouble rotation, gdouble pressure)
gboolean fl_pointer_manager_cancel_input(FlPointerManager *self, guint event_time)

References ensure_pointer_added(), fl_engine_send_mouse_pointer_event(), fl_pointer_manager_cancel_input(), g_autoptr(), get_button(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by button_press_event_cb(), and TEST_F().

◆ fl_pointer_manager_handle_button_release()

gboolean fl_pointer_manager_handle_button_release ( FlPointerManager *  manager,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y,
guint  gdk_button,
gdouble  rotation,
gdouble  pressure 
)

fl_pointer_manager_handle_button_release: @manager: an #FlPointerManager. @event_time: event time in milliseconds. @device_kind: kind of device generating the event. @x: x co-ordinate of event. @y: y co-ordinate of event. @gdk_button: button being released. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Returns TRUE if this event was handled.

Definition at line 216 of file fl_pointer_manager.cc.

224  {
225  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
226 
227  int64_t button;
228  if (!get_button(device_kind, gdk_button, &button)) {
229  return FALSE;
230  }
231 
232  record_pointer_state(self, device_kind, x, y, rotation, pressure);
233 
234  // Drop the event if Flutter already thinks the button is up.
235  if ((self->button_state & button) == 0) {
236  return FALSE;
237  }
238 
239  FlutterPointerPhase phase = kMove;
240  self->button_state ^= button;
241 
242  phase = self->button_state == 0 ? kUp : kMove;
243 
244  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
245  if (engine == nullptr) {
246  return FALSE;
247  }
248 
250  engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
251  y, device_kind, 0, 0, self->button_state, rotation, pressure);
252 
253  return TRUE;
254 }
static void record_pointer_state(FlPointerManager *self, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, gdouble rotation, gdouble pressure)

References fl_engine_send_mouse_pointer_event(), g_autoptr(), get_button(), kMicrosecondsPerMillisecond, record_pointer_state(), and TRUE.

Referenced by button_release_event_cb(), and TEST_F().

◆ fl_pointer_manager_handle_enter()

gboolean fl_pointer_manager_handle_enter ( FlPointerManager *  manager,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y,
guint  gdk_state,
gdouble  rotation,
gdouble  pressure 
)

fl_pointer_manager_handle_enter: @manager: an #FlPointerManager. @event_time: event time in milliseconds. @device_kind: kind of device generating the event. @x: x co-ordinate of event. @y: y co-ordinate of event. @gdk_state: GDK state of buttons and modifiers when the event occurred. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Returns TRUE if this event was handled.

Definition at line 280 of file fl_pointer_manager.cc.

287  {
288  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
289 
290  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
291  if (engine == nullptr) {
292  return FALSE;
293  }
294 
295  ensure_pointer_added(self, event_time, device_kind, x, y, rotation, pressure);
296 
297  // The window system takes the pointer for interactive moves and resizes, and
298  // gives it back without saying the button was released. Cancel the press if
299  // the pointer has come back with nothing pressed.
300  if (self->button_state != 0 && !has_buttons_pressed(gdk_state)) {
301  fl_pointer_manager_cancel_input(self, event_time);
302  }
303 
304  return TRUE;
305 }
static gboolean has_buttons_pressed(guint gdk_state)

References ensure_pointer_added(), fl_pointer_manager_cancel_input(), g_autoptr(), has_buttons_pressed(), and TRUE.

Referenced by enter_notify_event_cb(), and TEST_F().

◆ fl_pointer_manager_handle_leave()

gboolean fl_pointer_manager_handle_leave ( FlPointerManager *  manager,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y,
gdouble  rotation,
gdouble  pressure 
)

fl_pointer_manager_handle_leave: @manager: an #FlPointerManager. @event_time: event time in milliseconds. @device_kind: kind of device generating the event. @x: x co-ordinate of event. @y: y co-ordinate of event. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Returns TRUE if this event was handled.

Definition at line 307 of file fl_pointer_manager.cc.

313  {
314  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
315 
316  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
317  if (engine == nullptr) {
318  return FALSE;
319  }
320 
321  if (!self->pointer_inside) {
322  return TRUE;
323  }
324 
325  // Don't remove pointer while button is down; In case of dragging outside of
326  // window with mouse grab active Gtk will send another leave notify on
327  // release. Remember the leave so the pointer can still be removed if that
328  // release is never delivered, e.g. because the window system took the
329  // pointer.
330  if (self->button_state != 0) {
331  record_pointer_state(self, device_kind, x, y, rotation, pressure);
332  self->leave_pending = TRUE;
333  return TRUE;
334  }
335 
337  engine, self->view_id, kRemove, event_time * kMicrosecondsPerMillisecond,
338  x, y, device_kind, 0, 0, self->button_state, rotation, pressure);
339  self->pointer_inside = FALSE;
340  self->leave_pending = FALSE;
341 
342  return TRUE;
343 }

References fl_engine_send_mouse_pointer_event(), g_autoptr(), kMicrosecondsPerMillisecond, record_pointer_state(), and TRUE.

Referenced by leave_notify_event_cb(), and TEST_F().

◆ fl_pointer_manager_handle_motion()

gboolean fl_pointer_manager_handle_motion ( FlPointerManager *  manager,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y,
gdouble  rotation,
gdouble  pressure 
)

fl_pointer_manager_handle_motion: @manager: an #FlPointerManager. @event_time: event time in milliseconds. @device_kind: kind of device generating the event. @x: x co-ordinate of event. @y: y co-ordinate of event. @rotation: rotation of the pointer device in degrees. @pressure: pressure of the pointer device.

Returns TRUE if this event was handled.

Definition at line 256 of file fl_pointer_manager.cc.

262  {
263  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
264 
265  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
266  if (engine == nullptr) {
267  return FALSE;
268  }
269 
270  ensure_pointer_added(self, event_time, device_kind, x, y, rotation, pressure);
271 
273  engine, self->view_id, self->button_state != 0 ? kMove : kHover,
274  event_time * kMicrosecondsPerMillisecond, x, y, device_kind, 0, 0,
275  self->button_state, rotation, pressure);
276 
277  return TRUE;
278 }

References ensure_pointer_added(), fl_engine_send_mouse_pointer_event(), g_autoptr(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by motion_notify_event_cb(), and TEST_F().

◆ fl_pointer_manager_new()

FlPointerManager* fl_pointer_manager_new ( FlutterViewId  view_id,
FlEngine *  engine 
)

fl_pointer_manager_new: @view_id: view ID to report events for. @engine: an #FlEngine.

Create a new #FlPointerManager.

Returns: a new #FlPointerManager.

Definition at line 161 of file fl_pointer_manager.cc.

162  {
163  FlPointerManager* self =
164  FL_POINTER_MANAGER(g_object_new(fl_pointer_manager_get_type(), nullptr));
165 
166  self->view_id = view_id;
167  g_weak_ref_init(&self->engine, engine);
168 
169  return self;
170 }
G_BEGIN_DECLS FlutterViewId view_id

References view_id.

Referenced by setup_engine(), and TEST_F().

◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE ( FlPointerManager  ,
fl_pointer_manager  ,
FL  ,
POINTER_MANAGER  ,
GObject   
)