update linux default func use

This commit is contained in:
vcaesar 2018-07-10 20:54:35 +08:00
parent 2a6299df59
commit f0c84a23d3
2 changed files with 17 additions and 5 deletions

View File

@ -4,11 +4,12 @@ package robotgo
// ActivePID active the window by PID,
// If args[0] > 0 on the Windows platform via a window handle to active
func ActivePID(pid int32, args ...int) {
func ActivePID(pid int32, args ...int) error {
var hwnd int
if len(args) > 0 {
hwnd = args[0]
}
internalActive(pid, hwnd)
return nil
}

View File

@ -4,6 +4,7 @@ package robotgo
import (
"errors"
"log"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
@ -12,9 +13,9 @@ import (
var xu *xgbutil.XUtil
// ActivePID active the window by PID,
// ActivePIDC active the window by PID,
// If args[0] > 0 on the unix platform via a xid to active
func ActivePID(pid int32, args ...int) {
func ActivePIDC(pid int32, args ...int) {
var hwnd int
if len(args) > 0 {
hwnd = args[0]
@ -23,16 +24,26 @@ func ActivePID(pid int32, args ...int) {
return
}
if xu == nil {
var err error
xu, err = xgbutil.NewConn()
if err != nil {
log.Println("xgbutil.NewConn errors is: ", err)
return
}
}
xid, err := getXidFromPid(xu, pid)
if err != nil {
log.Println("getXidFromPid errors is: ", err)
return
}
internalActive(int32(xid), hwnd)
}
// ActivePIDXgb makes the window of the PID the active window
func ActivePIDXgb(pid int32) error {
// ActivePID makes the window of the PID the active window
func ActivePID(pid int32) error {
if xu == nil {
var err error
xu, err = xgbutil.NewConn()