Skip to content

Commit

Permalink
Implements #127
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev31 committed Jul 19, 2024
1 parent 9763c05 commit d455685
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pyprland/plugins/scratchpads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ async def ensure_alive(self, uid: str) -> bool:
item = self.scratches.get(name=uid)
assert item

if not item.have_command:
return True

if self.cast_bool(item.conf.get("process_tracking"), True):
if not await item.is_alive():
await self._configure_windowrules(item)
Expand Down Expand Up @@ -389,9 +392,10 @@ async def _alternative_lookup(self) -> bool:

async def event_openwindow(self, params: str) -> None:
"""Open windows hook."""
addr, _wrkspc, _kls, _title = params.split(",", 3)
addr, _wrkspc, klass, _title = params.split(",", 3)
item = self.scratches.get(addr=addr)
respawned = list(self.scratches.get_by_state("respawned"))

if item:
# ensure initialized (no-op if already initialized)
await item.initialize(self)
Expand Down
37 changes: 25 additions & 12 deletions pyprland/plugins/scratchpads/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,39 @@ def set_config(self, opts: dict[str, Any]) -> None:

self.conf = opts

if not self.have_command:
self.conf["match_by"] = "class"

def have_address(self, addr: str) -> bool:
"""Check if the address is the same as the client."""
return addr == self.full_address or addr in self.extra_addr

@property
def have_command(self) -> bool:
"""Check if the command is provided."""
return bool(self.conf.get("command"))

async def initialize(self, ex: "_scratchpads_extension_m.Extension") -> None:
"""Initialize the scratchpad."""
if self.meta.initialized:
return
self.meta.initialized = True
await self.update_client_info()
if self.have_command:
await self.update_client_info()
else:
self.client_info = await self.fetch_matching_client()
assert self.client_info, "couldn't find a matching client"
await ex.hyprctl(f"movetoworkspacesilent special:scratch_{self.uid},address:{self.full_address}")
if "class_match" in self.conf: # NOTE: legacy, to be removed
await notify_error(
f'scratchpad {self.uid} should use match_by="class" instead of the deprecated class_match',
logger=self.log,
)
self.meta.initialized = True

async def is_alive(self) -> bool:
"""Is the process running ?."""
if not self.have_command:
return True
if self.cast_bool(self.conf.get("process_tracking"), True):
path = f"/proc/{self.pid}"
if await aiexists(path):
Expand Down Expand Up @@ -152,16 +166,15 @@ async def update_client_info(
) -> None:
"""Update the internal client info property, if not provided, refresh based on the current address."""
if client_info is None:
client_info = await self.get_client_props(addr=self.full_address, clients=clients)
if not isinstance(client_info, dict):
if client_info is None:
self.log.error("The client window %s vanished", self.full_address)
msg = f"Client window {self.full_address} not found"
raise KeyError(msg)
# Unexpected type:
self.log.error("client_info of %s must be a dict: %s", self.address, client_info) # type: ignore
msg = f"Not a dict: {client_info}"
raise TypeError(msg)
if self.have_command:
client_info = await self.get_client_props(addr=self.full_address, clients=clients)
else:
client_info = await self.fetch_matching_client(clients=clients)

if client_info is None:
self.log.error("The client window %s vanished", self.full_address)
msg = f"Client window {self.full_address} not found"
raise KeyError(msg)

self.client_info.update(client_info)

Expand Down
2 changes: 1 addition & 1 deletion pyprland/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package version."""

VERSION = "2.4.0-31"
VERSION = "2.4.0-45"

0 comments on commit d455685

Please sign in to comment.