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

Make Windows a UserList

parent 33865141
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ Run-or-raise launcher
"""
import argparse
from collections import UserList
import i3ipc # would that we could make this optional
import os
from pathlib import Path
......@@ -265,11 +266,12 @@ class Sway():
print(ret)
return ret
class Windows:
class Windows(UserList):
wmctrl = None
"Model a list of windows, regardless of whether they're xwindows or wayland windows"
def __init__(self):
self.windows = []
UserList.__init__(self)
self.data = [] # UserList stores data here, but we just access via self
if SWAY:
self.sway = Sway()
......@@ -278,7 +280,7 @@ class Windows:
self.curr_desktop = self.curr_win.desktop
# Build a list of windows
self.windows.extend(self.sway.get_window_list())
self.extend(self.sway.get_window_list())
elif WAYLAND:
raise Exception("On wayland, but not Sway. No way to get window info")
......@@ -293,7 +295,7 @@ class Windows:
parts[1] = int(parts[1])
if parts[1] < 0:
continue
self.windows.append(
self.append(
Window(parts[0], parts[1], parts[2], parts[3], " ".join(parts[5:]))
)
......@@ -315,12 +317,12 @@ class Windows:
def get_win_by_id(self, ident:int)->list[Window]:
"""This returns a list of windows matching the id, but it shouldn't. It
should return a window or None"""
return [w for w in self.windows if w.id == ident]
return [w for w in self if w.id == ident]
def get_win_by_class(self, wm_class):
if VERBOSE:
pp(self.windows)
return [w for w in self.windows if w.wm_class == wm_class]
pp(self)
return [w for w in self if w.wm_class == wm_class]
def get_closest_win_by_class(self, wm_class, skip_current:bool=True) -> list:
print(f"get_closest_win_by_class: {wm_class}")
......@@ -340,7 +342,7 @@ class Windows:
return wins
def get_win_by_desktop(self, desktop):
return [w for w in self.windows if w.desktop == desktop]
return [w for w in self if w.desktop == desktop]
def switch_to(self, win):
Log().write_win(win)
......@@ -359,7 +361,7 @@ class Windows:
def __str__(self):
return "\n".join([str(w) for w in self.windows])
return "\n".join([str(w) for w in self])
class Launcher():
env:dict[str,str] = {}
......
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