swaymux/tree/SwayTreeModel.cpp

27 lines
719 B
C++
Raw Normal View History

2024-03-04 00:27:05 +01:00
//
// Created by grimmauld on 03.03.24.
//
#include "SwayTreeModel.h"
QModelIndex SwayTreeModel::getFocused() const {
std::function<bool(const SwayTreeNode *)> test = [](const SwayTreeNode *node) {
return node->node.focused;
};
const SwayTreeNode *focused = rootItem->findChildRecursive(test);
std::vector<int> indices;
for (const auto *head = focused; head != nullptr; head = head->parentItem()) {
indices.insert(indices.cbegin(), head->row());
}
// weirdness, idk... ask QT
QModelIndex idx = this->index(indices.size() < 2 ? 0 : indices[1], 0);
for (int i = 2; i < indices.size(); ++i) {
idx = this->index(indices[i], 0, idx);
}
return idx;
}