-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a window process for the tray icon #10980
Conversation
… tray icon, I just need to set it as foreground
WS_DISABLED, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
HWND_MESSAGE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't actually sure what were the necessary options to make this window process as un-interactable as possible, but I believe WS_DISABLED
and maybe HWND_MESSAGE
should be good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, HWND_MESSAGE
is enough to make it totally uninteractable. Though, in the past we've also done:
hwnd = CreateWindowExW(
0, PSEUDO_WINDOW_CLASS, nullptr, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, HWND_DESKTOP, nullptr, nullptr, nullptr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really only care about the wil::unique_hwnd
thing. Rest looks good.
@@ -32,6 +35,7 @@ class TrayIcon | |||
private: | |||
HMENU _CreateTrayContextMenu(winrt::Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> peasants); | |||
|
|||
HWND _trayIconWndProc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming this WndProc
seems weird - makes me thing it's a handle to the actual wndproc function itself. maybe just
HWND _trayIconWndProc; | |
HWND _trayIconHwnd; |
@@ -20,9 +22,41 @@ TrayIcon::TrayIcon(const HWND owningHwnd) : | |||
|
|||
TrayIcon::~TrayIcon() | |||
{ | |||
DestroyWindow(_trayIconWndProc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make this member a wil::unique_hwnd
, it'll clean itself up for you 😉
WS_DISABLED, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
CW_USEDEFAULT, | ||
HWND_MESSAGE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, HWND_MESSAGE
is enough to make it totally uninteractable. Though, in the past we've also done:
hwnd = CreateWindowExW(
0, PSEUDO_WINDOW_CLASS, nullptr, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, HWND_DESKTOP, nullptr, nullptr, nullptr);
{ | ||
WNDCLASSW wc{}; | ||
wc.hCursor = LoadCursor(nullptr, IDC_ARROW); | ||
wc.hInstance = reinterpret_cast<HINSTANCE>(&__ImageBase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, i suspect this got copied from some other Cascadia stuff. Surprised it wasn't using a wil helper!
@@ -23,6 +23,37 @@ TrayIcon::~TrayIcon() | |||
RemoveIconFromTray(); | |||
} | |||
|
|||
void TrayIcon::CreateWindowProcess() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void TrayIcon::CreateWindowProcess() | |
void TrayIcon::CreateWindow() |
This is sufficient -- it's not a process, after all! 😄
|
||
LRESULT CALLBACK TrayIcon::_WindowProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept | ||
{ | ||
return DefWindowProc(window, message, wparam, lparam); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can actually just literally set, lpfnWndProc = DefWindowProcW
above! No need for all this ^^
I don't know if it has been suggested or considered, but if the tray icon gets a window process, it might process WM_MOUSEMOVE by updating NOTIFYICONDATAW::szTip, perhaps with the caption of the current tab. |
Oh whoa that's a really weird interaction, I'm curious where you've encountered this! |
I've done it several times. In a plugin for a console app (TCC interpreter from JPSoft) I do these things (in various places)
I first did this in 2004 and on Windows XP and on a much slower machine. I don't recall if the timing mechanism (commented out) was necessary. It doesn't seem necessary today. Since nid.szTip is only 128 WCHARs, I shorten the Caption if necessary. It winds up "first_part ... last_part". I also process WM_LBUTTONDOWN (restore, tray icon only shows when minimized/hidden) and WM_RBUTTONDOWN (show a menu of things to do). I hope that answers your question. |
I failed to mention that "case WM_MOUSEMOVE" (WM_LBUTTONDOWN and WM_RIGHTBUTTONDOWN too) is inside
|
Ahh, sorry I misunderstood, I was under the impression that you were trying to let me know that there may be a bug to watch out for where |
Right ... just suggesting a feature. |
Hello @zadjii-msft! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Currently, the monarch window will show itself when opening the tray icon context menu. This is because a window must be set as the foreground window when the context menu opens, otherwise the menu won't be able to be dismissed when clicking outside of the context menu.
This PR makes the tray icon create a non visible/interactable window for the sole purpose of being set as the foreground window when the tray icon's context menu is opened. Then none of the terminal windows should be set as the foreground window when opening the context menu.
Closes #10936