Skip to content

Update: move scale to screen and rename pub mdata #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions screen/screen_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,70 @@
#include <ApplicationServices/ApplicationServices.h>
#elif defined(USE_X11)
#include <X11/Xlib.h>
#include <X11/Xresource.h>
// #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
65 changes: 3 additions & 62 deletions window/win_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#if defined(USE_X11)
#include <X11/Xresource.h>
#endif
// #if defined(USE_X11)
// #include <X11/Xresource.h>
// #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
Loading