mirror of
https://github.com/polybar/polybar.git
synced 2024-11-25 13:55:47 -05:00
refactor(signals): Simple types
This commit is contained in:
parent
b422d1d1a4
commit
789800a68f
9 changed files with 76 additions and 46 deletions
|
@ -42,8 +42,8 @@ namespace sig_ev = signals::eventqueue;
|
|||
namespace sig_ui = signals::ui;
|
||||
namespace sig_ipc = signals::ipc;
|
||||
|
||||
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::process_broadcast, sig_ev::process_update,
|
||||
sig_ev::process_quit, sig_ev::process_check, sig_ipc::process_action,
|
||||
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload,
|
||||
sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::process_action,
|
||||
sig_ipc::process_command, sig_ipc::process_hook, sig_ui::button_press> {
|
||||
public:
|
||||
using make_type = unique_ptr<controller>;
|
||||
|
@ -63,10 +63,11 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::proc
|
|||
void process_eventqueue();
|
||||
void process_inputdata();
|
||||
|
||||
bool on(const sig_ev::process_broadcast& evt);
|
||||
bool on(const sig_ev::process_update& evt);
|
||||
bool on(const sig_ev::process_quit& evt);
|
||||
bool on(const sig_ev::process_check& evt);
|
||||
bool on(const sig_ev::notify_change& evt);
|
||||
bool on(const sig_ev::update& evt);
|
||||
bool on(const sig_ev::exit_terminate& evt);
|
||||
bool on(const sig_ev::exit_reload& evt);
|
||||
bool on(const sig_ev::check_state& evt);
|
||||
bool on(const sig_ui::button_press& evt);
|
||||
bool on(const sig_ipc::process_action& evt);
|
||||
bool on(const sig_ipc::process_command& evt);
|
||||
|
|
|
@ -92,10 +92,11 @@ namespace signals {
|
|||
}
|
||||
|
||||
namespace eventqueue {
|
||||
DEFINE_VALUE_SIGNAL(1, process_quit, event);
|
||||
DEFINE_VALUE_SIGNAL(2, process_update, event);
|
||||
DEFINE_SIGNAL(3, process_check);
|
||||
DEFINE_SIGNAL(4, process_broadcast);
|
||||
DEFINE_SIGNAL(1, exit_terminate);
|
||||
DEFINE_SIGNAL(2, exit_reload);
|
||||
DEFINE_SIGNAL(3, notify_change);
|
||||
DEFINE_SIGNAL(4, check_state);
|
||||
DEFINE_SIGNAL(5, update);
|
||||
}
|
||||
|
||||
namespace ipc {
|
||||
|
|
|
@ -6,10 +6,11 @@ POLYBAR_NS
|
|||
|
||||
namespace signals {
|
||||
namespace eventqueue {
|
||||
struct process_quit;
|
||||
struct process_update;
|
||||
struct process_check;
|
||||
struct process_broadcast;
|
||||
struct exit_terminate;
|
||||
struct exit_reload;
|
||||
struct notify_change;
|
||||
struct check_state;
|
||||
struct update;
|
||||
}
|
||||
namespace ipc {
|
||||
struct process_command;
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
enum class event_type : uint8_t {
|
||||
NONE = 0,
|
||||
UPDATE,
|
||||
|
@ -16,6 +20,10 @@ struct event {
|
|||
};
|
||||
|
||||
namespace {
|
||||
inline bool operator==(uint8_t id, event_type type) {
|
||||
return id == static_cast<uint8_t>(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create QUIT event
|
||||
*/
|
||||
|
@ -44,3 +52,5 @@ namespace {
|
|||
return event{static_cast<uint8_t>(event_type::CHECK)};
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace modules {
|
|||
CAST_MOD(Impl)->wakeup();
|
||||
CAST_MOD(Impl)->teardown();
|
||||
|
||||
m_sig.emit(sig_ev::process_check{});
|
||||
m_sig.emit(sig_ev::check_state{});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace modules {
|
|||
template <typename Impl>
|
||||
void module<Impl>::broadcast() {
|
||||
m_changed = true;
|
||||
m_sig.emit(sig_ev::process_broadcast{});
|
||||
m_sig.emit(sig_ev::notify_change{});
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
|
|
|
@ -188,7 +188,7 @@ bool controller::run(bool writeback) {
|
|||
read_events();
|
||||
|
||||
if (m_event_thread.joinable()) {
|
||||
m_queue.enqueue(make_quit_evt(static_cast<bool>(g_reload)));
|
||||
enqueue(make_quit_evt(static_cast<bool>(g_reload)));
|
||||
m_event_thread.join();
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ void controller::read_events() {
|
|||
void controller::process_eventqueue() {
|
||||
m_log.info("Eventqueue worker (thread-id=%lu)", this_thread::get_id());
|
||||
|
||||
m_queue.enqueue(make_update_evt(true));
|
||||
enqueue(make_update_evt(true));
|
||||
|
||||
while (!g_terminate) {
|
||||
event evt{};
|
||||
|
@ -320,22 +320,26 @@ void controller::process_eventqueue() {
|
|||
|
||||
if (g_terminate) {
|
||||
break;
|
||||
} else if (evt.type == static_cast<uint8_t>(event_type::QUIT)) {
|
||||
m_sig.emit(sig_ev::process_quit{make_quit_evt(evt.flag)});
|
||||
} else if (evt.type == static_cast<uint8_t>(event_type::INPUT)) {
|
||||
} else if (evt.type == event_type::QUIT) {
|
||||
if (evt.flag) {
|
||||
on(sig_ev::exit_reload{});
|
||||
} else {
|
||||
on(sig_ev::exit_terminate{});
|
||||
}
|
||||
} else if (evt.type == event_type::INPUT) {
|
||||
process_inputdata();
|
||||
} else {
|
||||
event next{};
|
||||
size_t swallowed{0};
|
||||
while (swallowed++ < m_swallow_limit && m_queue.wait_dequeue_timed(next, m_swallow_update)) {
|
||||
if (next.type == static_cast<uint8_t>(event_type::QUIT)) {
|
||||
if (next.type == event_type::QUIT) {
|
||||
evt = next;
|
||||
break;
|
||||
} else if (next.type == static_cast<uint8_t>(event_type::INPUT)) {
|
||||
} else if (next.type == event_type::INPUT) {
|
||||
evt = next;
|
||||
break;
|
||||
} else if (evt.type != next.type) {
|
||||
m_queue.try_enqueue(move(next));
|
||||
enqueue(move(next));
|
||||
break;
|
||||
} else {
|
||||
m_log.trace_x("controller: Swallowing event within timeframe");
|
||||
|
@ -343,14 +347,18 @@ void controller::process_eventqueue() {
|
|||
}
|
||||
}
|
||||
|
||||
if (evt.type == static_cast<uint8_t>(event_type::UPDATE)) {
|
||||
m_sig.emit(sig_ev::process_update{make_update_evt(evt.flag)});
|
||||
} else if (evt.type == static_cast<uint8_t>(event_type::INPUT)) {
|
||||
if (evt.type == event_type::UPDATE) {
|
||||
on(sig_ev::update{});
|
||||
} else if (evt.type == event_type::INPUT) {
|
||||
process_inputdata();
|
||||
} else if (evt.type == static_cast<uint8_t>(event_type::QUIT)) {
|
||||
m_sig.emit(sig_ev::process_quit{make_quit_evt(evt.flag)});
|
||||
} else if (evt.type == static_cast<uint8_t>(event_type::CHECK)) {
|
||||
m_sig.emit(sig_ev::process_check{});
|
||||
} else if (evt.type == event_type::QUIT) {
|
||||
if (evt.flag) {
|
||||
on(sig_ev::exit_reload{});
|
||||
} else {
|
||||
on(sig_ev::exit_terminate{});
|
||||
}
|
||||
} else if (evt.type == event_type::CHECK) {
|
||||
on(sig_ev::check_state{});
|
||||
} else {
|
||||
m_log.warn("Unknown event type for enqueued event (%d)", evt.type);
|
||||
}
|
||||
|
@ -394,7 +402,7 @@ void controller::process_inputdata() {
|
|||
/**
|
||||
* Process broadcast events
|
||||
*/
|
||||
bool controller::on(const sig_ev::process_broadcast&) {
|
||||
bool controller::on(const sig_ev::notify_change&) {
|
||||
enqueue(make_update_evt(false));
|
||||
return true;
|
||||
}
|
||||
|
@ -402,9 +410,7 @@ bool controller::on(const sig_ev::process_broadcast&) {
|
|||
/**
|
||||
* Process eventqueue update event
|
||||
*/
|
||||
bool controller::on(const sig_ev::process_update& evt) {
|
||||
bool force{evt.data()->flag};
|
||||
|
||||
bool controller::on(const sig_ev::update&) {
|
||||
const bar_settings& bar{m_bar->settings()};
|
||||
string contents;
|
||||
string separator{bar.separator};
|
||||
|
@ -475,7 +481,7 @@ bool controller::on(const sig_ev::process_update& evt) {
|
|||
|
||||
try {
|
||||
if (!m_writeback) {
|
||||
m_bar->parse(move(contents), force);
|
||||
m_bar->parse(move(contents), false);
|
||||
} else {
|
||||
std::cout << contents << std::endl;
|
||||
}
|
||||
|
@ -487,17 +493,25 @@ bool controller::on(const sig_ev::process_update& evt) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Process eventqueue quit event
|
||||
* Process eventqueue terminate event
|
||||
*/
|
||||
bool controller::on(const sig_ev::process_quit& evt) {
|
||||
raise((*evt()).flag ? SIGUSR1 : SIGALRM);
|
||||
bool controller::on(const sig_ev::exit_terminate&) {
|
||||
raise(SIGALRM);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process eventqueue reload event
|
||||
*/
|
||||
bool controller::on(const sig_ev::exit_reload&) {
|
||||
raise(SIGUSR1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process eventqueue check event
|
||||
*/
|
||||
bool controller::on(const sig_ev::process_check&) {
|
||||
bool controller::on(const sig_ev::check_state&) {
|
||||
for (const auto& block : m_modules) {
|
||||
for (const auto& module : block.second) {
|
||||
if (module->running()) {
|
||||
|
@ -506,7 +520,7 @@ bool controller::on(const sig_ev::process_check&) {
|
|||
}
|
||||
}
|
||||
m_log.warn("No running modules...");
|
||||
enqueue(make_quit_evt(false));
|
||||
on(exit_terminate{});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ void screen::handle(const evt::randr_screen_change_notify& evt) {
|
|||
}
|
||||
|
||||
m_log.warn("randr_screen_change_notify (%ux%u)... reloading", evt->width, evt->height);
|
||||
m_sig.emit(process_quit{make_quit_evt(true)});
|
||||
m_sig.emit(exit_reload{});
|
||||
m_sigraised = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ void tray_manager::deactivate(bool clear_selection) {
|
|||
|
||||
m_connection.flush();
|
||||
|
||||
m_sig.emit(process_update{make_update_evt(true)});
|
||||
m_sig.emit(notify_change{});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -325,7 +325,7 @@ void tray_manager::reconfigure() {
|
|||
|
||||
m_connection.flush();
|
||||
|
||||
m_sig.emit(process_update{make_update_evt(true)});
|
||||
m_sig.emit(notify_change{});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,8 +13,11 @@ namespace xutils {
|
|||
xcb_connection_t* get_connection() {
|
||||
static xcb_connection_t* connection;
|
||||
if (!connection) {
|
||||
XSetEventQueueOwner(xlib::get_display(), XCBOwnsEventQueue);
|
||||
connection = XGetXCBConnection(xlib::get_display());
|
||||
auto display = xlib::get_display();
|
||||
if (display != nullptr) {
|
||||
XSetEventQueueOwner(display, XCBOwnsEventQueue);
|
||||
connection = XGetXCBConnection(xlib::get_display());
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue