From ad1f641f496c21a02c8d173167d77f1b31849273 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 2 Aug 2022 02:05:01 +0200 Subject: [PATCH] fix(windows): fix tray event window showing up on click, closes #506 (#507) * fix(windows): fix tray event window showing up on click, closes #506 * changefile * change file * changefile content --- .changes/tray-ghost-window.md | 5 +++++ src/platform_impl/windows/system_tray.rs | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changes/tray-ghost-window.md diff --git a/.changes/tray-ghost-window.md b/.changes/tray-ghost-window.md new file mode 100644 index 000000000..e39d3a8af --- /dev/null +++ b/.changes/tray-ghost-window.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Windows, fix a ghost window appearing occasionally when clicking the tray icon. diff --git a/src/platform_impl/windows/system_tray.rs b/src/platform_impl/windows/system_tray.rs index a68a8bd23..64e4b8d4c 100644 --- a/src/platform_impl/windows/system_tray.rs +++ b/src/platform_impl/windows/system_tray.rs @@ -72,10 +72,18 @@ impl SystemTrayBuilder { RegisterClassW(&wnd_class); let hwnd = CreateWindowExW( - Default::default(), + WS_EX_NOACTIVATE | WS_EX_TRANSPARENT | WS_EX_LAYERED | + // WS_EX_TOOLWINDOW prevents this window from ever showing up in the taskbar, which + // we want to avoid. If you remove this style, this window won't show up in the + // taskbar *initially*, but it can show up at some later point. This can sometimes + // happen on its own after several hours have passed, although this has proven + // difficult to reproduce. Alternatively, it can be manually triggered by killing + // `explorer.exe` and then starting the process back up. + // It is unclear why the bug is triggered by waiting for several hours. + WS_EX_TOOLWINDOW, PCWSTR(class_name.as_ptr()), - "tao_system_tray_window", - WS_OVERLAPPEDWINDOW, + PCWSTR::default(), + WS_OVERLAPPED, CW_USEDEFAULT, 0, CW_USEDEFAULT,