eww icon indicating copy to clipboard operation
eww copied to clipboard

[FEATURE] Force poll to execute on event handler

Open KiranWells opened this issue 2 years ago • 2 comments

Description of the requested feature

For many widgets, the intended functionality is to have a button or scale change some value in the background, such as volume or mute. The issue is that while the onclick/onchange properties immediately change the value in the background, the widget will not update to show the new information until the poll triggers again. Is there a way to force a poll to re-run when an onclick/onchange handler is called?

Proposed configuration syntax

I would imagine a feature similar to the eww update var=value command, but which just triggers the poll command. For example:

eww repoll [varname]

Another option would be to allow polls to automatically re-execute when event handlers are called, such as:

(defpoll myvar :interval "10s" :repoll-on-events true "command" )

or

(button :onclick "command" :repoll myvar "Value: ${myvar}")

Additional context

No response

KiranWells avatar Jun 19 '22 21:06 KiranWells

The repoll attribute isn't really feasible, I'm afraid. I'm also not sure if I like the idea of having a repoll command, for a simple reason: script vars (poll and listen) can still manually be set via eww update. Thus, you can simply run eww update mypollvar=newvalue in your listeners to immediately update the variable to the new value.

Im not completely opposed to the idea of making that a bit easier, but id love to hear a bit more specific reason why running eww update isn't sufficient

elkowar avatar Jun 20 '22 08:06 elkowar

There are a couple of reasons I requested this, the first is that I was unaware that polled variables could be manually updated. This does solve some of the problem, but it is a somewhat unwieldy solution.

The main issue is the inconvenience of having to write:

:onclick "some command for click; eww update VARNAME `the command for updating that variable`"

This causes there to be many duplicates of the same logic, leading to more confusing code and the possibility for errors when updating the command for the polled variable.

The root of the problem, however, is that I have a lot of variables being updated with polls that should really be deflisten variables. The main issue is that there are no command-line tools that I am aware of for listening to things like volume changes, brightness changes, and the like. The current solution is to have high-frequency polls, which increases resource usage unnecessarily. I am considering creating a separate program that can handle some of the logic of monitoring the system and updating eww variables when necessary; that could fix many of the issues I have.

KiranWells avatar Jul 06 '22 15:07 KiranWells

I do think that just going for more deflistens would be the clean solution! While I see how it's slightly unweildly, I don't think it's worth it to add an option to explicitly repoll a variable currently -- so I'll close this. sorry!

Thanks for your efforts anyways!

elkowar avatar Aug 27 '22 11:08 elkowar