Move quit event to eventloop
This commit is contained in:
parent
ba341f584e
commit
f36224eaab
@ -52,7 +52,8 @@ class controller
|
|||||||
bool run(bool writeback, string snapshot_dst);
|
bool run(bool writeback, string snapshot_dst);
|
||||||
|
|
||||||
bool enqueue(event&& evt);
|
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);
|
void stop(bool reload);
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ POLYBAR_NS
|
|||||||
enum class event_type {
|
enum class event_type {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
UPDATE,
|
UPDATE,
|
||||||
QUIT,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct event {
|
struct event {
|
||||||
@ -26,19 +25,12 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create QUIT event
|
* Create NONE event
|
||||||
*/
|
*/
|
||||||
inline event make_none_evt() {
|
inline event make_none_evt() {
|
||||||
return event{static_cast<int>(event_type::NONE)};
|
return event{static_cast<int>(event_type::NONE)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create QUIT event
|
|
||||||
*/
|
|
||||||
inline event make_quit_evt(bool reload = false) {
|
|
||||||
return event{static_cast<int>(event_type::QUIT), reload};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create UPDATE event
|
* Create UPDATE event
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +147,7 @@ bool controller::run(bool writeback, string snapshot_dst) {
|
|||||||
* Enqueue event
|
* Enqueue event
|
||||||
*/
|
*/
|
||||||
bool controller::enqueue(event&& evt) {
|
bool controller::enqueue(event&& evt) {
|
||||||
if (!m_process_events && evt.type != event_type::QUIT) {
|
if (!m_process_events) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!m_queue.enqueue(forward<decltype(evt)>(evt))) {
|
if (!m_queue.enqueue(forward<decltype(evt)>(evt))) {
|
||||||
@ -160,14 +160,19 @@ bool controller::enqueue(event&& evt) {
|
|||||||
/**
|
/**
|
||||||
* Enqueue input data
|
* Enqueue input data
|
||||||
*/
|
*/
|
||||||
bool controller::trigger_action(string&& input_data) {
|
void controller::trigger_action(string&& input_data) {
|
||||||
if (!m_inputdata.empty()) {
|
if (!m_inputdata.empty()) {
|
||||||
m_log.trace("controller: Swallowing input event (pending data)");
|
m_log.trace("controller: Swallowing input event (pending data)");
|
||||||
} else {
|
} else {
|
||||||
m_inputdata = forward<string>(input_data);
|
m_inputdata = forward<string>(input_data);
|
||||||
UV(uv_async_send, m_notifier.get());
|
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) {
|
void controller::stop(bool reload) {
|
||||||
@ -224,6 +229,11 @@ void controller::confwatch_handler(const char* filename, int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void controller::notifier_handler() {
|
void controller::notifier_handler() {
|
||||||
|
if (g_terminate) {
|
||||||
|
eloop->stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_inputdata.empty()) {
|
if (!m_inputdata.empty()) {
|
||||||
process_inputdata();
|
process_inputdata();
|
||||||
}
|
}
|
||||||
@ -325,22 +335,13 @@ void controller::process_eventqueue() {
|
|||||||
|
|
||||||
if (g_terminate) {
|
if (g_terminate) {
|
||||||
break;
|
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) {
|
} else if (evt.type == event_type::UPDATE && evt.flag) {
|
||||||
process_update(true);
|
process_update(true);
|
||||||
} else {
|
} else {
|
||||||
event next{};
|
event next{};
|
||||||
size_t swallowed{0};
|
size_t swallowed{0};
|
||||||
while (swallowed++ < m_swallow_limit && m_queue.wait_dequeue_timed(next, m_swallow_update)) {
|
while (swallowed++ < m_swallow_limit && m_queue.wait_dequeue_timed(next, m_swallow_update)) {
|
||||||
if (next.type == event_type::QUIT) {
|
if (evt.type != next.type) {
|
||||||
evt = next;
|
|
||||||
break;
|
|
||||||
} else if (evt.type != next.type) {
|
|
||||||
enqueue(move(next));
|
enqueue(move(next));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -351,12 +352,6 @@ void controller::process_eventqueue() {
|
|||||||
|
|
||||||
if (evt.type == event_type::UPDATE) {
|
if (evt.type == event_type::UPDATE) {
|
||||||
process_update(evt.flag);
|
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 {
|
} else {
|
||||||
m_log.warn("Unknown event type for enqueued event (%d)", evt.type);
|
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
|
* Process eventqueue terminate event
|
||||||
*/
|
*/
|
||||||
bool controller::on(const signals::eventqueue::exit_terminate&) {
|
bool controller::on(const signals::eventqueue::exit_terminate&) {
|
||||||
raise(SIGALRM);
|
trigger_quit(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +715,7 @@ bool controller::on(const signals::eventqueue::exit_terminate&) {
|
|||||||
* Process eventqueue reload event
|
* Process eventqueue reload event
|
||||||
*/
|
*/
|
||||||
bool controller::on(const signals::eventqueue::exit_reload&) {
|
bool controller::on(const signals::eventqueue::exit_reload&) {
|
||||||
raise(SIGUSR1);
|
trigger_quit(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,9 +794,9 @@ bool controller::on(const signals::ipc::command& evt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command == "quit") {
|
if (command == "quit") {
|
||||||
enqueue(make_quit_evt(false));
|
trigger_quit(false);
|
||||||
} else if (command == "restart") {
|
} else if (command == "restart") {
|
||||||
enqueue(make_quit_evt(true));
|
trigger_quit(true);
|
||||||
} else if (command == "hide") {
|
} else if (command == "hide") {
|
||||||
m_bar->hide();
|
m_bar->hide();
|
||||||
} else if (command == "show") {
|
} else if (command == "show") {
|
||||||
|
Loading…
Reference in New Issue
Block a user