File indexing completed on 2024-05-19 05:32:25
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2010 Rohan Prabhu <rohan@rohanprabhu.com> 0006 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "effect/globals.h" 0014 #include <QObject> 0015 #include <QQmlListProperty> 0016 #include <QRect> 0017 #include <QSize> 0018 #include <QStringList> 0019 0020 namespace KWin 0021 { 0022 // forward declarations 0023 class TileManager; 0024 class Window; 0025 class Output; 0026 class VirtualDesktop; 0027 0028 class WorkspaceWrapper : public QObject 0029 { 0030 Q_OBJECT 0031 Q_PROPERTY(QList<KWin::VirtualDesktop *> desktops READ desktops NOTIFY desktopsChanged) 0032 Q_PROPERTY(KWin::VirtualDesktop *currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged) 0033 Q_PROPERTY(KWin::Window *activeWindow READ activeWindow WRITE setActiveWindow NOTIFY windowActivated) 0034 // TODO: write and notify? 0035 Q_PROPERTY(QSize desktopGridSize READ desktopGridSize NOTIFY desktopLayoutChanged) 0036 Q_PROPERTY(int desktopGridWidth READ desktopGridWidth NOTIFY desktopLayoutChanged) 0037 Q_PROPERTY(int desktopGridHeight READ desktopGridHeight NOTIFY desktopLayoutChanged) 0038 Q_PROPERTY(int workspaceWidth READ workspaceWidth) 0039 Q_PROPERTY(int workspaceHeight READ workspaceHeight) 0040 Q_PROPERTY(QSize workspaceSize READ workspaceSize) 0041 Q_PROPERTY(KWin::Output *activeScreen READ activeScreen) 0042 Q_PROPERTY(QList<KWin::Output *> screens READ screens NOTIFY screensChanged) 0043 Q_PROPERTY(QString currentActivity READ currentActivity WRITE setCurrentActivity NOTIFY currentActivityChanged) 0044 Q_PROPERTY(QStringList activities READ activityList NOTIFY activitiesChanged) 0045 /** 0046 * The bounding size of all screens combined. Overlapping areas 0047 * are not counted multiple times. 0048 * @see virtualScreenGeometry 0049 */ 0050 Q_PROPERTY(QSize virtualScreenSize READ virtualScreenSize NOTIFY virtualScreenSizeChanged) 0051 /** 0052 * The bounding geometry of all screens combined. Always starts at (0,0) and has 0053 * virtualScreenSize as it's size. 0054 * @see virtualScreenSize 0055 */ 0056 Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged) 0057 /** 0058 * List of Clients currently managed by KWin, orderd by 0059 * their visibility (later ones cover earlier ones). 0060 */ 0061 Q_PROPERTY(QList<KWin::Window *> stackingOrder READ stackingOrder) 0062 /** 0063 * The current position of the cursor. 0064 */ 0065 Q_PROPERTY(QPoint cursorPos READ cursorPos NOTIFY cursorPosChanged) 0066 0067 private: 0068 Q_DISABLE_COPY(WorkspaceWrapper) 0069 0070 Q_SIGNALS: 0071 void windowAdded(KWin::Window *window); 0072 void windowRemoved(KWin::Window *window); 0073 void windowActivated(KWin::Window *window); 0074 /** 0075 * This signal is emitted when a virtual desktop is added or removed. 0076 */ 0077 void desktopsChanged(); 0078 /** 0079 * Signal emitted whenever the layout of virtual desktops changed. 0080 * That is desktopGrid(Size/Width/Height) will have new values. 0081 * @since 4.11 0082 */ 0083 void desktopLayoutChanged(); 0084 /** 0085 * Emitted when the output list changes, e.g. an output is connected or removed. 0086 */ 0087 void screensChanged(); 0088 /** 0089 * Signal emitted whenever the current activity changed. 0090 * @param id id of the new activity 0091 */ 0092 void currentActivityChanged(const QString &id); 0093 /** 0094 * Signal emitted whenever the list of activities changed. 0095 * @param id id of the new activity 0096 */ 0097 void activitiesChanged(const QString &id); 0098 /** 0099 * This signal is emitted when a new activity is added 0100 * @param id id of the new activity 0101 */ 0102 void activityAdded(const QString &id); 0103 /** 0104 * This signal is emitted when the activity 0105 * is removed 0106 * @param id id of the removed activity 0107 */ 0108 void activityRemoved(const QString &id); 0109 /** 0110 * Emitted whenever the virtualScreenSize changes. 0111 * @see virtualScreenSize() 0112 * @since 5.0 0113 */ 0114 void virtualScreenSizeChanged(); 0115 /** 0116 * Emitted whenever the virtualScreenGeometry changes. 0117 * @see virtualScreenGeometry() 0118 * @since 5.0 0119 */ 0120 void virtualScreenGeometryChanged(); 0121 /** 0122 * This signal is emitted when the current virtual desktop changes. 0123 */ 0124 void currentDesktopChanged(KWin::VirtualDesktop *previous); 0125 /** 0126 * This signal is emitted when the cursor position changes. 0127 * @see cursorPos() 0128 */ 0129 void cursorPosChanged(); 0130 0131 public: 0132 //------------------------------------------------------------------ 0133 // enums copy&pasted from kwinglobals.h because qtscript is evil 0134 0135 enum ClientAreaOption { 0136 ///< geometry where a window will be initially placed after being mapped 0137 PlacementArea, 0138 ///< window movement snapping area? ignore struts 0139 MovementArea, 0140 ///< geometry to which a window will be maximized 0141 MaximizeArea, 0142 ///< like MaximizeArea, but ignore struts - used e.g. for topmenu 0143 MaximizeFullArea, 0144 ///< area for fullscreen windows 0145 FullScreenArea, 0146 ///< whole workarea (all screens together) 0147 WorkArea, 0148 ///< whole area (all screens together), ignore struts 0149 FullArea, 0150 ///< one whole screen, ignore struts 0151 ScreenArea 0152 }; 0153 Q_ENUM(ClientAreaOption) 0154 enum ElectricBorder { 0155 ElectricTop, 0156 ElectricTopRight, 0157 ElectricRight, 0158 ElectricBottomRight, 0159 ElectricBottom, 0160 ElectricBottomLeft, 0161 ElectricLeft, 0162 ElectricTopLeft, 0163 ELECTRIC_COUNT, 0164 ElectricNone 0165 }; 0166 Q_ENUM(ElectricBorder) 0167 0168 protected: 0169 explicit WorkspaceWrapper(QObject *parent = nullptr); 0170 0171 public: 0172 Window *activeWindow() const; 0173 void setActiveWindow(Window *window); 0174 0175 QString currentActivity() const; 0176 void setCurrentActivity(const QString &activity); 0177 0178 QSize desktopGridSize() const; 0179 int desktopGridWidth() const; 0180 int desktopGridHeight() const; 0181 int workspaceWidth() const; 0182 int workspaceHeight() const; 0183 QSize workspaceSize() const; 0184 KWin::Output *activeScreen() const; 0185 QList<KWin::Output *> screens() const; 0186 QStringList activityList() const; 0187 QSize virtualScreenSize() const; 0188 QRect virtualScreenGeometry() const; 0189 QPoint cursorPos() const; 0190 0191 QList<VirtualDesktop *> desktops() const; 0192 VirtualDesktop *currentDesktop() const; 0193 void setCurrentDesktop(VirtualDesktop *desktop); 0194 0195 Q_INVOKABLE KWin::Output *screenAt(const QPointF &pos) const; 0196 0197 Q_INVOKABLE KWin::TileManager *tilingForScreen(const QString &screenName) const; 0198 Q_INVOKABLE KWin::TileManager *tilingForScreen(KWin::Output *output) const; 0199 0200 /** 0201 * Returns the geometry a Client can use with the specified option. 0202 * This method should be preferred over other methods providing screen sizes as the 0203 * various options take constraints such as struts set on panels into account. 0204 * This method is also multi screen aware, but there are also options to get full areas. 0205 * @param option The type of area which should be considered 0206 * @param screen The screen for which the area should be considered 0207 * @param desktop The desktop for which the area should be considered, in general there should not be a difference 0208 * @returns The specified screen geometry 0209 */ 0210 Q_SCRIPTABLE QRectF clientArea(ClientAreaOption option, KWin::Output *output, KWin::VirtualDesktop *desktop) const; 0211 /** 0212 * Overloaded method for convenience. 0213 * @param client The Client for which the area should be retrieved 0214 * @returns The specified screen geometry 0215 */ 0216 Q_SCRIPTABLE QRectF clientArea(ClientAreaOption option, KWin::Window *client) const; 0217 Q_SCRIPTABLE QRectF clientArea(ClientAreaOption option, const KWin::Window *client) const; 0218 /** 0219 * Create a new virtual desktop at the requested position. 0220 * @param position The position of the desktop. It should be in range [0, count]. 0221 * @param name The name for the new desktop, if empty the default name will be used. 0222 */ 0223 Q_SCRIPTABLE void createDesktop(int position, const QString &name) const; 0224 /** 0225 * Removes the specified virtual desktop. 0226 */ 0227 Q_SCRIPTABLE void removeDesktop(KWin::VirtualDesktop *desktop) const; 0228 /** 0229 * Provides support information about the currently running KWin instance. 0230 */ 0231 Q_SCRIPTABLE QString supportInformation() const; 0232 0233 /** 0234 * List of Clients currently managed by KWin, orderd by 0235 * their visibility (later ones cover earlier ones). 0236 */ 0237 QList<KWin::Window *> stackingOrder() const; 0238 /** 0239 * Raises a Window above all others on the screen. 0240 * @param window The Window to raise 0241 */ 0242 Q_INVOKABLE void raiseWindow(KWin::Window *window); 0243 /** 0244 * Finds the Client with the given @p windowId. 0245 * @param windowId The window Id of the Client 0246 * @return The found Client or @c null 0247 */ 0248 Q_SCRIPTABLE KWin::Window *getClient(qulonglong windowId); 0249 /** 0250 * Finds up to count windows at a particular location, 0251 * prioritizing the topmost one first. A negative count 0252 * returns all matching clients. 0253 * @param pos The location to look for 0254 * @param count The number of clients to return 0255 * @return A list of Client objects 0256 */ 0257 Q_INVOKABLE QList<KWin::Window *> windowAt(const QPointF &pos, int count = 1) const; 0258 0259 /** 0260 * Checks if a specific effect is currently active. 0261 * @param pluginId The plugin Id of the effect to check. 0262 * @return @c true if the effect is loaded and currently active, @c false otherwise. 0263 * @since 6.0 0264 */ 0265 Q_INVOKABLE bool isEffectActive(const QString &pluginId) const; 0266 0267 public Q_SLOTS: 0268 // all the available key bindings 0269 void slotSwitchDesktopNext(); 0270 void slotSwitchDesktopPrevious(); 0271 void slotSwitchDesktopRight(); 0272 void slotSwitchDesktopLeft(); 0273 void slotSwitchDesktopUp(); 0274 void slotSwitchDesktopDown(); 0275 0276 void slotSwitchToNextScreen(); 0277 void slotSwitchToPrevScreen(); 0278 void slotSwitchToRightScreen(); 0279 void slotSwitchToLeftScreen(); 0280 void slotSwitchToAboveScreen(); 0281 void slotSwitchToBelowScreen(); 0282 void slotWindowToNextScreen(); 0283 void slotWindowToPrevScreen(); 0284 void slotWindowToRightScreen(); 0285 void slotWindowToLeftScreen(); 0286 void slotWindowToAboveScreen(); 0287 void slotWindowToBelowScreen(); 0288 0289 void slotToggleShowDesktop(); 0290 0291 void slotWindowMaximize(); 0292 void slotWindowMaximizeVertical(); 0293 void slotWindowMaximizeHorizontal(); 0294 void slotWindowMinimize(); 0295 void slotWindowShade(); 0296 void slotWindowRaise(); 0297 void slotWindowLower(); 0298 void slotWindowRaiseOrLower(); 0299 void slotActivateAttentionWindow(); 0300 0301 void slotWindowMoveLeft(); 0302 void slotWindowMoveRight(); 0303 void slotWindowMoveUp(); 0304 void slotWindowMoveDown(); 0305 void slotWindowExpandHorizontal(); 0306 void slotWindowExpandVertical(); 0307 void slotWindowShrinkHorizontal(); 0308 void slotWindowShrinkVertical(); 0309 void slotWindowQuickTileLeft(); 0310 void slotWindowQuickTileRight(); 0311 void slotWindowQuickTileTop(); 0312 void slotWindowQuickTileBottom(); 0313 void slotWindowQuickTileTopLeft(); 0314 void slotWindowQuickTileTopRight(); 0315 void slotWindowQuickTileBottomLeft(); 0316 void slotWindowQuickTileBottomRight(); 0317 0318 void slotSwitchWindowUp(); 0319 void slotSwitchWindowDown(); 0320 void slotSwitchWindowRight(); 0321 void slotSwitchWindowLeft(); 0322 0323 void slotIncreaseWindowOpacity(); 0324 void slotLowerWindowOpacity(); 0325 0326 void slotWindowOperations(); 0327 void slotWindowClose(); 0328 void slotWindowMove(); 0329 void slotWindowResize(); 0330 void slotWindowAbove(); 0331 void slotWindowBelow(); 0332 void slotWindowOnAllDesktops(); 0333 void slotWindowFullScreen(); 0334 void slotWindowNoBorder(); 0335 0336 void slotWindowToNextDesktop(); 0337 void slotWindowToPreviousDesktop(); 0338 void slotWindowToDesktopRight(); 0339 void slotWindowToDesktopLeft(); 0340 void slotWindowToDesktopUp(); 0341 void slotWindowToDesktopDown(); 0342 0343 /** 0344 * Sends the Window to the given @p output. 0345 */ 0346 void sendClientToScreen(KWin::Window *client, KWin::Output *output); 0347 0348 /** 0349 * Shows an outline at the specified @p geometry. 0350 * If an outline is already shown the outline is moved to the new position. 0351 * Use hideOutline to remove the outline again. 0352 */ 0353 void showOutline(const QRect &geometry); 0354 /** 0355 * Overloaded method for convenience. 0356 */ 0357 void showOutline(int x, int y, int width, int height); 0358 /** 0359 * Hides the outline previously shown by showOutline. 0360 */ 0361 void hideOutline(); 0362 }; 0363 0364 class QtScriptWorkspaceWrapper : public WorkspaceWrapper 0365 { 0366 Q_OBJECT 0367 public: 0368 /** 0369 * List of windows currently managed by KWin. 0370 */ 0371 Q_INVOKABLE QList<KWin::Window *> windowList() const; 0372 0373 explicit QtScriptWorkspaceWrapper(QObject *parent = nullptr); 0374 }; 0375 0376 class DeclarativeScriptWorkspaceWrapper : public WorkspaceWrapper 0377 { 0378 Q_OBJECT 0379 0380 Q_PROPERTY(QQmlListProperty<KWin::Window> windows READ windows) 0381 public: 0382 QQmlListProperty<KWin::Window> windows(); 0383 static qsizetype countWindowList(QQmlListProperty<KWin::Window> *window); 0384 static KWin::Window *atWindowList(QQmlListProperty<KWin::Window> *windows, qsizetype index); 0385 0386 explicit DeclarativeScriptWorkspaceWrapper(QObject *parent = nullptr); 0387 }; 0388 0389 }