Merge pull request #247 from go-vgo/dev

add all platform system scale support
This commit is contained in:
vz 2019-12-05 07:54:40 -04:00 committed by GitHub
commit 64a0d310e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -214,6 +214,12 @@ func ScaleX() int {
return int(C.scale_x())
}
// SysScale get the sys scale
func SysScale() float64 {
s := C.sys_scale()
return float64(s)
}
// ScaleY get primary display vertical DPI scale factor
func ScaleY() int {
return int(C.scale_y())

View File

@ -27,6 +27,37 @@ intptr scaleX(){
#endif
}
double sys_scale() {
#if defined(IS_MACOSX)
CGDirectDisplayID displayID = CGMainDisplayID();
CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
double targetWidth = CGDisplayModeGetWidth(modeRef);
return pixelWidth / targetWidth;
#elif defined(USE_X11)
double xres;
Display *dpy;
char *displayname = NULL;
int scr = 0; /* Screen number */
dpy = XOpenDisplay (displayname);
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
((double) DisplayWidthMM(dpy, scr)));
XCloseDisplay (dpy);
return xres + 0.5;
#elif defined(IS_WINDOWS)
double s = scaleX() / 96.0;
return s;
#endif
}
intptr scaleY(){
#if defined(IS_MACOSX)
return 0;