mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Since idle_inhibitor's have a surface, we should have one for each inhibitor module. Therefore, the status is stored on the Client, and all modules create or destroy their inhibitors depending on Client's idle_inhibitor_status. Also, when modules are destroyed they remove themselves from Client's idle_inhibitor_modules.
This commit is contained in:
parent
aa4fc3dd29
commit
4889e655eb
@ -23,8 +23,8 @@ class Client {
|
|||||||
struct zxdg_output_manager_v1 * xdg_output_manager = nullptr;
|
struct zxdg_output_manager_v1 * xdg_output_manager = nullptr;
|
||||||
|
|
||||||
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
|
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
|
||||||
struct zwp_idle_inhibitor_v1* idle_inhibitor;
|
std::list<waybar::AModule*> idle_inhibitor_modules;
|
||||||
std::vector<waybar::AModule*> idle_inhibitor_modules;
|
std::string idle_inhibitor_status = "deactivated";
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Bar>> bars;
|
std::vector<std::unique_ptr<Bar>> bars;
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ 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;
|
||||||
|
struct zwp_idle_inhibitor_v1* idle_inhibitor_ = nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool handleToggle(GdkEventButton* const& e);
|
bool handleToggle(GdkEventButton* const& e);
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
std::string status_;
|
|
||||||
int pid_;
|
int pid_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,20 +5,26 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const 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"),
|
|
||||||
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 Client's idle_inhibitor_modules
|
||||||
waybar::Client::inst()->idle_inhibitor_modules.push_back(this);
|
waybar::Client::inst()->idle_inhibitor_modules.push_back(this);
|
||||||
|
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
||||||
if (waybar::Client::inst()->idle_inhibitor != nullptr) {
|
if (idle_inhibitor_ != nullptr) {
|
||||||
zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor);
|
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||||
waybar::Client::inst()->idle_inhibitor = nullptr;
|
idle_inhibitor_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove this from the Client's idle_inhibitor_modules
|
||||||
|
waybar::Client::inst()->idle_inhibitor_modules.remove(this);
|
||||||
|
|
||||||
if (pid_ != -1) {
|
if (pid_ != -1) {
|
||||||
kill(-pid_, 9);
|
kill(-pid_, 9);
|
||||||
pid_ = -1;
|
pid_ = -1;
|
||||||
@ -27,17 +33,24 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
|||||||
|
|
||||||
auto waybar::modules::IdleInhibitor::update() -> void {
|
auto waybar::modules::IdleInhibitor::update() -> void {
|
||||||
// Check status
|
// Check status
|
||||||
if (waybar::Client::inst()->idle_inhibitor != nullptr) {
|
std::string status = waybar::Client::inst()->idle_inhibitor_status;
|
||||||
status_ = "activated";
|
if (status == "activated") {
|
||||||
|
if (idle_inhibitor_ == nullptr) {
|
||||||
|
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
||||||
|
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
status_ = "deactivated";
|
if (idle_inhibitor_ != nullptr) {
|
||||||
|
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||||
|
idle_inhibitor_ = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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), fmt::arg("icon", getIcon(0, status))));
|
||||||
label_.get_style_context()->add_class(status_);
|
label_.get_style_context()->add_class(status);
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(status_);
|
label_.set_tooltip_text(status);
|
||||||
}
|
}
|
||||||
// Call parent update
|
// Call parent update
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
@ -45,17 +58,15 @@ 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_);
|
std::string status = waybar::Client::inst()->idle_inhibitor_status;
|
||||||
if (waybar::Client::inst()->idle_inhibitor != nullptr) {
|
label_.get_style_context()->remove_class(status);
|
||||||
zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor);
|
if (status == "activated") {
|
||||||
waybar::Client::inst()->idle_inhibitor = nullptr;
|
status = "deactivated";
|
||||||
status_ = "deactivated";
|
|
||||||
} else {
|
} else {
|
||||||
waybar::Client::inst()->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
status = "activated";
|
||||||
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
|
||||||
status_ = "activated";
|
|
||||||
}
|
}
|
||||||
click_param = status_;
|
waybar::Client::inst()->idle_inhibitor_status = status;
|
||||||
|
click_param = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make all other idle inhibitor modules update
|
// Make all other idle inhibitor modules update
|
||||||
|
Loading…
Reference in New Issue
Block a user