zenity/internal/zencmd/window_darwin.go

37 lines
549 B
Go
Raw Normal View History

2022-06-28 09:25:19 -04:00
package zencmd
2022-06-09 08:35:02 -04:00
import (
"strconv"
2022-06-13 18:46:03 -04:00
"golang.org/x/sys/unix"
2022-06-09 08:35:02 -04:00
)
2022-06-28 09:25:19 -04:00
type any = interface{}
2022-06-09 08:35:02 -04:00
// ParseWindowId is internal.
func ParseWindowId(id string) any {
if pid, err := strconv.ParseUint(id, 0, 64); err == nil {
return int(pid)
}
return id
}
// GetParentWindowId is internal.
2022-06-16 20:55:02 -04:00
func GetParentWindowId(pid int) int {
2022-06-09 08:35:02 -04:00
for {
2022-06-13 18:46:03 -04:00
kinfo, err := unix.SysctlKinfoProc("kern.proc.pid", pid)
if err != nil {
return 0
}
ppid := kinfo.Eproc.Ppid
2022-06-09 08:35:02 -04:00
switch ppid {
case 0:
return 0
case 1:
return pid
default:
2022-06-13 18:46:03 -04:00
pid = int(ppid)
2022-06-09 08:35:02 -04:00
}
}
}