Skip to content

Commit

Permalink
Merge pull request #691 from go-vgo/bitmap-pr
Browse files Browse the repository at this point in the history
Update: move scale to screen and rename pub mdata
  • Loading branch information
vcaesar authored Oct 7, 2024
2 parents 0de26ec + ead43d0 commit 1923d7b
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 104 deletions.
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

0 comments on commit 1923d7b

Please sign in to comment.