From 587dc6c84d2fe7c20684f9d19024a0cac6d9060f Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 27 Oct 2019 13:32:45 +0100
Subject: [PATCH] bar: Make module separator a label
Some people use text modules instead of the `separator` key in the bar
section to better configure the separator (colors, fonts).
Since we disallowed the same module being used multiple times in #1534,
this will now print an error message.
This should help with this a bit.
Ref #1913
---
include/components/builder.hpp | 4 ----
include/components/types.hpp | 8 +++++++-
include/drawtypes/label.hpp | 3 ---
include/drawtypes/progressbar.hpp | 4 ----
include/modules/meta/base.hpp | 2 --
src/components/bar.cpp | 3 ++-
src/components/controller.cpp | 6 +++++-
7 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/include/components/builder.hpp b/include/components/builder.hpp
index 2afd291e..a14d55f0 100644
--- a/include/components/builder.hpp
+++ b/include/components/builder.hpp
@@ -10,10 +10,6 @@ POLYBAR_NS
using std::map;
// fwd decl
-namespace drawtypes {
- class label;
- using label_t = shared_ptr;
-} // namespace drawtypes
using namespace drawtypes;
class builder {
diff --git a/include/components/types.hpp b/include/components/types.hpp
index 8f9b2751..558a77cf 100644
--- a/include/components/types.hpp
+++ b/include/components/types.hpp
@@ -12,6 +12,12 @@ POLYBAR_NS
// fwd {{{
struct randr_output;
using monitor_t = shared_ptr;
+
+namespace drawtypes {
+ class label;
+}
+
+using label_t = shared_ptr;
// }}}
struct enum_hash {
@@ -159,7 +165,7 @@ struct bar_settings {
struct radius radius {};
int spacing{0};
- string separator{};
+ label_t separator{};
string wmname{};
string locale{};
diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp
index 45a5f8b1..5859b716 100644
--- a/include/drawtypes/label.hpp
+++ b/include/drawtypes/label.hpp
@@ -18,9 +18,6 @@ namespace drawtypes {
bool zpad{false};
};
- class label;
- using label_t = shared_ptr;
-
class label : public non_copyable_mixin {
public:
string m_foreground{};
diff --git a/include/drawtypes/progressbar.hpp b/include/drawtypes/progressbar.hpp
index c2b27277..097cd99d 100644
--- a/include/drawtypes/progressbar.hpp
+++ b/include/drawtypes/progressbar.hpp
@@ -9,10 +9,6 @@
POLYBAR_NS
namespace drawtypes {
- // fwd
- class label;
- using label_t = shared_ptr;
-
class progressbar : public non_copyable_mixin {
public:
explicit progressbar(const bar_settings& bar, int width, string format);
diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp
index e3b84c42..23e74fbf 100644
--- a/include/modules/meta/base.hpp
+++ b/include/modules/meta/base.hpp
@@ -29,8 +29,6 @@ using std::map;
// fwd decl {{{
namespace drawtypes {
- class label;
- using label_t = shared_ptr;
class ramp;
using ramp_t = shared_ptr;
class progressbar;
diff --git a/src/components/bar.cpp b/src/components/bar.cpp
index 70586d29..2f7b0e88 100644
--- a/src/components/bar.cpp
+++ b/src/components/bar.cpp
@@ -7,6 +7,7 @@
#include "components/screen.hpp"
#include "components/taskqueue.hpp"
#include "components/types.hpp"
+#include "drawtypes/label.hpp"
#include "events/signal.hpp"
#include "events/signal_emitter.hpp"
#include "utils/bspwm.hpp"
@@ -155,7 +156,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
// Load configuration values
m_opts.origin = m_conf.get(bs, "bottom", false) ? edge::BOTTOM : edge::TOP;
m_opts.spacing = m_conf.get(bs, "spacing", m_opts.spacing);
- m_opts.separator = m_conf.get(bs, "separator", ""s);
+ m_opts.separator = drawtypes::load_optional_label(m_conf, bs, "separator", "");
m_opts.locale = m_conf.get(bs, "locale", ""s);
auto radius = m_conf.get(bs, "radius", 0.0);
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index 60b1feb4..a85e6f7f 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -3,6 +3,7 @@
#include
#include "components/bar.hpp"
+#include "components/builder.hpp"
#include "components/config.hpp"
#include "components/ipc.hpp"
#include "components/logger.hpp"
@@ -447,12 +448,15 @@ void controller::process_inputdata() {
bool controller::process_update(bool force) {
const bar_settings& bar{m_bar->settings()};
string contents;
- string separator{bar.separator};
string padding_left(bar.padding.left, ' ');
string padding_right(bar.padding.right, ' ');
string margin_left(bar.module_margin.left, ' ');
string margin_right(bar.module_margin.right, ' ');
+ builder build{bar};
+ build.node(bar.separator);
+ string separator{build.flush()};
+
for (const auto& block : m_blocks) {
string block_contents;
bool is_left = false;