Merge pull request #906 from JordanL2/master
Fix for syncing idle inhibitor across outputspull/918/head
commit
c21e0f6cf3
|
@ -19,7 +19,6 @@ class ALabel : public AModule {
|
|||
protected:
|
||||
Gtk::Label label_;
|
||||
std::string format_;
|
||||
std::string click_param;
|
||||
const std::chrono::seconds interval_;
|
||||
bool alt_ = false;
|
||||
std::string default_format_;
|
||||
|
|
|
@ -12,12 +12,13 @@ class IdleInhibitor : public ALabel {
|
|||
IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~IdleInhibitor();
|
||||
auto update() -> void;
|
||||
static std::list<waybar::AModule*> modules;
|
||||
static bool status;
|
||||
|
||||
private:
|
||||
bool handleToggle(GdkEventButton* const& e);
|
||||
|
||||
const Bar& bar_;
|
||||
std::string status_;
|
||||
struct zwp_idle_inhibitor_v1* idle_inhibitor_;
|
||||
int pid_;
|
||||
};
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
#include "modules/idle_inhibitor.hpp"
|
||||
#include "util/command.hpp"
|
||||
|
||||
std::list<waybar::AModule*> waybar::modules::IdleInhibitor::modules;
|
||||
bool waybar::modules::IdleInhibitor::status = false;
|
||||
|
||||
waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar,
|
||||
const Json::Value& config)
|
||||
: ALabel(config, "idle_inhibitor", id, "{status}"),
|
||||
bar_(bar),
|
||||
status_("deactivated"),
|
||||
idle_inhibitor_(nullptr),
|
||||
pid_(-1) {
|
||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
event_box_.signal_button_press_event().connect(
|
||||
sigc::mem_fun(*this, &IdleInhibitor::handleToggle));
|
||||
|
||||
// Add this to the modules list
|
||||
waybar::modules::IdleInhibitor::modules.push_back(this);
|
||||
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
|
@ -19,6 +25,10 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
|||
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||
idle_inhibitor_ = nullptr;
|
||||
}
|
||||
|
||||
// Remove this from the modules list
|
||||
waybar::modules::IdleInhibitor::modules.remove(this);
|
||||
|
||||
if (pid_ != -1) {
|
||||
kill(-pid_, 9);
|
||||
pid_ = -1;
|
||||
|
@ -26,11 +36,27 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
|||
}
|
||||
|
||||
auto waybar::modules::IdleInhibitor::update() -> void {
|
||||
// Check status
|
||||
if (status) {
|
||||
label_.get_style_context()->remove_class("deactivated");
|
||||
if (idle_inhibitor_ == nullptr) {
|
||||
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
||||
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
||||
}
|
||||
} else {
|
||||
label_.get_style_context()->remove_class("activated");
|
||||
if (idle_inhibitor_ != nullptr) {
|
||||
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||
idle_inhibitor_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string status_text = status ? "activated" : "deactivated";
|
||||
label_.set_markup(
|
||||
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
|
||||
label_.get_style_context()->add_class(status_);
|
||||
fmt::format(format_, fmt::arg("status", status_text), fmt::arg("icon", getIcon(0, status_text))));
|
||||
label_.get_style_context()->add_class(status_text);
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(status_);
|
||||
label_.set_tooltip_text(status_text);
|
||||
}
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
|
@ -38,18 +64,16 @@ auto waybar::modules::IdleInhibitor::update() -> void {
|
|||
|
||||
bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
|
||||
if (e->button == 1) {
|
||||
label_.get_style_context()->remove_class(status_);
|
||||
if (idle_inhibitor_ != nullptr) {
|
||||
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||
idle_inhibitor_ = nullptr;
|
||||
status_ = "deactivated";
|
||||
} else {
|
||||
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
||||
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
||||
status_ = "activated";
|
||||
status = !status;
|
||||
|
||||
// Make all other idle inhibitor modules update
|
||||
for (auto const& module : waybar::modules::IdleInhibitor::modules) {
|
||||
if (module != this) {
|
||||
module->update();
|
||||
}
|
||||
click_param = status_;
|
||||
}
|
||||
}
|
||||
|
||||
ALabel::handleToggle(e);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue