From 47bc4597421ca655c870e9ed2c66c3893fceb94c Mon Sep 17 00:00:00 2001 From: Adam Ransom Date: Tue, 21 Feb 2017 22:23:16 +0900 Subject: [PATCH] fix(bspwm): Update when focusing urgent desktops When focusing a desktop with the urgent flag, two events are received from `bspc` simultaneously, separated by a newline character. This was not handled correctly and the second event was discarded causing the urgent style to be removed, but the focused style would remain on the previously focused desktop. This fixes the problem by handling any number of events that arrive at the same time (separated by newlines). --- include/modules/bspwm.hpp | 2 ++ src/modules/bspwm.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 5e9a07be..b1b02a7a 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -51,6 +51,8 @@ namespace modules { bool input(string&& cmd); private: + bool handle_status(string& data); + static constexpr auto DEFAULT_ICON = "ws-icon-default"; static constexpr auto DEFAULT_LABEL = "%icon% %name%"; static constexpr auto DEFAULT_MONITOR_LABEL = "%name%"; diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index cd036ad9..0ae8e725 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -157,12 +157,18 @@ namespace modules { } string data{m_subscriber->receive(BUFSIZ)}; + bool result = false; - size_t pos; - if ((pos = data.find('\n')) != string::npos) { - data.erase(pos); + for (auto&& status_line : string_util::split(data, '\n')) { + // Need to return true if ANY of the handle_status calls + // return true + result = this->handle_status(status_line) || result; } + return result; + } + + bool bspwm_module::handle_status(string& data) { if (data.empty()) { return false; } @@ -180,6 +186,8 @@ namespace modules { m_hash = hash; + size_t pos; + // Extract the string for the defined monitor if (m_pinworkspaces) { const auto needle_active = ":M" + m_bar.monitor->name + ":";