mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-16 05:04:21 +02:00
i3-companion: encapsulate state into function object
This avoids littering the code with global variables.
This commit is contained in:
parent
b25442dfd9
commit
4f28e682e1
1 changed files with 6 additions and 9 deletions
|
@ -318,20 +318,17 @@ async def workspace_info(i3, event):
|
|||
body.lstrip("\n"))
|
||||
|
||||
|
||||
output_update_running = None
|
||||
|
||||
|
||||
@on(Event.OUTPUT)
|
||||
async def output_update(i3, event):
|
||||
"""React to a XRandR change."""
|
||||
global output_update_running
|
||||
if output_update_running is not None:
|
||||
output_update_running.cancel()
|
||||
running = getattr(output_update, "running", None)
|
||||
if running is not None:
|
||||
running.cancel()
|
||||
output_update.running = None
|
||||
|
||||
def output_update_now():
|
||||
"""Execute actions to react to XRandR change."""
|
||||
global output_update_running
|
||||
output_update_running = None
|
||||
output_update.running = None
|
||||
|
||||
logger.info("XRandR change detected")
|
||||
cmds = (
|
||||
|
@ -344,7 +341,7 @@ async def output_update(i3, event):
|
|||
logger.warning(f"{cmd} exited with {proc.returncode}")
|
||||
|
||||
logger.debug("schedule XRandR change")
|
||||
output_update_running = asyncio.get_event_loop().call_later(
|
||||
output_update.running = asyncio.get_event_loop().call_later(
|
||||
2, output_update_now)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue