Changeset View
Changeset View
Standalone View
Standalone View
backends/xcbeventlistener.cpp
Show All 20 Lines | |||||
21 | #include <QX11Info> | 21 | #include <QX11Info> | ||
22 | #include <QGuiApplication> | 22 | #include <QGuiApplication> | ||
23 | 23 | | |||
24 | #include <QRect> | 24 | #include <QRect> | ||
25 | 25 | | |||
26 | Q_LOGGING_CATEGORY(KSCREEN_XCB_HELPER, "kscreen.xcb.helper") | 26 | Q_LOGGING_CATEGORY(KSCREEN_XCB_HELPER, "kscreen.xcb.helper") | ||
27 | 27 | | |||
28 | XCBEventListener::XCBEventListener(): | 28 | XCBEventListener::XCBEventListener(): | ||
29 | QObject(), | | |||
30 | m_isRandrPresent(false), | 29 | m_isRandrPresent(false), | ||
31 | m_randrBase(0), | 30 | m_randrBase(0), | ||
32 | m_randrErrorBase(0), | 31 | m_randrErrorBase(0), | ||
33 | m_majorOpcode(0), | 32 | m_majorOpcode(0), | ||
34 | m_eventType(0), | | |||
35 | m_versionMajor(0), | 33 | m_versionMajor(0), | ||
36 | m_versionMinor(0), | 34 | m_versionMinor(0), | ||
37 | m_window(0) | 35 | m_window(0) | ||
38 | { | 36 | { | ||
39 | xcb_connection_t* c = QX11Info::connection(); | 37 | xcb_connection_t *c = QX11Info::connection(); | ||
40 | xcb_prefetch_extension_data(c, &xcb_randr_id); | 38 | xcb_prefetch_extension_data(c, &xcb_randr_id); | ||
41 | auto cookie = xcb_randr_query_version(c, XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION); | 39 | auto cookie = xcb_randr_query_version(c, XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION); | ||
42 | const auto *queryExtension = xcb_get_extension_data(c, &xcb_randr_id); | 40 | const auto *queryExtension = xcb_get_extension_data(c, &xcb_randr_id); | ||
43 | if (!queryExtension) { | 41 | if (!queryExtension) { | ||
44 | qCDebug(KSCREEN_XCB_HELPER) << "Fail to query for xrandr extension"; | 42 | qCDebug(KSCREEN_XCB_HELPER) << "Fail to query for xrandr extension"; | ||
45 | return; | 43 | return; | ||
46 | } | 44 | } | ||
47 | if (!queryExtension->present) { | 45 | if (!queryExtension->present) { | ||
48 | qCDebug(KSCREEN_XCB_HELPER) << "XRandR extension is not present at all"; | 46 | qCDebug(KSCREEN_XCB_HELPER) << "XRandR extension is not present at all"; | ||
49 | return; | 47 | return; | ||
50 | } | 48 | } | ||
51 | 49 | | |||
52 | m_isRandrPresent = queryExtension->present; | 50 | m_isRandrPresent = queryExtension->present; | ||
53 | m_randrBase = queryExtension->first_event; | 51 | m_randrBase = queryExtension->first_event; | ||
54 | m_randrErrorBase = queryExtension->first_error; | 52 | m_randrErrorBase = queryExtension->first_error; | ||
55 | m_majorOpcode = queryExtension->major_opcode; | 53 | m_majorOpcode = queryExtension->major_opcode; | ||
56 | 54 | | |||
57 | xcb_generic_error_t *error = nullptr; | 55 | xcb_generic_error_t *error = nullptr; | ||
58 | auto* versionReply = xcb_randr_query_version_reply(c, cookie, &error); | 56 | auto *versionReply = xcb_randr_query_version_reply(c, cookie, &error); | ||
59 | Q_ASSERT_X(versionReply, "xrandrxcbhelper", "Query to fetch xrandr version failed"); | 57 | Q_ASSERT_X(versionReply, "xrandrxcbhelper", "Query to fetch xrandr version failed"); | ||
60 | if (error) { | 58 | if (error) { | ||
61 | qFatal("Error while querying for xrandr version: %d", error->error_code); | 59 | qFatal("Error while querying for xrandr version: %d", error->error_code); | ||
62 | } | 60 | } | ||
63 | m_versionMajor = versionReply->major_version; | 61 | m_versionMajor = versionReply->major_version; | ||
64 | m_versionMinor = versionReply->minor_version; | 62 | m_versionMinor = versionReply->minor_version; | ||
65 | free(versionReply); | 63 | free(versionReply); | ||
66 | 64 | | |||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
129 | bool XCBEventListener::nativeEventFilter(const QByteArray& eventType, void* message, long int* result) | 127 | bool XCBEventListener::nativeEventFilter(const QByteArray& eventType, void* message, long int* result) | ||
130 | { | 128 | { | ||
131 | Q_UNUSED(result); | 129 | Q_UNUSED(result); | ||
132 | 130 | | |||
133 | if (eventType != "xcb_generic_event_t") { | 131 | if (eventType != "xcb_generic_event_t") { | ||
134 | return false; | 132 | return false; | ||
135 | } | 133 | } | ||
136 | 134 | | |||
137 | xcb_generic_event_t* e = static_cast<xcb_generic_event_t *>(message); | 135 | auto *e = static_cast<xcb_generic_event_t *>(message); | ||
zzag: `auto *e` | |||||
138 | const uint8_t xEventType = e->response_type & ~0x80; | 136 | const uint8_t xEventType = e->response_type & ~0x80; | ||
139 | 137 | | |||
140 | //If this event is not xcb_randr_notify, we don't want it | 138 | //If this event is not xcb_randr_notify, we don't want it | ||
141 | if (xEventType == m_randrBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { | 139 | if (xEventType == m_randrBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { | ||
142 | handleScreenChange(e); | 140 | handleScreenChange(e); | ||
143 | } | 141 | } | ||
144 | if (xEventType == m_randrBase + XCB_RANDR_NOTIFY) { | 142 | if (xEventType == m_randrBase + XCB_RANDR_NOTIFY) { | ||
145 | handleXRandRNotify(e); | 143 | handleXRandRNotify(e); | ||
146 | } | 144 | } | ||
147 | 145 | | |||
148 | return false; | 146 | return false; | ||
149 | } | 147 | } | ||
150 | 148 | | |||
151 | void XCBEventListener::handleScreenChange(xcb_generic_event_t* e) | 149 | void XCBEventListener::handleScreenChange(xcb_generic_event_t* e) | ||
152 | { | 150 | { | ||
153 | xcb_randr_screen_change_notify_event_t *e2 = | 151 | auto *e2 = reinterpret_cast<xcb_randr_screen_change_notify_event_t*>(e); | ||
broulik: I prefer to keep `*` and `&` even for when using `auto` | |||||
Also, keeping * in some cases matter. For example, int x = 42; const auto foo = &x; // foo has type of int* const *foo = 43; // totally fine const auto *bar = &x; // bar has type of const int* *bar = 43; // compilation error zzag: Also, keeping `*` in some cases matter. For example,
```lang=cpp
int x = 42;
const auto foo =… | |||||
154 | (xcb_randr_screen_change_notify_event_t *) e; | | |||
155 | 152 | | |||
156 | // Only accept notifications for our window | 153 | // Only accept notifications for our window | ||
157 | if (e2->request_window != m_window) { | 154 | if (e2->request_window != m_window) { | ||
158 | return; | 155 | return; | ||
159 | } | 156 | } | ||
160 | 157 | | |||
161 | qCDebug(KSCREEN_XCB_HELPER) << "RRScreenChangeNotify"; | 158 | qCDebug(KSCREEN_XCB_HELPER) << "RRScreenChangeNotify"; | ||
162 | qCDebug(KSCREEN_XCB_HELPER) << "\tWindow:" << e2->request_window; | 159 | qCDebug(KSCREEN_XCB_HELPER) << "\tWindow:" << e2->request_window; | ||
163 | qCDebug(KSCREEN_XCB_HELPER) << "\tRoot:" << e2->root; | 160 | qCDebug(KSCREEN_XCB_HELPER) << "\tRoot:" << e2->root; | ||
164 | qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t) e2->rotation); | 161 | qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t) e2->rotation); | ||
165 | qCDebug(KSCREEN_XCB_HELPER) << "\tSize ID:" << e2->sizeID; | 162 | qCDebug(KSCREEN_XCB_HELPER) << "\tSize ID:" << e2->sizeID; | ||
166 | qCDebug(KSCREEN_XCB_HELPER) << "\tSize: " << e2->width << e2->height; | 163 | qCDebug(KSCREEN_XCB_HELPER) << "\tSize: " << e2->width << e2->height; | ||
167 | qCDebug(KSCREEN_XCB_HELPER) << "\tSizeMM: " << e2->mwidth << e2->mheight; | 164 | qCDebug(KSCREEN_XCB_HELPER) << "\tSizeMM: " << e2->mwidth << e2->mheight; | ||
168 | 165 | | |||
169 | Q_EMIT screenChanged((xcb_randr_rotation_t) e2->rotation, QSize(e2->width, e2->height), QSize(e2->mwidth, e2->mheight)); | 166 | Q_EMIT screenChanged((xcb_randr_rotation_t) e2->rotation, QSize(e2->width, e2->height), QSize(e2->mwidth, e2->mheight)); | ||
170 | Q_EMIT outputsChanged(); | 167 | Q_EMIT outputsChanged(); | ||
171 | } | 168 | } | ||
172 | 169 | | |||
173 | void XCBEventListener::handleXRandRNotify(xcb_generic_event_t* e) | 170 | void XCBEventListener::handleXRandRNotify(xcb_generic_event_t* e) | ||
174 | { | 171 | { | ||
175 | xcb_randr_notify_event_t* | 172 | auto *randrEvent = reinterpret_cast<xcb_randr_notify_event_t*>(e); | ||
176 | randrEvent = reinterpret_cast<xcb_randr_notify_event_t*>(e); | | |||
177 | 173 | | |||
178 | if (randrEvent->subCode == XCB_RANDR_NOTIFY_CRTC_CHANGE) { | 174 | if (randrEvent->subCode == XCB_RANDR_NOTIFY_CRTC_CHANGE) { | ||
179 | xcb_randr_crtc_change_t crtc = randrEvent->u.cc; | 175 | xcb_randr_crtc_change_t crtc = randrEvent->u.cc; | ||
180 | qCDebug(KSCREEN_XCB_HELPER) << "RRNotify_CrtcChange"; | 176 | qCDebug(KSCREEN_XCB_HELPER) << "RRNotify_CrtcChange"; | ||
181 | qCDebug(KSCREEN_XCB_HELPER) << "\tCRTC: " << crtc.crtc; | 177 | qCDebug(KSCREEN_XCB_HELPER) << "\tCRTC: " << crtc.crtc; | ||
182 | qCDebug(KSCREEN_XCB_HELPER) << "\tMode: " << crtc.mode; | 178 | qCDebug(KSCREEN_XCB_HELPER) << "\tMode: " << crtc.mode; | ||
183 | qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t) crtc.rotation); | 179 | qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t) crtc.rotation); | ||
184 | qCDebug(KSCREEN_XCB_HELPER) << "\tGeometry: " << crtc.x << crtc.y << crtc.width << crtc.height; | 180 | qCDebug(KSCREEN_XCB_HELPER) << "\tGeometry: " << crtc.x << crtc.y << crtc.width << crtc.height; | ||
Show All 27 Lines |
auto *e