From 41b2b04121820cd0d487a9ea9f317d05976d2f1b Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Thu, 24 Nov 2022 21:01:06 -0800 Subject: [PATCH] Added support for single indicators And indicator configuration --- src/bar.cpp | 63 +++++++++++++++++++++++++++++++++++++++----------- src/bar.hpp | 3 +++ src/config.hpp | 5 +++- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index 4889c1a..d95d6da 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -146,10 +146,10 @@ uint32_t Bar::getSelectedTagNumClients() { for (auto &tag : _tags) { if (tag.state == TagState::Active) { - return tag.numClients; - } + return tag.numClients; + } } - return 0; + return 0; } void Bar::setSelected(bool selected) @@ -251,22 +251,52 @@ void Bar::render() void Bar::renderTags() { for (auto &tag : _tags) { - setColorScheme( - tag.state & TagState::Active ? colorActive : colorInactive, - tag.state & TagState::Urgent); + setTagColorScheme(tag); renderComponent(tag.component); auto indicators = std::min(tag.numClients, static_cast(_bufs->height/2)); - for (auto ind = 0; ind < indicators; ind++) { - auto w = ind == tag.focusedClient ? 7 : 3; - cairo_move_to(_painter, tag.component.x, ind*2+0.5); - cairo_rel_line_to(_painter, w, 0); - cairo_close_path(_painter); - cairo_set_line_width(_painter, 3); - cairo_stroke(_painter); + if (showIndicators == 1) { + renderSingleIndicator(tag, indicators); + } else if (showIndicators == 2) { + renderMultiIndicators(tag, indicators); } } } +void Bar::renderMultiIndicators(const Tag& t, int inds) +{ + for (auto ind = 0; ind < inds; ind++) { + auto w = ind == t.focusedClient ? 7 : 3; + cairo_move_to(_painter, t.component.x, ind*2+0.5); + cairo_rel_line_to(_painter, w, 0); + cairo_close_path(_painter); + cairo_set_line_width(_painter, 3); + cairo_stroke(_painter); + } +} + +void Bar::renderSingleIndicator(const Tag& t, int inds) +{ + if (inds > 0) { + auto w = 4; + setColorScheme(colorIndicator); + cairo_move_to(_painter, t.component.x+1, 1); + cairo_rel_line_to(_painter, w, 0); + cairo_rel_line_to(_painter, 0, w); + cairo_rel_line_to(_painter, -w, 0); + cairo_close_path(_painter); + cairo_set_line_width(_painter, 1); + beginFg(); + cairo_stroke_preserve(_painter); + if (t.state == TagState::Active) { + beginBg(); + } else { + setTagColorScheme(t); + beginBg(); + } + cairo_fill(_painter); + } +} + void Bar::renderStatus() { pango_cairo_update_layout(_painter, _statusCmp.pangoLayout.get()); @@ -279,6 +309,13 @@ void Bar::renderStatus() renderComponent(_statusCmp); } +void Bar::setTagColorScheme(const Tag& t) +{ + setColorScheme( + t.state & TagState::Active ? colorActive : colorInactive, + t.state & TagState::Urgent); +} + void Bar::setColorScheme(const ColorScheme& scheme, bool invert) { _colorScheme = invert diff --git a/src/bar.hpp b/src/bar.hpp index 1c8c31e..1c45961 100644 --- a/src/bar.hpp +++ b/src/bar.hpp @@ -50,9 +50,12 @@ class Bar { void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height); void render(); void renderTags(); + void renderMultiIndicators(const Tag& t, int inds); + void renderSingleIndicator(const Tag& t, int inds); void renderStatus(); // low-level rendering + void setTagColorScheme(const Tag& t); void setColorScheme(const ColorScheme& scheme, bool invert = false); void beginFg(); void beginBg(); diff --git a/src/config.hpp b/src/config.hpp index f58ea52..3596657 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -14,8 +14,11 @@ constexpr const char* font = "Iosevka 11"; constexpr ColorScheme colorInactive = {Color(0xff, 0xff, 0xff), Color(0x88, 0x88, 0x88)}; constexpr ColorScheme colorActive = {Color(0xff, 0xff, 0xff), Color(0xaa, 0x44, 0x44)}; +constexpr ColorScheme colorIndicator = {Color(0xff, 0xff, 0xff), Color(0xff, 0xff, 0xff)}; constexpr const char* termcmd[] = {"dwl_term", nullptr}; - +constexpr int showIndicators = 1; // 0 = no indicators + // 1 = single indicator + // 2 = multiple indicators constexpr Button buttons[] = { { ClkTagBar, BTN_LEFT, view, {0} }, { ClkTagBar, BTN_RIGHT, tag, {0} },