Harden i3 context capture

This commit is contained in:
Thales Maciel 2026-02-07 19:07:39 -03:00
parent 0e79edfa20
commit 328dcec458

View file

@ -44,19 +44,26 @@ class I3Provider(ContextProvider):
def capture(self) -> Context:
node = self._focused()
props = node.window_properties or {}
props = getattr(node, "window_properties", None) or {}
return Context(
window_id=node.id,
app_id=node.app_id or "",
app_id=getattr(node, "app_id", None) or "",
klass=props.get("class") or "",
instance=props.get("instance") or "",
title=node.name or "",
title=getattr(node, "name", None) or "",
)
def is_same_focus(self, ctx: Context) -> bool:
node = self._focused()
return node.id == ctx.window_id
def focus_window(self, window_id: int) -> bool:
node = self.i3.get_tree().find_by_id(window_id)
if node is None:
return False
node.command("focus")
return True
def _match_text(val: str, needle: str | None) -> bool:
if not needle: