KWin
Loading...
Searching...
No Matches
main.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#pragma once
12
13#include "effect/globals.h"
14#include <config-kwin.h>
15
16#include <KSharedConfig>
17#include <memory>
18// Qt
19#include <QAbstractNativeEventFilter>
20#include <QApplication>
21#include <QProcessEnvironment>
22
23#include <xcb/xcb.h>
24
25class KPluginMetaData;
26class QCommandLineParser;
27
28namespace KWin
29{
30
31class OutputBackend;
32class Session;
33class X11EventFilter;
34class PluginManager;
35class InputMethod;
36class ColorManager;
37class ScreenLockerWatcher;
38class TabletModeManager;
39class XwaylandInterface;
40class Cursor;
41class Edge;
42class ScreenEdges;
43class Outline;
44class OutlineVisual;
45class Compositor;
46class WorkspaceScene;
47class Window;
48
49class XcbEventFilter : public QAbstractNativeEventFilter
50{
51public:
52 bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
53};
54
55class X11EventFilterContainer : public QObject
56{
57 Q_OBJECT
58
59public:
61
62 X11EventFilter *filter() const;
63
64private:
65 X11EventFilter *m_filter;
66};
67
68class KWIN_EXPORT Application : public QApplication
69{
70 Q_OBJECT
71 Q_PROPERTY(quint32 x11Time READ x11Time WRITE setX11Time)
72 Q_PROPERTY(quint32 x11RootWindow READ x11RootWindow CONSTANT)
73 Q_PROPERTY(void *x11Connection READ x11Connection NOTIFY x11ConnectionChanged)
74 Q_PROPERTY(KSharedConfigPtr config READ config WRITE setConfig)
75 Q_PROPERTY(KSharedConfigPtr kxkbConfig READ kxkbConfig WRITE setKxkbConfig)
76public:
97 Q_ENUM(OperationMode)
98 ~Application() override;
99
100 void setConfigLock(bool lock);
101
102 KSharedConfigPtr config() const
103 {
104 return m_config;
105 }
106 void setConfig(KSharedConfigPtr config)
107 {
108 m_config = std::move(config);
109 }
110
111 KSharedConfigPtr kxkbConfig() const
112 {
113 return m_kxkbConfig;
114 }
115 void setKxkbConfig(KSharedConfigPtr config)
116 {
117 m_kxkbConfig = std::move(config);
118 }
119
120 KSharedConfigPtr inputConfig() const
121 {
122 return m_inputConfig;
123 }
124 void setInputConfig(KSharedConfigPtr config)
125 {
126 m_inputConfig = std::move(config);
127 }
128
129 void start();
135 OperationMode operationMode() const;
136 void setOperationMode(OperationMode mode);
137 bool shouldUseWaylandForCompositing() const;
138
139 void setupCommandLine(QCommandLineParser *parser);
140 void processCommandLine(QCommandLineParser *parser);
141
142 void registerEventFilter(X11EventFilter *filter);
143 void unregisterEventFilter(X11EventFilter *filter);
144 bool dispatchEvent(xcb_generic_event_t *event);
145
146 xcb_timestamp_t x11Time() const
147 {
148 return m_x11Time;
149 }
150 enum class TimestampUpdate {
151 OnlyIfLarger,
152 Always
153 };
154 void setX11Time(xcb_timestamp_t timestamp, TimestampUpdate force = TimestampUpdate::OnlyIfLarger)
155 {
156 if ((timestamp > m_x11Time || force == TimestampUpdate::Always) && timestamp != 0) {
157 m_x11Time = timestamp;
158 }
159 }
163 void updateXTime();
164 void updateX11Time(xcb_generic_event_t *event);
165
166 static void setCrashCount(int count);
167 static bool wasCrash();
168 void resetCrashesCount();
169
174 static void createAboutData();
175
179 xcb_window_t x11RootWindow() const
180 {
181 return m_rootWindow;
182 }
183
187 xcb_window_t x11CompositeWindow() const
188 {
189 return m_compositeWindow;
190 }
191
195 xcb_connection_t *x11Connection() const
196 {
197 return m_connection;
198 }
199
204 void setX11RootWindow(xcb_window_t root)
205 {
206 m_rootWindow = root;
207 }
212 void setX11Connection(xcb_connection_t *c)
213 {
214 m_connection = c;
215 }
216 void setX11CompositeWindow(xcb_window_t window)
217 {
218 m_compositeWindow = window;
219 }
220
221 qreal xwaylandScale() const
222 {
223 return m_xwaylandScale;
224 }
225
226 void setXwaylandScale(qreal scale);
227
228#if KWIN_BUILD_ACTIVITIES
229 bool usesKActivities() const
230 {
231 return m_useKActivities;
232 }
233 void setUseKActivities(bool use)
234 {
235 m_useKActivities = use;
236 }
237#endif
238
239 QProcessEnvironment processStartupEnvironment() const;
240 void setProcessStartupEnvironment(const QProcessEnvironment &environment);
241
243 {
244 return m_outputBackend.get();
245 }
246 void setOutputBackend(std::unique_ptr<OutputBackend> &&backend);
247
249 {
250 return m_session.get();
251 }
252 void setSession(std::unique_ptr<Session> &&session);
253 void setFollowLocale1(bool follow)
254 {
255 m_followLocale1 = follow;
256 }
257 bool followLocale1() const
258 {
259 return m_followLocale1;
260 }
261
262 bool isTerminating() const
263 {
264 return m_terminating;
265 }
266
267 void installNativeX11EventFilter();
268 void removeNativeX11EventFilter();
269
270 void createAtoms();
271 void destroyAtoms();
272
273 virtual std::unique_ptr<Edge> createScreenEdge(ScreenEdges *parent);
274 virtual std::unique_ptr<Cursor> createPlatformCursor();
275 virtual std::unique_ptr<OutlineVisual> createOutline(Outline *outline);
276 virtual void createEffectsHandler(Compositor *compositor, WorkspaceScene *scene);
277
278 static void setupMalloc();
279 static void setupLocalizedString();
280
281 PluginManager *pluginManager() const;
282 InputMethod *inputMethod() const;
283 ColorManager *colorManager() const;
284 virtual XwaylandInterface *xwayland() const;
285#if KWIN_BUILD_SCREENLOCKER
286 ScreenLockerWatcher *screenLockerWatcher() const;
287#endif
288 TabletModeManager *tabletModeManager() const;
289
306 virtual void startInteractiveWindowSelection(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName = QByteArray());
307
322 virtual void startInteractivePositionSelection(std::function<void(const QPointF &)> callback);
323
333 virtual PlatformCursorImage cursorImage() const;
334
335Q_SIGNALS:
341 void started();
342
343protected:
344 Application(OperationMode mode, int &argc, char **argv);
345 virtual void performStartup() = 0;
346
348 void notifyStarted();
349 void createInput();
350 void createWorkspace();
351 void createOptions();
352 void createPlugins();
353 void createColorManager();
354 void createInputMethod();
355 void createTabletModeManager();
356 void destroyInput();
357 void destroyWorkspace();
358 void destroyCompositor();
359 void destroyPlugins();
360 void destroyColorManager();
361 void destroyInputMethod();
362 void destroyPlatform();
363 void applyXwaylandScale();
364
366 {
367 m_terminating = true;
368 }
369
370protected:
371 static int crashes;
372
373private:
374 QList<QPointer<X11EventFilterContainer>> m_eventFilters;
375 QList<QPointer<X11EventFilterContainer>> m_genericEventFilters;
376 std::unique_ptr<XcbEventFilter> m_eventFilter;
377 bool m_followLocale1 = false;
378 bool m_configLock;
379 KSharedConfigPtr m_config;
380 KSharedConfigPtr m_kxkbConfig;
381 KSharedConfigPtr m_inputConfig;
382 OperationMode m_operationMode;
383 xcb_timestamp_t m_x11Time = XCB_TIME_CURRENT_TIME;
384 xcb_window_t m_rootWindow = XCB_WINDOW_NONE;
385 xcb_window_t m_compositeWindow = XCB_WINDOW_NONE;
386 xcb_connection_t *m_connection = nullptr;
387#if KWIN_BUILD_ACTIVITIES
388 bool m_useKActivities = true;
389#endif
390 std::unique_ptr<Session> m_session;
391 std::unique_ptr<OutputBackend> m_outputBackend;
392 bool m_terminating = false;
393 qreal m_xwaylandScale = 1;
394 QProcessEnvironment m_processEnvironment;
395 std::unique_ptr<PluginManager> m_pluginManager;
396 std::unique_ptr<InputMethod> m_inputMethod;
397 std::unique_ptr<ColorManager> m_colorManager;
398 std::unique_ptr<TabletModeManager> m_tabletModeManager;
399#if KWIN_BUILD_SCREENLOCKER
400 std::unique_ptr<ScreenLockerWatcher> m_screenLockerWatcher;
401#endif
402 std::unique_ptr<Cursor> m_platformCursor;
403};
404
405inline static Application *kwinApp()
406{
407 Q_ASSERT(qobject_cast<Application *>(QCoreApplication::instance()));
408
409 return static_cast<Application *>(QCoreApplication::instance());
410}
411
412} // namespace
void virtualTerminalCreated()
xcb_connection_t * x11Connection() const
Definition main.h:195
virtual void performStartup()=0
static int crashes
Definition main.h:371
OutputBackend * outputBackend() const
Definition main.h:242
KSharedConfigPtr config() const
Definition main.h:102
void setKxkbConfig(KSharedConfigPtr config)
Definition main.h:115
qreal xwaylandScale() const
Definition main.h:221
void setX11RootWindow(xcb_window_t root)
Definition main.h:204
bool followLocale1() const
Definition main.h:257
void setFollowLocale1(bool follow)
Definition main.h:253
void setConfig(KSharedConfigPtr config)
Definition main.h:106
xcb_window_t x11CompositeWindow() const
Definition main.h:187
void setX11Time(xcb_timestamp_t timestamp, TimestampUpdate force=TimestampUpdate::OnlyIfLarger)
Definition main.h:154
void setX11CompositeWindow(xcb_window_t window)
Definition main.h:216
Session * session() const
Definition main.h:248
xcb_timestamp_t x11Time() const
Definition main.h:146
xcb_window_t x11RootWindow() const
Definition main.h:179
void setInputConfig(KSharedConfigPtr config)
Definition main.h:124
void xwaylandScaleChanged()
KSharedConfigPtr kxkbConfig() const
Definition main.h:111
KSharedConfigPtr inputConfig() const
Definition main.h:120
bool isTerminating() const
Definition main.h:262
void setTerminating()
Definition main.h:365
void x11ConnectionChanged()
void x11ConnectionAboutToBeDestroyed()
OperationMode
This enum provides the various operation modes of KWin depending on the available Windowing Systems a...
Definition main.h:83
@ OperationModeX11
KWin uses only X11 for managing windows and compositing.
Definition main.h:87
@ OperationModeWaylandOnly
KWin uses only Wayland.
Definition main.h:91
void setX11Connection(xcb_connection_t *c)
Definition main.h:212
This class is used to show the outline of a given geometry.
Definition outline.h:38
Class for controlling screen edges.
Definition screenedge.h:222
X11EventFilterContainer(X11EventFilter *filter)
Definition workspace.cpp:80
X11EventFilter * filter() const
Definition workspace.cpp:85
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override
Definition main.cpp:620