56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
//
|
|
// Created by grimmauld on 03.03.24.
|
|
//
|
|
|
|
#ifndef SWAYMUX_SWAYTREEMODEL_H
|
|
#define SWAYMUX_SWAYTREEMODEL_H
|
|
|
|
#include <QAbstractItemModel>
|
|
#include <utility>
|
|
#include "pstree.h"
|
|
#include "AbstractTreeModel.h"
|
|
#include "swaytree.h"
|
|
#include "../sway_bindings/Sway.h"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
#include <utility>
|
|
#include <QTreeView>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
class SwayTreeModel : public AbstractTreeModel<SwayTreeNode> {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
inline static Sway sway = Sway();
|
|
|
|
Q_DISABLE_COPY_MOVE(SwayTreeModel)
|
|
|
|
explicit SwayTreeModel(QObject *parent = nullptr) : AbstractTreeModel<SwayTreeNode>(parent) {
|
|
auto res = sway.sendIPC(SWAY_GET_TREE);
|
|
auto rep = json::parse(res.msg);
|
|
rootItem = new SwayTreeNode(rep);
|
|
}
|
|
|
|
~SwayTreeModel() override = default;
|
|
|
|
explicit SwayTreeModel(SwayTreeNode * rootItem, QObject *parent = nullptr) : rootItem(rootItem),
|
|
AbstractTreeModel<SwayTreeNode>(
|
|
parent) {};
|
|
|
|
[[nodiscard]] const SwayTreeNode *getRoot() const override {
|
|
return rootItem;
|
|
};
|
|
|
|
|
|
[[nodiscard]] QModelIndex findFocusedWindowIndex() const;
|
|
|
|
[[nodiscard]] std::set<SwayTreeNode*> getSelectedNodes(const QTreeView* treeView) const;
|
|
|
|
|
|
private:
|
|
SwayTreeNode * rootItem;
|
|
};
|
|
|
|
#endif //SWAYMUX_SWAYTREEMODEL_H
|