Skip to content

Commit

Permalink
Update: move scale to screen and rename pub mdata
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Oct 7, 2024
1 parent c48e3d0 commit 3258566
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 101 deletions.
60 changes: 60 additions & 0 deletions screen/screen_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,66 @@
// #include "../base/xdisplay_c.h"
#endif

intptr scaleX();

double sys_scale(int32_t display_id) {
#if defined(IS_MACOSX)
CGDirectDisplayID displayID = (CGDirectDisplayID) display_id;
if (displayID == -1) {
displayID = CGMainDisplayID();
}

CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
double targetWidth = CGDisplayModeGetWidth(modeRef);

return pixelWidth / targetWidth;
#elif defined(USE_X11)
Display *dpy = XOpenDisplay(NULL);

int scr = 0; /* Screen number */
double xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
((double) DisplayWidthMM(dpy, scr)));

char *rms = XResourceManagerString(dpy);
if (rms) {
XrmDatabase db = XrmGetStringDatabase(rms);
if (db) {
XrmValue value;
char *type = NULL;

if (XrmGetResource(db, "Xft.dpi", "String", &type, &value)) {
if (value.addr) {
xres = atof(value.addr);
}
}

XrmDestroyDatabase(db);
}
}
XCloseDisplay (dpy);

return xres / 96.0;
#elif defined(IS_WINDOWS)
double s = scaleX() / 96.0;
return s;
#endif
}

intptr scaleX(){
#if defined(IS_MACOSX)
return 0;
#elif defined(USE_X11)
return 0;
#elif defined(IS_WINDOWS)
// Get desktop dc
HDC desktopDc = GetDC(NULL);
// Get native resolution
intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX);
return horizontalDPI;
#endif
}

MMSizeInt32 getMainDisplaySize(void) {
#if defined(IS_MACOSX)
CGDirectDisplayID displayID = CGMainDisplayID();
Expand Down
6 changes: 3 additions & 3 deletions window/goWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ uintptr get_handle(){

uintptr b_get_handle() {
#if defined(IS_MACOSX)
return (uintptr)mData.CgID;
return (uintptr)pub_mData.CgID;
#elif defined(USE_X11)
return (uintptr)mData.XWin;
return (uintptr)pub_mData.XWin;
#elif defined(IS_WINDOWS)
return (uintptr)mData.HWnd;
return (uintptr)pub_mData.HWnd;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion window/pub.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct _MData{
};

typedef struct _MData MData;
MData mData;
MData pub_mData;

struct _Bounds {
int32_t X; // Top left X coordinate
Expand Down
59 changes: 0 additions & 59 deletions window/win_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,6 @@
#endif

Bounds get_client(uintptr pid, int8_t isPid);
intptr scaleX();

double sys_scale(int32_t display_id) {
#if defined(IS_MACOSX)
CGDirectDisplayID displayID = (CGDirectDisplayID) display_id;
if (displayID == -1) {
displayID = CGMainDisplayID();
}

CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
double targetWidth = CGDisplayModeGetWidth(modeRef);

return pixelWidth / targetWidth;
#elif defined(USE_X11)
Display *dpy = XOpenDisplay(NULL);

int scr = 0; /* Screen number */
double xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
((double) DisplayWidthMM(dpy, scr)));

char *rms = XResourceManagerString(dpy);
if (rms) {
XrmDatabase db = XrmGetStringDatabase(rms);
if (db) {
XrmValue value;
char *type = NULL;

if (XrmGetResource(db, "Xft.dpi", "String", &type, &value)) {
if (value.addr) {
xres = atof(value.addr);
}
}

XrmDestroyDatabase(db);
}
}
XCloseDisplay (dpy);

return xres / 96.0;
#elif defined(IS_WINDOWS)
double s = scaleX() / 96.0;
return s;
#endif
}

intptr scaleX(){
#if defined(IS_MACOSX)
return 0;
#elif defined(USE_X11)
return 0;
#elif defined(IS_WINDOWS)
// Get desktop dc
HDC desktopDc = GetDC(NULL);
// Get native resolution
intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX);
return horizontalDPI;
#endif
}

Bounds get_bounds(uintptr pid, int8_t isPid){
// Check if the window is valid
Expand Down
Loading

0 comments on commit 3258566

Please sign in to comment.