UtkarshVerma / dwmblocks-async

An efficient, lean, and asynchronous status feed generator for dwm.
GNU General Public License v2.0
224 stars 87 forks source link

How to avoid re-runing on click/scroll #23

Closed psiho closed 2 years ago

psiho commented 2 years ago

I'm not sure if I'm doing this right, but I'd like to use mouse scroll on my volume block. In order to do this, I have to enable scroll buttons in dwm, and by doing it I enable it for ALL the blocks. It works, scrolling triggers my script action but it also reruns calculation too. It's not a problem for the volume block, it is actually desirable, but I have some blocks that take seconds to execute, and scrolling above them makes them execute many times.

I'm not sure how to do this or is it even possible.

UtkarshVerma commented 2 years ago

That is by design. Any mouse event on a block is supposed to update it.

Can you give me a reason why you'd want to scroll on a block knowing that it won't do anything?

psiho commented 2 years ago

I have several very small indicators in my bar, like single icon ones (temperature, utilization, etc). I need scroll on only few of them, not on all. But since they're so small, sometimes I do scroll above the "wrong" one accidentally. No big deal for regular ones, but some of them take long time to update and this triggers several updates.

I just don't know how to completely ignore scrolling over some blocks, other than adding some caching to memory to my long running scripts.

UtkarshVerma commented 2 years ago

You can try rate-limiting your block by adding a sleep statement in your block command, something like sb-util; sleep 1. This will ensure that the block is updated after at least 1 second.

Why sleep works? dwmblocks-async ignores any incoming signals for the block during its execution time. Here, the sleep command extends that execution time to at least 1 second.

UtkarshVerma commented 2 years ago

Closing due to inactivity. Feel free to reopen this.