#include "modules/i3.hpp" #include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" #include "modules/meta/base.inl" #include "utils/file.hpp" #include POLYBAR_NS namespace modules { template class module; i3_module::i3_module(const bar_settings& bar, string name_, const config& conf) : event_module(bar, move(name_), conf) { m_router->register_action_with_data(EVENT_FOCUS, [this](const std::string& data) { action_focus(data); }); m_router->register_action(EVENT_NEXT, [this]() { action_next(); }); m_router->register_action(EVENT_PREV, [this]() { action_prev(); }); try { auto socket_path = i3ipc::get_socketpath(); if (!file_util::exists(socket_path)) { throw module_error("i3 socket does not exist: " + (socket_path.empty() ? "" : socket_path)); } else { m_log.info("%s: Found i3 socket at '%s'", name(), socket_path); } } catch (const i3ipc::ipc_error& e) { throw module_error("Could not find i3 socket: " + string(e.what())); } m_ipc = std::make_unique(); // Load configuration values m_click = m_conf.get(name(), "enable-click", m_click); m_scroll = m_conf.get(name(), "enable-scroll", m_scroll); m_revscroll = m_conf.get(name(), "reverse-scroll", m_revscroll); m_wrap = m_conf.get(name(), "wrapping-scroll", m_wrap); m_indexsort = m_conf.get(name(), "index-sort", m_indexsort); m_pinworkspaces = m_conf.get(name(), "pin-workspaces", m_pinworkspaces); m_show_urgent = m_conf.get(name(), "show-urgent", m_show_urgent); m_strip_wsnumbers = m_conf.get(name(), "strip-wsnumbers", m_strip_wsnumbers); m_fuzzy_match = m_conf.get(name(), "fuzzy-match", m_fuzzy_match); m_conf.warn_deprecated(name(), "wsname-maxlen", "%name:min:max%"); // Add formats and create components m_formatter->add(DEFAULT_FORMAT, DEFAULT_TAGS, {TAG_LABEL_STATE, TAG_LABEL_MODE}); if (m_formatter->has(TAG_LABEL_STATE)) { m_statelabels.insert( make_pair(state::FOCUSED, load_optional_label(m_conf, name(), "label-focused", DEFAULT_WS_LABEL))); m_statelabels.insert( make_pair(state::UNFOCUSED, load_optional_label(m_conf, name(), "label-unfocused", DEFAULT_WS_LABEL))); m_statelabels.insert( make_pair(state::VISIBLE, load_optional_label(m_conf, name(), "label-visible", DEFAULT_WS_LABEL))); m_statelabels.insert( make_pair(state::URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); } if (m_formatter->has(TAG_LABEL_MODE)) { m_modelabel = load_optional_label(m_conf, name(), "label-mode", "%mode%"); } m_labelseparator = load_optional_label(m_conf, name(), "label-separator", ""); m_icons = std::make_shared(); m_icons->add(DEFAULT_WS_ICON, std::make_shared