Compare commits

...

9 Commits

Author SHA1 Message Date
Sakishum
4f43d5cfb0
Merge 9aa4059a31 into 57b5e5bca2 2025-04-24 12:16:31 +00:00
Evans
57b5e5bca2
Merge pull request #720 from go-vgo/bitmap-pr
Some checks failed
Go / test (macOS-latest) (push) Has been cancelled
Go / test (windows-latest) (push) Has been cancelled
Update: update import
2025-04-19 12:56:42 -07:00
vcaesar
8031f7f526 Update: update import
Some checks failed
Go / test (macOS-latest) (push) Has been cancelled
Go / test (windows-latest) (push) Has been cancelled
2025-04-19 12:54:47 -07:00
Evans
36bc85ad19
Merge pull request #719 from go-vgo/bitmap-pr
Some checks are pending
Go / test (macOS-latest) (push) Waiting to run
Go / test (windows-latest) (push) Waiting to run
Fix: fixed mac os version min required #698
2025-04-19 10:06:37 -07:00
vcaesar
5fc2bd4c73 Fix: fixed mac os version min required #698
Some checks are pending
Go / test (macOS-latest) (push) Waiting to run
Go / test (windows-latest) (push) Waiting to run
2025-04-19 10:05:01 -07:00
saki.shen
9aa4059a31 [EDIT] By Saki, replace _AXUIElementGetWindow with AXUIElementCopyAttributeValue 2024-03-19 17:01:07 +08:00
saki.shen
31ddf1a959 [EDIT] By Saki, fixed bug of previous definition 2024-03-19 16:46:34 +08:00
saki.shen
de95edb1a8 [EDIT] By Saki, 去除 _AXUIElementGetWindow 的调用 2024-03-19 16:41:19 +08:00
saki.shen
df394a94b8 [EDIT] By Saki, 去除 robotgo.go 的 window/goWindow.h 2024-03-19 16:16:39 +08:00
8 changed files with 51 additions and 14 deletions

View File

@ -1,5 +1,5 @@
# FROM golang:1.10.1 # FROM golang:1.10.1
FROM golang:1.23.2-stretch AS build FROM golang:1.24.2-stretch AS build
# FROM govgo/go:1.11.1 # FROM govgo/go:1.11.1
RUN apt update && apt install -y --no-install-recommends \ RUN apt update && apt install -y --no-install-recommends \

2
go.mod
View File

@ -23,13 +23,13 @@ require (
github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/jezek/xgb v1.1.1 // indirect github.com/jezek/xgb v1.1.1 // indirect
github.com/kbinani/screenshot v0.0.0-20250118074034-a3924b7bbc8c
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect github.com/tklauser/numcpus v0.9.0 // indirect
github.com/vcaesar/screenshot v0.11.0
github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/exp v0.0.0-20250215185904-eff6e970281f // indirect golang.org/x/exp v0.0.0-20250215185904-eff6e970281f // indirect
golang.org/x/image v0.24.0 // indirect golang.org/x/image v0.24.0 // indirect

4
go.sum
View File

@ -17,8 +17,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4= github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/kbinani/screenshot v0.0.0-20250118074034-a3924b7bbc8c h1:1IlzDla/ZATV/FsRn1ETf7ir91PHS2mrd4VMunEtd9k=
github.com/kbinani/screenshot v0.0.0-20250118074034-a3924b7bbc8c/go.mod h1:Pmpz2BLf55auQZ67u3rvyI2vAQvNetkK/4zYUmpauZQ=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc= github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
@ -56,6 +54,8 @@ github.com/vcaesar/imgo v0.40.2 h1:5GWScRLdBCMtO1v2I1bs+ZmDLZFINxYSMZ+mtUw5qPM=
github.com/vcaesar/imgo v0.40.2/go.mod h1:MVCl+FxHI2gTgmiHoi0n5xNCbYcfv9SVtdEOUC92+eo= github.com/vcaesar/imgo v0.40.2/go.mod h1:MVCl+FxHI2gTgmiHoi0n5xNCbYcfv9SVtdEOUC92+eo=
github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw= github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw=
github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ= github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ=
github.com/vcaesar/screenshot v0.11.0 h1:ULNC6tTye6oNzleuqskzTMSjH8xonmuUIYfYjlYAM3g=
github.com/vcaesar/screenshot v0.11.0/go.mod h1:wixTD3T2Sz3Oi6Hfl33CMcBffd3mLbT7WavfK2UrQcI=
github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4= github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4=
github.com/vcaesar/tt v0.20.1/go.mod h1:cH2+AwGAJm19Wa6xvEa+0r+sXDJBT0QgNQey6mwqLeU= github.com/vcaesar/tt v0.20.1/go.mod h1:cH2+AwGAJm19Wa6xvEa+0r+sXDJBT0QgNQey6mwqLeU=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=

View File

@ -31,10 +31,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 CoreFoundation -framework IOKit
#cgo darwin LDFLAGS: -framework Carbon -framework CoreFoundation #cgo darwin LDFLAGS: -framework Carbon -framework OpenGL
// //
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > 140400
#cgo darwin LDFLAGS: -framework ScreenCaptureKit #cgo darwin LDFLAGS: -framework ScreenCaptureKit
#endif #endif

View File

@ -13,7 +13,8 @@ package robotgo
import ( import (
"image" "image"
"github.com/kbinani/screenshot" // "github.com/kbinani/screenshot"
"github.com/vcaesar/screenshot"
) )
// GetDisplayBounds gets the display screen bounds // GetDisplayBounds gets the display screen bounds

View File

@ -15,7 +15,7 @@
#endif #endif
#include "screen_c.h" #include "screen_c.h"
#if defined(IS_MACOSX) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4 #if defined(IS_MACOSX) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > 140400
static CGImageRef capture15(CGDirectDisplayID id, CGRect diIntersectDisplayLocal, CGColorSpaceRef colorSpace) { static CGImageRef capture15(CGDirectDisplayID id, CGRect diIntersectDisplayLocal, CGColorSpaceRef colorSpace) {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
__block CGImageRef image1 = nil; __block CGImageRef image1 = nil;
@ -76,7 +76,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id,
} }
MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size; MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size;
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > 140400
CGColorSpaceRef color = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); CGColorSpaceRef color = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
CGImageRef image = capture15(displayID, CGRectMake(o.x, o.y, s.w, s.h), color); CGImageRef image = capture15(displayID, CGRectMake(o.x, o.y, s.w, s.h), color);
CGColorSpaceRelease(color); CGColorSpaceRelease(color);

View File

@ -42,7 +42,7 @@ typedef struct _Bounds Bounds;
static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef); static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
static CFStringRef* gkAXTrustedCheckOptionPrompt; static CFStringRef* gkAXTrustedCheckOptionPrompt;
AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out); //AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
static AXUIElementRef GetUIElement(CGWindowID win){ static AXUIElementRef GetUIElement(CGWindowID win){
intptr pid = 0; intptr pid = 0;
// double_t pid = 0; // double_t pid = 0;
@ -90,13 +90,25 @@ typedef struct _Bounds Bounds;
AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i); AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i);
CGWindowID temp = 0; CGWindowID temp = 0;
// Use undocumented API to get WindowID // Use undocumented API to get WindowID
_AXUIElementGetWindow(element, &temp); /*_AXUIElementGetWindow(element, &temp);
if (temp == win) { if (temp == win) {
// Retain element // Retain element
CFRetain(element); CFRetain(element);
result = element; result = element;
break; break;
}*/
CFTypeRef cfWindow = NULL;
if (AXUIElementCopyAttributeValue(element, kAXWindowAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
temp = *(CGWindowID*)CFDataGetBytePtr(cfWindow);
CFRelease(cfWindow);
if (temp == win) {
// Retain element
CFRetain(element);
result = element;
break;
}
} }
} }

View File

@ -366,12 +366,12 @@ MData get_active(void) {
AXUIElementRef focused = AXUIElementCreateApplication(pid); AXUIElementRef focused = AXUIElementCreateApplication(pid);
if (focused == NULL) { return result; } // Verify if (focused == NULL) { return result; } // Verify
AXUIElementRef element; /*AXUIElementRef element;
CGWindowID win = 0; CGWindowID win = 0;
// Retrieve the currently focused window // Retrieve the currently focused window
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element) if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element)
== kAXErrorSuccess && element) { == kAXErrorSuccess && element) {
// Use undocumented API to get WID // Use undocumented API to get WID
if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) { if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) {
// Manually set internals // Manually set internals
@ -383,7 +383,31 @@ MData get_active(void) {
} else { } else {
result.CgID = win; result.CgID = win;
result.AxID = element; result.AxID = element;
}*/
AXUIElementRef windowElement = NULL;
CGWindowID win = 0;
// Retrieve the currently focused window
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &windowElement) == kAXErrorSuccess && windowElement) {
// Use AXUIElementCopyAttributeValue to get parent window
CFTypeRef cfWindow = NULL;
if (AXUIElementCopyAttributeValue(windowElement, kAXParentAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
AXUIElementRef parentWindow = (AXUIElementRef)cfWindow;
if (AXUIElementCopyAttributeValue(parentWindow, kAXWindowAttribute, (CFTypeRef*)&win) == kAXErrorSuccess && win) {
// Manually set internals
result.CgID = win;
result.AxID = windowElement;
} else {
CFRelease(parentWindow);
}
}
CFRelease(windowElement);
} else {
result.CgID = 0;
result.AxID = NULL;
} }
CFRelease(focused); CFRelease(focused);
return result; return result;