window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

Windows platforms do not support a maximize call in onDoubleTapDown

Open luoluoqixi opened this issue 1 year ago • 2 comments

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 avatar Nov 18 '24 07:11 luoluoqixi

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 avatar Nov 23 '24 15:11 luoluoqixi

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

luoluoqixi avatar Nov 23 '24 15:11 luoluoqixi