From 325ef4c3b3a5ea63c83723495067aa63770cf104 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 14 Mar 2022 18:39:34 +0100
Subject: [PATCH] Cleanup builder
Removes unused methods and fields
---
include/components/builder.hpp | 18 +++----
include/modules/meta/base.inl | 4 +-
src/components/builder.cpp | 87 +++++-----------------------------
src/modules/alsa.cpp | 4 +-
src/modules/backlight.cpp | 4 +-
src/modules/ipc.cpp | 4 +-
src/modules/meta/base.cpp | 4 +-
src/modules/pulseaudio.cpp | 4 +-
src/modules/script.cpp | 4 +-
src/modules/systray.cpp | 4 +-
src/modules/text.cpp | 4 +-
src/modules/xbacklight.cpp | 4 +-
src/modules/xkeyboard.cpp | 6 +--
src/modules/xworkspaces.cpp | 9 ++--
14 files changed, 47 insertions(+), 113 deletions(-)
diff --git a/include/components/builder.hpp b/include/components/builder.hpp
index d9041695..1efc0c5f 100644
--- a/include/components/builder.hpp
+++ b/include/components/builder.hpp
@@ -21,11 +21,9 @@ class builder {
void reset();
string flush();
- void append(const string& text);
void node(const string& str);
void node(const string& str, int font_index);
void node(const label_t& label);
- void node_repeat(const string& str, size_t n);
void node_repeat(const label_t& label, size_t n);
void offset(extent_val pixels = ZERO_PX_EXTENT);
void spacing(spacing_val size);
@@ -35,12 +33,6 @@ class builder {
void background_close();
void color(rgba color);
void color_close();
- void line_color(const rgba& color);
- void line_color_close();
- void overline_color(rgba color);
- void overline_color_close();
- void underline_color(rgba color);
- void underline_color_close();
void overline(const rgba& color = rgba{});
void overline_close();
void underline(const rgba& color = rgba{});
@@ -55,6 +47,13 @@ class builder {
static string get_spacing_format_string(const spacing_val& space);
protected:
+ void append(const string& text);
+
+ void overline_color(rgba color);
+ void overline_color_close();
+ void underline_color(rgba color);
+ void underline_color_close();
+
void tag_open(tags::syntaxtag tag, const string& value);
void tag_open(tags::attribute attr);
void tag_close(tags::syntaxtag tag);
@@ -65,10 +64,7 @@ class builder {
string m_output;
map m_tags{};
- map m_colors{};
map m_attrs{};
-
- int m_fontindex{0};
};
POLYBAR_NS_END
diff --git a/include/modules/meta/base.inl b/include/modules/meta/base.inl
index 1f4378bc..8ea403d2 100644
--- a/include/modules/meta/base.inl
+++ b/include/modules/meta/base.inl
@@ -271,7 +271,7 @@ namespace modules {
m_builder->spacing(format->spacing);
}
- m_builder->append(tag_content);
+ m_builder->node(tag_content);
has_tags = true;
}
@@ -279,7 +279,7 @@ namespace modules {
}
if (cursor < value.size()) {
- m_builder->append(value.substr(cursor));
+ m_builder->node(value.substr(cursor));
}
return format->decorate(&*m_builder, m_builder->flush());
diff --git a/src/components/builder.cpp b/src/components/builder.cpp
index ace1dd69..fc85b110 100644
--- a/src/components/builder.cpp
+++ b/src/components/builder.cpp
@@ -31,19 +31,12 @@ void builder::reset() {
m_tags[syntaxtag::u] = 0;
m_tags[syntaxtag::P] = 0;
- m_colors.clear();
- m_colors[syntaxtag::B] = string();
- m_colors[syntaxtag::F] = string();
- m_colors[syntaxtag::o] = string();
- m_colors[syntaxtag::u] = string();
-
m_attrs.clear();
m_attrs[attribute::NONE] = false;
m_attrs[attribute::UNDERLINE] = false;
m_attrs[attribute::OVERLINE] = false;
m_output.clear();
- m_fontindex = 1;
}
/**
@@ -52,33 +45,20 @@ void builder::reset() {
* This will also close any unclosed tags
*/
string builder::flush() {
- if (m_tags[syntaxtag::B]) {
- background_close();
- }
- if (m_tags[syntaxtag::F]) {
- color_close();
- }
- if (m_tags[syntaxtag::T]) {
- font_close();
- }
- if (m_tags[syntaxtag::o]) {
- overline_color_close();
- }
- if (m_tags[syntaxtag::u]) {
- underline_color_close();
- }
- if (m_attrs[attribute::UNDERLINE]) {
- underline_close();
- }
- if (m_attrs[attribute::OVERLINE]) {
- overline_close();
- }
+ background_close();
+ color_close();
+ font_close();
+ overline_color_close();
+ underline_color_close();
+ underline_close();
+ overline_close();
while (m_tags[syntaxtag::A]) {
action_close();
}
- string output{m_output};
+ string output{};
+ std::swap(m_output, output);
reset();
@@ -174,18 +154,6 @@ void builder::node(const label_t& label) {
}
}
-/**
- * Repeat text string n times
- */
-void builder::node_repeat(const string& str, size_t n) {
- string text;
- text.reserve(str.size() * n);
- while (n--) {
- text += str;
- }
- node(text);
-}
-
/**
* Repeat label contents n times
*/
@@ -233,7 +201,6 @@ void builder::font(int index) {
if (index == 0) {
return;
}
- m_fontindex = index;
tag_open(syntaxtag::T, to_string(index));
}
@@ -241,7 +208,6 @@ void builder::font(int index) {
* Insert tag to reset the font index
*/
void builder::font_close() {
- m_fontindex = 1;
tag_close(syntaxtag::T);
}
@@ -252,7 +218,6 @@ void builder::background(rgba color) {
color = color.try_apply_alpha_to(m_bar.background);
auto hex = color_util::simplify_hex(color);
- m_colors[syntaxtag::B] = hex;
tag_open(syntaxtag::B, hex);
}
@@ -260,7 +225,6 @@ void builder::background(rgba color) {
* Insert tag to reset the background color
*/
void builder::background_close() {
- m_colors[syntaxtag::B].clear();
tag_close(syntaxtag::B);
}
@@ -271,7 +235,6 @@ void builder::color(rgba color) {
color = color.try_apply_alpha_to(m_bar.foreground);
auto hex = color_util::simplify_hex(color);
- m_colors[syntaxtag::F] = hex;
tag_open(syntaxtag::F, hex);
}
@@ -279,32 +242,14 @@ void builder::color(rgba color) {
* Insert tag to reset the foreground color
*/
void builder::color_close() {
- m_colors[syntaxtag::F].clear();
tag_close(syntaxtag::F);
}
-/**
- * Insert tag to alter the current overline/underline color
- */
-void builder::line_color(const rgba& color) {
- overline_color(color);
- underline_color(color);
-}
-
-/**
- * Close overline/underline color tag
- */
-void builder::line_color_close() {
- overline_color_close();
- underline_color_close();
-}
-
/**
* Insert tag to alter the current overline color
*/
void builder::overline_color(rgba color) {
auto hex = color_util::simplify_hex(color);
- m_colors[syntaxtag::o] = hex;
tag_open(syntaxtag::o, hex);
tag_open(attribute::OVERLINE);
}
@@ -313,7 +258,6 @@ void builder::overline_color(rgba color) {
* Close underline color tag
*/
void builder::overline_color_close() {
- m_colors[syntaxtag::o].clear();
tag_close(syntaxtag::o);
}
@@ -322,7 +266,6 @@ void builder::overline_color_close() {
*/
void builder::underline_color(rgba color) {
auto hex = color_util::simplify_hex(color);
- m_colors[syntaxtag::u] = hex;
tag_open(syntaxtag::u, hex);
tag_open(attribute::UNDERLINE);
}
@@ -332,7 +275,6 @@ void builder::underline_color(rgba color) {
*/
void builder::underline_color_close() {
tag_close(syntaxtag::u);
- m_colors[syntaxtag::u].clear();
}
/**
@@ -415,7 +357,7 @@ void builder::action(mousebtn index, string action_name, const label_t& label) {
if (label && *label) {
action(index, action_name);
node(label);
- tag_close(syntaxtag::A);
+ action_close();
}
}
@@ -531,13 +473,8 @@ void builder::tag_close(syntaxtag tag) {
case syntaxtag::o:
append("%{o-}");
break;
- case syntaxtag::R:
- case syntaxtag::P:
- case syntaxtag::O:
- case syntaxtag::l:
- case syntaxtag::c:
- case syntaxtag::r:
- break;
+ default:
+ throw runtime_error("Cannot close syntaxtag: " + to_string(to_integral(tag)));
}
}
diff --git a/src/modules/alsa.cpp b/src/modules/alsa.cpp
index 88aad7a3..21cd4dc3 100644
--- a/src/modules/alsa.cpp
+++ b/src/modules/alsa.cpp
@@ -212,7 +212,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
- m_builder->append(output);
+ m_builder->node(output);
return m_builder->flush();
}
@@ -293,6 +293,6 @@ namespace modules {
return mixers;
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp
index 19d86859..b85a5be4 100644
--- a/src/modules/backlight.cpp
+++ b/src/modules/backlight.cpp
@@ -98,7 +98,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
- m_builder->append(std::move(output));
+ m_builder->node(output);
m_builder->action_close();
m_builder->action_close();
@@ -141,6 +141,6 @@ namespace modules {
name(), err.what());
}
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp
index c942bee4..1ef1f1cf 100644
--- a/src/modules/ipc.cpp
+++ b/src/modules/ipc.cpp
@@ -99,7 +99,7 @@ namespace modules {
}
}
- m_builder->append(output);
+ m_builder->node(output);
return m_builder->flush();
}
@@ -224,6 +224,6 @@ namespace modules {
broadcast();
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp
index 72bc29d3..56d2e3b4 100644
--- a/src/modules/meta/base.cpp
+++ b/src/modules/meta/base.cpp
@@ -55,7 +55,7 @@ namespace modules {
builder->overline(ol);
}
- builder->append(move(output));
+ builder->node(output);
builder->node(suffix);
if (padding) {
@@ -182,6 +182,6 @@ namespace modules {
}
// }}}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp
index 1eebb4b2..cbe829e5 100644
--- a/src/modules/pulseaudio.cpp
+++ b/src/modules/pulseaudio.cpp
@@ -128,7 +128,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
- m_builder->append(output);
+ m_builder->node(output);
return m_builder->flush();
}
@@ -159,6 +159,6 @@ namespace modules {
void pulseaudio_module::action_toggle() {
m_pulseaudio->toggle_mute();
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/script.cpp b/src/modules/script.cpp
index af9466c9..ec9c856c 100644
--- a/src/modules/script.cpp
+++ b/src/modules/script.cpp
@@ -120,7 +120,7 @@ namespace modules {
}
}
- m_builder->append(output);
+ m_builder->node(output);
return m_builder->flush();
}
@@ -139,6 +139,6 @@ namespace modules {
return true;
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/systray.cpp b/src/modules/systray.cpp
index e8c69188..6ffa732f 100644
--- a/src/modules/systray.cpp
+++ b/src/modules/systray.cpp
@@ -45,7 +45,7 @@ namespace modules {
if (tag == TAG_LABEL_TOGGLE) {
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label);
} else if (tag == TAG_TRAY_CLIENTS && !m_hidden) {
- builder->append(TRAY_PLACEHOLDER);
+ builder->node(TRAY_PLACEHOLDER);
} else {
return false;
}
@@ -59,7 +59,7 @@ namespace modules {
m_hidden = !m_hidden;
broadcast();
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
#endif
diff --git a/src/modules/text.cpp b/src/modules/text.cpp
index 01882e7c..7a372745 100644
--- a/src/modules/text.cpp
+++ b/src/modules/text.cpp
@@ -47,10 +47,10 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, scroll_down);
}
- m_builder->append(output);
+ m_builder->node(output);
return m_builder->flush();
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/xbacklight.cpp b/src/modules/xbacklight.cpp
index d0ec3794..6e391aac 100644
--- a/src/modules/xbacklight.cpp
+++ b/src/modules/xbacklight.cpp
@@ -123,7 +123,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
- m_builder->append(output);
+ m_builder->node(output);
m_builder->action_close();
m_builder->action_close();
@@ -164,6 +164,6 @@ namespace modules {
m_connection.change_output_property_checked(
m_output->output, m_output->backlight.atom, XCB_ATOM_INTEGER, 32, XCB_PROP_MODE_REPLACE, 1, values);
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/xkeyboard.cpp b/src/modules/xkeyboard.cpp
index 8e65fb9f..53920640 100644
--- a/src/modules/xkeyboard.cpp
+++ b/src/modules/xkeyboard.cpp
@@ -167,10 +167,10 @@ namespace modules {
if (m_keyboard && m_keyboard->size() > 1) {
m_builder->action(mousebtn::LEFT, *this, EVENT_SWITCH, "");
- m_builder->append(output);
+ m_builder->node(output);
m_builder->action_close();
} else {
- m_builder->append(output);
+ m_builder->node(output);
}
return m_builder->flush();
@@ -319,6 +319,6 @@ namespace modules {
name(), entry);
}
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp
index 57060e73..467e7c16 100644
--- a/src/modules/xworkspaces.cpp
+++ b/src/modules/xworkspaces.cpp
@@ -18,7 +18,7 @@ namespace {
inline bool operator==(const position& a, const position& b) {
return a.x + a.y == b.x + b.y;
}
-} // namespace
+} // namespace
/**
* Defines a lexicographical order on position
@@ -79,7 +79,8 @@ namespace modules {
if (vec.size() == 2) {
m_icons->add(vec[0], std::make_shared