Skip to content

[Windows] Multi-window: buttons stop working when dragging a click from a window to another one #189583

Closed

Description

@kevindespoulains-bc

Steps to reproduce

This issue seems to have been introduced by this commit : #187629
I tried on the previous commit and everything was working fine.

  1. Use the master Flutter channel on Windows
  2. Run the flutter config --enable-windowing command to enable windowing
  3. Launch the app from the code sample below (flutter run -d windows)
  4. Like in the following video, open 2 other windows using the main screen button
  5. Press down the left mouse button on the first child window
  6. While keeping the mouse button down, switch the focused window using Alt+tab
  7. Hover or release the left mouse button on one of the buttons of the new focused window
  8. The button where the click is released doesn't work anymore

Expected results

When moving from a window to another one while keeping the left mouse button pressed, the press should be dismissed when leaving the window and ignored by the new window.

Actual results

When releasing the mouse button that was pressed on one window above a button of another window, the button do not receive the press events anymore and appear pressed (like in the video).

Code sample

The code used in the video :

Code sample
// ignore_for_file: implementation_imports, invalid_use_of_internal_member

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/_window.dart' as fw;

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runWidget(const MultiWindowApp());
}

class MultiWindowApp extends StatefulWidget {
  const MultiWindowApp({super.key});

  @override
  State<MultiWindowApp> createState() => _MultiWindowAppState();
}

class _MultiWindowAppState extends State<MultiWindowApp> {
  final fw.RegularWindowController _controller = fw.RegularWindowController(
    size: const Size(800, 600),
    title: 'Main window',
    delegate: _MainWindowDelegate(),
  );

  @override
  Widget build(BuildContext context) {
    return fw.RegularWindow(
      controller: _controller,
      child: const MaterialApp(home: MainWindow()),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final registry = fw.WindowRegistry.of(context);

    return Scaffold(
      body: Center(
        child: FilledButton(
          onPressed: () => openChildWindow(registry),
          child: const Text('Open child window'),
        ),
      ),
    );
  }
}

void openChildWindow(fw.WindowRegistry registry) {
  late final fw.WindowEntry entry;
  final controller = fw.RegularWindowController(
    size: const Size(520, 360),
    title: 'Child window',
    delegate: _ChildWindowDelegate(
      onDestroyed: () => registry.unregister(entry),
    ),
  );

  entry = fw.WindowEntry(
    controller: controller,
    builder: (_) => const MaterialApp(home: ChildWindow()),
  );

  registry.register(entry);
}

class ChildWindow extends StatefulWidget {
  const ChildWindow({super.key});

  @override
  State<ChildWindow> createState() => _ChildWindowState();
}

class _ChildWindowState extends State<ChildWindow> {
  static const colors = [
    Color(0xFFE8F0FF),
    Color(0xFFFFE8E8),
  ];

  Color color = colors[0];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: color,
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          spacing: 4,
          children: [
            ElevatedButton(
              onPressed: () {
                setState(() {
                  color = colors.firstWhere((c) => c != color);
                });
              },
              child: const Text('Change color'),
            ),
            ElevatedButton(
              onPressed: () {
                setState(() {
                  color = colors.firstWhere((c) => c != color);
                });
              },
              child: const Text('Change color'),
            ),
          ],
        ),
      ),
    );
  }
}

class _MainWindowDelegate with fw.RegularWindowControllerDelegate {
  @override
  void onWindowDestroyed() {
    exit(0);
  }
}

class _ChildWindowDelegate with fw.RegularWindowControllerDelegate {
  const _ChildWindowDelegate({required this.onDestroyed});

  final VoidCallback onDestroyed;

  @override
  void onWindowDestroyed() {
    onDestroyed();
  }
}

Screenshots or Video

Screenshots / Video demonstration
2026-07-16.14-14-44.mp4

Logs

Logs
Running the app with the `--verbose` flag does not show specific logs when the bug occurs.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.47.0-1.0.pre-98, on Microsoft Windows [version 10.0.19045.6937], locale fr-FR)
[√] Windows Version (10 Famille 64 bits, 22H2, 2009)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: [https://developer.android.com/studio/index.html](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdeveloper.android.com%2Fstudio%2Findex.html&data=05%7C02%7Ck.despoulains%40betclicgroup.com%7C92e899b336f5496a86a708dee33cbe7c%7C349cb0f5cf5b4f4c89f1e13af5555b16%7C0%7C0%7C639198047214544654%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=nkI%2FTW4EIgyp2PwtOfjsy0QPCd%2Bq1jHK%2B7oaCqU3AUg%3D&reserved=0)
      On first launch it will assist you in installing the Android SDK components.
      (or visit [https://flutter.dev/to/windows-android-setup](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fflutter.dev%2Fto%2Fwindows-android-setup&data=05%7C02%7Ck.despoulains%40betclicgroup.com%7C92e899b336f5496a86a708dee33cbe7c%7C349cb0f5cf5b4f4c89f1e13af5555b16%7C0%7C0%7C639198047214584947%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Pd0TYc0zdlxFgRnHHFrrP%2BH1CF2ByQU15gIeybSn2VM%3D&reserved=0) for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.8.0)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.

Activity

  1. added
    in triagePresently being triaged by the triage team
    platform-windowsBuilding on or for Windows specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-windowsOwned by the Windows platform team
    and removed
    in triagePresently being triaged by the triage team
    on Jul 17, 2026
  2. suryaKommana2662 commented on Jul 17, 2026

    @suryaKommana2662

    @kevindespoulains-bc Thanks for the report. I was able to reproduce this issue on Windows using the latest Flutter master.

    Following the provided reproduction steps, I observed the same behavior:

    • Opened multiple child windows.
    • Pressed and held the left mouse button on a button in one child window.
    • Switched to another window using Alt + Tab while keeping the mouse button pressed.
    • Released the mouse button over a button in the second window.

    After doing so, the button in the second window remained in a pressed state and no longer responded to subsequent clicks, matching the behavior described in the report. Routing this to team-windows for further investigation.

    I've attached a screen recording demonstrating the issue.
    https://github.com/user-attachments/assets/f0c560f9-8369-4264-bb20-c596ed9e984a

    Flutter Doctor Output

    [√] Flutter (Channel master, 3.47.0-1.0.pre-109, on Microsoft Windows [Version 10.0.26200.8875], locale en-IN) [3.3s]
        • Flutter version 3.47.0-1.0.pre-109 on channel master at C:\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 8ad25edd84 (4 hours ago), 2026-07-16 21:17:07 -0400
        • Engine revision 8ad25edd84
        • Dart version 3.14.0 (build 3.14.0-36.0.dev)
        • DevTools version 2.60.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
          cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-windowing,
          enable-lldb-debugging, enable-uiscene-migration, enable-riscv64
    
    [√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,089ms]
    
    [√] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [3.5s]
        • Android SDK at C:\Android\Sdk
        • Emulator version 36.5.11.0 (build_id 15261927) (CL:N/A)
        • Platform android-36.1, build-tools 36.1.0
        • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.10+-14961533-b1163.108)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web [144ms]
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.6.1) [142ms]
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
        • Visual Studio Community 2026 version 18.6.11819.183
        • Windows 10 SDK version 10.0.26100.0
    
    [√] Connected device (3 available) [373ms]
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.8875]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 150.0.7871.115
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 150.0.4078.65
    
    [√] Network resources [704ms]
        • All expected network resources are available.
    
    • No issues found!
  3. self-assigned this
    on Jul 20, 2026
  4. knopp commented on Jul 20, 2026

    @knopp
    Member
  5. knopp commented on Jul 25, 2026

    @knopp
    Member

    Thanks for the bisect, it really helped!
    I looked into this - the culprit is this part of #187629:

    void FlutterWindowsView::OnPointerMove(double x,
                                           double y,
                                           FlutterPointerDeviceKind device_kind,
                                           int32_t device_id,
                                           uint64_t buttons,
                                           uint32_t rotation,
                                           uint32_t pressure,
                                           int modifiers_state) {
      engine_->keyboard_key_handler()->SyncModifiersIfNeeded(modifiers_state);
      auto state = GetOrCreatePointerState(device_kind, device_id);
    // >>>>>>>>>>>>>>>>>>>>>>>
      state->buttons = buttons; 
    // <<<<<<<<<<<<<<<<<<<<<<
      state->rotation = rotation;
      state->pressure = pressure;
      SendPointerMove(x, y, state);
    }

    With this the WM_MOUSEMOVE sets the mouse button state from the event itself. Before this didn't happen, the mouse buttons state was set through mouse down and up events.

    This normally doesn't make difference because we get mouse down, capture mouse and send mouse move - the buttons in mouse move event match the state set by mouse down. However when switching to new window mid drag, windows will no longer honor the mouse capture and will start sending the WM_MOUSEMOVE event to new window, with the button flag sets. But this window never saw the mouse down event - this confuses the pointer tracking in Flutter. In debug build this actually crashes with assertion.

    I looked at most other applications, and I think generally the best way to handle this is to simply ignore WM_MOUSEMOVE that has buttons set when GetCapture() doesn't return current HWND. This seems to match behavior of other windows applications.

  6. github-actions commented on Aug 12, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: desktopRunning on desktopa: multi windowIssues related to multi window supporthas reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-windowsBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions