diff --git a/example.py b/example.py index e12640d..075396d 100644 --- a/example.py +++ b/example.py @@ -1,8 +1,13 @@ from py_xdotool import * from time import sleep +print getactivewindow() +print search(name="System Monitor") +print search(name="System Monitor", onlyvisible=True)[0].get_name() +''' mousemove(0, 0) sleep(1) click_at(100, 100, 3) sleep(1) click_at(500, 100, 1) +''' diff --git a/py_xdotool.py b/py_xdotool.py index 8cc177f..7e33e45 100644 --- a/py_xdotool.py +++ b/py_xdotool.py @@ -1,5 +1,57 @@ from subprocess import Popen, PIPE +class Window: + def __init__(self, wid): + assert type(wid) == int + self.wid = wid + + def get_wid(self): + return self.wid + + def get_pid(self): + c = "getwindowpid %d" % self.wid + return int(run_command(c)) + + def get_name(self): + c = "getwindowname %d" % self.wid + return run_command(c) + + def activate(self): + c = "windowactivate %d" % self.wid + return run_command(c) + + def focus(self): + c = "windowfocus %d" % self.wid + return run_command(c) + +def getactivewindow(): + c = "getactivewindow" + wid = int(run_command(c)) + return Window(wid) + +def get_windows(wids): + windows = [] + for wid in wids: + windows.append(Window(wid)) + return windows + +def search(**kwargs): + c = "search" + noargs = ["onlyvisible", "class", "classname", "all", "any", "sync"] + for arg in noargs: + if arg in kwargs: + if kwargs[arg]: + c += " --%s" % arg + if "name" in kwargs: + c += ' --name "%s"' % kwargs['name'] + if "pid" in kwargs: + c += " --pid %s" % kwargs['pid'] + str_wids = run_command(c).split() + wids = [] + for str_wid in str_wids: + wids.append(int(str_wid)) + return get_windows(wids) + def mousemove(x, y): c = "mousemove %d %d" % (x, y) return run_command(c)