From b3f7cd08e9fa87f8bf8b0380a119a6b56f1cb2a0 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Fri, 1 Mar 2019 16:38:07 +0100
Subject: [PATCH] fix(xkeyboard): Only update indicators when used
Was causing a segfault if `format = `
---
src/modules/xkeyboard.cpp | 48 ++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/src/modules/xkeyboard.cpp b/src/modules/xkeyboard.cpp
index 2470750d..23b686bd 100644
--- a/src/modules/xkeyboard.cpp
+++ b/src/modules/xkeyboard.cpp
@@ -130,32 +130,34 @@ namespace modules {
m_layout->replace_token("%number%", to_string(m_keyboard->current()));
}
- m_indicators.clear();
+ if (m_formatter->has(TAG_LABEL_INDICATOR)) {
+ m_indicators.clear();
- for (auto it : INDICATOR_TYPES) {
- const auto& indicator_str = m_keyboard->indicator_name(it);
+ for (auto it : INDICATOR_TYPES) {
+ const auto& indicator_str = m_keyboard->indicator_name(it);
- if (blacklisted(indicator_str)) {
- continue;
+ if (blacklisted(indicator_str)) {
+ continue;
+ }
+
+ auto indicator_on = m_keyboard->on(it);
+ auto &indicator_labels = indicator_on ? m_indicator_on_labels : m_indicator_off_labels;
+ auto &indicator_icons = indicator_on ? m_indicator_icons_on : m_indicator_icons_off;
+ auto &indicator_state = indicator_on ? m_indicator_state_on : m_indicator_state_off;
+
+ label_t indicator;
+ if (indicator_labels.find(it) != indicator_labels.end()) {
+ indicator = indicator_labels[it]->clone();
+ } else {
+ indicator = indicator_state->clone();
+ }
+
+ auto icon = indicator_icons->get(string_util::lower(indicator_str), DEFAULT_INDICATOR_ICON);
+
+ indicator->replace_token("%name%", indicator_str);
+ indicator->replace_token("%icon%", icon->get());
+ m_indicators.emplace(it, move(indicator));
}
-
- auto indicator_on = m_keyboard->on(it);
- auto &indicator_labels = indicator_on ? m_indicator_on_labels : m_indicator_off_labels;
- auto &indicator_icons = indicator_on ? m_indicator_icons_on : m_indicator_icons_off;
- auto &indicator_state = indicator_on ? m_indicator_state_on : m_indicator_state_off;
-
- label_t indicator;
- if (indicator_labels.find(it) != indicator_labels.end()) {
- indicator = indicator_labels[it]->clone();
- } else {
- indicator = indicator_state->clone();
- }
-
- auto icon = indicator_icons->get(string_util::lower(indicator_str), DEFAULT_INDICATOR_ICON);
-
- indicator->replace_token("%name%", indicator_str);
- indicator->replace_token("%icon%", icon->get());
- m_indicators.emplace(it, move(indicator));
}
// Trigger redraw