2019-02-17 14:27:54 +00:00
|
|
|
#include "modules/idle_inhibitor.hpp"
|
2019-03-03 21:02:34 +00:00
|
|
|
#include "util/command.hpp"
|
2019-02-17 14:27:54 +00:00
|
|
|
|
|
|
|
waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config)
|
|
|
|
: ALabel(config, "{status}"), bar_(bar), status_("deactivated"), idle_inhibitor_(nullptr)
|
|
|
|
{
|
|
|
|
label_.set_name("idle_inhibitor");
|
|
|
|
if (!id.empty()) {
|
|
|
|
label_.get_style_context()->add_class(id);
|
|
|
|
}
|
|
|
|
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
|
|
|
event_box_.signal_button_press_event().connect(
|
2019-03-03 21:02:34 +00:00
|
|
|
sigc::mem_fun(*this, &IdleInhibitor::handleToggle));
|
2019-02-17 14:27:54 +00:00
|
|
|
dp.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
waybar::modules::IdleInhibitor::~IdleInhibitor()
|
|
|
|
{
|
|
|
|
if(idle_inhibitor_) {
|
|
|
|
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
|
|
|
idle_inhibitor_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto waybar::modules::IdleInhibitor::update() -> void
|
|
|
|
{
|
|
|
|
label_.set_markup(
|
|
|
|
fmt::format(format_, fmt::arg("status", status_),
|
|
|
|
fmt::arg("icon", getIcon(0, status_))));
|
2019-03-10 09:29:06 +00:00
|
|
|
label_.get_style_context()->add_class(status_);
|
2019-02-22 15:58:36 +00:00
|
|
|
if(tooltipEnabled()) {
|
|
|
|
label_.set_tooltip_text(status_);
|
|
|
|
}
|
2019-02-17 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:02:34 +00:00
|
|
|
bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
|
|
|
|
if (e->button == 1) {
|
2019-03-10 09:29:06 +00:00
|
|
|
label_.get_style_context()->remove_class(status_);
|
2019-02-17 14:27:54 +00:00
|
|
|
if (idle_inhibitor_) {
|
|
|
|
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
|
|
|
idle_inhibitor_ = nullptr;
|
|
|
|
status_ = "deactivated";
|
|
|
|
} else {
|
|
|
|
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
|
|
|
bar_.client.idle_inhibit_manager, bar_.surface);
|
|
|
|
status_ = "activated";
|
|
|
|
}
|
2019-03-03 21:02:34 +00:00
|
|
|
if (config_["on-click"].isString() && e->button == 1) {
|
|
|
|
waybar::util::command::forkExec(config_["on-click"].asString());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ALabel::handleToggle(e);
|
2019-02-17 14:27:54 +00:00
|
|
|
}
|
2019-03-03 21:02:34 +00:00
|
|
|
|
2019-02-17 14:27:54 +00:00
|
|
|
dp.emit();
|
|
|
|
return true;
|
|
|
|
}
|