refactor(signals): Use full namespace

This commit is contained in:
Michael Carlberg 2017-01-12 16:34:14 +01:00
parent da9f1d90f4
commit f72ddf9294
7 changed files with 56 additions and 76 deletions

View File

@ -15,10 +15,7 @@
POLYBAR_NS
namespace chrono = std::chrono;
using namespace std::chrono_literals;
// fwd
// fwd {{{
class config;
class connection;
class logger;
@ -28,14 +25,12 @@ class screen;
class signal_emitter;
class taskqueue;
class tray_manager;
namespace sig_ui = signals::ui;
namespace sig_ev = signals::eventqueue;
// }}}
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify,
evt::leave_notify, evt::destroy_notify, evt::client_message>,
public signal_receiver<SIGN_PRIORITY_BAR, sig_ev::start, sig_ui::tick, sig_ui::shade_window, sig_ui::unshade_window,
sig_ui::dim_window> {
public signal_receiver<SIGN_PRIORITY_BAR, signals::eventqueue::start, signals::ui::tick, signals::ui::shade_window, signals::ui::unshade_window,
signals::ui::dim_window> {
public:
using make_type = unique_ptr<bar>;
static make_type make(bool only_initialize_values = false);
@ -63,11 +58,11 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
void handle(const evt::expose& evt);
void handle(const evt::property_notify& evt);
bool on(const sig_ev::start&);
bool on(const sig_ui::unshade_window&);
bool on(const sig_ui::shade_window&);
bool on(const sig_ui::tick&);
bool on(const sig_ui::dim_window&);
bool on(const signals::eventqueue::start&);
bool on(const signals::ui::unshade_window&);
bool on(const signals::ui::shade_window&);
bool on(const signals::ui::tick&);
bool on(const signals::ui::dim_window&);
private:
connection& m_connection;

View File

@ -25,28 +25,18 @@ class inotify_watch;
class ipc;
class logger;
class signal_emitter;
namespace modules {
struct module_interface;
class input_handler;
}
using module_t = unique_ptr<modules::module_interface>;
using modulemap_t = std::map<alignment, vector<module_t>>;
// }}}
using std::thread;
namespace chrono = std::chrono;
using namespace std::chrono_literals;
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::exit_terminate, sig_ev::exit_reload,
sig_ev::notify_change, sig_ev::notify_forcechange, sig_ev::check_state, sig_ipc::action,
sig_ipc::command, sig_ipc::hook, sig_ui::button_press> {
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eventqueue::exit_terminate, signals::eventqueue::exit_reload,
signals::eventqueue::notify_change, signals::eventqueue::notify_forcechange, signals::eventqueue::check_state, signals::ipc::action,
signals::ipc::command, signals::ipc::hook, signals::ui::button_press> {
public:
using make_type = unique_ptr<controller>;
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
@ -66,15 +56,15 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
void process_inputdata();
bool process_update(bool force);
bool on(const sig_ev::notify_change& evt);
bool on(const sig_ev::notify_forcechange& 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::action& evt);
bool on(const sig_ipc::command& evt);
bool on(const sig_ipc::hook& evt);
bool on(const signals::eventqueue::notify_change& evt);
bool on(const signals::eventqueue::notify_forcechange& evt);
bool on(const signals::eventqueue::exit_terminate& evt);
bool on(const signals::eventqueue::exit_reload& evt);
bool on(const signals::eventqueue::check_state& evt);
bool on(const signals::ui::button_press& evt);
bool on(const signals::ipc::action& evt);
bool on(const signals::ipc::command& evt);
bool on(const signals::ipc::hook& evt);
private:
connection& m_connection;
@ -96,8 +86,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
/**
* @brief Internal event queue
*/
using queue_t = moodycamel::BlockingConcurrentQueue<event>;
queue_t m_queue;
moodycamel::BlockingConcurrentQueue<event> m_queue;
/**
* @brief Loaded modules
@ -117,17 +106,17 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
/**
* @brief Time to wait for subsequent events
*/
chrono::milliseconds m_swallow_update{10ms};
std::chrono::milliseconds m_swallow_update{10};
/**
* @brief Time to throttle input events
*/
chrono::milliseconds m_swallow_input{30ms};
std::chrono::milliseconds m_swallow_input{30};
/**
* @brief Time of last handled input event
*/
chrono::time_point<chrono::system_clock, chrono::milliseconds> m_lastinput;
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> m_lastinput;
/**
* @brief Input data
@ -137,7 +126,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
/**
* @brief Thread for the eventqueue loop
*/
thread m_event_thread;
std::thread m_event_thread;
};
POLYBAR_NS_END

View File

@ -6,8 +6,6 @@
POLYBAR_NS
namespace sig_ev = signals::eventqueue;
namespace modules {
// module<Impl> public {{{
@ -61,7 +59,7 @@ namespace modules {
CAST_MOD(Impl)->wakeup();
CAST_MOD(Impl)->teardown();
m_sig.emit(sig_ev::check_state{});
m_sig.emit(signals::eventqueue::check_state{});
}
}
@ -91,7 +89,7 @@ namespace modules {
template <typename Impl>
void module<Impl>::broadcast() {
m_changed = true;
m_sig.emit(sig_ev::notify_change{});
m_sig.emit(signals::eventqueue::notify_change{});
}
template <typename Impl>

View File

@ -477,7 +477,7 @@ void bar::handle(const evt::destroy_notify& evt) {
void bar::handle(const evt::enter_notify&) {
#if DEBUG
if (m_opts.origin == edge::TOP) {
m_taskqueue->defer_unique("window-hover", 25ms, [&](size_t) { m_sig.emit(sig_ui::unshade_window{}); });
m_taskqueue->defer_unique("window-hover", 25ms, [&](size_t) { m_sig.emit(signals::ui::unshade_window{}); });
return;
}
#endif
@ -501,7 +501,7 @@ void bar::handle(const evt::enter_notify&) {
void bar::handle(const evt::leave_notify&) {
#if DEBUG
if (m_opts.origin == edge::TOP) {
m_taskqueue->defer_unique("window-hover", 25ms, [&](size_t) { m_sig.emit(sig_ui::shade_window{}); });
m_taskqueue->defer_unique("window-hover", 25ms, [&](size_t) { m_sig.emit(signals::ui::shade_window{}); });
return;
}
#endif
@ -614,14 +614,14 @@ void bar::handle(const evt::property_notify& evt) {
}
}
bool bar::on(const sig_ev::start&) {
bool bar::on(const signals::eventqueue::start&) {
m_log.trace("bar: Setup tray manager");
m_tray->setup(static_cast<const bar_settings&>(m_opts));
broadcast_visibility();
return true;
}
bool bar::on(const sig_ui::unshade_window&) {
bool bar::on(const signals::ui::unshade_window&) {
m_opts.shaded = false;
m_opts.shade_size.w = m_opts.size.w;
m_opts.shade_size.h = m_opts.size.h;
@ -635,7 +635,7 @@ bool bar::on(const sig_ui::unshade_window&) {
m_taskqueue->defer_unique("window-shade", 25ms,
[&](size_t remaining) {
if (!m_opts.shaded) {
m_sig.emit(sig_ui::tick{});
m_sig.emit(signals::ui::tick{});
}
if (!remaining) {
m_renderer->flush(false);
@ -650,7 +650,7 @@ bool bar::on(const sig_ui::unshade_window&) {
return true;
}
bool bar::on(const sig_ui::shade_window&) {
bool bar::on(const signals::ui::shade_window&) {
taskqueue::deferred::duration offset{2000ms};
if (!m_opts.shaded && m_opts.shade_size.h != m_opts.size.h) {
@ -674,7 +674,7 @@ bool bar::on(const sig_ui::shade_window&) {
m_taskqueue->defer_unique("window-shade", 25ms,
[&](size_t remaining) {
if (m_opts.shaded) {
m_sig.emit(sig_ui::tick{});
m_sig.emit(signals::ui::tick{});
}
if (!remaining) {
m_renderer->flush(false);
@ -689,7 +689,7 @@ bool bar::on(const sig_ui::shade_window&) {
return true;
}
bool bar::on(const sig_ui::tick&) {
bool bar::on(const signals::ui::tick&) {
auto geom = m_connection.get_geometry(m_opts.window);
if (geom->y == m_opts.shade_pos.y && geom->height == m_opts.shade_size.h) {
return false;
@ -723,7 +723,7 @@ bool bar::on(const sig_ui::tick&) {
return false;
}
bool bar::on(const sig_ui::dim_window& sig) {
bool bar::on(const signals::ui::dim_window& sig) {
m_opts.dimmed = sig.cast() != 1.0;
set_wm_window_opacity(m_connection, m_opts.window, sig.cast() * 0xFFFFFFFF);
m_connection.flush();

View File

@ -326,9 +326,9 @@ void controller::process_eventqueue() {
break;
} else if (evt.type == event_type::QUIT) {
if (evt.flag) {
on(sig_ev::exit_reload{});
on(signals::eventqueue::exit_reload{});
} else {
on(sig_ev::exit_terminate{});
on(signals::eventqueue::exit_terminate{});
}
} else if (evt.type == event_type::INPUT) {
process_inputdata();
@ -359,12 +359,12 @@ void controller::process_eventqueue() {
process_inputdata();
} else if (evt.type == event_type::QUIT) {
if (evt.flag) {
on(sig_ev::exit_reload{});
on(signals::eventqueue::exit_reload{});
} else {
on(sig_ev::exit_terminate{});
on(signals::eventqueue::exit_terminate{});
}
} else if (evt.type == event_type::CHECK) {
on(sig_ev::check_state{});
on(signals::eventqueue::check_state{});
} else {
m_log.warn("Unknown event type for enqueued event (%d)", evt.type);
}
@ -497,21 +497,21 @@ bool controller::process_update(bool force) {
/**
* Process broadcast events
*/
bool controller::on(const sig_ev::notify_change&) {
bool controller::on(const signals::eventqueue::notify_change&) {
return enqueue(make_update_evt(false));
}
/**
* Process forced broadcast events
*/
bool controller::on(const sig_ev::notify_forcechange&) {
bool controller::on(const signals::eventqueue::notify_forcechange&) {
return enqueue(make_update_evt(true));
}
/**
* Process eventqueue terminate event
*/
bool controller::on(const sig_ev::exit_terminate&) {
bool controller::on(const signals::eventqueue::exit_terminate&) {
raise(SIGALRM);
return true;
}
@ -519,7 +519,7 @@ bool controller::on(const sig_ev::exit_terminate&) {
/**
* Process eventqueue reload event
*/
bool controller::on(const sig_ev::exit_reload&) {
bool controller::on(const signals::eventqueue::exit_reload&) {
raise(SIGUSR1);
return true;
}
@ -527,7 +527,7 @@ bool controller::on(const sig_ev::exit_reload&) {
/**
* Process eventqueue check event
*/
bool controller::on(const sig_ev::check_state&) {
bool controller::on(const signals::eventqueue::check_state&) {
for (const auto& block : m_modules) {
for (const auto& module : block.second) {
if (module->running()) {
@ -536,14 +536,14 @@ bool controller::on(const sig_ev::check_state&) {
}
}
m_log.warn("No running modules...");
on(sig_ev::exit_terminate{});
on(signals::eventqueue::exit_terminate{});
return true;
}
/**
* Process ui button press event
*/
bool controller::on(const sig_ui::button_press& evt) {
bool controller::on(const signals::ui::button_press& evt) {
string input{evt.cast()};
if (input.empty()) {
@ -558,7 +558,7 @@ bool controller::on(const sig_ui::button_press& evt) {
/**
* Process ipc action messages
*/
bool controller::on(const sig_ipc::action& evt) {
bool controller::on(const signals::ipc::action& evt) {
string action{evt.cast()};
if (action.empty()) {
@ -574,7 +574,7 @@ bool controller::on(const sig_ipc::action& evt) {
/**
* Process ipc command messages
*/
bool controller::on(const sig_ipc::command& evt) {
bool controller::on(const signals::ipc::command& evt) {
string command{evt.cast()};
if (command.empty()) {
@ -595,7 +595,7 @@ bool controller::on(const sig_ipc::command& evt) {
/**
* Process ipc hook messages
*/
bool controller::on(const sig_ipc::hook& evt) {
bool controller::on(const signals::ipc::hook& evt) {
string hook{evt.cast()};
for (const auto& block : m_modules) {

View File

@ -11,8 +11,6 @@
POLYBAR_NS
namespace sig_ipc = signals::ipc;
/**
* Create instance
*/
@ -61,11 +59,11 @@ void ipc::receive_message() {
string payload{string_util::trim(string{buffer}, '\n')};
if (payload.find(ipc_command::prefix) == 0) {
m_sig.emit(sig_ipc::command{payload.substr(strlen(ipc_command::prefix))});
m_sig.emit(signals::ipc::command{payload.substr(strlen(ipc_command::prefix))});
} else if (payload.find(ipc_hook::prefix) == 0) {
m_sig.emit(sig_ipc::hook{payload.substr(strlen(ipc_hook::prefix))});
m_sig.emit(signals::ipc::hook{payload.substr(strlen(ipc_hook::prefix))});
} else if (payload.find(ipc_action::prefix) == 0) {
m_sig.emit(sig_ipc::action{payload.substr(strlen(ipc_action::prefix))});
m_sig.emit(signals::ipc::action{payload.substr(strlen(ipc_action::prefix))});
} else if (!payload.empty()) {
m_log.warn("Received unknown ipc message: (payload=%s)", payload);
}

View File

@ -1,5 +1,5 @@
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <thread>
#include <utility>