refactor: prefer static methods

This commit is contained in:
Alexis
2018-08-09 20:22:01 +02:00
parent 03132bd219
commit 23f48cb8b7
8 changed files with 152 additions and 148 deletions

View File

@@ -1,28 +1,8 @@
#include "modules/workspaces.hpp"
#include "ipc/client.hpp"
static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
if (o->thread) {
delete o->thread;
o->thread = nullptr;
}
}
static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
if (!o->thread) {
o->updateThread();
}
}
static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
.idle = handle_idle,
.resumed = handle_resume,
};
waybar::modules::Workspaces::Workspaces(Bar &bar)
: thread(nullptr), _bar(bar), _box(Gtk::manage(new Gtk::Box))
: _bar(bar), _thread(nullptr), _box(Gtk::manage(new Gtk::Box))
{
_box->get_style_context()->add_class("workspaces");
std::string socketPath = get_socketpath();
@@ -34,17 +14,13 @@ waybar::modules::Workspaces::Workspaces(Bar &bar)
_idle_timer =
org_kde_kwin_idle_get_idle_timeout(_bar.client.idle_manager,
_bar.client.seat, 10000); // 10 seconds
static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
.idle = _handle_idle,
.resumed = _handle_resume,
};
org_kde_kwin_idle_timeout_add_listener(_idle_timer,
&idle_timer_listener, this);
updateThread();
}
void waybar::modules::Workspaces::updateThread()
{
thread = new waybar::util::SleeperThread([this] {
update();
thread->sleep_for(waybar::chrono::milliseconds(250));
});
_updateThread();
}
auto waybar::modules::Workspaces::update() -> void
@@ -79,6 +55,33 @@ auto waybar::modules::Workspaces::update() -> void
}
}
void waybar::modules::Workspaces::_updateThread()
{
_thread = new waybar::util::SleeperThread([this] {
update();
_thread->sleep_for(waybar::chrono::milliseconds(250));
});
}
void waybar::modules::Workspaces::_handle_idle(void *data,
struct org_kde_kwin_idle_timeout *timer) {
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
if (o->_thread) {
delete o->_thread;
o->_thread = nullptr;
std::cout << "IDLE" << std::endl;
}
}
void waybar::modules::Workspaces::_handle_resume(void *data,
struct org_kde_kwin_idle_timeout *timer) {
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
if (!o->_thread) {
o->_updateThread();
std::cout << "RESUME" << std::endl;
}
}
void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
{
auto pair = _buttons.emplace(node["num"].asInt(), node["name"].asString());