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