From f36224eaab0926eaac039f600df18e61e3ffe1c2 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sat, 11 Sep 2021 12:36:52 +0200
Subject: [PATCH] Move quit event to eventloop
---
include/components/controller.hpp | 3 ++-
include/events/types.hpp | 10 +-------
src/components/controller.cpp | 41 ++++++++++++++-----------------
3 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/include/components/controller.hpp b/include/components/controller.hpp
index a697d6f8..217fd560 100644
--- a/include/components/controller.hpp
+++ b/include/components/controller.hpp
@@ -52,7 +52,8 @@ class controller
bool run(bool writeback, string snapshot_dst);
bool enqueue(event&& evt);
- bool trigger_action(string&& input_data);
+ void trigger_action(string&& input_data);
+ void trigger_quit(bool reload);
void stop(bool reload);
diff --git a/include/events/types.hpp b/include/events/types.hpp
index 515a7e37..8e5cc831 100644
--- a/include/events/types.hpp
+++ b/include/events/types.hpp
@@ -9,7 +9,6 @@ POLYBAR_NS
enum class event_type {
NONE = 0,
UPDATE,
- QUIT,
};
struct event {
@@ -26,19 +25,12 @@ namespace {
}
/**
- * Create QUIT event
+ * Create NONE event
*/
inline event make_none_evt() {
return event{static_cast(event_type::NONE)};
}
- /**
- * Create QUIT event
- */
- inline event make_quit_evt(bool reload = false) {
- return event{static_cast(event_type::QUIT), reload};
- }
-
/**
* Create UPDATE event
*/
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index cbf8a10d..35cde3e5 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -147,7 +147,7 @@ bool controller::run(bool writeback, string snapshot_dst) {
* Enqueue event
*/
bool controller::enqueue(event&& evt) {
- if (!m_process_events && evt.type != event_type::QUIT) {
+ if (!m_process_events) {
return false;
}
if (!m_queue.enqueue(forward(evt))) {
@@ -160,14 +160,19 @@ bool controller::enqueue(event&& evt) {
/**
* Enqueue input data
*/
-bool controller::trigger_action(string&& input_data) {
+void controller::trigger_action(string&& input_data) {
if (!m_inputdata.empty()) {
m_log.trace("controller: Swallowing input event (pending data)");
} else {
m_inputdata = forward(input_data);
UV(uv_async_send, m_notifier.get());
}
- return false;
+}
+
+void controller::trigger_quit(bool reload) {
+ g_terminate = 1;
+ g_reload = reload;
+ UV(uv_async_send, m_notifier.get());
}
void controller::stop(bool reload) {
@@ -224,6 +229,11 @@ void controller::confwatch_handler(const char* filename, int, int) {
}
void controller::notifier_handler() {
+ if (g_terminate) {
+ eloop->stop();
+ return;
+ }
+
if (!m_inputdata.empty()) {
process_inputdata();
}
@@ -325,22 +335,13 @@ void controller::process_eventqueue() {
if (g_terminate) {
break;
- } else if (evt.type == event_type::QUIT) {
- if (evt.flag) {
- on(signals::eventqueue::exit_reload{});
- } else {
- on(signals::eventqueue::exit_terminate{});
- }
} else if (evt.type == event_type::UPDATE && evt.flag) {
process_update(true);
} else {
event next{};
size_t swallowed{0};
while (swallowed++ < m_swallow_limit && m_queue.wait_dequeue_timed(next, m_swallow_update)) {
- if (next.type == event_type::QUIT) {
- evt = next;
- break;
- } else if (evt.type != next.type) {
+ if (evt.type != next.type) {
enqueue(move(next));
break;
} else {
@@ -351,12 +352,6 @@ void controller::process_eventqueue() {
if (evt.type == event_type::UPDATE) {
process_update(evt.flag);
- } else if (evt.type == event_type::QUIT) {
- if (evt.flag) {
- on(signals::eventqueue::exit_reload{});
- } else {
- on(signals::eventqueue::exit_terminate{});
- }
} else {
m_log.warn("Unknown event type for enqueued event (%d)", evt.type);
}
@@ -712,7 +707,7 @@ bool controller::on(const signals::eventqueue::notify_forcechange&) {
* Process eventqueue terminate event
*/
bool controller::on(const signals::eventqueue::exit_terminate&) {
- raise(SIGALRM);
+ trigger_quit(false);
return true;
}
@@ -720,7 +715,7 @@ bool controller::on(const signals::eventqueue::exit_terminate&) {
* Process eventqueue reload event
*/
bool controller::on(const signals::eventqueue::exit_reload&) {
- raise(SIGUSR1);
+ trigger_quit(true);
return true;
}
@@ -799,9 +794,9 @@ bool controller::on(const signals::ipc::command& evt) {
}
if (command == "quit") {
- enqueue(make_quit_evt(false));
+ trigger_quit(false);
} else if (command == "restart") {
- enqueue(make_quit_evt(true));
+ trigger_quit(true);
} else if (command == "hide") {
m_bar->hide();
} else if (command == "show") {