Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions SwitchAppWindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import re
import subprocess

from albertv0 import *

__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Switch App Window"
__version__ = "1.0"
__trigger__ = "w "
__author__ = "Markus Geiger <mg@evolution515.net>"
__id__ = "window"
__dependencies__ = []

iconPath = iconLookup("go-next")

def handleQuery(query):
stripped = query.string.strip()
if not query.isTriggered and not stripped:
return

results = []
process = subprocess.Popen(['wmctrl', '-l'], stdout=subprocess.PIPE, encoding='utf8')

output, error = process.communicate()

patt = re.compile(r'^(\w+)\s+(\d+)\s+([^\s]+)\s+(.+)$')
window_re = re.compile(r'^(.+)\s+-\s+(.+)$')

for line in output.split('\n'):
match = patt.match(line)
if not match:
continue

window_id = match.group(1)
fulltitle = match.group(4)
if not query.string.lower() in fulltitle.lower():
continue

titlematch = window_re.match(fulltitle)

if titlematch:
windowtitle = titlematch.group(1)
program_title = titlematch.group(2)
else:
program_title = fulltitle
windowtitle = fulltitle

results.append(
Item(
id="%s_%s" % (__id__, window_id),
icon=iconPath,
text=program_title,
subtext=windowtitle,
completion=query.rawString,
actions=[
ProcAction("Focus", ["wmctrl", "-ia", window_id]),
ProcAction("Close", ["wmctrl", "-ic", window_id])
]
)
)
return results