Skip to content

Commit 337cd3f

Browse files
committed
add sys scale option displayID support
1 parent 627f5c9 commit 337cd3f

File tree

7 files changed

+66
-69
lines changed

7 files changed

+66
-69
lines changed

base/MMBitmap.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef MMBitmap *MMBitmapRef;
3333

3434
/* Creates new MMBitmap with the given values.
3535
* Follows the Create Rule (caller is responsible for destroy()'ing object). */
36-
MMBitmapRef createMMBitmap(uint8_t *buffer, size_t width, size_t height,
36+
MMBitmapRef createMMBitmap_c(uint8_t *buffer, size_t width, size_t height,
3737
size_t bytewidth, uint8_t bitsPerPixel,
3838
uint8_t bytesPerPixel);
3939

@@ -43,12 +43,12 @@ void destroyMMBitmap(MMBitmapRef bitmap);
4343
/* Releases memory occupied by MMBitmap. Acts via CallBack method*/
4444
void destroyMMBitmapBuffer(char * bitmapBuffer, void * hint);
4545

46-
/* Returns copy of MMBitmap, to be destroy()'d by caller. */
47-
MMBitmapRef copyMMBitmap(MMBitmapRef bitmap);
46+
// /* Returns copy of MMBitmap, to be destroy()'d by caller. */
47+
// MMBitmapRef copyMMBitmap(MMBitmapRef bitmap);
4848

49-
/* Returns copy of one MMBitmap juxtaposed in another (to be destroy()'d
50-
* by the caller.), or NULL on error. */
51-
MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
49+
// /* Returns copy of one MMBitmap juxtaposed in another (to be destroy()'d
50+
// * by the caller.), or NULL on error. */
51+
// MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
5252

5353
#define MMBitmapPointInBounds(image, p) ((p).x < (image)->width && \
5454
(p).y < (image)->height)
@@ -72,19 +72,19 @@ MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
7272
#define MMRGBHexAtPoint(image, x, y) \
7373
hexFromMMRGB(MMRGBColorAtPoint(image, x, y))
7474

75-
/* Increment either point.x or point.y depending on the position of point.x.
76-
* That is, if x + 1 is >= width, increment y and start x at the beginning.
77-
* Otherwise, increment x.
78-
*
79-
* This is used as a convenience macro to scan rows when calling functions such
80-
* as findColorInRectAt() and findBitmapInBitmapAt(). */
81-
#define ITER_NEXT_POINT(pixel, width, start_x) \
82-
do { \
83-
if (++(pixel).x >= (width)) { \
84-
(pixel).x = start_x; \
85-
++(point).y; \
86-
} \
87-
} while (0);
75+
// /* Increment either point.x or point.y depending on the position of point.x.
76+
// * That is, if x + 1 is >= width, increment y and start x at the beginning.
77+
// * Otherwise, increment x.
78+
// *
79+
// * This is used as a convenience macro to scan rows when calling functions such
80+
// * as findColorInRectAt() and findBitmapInBitmapAt(). */
81+
// #define ITER_NEXT_POINT(pixel, width, start_x) \
82+
// do { \
83+
// if (++(pixel).x >= (width)) { \
84+
// (pixel).x = start_x; \
85+
// ++(point).y; \
86+
// } \
87+
// } while (0);
8888

8989
#ifdef __cplusplus
9090
}

base/deadbeef_rand_c.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
static uint32_t deadbeef_seed;
55
static uint32_t deadbeef_beef = 0xdeadbeef;
66

7-
uint32_t deadbeef_rand(void)
8-
{
7+
uint32_t deadbeef_rand(void) {
98
deadbeef_seed = (deadbeef_seed << 7) ^ ((deadbeef_seed >> 25) + deadbeef_beef);
109
deadbeef_beef = (deadbeef_beef << 7) ^ ((deadbeef_beef >> 25) + 0xdeadbeef);
1110
return deadbeef_seed;
1211
}
1312

14-
void deadbeef_srand(uint32_t x)
15-
{
13+
void deadbeef_srand(uint32_t x) {
1614
deadbeef_seed = x;
1715
deadbeef_beef = 0xdeadbeef;
1816
}
1917

2018
/* Taken directly from the documentation:
2119
* http://inglorion.net/software/cstuff/deadbeef_rand/ */
22-
uint32_t deadbeef_generate_seed(void)
23-
{
20+
uint32_t deadbeef_generate_seed(void) {
2421
uint32_t t = (uint32_t)time(NULL);
2522
uint32_t c = (uint32_t)clock();
2623
return (t << 24) ^ (c << 11) ^ t ^ (size_t) &c;

robotgo.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,15 @@ func displayIdx(id ...int) int {
236236
}
237237

238238
// SysScale get the sys scale
239-
func SysScale() float64 {
240-
s := C.sys_scale()
239+
func SysScale(displayId ...int) float64 {
240+
display := displayIdx(displayId...)
241+
s := C.sys_scale(C.int32_t(display))
241242
return float64(s)
242243
}
243244

244245
// Scaled get the screen scaled size
245-
func Scaled(x int) int {
246-
f := ScaleF()
246+
func Scaled(x int, displayId ...int) int {
247+
f := ScaleF(displayId...)
247248
return Scaled0(x, f)
248249
}
249250

@@ -271,7 +272,7 @@ func GetScreenRect(displayId ...int) Rect {
271272
int(rect.size.w), int(rect.size.h)
272273

273274
if runtime.GOOS == "windows" {
274-
f := ScaleF()
275+
f := ScaleF(displayId...)
275276
x, y, w, h = Scaled0(x, f), Scaled0(y, f), Scaled0(w, f), Scaled0(h, f)
276277
}
277278
return Rect{
@@ -281,9 +282,9 @@ func GetScreenRect(displayId ...int) Rect {
281282
}
282283

283284
// GetScaleSize get the screen scale size
284-
func GetScaleSize() (int, int) {
285+
func GetScaleSize(displayId ...int) (int, int) {
285286
x, y := GetScreenSize()
286-
f := ScaleF()
287+
f := ScaleF(displayId...)
287288
return int(float64(x) * f), int(float64(y) * f)
288289
}
289290

robotgo_mac_unix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
package robotgo
1515

1616
// ScaleF get the system scale val
17-
func ScaleF() float64 {
18-
f := SysScale()
17+
func ScaleF(displayId ...int) float64 {
18+
f := SysScale(displayId...)
1919
if f == 0.0 {
2020
f = 1.0
2121
}

robotgo_win.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ func SetFocus(hwnd win.HWND) win.HWND {
5353
}
5454

5555
// ScaleF get the system scale val
56-
func ScaleF() float64 {
57-
f := float64(GetMainDPI()) / 96.0
56+
func ScaleF(displayId ...int) (f float64) {
57+
if len(displayId) > 0 && displayId[0] != -1 {
58+
dpi := GetDPI(win.HWND(displayId[0]))
59+
f = float64(dpi) / 96.0
60+
} else {
61+
f = float64(GetMainDPI()) / 96.0
62+
}
5863
if f == 0.0 {
5964
f = 1.0
6065
}

window/alert_c.h

+5-13
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,18 @@ static int xmessage(char *argv[], int *exit_status);
3737
kCFStringEncodingUTF8))
3838
#endif
3939

40-
int showAlert(const char *title, const char *msg, const char *defaultButton,
41-
const char *cancelButton)
40+
int showAlert(const char *title, const char *msg,
41+
const char *defaultButton, const char *cancelButton)
4242
{
4343
#if defined(IS_MACOSX)
4444
CFStringRef alertHeader = CFStringCreateWithUTF8String(title);
4545
CFStringRef alertMessage = CFStringCreateWithUTF8String(msg);
4646
CFStringRef defaultButtonTitle = CFStringCreateWithUTF8String(defaultButton);
4747
CFStringRef cancelButtonTitle = CFStringCreateWithUTF8String(cancelButton);
4848
CFOptionFlags responseFlags;
49-
SInt32 err = CFUserNotificationDisplayAlert(0.0,
50-
kCFUserNotificationNoteAlertLevel,
51-
NULL,
52-
NULL,
53-
NULL,
54-
alertHeader,
55-
alertMessage,
56-
defaultButtonTitle,
57-
cancelButtonTitle,
58-
NULL,
59-
&responseFlags);
49+
SInt32 err = CFUserNotificationDisplayAlert(
50+
0.0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, alertHeader, alertMessage,
51+
defaultButtonTitle, cancelButtonTitle, NULL, &responseFlags);
6052

6153
if (alertHeader != NULL) CFRelease(alertHeader);
6254
if (alertMessage != NULL) CFRelease(alertMessage);

window/win_sys.h

+22-20
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,13 @@
1717

1818
Bounds get_client(uintptr pid, uintptr isHwnd);
1919

20-
intptr scaleX(){
21-
#if defined(IS_MACOSX)
22-
return 0;
23-
#elif defined(USE_X11)
24-
return 0;
25-
#elif defined(IS_WINDOWS)
26-
// Get desktop dc
27-
HDC desktopDc = GetDC(NULL);
28-
// Get native resolution
29-
intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX);
30-
// intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY);
31-
return horizontalDPI;
32-
#endif
33-
}
34-
35-
double sys_scale() {
20+
double sys_scale(int32_t display_id) {
3621
#if defined(IS_MACOSX)
3722

38-
CGDirectDisplayID displayID = CGMainDisplayID();
23+
CGDirectDisplayID displayID = (CGDirectDisplayID) display_id;
24+
if (displayID == -1) {
25+
displayID = CGMainDisplayID();
26+
}
3927
CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
4028

4129
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
@@ -44,12 +32,11 @@ double sys_scale() {
4432
return pixelWidth / targetWidth;
4533
#elif defined(USE_X11)
4634
double xres;
47-
Display *dpy;
4835

4936
char *displayname = NULL;
37+
Display *dpy = XOpenDisplay(displayname);
38+
5039
int scr = 0; /* Screen number */
51-
52-
dpy = XOpenDisplay(displayname);
5340
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
5441
((double) DisplayWidthMM(dpy, scr)));
5542

@@ -79,6 +66,21 @@ double sys_scale() {
7966
#endif
8067
}
8168

69+
intptr scaleX(){
70+
#if defined(IS_MACOSX)
71+
return 0;
72+
#elif defined(USE_X11)
73+
return 0;
74+
#elif defined(IS_WINDOWS)
75+
// Get desktop dc
76+
HDC desktopDc = GetDC(NULL);
77+
// Get native resolution
78+
intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX);
79+
// intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY);
80+
return horizontalDPI;
81+
#endif
82+
}
83+
8284
intptr scaleY(){
8385
#if defined(IS_MACOSX)
8486
return 0;

0 commit comments

Comments
 (0)