File indexing completed on 2024-05-19 05:35:57

0001 /*
0002     SPDX-FileCopyrightText: 2013-2016 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QRect>
0011 
0012 #include <netwm.h>
0013 #include <qwindowdefs.h>
0014 
0015 class QAction;
0016 class QActionGroup;
0017 class QQuickItem;
0018 class QQuickWindow;
0019 class QJsonArray;
0020 
0021 namespace KActivities
0022 {
0023 class Consumer;
0024 }
0025 
0026 class Backend : public QObject
0027 {
0028     Q_OBJECT
0029 
0030     Q_PROPERTY(bool highlightWindows READ highlightWindows WRITE setHighlightWindows NOTIFY highlightWindowsChanged)
0031     Q_PROPERTY(bool windowViewAvailable READ windowViewAvailable NOTIFY windowViewAvailableChanged)
0032 
0033 public:
0034     enum MiddleClickAction {
0035         None = 0,
0036         Close,
0037         NewInstance,
0038         ToggleMinimized,
0039         ToggleGrouping,
0040         BringToCurrentDesktop,
0041     };
0042 
0043     Q_ENUM(MiddleClickAction)
0044 
0045     explicit Backend(QObject *parent = nullptr);
0046     ~Backend() override;
0047 
0048     bool highlightWindows() const;
0049     void setHighlightWindows(bool highlight);
0050 
0051     Q_INVOKABLE QVariantList jumpListActions(const QUrl &launcherUrl, QObject *parent);
0052     Q_INVOKABLE QVariantList placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent);
0053     Q_INVOKABLE QVariantList recentDocumentActions(const QUrl &launcherUrl, QObject *parent);
0054     Q_INVOKABLE void setActionGroup(QAction *action) const;
0055 
0056     Q_INVOKABLE QRect globalRect(QQuickItem *item) const;
0057 
0058     bool windowViewAvailable() const;
0059 
0060     Q_INVOKABLE bool isApplication(const QUrl &url) const;
0061 
0062     Q_INVOKABLE void cancelHighlightWindows();
0063 
0064     Q_INVOKABLE qint64 parentPid(qint64 pid) const;
0065 
0066     Q_INVOKABLE static QUrl tryDecodeApplicationsUrl(const QUrl &launcherUrl);
0067     Q_INVOKABLE static QStringList applicationCategories(const QUrl &launcherUrl);
0068 
0069 public Q_SLOTS:
0070     void activateWindowView(const QVariant &winIds);
0071     void windowsHovered(const QVariant &winIds, bool hovered);
0072 
0073 Q_SIGNALS:
0074     void highlightWindowsChanged() const;
0075     void addLauncher(const QUrl &url) const;
0076     void windowViewAvailableChanged();
0077 
0078     void showAllPlaces();
0079 
0080 private Q_SLOTS:
0081     void handleRecentDocumentAction() const;
0082 
0083 private:
0084     void updateWindowHighlight();
0085 
0086     QVariantList systemSettingsActions(QObject *parent) const;
0087 
0088     bool m_highlightWindows;
0089     QStringList m_windowsToHighlight;
0090     QActionGroup *m_actionGroup = nullptr;
0091     KActivities::Consumer *m_activitiesConsumer = nullptr;
0092     bool m_windowViewAvailable = false;
0093 };