1 /*
2     KWin - the KDE window manager
3     This file is part of the KDE project.
4 
5     SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
6 
7     SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #ifndef KWIN_LIB_KWINGLOBALS_H
11 #define KWIN_LIB_KWINGLOBALS_H
12 
13 #include <QCoreApplication>
14 #include <QImage>
15 #include <QPoint>
16 #include <QVariant>
17 
18 #include <kwin_export.h>
19 
20 #include <xcb/xcb.h>
21 
22 #include <kwinconfig.h>
23 
24 #define KWIN_QT5_PORTING 0
25 
26 namespace KWin
27 {
28 KWIN_EXPORT Q_NAMESPACE
29 
30 enum CompositingType {
31     NoCompositing = 0,
32     /**
33      * Used as a flag whether OpenGL based compositing is used.
34      * The flag is or-ed to the enum values of the specific OpenGL types.
35      * The actual Compositors use the or @c OpenGLCompositing
36      * flags. If you need to know whether OpenGL is used, either and the flag or
37      * use EffectsHandler::isOpenGLCompositing().
38      */
39     OpenGLCompositing = 1,
40     /* XRenderCompositing = 1<<1, */
41     QPainterCompositing = 1<< 2,
42 };
43 
44 enum OpenGLPlatformInterface {
45     NoOpenGLPlatformInterface = 0,
46     GlxPlatformInterface,
47     EglPlatformInterface,
48 };
49 
50 enum clientAreaOption {
51     PlacementArea,         // geometry where a window will be initially placed after being mapped
52     MovementArea,          // ???  window movement snapping area?  ignore struts
53     MaximizeArea,          // geometry to which a window will be maximized
54     MaximizeFullArea,      // like MaximizeArea, but ignore struts - used e.g. for topmenu
55     FullScreenArea,        // area for fullscreen windows
56     // these below don't depend on xinerama settings
57     WorkArea,              // whole workarea (all screens together)
58     FullArea,              // whole area (all screens together), ignore struts
59     ScreenArea,            // one whole screen, ignore struts
60 };
61 
62 enum ElectricBorder {
63     ElectricTop,
64     ElectricTopRight,
65     ElectricRight,
66     ElectricBottomRight,
67     ElectricBottom,
68     ElectricBottomLeft,
69     ElectricLeft,
70     ElectricTopLeft,
71     ELECTRIC_COUNT,
72     ElectricNone,
73 };
74 
75 // TODO: Hardcoding is bad, need to add some way of registering global actions to these.
76 // When designing the new system we must keep in mind that we have conditional actions
77 // such as "only when moving windows" desktop switching that the current global action
78 // system doesn't support.
79 enum ElectricBorderAction {
80     ElectricActionNone,          // No special action, not set, desktop switch or an effect
81     ElectricActionShowDesktop,   // Show desktop or restore
82     ElectricActionLockScreen,   // Lock screen
83     ElectricActionKRunner,       // Open KRunner
84     ElectricActionActivityManager, // Activity Manager
85     ElectricActionApplicationLauncher, // Application Launcher
86     ELECTRIC_ACTION_COUNT,
87 };
88 
89 // DesktopMode and WindowsMode are based on the order in which the desktop
90 //  or window were viewed.
91 // DesktopListMode lists them in the order created.
92 enum TabBoxMode {
93     TabBoxDesktopMode,                      // Focus chain of desktops
94     TabBoxDesktopListMode,                  // Static desktop order
95     TabBoxWindowsMode,                      // Primary window switching mode
96     TabBoxWindowsAlternativeMode,           // Secondary window switching mode
97     TabBoxCurrentAppWindowsMode,            // Same as primary window switching mode but only for windows of current application
98     TabBoxCurrentAppWindowsAlternativeMode,  // Same as secondary switching mode but only for windows of current application
99 };
100 
101 enum KWinOption {
102     CloseButtonCorner,
103     SwitchDesktopOnScreenEdge,
104     SwitchDesktopOnScreenEdgeMovingWindows,
105 };
106 
107 /**
108  * @brief The direction in which a pointer axis is moved.
109  */
110 enum PointerAxisDirection {
111     PointerAxisUp,
112     PointerAxisDown,
113     PointerAxisLeft,
114     PointerAxisRight,
115 };
116 
117 /**
118  * @brief Directions for swipe gestures
119  * @since 5.10
120  */
121 enum class SwipeDirection {
122     Invalid,
123     Down,
124     Left,
125     Up,
126     Right,
127 };
128 
129 /**
130  * Represents the state of the session running outside kwin
131  * Under Plasma this is managed by ksmserver
132  */
133 enum class SessionState {
134     Normal,
135     Saving,
136     Quitting,
137 };
Q_ENUM_NS(SessionState)138 Q_ENUM_NS(SessionState)
139 
140 inline
141 KWIN_EXPORT xcb_connection_t *connection()
142 {
143     return reinterpret_cast<xcb_connection_t*>(qApp->property("x11Connection").value<void*>());
144 }
145 
146 inline
rootWindow()147 KWIN_EXPORT xcb_window_t rootWindow()
148 {
149     return qApp->property("x11RootWindow").value<quint32>();
150 }
151 
152 inline
xTime()153 KWIN_EXPORT xcb_timestamp_t xTime()
154 {
155     return qApp->property("x11Time").value<xcb_timestamp_t>();
156 }
157 
158 /**
159  * Short wrapper for a cursor image provided by the Platform.
160  * @since 5.9
161  */
162 class PlatformCursorImage {
163 public:
PlatformCursorImage()164     explicit PlatformCursorImage()
165         : m_image()
166         , m_hotSpot()
167     {
168     }
PlatformCursorImage(const QImage & image,const QPoint & hotSpot)169     explicit PlatformCursorImage(const QImage &image, const QPoint &hotSpot)
170         : m_image(image)
171         , m_hotSpot(hotSpot)
172     {
173     }
174     virtual ~PlatformCursorImage() = default;
175 
isNull()176     bool isNull() const {
177         return m_image.isNull();
178     }
image()179     QImage image() const {
180         return m_image;
181     }
hotSpot()182     QPoint hotSpot() const {
183         return m_hotSpot;
184     }
185 
186 private:
187     QImage m_image;
188     QPoint m_hotSpot;
189 };
190 
191 } // namespace
192 
193 Q_DECLARE_METATYPE(std::chrono::nanoseconds)
194 
195 #define KWIN_SINGLETON_VARIABLE(ClassName, variableName) \
196 public: \
197     static ClassName *create(QObject *parent = nullptr);\
198     static ClassName *self() { return variableName; }\
199 protected: \
200     explicit ClassName(QObject *parent = nullptr); \
201 private: \
202     static ClassName *variableName;
203 
204 #define KWIN_SINGLETON(ClassName) KWIN_SINGLETON_VARIABLE(ClassName, s_self)
205 
206 #define KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, variableName) \
207 ClassName *ClassName::variableName = nullptr; \
208 ClassName *ClassName::create(QObject *parent) \
209 { \
210     Q_ASSERT(!variableName); \
211     variableName = new FactoredClassName(parent); \
212     return variableName; \
213 }
214 #define KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, variableName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, ClassName, variableName)
215 #define KWIN_SINGLETON_FACTORY_FACTORED(ClassName, FactoredClassName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, s_self)
216 #define KWIN_SINGLETON_FACTORY(ClassName) KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, s_self)
217 
218 #endif
219