From a3da8915b9135db99d219811a7a1021f69d49a37 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 30 Nov 2019 10:44:40 -0400 Subject: [PATCH 1/7] add int32_t types support --- base/types.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/base/types.h b/base/types.h index dde1299..dbc8755 100644 --- a/base/types.h +++ b/base/types.h @@ -5,6 +5,7 @@ #include "os.h" #include "inline_keywords.h" /* For H_INLINE */ #include +#include /* Some generic, cross-platform types. */ @@ -15,6 +16,13 @@ struct _MMPoint { typedef struct _MMPoint MMPoint; +struct _MMSignedPoint { + int32_t x; + int32_t y; +}; + +typedef struct _MMSignedPoint MMSignedPoint; + struct _MMSize { size_t width; size_t height; @@ -22,6 +30,14 @@ struct _MMSize { typedef struct _MMSize MMSize; +struct _MMSignedSize { + int32_t w; + int32_t h; +}; + +typedef struct _MMSignedSize MMSignedSize; + + struct _MMRect { MMPoint origin; MMSize size; @@ -29,6 +45,13 @@ struct _MMRect { typedef struct _MMRect MMRect; +struct _MMSignedRect { + MMSignedPoint origin; + MMSignedSize size; +}; + +typedef struct _MMSignedRect MMSignedRect; + H_INLINE MMPoint MMPointMake(size_t x, size_t y) { MMPoint point; @@ -37,6 +60,14 @@ H_INLINE MMPoint MMPointMake(size_t x, size_t y) return point; } +H_INLINE MMSignedPoint MMSignedPointMake(int32_t x, int32_t y) +{ + MMSignedPoint point; + point.x = x; + point.y = y; + return point; +} + H_INLINE MMSize MMSizeMake(size_t width, size_t height) { MMSize size; @@ -45,6 +76,14 @@ H_INLINE MMSize MMSizeMake(size_t width, size_t height) return size; } +H_INLINE MMSignedSize MMSignedSizeMake(int32_t w, int32_t h) +{ + MMSignedSize size; + size.w = w; + size.h = h; + return size; +} + H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) { MMRect rect; @@ -53,6 +92,15 @@ H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) return rect; } +H_INLINE MMSignedRect MMSignedRectMake(int32_t x, int32_t y, int32_t w, int32_t h) +{ + MMSignedRect rect; + rect.origin = MMSignedPointMake(x, y); + rect.size = MMSignedSizeMake(w, h); + return rect; +} + +// #define MMPointZero MMPointMake(0, 0) #if defined(IS_MACOSX) @@ -60,6 +108,9 @@ H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) #define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) #define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y) +#define CGPointFromMMSignedPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) +#define MMSignedPointFromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) + #elif defined(IS_WINDOWS) #define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y) From 4df22c5baa390e6197ed9d1fac20f035ddb8c4f9 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 30 Nov 2019 14:28:38 -0400 Subject: [PATCH 2/7] add drag and move mouse multiple screens support --- mouse/goMouse.h | 16 ++++++++-------- mouse/mouse.h | 6 +++--- mouse/mouse_c.h | 22 +++++++++++----------- robotgo.go | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/mouse/goMouse.h b/mouse/goMouse.h index 0abacbb..5125be2 100644 --- a/mouse/goMouse.h +++ b/mouse/goMouse.h @@ -16,7 +16,7 @@ int mouseDelay = 10; // int keyboardDelay = 10; -// int CheckMouseButton(const char * const b, +// int CheckMouseButton(const char * const b, // MMMouseButton * const button){ // if (!button) return -1; @@ -35,24 +35,24 @@ int mouseDelay = 10; // return 0; // } -int move_mouse(size_t x, size_t y){ - MMPoint point; +int move_mouse(int32_t x, int32_t y){ + MMSignedPoint point; // int x = 103; // int y = 104; - point = MMPointMake(x, y); + point = MMSignedPointMake(x, y); moveMouse(point); return 0; } -int drag_mouse(size_t x, size_t y, MMMouseButton button){ +int drag_mouse(int32_t x, int32_t y, MMMouseButton button){ // const size_t x = 10; // const size_t y = 20; // MMMouseButton button = LEFT_BUTTON; - MMPoint point; - point = MMPointMake(x, y); + MMSignedPoint point; + point = MMSignedPointMake(x, y); dragMouse(point, button); microsleep(mouseDelay); @@ -105,7 +105,7 @@ int mouse_toggle(char* d, MMMouseButton button){ toggleMouse(down, button); microsleep(mouseDelay); - + return 0; } diff --git a/mouse/mouse.h b/mouse/mouse.h index 1b65916..9603723 100644 --- a/mouse/mouse.h +++ b/mouse/mouse.h @@ -65,20 +65,20 @@ typedef int MMMouseWheelDirection; /* Immediately moves the mouse to the given point on-screen. * It is up to the caller to ensure that this point is within the * screen boundaries. */ -void moveMouse(MMPoint point); +void moveMouse(MMSignedPoint point); /* Like moveMouse, moves the mouse to the given point on-screen, but marks * the event as the mouse being dragged on platforms where it is supported. * It is up to the caller to ensure that this point is within the screen * boundaries. */ -void dragMouse(MMPoint point, const MMMouseButton button); +void dragMouse(MMSignedPoint point, const MMMouseButton button); /* Smoothly moves the mouse from the current position to the given point. * deadbeef_srand() should be called before using this function. * * Returns false if unsuccessful (i.e. a point was hit that is outside of the * screen boundaries), or true if successful. */ -bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed); +bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed); // bool smoothlyMoveMouse(MMPoint point); /* Returns the coordinates of the mouse on the current screen. */ diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index b9217ba..32de2c7 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -66,7 +66,7 @@ * @param event The mouse move event (by ref). * @param point The new mouse x and y. */ -void calculateDeltas(CGEventRef *event, MMPoint point){ +void calculateDeltas(CGEventRef *event, MMSignedPoint point){ /** * The next few lines are a workaround for games not detecting mouse moves. * See this issue for more information: @@ -91,10 +91,10 @@ void calculateDeltas(CGEventRef *event, MMPoint point){ * Move the mouse to a specific point. * @param point The coordinates to move the mouse to (x, y). */ -void moveMouse(MMPoint point){ +void moveMouse(MMSignedPoint point){ #if defined(IS_MACOSX) CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, - CGPointFromMMPoint(point), + CGPointFromMMSignedPoint(point), kCGMouseButtonLeft); calculateDeltas(&move, point); @@ -108,7 +108,7 @@ void moveMouse(MMPoint point){ XSync(display, false); #elif defined(IS_WINDOWS) - // Mouse motion is now done using SendInput with MOUSEINPUT. + // Mouse motion is now done using SendInput with MOUSEINPUT. // We use Absolute mouse positioning #define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \ ((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1)) @@ -129,7 +129,7 @@ void moveMouse(MMPoint point){ #endif } -void dragMouse(MMPoint point, const MMMouseButton button){ +void dragMouse(MMSignedPoint point, const MMMouseButton button){ #if defined(IS_MACOSX) const CGEventType dragType = MMMouseDragToCGEventType(button); CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType, @@ -181,7 +181,7 @@ void toggleMouse(bool down, MMMouseButton button){ const CGEventType mouseType = MMMouseToCGEventType(down, button); CGEventRef event = CGEventCreateMouseEvent(NULL, mouseType, currentPos, (CGMouseButton)button); - + CGEventPost(kCGSessionEventTap, event); CFRelease(event); #elif defined(USE_X11) @@ -192,7 +192,7 @@ void toggleMouse(bool down, MMMouseButton button){ // mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0); INPUT mouseInput; - + mouseInput.type = INPUT_MOUSE; mouseInput.mi.dx = 0; mouseInput.mi.dy = 0; @@ -272,7 +272,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){ /* Make scroll magnitude negative if we're scrolling down. */ cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection; - event = CGEventCreateScrollWheelEvent(NULL, + event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); CGEventPost(kCGHIDEventTap, event); @@ -408,10 +408,10 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ double velo_x = 0.0, velo_y = 0.0; double distance; - while ((distance = + while ((distance = crude_hypot((double)pos.x - endPoint.x, (double)pos.y - endPoint.y) ) > 1.0) { - + double gravity = DEADBEEF_UNIFORM(5.0, 500.0); // double gravity = DEADBEEF_UNIFORM(lowSpeed, highSpeed); double veloDistance; @@ -432,7 +432,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ return false; } - moveMouse(pos); + moveMouse(MMSignedPointMake((int32_t)pos.x, (int32_t)pos.y)); /* Wait 1 - 3 milliseconds. */ microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed)); diff --git a/robotgo.go b/robotgo.go index 9a7d6e6..8e90d46 100644 --- a/robotgo.go +++ b/robotgo.go @@ -359,8 +359,8 @@ func MoveMouse(x, y int) { // Move move the mouse func Move(x, y int) { - cx := C.size_t(x) - cy := C.size_t(y) + cx := C.int32_t(x) + cy := C.int32_t(y) C.move_mouse(cx, cy) } @@ -373,8 +373,8 @@ func DragMouse(x, y int, args ...string) { func Drag(x, y int, args ...string) { var button C.MMMouseButton = C.LEFT_BUTTON - cx := C.size_t(x) - cy := C.size_t(y) + cx := C.int32_t(x) + cy := C.int32_t(y) if len(args) > 0 { button = CheckMouse(args[0]) From 772a43de443fb3740d27bea0bb2a97c74b2c8081 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 1 Dec 2019 08:46:04 -0400 Subject: [PATCH 3/7] rename type names make clearer --- base/types.h | 36 ++++++++++++++++++------------------ mouse/goMouse.h | 8 ++++---- mouse/mouse.h | 4 ++-- mouse/mouse_c.h | 10 +++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/base/types.h b/base/types.h index dbc8755..c9bae00 100644 --- a/base/types.h +++ b/base/types.h @@ -16,12 +16,12 @@ struct _MMPoint { typedef struct _MMPoint MMPoint; -struct _MMSignedPoint { +struct _MMPointInt32 { int32_t x; int32_t y; }; -typedef struct _MMSignedPoint MMSignedPoint; +typedef struct _MMPointInt32 MMPointInt32; struct _MMSize { size_t width; @@ -30,12 +30,12 @@ struct _MMSize { typedef struct _MMSize MMSize; -struct _MMSignedSize { +struct _MMSizeInt32 { int32_t w; int32_t h; }; -typedef struct _MMSignedSize MMSignedSize; +typedef struct _MMSizeInt32 MMSizeInt32; struct _MMRect { @@ -45,12 +45,12 @@ struct _MMRect { typedef struct _MMRect MMRect; -struct _MMSignedRect { - MMSignedPoint origin; - MMSignedSize size; +struct _MMRectInt32 { + MMPointInt32 origin; + MMSizeInt32 size; }; -typedef struct _MMSignedRect MMSignedRect; +typedef struct _MMRectInt32 MMRectInt32; H_INLINE MMPoint MMPointMake(size_t x, size_t y) { @@ -60,9 +60,9 @@ H_INLINE MMPoint MMPointMake(size_t x, size_t y) return point; } -H_INLINE MMSignedPoint MMSignedPointMake(int32_t x, int32_t y) +H_INLINE MMPointInt32 MMPointInt32Make(int32_t x, int32_t y) { - MMSignedPoint point; + MMPointInt32 point; point.x = x; point.y = y; return point; @@ -76,9 +76,9 @@ H_INLINE MMSize MMSizeMake(size_t width, size_t height) return size; } -H_INLINE MMSignedSize MMSignedSizeMake(int32_t w, int32_t h) +H_INLINE MMSizeInt32 MMSizeInt32Make(int32_t w, int32_t h) { - MMSignedSize size; + MMSizeInt32 size; size.w = w; size.h = h; return size; @@ -92,11 +92,11 @@ H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) return rect; } -H_INLINE MMSignedRect MMSignedRectMake(int32_t x, int32_t y, int32_t w, int32_t h) +H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h) { - MMSignedRect rect; - rect.origin = MMSignedPointMake(x, y); - rect.size = MMSignedSizeMake(w, h); + MMRectInt32 rect; + rect.origin = MMPointInt32Make(x, y); + rect.size = MMSizeInt32Make(w, h); return rect; } @@ -108,8 +108,8 @@ H_INLINE MMSignedRect MMSignedRectMake(int32_t x, int32_t y, int32_t w, int32_t #define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) #define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y) -#define CGPointFromMMSignedPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) -#define MMSignedPointFromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) +#define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) +#define MMPointInt32FromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) #elif defined(IS_WINDOWS) diff --git a/mouse/goMouse.h b/mouse/goMouse.h index 5125be2..1839e95 100644 --- a/mouse/goMouse.h +++ b/mouse/goMouse.h @@ -36,10 +36,10 @@ int mouseDelay = 10; // } int move_mouse(int32_t x, int32_t y){ - MMSignedPoint point; + MMPointInt32 point; // int x = 103; // int y = 104; - point = MMSignedPointMake(x, y); + point = MMPointInt32Make(x, y); moveMouse(point); return 0; @@ -51,8 +51,8 @@ int drag_mouse(int32_t x, int32_t y, MMMouseButton button){ // const size_t y = 20; // MMMouseButton button = LEFT_BUTTON; - MMSignedPoint point; - point = MMSignedPointMake(x, y); + MMPointInt32 point; + point = MMPointInt32Make(x, y); dragMouse(point, button); microsleep(mouseDelay); diff --git a/mouse/mouse.h b/mouse/mouse.h index 9603723..d0c7dac 100644 --- a/mouse/mouse.h +++ b/mouse/mouse.h @@ -65,13 +65,13 @@ typedef int MMMouseWheelDirection; /* Immediately moves the mouse to the given point on-screen. * It is up to the caller to ensure that this point is within the * screen boundaries. */ -void moveMouse(MMSignedPoint point); +void moveMouse(MMPointInt32 point); /* Like moveMouse, moves the mouse to the given point on-screen, but marks * the event as the mouse being dragged on platforms where it is supported. * It is up to the caller to ensure that this point is within the screen * boundaries. */ -void dragMouse(MMSignedPoint point, const MMMouseButton button); +void dragMouse(MMPointInt32 point, const MMMouseButton button); /* Smoothly moves the mouse from the current position to the given point. * deadbeef_srand() should be called before using this function. diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 32de2c7..f51a789 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -66,7 +66,7 @@ * @param event The mouse move event (by ref). * @param point The new mouse x and y. */ -void calculateDeltas(CGEventRef *event, MMSignedPoint point){ +void calculateDeltas(CGEventRef *event, MMPointInt32 point){ /** * The next few lines are a workaround for games not detecting mouse moves. * See this issue for more information: @@ -91,10 +91,10 @@ void calculateDeltas(CGEventRef *event, MMSignedPoint point){ * Move the mouse to a specific point. * @param point The coordinates to move the mouse to (x, y). */ -void moveMouse(MMSignedPoint point){ +void moveMouse(MMPointInt32 point){ #if defined(IS_MACOSX) CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, - CGPointFromMMSignedPoint(point), + CGPointFromMMPointInt32(point), kCGMouseButtonLeft); calculateDeltas(&move, point); @@ -129,7 +129,7 @@ void moveMouse(MMSignedPoint point){ #endif } -void dragMouse(MMSignedPoint point, const MMMouseButton button){ +void dragMouse(MMPointInt32 point, const MMMouseButton button){ #if defined(IS_MACOSX) const CGEventType dragType = MMMouseDragToCGEventType(button); CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType, @@ -432,7 +432,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ return false; } - moveMouse(MMSignedPointMake((int32_t)pos.x, (int32_t)pos.y)); + moveMouse(MMPointInt32Make((int32_t)pos.x, (int32_t)pos.y)); /* Wait 1 - 3 milliseconds. */ microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed)); From 0a4ae24aec5164d6a24247c4b5255554dfc4eea3 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 1 Dec 2019 09:22:03 -0400 Subject: [PATCH 4/7] add get screen size test code --- robotgo_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/robotgo_test.go b/robotgo_test.go index 33f73a7..e5e6e99 100644 --- a/robotgo_test.go +++ b/robotgo_test.go @@ -14,6 +14,7 @@ package robotgo import ( "fmt" + "log" "runtime" "testing" @@ -60,3 +61,8 @@ func TestScrollMouse(t *testing.T) { Scroll(210, 210) } + +func TestGetScreenSize(t *testing.T) { + x, y := GetScreenSize() + log.Println("GetScreenSize: ", x, y) +} From 29ae3d4fdf4338dc8feb746c47e2f5ebdb4c0e9d Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 1 Dec 2019 09:24:55 -0400 Subject: [PATCH 5/7] add screen and bitmap multiple screens support --- mouse/mouse_c.h | 4 ++-- robotgo.go | 26 +++++++++++++------------- screen/goScreen.h | 16 ++++++++-------- screen/screen.h | 4 ++-- screen/screen_c.h | 25 +++++++++++++++---------- screen/screengrab.h | 2 +- screen/screengrab_c.h | 30 +++++++++++++++--------------- 7 files changed, 56 insertions(+), 51 deletions(-) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index f51a789..4a70662 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -404,7 +404,7 @@ static double crude_hypot(double x, double y){ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ MMPoint pos = getMousePos(); - MMSize screenSize = getMainDisplaySize(); + MMSizeInt32 screenSize = getMainDisplaySize(); double velo_x = 0.0, velo_y = 0.0; double distance; @@ -428,7 +428,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ /* Make sure we are in the screen boundaries! * (Strange things will happen if we are not.) */ - if (pos.x >= screenSize.width || pos.y >= screenSize.height) { + if (pos.x >= screenSize.w || pos.y >= screenSize.h) { return false; } diff --git a/robotgo.go b/robotgo.go index 8e90d46..5089b90 100644 --- a/robotgo.go +++ b/robotgo.go @@ -184,8 +184,8 @@ func RgbToHex(r, g, b uint8) C.uint32_t { // GetPxColor get pixel color return C.MMRGBHex func GetPxColor(x, y int) C.MMRGBHex { - cx := C.size_t(x) - cy := C.size_t(y) + cx := C.int32_t(x) + cy := C.int32_t(y) color := C.get_px_color(cx, cy) return color @@ -193,8 +193,8 @@ func GetPxColor(x, y int) C.MMRGBHex { // GetPixelColor get pixel color return string func GetPixelColor(x, y int) string { - cx := C.size_t(x) - cy := C.size_t(y) + cx := C.int32_t(x) + cy := C.int32_t(y) color := C.get_pixel_color(cx, cy) gcolor := C.GoString(color) @@ -223,7 +223,7 @@ func ScaleY() int { func GetScreenSize() (int, int) { size := C.get_screen_size() // fmt.Println("...", size, size.width) - return int(size.width), int(size.height) + return int(size.w), int(size.h) } // Scale get the screen scale @@ -286,21 +286,21 @@ func GetXDisplayName() string { // // robotgo.CaptureScreen(x, y, w, h int) func CaptureScreen(args ...int) C.MMBitmapRef { - var x, y, w, h C.size_t + var x, y, w, h C.int32_t if len(args) > 3 { - x = C.size_t(args[0]) - y = C.size_t(args[1]) - w = C.size_t(args[2]) - h = C.size_t(args[3]) + x = C.int32_t(args[0]) + y = C.int32_t(args[1]) + w = C.int32_t(args[2]) + h = C.int32_t(args[3]) } else { x = 0 y = 0 // Get screen size. - var displaySize C.MMSize + var displaySize C.MMSizeInt32 displaySize = C.getMainDisplaySize() - w = displaySize.width - h = displaySize.height + w = displaySize.w + h = displaySize.h } bit := C.capture_screen(x, y, w, h) diff --git a/screen/goScreen.h b/screen/goScreen.h index 75b7c2f..648f73f 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -44,15 +44,15 @@ uint32_t color_rgb_to_hex(uint8_t r, uint8_t g, uint8_t b){ return RGB_TO_HEX(r, g, b); } -MMRGBHex get_px_color(size_t x, size_t y){ +MMRGBHex get_px_color(int32_t x, int32_t y){ MMBitmapRef bitmap; MMRGBHex color; - if (!pointVisibleOnMainDisplay(MMPointMake(x, y))){ + if (!pointVisibleOnMainDisplay(MMPointInt32Make(x, y))){ return color; } - bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1)); + bitmap = copyMMBitmapFromDisplayInRect(MMRectInt32Make(x, y, 1, 1)); // bitmap = MMRectMake(x, y, 1, 1); color = MMRGBHexAtPoint(bitmap, 0, 0); @@ -61,16 +61,16 @@ MMRGBHex get_px_color(size_t x, size_t y){ return color; } -char* get_pixel_color(size_t x, size_t y){ +char* get_pixel_color(int32_t x, int32_t y){ MMRGBHex color = get_px_color(x, y); char* s = pad_hex(color); return s; } -MMSize get_screen_size(){ +MMSizeInt32 get_screen_size(){ // Get display size. - MMSize displaySize = getMainDisplaySize(); + MMSizeInt32 displaySize = getMainDisplaySize(); return displaySize; } @@ -96,7 +96,7 @@ char* get_XDisplay_name(){ } // capture_screen capture screen -MMBitmapRef capture_screen(size_t x, size_t y, size_t w, size_t h){ +MMBitmapRef capture_screen(int32_t x, int32_t y, int32_t w, int32_t h){ // if (){ // x = 0; // y = 0; @@ -105,7 +105,7 @@ MMBitmapRef capture_screen(size_t x, size_t y, size_t w, size_t h){ // w = displaySize.width; // h = displaySize.height; // } - MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h)); + MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectInt32Make(x, y, w, h)); // printf("%s\n", bitmap); return bitmap; } diff --git a/screen/screen.h b/screen/screen.h index dc00bf4..9cc9887 100644 --- a/screen/screen.h +++ b/screen/screen.h @@ -16,11 +16,11 @@ extern "C" #endif /* Returns the size of the main display. */ -MMSize getMainDisplaySize(void); +MMSizeInt32 getMainDisplaySize(void); /* Convenience function that returns whether the given point is in the bounds * of the main screen. */ -bool pointVisibleOnMainDisplay(MMPoint point); +bool pointVisibleOnMainDisplay(MMPointInt32 point); #ifdef __cplusplus } diff --git a/screen/screen_c.h b/screen/screen_c.h index 2440a14..442292b 100644 --- a/screen/screen_c.h +++ b/screen/screen_c.h @@ -8,24 +8,29 @@ // #include "../base/xdisplay_c.h" #endif -MMSize getMainDisplaySize(void){ +MMSizeInt32 getMainDisplaySize(void){ #if defined(IS_MACOSX) CGDirectDisplayID displayID = CGMainDisplayID(); - return MMSizeMake(CGDisplayPixelsWide(displayID), - CGDisplayPixelsHigh(displayID)); + return MMSizeInt32Make((int32_t)CGDisplayPixelsWide(displayID), + (int32_t)CGDisplayPixelsHigh(displayID)); #elif defined(USE_X11) Display *display = XGetMainDisplay(); const int screen = DefaultScreen(display); - return MMSizeMake((size_t)DisplayWidth(display, screen), - (size_t)DisplayHeight(display, screen)); + return MMSizeInt32Make((int32_t)DisplayWidth(display, screen), + (int32_t)DisplayHeight(display, screen)); #elif defined(IS_WINDOWS) - return MMSizeMake((size_t)GetSystemMetrics(SM_CXSCREEN), - (size_t)GetSystemMetrics(SM_CYSCREEN)); + if (GetSystemMetrics(SM_CMONITORS) == 1) { + return MMSizeInt32Make((int32_t)GetSystemMetrics(SM_CXSCREEN), + (int32_t)GetSystemMetrics(SM_CYSCREEN)); + } else { + return MMSizeInt32Make((int32_t)GetSystemMetrics(SM_CXVIRTUALSCREEN), + (int32_t)GetSystemMetrics(SM_CYVIRTUALSCREEN)); + } #endif } -bool pointVisibleOnMainDisplay(MMPoint point){ - MMSize displaySize = getMainDisplaySize(); - return point.x < displaySize.width && point.y < displaySize.height; +bool pointVisibleOnMainDisplay(MMPointInt32 point){ + MMSizeInt32 displaySize = getMainDisplaySize(); + return point.x < displaySize.w && point.y < displaySize.h; } diff --git a/screen/screengrab.h b/screen/screengrab.h index a4a4b99..b40badd 100644 --- a/screen/screengrab.h +++ b/screen/screengrab.h @@ -12,7 +12,7 @@ extern "C" /* Returns a raw bitmap of screengrab of the display (to be destroyed()'d by * caller), or NULL on error. */ -MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect); +MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect); #ifdef __cplusplus } diff --git a/screen/screengrab_c.h b/screen/screengrab_c.h index 148b8d4..358f6a3 100644 --- a/screen/screengrab_c.h +++ b/screen/screengrab_c.h @@ -17,7 +17,7 @@ #include #endif -MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ +MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect){ #if defined(IS_MACOSX) MMBitmapRef bitmap = NULL; @@ -29,8 +29,8 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(rect.origin.x, rect.origin.y, - rect.size.width, - rect.size.height)); + rect.size.w, + rect.size.h)); if (!image) { return NULL; } @@ -63,15 +63,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ XDefaultRootWindow(display), (int)rect.origin.x, (int)rect.origin.y, - (unsigned int)rect.size.width, - (unsigned int)rect.size.height, + (unsigned int)rect.size.w, + (unsigned int)rect.size.h, AllPlanes, ZPixmap); XCloseDisplay(display); if (image == NULL) return NULL; bitmap = createMMBitmap((uint8_t *)image->data, - rect.size.width, - rect.size.height, + rect.size.w, + rect.size.h, (size_t)image->bytes_per_line, (uint8_t)image->bits_per_pixel, (uint8_t)image->bits_per_pixel / 8); @@ -89,12 +89,12 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ /* Initialize bitmap info. */ bi.bmiHeader.biSize = sizeof(bi.bmiHeader); - bi.bmiHeader.biWidth = (long)rect.size.width; - bi.bmiHeader.biHeight = -(long)rect.size.height; /* Non-cartesian, please */ + bi.bmiHeader.biWidth = (long)rect.size.w; + bi.bmiHeader.biHeight = -(long)rect.size.h; /* Non-cartesian, please */ bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; - bi.bmiHeader.biSizeImage = (DWORD)(4 * rect.size.width * rect.size.height); + bi.bmiHeader.biSizeImage = (DWORD)(4 * rect.size.w * rect.size.h); bi.bmiHeader.biXPelsPerMeter = 0; bi.bmiHeader.biYPelsPerMeter = 0; bi.bmiHeader.biClrUsed = 0; @@ -112,8 +112,8 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ !BitBlt(screenMem, (int)0, (int)0, - (int)rect.size.width, - (int)rect.size.height, + (int)rect.size.w, + (int)rect.size.h, screen, rect.origin.x, rect.origin.y, @@ -128,9 +128,9 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){ } bitmap = createMMBitmap(NULL, - rect.size.width, - rect.size.height, - 4 * rect.size.width, + rect.size.w, + rect.size.h, + 4 * rect.size.w, (uint8_t)bi.bmiHeader.biBitCount, 4); From 7affc721806ae04ee4f7604aef9f5b7347d6d957 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 1 Dec 2019 09:42:29 -0400 Subject: [PATCH 6/7] update types.h code and fixed bug --- base/types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/types.h b/base/types.h index c9bae00..4b88a1d 100644 --- a/base/types.h +++ b/base/types.h @@ -109,11 +109,12 @@ H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h) #define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y) #define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) -#define MMPointInt32FromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) +#define MMPointInt32FromCGPoint(p) MMPointInt32Make((int32_t)(p).x, (int32_t)(p).y) #elif defined(IS_WINDOWS) #define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y) +#define MMPointInt32FromPOINT(p) MMPointInt32Make((int32_t)p.x, (int32_t)p.y) #endif From a9655c12307643fd29fc7f2f49d3a1403afe1c82 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 1 Dec 2019 09:43:53 -0400 Subject: [PATCH 7/7] add getMousePos() multiple screens support --- mouse/goMouse.h | 4 ++-- mouse/mouse.h | 2 +- mouse/mouse_c.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mouse/goMouse.h b/mouse/goMouse.h index 1839e95..af7e663 100644 --- a/mouse/goMouse.h +++ b/mouse/goMouse.h @@ -70,8 +70,8 @@ bool move_mouse_smooth(size_t x, size_t y, double lowSpeed, return cbool; } -MMPoint get_mouse_pos(){ - MMPoint pos = getMousePos(); +MMPointInt32 get_mouse_pos(){ + MMPointInt32 pos = getMousePos(); // Return object with .x and .y. // printf("%zu\n%zu\n", pos.x, pos.y ); diff --git a/mouse/mouse.h b/mouse/mouse.h index d0c7dac..4438f2d 100644 --- a/mouse/mouse.h +++ b/mouse/mouse.h @@ -82,7 +82,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed); // bool smoothlyMoveMouse(MMPoint point); /* Returns the coordinates of the mouse on the current screen. */ -MMPoint getMousePos(void); +MMPointInt32 getMousePos(void); /* Holds down or releases the mouse with the given button in the current * position. */ diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 4a70662..5e5194b 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -144,13 +144,13 @@ void dragMouse(MMPointInt32 point, const MMMouseButton button){ #endif } -MMPoint getMousePos(){ +MMPointInt32 getMousePos(){ #if defined(IS_MACOSX) CGEventRef event = CGEventCreate(NULL); CGPoint point = CGEventGetLocation(event); CFRelease(event); - return MMPointFromCGPoint(point); + return MMPointInt32FromCGPoint(point); #elif defined(USE_X11) int x, y; /* This is all we care about. Seriously. */ Window garb1, garb2; /* Why you can't specify NULL as a parameter */ @@ -161,12 +161,12 @@ MMPoint getMousePos(){ XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2, &x, &y, &garb_x, &garb_y, &more_garbage); - return MMPointMake(x, y); + return MMPointInt32Make(x, y); #elif defined(IS_WINDOWS) POINT point; GetCursorPos(&point); - return MMPointFromPOINT(point); + return MMPointInt32FromPOINT(point); #endif } @@ -403,7 +403,7 @@ static double crude_hypot(double x, double y){ } bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){ - MMPoint pos = getMousePos(); + MMPointInt32 pos = getMousePos(); MMSizeInt32 screenSize = getMainDisplaySize(); double velo_x = 0.0, velo_y = 0.0; double distance;