mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
app/internal/window: use GetDpiForWindow if available
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -156,7 +156,8 @@ func createNativeWindow(opts *Options) (*window, error) {
|
|||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return nil, resErr
|
return nil, resErr
|
||||||
}
|
}
|
||||||
cfg := configForDC()
|
dpi := windows.GetSystemDPI()
|
||||||
|
cfg := configForDPI(dpi)
|
||||||
wr := windows.Rect{
|
wr := windows.Rect{
|
||||||
Right: int32(cfg.Px(opts.Width)),
|
Right: int32(cfg.Px(opts.Width)),
|
||||||
Bottom: int32(cfg.Px(opts.Height)),
|
Bottom: int32(cfg.Px(opts.Height)),
|
||||||
@@ -276,14 +277,14 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
mm := (*windows.MinMaxInfo)(unsafe.Pointer(uintptr(lParam)))
|
mm := (*windows.MinMaxInfo)(unsafe.Pointer(uintptr(lParam)))
|
||||||
if w.minmax.minWidth > 0 || w.minmax.minHeight > 0 {
|
if w.minmax.minWidth > 0 || w.minmax.minHeight > 0 {
|
||||||
mm.PtMinTrackSize = windows.Point{
|
mm.PtMinTrackSize = windows.Point{
|
||||||
w.minmax.minWidth+w.deltas.width,
|
w.minmax.minWidth + w.deltas.width,
|
||||||
w.minmax.minHeight+w.deltas.height,
|
w.minmax.minHeight + w.deltas.height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.minmax.maxWidth > 0 || w.minmax.maxHeight > 0 {
|
if w.minmax.maxWidth > 0 || w.minmax.maxHeight > 0 {
|
||||||
mm.PtMaxTrackSize = windows.Point{
|
mm.PtMaxTrackSize = windows.Point{
|
||||||
w.minmax.maxWidth+w.deltas.width,
|
w.minmax.maxWidth + w.deltas.width,
|
||||||
w.minmax.maxHeight+w.deltas.height,
|
w.minmax.maxHeight + w.deltas.height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +410,8 @@ func (w *window) draw(sync bool) {
|
|||||||
if w.width == 0 || w.height == 0 {
|
if w.width == 0 || w.height == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cfg := configForDC()
|
dpi := windows.GetWindowDPI(w.hwnd)
|
||||||
|
cfg := configForDPI(dpi)
|
||||||
w.minmax = getWindowConstraints(cfg, w.opts, w.deltas)
|
w.minmax = getWindowConstraints(cfg, w.opts, w.deltas)
|
||||||
w.w.Event(FrameEvent{
|
w.w.Event(FrameEvent{
|
||||||
FrameEvent: system.FrameEvent{
|
FrameEvent: system.FrameEvent{
|
||||||
@@ -631,8 +633,7 @@ func convertKeyCode(code uintptr) (string, bool) {
|
|||||||
return r, true
|
return r, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func configForDC() unit.Metric {
|
func configForDPI(dpi int) unit.Metric {
|
||||||
dpi := windows.GetSystemDPI()
|
|
||||||
const inchPrDp = 1.0 / 96.0
|
const inchPrDp = 1.0 / 96.0
|
||||||
ppdp := float32(dpi) * inchPrDp
|
ppdp := float32(dpi) * inchPrDp
|
||||||
return unit.Metric{
|
return unit.Metric{
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ var (
|
|||||||
_GetClientRect = user32.NewProc("GetClientRect")
|
_GetClientRect = user32.NewProc("GetClientRect")
|
||||||
_GetClipboardData = user32.NewProc("GetClipboardData")
|
_GetClipboardData = user32.NewProc("GetClipboardData")
|
||||||
_GetDC = user32.NewProc("GetDC")
|
_GetDC = user32.NewProc("GetDC")
|
||||||
|
_GetDpiForWindow = user32.NewProc("GetDpiForWindow")
|
||||||
_GetKeyState = user32.NewProc("GetKeyState")
|
_GetKeyState = user32.NewProc("GetKeyState")
|
||||||
_GetMessage = user32.NewProc("GetMessageW")
|
_GetMessage = user32.NewProc("GetMessageW")
|
||||||
_GetMessageTime = user32.NewProc("GetMessageTime")
|
_GetMessageTime = user32.NewProc("GetMessageTime")
|
||||||
@@ -343,7 +344,7 @@ func getDpiForMonitor(hmonitor syscall.Handle, dpiType uint32) int {
|
|||||||
|
|
||||||
// GetSystemDPI returns the effective DPI of the system.
|
// GetSystemDPI returns the effective DPI of the system.
|
||||||
func GetSystemDPI() int {
|
func GetSystemDPI() int {
|
||||||
// Check for getDpiForMonitor, introduced in Windows 8.1.
|
// Check for GetDpiForMonitor, introduced in Windows 8.1.
|
||||||
if _GetDpiForMonitor.Find() == nil {
|
if _GetDpiForMonitor.Find() == nil {
|
||||||
hmon := monitorFromPoint(Point{}, MONITOR_DEFAULTTOPRIMARY)
|
hmon := monitorFromPoint(Point{}, MONITOR_DEFAULTTOPRIMARY)
|
||||||
return getDpiForMonitor(hmon, MDT_EFFECTIVE_DPI)
|
return getDpiForMonitor(hmon, MDT_EFFECTIVE_DPI)
|
||||||
@@ -377,6 +378,17 @@ func GetMessageTime() time.Duration {
|
|||||||
return time.Duration(r) * time.Millisecond
|
return time.Duration(r) * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWindowDPI returns the effective DPI of the window.
|
||||||
|
func GetWindowDPI(hwnd syscall.Handle) int {
|
||||||
|
// Check for GetDpiForWindow, introduced in Windows 10.
|
||||||
|
if _GetDpiForWindow.Find() == nil {
|
||||||
|
dpi, _, _ := _GetDpiForWindow.Call(uintptr(hwnd))
|
||||||
|
return int(dpi)
|
||||||
|
} else {
|
||||||
|
return GetSystemDPI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GlobalAlloc(size int) (syscall.Handle, error) {
|
func GlobalAlloc(size int) (syscall.Handle, error) {
|
||||||
r, _, err := _GlobalAlloc.Call(GHND, uintptr(size))
|
r, _, err := _GlobalAlloc.Call(GHND, uintptr(size))
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user