1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | *********************************************************************/ |
20 | |
21 | #ifndef KWIN_LIB_KWINGLOBALS_H |
22 | #define KWIN_LIB_KWINGLOBALS_H |
23 | |
24 | #include <QX11Info> |
25 | |
26 | #include <kdemacros.h> |
27 | |
28 | #include <X11/Xlib.h> |
29 | #include <X11/Xlib-xcb.h> |
30 | #include <fixx11h.h> |
31 | #include <xcb/xcb.h> |
32 | |
33 | #include <kwinconfig.h> |
34 | |
35 | #define KWIN_EXPORT KDE_EXPORT |
36 | |
37 | namespace KWin |
38 | { |
39 | |
40 | |
41 | enum CompositingType { |
42 | NoCompositing = 0, |
43 | /** |
44 | * Used as a flag whether OpenGL based compositing is used. |
45 | * The flag is or-ed to the enum values of the specific OpenGL types. |
46 | * The actual Compositors use the @c OpenGL1Compositing or @c OpenGL2Compositing |
47 | * flags. If you need to know whether OpenGL is used, either and the flag or |
48 | * use EffectsHandler::isOpenGLCompositing(). |
49 | **/ |
50 | OpenGLCompositing = 1, |
51 | XRenderCompositing = 1<<1, |
52 | OpenGL1Compositing = 1<<2 | OpenGLCompositing, |
53 | OpenGL2Compositing = 1<<3 | OpenGLCompositing |
54 | }; |
55 | |
56 | enum OpenGLPlatformInterface { |
57 | NoOpenGLPlatformInterface = 0, |
58 | GlxPlatformInterface, |
59 | EglPlatformInterface |
60 | }; |
61 | |
62 | enum clientAreaOption { |
63 | PlacementArea, // geometry where a window will be initially placed after being mapped |
64 | MovementArea, // ??? window movement snapping area? ignore struts |
65 | MaximizeArea, // geometry to which a window will be maximized |
66 | MaximizeFullArea, // like MaximizeArea, but ignore struts - used e.g. for topmenu |
67 | FullScreenArea, // area for fullscreen windows |
68 | // these below don't depend on xinerama settings |
69 | WorkArea, // whole workarea (all screens together) |
70 | FullArea, // whole area (all screens together), ignore struts |
71 | ScreenArea // one whole screen, ignore struts |
72 | }; |
73 | |
74 | enum ElectricBorder { |
75 | ElectricTop, |
76 | ElectricTopRight, |
77 | ElectricRight, |
78 | ElectricBottomRight, |
79 | ElectricBottom, |
80 | ElectricBottomLeft, |
81 | ElectricLeft, |
82 | ElectricTopLeft, |
83 | ELECTRIC_COUNT, |
84 | ElectricNone |
85 | }; |
86 | |
87 | // TODO: Hardcoding is bad, need to add some way of registering global actions to these. |
88 | // When designing the new system we must keep in mind that we have conditional actions |
89 | // such as "only when moving windows" desktop switching that the current global action |
90 | // system doesn't support. |
91 | enum ElectricBorderAction { |
92 | ElectricActionNone, // No special action, not set, desktop switch or an effect |
93 | ElectricActionDashboard, // Launch the Plasma dashboard |
94 | ElectricActionShowDesktop, // Show desktop or restore |
95 | ElectricActionLockScreen, // Lock screen |
96 | ElectricActionPreventScreenLocking, |
97 | ELECTRIC_ACTION_COUNT |
98 | }; |
99 | |
100 | // DesktopMode and WindowsMode are based on the order in which the desktop |
101 | // or window were viewed. |
102 | // DesktopListMode lists them in the order created. |
103 | enum TabBoxMode { |
104 | TabBoxDesktopMode, // Focus chain of desktops |
105 | TabBoxDesktopListMode, // Static desktop order |
106 | TabBoxWindowsMode, // Primary window switching mode |
107 | TabBoxWindowsAlternativeMode, // Secondary window switching mode |
108 | TabBoxCurrentAppWindowsMode, // Same as primary window switching mode but only for windows of current application |
109 | TabBoxCurrentAppWindowsAlternativeMode // Same as secondary switching mode but only for windows of current application |
110 | }; |
111 | |
112 | enum KWinOption { |
113 | CloseButtonCorner, |
114 | SwitchDesktopOnScreenEdge, |
115 | SwitchDesktopOnScreenEdgeMovingWindows |
116 | }; |
117 | |
118 | inline |
119 | KWIN_EXPORT Display* display() |
120 | { |
121 | return QX11Info::display(); |
122 | } |
123 | |
124 | inline |
125 | KWIN_EXPORT xcb_connection_t *connection() |
126 | { |
127 | static xcb_connection_t *s_con = NULL; |
128 | if (!s_con) { |
129 | s_con = XGetXCBConnection(display()); |
130 | } |
131 | return s_con; |
132 | } |
133 | |
134 | inline |
135 | KWIN_EXPORT xcb_window_t rootWindow() |
136 | { |
137 | return QX11Info::appRootWindow(); |
138 | } |
139 | |
140 | inline |
141 | KWIN_EXPORT xcb_timestamp_t xTime() |
142 | { |
143 | return QX11Info::appTime(); |
144 | } |
145 | |
146 | inline |
147 | KWIN_EXPORT xcb_screen_t *defaultScreen() |
148 | { |
149 | static xcb_screen_t *s_screen = NULL; |
150 | if (s_screen) { |
151 | return s_screen; |
152 | } |
153 | int screen = QX11Info::appScreen(); |
154 | for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(connection())); |
155 | it.rem; |
156 | --screen, xcb_screen_next(&it)) { |
157 | if (screen == 0) { |
158 | s_screen = it.data; |
159 | } |
160 | } |
161 | return s_screen; |
162 | } |
163 | |
164 | inline |
165 | KWIN_EXPORT int displayWidth() |
166 | { |
167 | #if 0 |
168 | xcb_screen_t *screen = defaultScreen(); |
169 | return screen ? screen->width_in_pixels : 0; |
170 | #else |
171 | return XDisplayWidth(display(), DefaultScreen(display())); |
172 | #endif |
173 | } |
174 | |
175 | inline |
176 | KWIN_EXPORT int displayHeight() |
177 | { |
178 | #if 0 |
179 | xcb_screen_t *screen = defaultScreen(); |
180 | return screen ? screen->height_in_pixels : 0; |
181 | #else |
182 | return XDisplayHeight(display(), DefaultScreen(display())); |
183 | #endif |
184 | } |
185 | |
186 | /** @internal */ |
187 | // TODO: QT5: remove |
188 | class KWIN_EXPORT Extensions |
189 | { |
190 | public: |
191 | static void init(); |
192 | static bool nonNativePixmaps() { |
193 | return non_native_pixmaps; |
194 | } |
195 | private: |
196 | static bool non_native_pixmaps; |
197 | }; |
198 | |
199 | } // namespace |
200 | |
201 | #define KWIN_SINGLETON_VARIABLE(ClassName, variableName) \ |
202 | public: \ |
203 | static ClassName *create(QObject *parent = 0);\ |
204 | static ClassName *self() { return variableName; }\ |
205 | protected: \ |
206 | explicit ClassName(QObject *parent = 0); \ |
207 | private: \ |
208 | static ClassName *variableName; |
209 | |
210 | #define KWIN_SINGLETON(ClassName) KWIN_SINGLETON_VARIABLE(ClassName, s_self) |
211 | |
212 | #define KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, variableName) \ |
213 | ClassName *ClassName::variableName = 0; \ |
214 | ClassName *ClassName::create(QObject *parent) \ |
215 | { \ |
216 | Q_ASSERT(!variableName); \ |
217 | variableName = new FactoredClassName(parent); \ |
218 | return variableName; \ |
219 | } |
220 | #define KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, variableName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, ClassName, variableName) |
221 | #define KWIN_SINGLETON_FACTORY_FACTORED(ClassName, FactoredClassName) KWIN_SINGLETON_FACTORY_VARIABLE_FACTORED(ClassName, FactoredClassName, s_self) |
222 | #define KWIN_SINGLETON_FACTORY(ClassName) KWIN_SINGLETON_FACTORY_VARIABLE(ClassName, s_self) |
223 | |
224 | #endif |
225 | |