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