diff --git a/robotgo.go b/robotgo.go index e69a0a2..f03a9fd 100644 --- a/robotgo.go +++ b/robotgo.go @@ -1498,25 +1498,26 @@ func GetBHandle() int { return ghwnd } +func cgetTitle(hwnd, isHwnd int32) string { + title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd)) + gtitle := C.GoString(title) + + return gtitle +} + // GetTitle get the window title func GetTitle(args ...int32) string { if len(args) <= 0 { title := C.get_main_title() - gtittle := C.GoString(title) - return gtittle + gtitle := C.GoString(title) + return gtitle } - var hwnd, isHwnd int32 - if len(args) > 0 { - hwnd = args[0] - } if len(args) > 1 { - isHwnd = args[1] + return internalGetTitle(args[0], args[1]) } - title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd)) - gtittle := C.GoString(title) - return gtittle + return internalGetTitle(args[0]) } // GetPID get the process id diff --git a/robotgo_mac_win.go b/robotgo_mac_win.go index a4031fc..53d7541 100644 --- a/robotgo_mac_win.go +++ b/robotgo_mac_win.go @@ -22,6 +22,17 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) { return internalGetBounds(pid, hwnd) } +// internalGetTitle get the window title +func internalGetTitle(pid int32, args ...int32) string { + var isHwnd int32 + if len(args) > 0 { + isHwnd = args[0] + } + gtitle := cgetTitle(pid, isHwnd) + + return gtitle +} + // ActivePID active the window by PID, // // If args[0] > 0 on the Windows platform via a window handle to active diff --git a/robotgo_unix.go b/robotgo_unix.go index c5d3b54..a14a100 100644 --- a/robotgo_unix.go +++ b/robotgo_unix.go @@ -41,6 +41,24 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) { return internalGetBounds(int32(xid), hwnd) } +// internalGetTitle get the window title +func internalGetTitle(pid int32, args ...int) string { + var hwnd int + if len(args) > 0 { + hwnd = args[0] + + return cgetTitle(pid, hwnd) + } + + xid, err := GetXId(xu, pid) + if err != nil { + log.Println("GetXidFromPid errors is: ", err) + return "" + } + + return cgetTitle(int32(xid), hwnd) +} + // ActivePIDC active the window by PID, // If args[0] > 0 on the unix platform via a xid to active func ActivePIDC(pid int32, args ...int) {