Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework command enqueing to minimize swallowing #2469

Closed
Astrono2 opened this issue Jul 15, 2021 · 9 comments · Fixed by #2517
Closed

Rework command enqueing to minimize swallowing #2469

Astrono2 opened this issue Jul 15, 2021 · 9 comments · Fixed by #2517
Assignees
Labels

Comments

@Astrono2
Copy link

Is your feature request related to a problem? Please describe.

It is currently not possible to call m_sig.emit(button_press{*}); more than once before m_inputdata is cleared in the next iteration of the eventqueue worker loop. This is a problem, for example, if more than one action need to be triggered in the same method call.

Why does polybar need this feature?

This feature would make the core system underlying polybar considerably more flexible, and would allow for easier and faster implementation of some features.

Describe the solution you'd like

Instead of m_inputdata there could be a queue of input data strings.

Describe alternatives you've considered

One alternative is to not emit many signals one after the other, and instead store the signals and call them after a short delay, but this increases complexity and makes everything more prone to bugs.

Additional context

image
Results in
image

@madhavpcm
Copy link
Contributor

Hello I am new to polybar, I would like to contribute to this issue, is there any place where I could start?

@patrick96
Copy link
Member

@madhavpcm Yes, the pending action string is stored in inputdata in notifications_t in controller.hpp. Making that a queue would probably be the most straightforward way to solve this.

Thanks :)

@madhavpcm
Copy link
Contributor

madhavpcm commented Oct 2, 2021

I have did some changes to notifier_handler() and trigger_action() as these were the places where I noticed enqueuing and dequeuing takes place. I believe the notifier_handler() loop runs separately and checks if inputdata is available and call process_inputdata(). However, in order to test I'm confused not sure how to try out m_sig.emit(button_press{*}) multiple times

   notifer_handler()
  if (!data.inputdata.empty()) {
    process_inputdata(std::move(data.inputdata.front()));
  }
void controller::trigger_action(string&& input_data) {
  std::unique_lock<std::mutex> guard(m_notification_mutex);
  m_notifications.inputdata.push(std::move(input_data));
  m_log.trace("controller: Queueing input event (pending data)");
  trigger_notification();
}

@patrick96
Copy link
Member

Yeah testing might be tricky here since it relies on the button clicks (or ipc actions) arriving very quickly after each other. I don't think there is a way to trigger this by hand.

I also don't think you can write any automated tests for this since the controller relies on an X server running which we can't handle yet in our testing infrastructure.

But if you want to just quickly verify things work for you, you could add something like this:

m_loop->timer_handle([this]() { trigger_action("notify-send A"); trigger_action("notify-send B"); })->start(500, 0);

This will trigger two actions directly after one another (they should each create a notification popup) after about half a second. Add this line directly before we set m_loop_ready to true.

@madhavpcm
Copy link
Contributor

image
I hope this is the desired behaviour

@patrick96
Copy link
Member

Yes, that looks alright :)

@madhavpcm
Copy link
Contributor

Im terribly sorry for the messy commits in the PR, I keep forgetting one thing or the other before committing. Kind of a beginner with git and pull requests. Thanks alot for the help!

@patrick96
Copy link
Member

Don't worry about that one bit. That's why we have PR reviews and formatting tools ;)

I appreciate the effort

@madhavpcm
Copy link
Contributor

Thanks Alot! I will work on my approach, looking forward to contribute more in the near future :).

patrick96 added a commit that referenced this issue Oct 3, 2021
Fixes #2469

* made inputdata to queue<string>

* changed back to front

* fixed move semantics issue while popping queue

* Removed ide file

* commented test lines

* review changes

* review changes

* Update CHANGELOG.md

* Cleanup

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants