// // Created by grimmauld on 03.03.24. // #ifndef SWAYMUX_SWAYTREEMODEL_H #define SWAYMUX_SWAYTREEMODEL_H #include #include #include "pstree.h" #include "AbstractTreeModel.h" #include "swaytree.h" #include "../sway_bindings/Sway.h" #include #include #include using json = nlohmann::json; class SwayTreeModel : public AbstractTreeModel { Q_OBJECT public: inline static Sway sway = Sway(); Q_DISABLE_COPY_MOVE(SwayTreeModel) explicit SwayTreeModel(QObject *parent = nullptr) : AbstractTreeModel(parent) { rootItem = nullptr; } void generateRoot() { 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( parent) {}; [[nodiscard]] SwayTreeNode *getRoot() const override { return rootItem; }; [[nodiscard]] inline QModelIndex findFocusedWindowIndex() const { return findIndexByNode(getRoot()->findFocused()); } [[nodiscard]] std::set getSelectedNodes(const QTreeView *treeView) const; [[nodiscard]] SwayTreeNode *getSelectedNode(const QModelIndex &i) const; [[nodiscard]] QModelIndex findIndexByNode(const SwayTreeNode *node) const; private: SwayTreeNode *rootItem; }; #endif //SWAYMUX_SWAYTREEMODEL_H