fix(bar): make disable-on-sleep DPMS suspend actually reach modules

toggleSuspend dynamic_cast<AModule*>-ed the children of the left/center/right
Gtk::Box. But modules are packed via AModule::operator Gtk::Widget&(), which
returns the member event_box_, so every box child is a Gtk::EventBox and the
cast is always null -- suspend()/resume() never ran, making disable-on-sleep a
silent no-op. Iterate modules_all_ (the real module pointers) instead.

Fixes disable-on-sleep DPMS suspend/resume never firing.
This commit is contained in:
Alex
2026-07-05 10:13:24 +02:00
parent afa6ab1fd8
commit 48db4aa36e
+10 -10
View File
@@ -331,12 +331,14 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
* returned to the main loop, when any late initial configure has been dispatched and widgets have * returned to the main loop, when any late initial configure has been dispatched and widgets have
* had a chance to allocate/draw. * had a chance to allocate/draw.
*/ */
Glib::signal_idle().connect(sigc::track_obj([this] { Glib::signal_idle().connect(sigc::track_obj(
[this] {
window.queue_resize(); window.queue_resize();
window.queue_draw(); window.queue_draw();
forceLayerCommit(); forceLayerCommit();
return false; return false;
}, *this)); },
*this));
if (spdlog::should_log(spdlog::level::debug)) { if (spdlog::should_log(spdlog::level::debug)) {
// Unfortunately, this function isn't in the C++ bindings, so we have to call the C version. // Unfortunately, this function isn't in the C++ bindings, so we have to call the C version.
@@ -750,9 +752,12 @@ void waybar::Bar::onOutputGeometryChanged() {
} }
void waybar::Bar::toggleSuspend(bool suspend) { void waybar::Bar::toggleSuspend(bool suspend) {
auto process_modules = [suspend](Gtk::Box& module_box) { // Iterate the actual module objects. Modules are packed into the Gtk::Box via
for (auto* widget : module_box.get_children()) { // AModule::operator Gtk::Widget&(), which returns the member event_box_, so the
auto* module = dynamic_cast<waybar::AModule*>(widget); // box children are Gtk::EventBox, never AModule -- a dynamic_cast over them is
// always null and suspend()/resume() would never fire. modules_all_ holds the
// real module pointers (including group children), so use it instead.
for (auto const& module : modules_all_) {
if (module && module->shouldSuspend()) { if (module && module->shouldSuspend()) {
if (suspend) { if (suspend) {
module->suspend(); module->suspend();
@@ -761,9 +766,4 @@ void waybar::Bar::toggleSuspend(bool suspend) {
} }
} }
} }
};
process_modules(left_);
process_modules(center_);
process_modules(right_);
} }