From 48db4aa36e85fe1e0d67ac4b4c9ef8e576d71e70 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Jul 2026 10:07:21 +0200 Subject: [PATCH] fix(bar): make disable-on-sleep DPMS suspend actually reach modules toggleSuspend dynamic_cast-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. --- src/bar.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index cf284e0d..1eb5ce41 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -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 * had a chance to allocate/draw. */ - Glib::signal_idle().connect(sigc::track_obj([this] { - window.queue_resize(); - window.queue_draw(); - forceLayerCommit(); - return false; - }, *this)); + Glib::signal_idle().connect(sigc::track_obj( + [this] { + window.queue_resize(); + window.queue_draw(); + forceLayerCommit(); + return false; + }, + *this)); if (spdlog::should_log(spdlog::level::debug)) { // Unfortunately, this function isn't in the C++ bindings, so we have to call the C version. @@ -750,20 +752,18 @@ void waybar::Bar::onOutputGeometryChanged() { } void waybar::Bar::toggleSuspend(bool suspend) { - auto process_modules = [suspend](Gtk::Box& module_box) { - for (auto* widget : module_box.get_children()) { - auto* module = dynamic_cast(widget); - if (module && module->shouldSuspend()) { - if (suspend) { - module->suspend(); - } else { - module->resume(); - } + // Iterate the actual module objects. Modules are packed into the Gtk::Box via + // AModule::operator Gtk::Widget&(), which returns the member event_box_, so the + // 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 (suspend) { + module->suspend(); + } else { + module->resume(); } } - }; - - process_modules(left_); - process_modules(center_); - process_modules(right_); + } }