src/modules/ipc.cpp
/**
   * Load user-defined ipc hooks and
   * create formatting tags
   */
Load user-defined ipc hooks and
create formatting tags
Load user - defined ipc hooks and create formatting tags
ipc_module::ipc_module(const bar_settings& bar, string name_) : module<ipc_module>(bar, move(name_)), m_initial(0) {
    m_router->register_action_with_data(EVENT_SEND, [this](const std::string& data) { action_send(data); });
    m_router->register_action_with_data(EVENT_HOOK, [this](const std::string& data) { action_hook(data); });
    m_router->register_action(EVENT_NEXT, [this]() { action_next(); });
    m_router->register_action(EVENT_PREV, [this]() { action_prev(); });
    m_router->register_action(EVENT_RESET, [this]() { action_reset(); });
    size_t index = 0;
    for (auto&& command : m_conf.get_list<string>(name(), "hook", {})) {
      m_hooks.emplace_back(std::make_unique<hook>(hook{name() + to_string(++index), command}));
    }
    m_log.info("%s: Loaded %d hooks", name(), m_hooks.size());
    m_initial = m_conf.get(name(), "initial", 0_z);
    if (m_conf.has(name(), "initial") && m_initial != 0) {
      if (m_initial <= m_hooks.size()) {
        m_current_hook = m_initial - 1;
      } else {
        throw module_error("Initial hook out of bounds '" + to_string(m_initial) + "'. Defined hooks goes from 1 to " +
                           to_string(m_hooks.size()) + ")");
      }
    } else {
      m_current_hook = m_hooks.size();
    }
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::LEFT, m_conf.get(name(), "click-left", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::MIDDLE, m_conf.get(name(), "click-middle", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::RIGHT, m_conf.get(name(), "click-right", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::SCROLL_UP, m_conf.get(name(), "scroll-up", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::SCROLL_DOWN, m_conf.get(name(), "scroll-down", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::DOUBLE_LEFT, m_conf.get(name(), "double-click-left", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::DOUBLE_MIDDLE, m_conf.get(name(), "double-click-middle", ""s)));
    m_actions.emplace(make_pair<mousebtn, string>(mousebtn::DOUBLE_RIGHT, m_conf.get(name(), "double-click-right", ""s)));
    const auto pid_token = [](const string& s) { return string_util::replace_all(s, "%pid%", to_string(getpid())); };
    for (auto& action : m_actions) {
      action.second = pid_token(action.second);
    }
    for (auto& hook : m_hooks) {
      hook->command = pid_token(hook->command);
    }
    m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});
  }
ipc_module :: ipc_module ( const bar_settings & bar , string name_ ) : module < ipc_module > ( bar , move ( name_ ) ) , m_initial ( 0 ) { m_router -> register_action_with_data ( EVENT_SEND , [ this ] ( const std :: string & data ) { action_send ( data ) ; } ) ; m_router -> register_action_with_data ( EVENT_HOOK , [ this ] ( const std :: string & data ) { action_hook ( data ) ; } ) ; m_router -> register_action ( EVENT_NEXT , [ this ] ( ) { action_next ( ) ; } ) ; m_router -> register_action ( EVENT_PREV , [ this ] ( ) { action_prev ( ) ; } ) ; m_router -> register_action ( EVENT_RESET , [ this ] ( ) { action_reset ( ) ; } ) ; size_t index = 0 ; for ( auto && command : m_conf . get_list < string > ( name ( ) , " " , { } ) ) { m_hooks . emplace_back ( std :: make_unique < hook > ( hook { name ( ) + to_string ( ++ index ) , command } ) ) ; } m_log . info ( " " , name ( ) , m_hooks . size ( ) ) ; m_initial = m_conf . get ( name ( ) , " " , 0 _z ) ; if ( m_conf . has ( name ( ) , " " ) && m_initial != 0 ) { if ( m_initial <= m_hooks . size ( ) ) { m_current_hook = m_initial - 1 ; } else { throw module_error ( " " + to_string ( m_initial ) + " " + to_string ( m_hooks . size ( ) ) + " " ) ; } } else { m_current_hook = m_hooks . size ( ) ; } m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: LEFT , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: MIDDLE , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: RIGHT , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: SCROLL_UP , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: SCROLL_DOWN , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: DOUBLE_LEFT , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: DOUBLE_MIDDLE , m_conf . get ( name ( ) , " " , " " s ) ) ) ; m_actions . emplace ( make_pair < mousebtn , string > ( mousebtn :: DOUBLE_RIGHT , m_conf . get ( name ( ) , " " , " " s ) ) ) ; const auto pid_token = [ ] ( const string & s ) { return string_util :: replace_all ( s , " " , to_string ( getpid ( ) ) ) ; } ; for ( auto & action : m_actions ) { action . second = pid_token ( action . second ) ; } for ( auto & hook : m_hooks ) { hook -> command = pid_token ( hook -> command ) ; } m_formatter -> add ( DEFAULT_FORMAT , TAG_OUTPUT , { TAG_OUTPUT } ) ; }
Load user-defined ipc hooks and
 create formatting tags
Load user - defined ipc hooks and create formatting tags
// clang-format off // clang-format on