#include "modules/xkeyboard.hpp" #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" #include "modules/meta/base.inl" #include "x11/atoms.hpp" #include "x11/connection.hpp" POLYBAR_NS namespace modules { template class module; // clang-format off static const keyboard::indicator::type INDICATOR_TYPES[] { keyboard::indicator::type::CAPS_LOCK, keyboard::indicator::type::NUM_LOCK, keyboard::indicator::type::SCROLL_LOCK }; // clang-format on /** * Construct module */ xkeyboard_module::xkeyboard_module(const bar_settings& bar, string name_) : static_module(bar, move(name_)), m_connection(connection::make()) { m_router->register_action(EVENT_SWITCH, [this]() { action_switch(); }); // Setup extension // clang-format off m_connection.xkb().select_events_checked(XCB_XKB_ID_USE_CORE_KBD, XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY | XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_INDICATOR_STATE_NOTIFY, 0, XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY | XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_INDICATOR_STATE_NOTIFY, 0, 0, nullptr); // clang-format on // Create keyboard object query_keyboard(); // Load config values m_blacklist = m_conf.get_list(name(), "blacklist", {}); // load layout icons parse_icons(); // Add formats and elements m_formatter->add(DEFAULT_FORMAT, FORMAT_DEFAULT, {TAG_LABEL_LAYOUT, TAG_LABEL_INDICATOR}); if (m_formatter->has(TAG_LABEL_LAYOUT)) { m_layout = load_optional_label(m_conf, name(), TAG_LABEL_LAYOUT, "%layout%"); } if (m_formatter->has(TAG_LABEL_INDICATOR)) { m_conf.warn_deprecated(name(), "label-indicator", "label-indicator-on"); // load an empty label if 'label-indicator-off' is not explicitly specified so // no existing user configs are broken (who expect nothing to be shown when indicator is off) m_indicator_state_off = load_optional_label(m_conf, name(), "label-indicator-off"s, ""s); if (m_conf.has(name(), "label-indicator-on"s)) { m_indicator_state_on = load_optional_label(m_conf, name(), "label-indicator-on"s, "%name%"s); } else { // if 'label-indicator-on' is not explicitly specified, use 'label-indicator' // as to not break existing user configs m_indicator_state_on = load_optional_label(m_conf, name(), TAG_LABEL_INDICATOR, "%name%"s); } // load indicator icons m_indicator_icons_off = std::make_shared(); m_indicator_icons_on = std::make_shared(); auto icon_pair = string_util::tokenize(m_conf.get(name(), DEFAULT_INDICATOR_ICON, ""s), ';'); if (icon_pair.size() == 2) { m_indicator_icons_off->add(DEFAULT_INDICATOR_ICON, std::make_shared