forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window_switcher.py
41 lines (33 loc) · 1.73 KB
/
window_switcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""List and manage X11 windows.
Synopsis: <filter>"""
import subprocess
from collections import namedtuple
from shutil import which
from albertv0 import Item, ProcAction, iconLookup
Window = namedtuple("Window", ["wid", "desktop", "wm_class", "host", "wm_name"])
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Window Switcher"
__version__ = "1.4"
__author__ = "Ed Perez, Manuel Schneider"
__dependencies__ = ["wmctrl"]
if which("wmctrl") is None:
raise Exception("'wmctrl' is not in $PATH.")
def handleQuery(query):
stripped = query.string.strip().lower()
if stripped:
results = []
for line in subprocess.check_output(['wmctrl', '-l', '-x']).splitlines():
win = Window(*[token.decode() for token in line.split(None,4)])
if win.desktop != "-1" and stripped in win.wm_class.split('.')[0].lower():
results.append(Item(id="%s%s" % (__prettyname__, win.wm_class),
icon=iconLookup(win.wm_class.split('.')[0]),
text="%s - <i>Desktop %s</i>" % (win.wm_class.split('.')[-1].replace('-',' '), win.desktop),
subtext=win.wm_name,
actions=[ProcAction("Switch Window",
["wmctrl", '-i', '-a', win.wid] ),
ProcAction("Move window to this desktop",
["wmctrl", '-i', '-R', win.wid] ),
ProcAction("Close the window gracefully.",
["wmctrl", '-c', win.wid])]))
return results