Experimental logic chnge
This commit is contained in:
parent
02de5fbc76
commit
1653d383d3
1 changed files with 40 additions and 36 deletions
|
@ -1,6 +1,7 @@
|
||||||
" Scratchpads addon "
|
" Scratchpads addon "
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
from itertools import count
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
import logging
|
import logging
|
||||||
|
@ -217,6 +218,7 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
||||||
scratch.just_created = False
|
scratch.just_created = False
|
||||||
else:
|
else:
|
||||||
for uid, scratch in self.scratches.items():
|
for uid, scratch in self.scratches.items():
|
||||||
|
self.log.info((scratch.address, addr))
|
||||||
if scratch.client_info and scratch.address != addr:
|
if scratch.client_info and scratch.address != addr:
|
||||||
if (
|
if (
|
||||||
scratch.visible
|
scratch.visible
|
||||||
|
@ -299,28 +301,21 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
||||||
return # abort sequence
|
return # abort sequence
|
||||||
await asyncio.sleep(0.2) # await for animation to finish
|
await asyncio.sleep(0.2) # await for animation to finish
|
||||||
|
|
||||||
async def updateScratchInfo(self, scratch: Scratch | None = None) -> None:
|
async def updateScratchInfo(self, orig_scratch: Scratch | None = None) -> None:
|
||||||
"""Update every scratchpads information if no `scratch` given,
|
"""Update every scratchpads information if no `scratch` given,
|
||||||
else update a specific scratchpad info"""
|
else update a specific scratchpad info"""
|
||||||
if scratch is None:
|
pid = orig_scratch.pid if orig_scratch else None
|
||||||
self.log.info("update from None")
|
for client in await hyprctlJSON("clients"):
|
||||||
for client in await hyprctlJSON("clients"):
|
assert isinstance(client, dict)
|
||||||
assert isinstance(client, dict)
|
if pid and pid != client["pid"]:
|
||||||
scratch = self.scratches_by_address.get(client["address"][2:])
|
continue
|
||||||
if not scratch:
|
scratch = self.scratches_by_address.get(client["address"][2:])
|
||||||
scratch = self.scratches_by_pid.get(client["pid"])
|
if not scratch:
|
||||||
if scratch:
|
scratch = self.scratches_by_pid.get(client["pid"])
|
||||||
self.scratches_by_address[client["address"][2:]] = scratch
|
|
||||||
if scratch:
|
if scratch:
|
||||||
await scratch.updateClientInfo(client)
|
self.scratches_by_address[client["address"][2:]] = scratch
|
||||||
else:
|
if scratch:
|
||||||
add_to_address_book = ("address" not in scratch.client_info) or (
|
await scratch.updateClientInfo(client)
|
||||||
scratch.address not in self.scratches_by_address
|
|
||||||
)
|
|
||||||
self.log.info(f"update from something, adding: {add_to_address_book}")
|
|
||||||
await scratch.updateClientInfo()
|
|
||||||
if add_to_address_book:
|
|
||||||
self.scratches_by_address[scratch.client_info["address"][2:]] = scratch
|
|
||||||
|
|
||||||
async def run_hide(self, uid: str, force=False, autohide=False) -> None:
|
async def run_hide(self, uid: str, force=False, autohide=False) -> None:
|
||||||
"""<name> hides scratchpad "name" """
|
"""<name> hides scratchpad "name" """
|
||||||
|
@ -332,8 +327,11 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
||||||
if not scratch.visible and not force:
|
if not scratch.visible and not force:
|
||||||
self.log.warning("%s is already hidden", uid)
|
self.log.warning("%s is already hidden", uid)
|
||||||
return
|
return
|
||||||
self.log.info("Hiding %s", uid)
|
|
||||||
scratch.visible = False
|
scratch.visible = False
|
||||||
|
if not scratch.isAlive():
|
||||||
|
await self.run_show(uid, force=True)
|
||||||
|
return
|
||||||
|
self.log.info("Hiding %s", uid)
|
||||||
addr = "address:0x" + scratch.address
|
addr = "address:0x" + scratch.address
|
||||||
animation_type: str = scratch.conf.get("animation", "").lower()
|
animation_type: str = scratch.conf.get("animation", "").lower()
|
||||||
if animation_type:
|
if animation_type:
|
||||||
|
@ -351,6 +349,27 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
||||||
)
|
)
|
||||||
del self.focused_window_tracking[uid]
|
del self.focused_window_tracking[uid]
|
||||||
|
|
||||||
|
async def ensure_alive(self, uid, item=None):
|
||||||
|
if item is None:
|
||||||
|
item = self.scratches.get(uid)
|
||||||
|
|
||||||
|
if not item.isAlive():
|
||||||
|
self.log.info("%s is not running, restarting...", uid)
|
||||||
|
if uid in self.procs:
|
||||||
|
self.procs[uid].kill()
|
||||||
|
if item.pid in self.scratches_by_pid:
|
||||||
|
del self.scratches_by_pid[item.pid]
|
||||||
|
if item.address in self.scratches_by_address:
|
||||||
|
del self.scratches_by_address[item.address]
|
||||||
|
self.log.info(f"starting {uid}")
|
||||||
|
await self.start_scratch_command(uid)
|
||||||
|
self.log.info(f"{uid} started")
|
||||||
|
self.log.info("==> Wait for spawning")
|
||||||
|
loop_count = count()
|
||||||
|
while uid in self._respawned_scratches and next(loop_count) < 10:
|
||||||
|
await asyncio.sleep(0.05)
|
||||||
|
self.log.info(f"=> spawned {uid} as proc {item.pid}")
|
||||||
|
|
||||||
async def run_show(self, uid, force=False) -> None:
|
async def run_show(self, uid, force=False) -> None:
|
||||||
"""<name> shows scratchpad "name" """
|
"""<name> shows scratchpad "name" """
|
||||||
uid = uid.strip()
|
uid = uid.strip()
|
||||||
|
@ -369,22 +388,7 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
||||||
return
|
return
|
||||||
|
|
||||||
self.log.info("Showing %s", uid)
|
self.log.info("Showing %s", uid)
|
||||||
|
await self.ensure_alive(uid, item)
|
||||||
if not item.isAlive():
|
|
||||||
self.log.info("%s is not running, restarting...", uid)
|
|
||||||
if uid in self.procs:
|
|
||||||
self.procs[uid].kill()
|
|
||||||
if item.pid in self.scratches_by_pid:
|
|
||||||
del self.scratches_by_pid[item.pid]
|
|
||||||
if item.address in self.scratches_by_address:
|
|
||||||
del self.scratches_by_address[item.address]
|
|
||||||
self.log.info(f"starting {uid}")
|
|
||||||
await self.start_scratch_command(uid)
|
|
||||||
self.log.info(f"{uid} started")
|
|
||||||
self.log.info("==> Wait for spawning")
|
|
||||||
while uid in self._respawned_scratches:
|
|
||||||
await asyncio.sleep(0.05)
|
|
||||||
self.log.info(f"=> spawned {uid} as proc {item.pid}")
|
|
||||||
|
|
||||||
item.visible = True
|
item.visible = True
|
||||||
monitor = await get_focused_monitor_props()
|
monitor = await get_focused_monitor_props()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue