Draft fix for syncing idle inhibitor across outputs. The idle_inhibitor surface has been moved to Client, all instances of idle inhibitor module now use one surface between them. Any time an idle inhibitor is clicked, currently it force updates ALL modules on all outputs, this needs work.

This commit is contained in:
Jordan Leppert 2020-10-31 16:31:27 +00:00
parent abe1fa5bd4
commit 4872091442
5 changed files with 35 additions and 10 deletions

View File

@ -31,6 +31,7 @@ class Bar {
auto toggle() -> void; auto toggle() -> void;
void handleSignal(int); void handleSignal(int);
void updateAll();
struct waybar_output *output; struct waybar_output *output;
Json::Value config; Json::Value config;

View File

@ -22,6 +22,7 @@ class Client {
struct zwlr_layer_shell_v1 * layer_shell = nullptr; struct zwlr_layer_shell_v1 * layer_shell = nullptr;
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::vector<std::unique_ptr<Bar>> bars; std::vector<std::unique_ptr<Bar>> bars;
private: private:

View File

@ -18,7 +18,6 @@ class IdleInhibitor : public ALabel {
const Bar& bar_; const Bar& bar_;
std::string status_; std::string status_;
struct zwp_idle_inhibitor_v1* idle_inhibitor_;
int pid_; int pid_;
}; };

View File

@ -461,3 +461,15 @@ auto waybar::Bar::setupWidgets() -> void {
right_.pack_end(*module, false, false); right_.pack_end(*module, false, false);
} }
} }
void waybar::Bar::updateAll() {
for (auto const& module : modules_left_) {
module->update();
}
for (auto const& module : modules_center_) {
module->update();
}
for (auto const& module : modules_right_) {
module->update();
}
}

View File

@ -6,7 +6,6 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar&
: ALabel(config, "idle_inhibitor", id, "{status}"), : ALabel(config, "idle_inhibitor", id, "{status}"),
bar_(bar), bar_(bar),
status_("deactivated"), status_("deactivated"),
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(
@ -15,9 +14,9 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar&
} }
waybar::modules::IdleInhibitor::~IdleInhibitor() { waybar::modules::IdleInhibitor::~IdleInhibitor() {
if (idle_inhibitor_ != nullptr) { if (waybar::Client::inst()->idle_inhibitor != nullptr) {
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor);
idle_inhibitor_ = nullptr; waybar::Client::inst()->idle_inhibitor = nullptr;
} }
if (pid_ != -1) { if (pid_ != -1) {
kill(-pid_, 9); kill(-pid_, 9);
@ -26,6 +25,13 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
} }
auto waybar::modules::IdleInhibitor::update() -> void { auto waybar::modules::IdleInhibitor::update() -> void {
// Check status
if (waybar::Client::inst()->idle_inhibitor != nullptr) {
status_ = "activated";
} else {
status_ = "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_), fmt::arg("icon", getIcon(0, status_))));
label_.get_style_context()->add_class(status_); label_.get_style_context()->add_class(status_);
@ -39,17 +45,23 @@ 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_); label_.get_style_context()->remove_class(status_);
if (idle_inhibitor_ != nullptr) { if (waybar::Client::inst()->idle_inhibitor != nullptr) {
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor);
idle_inhibitor_ = nullptr; waybar::Client::inst()->idle_inhibitor = nullptr;
status_ = "deactivated"; status_ = "deactivated";
} else { } else {
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( waybar::Client::inst()->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
waybar::Client::inst()->idle_inhibit_manager, bar_.surface); waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
status_ = "activated"; status_ = "activated";
} }
click_param = status_; click_param = status_;
} }
// Make all modules update
for (auto const& bar : waybar::Client::inst()->bars) {
bar->updateAll();
}
ALabel::handleToggle(e); ALabel::handleToggle(e);
return true; return true;
} }