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

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 #include "tabboxhandler.h"
0012 
0013 #include <QModelIndex>
0014 /**
0015  * @file
0016  * This file defines the class ClientModel, the model for Windows.
0017  *
0018  * @author Martin Gräßlin <mgraesslin@kde.org>
0019  * @since 4.4
0020  */
0021 
0022 namespace KWin
0023 {
0024 namespace TabBox
0025 {
0026 
0027 /**
0028  * The model for Windows used in TabBox.
0029  *
0030  * @author Martin Gräßlin <mgraesslin@kde.org>
0031  * @since 4.4
0032  */
0033 class ClientModel
0034     : public QAbstractItemModel
0035 {
0036     Q_OBJECT
0037 public:
0038     enum {
0039         ClientRole = Qt::UserRole, ///< The Window
0040         CaptionRole = Qt::UserRole + 1, ///< The caption of Window
0041         DesktopNameRole = Qt::UserRole + 2, ///< The name of the desktop the Window is on
0042         IconRole = Qt::UserRole + 3, // TODO: to be removed
0043         WIdRole = Qt::UserRole + 5, ///< The window ID of Window
0044         MinimizedRole = Qt::UserRole + 6, ///< Window is minimized
0045         CloseableRole = Qt::UserRole + 7 ///< Window can be closed
0046     };
0047     explicit ClientModel(QObject *parent = nullptr);
0048     ~ClientModel() override;
0049     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0050     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0051     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0052     QModelIndex parent(const QModelIndex &child) const override;
0053     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0054     QHash<int, QByteArray> roleNames() const override;
0055     Q_INVOKABLE QString longestCaption() const;
0056 
0057     /**
0058      * @param client The Window whose index should be returned
0059      * @return Returns the ModelIndex of given Window or an invalid ModelIndex
0060      * if the model does not contain the given Window.
0061      */
0062     QModelIndex index(Window *client) const;
0063 
0064     /**
0065      * Generates a new list of Windows based on the current config.
0066      * Calling this method will reset the model. If partialReset is true
0067      * the top of the list is kept as a starting point. If not the
0068      * current active client is used as the starting point to generate the
0069      * list.
0070      * @param partialReset Keep the currently selected client or regenerate everything
0071      */
0072     void createClientList(bool partialReset = false);
0073     /**
0074      * @return Returns the current list of Windows.
0075      */
0076     QList<Window *> clientList() const
0077     {
0078         return m_mutableClientList;
0079     }
0080 
0081 public Q_SLOTS:
0082     void close(int index);
0083     /**
0084      * Activates the client at @p index and closes the TabBox.
0085      * @param index The row index
0086      */
0087     void activate(int index);
0088 
0089 private:
0090     void createFocusChainClientList(Window *start);
0091     void createStackingOrderClientList(Window *start);
0092 
0093     QList<Window *> m_clientList;
0094     QList<Window *> m_mutableClientList;
0095 };
0096 
0097 } // namespace Tabbox
0098 } // namespace KWin