#include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" #include "modules/xworkspaces.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" #include "modules/meta/base.inl" #include "modules/meta/static_module.inl" POLYBAR_NS namespace modules { template class module; template class static_module; /** * Construct module */ xworkspaces_module::xworkspaces_module( const bar_settings& bar, const logger& logger, const config& config, string name) : static_module(bar, logger, config, name) , m_connection(configure_connection().create()) {} /** * Bootstrap the module */ void xworkspaces_module::setup() { // 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); // 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.get(), 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 (!ewmh_util::supports(m_ewmh.get(), m_ewmh->_NET_DESKTOP_VIEWPORT) && m_pinworkspaces) { throw module_error("The WM does not support _NET_DESKTOP_VIEWPORT (required when `pin-workspaces = true`)"); } else if (!m_pinworkspaces) { m_monitorsupport = false; } // Get list of monitors m_monitors = randr_util::get_monitors(m_connection, m_connection.root(), false); // 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)) { 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))); } m_icons = make_shared(); m_icons->add(DEFAULT_ICON, make_shared