mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-29 21:43:55 +00:00
add sys scale option displayID support
This commit is contained in:
parent
627f5c9d3b
commit
337cd3f73a
@ -33,7 +33,7 @@ typedef MMBitmap *MMBitmapRef;
|
|||||||
|
|
||||||
/* Creates new MMBitmap with the given values.
|
/* Creates new MMBitmap with the given values.
|
||||||
* Follows the Create Rule (caller is responsible for destroy()'ing object). */
|
* Follows the Create Rule (caller is responsible for destroy()'ing object). */
|
||||||
MMBitmapRef createMMBitmap(uint8_t *buffer, size_t width, size_t height,
|
MMBitmapRef createMMBitmap_c(uint8_t *buffer, size_t width, size_t height,
|
||||||
size_t bytewidth, uint8_t bitsPerPixel,
|
size_t bytewidth, uint8_t bitsPerPixel,
|
||||||
uint8_t bytesPerPixel);
|
uint8_t bytesPerPixel);
|
||||||
|
|
||||||
@ -43,12 +43,12 @@ void destroyMMBitmap(MMBitmapRef bitmap);
|
|||||||
/* Releases memory occupied by MMBitmap. Acts via CallBack method*/
|
/* Releases memory occupied by MMBitmap. Acts via CallBack method*/
|
||||||
void destroyMMBitmapBuffer(char * bitmapBuffer, void * hint);
|
void destroyMMBitmapBuffer(char * bitmapBuffer, void * hint);
|
||||||
|
|
||||||
/* Returns copy of MMBitmap, to be destroy()'d by caller. */
|
// /* Returns copy of MMBitmap, to be destroy()'d by caller. */
|
||||||
MMBitmapRef copyMMBitmap(MMBitmapRef bitmap);
|
// MMBitmapRef copyMMBitmap(MMBitmapRef bitmap);
|
||||||
|
|
||||||
/* Returns copy of one MMBitmap juxtaposed in another (to be destroy()'d
|
// /* Returns copy of one MMBitmap juxtaposed in another (to be destroy()'d
|
||||||
* by the caller.), or NULL on error. */
|
// * by the caller.), or NULL on error. */
|
||||||
MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
|
// MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
|
||||||
|
|
||||||
#define MMBitmapPointInBounds(image, p) ((p).x < (image)->width && \
|
#define MMBitmapPointInBounds(image, p) ((p).x < (image)->width && \
|
||||||
(p).y < (image)->height)
|
(p).y < (image)->height)
|
||||||
@ -72,19 +72,19 @@ MMBitmapRef copyMMBitmapFromPortion(MMBitmapRef source, MMRect rect);
|
|||||||
#define MMRGBHexAtPoint(image, x, y) \
|
#define MMRGBHexAtPoint(image, x, y) \
|
||||||
hexFromMMRGB(MMRGBColorAtPoint(image, x, y))
|
hexFromMMRGB(MMRGBColorAtPoint(image, x, y))
|
||||||
|
|
||||||
/* Increment either point.x or point.y depending on the position of point.x.
|
// /* Increment either point.x or point.y depending on the position of point.x.
|
||||||
* That is, if x + 1 is >= width, increment y and start x at the beginning.
|
// * That is, if x + 1 is >= width, increment y and start x at the beginning.
|
||||||
* Otherwise, increment x.
|
// * Otherwise, increment x.
|
||||||
*
|
// *
|
||||||
* This is used as a convenience macro to scan rows when calling functions such
|
// * This is used as a convenience macro to scan rows when calling functions such
|
||||||
* as findColorInRectAt() and findBitmapInBitmapAt(). */
|
// * as findColorInRectAt() and findBitmapInBitmapAt(). */
|
||||||
#define ITER_NEXT_POINT(pixel, width, start_x) \
|
// #define ITER_NEXT_POINT(pixel, width, start_x) \
|
||||||
do { \
|
// do { \
|
||||||
if (++(pixel).x >= (width)) { \
|
// if (++(pixel).x >= (width)) { \
|
||||||
(pixel).x = start_x; \
|
// (pixel).x = start_x; \
|
||||||
++(point).y; \
|
// ++(point).y; \
|
||||||
} \
|
// } \
|
||||||
} while (0);
|
// } while (0);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -4,23 +4,20 @@
|
|||||||
static uint32_t deadbeef_seed;
|
static uint32_t deadbeef_seed;
|
||||||
static uint32_t deadbeef_beef = 0xdeadbeef;
|
static uint32_t deadbeef_beef = 0xdeadbeef;
|
||||||
|
|
||||||
uint32_t deadbeef_rand(void)
|
uint32_t deadbeef_rand(void) {
|
||||||
{
|
|
||||||
deadbeef_seed = (deadbeef_seed << 7) ^ ((deadbeef_seed >> 25) + deadbeef_beef);
|
deadbeef_seed = (deadbeef_seed << 7) ^ ((deadbeef_seed >> 25) + deadbeef_beef);
|
||||||
deadbeef_beef = (deadbeef_beef << 7) ^ ((deadbeef_beef >> 25) + 0xdeadbeef);
|
deadbeef_beef = (deadbeef_beef << 7) ^ ((deadbeef_beef >> 25) + 0xdeadbeef);
|
||||||
return deadbeef_seed;
|
return deadbeef_seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deadbeef_srand(uint32_t x)
|
void deadbeef_srand(uint32_t x) {
|
||||||
{
|
|
||||||
deadbeef_seed = x;
|
deadbeef_seed = x;
|
||||||
deadbeef_beef = 0xdeadbeef;
|
deadbeef_beef = 0xdeadbeef;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Taken directly from the documentation:
|
/* Taken directly from the documentation:
|
||||||
* http://inglorion.net/software/cstuff/deadbeef_rand/ */
|
* http://inglorion.net/software/cstuff/deadbeef_rand/ */
|
||||||
uint32_t deadbeef_generate_seed(void)
|
uint32_t deadbeef_generate_seed(void) {
|
||||||
{
|
|
||||||
uint32_t t = (uint32_t)time(NULL);
|
uint32_t t = (uint32_t)time(NULL);
|
||||||
uint32_t c = (uint32_t)clock();
|
uint32_t c = (uint32_t)clock();
|
||||||
return (t << 24) ^ (c << 11) ^ t ^ (size_t) &c;
|
return (t << 24) ^ (c << 11) ^ t ^ (size_t) &c;
|
||||||
|
15
robotgo.go
15
robotgo.go
@ -236,14 +236,15 @@ func displayIdx(id ...int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SysScale get the sys scale
|
// SysScale get the sys scale
|
||||||
func SysScale() float64 {
|
func SysScale(displayId ...int) float64 {
|
||||||
s := C.sys_scale()
|
display := displayIdx(displayId...)
|
||||||
|
s := C.sys_scale(C.int32_t(display))
|
||||||
return float64(s)
|
return float64(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scaled get the screen scaled size
|
// Scaled get the screen scaled size
|
||||||
func Scaled(x int) int {
|
func Scaled(x int, displayId ...int) int {
|
||||||
f := ScaleF()
|
f := ScaleF(displayId...)
|
||||||
return Scaled0(x, f)
|
return Scaled0(x, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +272,7 @@ func GetScreenRect(displayId ...int) Rect {
|
|||||||
int(rect.size.w), int(rect.size.h)
|
int(rect.size.w), int(rect.size.h)
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
f := ScaleF()
|
f := ScaleF(displayId...)
|
||||||
x, y, w, h = Scaled0(x, f), Scaled0(y, f), Scaled0(w, f), Scaled0(h, f)
|
x, y, w, h = Scaled0(x, f), Scaled0(y, f), Scaled0(w, f), Scaled0(h, f)
|
||||||
}
|
}
|
||||||
return Rect{
|
return Rect{
|
||||||
@ -281,9 +282,9 @@ func GetScreenRect(displayId ...int) Rect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetScaleSize get the screen scale size
|
// GetScaleSize get the screen scale size
|
||||||
func GetScaleSize() (int, int) {
|
func GetScaleSize(displayId ...int) (int, int) {
|
||||||
x, y := GetScreenSize()
|
x, y := GetScreenSize()
|
||||||
f := ScaleF()
|
f := ScaleF(displayId...)
|
||||||
return int(float64(x) * f), int(float64(y) * f)
|
return int(float64(x) * f), int(float64(y) * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
package robotgo
|
package robotgo
|
||||||
|
|
||||||
// ScaleF get the system scale val
|
// ScaleF get the system scale val
|
||||||
func ScaleF() float64 {
|
func ScaleF(displayId ...int) float64 {
|
||||||
f := SysScale()
|
f := SysScale(displayId...)
|
||||||
if f == 0.0 {
|
if f == 0.0 {
|
||||||
f = 1.0
|
f = 1.0
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,13 @@ func SetFocus(hwnd win.HWND) win.HWND {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ScaleF get the system scale val
|
// ScaleF get the system scale val
|
||||||
func ScaleF() float64 {
|
func ScaleF(displayId ...int) (f float64) {
|
||||||
f := float64(GetMainDPI()) / 96.0
|
if len(displayId) > 0 && displayId[0] != -1 {
|
||||||
|
dpi := GetDPI(win.HWND(displayId[0]))
|
||||||
|
f = float64(dpi) / 96.0
|
||||||
|
} else {
|
||||||
|
f = float64(GetMainDPI()) / 96.0
|
||||||
|
}
|
||||||
if f == 0.0 {
|
if f == 0.0 {
|
||||||
f = 1.0
|
f = 1.0
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ static int xmessage(char *argv[], int *exit_status);
|
|||||||
kCFStringEncodingUTF8))
|
kCFStringEncodingUTF8))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int showAlert(const char *title, const char *msg, const char *defaultButton,
|
int showAlert(const char *title, const char *msg,
|
||||||
const char *cancelButton)
|
const char *defaultButton, const char *cancelButton)
|
||||||
{
|
{
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CFStringRef alertHeader = CFStringCreateWithUTF8String(title);
|
CFStringRef alertHeader = CFStringCreateWithUTF8String(title);
|
||||||
@ -46,17 +46,9 @@ int showAlert(const char *title, const char *msg, const char *defaultButton,
|
|||||||
CFStringRef defaultButtonTitle = CFStringCreateWithUTF8String(defaultButton);
|
CFStringRef defaultButtonTitle = CFStringCreateWithUTF8String(defaultButton);
|
||||||
CFStringRef cancelButtonTitle = CFStringCreateWithUTF8String(cancelButton);
|
CFStringRef cancelButtonTitle = CFStringCreateWithUTF8String(cancelButton);
|
||||||
CFOptionFlags responseFlags;
|
CFOptionFlags responseFlags;
|
||||||
SInt32 err = CFUserNotificationDisplayAlert(0.0,
|
SInt32 err = CFUserNotificationDisplayAlert(
|
||||||
kCFUserNotificationNoteAlertLevel,
|
0.0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, alertHeader, alertMessage,
|
||||||
NULL,
|
defaultButtonTitle, cancelButtonTitle, NULL, &responseFlags);
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
alertHeader,
|
|
||||||
alertMessage,
|
|
||||||
defaultButtonTitle,
|
|
||||||
cancelButtonTitle,
|
|
||||||
NULL,
|
|
||||||
&responseFlags);
|
|
||||||
|
|
||||||
if (alertHeader != NULL) CFRelease(alertHeader);
|
if (alertHeader != NULL) CFRelease(alertHeader);
|
||||||
if (alertMessage != NULL) CFRelease(alertMessage);
|
if (alertMessage != NULL) CFRelease(alertMessage);
|
||||||
|
@ -17,25 +17,13 @@
|
|||||||
|
|
||||||
Bounds get_client(uintptr pid, uintptr isHwnd);
|
Bounds get_client(uintptr pid, uintptr isHwnd);
|
||||||
|
|
||||||
intptr scaleX(){
|
double sys_scale(int32_t display_id) {
|
||||||
#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);
|
|
||||||
// intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY);
|
|
||||||
return horizontalDPI;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
double sys_scale() {
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
|
|
||||||
CGDirectDisplayID displayID = CGMainDisplayID();
|
CGDirectDisplayID displayID = (CGDirectDisplayID) display_id;
|
||||||
|
if (displayID == -1) {
|
||||||
|
displayID = CGMainDisplayID();
|
||||||
|
}
|
||||||
CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
|
CGDisplayModeRef modeRef = CGDisplayCopyDisplayMode(displayID);
|
||||||
|
|
||||||
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
|
double pixelWidth = CGDisplayModeGetPixelWidth(modeRef);
|
||||||
@ -44,12 +32,11 @@ double sys_scale() {
|
|||||||
return pixelWidth / targetWidth;
|
return pixelWidth / targetWidth;
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
double xres;
|
double xres;
|
||||||
Display *dpy;
|
|
||||||
|
|
||||||
char *displayname = NULL;
|
char *displayname = NULL;
|
||||||
|
Display *dpy = XOpenDisplay(displayname);
|
||||||
|
|
||||||
int scr = 0; /* Screen number */
|
int scr = 0; /* Screen number */
|
||||||
|
|
||||||
dpy = XOpenDisplay(displayname);
|
|
||||||
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
|
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
|
||||||
((double) DisplayWidthMM(dpy, scr)));
|
((double) DisplayWidthMM(dpy, scr)));
|
||||||
|
|
||||||
@ -79,6 +66,21 @@ double sys_scale() {
|
|||||||
#endif
|
#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);
|
||||||
|
// intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY);
|
||||||
|
return horizontalDPI;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
intptr scaleY(){
|
intptr scaleY(){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user