diff --git a/include/components/config.hpp b/include/components/config.hpp index 59ffce0c..5f4a1acb 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -33,7 +33,6 @@ class config { string build_path(const string& section, const string& key) const; void warn_deprecated(const string& section, const string& key, string replacement) const; - /** * Returns true if a given parameter exists */ diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index ae4d4d33..f352c1df 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -70,13 +70,9 @@ namespace drawtypes { }; label_t load_label(const config& conf, const string& section, string name, bool required = true, string def = ""); - label_t load_optional_label(const config& conf, string section, string name, string def = ""); - label_t load_either_config_label(const config& conf, string section, string name1, string name2, string def = ""); - icon_t load_icon(const config& conf, string section, string name, bool required = true, string def = ""); - icon_t load_optional_icon(const config& conf, string section, string name, string def = ""); } diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index e311f134..1cfe1599 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -6,42 +6,36 @@ POLYBAR_NS namespace modules { - enum class state_ws { - WORKSPACE_NONE, - WORKSPACE_ACTIVE, - WORKSPACE_URGENT, - WORKSPACE_EMPTY, - WORKSPACE_OCCUPIED, - WORKSPACE_FOCUSED_URGENT, - WORKSPACE_FOCUSED_EMPTY, - WORKSPACE_FOCUSED_OCCUPIED, - WORKSPACE_DIMMED, // used when the monitor is out of focus - WORKSPACE_DIMMED_ACTIVE, - WORKSPACE_DIMMED_URGENT, - WORKSPACE_DIMMED_EMPTY, - WORKSPACE_DIMMED_OCCUPIED - }; - enum class state_mode { - MODE_NONE, - MODE_LAYOUT_MONOCLE, - MODE_LAYOUT_TILED, - MODE_STATE_FULLSCREEN, - MODE_STATE_FLOATING, - MODE_NODE_LOCKED, - MODE_NODE_STICKY, - MODE_NODE_PRIVATE - }; - - struct bspwm_monitor { - vector> workspaces; - vector modes; - label_t label; - string name; - bool focused = false; - }; - class bspwm_module : public event_module { public: + enum class state { + NONE = 0U, + EMPTY, + OCCUPIED, + FOCUSED, + URGENT, + DIMMED, // used when the monitor is out of focus + }; + + enum class mode { + NONE = 0U, + LAYOUT_MONOCLE, + LAYOUT_TILED, + STATE_FULLSCREEN, + STATE_FLOATING, + NODE_LOCKED, + NODE_STICKY, + NODE_PRIVATE + }; + + struct bspwm_monitor { + vector> workspaces; + vector modes; + label_t label; + string name; + bool focused = false; + }; + using event_module::event_module; void setup(); @@ -56,12 +50,14 @@ namespace modules { } private: - static constexpr auto DEFAULT_WS_ICON = "ws-icon-default"; - static constexpr auto DEFAULT_WS_LABEL = "%icon% %name%"; + static constexpr auto DEFAULT_ICON = "ws-icon-default"; + static constexpr auto DEFAULT_LABEL = "%icon% %name%"; static constexpr auto DEFAULT_MONITOR_LABEL = "%name%"; + static constexpr auto TAG_LABEL_MONITOR = ""; static constexpr auto TAG_LABEL_STATE = ""; static constexpr auto TAG_LABEL_MODE = ""; + static constexpr auto EVENT_PREFIX = "bwm"; static constexpr auto EVENT_CLICK = "bwmf"; static constexpr auto EVENT_SCROLL_UP = "bwmn"; @@ -71,8 +67,8 @@ namespace modules { vector> m_monitors; - map m_modelabels; - map m_statelabels; + map m_modelabels; + map m_statelabels; label_t m_monitorlabel; iconset_t m_icons; diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index e7032cee..2982e461 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -167,13 +167,6 @@ namespace drawtypes { return load_label(conf, move(section), move(name), false, move(def)); } - label_t load_either_config_label(const config& conf, string section, string name1, string name2, string def) { - if (conf.has(section, name1)) - return load_label(conf, section, name1, true, ""); - else - return load_optional_label(conf, section, name2, def); - } - /** * Create an icon by loading values from the configuration */ diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index f8baf1b4..62e780f7 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -10,6 +10,28 @@ POLYBAR_NS +namespace { + using bspwm_state = modules::bspwm_module::state; + + uint32_t make_mask(bspwm_state s1, bspwm_state s2 = bspwm_state::NONE) { + uint32_t mask{0U}; + if (static_cast(s1)) + mask |= 1 << (static_cast(s1) - 1); + if (static_cast(s2)) + mask |= 1 << (static_cast(s2) - 1); + return mask; + } + + // uint32_t check_mask(uint32_t base, bspwm_state s1, bspwm_state s2 = bspwm_state::NONE) { + // uint32_t mask{0U}; + // if (static_cast(s1)) + // mask |= 1 << (static_cast(s1) - 1); + // if (static_cast(s2)) + // mask |= 1 << (static_cast(s2) - 1); + // return (base & mask) == mask; + // } +} + namespace modules { template class module; template class event_module; @@ -37,49 +59,65 @@ namespace modules { } if (m_formatter->has(TAG_LABEL_STATE)) { - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_ACTIVE, load_optional_label(m_conf, name(), "label-active", DEFAULT_WS_LABEL))); - m_statelabels.insert(make_pair( - state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_FOCUSED_OCCUPIED, load_either_config_label(m_conf, name(), "label-focused-occupied", "label-focused", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_FOCUSED_URGENT, load_either_config_label(m_conf, name(), "label-focused-urgent", "label-focused", DEFAULT_WS_LABEL))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_FOCUSED_EMPTY, load_either_config_label(m_conf, name(), "label-focused-empty", "label-focused", DEFAULT_WS_LABEL))); - m_statelabels.insert(make_pair(state_ws::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed"))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_DIMMED_ACTIVE, load_optional_label(m_conf, name(), "label-dimmed-active"))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_DIMMED_URGENT, load_optional_label(m_conf, name(), "label-dimmed-urgent"))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_DIMMED_EMPTY, load_optional_label(m_conf, name(), "label-dimmed-empty"))); - m_statelabels.insert( - make_pair(state_ws::WORKSPACE_DIMMED_OCCUPIED, load_optional_label(m_conf, name(), "label-dimmed-occupied"))); + // XXX: Warn about deprecated parameters + m_conf.warn_deprecated(name(), "label-dimmed-active", "label-dimmed-focused"); + + // clang-format off + try { + m_statelabels.emplace(make_mask(state::FOCUSED), load_label(m_conf, name(), "label-active", DEFAULT_LABEL)); + m_conf.warn_deprecated(name(), "label-active", "label-focused and label-dimmed-focused"); + } catch (const key_error& err) { + m_statelabels.emplace(make_mask(state::FOCUSED), load_optional_label(m_conf, name(), "label-focused", DEFAULT_LABEL)); + } + + m_statelabels.emplace(make_mask(state::OCCUPIED), + load_optional_label(m_conf, name(), "label-occupied", DEFAULT_LABEL)); + m_statelabels.emplace(make_mask(state::URGENT), + load_optional_label(m_conf, name(), "label-urgent", DEFAULT_LABEL)); + m_statelabels.emplace(make_mask(state::EMPTY), + load_optional_label(m_conf, name(), "label-empty", DEFAULT_LABEL)); + m_statelabels.emplace(make_mask(state::DIMMED), + load_optional_label(m_conf, name(), "label-dimmed")); + + vector> focused_overrides{ + {state::OCCUPIED, "label-focused-occupied"}, + {state::URGENT, "label-focused-urgent"}, + {state::EMPTY, "label-focused-empty"}}; + + for (auto&& os : focused_overrides) { + uint32_t mask{make_mask(state::FOCUSED, os.first)}; + try { + m_statelabels.emplace(mask, load_label(m_conf, name(), os.second)); + } catch (const key_error& err) { + m_statelabels.emplace(mask, m_statelabels.at(make_mask(state::FOCUSED))->clone()); + } + } + + vector> dimmed_overrides{ + {state::FOCUSED, "label-dimmed-focused"}, + {state::OCCUPIED, "label-dimmed-occupied"}, + {state::URGENT, "label-dimmed-urgent"}, + {state::EMPTY, "label-dimmed-empty"}}; + + for (auto&& os : dimmed_overrides) { + m_statelabels.emplace(make_mask(state::DIMMED, os.first), + load_optional_label(m_conf, name(), os.second, m_statelabels.at(make_mask(os.first))->get())); + } + // clang-format on } if (m_formatter->has(TAG_LABEL_MODE)) { - m_modelabels.insert( - make_pair(state_mode::MODE_LAYOUT_MONOCLE, load_optional_label(m_conf, name(), "label-monocle"))); - m_modelabels.insert(make_pair(state_mode::MODE_LAYOUT_TILED, load_optional_label(m_conf, name(), "label-tiled"))); - m_modelabels.insert( - make_pair(state_mode::MODE_STATE_FULLSCREEN, load_optional_label(m_conf, name(), "label-fullscreen"))); - m_modelabels.insert( - make_pair(state_mode::MODE_STATE_FLOATING, load_optional_label(m_conf, name(), "label-floating"))); - m_modelabels.insert(make_pair(state_mode::MODE_NODE_LOCKED, load_optional_label(m_conf, name(), "label-locked"))); - m_modelabels.insert(make_pair(state_mode::MODE_NODE_STICKY, load_optional_label(m_conf, name(), "label-sticky"))); - m_modelabels.insert( - make_pair(state_mode::MODE_NODE_PRIVATE, load_optional_label(m_conf, name(), "label-private"))); + m_modelabels.emplace(mode::LAYOUT_MONOCLE, load_optional_label(m_conf, name(), "label-monocle")); + m_modelabels.emplace(mode::LAYOUT_TILED, load_optional_label(m_conf, name(), "label-tiled")); + m_modelabels.emplace(mode::STATE_FULLSCREEN, load_optional_label(m_conf, name(), "label-fullscreen")); + m_modelabels.emplace(mode::STATE_FLOATING, load_optional_label(m_conf, name(), "label-floating")); + m_modelabels.emplace(mode::NODE_LOCKED, load_optional_label(m_conf, name(), "label-locked")); + m_modelabels.emplace(mode::NODE_STICKY, load_optional_label(m_conf, name(), "label-sticky")); + m_modelabels.emplace(mode::NODE_PRIVATE, load_optional_label(m_conf, name(), "label-private")); } m_icons = make_shared(); - m_icons->add(DEFAULT_WS_ICON, make_shared