| Flutter Linux Embedder |

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

Go to the source code of this file.

## Classes
struct | _FlPointerManager

## Functions
| G_DEFINE_TYPE (FlPointerManager, fl_pointer_manager, G_TYPE_OBJECT)
static gboolean | get_mouse_button (guint gdk_button, int64_t *button)
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, guint gdk_button)
gboolean | fl_pointer_manager_handle_button_release (FlPointerManager *self, guint event_time, FlutterPointerDeviceKind device_kind, gdouble x, gdouble y, guint gdk_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
static constexpr guint | kMouseButtonBack = 8
static constexpr guint | kMouseButtonForward = 9

## 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 60 of file fl_pointer_manager.cc.

64 {
65 if (self->pointer_inside) {
66 return;
67 }
68 self->pointer_inside = TRUE;
69
70 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
71 if (engine == nullptr) {
72 return;
73 }
74
75 fl_engine_send_mouse_pointer_event(
76 engine, self->view_id, kAdd, event_time * kMicrosecondsPerMillisecond, x,
77 y, device_kind, 0, 0, self->button_state);
78 }
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
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:1132
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_pointer_manager.cc:9

References fl_engine_send_mouse_pointer_event(), g_autoptr(), 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 88 of file fl_pointer_manager.cc.

88 {
89 G_OBJECT_CLASS(klass)->dispose = fl_pointer_manager_dispose;
90 }
fl_pointer_manager_dispose
static void fl_pointer_manager_dispose(GObject *object)
Definition: fl_pointer_manager.cc:80

References fl_pointer_manager_dispose().

## ◆ fl_pointer_manager_dispose()

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

Definition at line 80 of file fl_pointer_manager.cc.

80 {
81 FlPointerManager* self = FL_POINTER_MANAGER(object);
82
83 g_weak_ref_clear(&self->engine);
84
85 G_OBJECT_CLASS(fl_pointer_manager_parent_class)->dispose(object);
86 }

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,
|  | guint | gdk_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. @gdk_button: button being pressed.

Returns TRUE if this event was handled.

Definition at line 105 of file fl_pointer_manager.cc.

111 {
112 g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
113
114 int64_t button;
115 if (!get_mouse_button(gdk_button, &button)) {
116 return FALSE;
117 }
118
119 ensure_pointer_added(self, event_time, device_kind, x, y);
120
121 // Drop the event if Flutter already thinks the button is down.
122 if ((self->button_state & button) != 0) {
123 return FALSE;
124 }
125
126 int old_button_state = self->button_state;
127 FlutterPointerPhase phase = kMove;
128 self->button_state ^= button;
129 phase = old_button_state == 0 ? kDown : kMove;
130
131 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
132 if (engine == nullptr) {
133 return FALSE;
134 }
135
136 fl_engine_send_mouse_pointer_event(
137 engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
138 y, device_kind, 0, 0, self->button_state);
139
140 return TRUE;
141 }
get_mouse_button
static gboolean get_mouse_button(guint gdk_button, int64_t *button)
Definition: fl_pointer_manager.cc:37
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:60

References ensure_pointer_added(), fl_engine_send_mouse_pointer_event(), g_autoptr(), get_mouse_button(), 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,
|  | guint | gdk_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. @gdk_button: button being released.

Returns TRUE if this event was handled.

Definition at line 143 of file fl_pointer_manager.cc.

149 {
150 g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
151
152 int64_t button;
153 if (!get_mouse_button(gdk_button, &button)) {
154 return FALSE;
155 }
156
157 // Drop the event if Flutter already thinks the button is up.
158 if ((self->button_state & button) == 0) {
159 return FALSE;
160 }
161
162 FlutterPointerPhase phase = kMove;
163 self->button_state ^= button;
164
165 phase = self->button_state == 0 ? kUp : kMove;
166
167 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
168 if (engine == nullptr) {
169 return FALSE;
170 }
171
172 fl_engine_send_mouse_pointer_event(
173 engine, self->view_id, phase, event_time * kMicrosecondsPerMillisecond, x,
174 y, device_kind, 0, 0, self->button_state);
175
176 return TRUE;
177 }

References fl_engine_send_mouse_pointer_event(), g_autoptr(), get_mouse_button(), 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 201 of file fl_pointer_manager.cc.

205 {
206 g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
207
208 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
209 if (engine == nullptr) {
210 return FALSE;
211 }
212
213 ensure_pointer_added(self, event_time, device_kind, x, y);
214
215 return TRUE;
216 }

References ensure_pointer_added(), g_autoptr(), 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 218 of file fl_pointer_manager.cc.

222 {
223 g_return_val_if_fail(FL_IS_POINTER_MANAGER(self), FALSE);
224
225 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
226 if (engine == nullptr) {
227 return FALSE;
228 }
229
230 // Don't remove pointer while button is down; In case of dragging outside of
231 // window with mouse grab active Gtk will send another leave notify on
232 // release.
233 if (self->pointer_inside && self->button_state == 0) {
234 fl_engine_send_mouse_pointer_event(engine, self->view_id, kRemove,
235 event_time * kMicrosecondsPerMillisecond,
236 x, y, device_kind, 0, 0,
237 self->button_state);
238 self->pointer_inside = FALSE;
239 }
240
241 return TRUE;
242 }

References fl_engine_send_mouse_pointer_event(), g_autoptr(), 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 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 ensure_pointer_added(self, event_time, device_kind, x, y);
192
193 fl_engine_send_mouse_pointer_event(
194 engine, self->view_id, self->button_state != 0 ? kMove : kHover,
195 event_time * kMicrosecondsPerMillisecond, x, y, device_kind, 0, 0,
196 self->button_state);
197
198 return TRUE;
199 }

References ensure_pointer_added(), fl_engine_send_mouse_pointer_event(), g_autoptr(), 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 92 of file fl_pointer_manager.cc.

92 {}

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

95 {
96 FlPointerManager* self =
97 FL_POINTER_MANAGER(g_object_new(fl_pointer_manager_get_type(), nullptr));
98
99 self->view_id = view_id;
100 g_weak_ref_init(&self->engine, engine);
101
102 return self;
103 }
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49

References view_id.

Referenced by setup_engine(), and TEST().

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlPointerManager | ,
|  | fl_pointer_manager | ,
|  | G_TYPE_OBJECT |
| ) |  |

## ◆ get_mouse_button()

static gboolean get_mouse_button | ( | guint | gdk_button,
|  | int64_t * | button
| ) |  |
| static

Definition at line 37 of file fl_pointer_manager.cc.

37 {
38 switch (gdk_button) {
39 case GDK_BUTTON_PRIMARY:
40 *button = kFlutterPointerButtonMousePrimary;
41 return TRUE;
42 case GDK_BUTTON_MIDDLE:
43 *button = kFlutterPointerButtonMouseMiddle;
44 return TRUE;
45 case GDK_BUTTON_SECONDARY:
46 *button = kFlutterPointerButtonMouseSecondary;
47 return TRUE;
48 case kMouseButtonBack:
49 *button = kFlutterPointerButtonMouseBack;
50 return TRUE;
51 case kMouseButtonForward:
52 *button = kFlutterPointerButtonMouseForward;
53 return TRUE;
54 default:
55 return FALSE;
56 }
57 }
kMouseButtonForward
static constexpr guint kMouseButtonForward
Definition: fl_pointer_manager.cc:34
kMouseButtonBack
static constexpr guint kMouseButtonBack
Definition: fl_pointer_manager.cc:31

References kMouseButtonBack, kMouseButtonForward, and TRUE.

Referenced by fl_pointer_manager_handle_button_press(), and fl_pointer_manager_handle_button_release().

## Variable Documentation

## ◆ kMicrosecondsPerMillisecond

constexpr int kMicrosecondsPerMillisecond = 1000
| staticconstexpr

Definition at line 9 of file fl_pointer_manager.cc.

Referenced by ensure_pointer_added(), fl_pointer_manager_handle_button_press(), fl_pointer_manager_handle_button_release(), fl_pointer_manager_handle_leave(), and fl_pointer_manager_handle_motion().

## ◆ kMouseButtonBack

constexpr guint kMouseButtonBack = 8
| staticconstexpr

Definition at line 31 of file fl_pointer_manager.cc.

Referenced by get_mouse_button().

## ◆ kMouseButtonForward

constexpr guint kMouseButtonForward = 9
| staticconstexpr

Definition at line 34 of file fl_pointer_manager.cc.

Referenced by get_mouse_button().