diff --git a/robotgo.go b/robotgo.go index eebf90f..bcc4f6d 100644 --- a/robotgo.go +++ b/robotgo.go @@ -305,8 +305,8 @@ func Mul(x int) int { // GetScaleSize get the screen scale size func GetScaleSize() (int, int) { x, y := GetScreenSize() - s := Scale() - return x * s / 100, y * s / 100 + f := ScaleF() + return int(float64(x) * f), int(float64(y) * f) } // SetXDisplayName set XDisplay name (Linux) diff --git a/robotgo_mac.go b/robotgo_mac.go new file mode 100644 index 0000000..d01706f --- /dev/null +++ b/robotgo_mac.go @@ -0,0 +1,19 @@ +// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// https://github.com/go-vgo/robotgo/blob/master/LICENSE +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//go:build !windows +// +build !windows + +package robotgo + +// ScaleF get the system scale val +func ScaleF() float64 { + return SysScale() +} diff --git a/robotgo_win.go b/robotgo_win.go index 46a3808..ba7bb58 100644 --- a/robotgo_win.go +++ b/robotgo_win.go @@ -21,16 +21,14 @@ import ( ) // FindWindow find window hwnd by name -func FindWindow(str string) win.HWND { - hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(str)) - +func FindWindow(name string) win.HWND { + hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(name)) return hwnd } // GetHWND get foreground window hwnd func GetHWND() win.HWND { hwnd := win.GetForegroundWindow() - return hwnd } @@ -50,6 +48,26 @@ func SetActiveWindow(hwnd win.HWND) win.HWND { } // SetFocus set window focus with hwnd -func SetFocus(hWnd win.HWND) win.HWND { +func SetFocus(hwnd win.HWND) win.HWND { return win.SetFocus(hWnd) } + +// ScaleF get the system scale val +func ScaleF() float64 { + return float64(GetMainDPI()) / 96.0 +} + +// GetMainDPI get the display dpi +func GetMainDPI() int { + return int(GetDPI(GetHWND())) +} + +// GetDPI get the window dpi +func GetDPI(hwnd win.HWND) uint32 { + return win.GetDpiForWindow(hwnd) +} + +// GetSysDPI get the system metrics dpi +func GetSysDPI(idx int32, dpi uint32) int32 { + return win.GetSystemMetricsForDpi(idex, dpi) +}