i3-companion: rename dampen to debounce

I think this is more correct. Dampen is used in network world, but
debounce seems more common (notably, we debounce push buttons).
Another word could be throttle but that does not match as we need to
react to the last event of a batch instead of the first (and we sure
don't want to drop the last).
This commit is contained in:
Vincent Bernat 2021-07-13 00:39:45 +02:00
parent 2781777842
commit 71dcb5d6bc

View file

@ -99,11 +99,13 @@ def on(*events):
return decorator return decorator
def dampen(sleep, *, unless=None, retry=0): def debounce(sleep, *, unless=None, retry=0):
"""Dampen a function call. Optional immediate execution. Optional """Debounce a function call (batch successive calls into only one).
retry on failure. Ensure only one instance is executed. It is Optional immediate execution. Optional retry on failure. Ensure
assumed the arguments provided to the dampened function have no only one instance is executed. It is assumed the arguments
effect on its execution. provided to the debounced function have no effect on its
execution.
""" """
def decorator(fn): def decorator(fn):
@ -195,7 +197,7 @@ async def notify(i3, **kwargs):
@on(StartEvent, I3Event.WINDOW_MOVE, I3Event.WINDOW_NEW, I3Event.WINDOW_CLOSE) @on(StartEvent, I3Event.WINDOW_MOVE, I3Event.WINDOW_NEW, I3Event.WINDOW_CLOSE)
@dampen(0.2) @debounce(0.2)
async def workspace_rename(i3, event): async def workspace_rename(i3, event):
"""Rename workspaces using icons to match what's inside it.""" """Rename workspaces using icons to match what's inside it."""
tree = await i3.get_tree() tree = await i3.get_tree()
@ -456,7 +458,7 @@ async def workspace_info(i3, event):
@on(I3Event.OUTPUT) @on(I3Event.OUTPUT)
@dampen(2) @debounce(2)
async def output_update(i3, event): async def output_update(i3, event):
"""React to a XRandR change.""" """React to a XRandR change."""
logger.info("XRandR change detected") logger.info("XRandR change detected")
@ -560,7 +562,7 @@ async def network_manager_notifications(i3, event, path, state, reason):
signature="a{sv}", signature="a{sv}",
), ),
) )
@dampen( @debounce(
1, 1,
unless=lambda i3, event, *args: ( unless=lambda i3, event, *args: (
isinstance(event, DBusSignal) and event.interface.endswith(".Active") isinstance(event, DBusSignal) and event.interface.endswith(".Active")