KWin
Loading...
Searching...
No Matches
x11_windowed_backend.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: 2015 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include "core/inputbackend.h"
12#include "core/inputdevice.h"
13#include "core/outputbackend.h"
15
16#include <kwin_export.h>
17
18#include <QObject>
19#include <QSize>
20
21#include <xcb/xcb.h>
22
23struct gbm_device;
24struct _XDisplay;
25typedef struct _XDisplay Display;
26typedef struct _XCBKeySymbols xcb_key_symbols_t;
27class NETWinInfo;
28class QSocketNotifier;
29
30namespace KWin
31{
32class X11WindowedBackend;
33class X11WindowedOutput;
34
36{
37 Q_OBJECT
38
39public:
40 explicit X11WindowedInputDevice() = default;
41
42 void setPointer(bool set);
43 void setKeyboard(bool set);
44 void setTouch(bool set);
45 void setName(const QString &name);
46
47 QString sysName() const override;
48 QString name() const override;
49
50 bool isEnabled() const override;
51 void setEnabled(bool enabled) override;
52
53 LEDs leds() const override;
54 void setLeds(LEDs leds) override;
55
56 bool isKeyboard() const override;
57 bool isPointer() const override;
58 bool isTouchpad() const override;
59 bool isTouch() const override;
60 bool isTabletTool() const override;
61 bool isTabletPad() const override;
62 bool isTabletModeSwitch() const override;
63 bool isLidSwitch() const override;
64
65private:
66 QString m_name;
67 bool m_pointer = false;
68 bool m_keyboard = false;
69 bool m_touch = false;
70};
71
73{
74 Q_OBJECT
75
76public:
78
79 void initialize() override;
80
81private:
82 X11WindowedBackend *m_backend;
83};
84
86{
87 QString display;
88 int outputCount = 1;
89 qreal outputScale = 1;
90 QSize outputSize = QSize(1024, 768);
91};
92
93class KWIN_EXPORT X11WindowedBackend : public OutputBackend
94{
95 Q_OBJECT
96
97public:
99 ~X11WindowedBackend() override;
100
101 ::Display *display() const;
102 xcb_connection_t *connection() const;
103 xcb_screen_t *screen() const;
104 int screenNumer() const;
105 xcb_window_t rootWindow() const;
106 gbm_device *gbmDevice() const;
107
108 bool hasXInput() const;
109
110 QHash<uint32_t, QList<uint64_t>> driFormats() const;
111 uint32_t driFormatForDepth(int depth) const;
112 int driMajorVersion() const;
113 int driMinorVersion() const;
114
115 bool initialize() override;
116 std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
117 std::unique_ptr<QPainterBackend> createQPainterBackend() override;
118 std::unique_ptr<InputBackend> createInputBackend() override;
119 QList<CompositingType> supportedCompositors() const override;
120 Outputs outputs() const override;
121
122 X11WindowedInputDevice *pointerDevice() const;
123 X11WindowedInputDevice *keyboardDevice() const;
124 X11WindowedInputDevice *touchDevice() const;
125
126 void setEglDisplay(std::unique_ptr<EglDisplay> &&display);
127 EglDisplay *sceneEglDisplayObject() const override;
128
129private:
130 void createOutputs();
131 void grabKeyboard(xcb_timestamp_t time);
132 void updateWindowTitle();
133 void handleEvent(xcb_generic_event_t *event);
134 void handleClientMessage(xcb_client_message_event_t *event);
135 void handleButtonPress(xcb_button_press_event_t *event);
136 void handleExpose(xcb_expose_event_t *event);
137 void handleXinputEvent(xcb_ge_generic_event_t *event);
138 void handlePresentEvent(xcb_ge_generic_event_t *event);
139 void updateSize(xcb_configure_notify_event_t *event);
140 void initXInput();
141 void initDri3();
142 X11WindowedOutput *findOutput(xcb_window_t window) const;
143 void destroyOutputs();
144
146 xcb_connection_t *m_connection = nullptr;
147 xcb_screen_t *m_screen = nullptr;
148 xcb_key_symbols_t *m_keySymbols = nullptr;
149 int m_screenNumber = 0;
150
151 std::unique_ptr<X11WindowedInputDevice> m_pointerDevice;
152 std::unique_ptr<X11WindowedInputDevice> m_keyboardDevice;
153 std::unique_ptr<X11WindowedInputDevice> m_touchDevice;
154
155 xcb_atom_t m_protocols = XCB_ATOM_NONE;
156 xcb_atom_t m_deleteWindowProtocol = XCB_ATOM_NONE;
157 ::Display *m_display = nullptr;
158 bool m_keyboardGrabbed = false;
159 std::unique_ptr<QSocketNotifier> m_eventNotifier;
160
161 bool m_hasXInput = false;
162 int m_xiOpcode = 0;
163 int m_majorVersion = 0;
164 int m_minorVersion = 0;
165
166 int m_presentOpcode = 0;
167 int m_presentMajorVersion = 0;
168 int m_presentMinorVersion = 0;
169
170 bool m_hasShm = false;
171
172 bool m_hasDri = false;
173 int m_driMajorVersion = 0;
174 int m_driMinorVersion = 0;
175 QHash<uint32_t, QList<uint64_t>> m_driFormats;
176
177 FileDescriptor m_drmFileDescriptor;
178 gbm_device *m_gbmDevice = nullptr;
179 std::unique_ptr<EglDisplay> m_eglDisplay;
180
181 QList<X11WindowedOutput *> m_outputs;
182};
183
184} // namespace KWin
X11WindowedInputBackend(X11WindowedBackend *backend)
void setEnabled(bool enabled) override
void setLeds(LEDs leds) override
bool isTabletModeSwitch() const override
QString sysName() const override
void setName(const QString &name)
KWIN_EXPORT xcb_window_t rootWindow()
Definition xcb.h:24
Options * options
Definition main.cpp:73
struct _XDisplay Display
struct _XCBKeySymbols xcb_key_symbols_t