leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
690 stars 188 forks source link

onWindowBlur creates a bug flickering effect #299

Closed Sushma-Shrestha closed 1 year ago

Sushma-Shrestha commented 1 year ago

It is taking even the click on the application's icon as onWindowBlur, I am facing this issue and cannot solve it. The video link is given below of flickering effect: https://screenrec.com/share/qhKBFVsIwQ I want my application to be able to toggle as well as make it disappear on blur, but the onWindowBlur takes the application icon click as blur, and it makes it look so uncomfortable user experience with this flickering effect it has reproduced.

I found that another issue is also created for this case: https://github.com/leanflutter/window_manager/issues/294

I want to get advice on what can be done. I will really appreciate any response.

damywise commented 1 year ago

I suggest making both onWindowBlur and on icon click call one function, since they do the same thing anyway, right? Now debounce that function. Make that function only be able to execute if the delay between the first and the second call is more than the time required to minimize/hide the window.

That's my immediate thought of a simple workaround

Sushma-Shrestha commented 1 year ago

@damywise How can we make it the same function? As for onWindowBlur, we override the function of window manager, @override void onWindowBlur() async { (Platform.isWindows) ? windowManager.minimize() : await windowManager.hide(); }

And for system tray we will do this, systemTray.registerSystemTrayEventHandler((eventName) async { windowManager.removeListener(this);

  debugPrint("eventName: $eventName");
  if (eventName == kSystemTrayEventClick) {

      if (await windowManager.isMinimized()) {
        await windowManager.restore();
      } else {
        await windowManager.minimize();
      }

  if (eventName == kSystemTrayEventRightClick) {
    await systemTray.popUpContextMenu();
  }
});