2024-03-04 00:27:05 +01:00
|
|
|
//
|
|
|
|
// Created by grimmauld on 03.03.24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SWAYMUX_SWAYTREEMODEL_H
|
|
|
|
#define SWAYMUX_SWAYTREEMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <utility>
|
|
|
|
#include "AbstractTreeModel.h"
|
|
|
|
#include "swaytree.h"
|
|
|
|
#include "../sway_bindings/Sway.h"
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <utility>
|
2024-03-08 13:13:28 +01:00
|
|
|
#include <QTreeView>
|
2024-03-04 00:27:05 +01:00
|
|
|
|
|
|
|
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) {
|
2024-03-11 13:33:26 +01:00
|
|
|
rootItem = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void generateRoot() {
|
2024-03-04 00:27:05 +01:00
|
|
|
auto res = sway.sendIPC(SWAY_GET_TREE);
|
|
|
|
auto rep = json::parse(res.msg);
|
|
|
|
rootItem = new SwayTreeNode(rep);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SwayTreeModel() override = default;
|
|
|
|
|
2024-03-11 13:33:26 +01:00
|
|
|
explicit SwayTreeModel(SwayTreeNode *rootItem, QObject *parent = nullptr) : rootItem(rootItem),
|
|
|
|
AbstractTreeModel<SwayTreeNode>(
|
|
|
|
parent) {};
|
2024-03-04 00:27:05 +01:00
|
|
|
|
2024-03-11 13:33:26 +01:00
|
|
|
[[nodiscard]] SwayTreeNode *getRoot() const override {
|
2024-03-04 00:27:05 +01:00
|
|
|
return rootItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-03-09 23:44:43 +01:00
|
|
|
[[nodiscard]] inline QModelIndex findFocusedWindowIndex() const {
|
|
|
|
return findIndexByNode(getRoot()->findFocused());
|
|
|
|
}
|
2024-03-06 23:40:48 +01:00
|
|
|
|
2024-03-26 18:01:53 +01:00
|
|
|
[[nodiscard]] std::set<const SwayTreeNode *> getSelectedNodes(const QTreeView *treeView) const;
|
2024-03-08 13:13:28 +01:00
|
|
|
|
2024-03-11 13:33:26 +01:00
|
|
|
[[nodiscard]] SwayTreeNode *getSelectedNode(const QModelIndex &i) const;
|
2024-03-09 23:44:43 +01:00
|
|
|
|
|
|
|
[[nodiscard]] QModelIndex findIndexByNode(const SwayTreeNode *node) const;
|
2024-03-06 23:40:48 +01:00
|
|
|
|
2024-03-11 13:33:26 +01:00
|
|
|
|
2024-03-04 00:27:05 +01:00
|
|
|
private:
|
2024-03-11 13:33:26 +01:00
|
|
|
SwayTreeNode *rootItem;
|
2024-03-04 00:27:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //SWAYMUX_SWAYTREEMODEL_H
|