Changeset View
Changeset View
Standalone View
Standalone View
src/kded/x11eventnotifier-xlib.cpp
Show All 36 Lines | |||||
37 | #include <X11/extensions/XInput.h> | 37 | #include <X11/extensions/XInput.h> | ||
38 | #include <X11/extensions/XInput2.h> | 38 | #include <X11/extensions/XInput2.h> | ||
39 | 39 | | |||
40 | namespace Wacom | 40 | namespace Wacom | ||
41 | { | 41 | { | ||
42 | class X11EventNotifierPrivate | 42 | class X11EventNotifierPrivate | ||
43 | { | 43 | { | ||
44 | public: | 44 | public: | ||
45 | xcb_randr_rotation_t currentRotation; | | |||
46 | bool isStarted; | 45 | bool isStarted; | ||
47 | }; | 46 | }; | ||
48 | } | 47 | } | ||
49 | 48 | | |||
50 | using namespace Wacom; | 49 | using namespace Wacom; | ||
51 | 50 | | |||
52 | X11EventNotifier::X11EventNotifier() | 51 | X11EventNotifier::X11EventNotifier() | ||
53 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | 52 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | ||
54 | { | 53 | { | ||
55 | Q_D( X11EventNotifier ); | 54 | Q_D( X11EventNotifier ); | ||
56 | d->currentRotation = XCB_RANDR_ROTATION_ROTATE_0; | | |||
57 | d->isStarted = false; | 55 | d->isStarted = false; | ||
58 | } | 56 | } | ||
59 | 57 | | |||
60 | X11EventNotifier::X11EventNotifier(const X11EventNotifier& notifier) | 58 | X11EventNotifier::X11EventNotifier(const X11EventNotifier& notifier) | ||
61 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | 59 | : EventNotifier(NULL), QAbstractNativeEventFilter(), d_ptr(new X11EventNotifierPrivate) | ||
62 | { | 60 | { | ||
63 | Q_UNUSED(notifier); | 61 | Q_UNUSED(notifier); | ||
64 | Q_D( X11EventNotifier ); | 62 | Q_D( X11EventNotifier ); | ||
65 | d->currentRotation = XCB_RANDR_ROTATION_ROTATE_0; | | |||
66 | d->isStarted = false; | 63 | d->isStarted = false; | ||
67 | } | 64 | } | ||
68 | 65 | | |||
69 | X11EventNotifier::~X11EventNotifier() | 66 | X11EventNotifier::~X11EventNotifier() | ||
70 | { | 67 | { | ||
71 | delete d_ptr; | 68 | delete d_ptr; | ||
72 | } | 69 | } | ||
73 | 70 | | |||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 120 | { | |||
125 | Q_UNUSED(result); | 122 | Q_UNUSED(result); | ||
126 | 123 | | |||
127 | xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message); | 124 | xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message); | ||
128 | xcb_ge_generic_event_t *cookie = reinterpret_cast<xcb_ge_generic_event_t *>(message); | 125 | xcb_ge_generic_event_t *cookie = reinterpret_cast<xcb_ge_generic_event_t *>(message); | ||
129 | 126 | | |||
130 | if (event->response_type == XCB_GE_GENERIC && cookie->event_type == XI_HierarchyChanged) { | 127 | if (event->response_type == XCB_GE_GENERIC && cookie->event_type == XI_HierarchyChanged) { | ||
131 | // handleX11InputEvent(cookie); | 128 | // handleX11InputEvent(cookie); | ||
132 | } else { | 129 | } else { | ||
133 | handleX11ScreenEvent(event); | 130 | // handleX11ScreenEvent(event); | ||
134 | } | 131 | } | ||
135 | 132 | | |||
136 | // return QWidget::x11Event(event); | 133 | // return QWidget::x11Event(event); | ||
137 | return false; | 134 | return false; | ||
138 | } | 135 | } | ||
139 | 136 | | |||
140 | 137 | | |||
141 | 138 | | |||
142 | // Handle plug/unplug events | 139 | // Handle plug/unplug events | ||
143 | void X11EventNotifier::handleX11InputEvent(xcb_ge_generic_event_t* event) | 140 | void X11EventNotifier::handleX11InputEvent(xcb_ge_generic_event_t* event) | ||
144 | { | 141 | { | ||
145 | Q_UNUSED(event) | 142 | Q_UNUSED(event) | ||
146 | // Sadly there does not seem to be a way to use this functionality :( | 143 | // Sadly there does not seem to be a way to use this functionality :( | ||
147 | } | 144 | } | ||
148 | 145 | | |||
149 | 146 | | |||
150 | 147 | | |||
151 | void X11EventNotifier::handleX11ScreenEvent(xcb_generic_event_t* event) | | |||
152 | { | | |||
153 | Q_D( X11EventNotifier ); | | |||
154 | | ||||
155 | const xcb_query_extension_reply_t* reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id); | | |||
156 | | ||||
157 | if (event->response_type == reply->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { | | |||
158 | xcb_randr_screen_change_notify_event_t* ev = reinterpret_cast<xcb_randr_screen_change_notify_event_t*>(event); | | |||
159 | auto old_r = d->currentRotation; | | |||
160 | d->currentRotation = static_cast<xcb_randr_rotation_t>(ev->rotation); | | |||
161 | | ||||
162 | if (old_r != d->currentRotation) { | | |||
163 | ScreenRotation newRotation = ScreenRotation::NONE; | | |||
164 | | ||||
165 | switch (d->currentRotation) { | | |||
166 | case XCB_RANDR_ROTATION_ROTATE_0: | | |||
167 | newRotation = ScreenRotation::NONE; | | |||
168 | break; | | |||
169 | case XCB_RANDR_ROTATION_ROTATE_90: | | |||
170 | newRotation = ScreenRotation::CCW; | | |||
171 | break; | | |||
172 | case XCB_RANDR_ROTATION_ROTATE_180: | | |||
173 | newRotation = ScreenRotation::HALF; | | |||
174 | break; | | |||
175 | case XCB_RANDR_ROTATION_ROTATE_270: | | |||
176 | newRotation = ScreenRotation::CW; | | |||
177 | break; | | |||
178 | default: | | |||
179 | errWacom << QString::fromLatin1("FIXME: Unsupported screen rotation '%1'.").arg(d->currentRotation); | | |||
180 | return; | | |||
181 | } | | |||
182 | | ||||
183 | qDebug() << QString::fromLatin1("XRandr screen rotation detected: '%1'.").arg(newRotation.key()); | | |||
184 | emit screenRotated(newRotation); | | |||
185 | } | | |||
186 | } | | |||
187 | } | | |||
188 | | ||||
189 | | ||||
190 | | ||||
191 | int X11EventNotifier::registerForNewDeviceEvent(xcb_connection_t* conn) | 148 | int X11EventNotifier::registerForNewDeviceEvent(xcb_connection_t* conn) | ||
192 | { | 149 | { | ||
193 | // This is already done by xcb plugin with more flags, doing this ourselves | 150 | // This is already done by xcb plugin with more flags, doing this ourselves | ||
194 | // will break Qt's xrandr functionality because connection is shared with Qt. | 151 | // will break Qt's xrandr functionality because connection is shared with Qt. | ||
195 | // TODO: uncomment this again when we use our private connection. | 152 | // TODO: uncomment this again when we use our private connection. | ||
196 | #if 0 | 153 | #if 0 | ||
197 | //register RandR events | 154 | //register RandR events | ||
198 | int rrmask = XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE; | 155 | int rrmask = XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE; | ||
199 | 156 | | |||
200 | xcb_randr_select_input(conn, QX11Info::appRootWindow(), 0); | 157 | xcb_randr_select_input(conn, QX11Info::appRootWindow(), 0); | ||
201 | xcb_randr_select_input(conn, QX11Info::appRootWindow(), rrmask); | 158 | xcb_randr_select_input(conn, QX11Info::appRootWindow(), rrmask); | ||
202 | #endif | 159 | #endif | ||
203 | 160 | | |||
204 | return 0; | 161 | return 0; | ||
205 | } | 162 | } |