Integrate bar taskqueue into eventloop (#2510)
* Remove DEBUG_SHADED Was disabled by default AND behind an #if 0 * Make TimerHandle expose more libuv functions * Prepare for moving double clicks into eventloop * Make eventloop available to bar * Remove bar mutex Everything in the bar is now in the same thread * Move double-click handling to eventloop * Extract double click deferred function into method * Stop throttling clicks * Increase double click interval to 400 and add option double-click-interval in the bar section Closes #1441 * Implement dimming using timer handles * Remove taskqueue * Remove unused dependencies * Cleanup & Comments
This commit is contained in:
parent
55eb19fdc7
commit
8afd5b71df
18 changed files with 156 additions and 471 deletions
src/components
|
@ -31,20 +31,21 @@ POLYBAR_NS
|
|||
* Build controller instance
|
||||
*/
|
||||
controller::make_type controller::make(unique_ptr<ipc>&& ipc) {
|
||||
return std::make_unique<controller>(connection::make(), signal_emitter::make(), logger::make(), config::make(),
|
||||
bar::make(), forward<decltype(ipc)>(ipc));
|
||||
return std::make_unique<controller>(
|
||||
connection::make(), signal_emitter::make(), logger::make(), config::make(), forward<decltype(ipc)>(ipc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct controller
|
||||
*/
|
||||
controller::controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config,
|
||||
unique_ptr<bar>&& bar, unique_ptr<ipc>&& ipc)
|
||||
controller::controller(
|
||||
connection& conn, signal_emitter& emitter, const logger& logger, const config& config, unique_ptr<ipc>&& ipc)
|
||||
: m_connection(conn)
|
||||
, m_sig(emitter)
|
||||
, m_log(logger)
|
||||
, m_conf(config)
|
||||
, m_bar(forward<decltype(bar)>(bar))
|
||||
, m_loop(make_unique<eventloop>())
|
||||
, m_bar(bar::make(*m_loop))
|
||||
, m_ipc(forward<decltype(ipc)>(ipc)) {
|
||||
m_conf.ignore_key("settings", "throttle-input-for");
|
||||
m_conf.ignore_key("settings", "throttle-output");
|
||||
|
@ -152,14 +153,14 @@ void controller::trigger_update(bool force) {
|
|||
}
|
||||
|
||||
void controller::trigger_notification() {
|
||||
if (m_eloop_ready) {
|
||||
if (m_loop_ready) {
|
||||
m_notifier->send();
|
||||
}
|
||||
}
|
||||
|
||||
void controller::stop(bool reload) {
|
||||
update_reload(reload);
|
||||
eloop->stop();
|
||||
m_loop->stop();
|
||||
}
|
||||
|
||||
void controller::conn_cb(uv_poll_event) {
|
||||
|
@ -210,7 +211,7 @@ void controller::notifier_handler() {
|
|||
|
||||
if (data.quit) {
|
||||
update_reload(data.reload);
|
||||
eloop->stop();
|
||||
m_loop->stop();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -234,29 +235,23 @@ void controller::screenshot_handler() {
|
|||
void controller::read_events(bool confwatch) {
|
||||
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
|
||||
|
||||
if (!m_writeback) {
|
||||
m_bar->start();
|
||||
}
|
||||
|
||||
try {
|
||||
eloop = std::make_unique<eventloop>();
|
||||
|
||||
eloop->poll_handle(
|
||||
m_loop->poll_handle(
|
||||
UV_READABLE, m_connection.get_file_descriptor(), [this](uv_poll_event events) { conn_cb(events); },
|
||||
[](int status) { throw runtime_error("libuv error while polling X connection: "s + uv_strerror(status)); });
|
||||
|
||||
for (auto s : {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGALRM}) {
|
||||
eloop->signal_handle(s, [this](int signum) { signal_handler(signum); });
|
||||
m_loop->signal_handle(s, [this](int signum) { signal_handler(signum); });
|
||||
}
|
||||
|
||||
if (confwatch) {
|
||||
eloop->fs_event_handle(
|
||||
m_loop->fs_event_handle(
|
||||
m_conf.filepath(), [this](const char* path, uv_fs_event events) { confwatch_handler(path, events); },
|
||||
[this](int err) { m_log.err("libuv error while watching config file for changes: %s", uv_strerror(err)); });
|
||||
}
|
||||
|
||||
if (m_ipc) {
|
||||
eloop->pipe_handle(
|
||||
m_loop->pipe_handle(
|
||||
m_ipc->get_path(), [this](const string payload) { m_ipc->receive_data(payload); },
|
||||
[this]() { m_ipc->receive_eof(); },
|
||||
[this](int err) { m_log.err("libuv error while listening to IPC channel: %s", uv_strerror(err)); });
|
||||
|
@ -264,19 +259,23 @@ void controller::read_events(bool confwatch) {
|
|||
|
||||
if (!m_snapshot_dst.empty()) {
|
||||
// Trigger a single screenshot after 3 seconds
|
||||
eloop->timer_handle(3000, 0, [this]() { screenshot_handler(); });
|
||||
m_loop->timer_handle([this]() { screenshot_handler(); })->start(3000, 0);
|
||||
}
|
||||
|
||||
m_notifier = eloop->async_handle([this]() { notifier_handler(); });
|
||||
m_notifier = m_loop->async_handle([this]() { notifier_handler(); });
|
||||
|
||||
m_eloop_ready.store(true);
|
||||
m_loop_ready = true;
|
||||
|
||||
if (!m_writeback) {
|
||||
m_bar->start();
|
||||
}
|
||||
|
||||
/*
|
||||
* Immediately trigger and update so that the bar displays something.
|
||||
*/
|
||||
trigger_update(true);
|
||||
|
||||
eloop->run();
|
||||
m_loop->run();
|
||||
} catch (const exception& err) {
|
||||
m_log.err("Fatal Error in eventloop: %s", err.what());
|
||||
stop(false);
|
||||
|
@ -284,7 +283,8 @@ void controller::read_events(bool confwatch) {
|
|||
|
||||
m_log.info("Eventloop finished");
|
||||
|
||||
eloop.reset();
|
||||
m_loop_ready = false;
|
||||
m_loop.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue