Warning, file /plasma/kwin/src/dbusinterface.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <QObject>
0013 #include <QtDBus>
0014 
0015 #include "virtualdesktopsdbustypes.h"
0016 
0017 namespace KWin
0018 {
0019 
0020 class Compositor;
0021 class PluginManager;
0022 class VirtualDesktopManager;
0023 
0024 /**
0025  * @brief This class is a wrapper for the org.kde.KWin D-Bus interface.
0026  *
0027  * The main purpose of this class is to be exported on the D-Bus as object /KWin.
0028  * It is a pure wrapper to provide the deprecated D-Bus methods which have been
0029  * removed from Workspace which used to implement the complete D-Bus interface.
0030  *
0031  * Nowadays the D-Bus interfaces are distributed, parts of it are exported on
0032  * /Compositor, parts on /Effects and parts on /KWin. The implementation in this
0033  * class just delegates the method calls to the actual implementation in one of the
0034  * three singletons.
0035  *
0036  * @author Martin Gräßlin <mgraesslin@kde.org>
0037  */
0038 class DBusInterface : public QObject, protected QDBusContext
0039 {
0040     Q_OBJECT
0041     Q_CLASSINFO("D-Bus Interface", "org.kde.KWin")
0042 public:
0043     explicit DBusInterface(QObject *parent);
0044     ~DBusInterface() override;
0045 
0046 public: // PROPERTIES
0047     Q_PROPERTY(bool showingDesktop READ showingDesktop NOTIFY showingDesktopChanged)
0048     bool showingDesktop() const;
0049 
0050 public Q_SLOTS: // METHODS
0051     Q_NOREPLY void cascadeDesktop();
0052     int currentDesktop();
0053     Q_NOREPLY void killWindow();
0054     void nextDesktop();
0055     void previousDesktop();
0056     Q_NOREPLY void reconfigure();
0057     bool setCurrentDesktop(int desktop);
0058     bool startActivity(const QString &in0);
0059     bool stopActivity(const QString &in0);
0060     QString supportInformation();
0061     QString activeOutputName();
0062     Q_NOREPLY void unclutterDesktop();
0063     Q_NOREPLY void showDebugConsole();
0064 
0065     /**
0066      * Instructs kwin_wayland to restart itself.
0067      *
0068      * This acts as an implementation detail of: kwin_wayland --replace
0069      */
0070     Q_NOREPLY void replace();
0071 
0072     /**
0073      * Allows the user to pick a window and get info on it.
0074      *
0075      * When called the user's mouse cursor will become a targeting reticule.
0076      * On clicking a window with the target a map will be returned
0077      * with various information about the picked window, such as:
0078      * height, width, minimized, fullscreen, etc.
0079      */
0080     QVariantMap queryWindowInfo();
0081 
0082     /**
0083      * Returns a map with information about the window.
0084      *
0085      * The map includes entries such as position, size, status, and more.
0086      *
0087      * @param uuid is a QUuid from Window::internalId().
0088      */
0089     QVariantMap getWindowInfo(const QString &uuid);
0090 
0091     Q_NOREPLY void showDesktop(bool show);
0092 
0093 Q_SIGNALS:
0094     void showingDesktopChanged(bool showing);
0095 
0096 private Q_SLOTS:
0097     void onShowingDesktopChanged(bool show, bool /*animated*/);
0098 
0099 private:
0100     QString m_serviceName;
0101     QDBusMessage m_replyQueryWindowInfo;
0102 };
0103 
0104 class CompositorDBusInterface : public QObject
0105 {
0106     Q_OBJECT
0107     Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Compositing")
0108 
0109     /**
0110      * @brief Whether the Compositor is active. That is a Scene is present and the Compositor is
0111      * not shutting down itself.
0112      */
0113     Q_PROPERTY(bool active READ isActive)
0114 
0115     /**
0116      * @brief Whether compositing is possible. Mostly means whether the required X extensions
0117      * are available.
0118      */
0119     Q_PROPERTY(bool compositingPossible READ isCompositingPossible)
0120 
0121     /**
0122      * @brief The reason why compositing is not possible. Empty String if compositing is possible.
0123      */
0124     Q_PROPERTY(QString compositingNotPossibleReason READ compositingNotPossibleReason)
0125 
0126     /**
0127      * @brief Whether OpenGL has failed badly in the past (crash) and is considered as broken.
0128      */
0129     Q_PROPERTY(bool openGLIsBroken READ isOpenGLBroken)
0130 
0131     /**
0132      * The type of the currently used Scene:
0133      * @li @c none No Compositing
0134      * @li @c gl1 OpenGL 1
0135      * @li @c gl2 OpenGL 2
0136      * @li @c gles OpenGL ES 2
0137      */
0138     Q_PROPERTY(QString compositingType READ compositingType)
0139 
0140     /**
0141      * @brief All currently supported OpenGLPlatformInterfaces.
0142      *
0143      * Possible values:
0144      * @li glx
0145      * @li egl
0146      *
0147      * Values depend on operation mode and compile time options.
0148      */
0149     Q_PROPERTY(QStringList supportedOpenGLPlatformInterfaces READ supportedOpenGLPlatformInterfaces)
0150 
0151     Q_PROPERTY(bool platformRequiresCompositing READ platformRequiresCompositing)
0152 public:
0153     explicit CompositorDBusInterface(Compositor *parent);
0154     ~CompositorDBusInterface() override = default;
0155 
0156     bool isActive() const;
0157     bool isCompositingPossible() const;
0158     QString compositingNotPossibleReason() const;
0159     bool isOpenGLBroken() const;
0160     QString compositingType() const;
0161     QStringList supportedOpenGLPlatformInterfaces() const;
0162     bool platformRequiresCompositing() const;
0163 
0164 public Q_SLOTS:
0165     /**
0166      * @brief Suspends the Compositor if it is currently active.
0167      *
0168      * Note: it is possible that the Compositor is not able to suspend. Use isActive to check
0169      * whether the Compositor has been suspended.
0170      *
0171      * @return void
0172      * @see resume
0173      * @see isActive
0174      */
0175     void suspend();
0176 
0177     /**
0178      * @brief Resumes the Compositor if it is currently suspended.
0179      *
0180      * Note: it is possible that the Compositor cannot be resumed, that is there might be Clients
0181      * blocking the usage of Compositing or the Scene might be broken. Use isActive to check
0182      * whether the Compositor has been resumed. Also check isCompositingPossible and
0183      * isOpenGLBroken.
0184      *
0185      * Note: The starting of the Compositor can require some time and is partially done threaded.
0186      * After this method returns the setup may not have been completed.
0187      *
0188      * @return void
0189      * @see suspend
0190      * @see isActive
0191      * @see isCompositingPossible
0192      * @see isOpenGLBroken
0193      */
0194     void resume();
0195 
0196     /**
0197      * @brief Used by Compositing KCM after settings change.
0198      *
0199      * On signal Compositor reloads settings and restarts.
0200      */
0201     void reinitialize();
0202 
0203 Q_SIGNALS:
0204     void compositingToggled(bool active);
0205 
0206 private:
0207     Compositor *m_compositor;
0208 };
0209 
0210 // TODO: disable all of this in case of kiosk?
0211 
0212 class VirtualDesktopManagerDBusInterface : public QObject
0213 {
0214     Q_OBJECT
0215     Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.VirtualDesktopManager")
0216 
0217     /**
0218      * The number of virtual desktops currently available.
0219      * The ids of the virtual desktops are in the range [1, VirtualDesktopManager::maximum()].
0220      */
0221     Q_PROPERTY(uint count READ count NOTIFY countChanged)
0222 
0223     /**
0224      * The number of rows the virtual desktops will be laid out in
0225      */
0226     Q_PROPERTY(uint rows READ rows WRITE setRows NOTIFY rowsChanged)
0227 
0228     /**
0229      * The id of the virtual desktop which is currently in use.
0230      */
0231     Q_PROPERTY(QString current READ current WRITE setCurrent NOTIFY currentChanged)
0232 
0233     /**
0234      * Whether navigation in the desktop layout wraps around at the borders.
0235      */
0236     Q_PROPERTY(bool navigationWrappingAround READ isNavigationWrappingAround WRITE setNavigationWrappingAround NOTIFY navigationWrappingAroundChanged)
0237 
0238     /**
0239      * list of key/value pairs which every one of them is representing a desktop
0240      */
0241     Q_PROPERTY(KWin::DBusDesktopDataVector desktops READ desktops NOTIFY desktopsChanged);
0242 
0243 public:
0244     VirtualDesktopManagerDBusInterface(VirtualDesktopManager *parent);
0245     ~VirtualDesktopManagerDBusInterface() override = default;
0246 
0247     uint count() const;
0248 
0249     void setRows(uint rows);
0250     uint rows() const;
0251 
0252     void setCurrent(const QString &id);
0253     QString current() const;
0254 
0255     void setNavigationWrappingAround(bool wraps);
0256     bool isNavigationWrappingAround() const;
0257 
0258     KWin::DBusDesktopDataVector desktops() const;
0259 
0260 Q_SIGNALS:
0261     void countChanged(uint count);
0262     void rowsChanged(uint rows);
0263     void currentChanged(const QString &id);
0264     void navigationWrappingAroundChanged(bool wraps);
0265     void desktopsChanged(KWin::DBusDesktopDataVector);
0266     void desktopDataChanged(const QString &id, KWin::DBusDesktopDataStruct);
0267     void desktopCreated(const QString &id, KWin::DBusDesktopDataStruct);
0268     void desktopRemoved(const QString &id);
0269 
0270 public Q_SLOTS:
0271     /**
0272      * Create a desktop with a new name at a given position
0273      * note: the position starts from 1
0274      */
0275     void createDesktop(uint position, const QString &name);
0276     void setDesktopName(const QString &id, const QString &name);
0277     void removeDesktop(const QString &id);
0278 
0279 private:
0280     VirtualDesktopManager *m_manager;
0281 };
0282 
0283 class PluginManagerDBusInterface : public QObject
0284 {
0285     Q_OBJECT
0286     Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.Plugins")
0287 
0288     Q_PROPERTY(QStringList LoadedPlugins READ loadedPlugins)
0289     Q_PROPERTY(QStringList AvailablePlugins READ availablePlugins)
0290 
0291 public:
0292     explicit PluginManagerDBusInterface(PluginManager *manager);
0293 
0294     QStringList loadedPlugins() const;
0295     QStringList availablePlugins() const;
0296 
0297 public Q_SLOTS:
0298     bool LoadPlugin(const QString &name);
0299     void UnloadPlugin(const QString &name);
0300 
0301 private:
0302     PluginManager *m_manager;
0303 };
0304 
0305 } // namespace