Skip to content
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

linux: Fix process PID to window mapping for X11 #22348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xtimsb
Copy link
Contributor

@0xtimsb 0xtimsb commented Dec 22, 2024

Closes #22326

This PR adds process PID information to window created by X11, so that window manager can identify which process this window belongs to. Without this property, the window manager would have no reliable way to know which process created this window.

In original issue, robotgo throws error on x, y, w, h := robotgo.GetBounds(pid) this method. If we go deeper into the source code of robotgo, it calls GetXidFromPid which goes through all windows, and tries to check for provided pid. Hence, when it tries to do that for Zed, it fails and returns 0, err to caller.

// Robotgo source code trying to look through all windows and query pid

// GetXidFromPid get the xid from pid
func GetXidFromPid(xu *xgbutil.XUtil, pid int) (xproto.Window, error) {
	windows, err := ewmh.ClientListGet(xu)
	if err != nil {
		return 0, err
	}

	for _, window := range windows {
		wmPid, err := ewmh.WmPidGet(xu, window)
		if err != nil {
			return 0, err
		}

		if uint(pid) == wmPid {
			return window, nil
		}
	}

	return 0, errors.New("failed to find a window with a matching pid.")
}

Querying for pid for active Zed window:

Before:

tims@lemon ~/w/go-repro [127]> xprop -root _NET_ACTIVE_WINDOW
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x4e00002
tims@lemon ~/w/go-repro> xprop -id 0x4e00002 _NET_WM_PID
_NET_WM_PID:  not found.

After:

tims@lemon ~/w/go-repro> xprop -root _NET_ACTIVE_WINDOW
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x4e00002
tims@lemon ~/w/go-repro> xprop -id 0x4e00002 _NET_WM_PID
_NET_WM_PID(CARDINAL) = 103548
tims@lemon ~/w/go-repro>

Correct zed process PID (below) assosiated with zed window (shown above):
image

Release Notes:

  • Fix robotgo failing when Zed window is open on Linux

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After running zed on Ubuntu, subsequent programs that start cannot obtain the name 'NTED_WM-PID'
1 participant