Compare commits

...

4 Commits

Author SHA1 Message Date
Blink-A
d377c69b1c
Merge be5a13d7b3 into dd208c6dd1 2025-06-15 13:10:05 -07:00
Evans
dd208c6dd1
Merge pull request #730 from cnwangjie/fix-window-mac
Some checks failed
Go / test (macOS-latest) (push) Has been cancelled
Go / test (windows-latest) (push) Has been cancelled
Fix: use window ref instead of app ref to get bounds on macos
2025-06-15 12:16:48 -07:00
Wang Jie
ae4390f607 Fix: use window ref instead of app ref to get bounds on macos 2025-06-15 00:05:35 +08:00
Blink-A
be5a13d7b3
Update screen_c.h 2024-08-18 16:34:02 +08:00
2 changed files with 41 additions and 16 deletions

View File

@ -76,12 +76,25 @@ MMSizeInt32 getMainDisplaySize(void) {
CGSize size = displayRect.size; CGSize size = displayRect.size;
return MMSizeInt32Make((int32_t)size.width, (int32_t)size.height); return MMSizeInt32Make((int32_t)size.width, (int32_t)size.height);
#elif defined(USE_X11) #elif defined(USE_X11)
Display *display = XGetMainDisplay(); // Display *display = XGetMainDisplay();
const int screen = DefaultScreen(display); // const int screen = DefaultScreen(display);
return MMSizeInt32Make( // 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)DisplayWidth(display, screen),
(int32_t)DisplayHeight(display, screen)); (int32_t)DisplayHeight(display, screen)
);
XCloseDisplay(display);
return resolution;
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
return MMSizeInt32Make( return MMSizeInt32Make(
(int32_t)GetSystemMetrics(SM_CXSCREEN), (int32_t)GetSystemMetrics(SM_CXSCREEN),

View File

@ -24,15 +24,26 @@ Bounds get_bounds(uintptr pid, int8_t isPid){
AXValueRef axp = NULL; AXValueRef axp = NULL;
AXValueRef axs = NULL; AXValueRef axs = NULL;
AXUIElementRef AxID = AXUIElementCreateApplication(pid); 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 // Determine the current point of the window
if (AXUIElementCopyAttributeValue(AxID, kAXPositionAttribute, (CFTypeRef*) &axp) if (AXUIElementCopyAttributeValue(AxWin, kAXPositionAttribute, (CFTypeRef*) &axp)
!= kAXErrorSuccess || axp == NULL) { != kAXErrorSuccess || axp == NULL) {
goto exit; goto exit;
} }
// Determine the current size of the window // Determine the current size of the window
if (AXUIElementCopyAttributeValue(AxID, kAXSizeAttribute, (CFTypeRef*) &axs) if (AXUIElementCopyAttributeValue(AxWin, kAXSizeAttribute, (CFTypeRef*) &axs)
!= kAXErrorSuccess || axs == NULL) { != kAXErrorSuccess || axs == NULL) {
goto exit; goto exit;
} }
@ -47,10 +58,11 @@ Bounds get_bounds(uintptr pid, int8_t isPid){
bounds.H = s.height; bounds.H = s.height;
} }
// return bounds;
exit: exit:
if (axp != NULL) { CFRelease(axp); } if (axp != NULL) { CFRelease(axp); }
if (axs != NULL) { CFRelease(axs); } if (axs != NULL) { CFRelease(axs); }
if (AxWin != NULL) { CFRelease(AxWin); }
if (AxID != NULL) { CFRelease(AxID); }
return bounds; return bounds;
#elif defined(USE_X11) #elif defined(USE_X11)