add all platform system scale support

This commit is contained in:
vcaesar 2019-12-04 10:08:09 -04:00
parent a5f566e505
commit c3334d86b3
2 changed files with 39 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,39 @@ 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 */
if( (NULL == x) || (NULL == y)){ return ; }
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;