Changeset View
Changeset View
Standalone View
Standalone View
libinput/connection.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "connection.h" | 20 | #include "connection.h" | ||
21 | #include "context.h" | 21 | #include "context.h" | ||
22 | #include "device.h" | 22 | #include "device.h" | ||
23 | #include "events.h" | 23 | #include "events.h" | ||
24 | | ||||
25 | // TODO: Make it compile also in testing environment | ||||
24 | #ifndef KWIN_BUILD_TESTING | 26 | #ifndef KWIN_BUILD_TESTING | ||
27 | #include "../abstract_wayland_output.h" | ||||
28 | #include "../main.h" | ||||
29 | #include "../platform.h" | ||||
25 | #include "../screens.h" | 30 | #include "../screens.h" | ||
26 | #endif | 31 | #endif | ||
32 | | ||||
27 | #include "../logind.h" | 33 | #include "../logind.h" | ||
28 | #include "../udev.h" | 34 | #include "../udev.h" | ||
29 | #include "libinput_logging.h" | 35 | #include "libinput_logging.h" | ||
30 | 36 | | |||
31 | #include <QDBusMessage> | 37 | #include <QDBusMessage> | ||
32 | #include <QDBusConnection> | 38 | #include <QDBusConnection> | ||
33 | #include <QDBusPendingCall> | 39 | #include <QDBusPendingCall> | ||
34 | #include <QMutexLocker> | 40 | #include <QMutexLocker> | ||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Line(s) | 240 | do { | |||
239 | } | 245 | } | ||
240 | m_eventQueue << event; | 246 | m_eventQueue << event; | ||
241 | } while (true); | 247 | } while (true); | ||
242 | if (wasEmpty && !m_eventQueue.isEmpty()) { | 248 | if (wasEmpty && !m_eventQueue.isEmpty()) { | ||
243 | emit eventsRead(); | 249 | emit eventsRead(); | ||
244 | } | 250 | } | ||
245 | } | 251 | } | ||
246 | 252 | | |||
253 | #ifndef KWIN_BUILD_TESTING | ||||
254 | QPointF devicePointToGlobalPosition(const QPointF &devicePos, const AbstractWaylandOutput *output) | ||||
zzag: Can be `static`. | |||||
255 | { | ||||
256 | using Transform = AbstractWaylandOutput::Transform; | ||||
257 | | ||||
258 | QPointF pos = devicePos; | ||||
259 | // TODO: Do we need to handle the flipped cases differently? | ||||
zzag: Yeah, I think so. | |||||
260 | switch (output->transform()) { | ||||
261 | case Transform::Normal: | ||||
262 | case Transform::Flipped: | ||||
263 | break; | ||||
264 | case Transform::Rotated90: | ||||
265 | case Transform::Flipped90: | ||||
266 | pos = QPointF(output->modeSize().height() - devicePos.y(), devicePos.x()); | ||||
267 | break; | ||||
268 | case Transform::Rotated180: | ||||
269 | case Transform::Flipped180: | ||||
270 | pos = QPointF(output->modeSize().width() - devicePos.x(), | ||||
271 | output->modeSize().height() - devicePos.y()); | ||||
272 | break; | ||||
273 | case Transform::Rotated270: | ||||
274 | case Transform::Flipped270: | ||||
275 | pos = QPointF(devicePos.y(), output->modeSize().width() - devicePos.x()); | ||||
276 | break; | ||||
277 | default: | ||||
278 | Q_UNREACHABLE(); | ||||
279 | } | ||||
280 | return output->geometry().topLeft() + pos / output->scale(); | ||||
281 | } | ||||
282 | #endif | ||||
283 | | ||||
247 | void Connection::processEvents() | 284 | void Connection::processEvents() | ||
248 | { | 285 | { | ||
249 | QMutexLocker locker(&m_mutex); | 286 | QMutexLocker locker(&m_mutex); | ||
250 | while (!m_eventQueue.isEmpty()) { | 287 | while (!m_eventQueue.isEmpty()) { | ||
251 | QScopedPointer<Event> event(m_eventQueue.takeFirst()); | 288 | QScopedPointer<Event> event(m_eventQueue.takeFirst()); | ||
252 | switch (event->type()) { | 289 | switch (event->type()) { | ||
253 | case LIBINPUT_EVENT_DEVICE_ADDED: { | 290 | case LIBINPUT_EVENT_DEVICE_ADDED: { | ||
254 | auto device = new Device(event->nativeDevice()); | 291 | auto device = new Device(event->nativeDevice()); | ||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | |||||
380 | case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { | 417 | case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { | ||
381 | PointerEvent *pe = static_cast<PointerEvent*>(event.data()); | 418 | PointerEvent *pe = static_cast<PointerEvent*>(event.data()); | ||
382 | emit pointerMotionAbsolute(pe->absolutePos(), pe->absolutePos(m_size), pe->time(), pe->device()); | 419 | emit pointerMotionAbsolute(pe->absolutePos(), pe->absolutePos(m_size), pe->time(), pe->device()); | ||
383 | break; | 420 | break; | ||
384 | } | 421 | } | ||
385 | case LIBINPUT_EVENT_TOUCH_DOWN: { | 422 | case LIBINPUT_EVENT_TOUCH_DOWN: { | ||
386 | #ifndef KWIN_BUILD_TESTING | 423 | #ifndef KWIN_BUILD_TESTING | ||
387 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | 424 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | ||
388 | const auto &geo = screens()->geometry(te->device()->screenId()); | 425 | const auto *output = static_cast<AbstractWaylandOutput*>( | ||
389 | emit touchDown(te->id(), geo.topLeft() + te->absolutePos(geo.size()), te->time(), te->device()); | 426 | kwinApp()->platform()->enabledOutputs()[te->device()->screenId()]); | ||
427 | const QPointF globalPos = | ||||
428 | devicePointToGlobalPosition(te->absolutePos(output->modeSize()), | ||||
429 | output); | ||||
430 | emit touchDown(te->id(), globalPos, te->time(), te->device()); | ||||
390 | break; | 431 | break; | ||
391 | #endif | 432 | #endif | ||
392 | } | 433 | } | ||
393 | case LIBINPUT_EVENT_TOUCH_UP: { | 434 | case LIBINPUT_EVENT_TOUCH_UP: { | ||
394 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | 435 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | ||
395 | emit touchUp(te->id(), te->time(), te->device()); | 436 | emit touchUp(te->id(), te->time(), te->device()); | ||
396 | break; | 437 | break; | ||
397 | } | 438 | } | ||
398 | case LIBINPUT_EVENT_TOUCH_MOTION: { | 439 | case LIBINPUT_EVENT_TOUCH_MOTION: { | ||
399 | #ifndef KWIN_BUILD_TESTING | 440 | #ifndef KWIN_BUILD_TESTING | ||
400 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | 441 | TouchEvent *te = static_cast<TouchEvent*>(event.data()); | ||
401 | const auto &geo = screens()->geometry(te->device()->screenId()); | 442 | const auto *output = static_cast<AbstractWaylandOutput*>( | ||
402 | emit touchMotion(te->id(), geo.topLeft() + te->absolutePos(geo.size()), te->time(), te->device()); | 443 | kwinApp()->platform()->enabledOutputs()[te->device()->screenId()]); | ||
444 | const QPointF globalPos = | ||||
445 | devicePointToGlobalPosition(te->absolutePos(output->modeSize()), | ||||
446 | output); | ||||
447 | emit touchMotion(te->id(), globalPos, te->time(), te->device()); | ||||
403 | break; | 448 | break; | ||
404 | #endif | 449 | #endif | ||
405 | } | 450 | } | ||
406 | case LIBINPUT_EVENT_TOUCH_CANCEL: { | 451 | case LIBINPUT_EVENT_TOUCH_CANCEL: { | ||
407 | emit touchCanceled(event->device()); | 452 | emit touchCanceled(event->device()); | ||
408 | break; | 453 | break; | ||
409 | } | 454 | } | ||
410 | case LIBINPUT_EVENT_TOUCH_FRAME: { | 455 | case LIBINPUT_EVENT_TOUCH_FRAME: { | ||
▲ Show 20 Lines • Show All 310 Lines • Show Last 20 Lines |
Can be static.