mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-17 05:23:56 +00:00
Compare commits
4 Commits
3d622980f2
...
d377c69b1c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d377c69b1c | ||
![]() |
dd208c6dd1 | ||
![]() |
ae4390f607 | ||
![]() |
be5a13d7b3 |
@ -76,12 +76,25 @@ MMSizeInt32 getMainDisplaySize(void) {
|
||||
CGSize size = displayRect.size;
|
||||
return MMSizeInt32Make((int32_t)size.width, (int32_t)size.height);
|
||||
#elif defined(USE_X11)
|
||||
Display *display = XGetMainDisplay();
|
||||
const int screen = DefaultScreen(display);
|
||||
// Display *display = XGetMainDisplay();
|
||||
// const int screen = DefaultScreen(display);
|
||||
|
||||
return MMSizeInt32Make(
|
||||
(int32_t)DisplayWidth(display, screen),
|
||||
(int32_t)DisplayHeight(display, screen));
|
||||
// return MMSizeInt32Make(
|
||||
// (int32_t)DisplayWidth(display, screen),
|
||||
// (int32_t)DisplayHeight(display, screen));
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if (display == NULL) {
|
||||
return MMSizeInt32Make(0, 0); // Return an invalid size if unable to open display
|
||||
}
|
||||
|
||||
const int screen = DefaultScreen(display);
|
||||
MMSizeInt32 resolution = MMSizeInt32Make(
|
||||
(int32_t)DisplayWidth(display, screen),
|
||||
(int32_t)DisplayHeight(display, screen)
|
||||
);
|
||||
|
||||
XCloseDisplay(display);
|
||||
return resolution;
|
||||
#elif defined(IS_WINDOWS)
|
||||
return MMSizeInt32Make(
|
||||
(int32_t)GetSystemMetrics(SM_CXSCREEN),
|
||||
|
@ -24,33 +24,45 @@ Bounds get_bounds(uintptr pid, int8_t isPid){
|
||||
AXValueRef axp = NULL;
|
||||
AXValueRef axs = NULL;
|
||||
AXUIElementRef AxID = AXUIElementCreateApplication(pid);
|
||||
AXUIElementRef AxWin = NULL;
|
||||
|
||||
// Get the window from the application
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXFocusedWindowAttribute, (CFTypeRef *)&AxWin)
|
||||
!= kAXErrorSuccess || AxWin == NULL) {
|
||||
// If no focused window, try to get the main window
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXMainWindowAttribute, (CFTypeRef *)&AxWin)
|
||||
!= kAXErrorSuccess || AxWin == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the current point of the window
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
!= kAXErrorSuccess || axp == NULL){
|
||||
if (AXUIElementCopyAttributeValue(AxWin, kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
!= kAXErrorSuccess || axp == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Determine the current size of the window
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
!= kAXErrorSuccess || axs == NULL){
|
||||
if (AXUIElementCopyAttributeValue(AxWin, kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
!= kAXErrorSuccess || axs == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
CGPoint p; CGSize s;
|
||||
// Attempt to convert both values into atomic types
|
||||
if (AXValueGetValue(axp, kAXValueCGPointType, &p) &&
|
||||
AXValueGetValue(axs, kAXValueCGSizeType, &s)){
|
||||
AXValueGetValue(axs, kAXValueCGSizeType, &s)) {
|
||||
bounds.X = p.x;
|
||||
bounds.Y = p.y;
|
||||
bounds.W = s.width;
|
||||
bounds.H = s.height;
|
||||
}
|
||||
|
||||
// return bounds;
|
||||
exit:
|
||||
if (axp != NULL) { CFRelease(axp); }
|
||||
if (axs != NULL) { CFRelease(axs); }
|
||||
if (AxWin != NULL) { CFRelease(AxWin); }
|
||||
if (AxID != NULL) { CFRelease(AxID); }
|
||||
|
||||
return bounds;
|
||||
#elif defined(USE_X11)
|
||||
|
Loading…
Reference in New Issue
Block a user