Changeset View
Changeset View
Standalone View
Standalone View
src/kded/x11eventnotifier-xcb.cpp
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include "x11eventnotifier.h" | 26 | #include "x11eventnotifier.h" | ||
27 | 27 | | |||
28 | #include "x11input.h" | 28 | #include "x11input.h" | ||
29 | #include "x11inputdevice.h" | 29 | #include "x11inputdevice.h" | ||
30 | 30 | | |||
31 | #include <xcb/xcb.h> | 31 | #include <xcb/xcb.h> | ||
32 | #include <xcb/xinput.h> | 32 | #include <xcb/xinput.h> | ||
33 | #include <xcb/randr.h> | | |||
34 | 33 | | |||
35 | namespace Wacom | 34 | namespace Wacom | ||
36 | { | 35 | { | ||
37 | class X11EventNotifierPrivate | 36 | class X11EventNotifierPrivate | ||
38 | { | 37 | { | ||
39 | public: | 38 | public: | ||
40 | xcb_randr_rotation_t currentRotation; | | |||
41 | bool isStarted; | 39 | bool isStarted; | ||
42 | }; | 40 | }; | ||
43 | } | 41 | } | ||
44 | 42 | | |||
45 | using namespace Wacom; | 43 | using namespace Wacom; | ||
46 | 44 | | |||
47 | X11EventNotifier::X11EventNotifier() | 45 | X11EventNotifier::X11EventNotifier() | ||
48 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | 46 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | ||
49 | { | 47 | { | ||
50 | Q_D( X11EventNotifier ); | 48 | Q_D( X11EventNotifier ); | ||
51 | d->currentRotation = XCB_RANDR_ROTATION_ROTATE_0; | | |||
52 | d->isStarted = false; | 49 | d->isStarted = false; | ||
53 | } | 50 | } | ||
54 | 51 | | |||
55 | X11EventNotifier::X11EventNotifier(const X11EventNotifier& notifier) | 52 | X11EventNotifier::X11EventNotifier(const X11EventNotifier& notifier) | ||
56 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | 53 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | ||
57 | { | 54 | { | ||
58 | Q_UNUSED(notifier); | 55 | Q_UNUSED(notifier); | ||
59 | Q_D( X11EventNotifier ); | 56 | Q_D( X11EventNotifier ); | ||
60 | d->currentRotation = XCB_RANDR_ROTATION_ROTATE_0; | | |||
61 | d->isStarted = false; | 57 | d->isStarted = false; | ||
62 | } | 58 | } | ||
63 | 59 | | |||
64 | X11EventNotifier::~X11EventNotifier() | 60 | X11EventNotifier::~X11EventNotifier() | ||
65 | { | 61 | { | ||
66 | delete d_ptr; | 62 | delete d_ptr; | ||
67 | } | 63 | } | ||
68 | 64 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
118 | { | 114 | { | ||
119 | Q_UNUSED(eventType); | 115 | Q_UNUSED(eventType); | ||
120 | Q_UNUSED(result); | 116 | Q_UNUSED(result); | ||
121 | xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message); | 117 | xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message); | ||
122 | xcb_ge_generic_event_t *cookie = reinterpret_cast<xcb_ge_generic_event_t *>(message); | 118 | xcb_ge_generic_event_t *cookie = reinterpret_cast<xcb_ge_generic_event_t *>(message); | ||
123 | 119 | | |||
124 | if (event->response_type == XCB_GE_GENERIC && cookie->event_type == XCB_INPUT_HIERARCHY) { | 120 | if (event->response_type == XCB_GE_GENERIC && cookie->event_type == XCB_INPUT_HIERARCHY) { | ||
125 | handleX11InputEvent(cookie); | 121 | handleX11InputEvent(cookie); | ||
126 | | ||||
127 | } else { | | |||
128 | handleX11ScreenEvent(event); | | |||
129 | } | 122 | } | ||
130 | 123 | | |||
131 | // return QWidget::x11Event(event); | 124 | // return QWidget::x11Event(event); | ||
132 | return false; | 125 | return false; | ||
133 | } | 126 | } | ||
134 | 127 | | |||
135 | 128 | | |||
136 | 129 | | |||
137 | void X11EventNotifier::handleX11InputEvent(xcb_ge_generic_event_t* event) | 130 | void X11EventNotifier::handleX11InputEvent(xcb_ge_generic_event_t* event) | ||
138 | { | 131 | { | ||
139 | xcb_input_hierarchy_event_t *hev = (xcb_input_hierarchy_event_t *) event; | 132 | xcb_input_hierarchy_event_t *hev = (xcb_input_hierarchy_event_t *) event; | ||
140 | 133 | | |||
141 | xcb_input_hierarchy_info_iterator_t iter; | 134 | xcb_input_hierarchy_info_iterator_t iter; | ||
142 | iter.data = reinterpret_cast<xcb_input_hierarchy_info_t*>(hev + 1); | 135 | iter.data = reinterpret_cast<xcb_input_hierarchy_info_t*>(hev + 1); | ||
143 | iter.rem = hev->num_infos; | 136 | iter.rem = hev->num_infos; | ||
144 | iter.index = reinterpret_cast<char*>(iter.data) - reinterpret_cast<char*>(hev); | 137 | iter.index = reinterpret_cast<char*>(iter.data) - reinterpret_cast<char*>(hev); | ||
145 | 138 | | |||
146 | for (; iter.rem; xcb_input_hierarchy_info_next(&iter)) { | 139 | for (; iter.rem; xcb_input_hierarchy_info_next(&iter)) { | ||
147 | if (iter.data->flags & XCB_INPUT_HIERARCHY_MASK_SLAVE_REMOVED) { | 140 | if (iter.data->flags & XCB_INPUT_HIERARCHY_MASK_SLAVE_REMOVED) { | ||
148 | qDebug() << QString::fromLatin1("X11 device with id '%1' removed.").arg(iter.data->deviceid); | 141 | dbgWacom << QString::fromLatin1("X11 device with id '%1' removed.").arg(iter.data->deviceid); | ||
149 | emit tabletRemoved(iter.data->deviceid); | 142 | emit tabletRemoved(iter.data->deviceid); | ||
150 | 143 | | |||
151 | } else if (iter.data->flags & XCB_INPUT_HIERARCHY_MASK_SLAVE_ADDED) { | 144 | } else if (iter.data->flags & XCB_INPUT_HIERARCHY_MASK_SLAVE_ADDED) { | ||
152 | qDebug() << QString::fromLatin1("X11 device with id '%1' added.").arg(iter.data->deviceid); | 145 | dbgWacom << QString::fromLatin1("X11 device with id '%1' added.").arg(iter.data->deviceid); | ||
153 | 146 | | |||
154 | X11InputDevice device (iter.data->deviceid, QLatin1String("Unknown X11 Device")); | 147 | X11InputDevice device (iter.data->deviceid, QLatin1String("Unknown X11 Device")); | ||
155 | 148 | | |||
156 | if (device.isOpen() && device.isTabletDevice()) { | 149 | if (device.isOpen() && device.isTabletDevice()) { | ||
157 | qDebug() << QString::fromLatin1("Wacom tablet device with X11 id '%1' added.").arg(iter.data->deviceid); | 150 | dbgWacom << QString::fromLatin1("Wacom tablet device with X11 id '%1' added.").arg(iter.data->deviceid); | ||
158 | emit tabletAdded(iter.data->deviceid); | 151 | emit tabletAdded(iter.data->deviceid); | ||
159 | } | 152 | } | ||
160 | } | 153 | } | ||
161 | } | 154 | } | ||
162 | } | 155 | } | ||
163 | 156 | | |||
164 | 157 | | |||
165 | 158 | | |||
166 | void X11EventNotifier::handleX11ScreenEvent(xcb_generic_event_t* event) | | |||
167 | { | | |||
168 | Q_D( X11EventNotifier ); | | |||
169 | | ||||
170 | const xcb_query_extension_reply_t* reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id); | | |||
171 | | ||||
172 | if (event->response_type == reply->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { | | |||
173 | xcb_randr_screen_change_notify_event_t* ev = reinterpret_cast<xcb_randr_screen_change_notify_event_t*>(event); | | |||
174 | auto old_r = d->currentRotation; | | |||
175 | d->currentRotation = static_cast<xcb_randr_rotation_t>(ev->rotation); | | |||
176 | | ||||
177 | if (old_r != d->currentRotation) { | | |||
178 | ScreenRotation newRotation = ScreenRotation::NONE; | | |||
179 | | ||||
180 | switch (d->currentRotation) { | | |||
181 | case XCB_RANDR_ROTATION_ROTATE_0: | | |||
182 | newRotation = ScreenRotation::NONE; | | |||
183 | break; | | |||
184 | case XCB_RANDR_ROTATION_ROTATE_90: | | |||
185 | newRotation = ScreenRotation::CCW; | | |||
186 | break; | | |||
187 | case XCB_RANDR_ROTATION_ROTATE_180: | | |||
188 | newRotation = ScreenRotation::HALF; | | |||
189 | break; | | |||
190 | case XCB_RANDR_ROTATION_ROTATE_270: | | |||
191 | newRotation = ScreenRotation::CW; | | |||
192 | break; | | |||
193 | default: | | |||
194 | errWacom << QString::fromLatin1("FIXME: Unsupported screen rotation '%1'.").arg(d->currentRotation); | | |||
195 | return; | | |||
196 | } | | |||
197 | | ||||
198 | qDebug() << QString::fromLatin1("XRandr screen rotation detected: '%1'.").arg(newRotation.key()); | | |||
199 | emit screenRotated(newRotation); | | |||
200 | } | | |||
201 | } | | |||
202 | } | | |||
203 | | ||||
204 | | ||||
205 | | ||||
206 | int X11EventNotifier::registerForNewDeviceEvent(xcb_connection_t* conn) | 159 | int X11EventNotifier::registerForNewDeviceEvent(xcb_connection_t* conn) | ||
207 | { | 160 | { | ||
208 | char buf[sizeof(xcb_input_event_mask_t) + sizeof(uint32_t)]; | 161 | char buf[sizeof(xcb_input_event_mask_t) + sizeof(uint32_t)]; | ||
209 | 162 | | |||
210 | xcb_input_event_mask_t* evmask = reinterpret_cast<xcb_input_event_mask_t*>(buf); | 163 | xcb_input_event_mask_t* evmask = reinterpret_cast<xcb_input_event_mask_t*>(buf); | ||
211 | evmask->deviceid = 0; | 164 | evmask->deviceid = 0; | ||
212 | evmask->mask_len = 1; | 165 | evmask->mask_len = 1; | ||
213 | 166 | | |||
Show All 18 Lines |