File indexing completed on 2024-05-05 05:38:40

0001 /*
0002     SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "abstractwindowtasksmodel.h"
0010 
0011 #include "taskmanager_export.h"
0012 
0013 #include <QMimeData>
0014 #include <qwindowdefs.h>
0015 
0016 #include <memory>
0017 
0018 #include <netwm.h>
0019 
0020 namespace TaskManager
0021 {
0022 /**
0023  * @short A tasks model for X Window System windows.
0024  *
0025  * This model presents tasks sourced from window data on the X Windows
0026  * server the host process is connected to.
0027  *
0028  * For the purposes of presentation in a user interface and efficiency,
0029  * certain types of windows (e.g. utility windows, or windows that are
0030  * transients for an otherwise-included window) are omitted from the
0031  * model.
0032  *
0033  * @see WindowTasksModel
0034  *
0035  * @author Eike Hein <hein@kde.org>
0036  */
0037 
0038 class TASKMANAGER_EXPORT XWindowTasksModel : public AbstractWindowTasksModel
0039 {
0040     Q_OBJECT
0041 
0042 public:
0043     explicit XWindowTasksModel(QObject *parent = nullptr);
0044     ~XWindowTasksModel() override;
0045 
0046     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0047     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0048 
0049     /**
0050      * Request activation of the window at the given index.
0051      *
0052      * If the window has a transient demanding attention, it will be
0053      * activated instead.
0054      *
0055      * If the window has a transient in shaded state, it will be
0056      * activated instead.
0057      *
0058      * @param index An index in this window tasks model.
0059      **/
0060     void requestActivate(const QModelIndex &index) override;
0061 
0062     /**
0063      * Request an additional instance of the application owning the window
0064      * at the given index. Success depends on whether a
0065      * AbstractTasksModel::LauncherUrl could be derived from window metadata.
0066      *
0067      * @param index An index in this window tasks model.
0068      **/
0069     void requestNewInstance(const QModelIndex &index) override;
0070 
0071     /**
0072      * Runs the application backing the launcher at the given index with the given URLs.
0073      * Success depends on whether a AbstractTasksModel::LauncherUrl could be
0074      * derived from window metadata and a KService could be found from that.
0075      *
0076      * @param index An index in this launcher tasks model
0077      * @param urls The URLs to be passed to the application
0078      */
0079     void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
0080 
0081     /**
0082      * Request the window at the given index be closed.
0083      *
0084      * @param index An index in this window tasks model.
0085      **/
0086     void requestClose(const QModelIndex &index) override;
0087 
0088     /**
0089      * Request starting an interactive move for the window at the given index.
0090      *
0091      * If the window is not currently the active window, it will be activated.
0092      *
0093      * If the window is not on the current desktop, the current desktop will
0094      * be set to the window's desktop.
0095      * FIXME: Desktop logic should maybe move into proxy.
0096      *
0097      * @param index An index in this window tasks model.
0098      **/
0099     void requestMove(const QModelIndex &index) override;
0100 
0101     /**
0102      * Request starting an interactive resize for the window at the given index.
0103      *
0104      * If the window is not currently the active window, it will be activated.
0105      *
0106      * If the window is not on the current desktop, the current desktop will
0107      * be set to the window's desktop.
0108      * FIXME: Desktop logic should maybe move into proxy.
0109      *
0110      * @param index An index in this window tasks model.
0111      **/
0112     void requestResize(const QModelIndex &index) override;
0113 
0114     /**
0115      * Request toggling the minimized state of the window at the given index.
0116      *
0117      * If the window is not on the current desktop, the current desktop will
0118      * be set to the window's desktop.
0119      * FIXME: Desktop logic should maybe move into proxy.
0120      *
0121      * @param index An index in this window tasks model.
0122      **/
0123     void requestToggleMinimized(const QModelIndex &index) override;
0124 
0125     /**
0126      * Request toggling the maximized state of the task at the given index.
0127      *
0128      * If the window is not on the current desktop, the current desktop will
0129      * be set to the window's desktop.
0130      * FIXME: Desktop logic should maybe move into proxy.
0131      *
0132      * @param index An index in this window tasks model.
0133      **/
0134     void requestToggleMaximized(const QModelIndex &index) override;
0135 
0136     /**
0137      * Request toggling the keep-above state of the task at the given index.
0138      *
0139      * @param index An index in this window tasks model.
0140      **/
0141     void requestToggleKeepAbove(const QModelIndex &index) override;
0142 
0143     /**
0144      * Request toggling the keep-below state of the task at the given index.
0145      *
0146      * @param index An index in this window tasks model.
0147      **/
0148     void requestToggleKeepBelow(const QModelIndex &index) override;
0149 
0150     /**
0151      * Request toggling the fullscreen state of the task at the given index.
0152      *
0153      * @param index An index in this window tasks model.
0154      **/
0155     void requestToggleFullScreen(const QModelIndex &index) override;
0156 
0157     /**
0158      * Request toggling the shaded state of the task at the given index.
0159      *
0160      * @param index An index in this window tasks model.
0161      **/
0162     void requestToggleShaded(const QModelIndex &index) override;
0163 
0164     /**
0165      * Request entering the window at the given index on the specified virtual desktop.
0166      * For compatibility across windowing systems the library supports, the desktops
0167      * parameter is a list; however, on X11 a window can only be on one or all virtual
0168      * desktops. Therefore, only the first list entry is actually used.
0169      *
0170      * An empty list has a special meaning: The window is entered on all virtual desktops
0171      * in the session.
0172      *
0173      * The id 0 has a special meaning: The window is entered on all virtual desktops in
0174      * the session.
0175      *
0176      * @param index An index in this window tasks model.
0177      * @param desktops A list of virtual desktop ids (uint).
0178      **/
0179     void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
0180 
0181     /**
0182      * Request entering the window at the given index on a new virtual desktop,
0183      * which is created in response to this request.
0184      *
0185      * @param index An index in this window tasks model.
0186      **/
0187     void requestNewVirtualDesktop(const QModelIndex &index) override;
0188 
0189     /**
0190      * Request moving the task at the given index to the specified activities.
0191      *
0192      * This is meant for tasks that have an associated window, and may be
0193      * a no-op when there is no window.
0194      *     *
0195      * @param index An index in this tasks model.
0196      * @param activities The new list of activities.
0197      **/
0198     void requestActivities(const QModelIndex &index, const QStringList &activities) override;
0199 
0200     /**
0201      * Request informing the window manager of new geometry for a visual
0202      * delegate for the window at the given index.
0203      *
0204      * @param index An index in this window tasks model.
0205      * @param geometry Visual delegate geometry in screen coordinates.
0206      * @param delegate The delegate. Unused in this implementation.
0207      **/
0208     void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
0209 
0210     /**
0211      * Tries to extract a X11 window id from supplied mime data.
0212      *
0213      * @param mimeData Some mime data.
0214      * @param @ok Set to true or false on success or failure.
0215      */
0216     static WId winIdFromMimeData(const QMimeData *mimeData, bool *ok = nullptr);
0217 
0218     /**
0219      * Tries to extract X11 window ids from supplied mime data.
0220      *
0221      * @param mimeData Some mime data.
0222      * @param @ok Set to true or false on success or failure.
0223      */
0224     static QList<WId> winIdsFromMimeData(const QMimeData *mimeData, bool *ok = nullptr);
0225 
0226 private:
0227     class Private;
0228     std::unique_ptr<Private> d;
0229 };
0230 
0231 }