@@ -27,6 +27,35 @@ struct _FlPointerManager {
2727
2828G_DEFINE_TYPE (FlPointerManager, fl_pointer_manager, G_TYPE_OBJECT);
2929
30+ // 8 corresponds to mouse back button on both x11 and wayland
31+ static constexpr guint kMouseButtonBack = 8 ;
32+
33+ // 9 corresponds to mouse forward button on both x11 and wayland
34+ static constexpr guint kMouseButtonForward = 9 ;
35+
36+ // Convert a GDK button ID into a Flutter button ID
37+ static gboolean get_mouse_button (guint gdk_button, int64_t * button) {
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+ }
58+
3059// Generates a mouse pointer event if the pointer appears inside the window.
3160static void ensure_pointer_added (FlPointerManager* self,
3261 guint event_time,
@@ -79,9 +108,14 @@ gboolean fl_pointer_manager_handle_button_press(
79108 FlutterPointerDeviceKind device_kind,
80109 gdouble x,
81110 gdouble y,
82- int64_t button ) {
111+ guint gdk_button ) {
83112 g_return_val_if_fail (FL_IS_POINTER_MANAGER (self), FALSE );
84113
114+ int64_t button;
115+ if (!get_mouse_button (gdk_button, &button)) {
116+ return FALSE ;
117+ }
118+
85119 ensure_pointer_added (self, event_time, device_kind, x, y);
86120
87121 // Drop the event if Flutter already thinks the button is down.
@@ -112,9 +146,14 @@ gboolean fl_pointer_manager_handle_button_release(
112146 FlutterPointerDeviceKind device_kind,
113147 gdouble x,
114148 gdouble y,
115- int64_t button ) {
149+ guint gdk_button ) {
116150 g_return_val_if_fail (FL_IS_POINTER_MANAGER (self), FALSE );
117151
152+ int64_t button;
153+ if (!get_mouse_button (gdk_button, &button)) {
154+ return FALSE ;
155+ }
156+
118157 // Drop the event if Flutter already thinks the button is up.
119158 if ((self->button_state & button) == 0 ) {
120159 return FALSE ;
0 commit comments