File indexing completed on 2024-05-19 16:34:32

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 <QCoreApplication>
0013 #include <QImage>
0014 #include <QPoint>
0015 #include <QVariant>
0016 
0017 #include <kwin_export.h>
0018 
0019 #include <xcb/xcb.h>
0020 
0021 #include <kwinconfig.h>
0022 
0023 #define KWIN_QT5_PORTING 0
0024 
0025 namespace KWin
0026 {
0027 KWIN_EXPORT Q_NAMESPACE
0028 
0029     enum CompositingType {
0030         NoCompositing = 0,
0031         /**
0032          * Used as a flag whether OpenGL based compositing is used.
0033          * The flag is or-ed to the enum values of the specific OpenGL types.
0034          * The actual Compositors use the or @c OpenGLCompositing
0035          * flags. If you need to know whether OpenGL is used, either and the flag or
0036          * use EffectsHandler::isOpenGLCompositing().
0037          */
0038         OpenGLCompositing = 1,
0039         /* XRenderCompositing = 1<<1, */
0040         QPainterCompositing = 1 << 2,
0041     };
0042 
0043 enum OpenGLPlatformInterface {
0044     NoOpenGLPlatformInterface = 0,
0045     GlxPlatformInterface,
0046     EglPlatformInterface,
0047 };
0048 
0049 enum clientAreaOption {
0050     PlacementArea, // geometry where a window will be initially placed after being mapped
0051     MovementArea, // ???  window movement snapping area?  ignore struts
0052     MaximizeArea, // geometry to which a window will be maximized
0053     MaximizeFullArea, // like MaximizeArea, but ignore struts - used e.g. for topmenu
0054     FullScreenArea, // area for fullscreen windows
0055     // these below don't depend on xinerama settings
0056     WorkArea, // whole workarea (all screens together)
0057     FullArea, // whole area (all screens together), ignore struts
0058     ScreenArea, // one whole screen, ignore struts
0059 };
0060 
0061 enum ElectricBorder {
0062     ElectricTop,
0063     ElectricTopRight,
0064     ElectricRight,
0065     ElectricBottomRight,
0066     ElectricBottom,
0067     ElectricBottomLeft,
0068     ElectricLeft,
0069     ElectricTopLeft,
0070     ELECTRIC_COUNT,
0071     ElectricNone,
0072 };
0073 Q_ENUM_NS(ElectricBorder)
0074 
0075 // TODO: Hardcoding is bad, need to add some way of registering global actions to these.
0076 // When designing the new system we must keep in mind that we have conditional actions
0077 // such as "only when moving windows" desktop switching that the current global action
0078 // system doesn't support.
0079 enum ElectricBorderAction {
0080     ElectricActionNone, // No special action, not set, desktop switch or an effect
0081     ElectricActionShowDesktop, // Show desktop or restore
0082     ElectricActionLockScreen, // Lock screen
0083     ElectricActionKRunner, // Open KRunner
0084     ElectricActionActivityManager, // Activity Manager
0085     ElectricActionApplicationLauncher, // Application Launcher
0086     ELECTRIC_ACTION_COUNT,
0087 };
0088 
0089 // DesktopMode and WindowsMode are based on the order in which the desktop
0090 //  or window were viewed.
0091 // DesktopListMode lists them in the order created.
0092 enum TabBoxMode {
0093     TabBoxDesktopMode, // Focus chain of desktops
0094     TabBoxDesktopListMode, // Static desktop order
0095     TabBoxWindowsMode, // Primary window switching mode
0096     TabBoxWindowsAlternativeMode, // Secondary window switching mode
0097     TabBoxCurrentAppWindowsMode, // Same as primary window switching mode but only for windows of current application
0098     TabBoxCurrentAppWindowsAlternativeMode, // Same as secondary switching mode but only for windows of current application
0099 };
0100 
0101 enum KWinOption {
0102     CloseButtonCorner,
0103     SwitchDesktopOnScreenEdge,
0104     SwitchDesktopOnScreenEdgeMovingWindows,
0105 };
0106 
0107 /**
0108  * @brief The direction in which a pointer axis is moved.
0109  */
0110 enum PointerAxisDirection {
0111     PointerAxisUp,
0112     PointerAxisDown,
0113     PointerAxisLeft,
0114     PointerAxisRight,
0115 };
0116 
0117 /**
0118  * @brief Directions for swipe gestures
0119  * @since 5.10
0120  */
0121 enum class SwipeDirection {
0122     Invalid,
0123     Down,
0124     Left,
0125     Up,
0126     Right,
0127 };
0128 
0129 enum class PinchDirection {
0130     Expanding,
0131     Contracting
0132 };
0133 
0134 /**
0135  * Represents the state of the session running outside kwin
0136  * Under Plasma this is managed by ksmserver
0137  */
0138 enum class SessionState {
0139     Normal,
0140     Saving,
0141     Quitting,
0142 };
0143 Q_ENUM_NS(SessionState)
0144 
0145 enum class LED {
0146     NumLock = 1 << 0,
0147     CapsLock = 1 << 1,
0148     ScrollLock = 1 << 2
0149 };
0150 Q_DECLARE_FLAGS(LEDs, LED)
0151 Q_FLAG_NS(LEDs)
0152 
0153 /**
0154  * The Gravity enum is used to specify the direction in which geometry changes during resize.
0155  */
0156 enum class Gravity {
0157     None,
0158     Left,
0159     Right,
0160     Top,
0161     Bottom,
0162     TopLeft,
0163     TopRight,
0164     BottomLeft,
0165     BottomRight,
0166 };
0167 
0168 inline KWIN_EXPORT xcb_connection_t *connection()
0169 {
0170     return reinterpret_cast<xcb_connection_t *>(qApp->property("x11Connection").value<void *>());
0171 }
0172 
0173 inline KWIN_EXPORT xcb_window_t rootWindow()
0174 {
0175     return qApp->property("x11RootWindow").value<quint32>();
0176 }
0177 
0178 inline KWIN_EXPORT xcb_timestamp_t xTime()
0179 {
0180     return qApp->property("x11Time").value<xcb_timestamp_t>();
0181 }
0182 
0183 /**
0184  * Short wrapper for a cursor image provided by the Platform.
0185  * @since 5.9
0186  */
0187 class PlatformCursorImage
0188 {
0189 public:
0190     explicit PlatformCursorImage()
0191         : m_image()
0192         , m_hotSpot()
0193     {
0194     }
0195     explicit PlatformCursorImage(const QImage &image, const QPoint &hotSpot)
0196         : m_image(image)
0197         , m_hotSpot(hotSpot)
0198     {
0199     }
0200     virtual ~PlatformCursorImage() = default;
0201 
0202     bool isNull() const
0203     {
0204         return m_image.isNull();
0205     }
0206     QImage image() const
0207     {
0208         return m_image;
0209     }
0210     QPoint hotSpot() const
0211     {
0212         return m_hotSpot;
0213     }
0214 
0215 private:
0216     QImage m_image;
0217     QPoint m_hotSpot;
0218 };
0219 
0220 /**
0221  * Infinite region (i.e. a special region type saying that everything needs to be painted).
0222  */
0223 inline KWIN_EXPORT QRect infiniteRegion()
0224 {
0225     // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
0226     return QRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX);
0227 }
0228 
0229 } // namespace
0230 
0231 Q_DECLARE_METATYPE(std::chrono::nanoseconds)
0232 
0233 #define KWIN_SINGLETON_VARIABLE(ClassName, variableName) \
0234 public:                                                  \
0235     static ClassName *create(QObject *parent = nullptr); \
0236     static ClassName *self()                             \
0237     {                                                    \
0238         return variableName;                             \
0239     }                                                    \
0240                                                          \
0241 protected:                                               \
0242     explicit ClassName(QObject *parent = nullptr);       \
0243                                                          \
0244 private:                                                 \
0245     static ClassName *variableName;
0246 
0247 #define KWIN_SINGLETON(ClassName) KWIN_SINGLETON_VARIABLE(ClassName, s_self)
0248 
0249 #define KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, variableName) \
0250     ClassName *ClassName::variableName = nullptr;                                            \
0251     ClassName *ClassName::create(QObject *parent)                                            \
0252     {                                                                                        \
0253         Q_ASSERT(!variableName);                                                             \
0254         variableName = new FactoredClassName(parent);                                        \
0255         return variableName;                                                                 \
0256     }
0257 #define KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, variableName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, ClassName, variableName)
0258 #define KWIN_SINGLETON_FACTORY_FACTORED(ClassName, FactoredClassName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, s_self)
0259 #define KWIN_SINGLETON_FACTORY(ClassName) KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, s_self)