File indexing completed on 2024-05-19 15:09:26

0001 /*
0002     SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef KWINDOWSYSTEMPROXY_H
0008 #define KWINDOWSYSTEMPROXY_H
0009 
0010 #include <QObject>
0011 #include <QString>
0012 
0013 #include "kdeclarative/kdeclarative_export.h"
0014 
0015 class QMetaMethod;
0016 class QWindow;
0017 
0018 /**
0019  * This item exposes various properties of KWindowSystem for use inside a QML environment.
0020  *
0021  * Example usage:
0022  * @code
0023  * import org.kde.kwindowsystem 1.0
0024  *
0025  * KWindowSystem {
0026  *     id: kwindowsystem
0027  * }
0028  *
0029  * Rectangle {
0030  *     width: 50
0031  *     height: 50
0032  *     color: "blue"
0033  *     opacity: kwindowsystem.compositingActive ? 0.5 : 1
0034  * }
0035  *
0036  * Label {
0037  *     text: i18n("You are currently on Desktop '%1'", kwindowsystem.currentDesktopName)
0038  * }
0039  * @endcode
0040  *
0041  * @note The features provided by this item are specific to the windowing system and might not
0042  * be supported on any platform other than X11
0043  */
0044 class KWindowSystemProxy : public QObject
0045 {
0046     Q_OBJECT
0047 
0048 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0049     /**
0050      * @brief The number of the current desktop
0051      */
0052     Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged)
0053 #endif
0054 
0055 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0056     /**
0057      * @brief The name of the current desktop
0058      */
0059     Q_PROPERTY(QString currentDesktopName READ currentDesktopName NOTIFY currentDesktopNameChanged)
0060 #endif
0061 
0062 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0063     /**
0064      * @brief The number of desktops
0065      */
0066     Q_PROPERTY(int numberOfDesktops READ numberOfDesktops NOTIFY numberOfDesktopsChanged)
0067 #endif
0068 
0069     /**
0070      * @brief Whether "show desktop" is currently active
0071      */
0072     Q_PROPERTY(bool showingDesktop READ showingDesktop WRITE setShowingDesktop NOTIFY showingDesktopChanged)
0073     /**
0074      * @brief Whether desktop compositing is active
0075      *
0076      * @note This property is updated delayed
0077      */
0078     Q_PROPERTY(bool compositingActive READ compositingActive NOTIFY compositingActiveChanged)
0079 
0080     /**
0081      * @brief Whether the Platform is X11.
0082      *
0083      * @see isPlatformWayland
0084      * @since 5.96
0085      */
0086     Q_PROPERTY(bool isPlatformX11 READ isPlatformX11 CONSTANT)
0087 
0088     /**
0089      * @brief Whether the Platform is Wayland.
0090      *
0091      * @see isPlatformX11
0092      * @since 5.96
0093      */
0094     Q_PROPERTY(bool isPlatformWayland READ isPlatformWayland CONSTANT)
0095 
0096 public:
0097     explicit KWindowSystemProxy(QObject *parent = nullptr);
0098     ~KWindowSystemProxy() override;
0099 
0100 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0101     int currentDesktop() const;
0102     void setCurrentDesktop(int desktop);
0103 #endif
0104 
0105 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0106     QString currentDesktopName() const;
0107     int numberOfDesktops() const;
0108 #endif
0109 
0110     bool showingDesktop() const;
0111     void setShowingDesktop(bool showingDesktop);
0112 
0113     bool compositingActive() const;
0114 
0115     bool isPlatformX11() const;
0116     bool isPlatformWayland() const;
0117 
0118 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0119     /**
0120      * Test to see if @p window still managed at present.
0121      * @param window the window to test
0122      */
0123     Q_INVOKABLE bool hasWindow(QWindow *window) const;
0124 #endif
0125 
0126     /**
0127      * Sets window @p window to be the active window.
0128      *
0129      * @note This should be called only in special cases, applications
0130      * shouldn't force themselves or other windows to be the active
0131      * window. Generally, this call should used only by pagers
0132      * and similar tools.
0133      *
0134      * @param window the window to make active
0135      * @param time X server timestamp of the user activity that caused this request
0136      */
0137     Q_INVOKABLE void forceActivateWindow(QWindow *window, long time = 0);
0138 
0139 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0140     /**
0141      * Sets window @p window to be present on all virtual desktops if @p
0142      * onAllDesktops true. Otherwise the window lives only on one single desktop.
0143      *
0144      * @param window the window
0145      * @param onAllDesktops true to show the window on all desktops, false otherwise
0146      */
0147     Q_INVOKABLE void setOnAllDesktops(QWindow *window, bool onAllDesktops);
0148 #endif
0149 
0150 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0151     /**
0152      * Moves window @p window to desktop @p desktop.
0153      *
0154      * @param window the window
0155      * @param desktop the number of the new desktop
0156      */
0157     Q_INVOKABLE void setOnDesktop(QWindow *window, int desktop);
0158 #endif
0159 
0160 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0161     /**
0162      * Moves window @p window to activities @p activities.
0163      *
0164      * @param window the window
0165      * @param activities the list of activity UUIDs
0166      */
0167     Q_INVOKABLE void setOnActivities(QWindow *window, const QStringList &activities);
0168 #endif
0169 
0170 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0171     /**
0172      * Returns the name of the specified desktop.
0173      * @see currentDesktopName
0174      * @param desktop the number of the desktop
0175      * @return the name of the desktop
0176      **/
0177     Q_INVOKABLE QString desktopName(int desktop) const;
0178 #endif
0179 
0180 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0181     /**
0182      * Sets the name of the specified desktop.
0183      * @param desktop the number of the desktop
0184      * @param name the new name for the desktop
0185      **/
0186     Q_INVOKABLE void setDesktopName(int desktop, const QString &name);
0187 #endif
0188 
0189 Q_SIGNALS:
0190 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0191     void currentDesktopChanged(int desktop);
0192 #endif
0193 
0194 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0195     void currentDesktopNameChanged();
0196 #endif
0197 
0198 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0199     void desktopNamesChanged();
0200 #endif
0201 
0202 #if KDECLARATIVE_BUILD_DEPRECATED_SINCE(5, 101)
0203     void numberOfDesktopsChanged(int numberOfDesktops);
0204 #endif
0205 
0206     void showingDesktopChanged(bool showingDesktop);
0207     void compositingActiveChanged(bool compositingActive);
0208 
0209 protected:
0210     void connectNotify(const QMetaMethod &signal) override;
0211 
0212 private:
0213     bool m_initialized;
0214 };
0215 
0216 #endif // KWINDOWSYSTEMPROXY_H