leanflutter / window_manager

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

cannot disable initial fullscreen on Windows #421

Closed Markus43 closed 5 months ago

Markus43 commented 7 months ago

My use case:

When disabling fullscreen mode, the window looses focus and I cannot click on the window anymore.

To reproduce this with the example project:

As a result, the app gets resized, its elements are not resized and the app looses focus. The app remains visible. The app cannot be clicked anymore: When I try to click on the app, the click goes to the window behind my app or to the desktop. So the app is not usable anymore, and it is not possible to bring it back to life or to even quit it.

As a temporary alternative for Windows, I switched to https://pub.dev/packages/fullscreen_window which works for this particular usecase, just as a reference that might help for a bugfix.

damywise commented 7 months ago

Heya, I can reproduce this. Thanks for the detailed info! I'll look into it.

damywise commented 7 months ago

Alright found the fix. Maybe will open a PR soon.

damywise commented 7 months ago

Sorry, nevermind that, I was mistaken.

For a workaround, you can call show() after the first setFullScreen(false). I haven't tested it yet but I think it should work. Tell me if it doesn't. I'll explain later.

damywise commented 7 months ago

Okay so basically, here's a breakdown.

setFullScreen(true) works like this:

  1. Save the current window style.
  2. Some magic to modify the window style to remove the title bar and frame.
  3. Some other magic to set the window size

setFullScreen(false) works like this:

  1. Load the previously saved window style.
  2. Some magic to set the window size.

What's the problem here? You see, when the app is first launched, a certain window style is omitted (WS_VISIBLE). As its name, if this style is not included, then the app is not shown. Therefore, achieving hide app at launch.

Now, let's go back to the fullscreen implementation. Since fullscreen: true is set before the show(), the window style that is saved doesn't include WS_VISIBLE. (I verified this using Spy++) As a side effect, when we set the fullscreen back to false, the window is gone.

What would fix this? In the native side, I don't know. I'm not proficient in C++. I just try things and see if it works. And I haven't found things that work yet. In the dart side, calling show() after setFullScreen(false) works. I have tested it.

If anyone has an idea, feel free to chime in.

Markus43 commented 7 months ago

Many thanks for the quick response! I can confirm that the workaround (call show after setFullScreen(false)) works.

explorer-source commented 7 months ago

for workaround instead of specifying fullscreen: true in WindowOptions call await windowManager.setFullScreen(true); in waitUntilReadyToShow after await windowManager.show();

  WindowOptions windowOptions = WindowOptions(
    center: true,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.hidden,
    // fullScreen: true,
  );

  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
    await windowManager.setFullScreen(true);
  });
Markus43 commented 4 months ago

@lijy91 I still can reproduce my original issue, so this bug is not solved yet.