From 6f13fe93a3e023f8cc6f53683dbe1b39d0b07f3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Filip=20Ban=C3=A1k?=
 <58399088+Filip62@users.noreply.github.com>
Date: Thu, 17 Dec 2020 20:49:10 +0100
Subject: [PATCH] xkeyboard: Fix indicator spacing (#2306)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Fix xkeyboard module spacing between the layout and indicators when indicators are empty.

* Simplify the empty label check.

* Remove permanently enabled SCROLL_LOCK, sorry.

* Another mistake.

* Update src/modules/xkeyboard.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/modules/xkeyboard.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update.

* Fix xkeyboard module spacing between the layout and indicators, when indicators are empty. And fix the spacing between indicators when some are empty.

* Add issue #2292 to fixed.

* Update CHANGELOG.md

Co-authored-by: Filip BanĂ¡k <6111455-Filip62@users.noreply.gitlab.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
---
 CHANGELOG.md              | 3 +++
 src/modules/xkeyboard.cpp | 8 +++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0dbf5150..c50feeb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
     KB/s (as before), 1 for MB/s and 2 for GB/s.
 
 ### Fixed
+- Trailing space after the layout label when indicators are empty and made sure right amount
+  of spacing is added between the indicator labels, in the xkeyboard module.
+  ([`#2292`](https://github.com/polybar/polybar/issues/2292))
 - Parser error if click command contained `}`
   ([`#2040`](https://github.com/polybar/polybar/issues/2040))
 
diff --git a/src/modules/xkeyboard.cpp b/src/modules/xkeyboard.cpp
index cdceccb7..ebfa9a74 100644
--- a/src/modules/xkeyboard.cpp
+++ b/src/modules/xkeyboard.cpp
@@ -191,10 +191,12 @@ namespace modules {
     } else if (tag == TAG_LABEL_INDICATOR && !m_indicators.empty()) {
       size_t n{0};
       for (auto&& indicator : m_indicators) {
-        if (n++) {
-          builder->space(m_formatter->get(DEFAULT_FORMAT)->spacing);
+        if (*indicator.second) {
+          if (n++) {
+            builder->space(m_formatter->get(DEFAULT_FORMAT)->spacing);
+          }
+          builder->node(indicator.second);
         }
-        builder->node(indicator.second);
       }
       return n > 0;
     } else {