Skip to content

Linux: mouse click events other than primary, secondary and tertiary are not recognized #152128

@Feichtmeier

Description

@Feichtmeier

Steps to reproduce

  1. create a Linux Flutter app with
flutter create --platforms=linux --org com.test my_app
  1. Create an implementation of BaseTapGestureRecognizer
class NthTap extends BaseTapGestureRecognizer {
  GestureTapDownCallback? onTapDown;

  NthTap({
    super.debugOwner,
    super.supportedDevices,
    super.allowedButtonsFilter,
  });

  @override
  void handleTapCancel({
    required PointerDownEvent down,
    PointerCancelEvent? cancel,
    required String reason,
  }) {}

  @override
  void handleTapDown({required PointerDownEvent down}) {
    final TapDownDetails details = TapDownDetails(
      globalPosition: down.position,
      localPosition: down.localPosition,
      kind: getKindForPointer(down.pointer),
    );

    if (onTapDown != null) {
      invokeCallback<void>('onTapDown', () => onTapDown!(details));
    }
  }

  @override
  void handleTapUp({
    required PointerDownEvent down,
    required PointerUpEvent up,
  }) {}
}
  1. Use it inside the widget tree
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: <Type, GestureRecognizerFactory>{
        NthTap: GestureRecognizerFactoryWithHandlers<NthTap>(
          () => NthTap(),
          (instance) =>
              instance.onTapDown = (details) => ScaffoldMessenger.of(context)
                ..clearSnackBars()
                ..showSnackBar(SnackBar(
                  content: Center(
                    child: Text(
                      details.globalPosition.toString(),
                    ),
                  ),
                  behavior: SnackBarBehavior.floating,
                )),
        ),
      },
      child: const Scaffold(),
    );
  }
}

Expected results

All mouse buttons should be recognized

Actual results

Only 1.,2. and 3. buttons are recognized. 4th and 5th arent

Code sample

Code sample
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: <Type, GestureRecognizerFactory>{
        NthTap: GestureRecognizerFactoryWithHandlers<NthTap>(
          () => NthTap(),
          (instance) =>
              instance.onTapDown = (details) => ScaffoldMessenger.of(context)
                ..clearSnackBars()
                ..showSnackBar(SnackBar(
                  content: Center(
                    child: Text(
                      details.globalPosition.toString(),
                    ),
                  ),
                  behavior: SnackBarBehavior.floating,
                )),
        ),
      },
      child: const Scaffold(),
    );
  }
}

class NthTap extends BaseTapGestureRecognizer {
  GestureTapDownCallback? onTapDown;

  NthTap({
    super.debugOwner,
    super.supportedDevices,
    super.allowedButtonsFilter,
  });

  @override
  void handleTapCancel({
    required PointerDownEvent down,
    PointerCancelEvent? cancel,
    required String reason,
  }) {}

  @override
  void handleTapDown({required PointerDownEvent down}) {
    final TapDownDetails details = TapDownDetails(
      globalPosition: down.position,
      localPosition: down.localPosition,
      kind: getKindForPointer(down.pointer),
    );

    if (onTapDown != null) {
      invokeCallback<void>('onTapDown', () => onTapDown!(details));
    }
  }

  @override
  void handleTapUp({
    required PointerDownEvent down,
    required PointerUpEvent up,
  }) {}
}

Screenshots or Video

Screenshots / Video demonstration
Bildschirmaufzeichnung.vom.2024-07-22.20-18-47.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
frederik@xps:~/my_app$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on Ubuntu 24.04 LTS 6.8.0-31-generic, locale de_DE.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
    ✗ No Java Development Kit (JDK) found; You must have the environment variable JAVA_HOME set and the java binary in your PATH. You can download the JDK from
      https://www.oracle.com/technetwork/java/javase/downloads/.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.91.1)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.

this also happens in 3.22.2 stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: mouseIssues related to using a mouse or mouse supportengineflutter/engine related. See also e: labels.found in release: 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions