#include "modules/xworkspaces.hpp" #include #include #include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" #include "modules/meta/base.inl" #include "utils/math.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" POLYBAR_NS namespace { inline bool operator==(const position& a, const position& b) { return a.x + a.y == b.x + b.y; } } // namespace /** * Defines a lexicographical order on position */ bool operator<(const position& a, const position& b) { return std::make_tuple(a.x, a.y) < std::make_tuple(b.x, b.y); } namespace modules { template class module; /** * Construct module */ xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name_) : static_module(bar, move(name_)), m_connection(connection::make()) { m_router->register_action_with_data(EVENT_FOCUS, &xworkspaces_module::action_focus); m_router->register_action(EVENT_NEXT, &xworkspaces_module::action_next); m_router->register_action(EVENT_PREV, &xworkspaces_module::action_prev); // Load config values m_pinworkspaces = m_conf.get(name(), "pin-workspaces", m_pinworkspaces); 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); // Initialize ewmh atoms if ((m_ewmh = ewmh_util::initialize()) == nullptr) { throw module_error("Failed to initialize ewmh atoms"); } // Check if the WM supports _NET_CURRENT_DESKTOP if (!ewmh_util::supports(m_ewmh->_NET_CURRENT_DESKTOP)) { throw module_error("The WM does not support _NET_CURRENT_DESKTOP, aborting..."); } // Check if the WM supports _NET_DESKTOP_VIEWPORT if (!(m_monitorsupport = ewmh_util::supports(m_ewmh->_NET_DESKTOP_VIEWPORT)) && m_pinworkspaces) { throw module_error("The WM does not support _NET_DESKTOP_VIEWPORT (required when `pin-workspaces = true`)"); } // Add formats and elements m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE, TAG_LABEL_MONITOR}); if (m_formatter->has(TAG_LABEL_MONITOR)) { m_monitorlabel = load_optional_label(m_conf, name(), "label-monitor", DEFAULT_LABEL_MONITOR); } if (m_formatter->has(TAG_LABEL_STATE)) { // clang-format off m_labels.insert(make_pair( desktop_state::ACTIVE, load_optional_label(m_conf, name(), "label-active", DEFAULT_LABEL_STATE))); m_labels.insert(make_pair( desktop_state::OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_LABEL_STATE))); m_labels.insert(make_pair( desktop_state::URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_LABEL_STATE))); m_labels.insert(make_pair( desktop_state::EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_LABEL_STATE))); // clang-format on } m_icons = std::make_shared(); m_icons->add(DEFAULT_ICON, std::make_shared