Skip to content
Snippets Groups Projects
Commit e989b9f9 authored by James Vasile's avatar James Vasile
Browse files

Handle multiple targets

parent 1c12eafc
No related branches found
No related tags found
No related merge requests found
......@@ -340,12 +340,13 @@ class Windows(UserList):
print(f"get_closest_win_by_class: {classes}")
# Remove current window, if it's there
wins = []
for w in self.get_win_by_class(wm_class):
if VERBOSE:
print(f"Win by class {wm_class}:", w)
if skip_current and w.id == self.curr_win_id:
continue
wins.append(w)
for wm_class in classes:
for w in self.get_win_by_class(wm_class):
if VERBOSE:
print(f"Win by class {wm_class}:", w)
if skip_current and w.id == self.curr_win_id:
continue
wins.append(w)
desktop = self.curr_desktop
curr = [w for w in wins if w.desktop == desktop and w.id != self.curr_win_id]
......@@ -382,15 +383,19 @@ class Windows(UserList):
class Launcher():
env:dict[str,str] = {}
key = ''
target = ''
targets:list[str] = []
launch = ''
def __init__(self, key:str="", target:str="", launch:str="") -> None:
def __init__(self, key:str="", targets:Union[str,list[str]]=[], launch:str="") -> None:
self.key = key or self.key
self.target = target or self.target
self.target = self.target.split('.')[0] # x has the . and some more stuff. sway doesn't
if isinstance(targets, str):
targets = [targets]
self.targets = targets or self.targets
for target in self.targets:
if "." in target:
self.targets.extend(target.split("."))
self.launch = launch or self.launch
def __repr__(self) -> str:
return (f"Launcher({self.key}, {self.target}, {self.launch})")
return (f"Launcher({self.key}, {self.targets}, {self.launch})")
def __str__(self) -> str:
return self.__repr__()
class Launchers(dict[str, Launcher]):
......@@ -511,24 +516,13 @@ def main(args):
runner.run()
# Non-window launcher. Only launch if not already launched.
if '/' in launcher.target:
if '/' in launcher.targets[0]:
runner = Runner(launcher.target)
runner.already_exit(full=True)
runner.run(launcher.launch)
# try:
# subprocess.check_call(f"pgrep -fxa {launcher.target}", shell=True)
# Log().write("Already running.")
# except subprocess.CalledProcessError:
# parts = shlex.split(launcher.launch)
# subprocess.Popen(launcher.launch,
# stdout=open(f'/tmp/launch/{args[1]}.stdout.log', 'a'),
# stderr=open(f'/tmp/launch/{args[1]}.stderr.log', 'a'),
# preexec_fn=os.setpgrp,
# )
sys.exit()
win = wins.get_closest_win_by_class(launcher.target, skip_current=False)
win = wins.get_closest_win_by_class(launcher.targets, skip_current=False)
if VERBOSE:
sys.stdout.write("Closest windows by class: ")
pp(win)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment