Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows platforms do not support a maximize call in onDoubleTapDown #511

Open
luoluoqixi opened this issue Nov 18, 2024 · 2 comments
Open

Comments

@luoluoqixi
Copy link

luoluoqixi commented Nov 18, 2024

windowManager.maximize() doesn't work when I change onDoubleTap to onDoubleTapDown (only windows)

@override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onPanStart: (details) {
        windowManager.startDragging();
      },
      onDoubleTapDown: (details) async {
        bool isMaximized = await windowManager.isMaximized();
        if (!isMaximized) {
          await windowManager.maximize();
        } else {
          await windowManager.unmaximize();
        }
      },
      child: child,
    );
  }

A simple fix looks like this:

onDoubleTapDown: (details) async {
  final isFix = Platform.isWindows;
  bool alwaysTop = false;
  if (isFix) {
    alwaysTop = await windowManager.isAlwaysOnTop();
    await windowManager.setAlwaysOnTop(true);
    await windowManager.blur();
  }
  bool isMaximized = await windowManager.isMaximized();
  if (!isMaximized) {
    await windowManager.maximize();
  } else {
    await windowManager.unmaximize();
  }
  if (isFix) {
    await windowManager.focus();
    await windowManager.setAlwaysOnTop(alwaysTop);
  }
},
@luoluoqixi luoluoqixi changed the title use onDoubleTapDown not work Windows platforms do not support a maximize call in onDoubleTapDown Nov 18, 2024
@luoluoqixi
Copy link
Author

I found a way to solve it, just send WM_LBUTTONUP before performing maximize

// dart
onDoubleTapDown: (details) async {
    if (Platform.isWindows) {
      // windows平台鼠标按下时maximize不生效, 强行释放一下鼠标
      await windowsInterface.releaseMouse();
    }
    bool isMaximized = await windowManager.isMaximized();
    if (!isMaximized) {
      await windowManager.maximize();
    } else {
      await windowManager.unmaximize();
    }
    _isDoubleTapped = true;
}
// c++
void WindowsInterface::ReleaseMouse() {
  HWND hwnd = GetMainWindow();
  ReleaseCapture();
  SendMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(0, 0));
}

@luoluoqixi
Copy link
Author

Can you replace the default onDoubleTap with this onDoubleTapDown implementation? Because if you look at the other applications in Windows, they are all maximized at the moment of onDoubleTapDown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant