mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-17 13:33:55 +00:00
Compare commits
10 Commits
db47cbf0b2
...
0d78012644
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0d78012644 | ||
![]() |
0de26ecee4 | ||
![]() |
c48e3d072c | ||
![]() |
b1ad7db6be | ||
![]() |
0110b85d40 | ||
![]() |
3e5b10f720 | ||
![]() |
cb51e2aa10 | ||
![]() |
85f2702683 | ||
![]() |
5b9871b063 | ||
![]() |
b201ab9f80 |
48
robotgo.go
48
robotgo.go
@ -33,6 +33,10 @@ package robotgo
|
|||||||
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations
|
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations
|
||||||
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit
|
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit
|
||||||
#cgo darwin LDFLAGS: -framework Carbon -framework CoreFoundation
|
#cgo darwin LDFLAGS: -framework Carbon -framework CoreFoundation
|
||||||
|
//
|
||||||
|
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4
|
||||||
|
#cgo darwin LDFLAGS: -framework ScreenCaptureKit
|
||||||
|
#endif
|
||||||
|
|
||||||
#cgo linux CFLAGS: -I/usr/src
|
#cgo linux CFLAGS: -I/usr/src
|
||||||
#cgo linux LDFLAGS: -L/usr/src -lm -lX11 -lXtst
|
#cgo linux LDFLAGS: -L/usr/src -lm -lX11 -lXtst
|
||||||
@ -86,6 +90,8 @@ type (
|
|||||||
CHex C.MMRGBHex
|
CHex C.MMRGBHex
|
||||||
// CBitmap define CBitmap as C.MMBitmapRef type
|
// CBitmap define CBitmap as C.MMBitmapRef type
|
||||||
CBitmap C.MMBitmapRef
|
CBitmap C.MMBitmapRef
|
||||||
|
// Handle define window Handle as C.MData type
|
||||||
|
Handle C.MData
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bitmap define the go Bitmap struct
|
// Bitmap define the go Bitmap struct
|
||||||
@ -453,6 +459,11 @@ func GetXDisplayName() string {
|
|||||||
return gname
|
return gname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseMainDisplay close the main X11 display
|
||||||
|
func CloseMainDisplay() {
|
||||||
|
C.close_main_display()
|
||||||
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF(),
|
// Deprecated: use the ScaledF(),
|
||||||
//
|
//
|
||||||
// ScaleX get the primary display horizontal DPI scale factor, drop
|
// ScaleX get the primary display horizontal DPI scale factor, drop
|
||||||
@ -866,12 +877,22 @@ func IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetActive set the window active
|
// SetActive set the window active
|
||||||
func SetActive(win C.MData) {
|
func SetActive(win Handle) {
|
||||||
|
SetActiveC(C.MData(win))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActiveC set the window active
|
||||||
|
func SetActiveC(win C.MData) {
|
||||||
C.set_active(win)
|
C.set_active(win)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetActive get the active window
|
// GetActive get the active window
|
||||||
func GetActive() C.MData {
|
func GetActive() Handle {
|
||||||
|
return Handle(GetActiveC())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetActiveC get the active window
|
||||||
|
func GetActiveC() C.MData {
|
||||||
mdata := C.get_active()
|
mdata := C.get_active()
|
||||||
// fmt.Println("active----", mdata)
|
// fmt.Println("active----", mdata)
|
||||||
return mdata
|
return mdata
|
||||||
@ -945,8 +966,29 @@ func SetHandlePid(pid int, args ...int) {
|
|||||||
C.set_handle_pid_mData(C.uintptr(pid), C.int8_t(isPid))
|
C.set_handle_pid_mData(C.uintptr(pid), C.int8_t(isPid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHandById get handle mdata by id
|
||||||
|
func GetHandById(id int, args ...int) Handle {
|
||||||
|
isPid := 1
|
||||||
|
if len(args) > 0 {
|
||||||
|
isPid = args[0]
|
||||||
|
}
|
||||||
|
return GetHandByPid(id, isPid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHandByPid get handle mdata by pid
|
||||||
|
func GetHandByPid(pid int, args ...int) Handle {
|
||||||
|
return Handle(GetHandByPidC(pid, args...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: use the GetHandByPid(),
|
||||||
|
//
|
||||||
// GetHandPid get handle mdata by pid
|
// GetHandPid get handle mdata by pid
|
||||||
func GetHandPid(pid int, args ...int) C.MData {
|
func GetHandPid(pid int, args ...int) Handle {
|
||||||
|
return GetHandByPid(pid, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHandByPidC get handle mdata by pid
|
||||||
|
func GetHandByPidC(pid int, args ...int) C.MData {
|
||||||
var isPid int
|
var isPid int
|
||||||
if len(args) > 0 || NotPid {
|
if len(args) > 0 || NotPid {
|
||||||
isPid = 1
|
isPid = 1
|
||||||
|
@ -79,6 +79,14 @@ char* get_XDisplay_name() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void close_main_display() {
|
||||||
|
#if defined(USE_X11)
|
||||||
|
XCloseMainDisplay();
|
||||||
|
#else
|
||||||
|
//
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t get_num_displays() {
|
uint32_t get_num_displays() {
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#include <ScreenCaptureKit/ScreenCaptureKit.h>
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
@ -13,6 +14,52 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(IS_MACOSX) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4
|
||||||
|
static CGImageRef capture15(CGDirectDisplayID id, CGRect diIntersectDisplayLocal, CGColorSpaceRef colorSpace) {
|
||||||
|
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||||
|
__block CGImageRef image1 = nil;
|
||||||
|
[SCShareableContent getShareableContentWithCompletionHandler:^(SCShareableContent* content, NSError* error) {
|
||||||
|
@autoreleasepool {
|
||||||
|
if (error) {
|
||||||
|
dispatch_semaphore_signal(semaphore);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCDisplay* target = nil;
|
||||||
|
for (SCDisplay *display in content.displays) {
|
||||||
|
if (display.displayID == id) {
|
||||||
|
target = display;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!target) {
|
||||||
|
dispatch_semaphore_signal(semaphore);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCContentFilter* filter = [[SCContentFilter alloc] initWithDisplay:target excludingWindows:@[]];
|
||||||
|
SCStreamConfiguration* config = [[SCStreamConfiguration alloc] init];
|
||||||
|
config.sourceRect = diIntersectDisplayLocal;
|
||||||
|
config.width = diIntersectDisplayLocal.size.width;
|
||||||
|
config.height = diIntersectDisplayLocal.size.height;
|
||||||
|
|
||||||
|
[SCScreenshotManager captureImageWithFilter:filter
|
||||||
|
configuration:config
|
||||||
|
completionHandler:^(CGImageRef img, NSError* error) {
|
||||||
|
if (!error) {
|
||||||
|
image1 = CGImageCreateCopyWithColorSpace(img, colorSpace);
|
||||||
|
}
|
||||||
|
dispatch_semaphore_signal(semaphore);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
||||||
|
dispatch_release(semaphore);
|
||||||
|
return image1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id, int8_t isPid) {
|
MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id, int8_t isPid) {
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
MMBitmapRef bitmap = NULL;
|
MMBitmapRef bitmap = NULL;
|
||||||
@ -25,9 +72,16 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size;
|
MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size;
|
||||||
CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(o.x, o.y, s.w, s.h));
|
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4
|
||||||
|
CGColorSpaceRef color = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
||||||
|
CGImageRef image = capture15(displayID, CGRectMake(o.x, o.y, s.w, s.h), color);
|
||||||
|
CGColorSpaceRelease(color);
|
||||||
|
#else
|
||||||
|
// This API is deprecated in macos 15, use ScreenCaptureKit's captureScreenshot
|
||||||
|
CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(o.x, o.y, s.w, s.h));
|
||||||
|
#endif
|
||||||
if (!image) { return NULL; }
|
if (!image) { return NULL; }
|
||||||
|
|
||||||
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(image));
|
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(image));
|
||||||
if (!imageData) { return NULL; }
|
if (!imageData) { return NULL; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user