src/modules/xworkspaces.cpp
/**
   * Rebuild the desktop tree
   *
   * This requires m_desktop_names to have an up-to-date value
   */
Rebuild the desktop tree
This requires m_desktop_names to have an up-to-date value
Rebuild the desktop tree This requires m_desktop_names to have an up - to - date value
void xworkspaces_module::rebuild_desktops() {
    m_viewports.clear();
    vector<position> ws_positions = ewmh_util::get_desktop_viewports();
    if (ws_positions.size() < m_desktop_names.size()) {
      auto num_insert = m_desktop_names.size() - ws_positions.size();
      ws_positions.reserve(num_insert);
      std::fill_n(std::back_inserter(ws_positions), num_insert, position{0, 0});
    }
    std::set<position> viewports(ws_positions.begin(), ws_positions.end());
    for (auto&& viewport_pos : viewports) {
      if (!m_pinworkspaces || m_bar.monitor->contains(viewport_pos)) {
        auto viewport = make_unique<struct viewport>();
        viewport->state = viewport_state::UNFOCUSED;
        viewport->pos = viewport_pos;
        for (auto&& m : m_monitors) {
          if (m->contains(viewport->pos)) {
            viewport->name = m->name;
            viewport->state = viewport_state::FOCUSED;
          }
        }
        viewport->label = [&] {
          label_t label;
          if (m_monitorlabel) {
            label = m_monitorlabel->clone();
            label->reset_tokens();
            label->replace_token("%name%", viewport->name);
          }
          return label;
        }();
        for (size_t i = 0; i < ws_positions.size(); i++) {
          auto&& ws_pos = ws_positions[i];
          if (ws_pos == viewport_pos) {
            viewport->desktops.emplace_back(make_unique<struct desktop>(i, desktop_state::EMPTY, label_t{}));
          }
        }
        m_viewports.emplace_back(move(viewport));
      }
    }
  }
void xworkspaces_module :: rebuild_desktops ( ) { m_viewports . clear ( ) ; vector < position > ws_positions = ewmh_util :: get_desktop_viewports ( ) ; if ( ws_positions . size ( ) < m_desktop_names . size ( ) ) { auto num_insert = m_desktop_names . size ( ) - ws_positions . size ( ) ; ws_positions . reserve ( num_insert ) ; std :: fill_n ( std :: back_inserter ( ws_positions ) , num_insert , position { 0 , 0 } ) ; } std :: set < position > viewports ( ws_positions . begin ( ) , ws_positions . end ( ) ) ; for ( auto && viewport_pos : viewports ) { if ( ! m_pinworkspaces || m_bar . monitor -> contains ( viewport_pos ) ) { auto viewport = make_unique < struct viewport > ( ) ; viewport -> state = viewport_state :: UNFOCUSED ; viewport -> pos = viewport_pos ; for ( auto && m : m_monitors ) { if ( m -> contains ( viewport -> pos ) ) { viewport -> name = m -> name ; viewport -> state = viewport_state :: FOCUSED ; } } viewport -> label = [ & ] { label_t label ; if ( m_monitorlabel ) { label = m_monitorlabel -> clone ( ) ; label -> reset_tokens ( ) ; label -> replace_token ( " " , viewport -> name ) ; } return label ; } ( ) ; for ( size_t i = 0 ; i < ws_positions . size ( ) ; i ++ ) { auto && ws_pos = ws_positions [ i ] ; if ( ws_pos == viewport_pos ) { viewport -> desktops . emplace_back ( make_unique < struct desktop > ( i , desktop_state :: EMPTY , label_t { } ) ) ; } } m_viewports . emplace_back ( move ( viewport ) ) ; } } }
Rebuild the desktop tree
 This requires m_desktop_names to have an up-to-date value
Rebuild the desktop tree This requires m_desktop_names to have an up - to - date value
/*
     * Stores the _NET_DESKTOP_VIEWPORT hint
     *
     * For WMs that don't support that hint, we store an empty vector
     *
     * If the length of the vector is less than _NET_NUMBER_OF_DESKTOPS
     * all desktops which aren't explicitly assigned a postion will be
     * assigned (0, 0)
     *
     * We use this to map workspaces to viewports, desktop i is at position
     * ws_positions[i].
     */ /*
     * Not all desktops were assigned a viewport, add (0, 0) for all missing
     * desktops.
     */ /*
     * The list of viewports is the set of unique positions in ws_positions
     * Using a set automatically removes duplicates.
     */ /*
       * If pin-workspaces is set, we only add the viewport if it's in the
       * monitor the bar is on.
       * Generally viewport_pos is the same as the top-left coordinate of the
       * monitor but we use `contains` here as a safety in case it isn't exactly.
       */