refactor(modules): prefer sigc::mem_fun

This commit is contained in:
Alexis 2018-08-11 02:40:13 +02:00
parent 14053d61fc
commit 04183dc696
8 changed files with 9 additions and 21 deletions

View File

@ -22,7 +22,7 @@ waybar::modules::Battery::Battery(Json::Value config)
_label.get_style_context()->add_class("battery"); _label.get_style_context()->add_class("battery");
int interval = _config["interval"] ? _config["inveral"].asInt() : 1; int interval = _config["interval"] ? _config["inveral"].asInt() : 1;
_thread = [this, interval] { _thread = [this, interval] {
update(); Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Battery::update));
_thread.sleep_for(chrono::seconds(interval)); _thread.sleep_for(chrono::seconds(interval));
}; };
} }

View File

@ -5,9 +5,7 @@ waybar::modules::Clock::Clock(Json::Value config)
{ {
_label.get_style_context()->add_class("clock"); _label.get_style_context()->add_class("clock");
_thread = [this] { _thread = [this] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
update();
});
auto now = waybar::chrono::clock::now(); auto now = waybar::chrono::clock::now();
auto timeout = auto timeout =
std::chrono::floor<std::chrono::minutes>(now + std::chrono::minutes(1)); std::chrono::floor<std::chrono::minutes>(now + std::chrono::minutes(1));

View File

@ -6,9 +6,7 @@ waybar::modules::Cpu::Cpu(Json::Value config)
_label.get_style_context()->add_class("cpu"); _label.get_style_context()->add_class("cpu");
int interval = _config["interval"] ? _config["inveral"].asInt() : 10; int interval = _config["interval"] ? _config["inveral"].asInt() : 10;
_thread = [this, interval] { _thread = [this, interval] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));
update();
});
_thread.sleep_for(chrono::seconds(interval)); _thread.sleep_for(chrono::seconds(interval));
}; };
}; };

View File

@ -10,9 +10,7 @@ waybar::modules::Custom::Custom(std::string name, Json::Value config)
} }
int interval = _config["interval"] ? _config["inveral"].asInt() : 30; int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
_thread = [this, interval] { _thread = [this, interval] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Custom::update));
update();
});
_thread.sleep_for(chrono::seconds(interval)); _thread.sleep_for(chrono::seconds(interval));
}; };
}; };

View File

@ -6,9 +6,7 @@ waybar::modules::Memory::Memory(Json::Value config)
_label.get_style_context()->add_class("memory"); _label.get_style_context()->add_class("memory");
int interval = _config["interval"] ? _config["inveral"].asInt() : 30; int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
_thread = [this, interval] { _thread = [this, interval] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Memory::update));
update();
});
_thread.sleep_for(chrono::seconds(interval)); _thread.sleep_for(chrono::seconds(interval));
}; };
}; };

View File

@ -6,9 +6,7 @@ waybar::modules::Network::Network(Json::Value config)
_label.get_style_context()->add_class("network"); _label.get_style_context()->add_class("network");
int interval = _config["interval"] ? _config["inveral"].asInt() : 30; int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
_thread = [this, interval] { _thread = [this, interval] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));
update();
});
_thread.sleep_for(chrono::minutes(1)); _thread.sleep_for(chrono::minutes(1));
}; };
}; };

View File

@ -80,7 +80,7 @@ void waybar::modules::Pulseaudio::_sinkInfoCb(pa_context *context,
pa->_volume = volume * 100.0f; pa->_volume = volume * 100.0f;
pa->_muted = i->mute; pa->_muted = i->mute;
pa->_desc = i->description; pa->_desc = i->description;
pa->update(); Glib::signal_idle().connect_once(sigc::mem_fun(*pa, &Pulseaudio::update));
} }
} }

View File

@ -17,9 +17,7 @@ waybar::modules::Workspaces::Workspaces(Bar &bar)
return; return;
} }
_thread = [this] { _thread = [this] {
Glib::signal_idle().connect_once([this] { Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Workspaces::update));
update();
});
_thread.sleep_for(chrono::milliseconds(250)); _thread.sleep_for(chrono::milliseconds(250));
}; };
} }
@ -95,7 +93,7 @@ Json::Value waybar::modules::Workspaces::_getWorkspaces()
delete reader; delete reader;
if (!res) { if (!res) {
std::cerr << err << std::endl; std::cerr << err << std::endl;
return nullptr; return root;
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;