File indexing completed on 2024-05-12 05:32:15

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include "customtile.h"
0013 #include "quicktile.h"
0014 #include "scripting/tilemodel.h"
0015 #include "tile.h"
0016 #include "utils/common.h"
0017 #include <kwin_export.h>
0018 
0019 #include <QAbstractItemModel>
0020 #include <QObject>
0021 #include <QRectF>
0022 
0023 #include <QJsonValue>
0024 
0025 class QTimer;
0026 
0027 namespace KWin
0028 {
0029 
0030 class Output;
0031 class Tile;
0032 class TileModel;
0033 
0034 /**
0035  * Custom tiling zones management per output.
0036  */
0037 class KWIN_EXPORT TileManager : public QObject
0038 {
0039     Q_OBJECT
0040     Q_PROPERTY(KWin::Tile *rootTile READ rootTile CONSTANT)
0041     Q_PROPERTY(TileModel *model READ model CONSTANT)
0042 
0043 public:
0044     explicit TileManager(Output *parent = nullptr);
0045     ~TileManager() override;
0046 
0047     Output *output() const;
0048 
0049     KWin::Tile *bestTileForPosition(const QPointF &pos);
0050     Q_INVOKABLE KWin::Tile *bestTileForPosition(qreal x, qreal y); // For scripting
0051     CustomTile *rootTile() const;
0052     KWin::Tile *quickTile(QuickTileMode mode) const;
0053 
0054     TileModel *model() const;
0055 
0056 Q_SIGNALS:
0057     void tileRemoved(KWin::Tile *tile);
0058 
0059 private:
0060     void readSettings();
0061     void saveSettings();
0062     QJsonObject tileToJSon(CustomTile *parentTile);
0063     CustomTile *parseTilingJSon(const QJsonValue &val, const QRectF &availableArea, CustomTile *parentTile);
0064 
0065     Q_DISABLE_COPY(TileManager)
0066 
0067     Output *m_output = nullptr;
0068     std::unique_ptr<QTimer> m_saveTimer;
0069     std::unique_ptr<CustomTile> m_rootTile = nullptr;
0070     std::unique_ptr<QuickRootTile> m_quickRootTile = nullptr;
0071     std::unique_ptr<TileModel> m_tileModel = nullptr;
0072     friend class CustomTile;
0073 };
0074 
0075 KWIN_EXPORT QDebug operator<<(QDebug debug, const TileManager *tileManager);
0076 
0077 } // namespace KWin