Show Windows 11 SnapAssist on hover of Max
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
in Win 11 when you hover over the Maximize button you should see
This doesn't fire in VS Code, Teams (electron apps) or Windows Terminal (custom owner draw title bar)
The Electron Core (whomever is responsible for the Maximize button) needs to implement WM_NCHITTEST and reply with HTMAXBUTTON when the hit test is over top of the max button. That will tell Windows it's a Max button which helps Accessibility AND fires SnapAssist.
We could expose a CSS variable to mark minimize/maximize/close buttons, just like --wails-draggable
https://github.com/microsoft/vscode/issues/140932
Describe alternatives you've considered
No response
Additional context
No response
Thanks for opening this. Wails uses native controls so I'm curious about your thinking with CSS variables
@leaanthony I'm not sure how --wails-draggable: drag is implemented, but couldn't we add --wails-window-control: maxbutton and then respond like this in WndProc WM_NCHITTEST?
I don't know anything about Win32 API development, I just found these ^ thru googling and saw that Wails implements a function called "WndProc" in it's win32 internals
This would put Wails one step ahead of Electron, I think, because you can designate any element as a window control.
Electron only supports PWA-style controls:
-
https://www.electronjs.org/docs/latest/tutorial/window-customization#window-controls-overlay-macos-windows
-
https://github.com/WICG/window-controls-overlay/blob/main/explainer.md#examples-of-desktop-apps-customizing-the-title-bar-area
Oh, you're talking about frameless windows? I'll come back to you when all this Christmas stuff is over 🤣
Yes!! Sorry, should've made that more clear :P
@merlindru - Oops this totally slipped off the radar. I'm very keen on adding this to v3.
IIRC this is pretty hard to achieve in the current way the WebView2 is hosted on the Window and goes more or less down the same route as for frameless dragging. The problem is the WM_NCHITTEST never gets fired on the Window because it is directly catched by the WebView2 when using frameless. I think this is only achievable by using composition hosting of the WebView2, which is a greater refactoring.
But it would be awesome to support this, we would take some efforts to test composition hosting and for testing if it is really going to allow us to support this.
It's possible to simulate keyboard input ( Win + z, Alt), instead of WM_NCHITTEST. And Robotgo can do that. tauri-plugin-decorum did that in this way.
Implemented in v3
I implemented a prototype that uses the non-client area. That also added a ton of native-like behavior to the window overall. @leaanthony, would you consider accepting my contribution after I stabilize it and test it in various scenarios?
Absolutely! Looks great. What did you implement?
@leaanthony I should make a dedicated issue or discussion thread. There are basically two methods to do it properly; I tested both, though one is still in development due to issues I have with it.
- So-called Window Controls Overlay. Basically this is the way to draw overlay control buttons for you. They stack it in front of WebView2 itself; no events are passed to the DOM. Works nicely, but there is not a lot of customization: you can change height and background color (foreground color Windows calculates automatically). Another con: it's still an experimental API (
ICoreWebView2Experimental31) and subject to change, though I think it's stable enough to implement without a lot of fear. There are also CSS properties that they expose to the DOM with titlebar position and size. - Hit-testing of mouse clicks in client and non-client areas. Basically you can control what kind of area is below your cursor. Windows detects that and behaves accordingly. For example, you can program your window to report that around the maximize button you have a maximize region kind (
CoreWebView2NonClientRegionKind). Pros: any design you want. Cons: it was hard to implement to behave correctly. Basically it requires you to reimplement rendering and replaceCoreWebView2ControllerwithCoreWebView2CompositionController. After that, you have to forward correctly all mouse events between the DOM and DWM, if I understand it correctly. Also, since Windows supports onlyapp-regionvaluesdrag/no-drag, you cannot ask Windows to do it automatically for you (in that case Windows would automatically return the correct region kind when your cursor is above the element with that CSS property). So you have to calculate, on the Wails JS runtime side, the position of the element on the screen and, usingSystem.invoke, pass it to the Go part of Wails where it can mark the zone.
I think both methods should coexists.

