jchv/go-webview2

[Feature Request] High DPI support

Tim-Paik opened this issue · 3 comments

High-resolution screen users need support, the demo now looks very vague (Windows11 125% zoom)
image

jchv commented

This is a bit confounding because DPI awareness is per-process on Windows. For example, go-webview2 will magically work fine with high DPI if you do:

	dll := syscall.MustLoadDLL("user32")
	if proc, err := dll.FindProc("SetProcessDpiAwarenessContext"); err == nil {
		aware := -4
		proc.Call(uintptr(aware))
	}

…but it will also impact everything else in process too, so doing this automatically may not be desirable.

The same can be accomplished using manifests as well.

Since this feature is really about making better Win32 apps with Go, maybe there can be some kind of helper package or recommended boilerplate that helps you get an ideal binary with backwards-compatible DPI awareness.

This can indeed become clear, but the window will be smaller than when the system is zoomed, and the content will not be zoomed.
I think this feature should work out of the box

jchv commented

Hmm? This method should work just fine. Try doing it in init() to ensure it occurs early enough.

I understand that it would be nice to have it be automatic, but even if this library does have this method it has to be optional. Otherwise, it would make the library unusable for users using any other Win32 code that is not DPI aware. I apologize for the inconvenience.

(Also, calls to SetProcessDpiAwarenessContext require Windows 10 1703. You can get DPI awareness on older Windows versions, but it works differently. When it comes to display scaling on Windows, there's enough nuance to fill a small book!)