#include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" #include "modules/bspwm.hpp" #include "utils/factory.hpp" #include "utils/file.hpp" #include "modules/meta/base.inl" 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; bspwm_module::bspwm_module(const bar_settings& bar, string name_) : event_module(bar, move(name_)) { auto socket_path = bspwm_util::get_socket_path(); if (!file_util::exists(socket_path)) { throw module_error("Could not find socket: " + (socket_path.empty() ? "" : socket_path)); } // Create ipc subscriber m_subscriber = bspwm_util::make_subscriber(); // Load configuration values GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces"); GET_CONFIG_VALUE(name(), m_click, "enable-click"); GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll"); GET_CONFIG_VALUE(name(), m_revscroll, "reverse-scroll"); // Add formats and create components m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE}); if (m_formatter->has(TAG_LABEL_MONITOR)) { m_monitorlabel = load_optional_label(m_conf, name(), "label-monitor", DEFAULT_MONITOR_LABEL); } if (m_formatter->has(TAG_LABEL_STATE)) { // 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.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 = factory_util::shared(); m_icons->add(DEFAULT_ICON, factory_util::shared