wails icon indicating copy to clipboard operation
wails copied to clipboard

Show Windows 11 SnapAssist on hover of Max

Open merlinaudio opened this issue 3 years ago • 12 comments

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 snapassist image

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.

minimize button image

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

merlinaudio avatar Dec 24 '22 11:12 merlinaudio

Thanks for opening this. Wails uses native controls so I'm curious about your thinking with CSS variables

leaanthony avatar Dec 24 '22 12:12 leaanthony

@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

merlinaudio avatar Dec 24 '22 13:12 merlinaudio

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

merlinaudio avatar Dec 24 '22 13:12 merlinaudio

Oh, you're talking about frameless windows? I'll come back to you when all this Christmas stuff is over 🤣

leaanthony avatar Dec 25 '22 00:12 leaanthony

Yes!! Sorry, should've made that more clear :P

merlinaudio avatar Dec 25 '22 11:12 merlinaudio

@merlindru - Oops this totally slipped off the radar. I'm very keen on adding this to v3.

leaanthony avatar Jul 09 '23 11:07 leaanthony

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.

stffabi avatar Jul 09 '23 11:07 stffabi

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.

liweilong avatar Apr 16 '25 12:04 liweilong

Implemented in v3

leaanthony avatar Aug 04 '25 09:08 leaanthony

Image

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?

savely-krasovsky avatar May 15 '26 01:05 savely-krasovsky

Absolutely! Looks great. What did you implement?

leaanthony avatar May 15 '26 02:05 leaanthony

@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.

  1. 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.
  2. 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 replace CoreWebView2Controller with CoreWebView2CompositionController. After that, you have to forward correctly all mouse events between the DOM and DWM, if I understand it correctly. Also, since Windows supports only app-region values drag/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, using System.invoke, pass it to the Go part of Wails where it can mark the zone.

I think both methods should coexists.

savely-krasovsky avatar May 15 '26 09:05 savely-krasovsky