window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

Windows' Auto-Hide Taskbar Feature Not Working with Custom Title Bar when Window is Maximized

Open LordLux opened this issue 6 months ago • 1 comments

Describe the bug

When creating a window without the default title bar by setting titleBarStyle: TitleBarStyle.hidden to implement a custom title bar, and then maximizing the window using windowManager.maximize();, the Auto-Hide feature of the Windows Taskbar stops functioning as expected.

To Reproduce

Steps to reproduce the behavior:

  1. Initialize the window manager with WindowOptions, setting titleBarStyle to TitleBarStyle.hidden for a custom title bar implementation.
  2. In the application, use windowManager.maximize(); to maximize the window programmatically.
  3. Once maximized, observe that the Windows Taskbar's Auto-Hide feature does not work; moving the cursor to the bottom of the screen does not reveal the taskbar.

Expected behavior

Even when the Flutter application window is maximized with a custom title bar, the Windows Taskbar's Auto-Hide feature should function normally, revealing the taskbar when the mouse is moved to the bottom edge of the screen, like all other windows apps do.

Additional context

Maybe it could have something to do with this stackoverflow answer

Thanks in advance and thanks for this plugin!

LordLux avatar Feb 15 '24 16:02 LordLux

~I had this exact issue except for the top bar. Basically when the window is maximized, it doesn't leave any gap for the taskbar side. Here's how I fixed it (should've opened a new PR for that) 81b972a (#374) If you got time, maybe open a PR and try to experiment with the bottom border.~

Don't do that, see below

damywise avatar Feb 16 '24 09:02 damywise

The sample code from Microsoft at https://learn.microsoft.com/en-us/windows/apps/develop/title-bar#full-customization-example also exhibits this problem: https://github.com/microsoft/microsoft-ui-xaml/issues/8431.

The workaround mentioned in that bug is using https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist2-markfullscreenwindow#remarks:

Since Windows 7, call SetProp(hwnd, L”NonRudeHWND”, reinterpret_cast<HANDLE>(TRUE)) before showing a window to indicate to the Shell that the window should not be treated as full-screen. This ensures the taskbar does not adjust itself to be below the window in z-order.

roman-yepishev avatar Feb 25 '24 23:02 roman-yepishev

Adding a call of SetProp with NonRudeHWND in windows/window_manager.cpp fixes the taskbar visibility:

diff --git a/windows/window_manager.cpp b/windows/window_manager.cpp
index 3484176..5bd0e28 100644
--- a/windows/window_manager.cpp
+++ b/windows/window_manager.cpp
@@ -256,6 +256,7 @@ bool WindowManager::IsFocused() {

 void WindowManager::Show() {
   HWND hWnd = GetMainWindow();
+  SetProp(hWnd, L"NonRudeHWND", reinterpret_cast<HANDLE>(TRUE));
   DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
   gwlStyle = gwlStyle | WS_VISIBLE;
   if ((gwlStyle & WS_VISIBLE) == 0) {

However, since this is the first time I see the codebase, I am not sure where this call should actually live.

roman-yepishev avatar Feb 25 '24 23:02 roman-yepishev

@roman-yepishev If this is only called once ever, you can put that here https://github.com/leanflutter/window_manager/blob/ef786b1574455ca141cea899ca2db788731163d4/windows/window_manager.cpp#L208-L211 and if you want, also enable/disable it when going to/from fullscreen here https://github.com/leanflutter/window_manager/blob/ef786b1574455ca141cea899ca2db788731163d4/windows/window_manager.cpp#L572-L617

damywise avatar Mar 03 '24 06:03 damywise

A crude version of how this may work is https://github.com/roman-yepishev/window_manager/commit/338588062efaf22031154c09ae53c4ae924b52e3, however it changes the behavior dramatically (hides the window before switching to/from full-screen), which is likely not expected by the clients. Additionally the example app had issues redrawing with this enabled so this does not look like a good solution.

roman-yepishev avatar Mar 06 '24 01:03 roman-yepishev

Is there an update? I'm still experiencing errors.

feimenggo avatar Jun 21 '24 11:06 feimenggo