Flutter Linux Embedder
fl_pointer_manager.cc File Reference

Go to the source code of this file.

Classes

struct  _FlPointerManager
 

Functions

 G_DEFINE_TYPE (FlPointerManager, fl_pointer_manager, G_TYPE_OBJECT)
 
static void ensure_pointer_added (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
 
static void fl_pointer_manager_dispose (GObject *object)
 
static void fl_pointer_manager_class_init (FlPointerManagerClass *klass)
 
static void fl_pointer_manager_init (FlPointerManager *self)
 
FlPointerManager * fl_pointer_manager_new (FlutterViewId view_id, FlEngine *engine)
 
gboolean fl_pointer_manager_handle_button_press (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, int64_t button)
 
gboolean fl_pointer_manager_handle_button_release (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, int64_t button)
 
gboolean fl_pointer_manager_handle_motion (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
 
gboolean fl_pointer_manager_handle_enter (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
 
gboolean fl_pointer_manager_handle_leave (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
 

Variables

static constexpr int kMicrosecondsPerMillisecond = 1000
 

Function Documentation

◆ ensure_pointer_added()

static void ensure_pointer_added ( FlPointerManager *  self,
guint  event_time,
FlutterPointerDeviceKind  device_kind,
gdouble  x,
gdouble  y 
)
static

Definition at line 31 of file fl_pointer_manager.cc.

35  {
36  if (self->pointer_inside) {
37  return;
38  }
39  self->pointer_inside = TRUE;
40 
41  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
42  if (engine == nullptr) {
43  return;
44  }
45 
47  engine, self->view_id, kAdd, event_time * kMicrosecondsPerMillisecond, x,
48  y, device_kind, 0, 0, self->button_state);
49 }

References fl_engine_send_mouse_pointer_event(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by fl_pointer_manager_handle_button_press(), fl_pointer_manager_handle_enter(), and fl_pointer_manager_handle_motion().

◆ fl_pointer_manager_class_init()

static void fl_pointer_manager_class_init ( FlPointerManagerClass *  klass)
static

Definition at line 59 of file fl_pointer_manager.cc.

59  {
60  G_OBJECT_CLASS(klass)->dispose = fl_pointer_manager_dispose;
61 }

References fl_pointer_manager_dispose().

◆ fl_pointer_manager_dispose()

static void fl_pointer_manager_dispose ( GObject *  object)
static

Definition at line 51 of file fl_pointer_manager.cc.

51  {
52  FlPointerManager* self = FL_POINTER_MANAGER(object);
53 
54  g_weak_ref_clear(&self->engine);
55 
56  G_OBJECT_CLASS(fl_pointer_manager_parent_class)->dispose(object);
57 }

Referenced by fl_pointer_manager_class_init().

◆ 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,
int64_t  button 
)

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. @button: button being pressed.

Returns TRUE if this event was handled.

Definition at line 76 of file fl_pointer_manager.cc.

82  {
83  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
84 
85  ensure_pointer_added(self, event_time, device_kind, x, y);
86 
87  // Drop the event if Flutter already thinks the button is down.
88  if ((self->button_state & button) != 0) {
89  return FALSE;
90  }
91 
92  int old_button_state = self->button_state;
93  FlutterPointerPhase phase = kMove;
94  self->button_state ^= button;
95  phase = old_button_state == 0 ? kDown : kMove;
96 
97  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
98  if (engine == nullptr) {
99  return FALSE;
100  }
101 
103  engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
104  y, device_kind, 0, 0, self->button_state);
105 
106  return TRUE;
107 }

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

Referenced by button_press_event_cb(), and TEST().

◆ 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,
int64_t  button 
)

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. @button: button being released.

Returns TRUE if this event was handled.

Definition at line 109 of file fl_pointer_manager.cc.

115  {
116  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
117 
118  // Drop the event if Flutter already thinks the button is up.
119  if ((self->button_state & button) == 0) {
120  return FALSE;
121  }
122 
123  FlutterPointerPhase phase = kMove;
124  self->button_state ^= button;
125 
126  phase = self->button_state == 0 ? kUp : kMove;
127 
128  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
129  if (engine == nullptr) {
130  return FALSE;
131  }
132 
134  engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
135  y, device_kind, 0, 0, self->button_state);
136 
137  return TRUE;
138 }

References fl_engine_send_mouse_pointer_event(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by button_release_event_cb(), and TEST().

◆ fl_pointer_manager_handle_enter()

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

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.

Returns TRUE if this event was handled.

Definition at line 162 of file fl_pointer_manager.cc.

166  {
167  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
168 
169  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
170  if (engine == nullptr) {
171  return FALSE;
172  }
173 
174  ensure_pointer_added(self, event_time, device_kind, x, y);
175 
176  return TRUE;
177 }

References ensure_pointer_added(), and TRUE.

Referenced by enter_notify_event_cb(), and TEST().

◆ fl_pointer_manager_handle_leave()

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

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.

Returns TRUE if this event was handled.

Definition at line 179 of file fl_pointer_manager.cc.

183  {
184  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
185 
186  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
187  if (engine == nullptr) {
188  return FALSE;
189  }
190 
191  // Don't remove pointer while button is down; In case of dragging outside of
192  // window with mouse grab active Gtk will send another leave notify on
193  // release.
194  if (self->pointer_inside && self->button_state == 0) {
195  fl_engine_send_mouse_pointer_event(engine, self->view_id, kRemove,
196  event_time * kMicrosecondsPerMillisecond,
197  x, y, device_kind, 0, 0,
198  self->button_state);
199  self->pointer_inside = FALSE;
200  }
201 
202  return TRUE;
203 }

References fl_engine_send_mouse_pointer_event(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by leave_notify_event_cb(), and TEST().

◆ fl_pointer_manager_handle_motion()

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

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.

Returns TRUE if this event was handled.

Definition at line 140 of file fl_pointer_manager.cc.

144  {
145  g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
146 
147  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
148  if (engine == nullptr) {
149  return FALSE;
150  }
151 
152  ensure_pointer_added(self, event_time, device_kind, x, y);
153 
155  engine, self->view_id, self->button_state != 0 ? kMove : kHover,
156  event_time * kMicrosecondsPerMillisecond, x, y, device_kind, 0, 0,
157  self->button_state);
158 
159  return TRUE;
160 }

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

Referenced by motion_notify_event_cb(), and TEST().

◆ fl_pointer_manager_init()

static void fl_pointer_manager_init ( FlPointerManager *  self)
static

Definition at line 63 of file fl_pointer_manager.cc.

63 {}

◆ 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 65 of file fl_pointer_manager.cc.

66  {
67  FlPointerManager* self =
68  FL_POINTER_MANAGER(g_object_new(fl_pointer_manager_get_type(), nullptr));
69 
70  self->view_id = view_id;
71  g_weak_ref_init(&self->engine, engine);
72 
73  return self;
74 }

Referenced by fl_view_new(), fl_view_new_for_engine(), and TEST().

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlPointerManager  ,
fl_pointer_manager  ,
G_TYPE_OBJECT   
)

Variable Documentation

◆ kMicrosecondsPerMillisecond

ensure_pointer_added
static void ensure_pointer_added(FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y)
Definition: fl_pointer_manager.cc:31
fl_pointer_manager_dispose
static void fl_pointer_manager_dispose(GObject *object)
Definition: fl_pointer_manager.cc:51
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_pointer_manager.cc:9
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_engine_send_mouse_pointer_event
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)
Definition: fl_engine.cc:918