File indexing completed on 2024-05-19 05:31:42

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include "config-kwin.h"
0013 
0014 #include <QCoreApplication>
0015 #include <QImage>
0016 #include <QPoint>
0017 #include <QVariant>
0018 #include <QVector2D>
0019 
0020 #include <kwin_export.h>
0021 
0022 #define KWIN_QT5_PORTING 0
0023 
0024 namespace KWin
0025 {
0026 KWIN_EXPORT Q_NAMESPACE
0027 
0028     enum CompositingType {
0029         NoCompositing = 0,
0030         /**
0031          * Used as a flag whether OpenGL based compositing is used.
0032          * The flag is or-ed to the enum values of the specific OpenGL types.
0033          * The actual Compositors use the or @c OpenGLCompositing
0034          * flags. If you need to know whether OpenGL is used, either and the flag or
0035          * use EffectsHandler::isOpenGLCompositing().
0036          */
0037         OpenGLCompositing = 1,
0038         /* XRenderCompositing = 1<<1, */
0039         QPainterCompositing = 1 << 2,
0040     };
0041 
0042 enum OpenGLPlatformInterface {
0043     NoOpenGLPlatformInterface = 0,
0044     GlxPlatformInterface,
0045     EglPlatformInterface,
0046 };
0047 
0048 enum clientAreaOption {
0049     PlacementArea, // geometry where a window will be initially placed after being mapped
0050     MovementArea, // ???  window movement snapping area?  ignore struts
0051     MaximizeArea, // geometry to which a window will be maximized
0052     MaximizeFullArea, // like MaximizeArea, but ignore struts - used e.g. for topmenu
0053     FullScreenArea, // area for fullscreen windows
0054     // these below don't depend on xinerama settings
0055     WorkArea, // whole workarea (all screens together)
0056     FullArea, // whole area (all screens together), ignore struts
0057     ScreenArea, // one whole screen, ignore struts
0058 };
0059 
0060 enum ElectricBorder {
0061     ElectricTop,
0062     ElectricTopRight,
0063     ElectricRight,
0064     ElectricBottomRight,
0065     ElectricBottom,
0066     ElectricBottomLeft,
0067     ElectricLeft,
0068     ElectricTopLeft,
0069     ELECTRIC_COUNT,
0070     ElectricNone,
0071 };
0072 Q_ENUM_NS(ElectricBorder)
0073 
0074 // TODO: Hardcoding is bad, need to add some way of registering global actions to these.
0075 // When designing the new system we must keep in mind that we have conditional actions
0076 // such as "only when moving windows" desktop switching that the current global action
0077 // system doesn't support.
0078 enum ElectricBorderAction {
0079     ElectricActionNone, // No special action, not set, desktop switch or an effect
0080     ElectricActionShowDesktop, // Show desktop or restore
0081     ElectricActionLockScreen, // Lock screen
0082     ElectricActionKRunner, // Open KRunner
0083     ElectricActionActivityManager, // Activity Manager
0084     ElectricActionApplicationLauncher, // Application Launcher
0085     ELECTRIC_ACTION_COUNT,
0086 };
0087 
0088 enum TabBoxMode {
0089     TabBoxWindowsMode, // Primary window switching mode
0090     TabBoxWindowsAlternativeMode, // Secondary window switching mode
0091     TabBoxCurrentAppWindowsMode, // Same as primary window switching mode but only for windows of current application
0092     TabBoxCurrentAppWindowsAlternativeMode, // Same as secondary switching mode but only for windows of current application
0093 };
0094 
0095 enum KWinOption {
0096     CloseButtonCorner,
0097     SwitchDesktopOnScreenEdge,
0098     SwitchDesktopOnScreenEdgeMovingWindows,
0099 };
0100 
0101 /**
0102  * @brief The direction in which a pointer axis is moved.
0103  */
0104 enum PointerAxisDirection {
0105     PointerAxisUp,
0106     PointerAxisDown,
0107     PointerAxisLeft,
0108     PointerAxisRight,
0109 };
0110 
0111 /**
0112  * @brief Directions for swipe gestures
0113  * @since 5.10
0114  */
0115 enum class SwipeDirection {
0116     Invalid,
0117     Down,
0118     Left,
0119     Up,
0120     Right,
0121 };
0122 
0123 enum class PinchDirection {
0124     Expanding,
0125     Contracting
0126 };
0127 
0128 /**
0129  * Represents the state of the session running outside kwin
0130  * Under Plasma this is managed by ksmserver
0131  */
0132 enum class SessionState {
0133     Normal,
0134     Saving,
0135     Quitting,
0136 };
0137 Q_ENUM_NS(SessionState)
0138 
0139 enum class LED {
0140     NumLock = 1 << 0,
0141     CapsLock = 1 << 1,
0142     ScrollLock = 1 << 2
0143 };
0144 Q_DECLARE_FLAGS(LEDs, LED)
0145 Q_FLAG_NS(LEDs)
0146 
0147 /**
0148  * The Gravity enum is used to specify the direction in which geometry changes during resize.
0149  */
0150 enum class Gravity {
0151     None,
0152     Left,
0153     Right,
0154     Top,
0155     Bottom,
0156     TopLeft,
0157     TopRight,
0158     BottomLeft,
0159     BottomRight,
0160 };
0161 
0162 enum Layer {
0163     UnknownLayer = -1,
0164     FirstLayer = 0,
0165     DesktopLayer = FirstLayer,
0166     BelowLayer,
0167     NormalLayer,
0168     AboveLayer,
0169     NotificationLayer, // layer for windows of type notification
0170     ActiveLayer, // active fullscreen, or active dialog
0171     PopupLayer, // tooltips, sub- and context menus
0172     CriticalNotificationLayer, // layer for notifications that should be shown even on top of fullscreen
0173     OnScreenDisplayLayer, // layer for On Screen Display windows such as volume feedback
0174     OverlayLayer,
0175     NumLayers, // number of layers, must be last
0176 };
0177 Q_ENUM_NS(Layer)
0178 
0179 // TODO: could this be in Tile itself?
0180 enum class QuickTileFlag {
0181     None = 0,
0182     Left = 1 << 0,
0183     Right = 1 << 1,
0184     Top = 1 << 2,
0185     Bottom = 1 << 3,
0186     Custom = 1 << 4,
0187     Horizontal = Left | Right,
0188     Vertical = Top | Bottom,
0189     Maximize = Left | Right | Top | Bottom,
0190 };
0191 Q_ENUM_NS(QuickTileFlag)
0192 Q_DECLARE_FLAGS(QuickTileMode, QuickTileFlag)
0193 
0194 /**
0195  * Short wrapper for a cursor image provided by the Platform.
0196  * @since 5.9
0197  */
0198 class PlatformCursorImage
0199 {
0200 public:
0201     explicit PlatformCursorImage()
0202         : m_image()
0203         , m_hotSpot()
0204     {
0205     }
0206     explicit PlatformCursorImage(const QImage &image, const QPointF &hotSpot)
0207         : m_image(image)
0208         , m_hotSpot(hotSpot)
0209     {
0210     }
0211     virtual ~PlatformCursorImage() = default;
0212 
0213     bool isNull() const
0214     {
0215         return m_image.isNull();
0216     }
0217     QImage image() const
0218     {
0219         return m_image;
0220     }
0221     QPointF hotSpot() const
0222     {
0223         return m_hotSpot;
0224     }
0225 
0226 private:
0227     QImage m_image;
0228     QPointF m_hotSpot;
0229 };
0230 
0231 /**
0232  * Infinite region (i.e. a special region type saying that everything needs to be painted).
0233  */
0234 inline KWIN_EXPORT QRect infiniteRegion()
0235 {
0236     // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
0237     return QRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX);
0238 }
0239 
0240 /**
0241  * Scale a rect by a scalar.
0242  */
0243 KWIN_EXPORT inline QRectF scaledRect(const QRectF &rect, qreal scale)
0244 {
0245     return QRectF{rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale};
0246 }
0247 
0248 /**
0249  * Round a vector to nearest integer.
0250  */
0251 KWIN_EXPORT inline QVector2D roundVector(const QVector2D &input)
0252 {
0253     return QVector2D(std::round(input.x()), std::round(input.y()));
0254 }
0255 
0256 /**
0257  * Convert a QPointF to a QPoint by flooring instead of rounding.
0258  *
0259  * By default, QPointF::toPoint() rounds which can cause problems in certain
0260  * cases.
0261  */
0262 KWIN_EXPORT inline QPoint flooredPoint(const QPointF &point)
0263 {
0264     return QPoint(std::floor(point.x()), std::floor(point.y()));
0265 }
0266 
0267 /**
0268  * @returns if @a point is contained in @a rect, including the left and top borders
0269  * but excluding the right and bottom borders
0270  */
0271 static inline bool exclusiveContains(const QRectF &rect, const QPointF &point)
0272 {
0273     return point.x() >= rect.x() && point.y() >= rect.y() && point.x() < (rect.x() + rect.width()) && point.y() < (rect.y() + rect.height());
0274 }
0275 
0276 enum class PresentationMode {
0277     VSync,
0278     AdaptiveSync,
0279     Async,
0280     AdaptiveAsync,
0281 };
0282 Q_ENUM_NS(PresentationMode);
0283 
0284 enum class ContentType {
0285     None = 0,
0286     Photo = 1,
0287     Video = 2,
0288     Game = 3,
0289 };
0290 Q_ENUM_NS(ContentType);
0291 
0292 enum class VrrPolicy {
0293     Never = 0,
0294     Always = 1,
0295     Automatic = 2,
0296 };
0297 Q_ENUM_NS(VrrPolicy);
0298 
0299 enum class PresentationModeHint {
0300     VSync,
0301     Async
0302 };
0303 Q_ENUM_NS(PresentationModeHint);
0304 
0305 } // namespace
0306 
0307 Q_DECLARE_METATYPE(std::chrono::nanoseconds)
0308 
0309 #define KWIN_SINGLETON_VARIABLE(ClassName, variableName) \
0310 public:                                                  \
0311     static ClassName *create(QObject *parent = nullptr); \
0312     static ClassName *self()                             \
0313     {                                                    \
0314         return variableName;                             \
0315     }                                                    \
0316                                                          \
0317 protected:                                               \
0318     explicit ClassName(QObject *parent = nullptr);       \
0319                                                          \
0320 private:                                                 \
0321     static ClassName *variableName;
0322 
0323 #define KWIN_SINGLETON(ClassName) KWIN_SINGLETON_VARIABLE(ClassName, s_self)
0324 
0325 #define KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, variableName) \
0326     ClassName *ClassName::variableName = nullptr;                                            \
0327     ClassName *ClassName::create(QObject *parent)                                            \
0328     {                                                                                        \
0329         Q_ASSERT(!variableName);                                                             \
0330         variableName = new FactoredClassName(parent);                                        \
0331         return variableName;                                                                 \
0332     }
0333 #define KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, variableName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, ClassName, variableName)
0334 #define KWIN_SINGLETON_FACTORY_FACTORED(ClassName, FactoredClassName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, s_self)
0335 #define KWIN_SINGLETON_FACTORY(ClassName) KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, s_self)