mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-29 13:00:02 +02:00
i3-companion: use contextlib to simplify a bit some code
This commit is contained in:
parent
e0569deacf
commit
adfec52532
1 changed files with 3 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
import collections
|
||||||
|
import contextlib
|
||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
|
@ -12,7 +13,6 @@ import html
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -177,12 +177,10 @@ def debounce(sleep, *, unless=None):
|
||||||
def decorator(fn):
|
def decorator(fn):
|
||||||
async def worker():
|
async def worker():
|
||||||
while True:
|
while True:
|
||||||
try:
|
with contextlib.suppress(asyncio.TimeoutError):
|
||||||
# Wait for an urgent work or until sleep is elapsed
|
# Wait for an urgent work or until sleep is elapsed
|
||||||
await asyncio.wait_for(workers[fn].urgent.wait(), timeout=sleep)
|
await asyncio.wait_for(workers[fn].urgent.wait(), timeout=sleep)
|
||||||
logger.debug("urgent work received for %s", fn)
|
logger.debug("urgent work received for %s", fn)
|
||||||
except asyncio.TimeoutError:
|
|
||||||
pass
|
|
||||||
args, kwargs = workers[fn].queue
|
args, kwargs = workers[fn].queue
|
||||||
workers[fn].queue = None
|
workers[fn].queue = None
|
||||||
workers[fn].urgent.clear()
|
workers[fn].urgent.clear()
|
||||||
|
@ -533,8 +531,7 @@ async def output_update(i3, event):
|
||||||
"""React to a XRandR change."""
|
"""React to a XRandR change."""
|
||||||
|
|
||||||
# Grab current setup. Synchronous, but it's short enough
|
# Grab current setup. Synchronous, but it's short enough
|
||||||
d = display.Display()
|
with contextlib.closing(display.Display()) as d:
|
||||||
try:
|
|
||||||
screen = d.screen()
|
screen = d.screen()
|
||||||
window = screen.root.create_window(0, 0, 1, 1, 1, screen.root_depth)
|
window = screen.root.create_window(0, 0, 1, 1, 1, screen.root_depth)
|
||||||
screen_resources = randr.get_screen_resources_current(window)
|
screen_resources = randr.get_screen_resources_current(window)
|
||||||
|
@ -557,8 +554,6 @@ async def output_update(i3, event):
|
||||||
crtc_info.y,
|
crtc_info.y,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
finally:
|
|
||||||
d.close()
|
|
||||||
|
|
||||||
# Compare to current setup
|
# Compare to current setup
|
||||||
if current_setup == output_update.last_setup:
|
if current_setup == output_update.last_setup:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue