MCPcopy Create free account
hub / github.com/WayfireWM/wayfire / flatten_tree

Function flatten_tree

plugins/tile/tree.cpp:514–559  ·  view source on GitHub ↗

----------------- Generic tree operations implementation ----------------- */

Source from the content-addressed store, hash-verified

512
513/* ----------------- Generic tree operations implementation ----------------- */
514bool flatten_tree(std::unique_ptr<tree_node_t>& root)
515{
516 /* Cannot flatten a view node */
517 if (root->as_view_node())
518 {
519 return true;
520 }
521
522 for (auto it = root->children.begin(); it != root->children.end();)
523 {
524 if (!flatten_tree(*it))
525 {
526 it = root->children.erase(it);
527 } else
528 {
529 ++it;
530 }
531 }
532
533 if (root->children.empty())
534 {
535 return false;
536 }
537
538 /* No flattening required on this level */
539 if (root->children.size() >= 2)
540 {
541 return true;
542 }
543
544 nonstd::observer_ptr<tree_node_t> child_ptr = {root->children.front()};
545
546 /* A single view child => cannot make it root */
547 if (child_ptr->as_view_node())
548 {
549 if (!root->parent)
550 {
551 return true;
552 }
553 }
554
555 /* Rewire the tree, skipping the current root */
556 child_ptr->parent = root->parent;
557 root = std::move(root->children.front());
558 return true;
559}
560
561nonstd::observer_ptr<split_node_t> get_root(
562 nonstd::observer_ptr<tree_node_t> node)

Callers 2

handle_ipc_set_layoutFunction · 0.85
flatten_rootsMethod · 0.85

Calls 5

as_view_nodeMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected