Skip to content

Fix: use window ref instead of app ref to get bounds on macos #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025

Conversation

cnwangjie
Copy link
Contributor

This PR fixes the problem mentioned in the issue #210.

The problem is AXUIElementCopyAttributeValue with kAXPositionAttribute should pass a window reference in most cases.

I modified it to try to get either the focused window or the main window to ensure compatibility with multi-window scenarios without modifying the API.

Following is the test code:

package main

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

func main() {
	pid := 35866

	x, y, w, h := robotgo.GetBounds(pid)
	fmt.Printf("Window bounds: x=%d, y=%d, width=%d, height=%d\n", x, y, w, h)
}

    

Before this PR, its output was like

Window bounds: x=1933312, y=1932168, width=19, height=-1177118969

After fix

Window bounds: x=980, y=58, width=1024, height=604

@cnwangjie cnwangjie requested a review from vcaesar as a code owner June 14, 2025 16:35
@CLAassistant
Copy link

CLAassistant commented Jun 14, 2025

CLA assistant check
All committers have signed the CLA.

@vcaesar vcaesar merged commit dd208c6 into go-vgo:master Jun 15, 2025
2 checks passed
@vcaesar vcaesar added this to the v1.0.0 milestone Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants