Notification string to a queue of strings (#2517)

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>
This commit is contained in:
Madhav Prabhu C M 2021-10-03 14:54:24 +05:30 committed by GitHub
parent 1a59599388
commit e5ab7e1c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 13 deletions

1
.gitignore vendored
View File

@ -6,5 +6,6 @@
*.swp
*.tmp
.tags
*.user
polybar-*.tar

View File

@ -141,6 +141,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Clicks arriving in close succession, no longer get dropped. Before polybar
would drop any click that arrived within 5ms of the previous one.
- Increased the double click interval from 150ms to 400ms.
- Stop ignoring actions if they arrive while the previous one hasn't been processed yet.
([`#2469`](https://github.com/polybar/polybar/issues/2469))
### Fixed
- `custom/script`: Concurrency issues with fast-updating tailed scripts.

View File

@ -2,6 +2,7 @@
#include <atomic>
#include <mutex>
#include <queue>
#include "common.hpp"
#include "components/eventloop.hpp"
@ -15,6 +16,8 @@
POLYBAR_NS
using std::queue;
// fwd decl {{{
enum class alignment;
@ -30,7 +33,6 @@ namespace modules {
} // namespace modules
using module_t = shared_ptr<modules::module_interface>;
using modulemap_t = std::map<alignment, vector<module_t>>;
// }}}
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eventqueue::exit_reload,
@ -83,9 +85,9 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
bool reload;
bool update;
bool force_update;
string inputdata;
queue<string> inputdata;
notifications_t() : quit(false), reload(false), update(false), force_update(false), inputdata(string{}) {}
notifications_t() : quit(false), reload(false), update(false), force_update(false), inputdata(queue<string>{}) {}
};
size_t setup_modules(alignment align);

View File

@ -128,13 +128,9 @@ bool controller::run(bool writeback, string snapshot_dst, bool confwatch) {
*/
void controller::trigger_action(string&& input_data) {
std::unique_lock<std::mutex> guard(m_notification_mutex);
if (m_notifications.inputdata.empty()) {
m_notifications.inputdata = std::move(input_data);
m_log.trace("controller: Queueing input event '%s'", input_data);
m_notifications.inputdata.push(std::move(input_data));
trigger_notification();
} else {
m_log.trace("controller: Swallowing input event (pending data)");
}
}
void controller::trigger_quit(bool reload) {
@ -215,8 +211,11 @@ void controller::notifier_handler() {
return;
}
if (!data.inputdata.empty()) {
process_inputdata(std::move(data.inputdata));
while (!data.inputdata.empty()) {
auto inputdata = data.inputdata.front();
data.inputdata.pop();
m_log.trace("controller: Dequeueing inputdata: '%s'", inputdata);
process_inputdata(std::move(inputdata));
}
if (data.update) {
@ -461,7 +460,6 @@ void controller::process_inputdata(string&& cmd) {
m_log.err("controller: Error while forwarding input to shell -> %s", err.what());
}
}
/**
* Process eventqueue update event
*/