Changeset View
Changeset View
Standalone View
Standalone View
src/server/seat_interface.cpp
Show All 40 Lines | |||||
41 | #include <functional> | 41 | #include <functional> | ||
42 | 42 | | |||
43 | namespace KWayland | 43 | namespace KWayland | ||
44 | { | 44 | { | ||
45 | 45 | | |||
46 | namespace Server | 46 | namespace Server | ||
47 | { | 47 | { | ||
48 | 48 | | |||
49 | const quint32 SeatInterface::Private::s_version = 4; | 49 | const quint32 SeatInterface::Private::s_version = 5; | ||
50 | const qint32 SeatInterface::Private::s_pointerVersion = 3; | 50 | const qint32 SeatInterface::Private::s_pointerVersion = 5; | ||
51 | const qint32 SeatInterface::Private::s_touchVersion = 3; | 51 | const qint32 SeatInterface::Private::s_touchVersion = 5; | ||
52 | const qint32 SeatInterface::Private::s_keyboardVersion = 4; | 52 | const qint32 SeatInterface::Private::s_keyboardVersion = 5; | ||
53 | 53 | | |||
54 | SeatInterface::Private::Private(SeatInterface *q, Display *display) | 54 | SeatInterface::Private::Private(SeatInterface *q, Display *display) | ||
55 | : Global::Private(display, &wl_seat_interface, s_version) | 55 | : Global::Private(display, &wl_seat_interface, s_version) | ||
56 | , q(q) | 56 | , q(q) | ||
57 | { | 57 | { | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | 60 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
61 | const struct wl_seat_interface SeatInterface::Private::s_interface = { | 61 | const struct wl_seat_interface SeatInterface::Private::s_interface = { | ||
62 | getPointerCallback, | 62 | getPointerCallback, | ||
63 | getKeyboardCallback, | 63 | getKeyboardCallback, | ||
64 | getTouchCallback | 64 | getTouchCallback, | ||
65 | releaseCallback | ||||
65 | }; | 66 | }; | ||
66 | #endif | 67 | #endif | ||
67 | 68 | | |||
68 | SeatInterface::SeatInterface(Display *display, QObject *parent) | 69 | SeatInterface::SeatInterface(Display *display, QObject *parent) | ||
69 | : Global(new Private(this, display), parent) | 70 | : Global(new Private(this, display), parent) | ||
70 | { | 71 | { | ||
71 | Q_D(); | 72 | Q_D(); | ||
72 | connect(this, &SeatInterface::nameChanged, this, | 73 | connect(this, &SeatInterface::nameChanged, this, | ||
Show All 36 Lines | 99 | { | |||
109 | sendName(r); | 110 | sendName(r); | ||
110 | } | 111 | } | ||
111 | 112 | | |||
112 | void SeatInterface::Private::unbind(wl_resource *r) | 113 | void SeatInterface::Private::unbind(wl_resource *r) | ||
113 | { | 114 | { | ||
114 | cast(r)->resources.removeAll(r); | 115 | cast(r)->resources.removeAll(r); | ||
115 | } | 116 | } | ||
116 | 117 | | |||
118 | void SeatInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) | ||||
119 | { | ||||
120 | Q_UNUSED(client) | ||||
121 | wl_resource_destroy(resource); | ||||
122 | } | ||||
123 | | ||||
117 | void SeatInterface::Private::updatePointerButtonSerial(quint32 button, quint32 serial) | 124 | void SeatInterface::Private::updatePointerButtonSerial(quint32 button, quint32 serial) | ||
118 | { | 125 | { | ||
119 | auto it = globalPointer.buttonSerials.find(button); | 126 | auto it = globalPointer.buttonSerials.find(button); | ||
120 | if (it == globalPointer.buttonSerials.end()) { | 127 | if (it == globalPointer.buttonSerials.end()) { | ||
121 | globalPointer.buttonSerials.insert(button, serial); | 128 | globalPointer.buttonSerials.insert(button, serial); | ||
122 | return; | 129 | return; | ||
123 | } | 130 | } | ||
124 | it.value() = serial; | 131 | it.value() = serial; | ||
▲ Show 20 Lines • Show All 328 Lines • ▼ Show 20 Line(s) | 458 | if (!pointer->resource()) { | |||
453 | delete pointer; | 460 | delete pointer; | ||
454 | return; | 461 | return; | ||
455 | } | 462 | } | ||
456 | pointers << pointer; | 463 | pointers << pointer; | ||
457 | if (globalPointer.focus.surface && globalPointer.focus.surface->client() == clientConnection) { | 464 | if (globalPointer.focus.surface && globalPointer.focus.surface->client() == clientConnection) { | ||
458 | // this is a pointer for the currently focused pointer surface | 465 | // this is a pointer for the currently focused pointer surface | ||
459 | globalPointer.focus.pointers << pointer; | 466 | globalPointer.focus.pointers << pointer; | ||
460 | pointer->setFocusedSurface(globalPointer.focus.surface, globalPointer.focus.serial); | 467 | pointer->setFocusedSurface(globalPointer.focus.surface, globalPointer.focus.serial); | ||
468 | pointer->d_func()->sendFrame(); | ||||
461 | if (globalPointer.focus.pointers.count() == 1) { | 469 | if (globalPointer.focus.pointers.count() == 1) { | ||
462 | // got a new pointer | 470 | // got a new pointer | ||
463 | emit q->focusedPointerChanged(pointer); | 471 | emit q->focusedPointerChanged(pointer); | ||
464 | } | 472 | } | ||
465 | } | 473 | } | ||
466 | QObject::connect(pointer, &QObject::destroyed, q, | 474 | QObject::connect(pointer, &QObject::destroyed, q, | ||
467 | [pointer,this] { | 475 | [pointer,this] { | ||
468 | pointers.removeAt(pointers.indexOf(pointer)); | 476 | pointers.removeAt(pointers.indexOf(pointer)); | ||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | |||||
667 | void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QMatrix4x4 &transformation) | 675 | void SeatInterface::setFocusedPointerSurface(SurfaceInterface *surface, const QMatrix4x4 &transformation) | ||
668 | { | 676 | { | ||
669 | Q_D(); | 677 | Q_D(); | ||
670 | if (d->drag.mode == Private::Drag::Mode::Pointer) { | 678 | if (d->drag.mode == Private::Drag::Mode::Pointer) { | ||
671 | // ignore | 679 | // ignore | ||
672 | return; | 680 | return; | ||
673 | } | 681 | } | ||
674 | const quint32 serial = d->display->nextSerial(); | 682 | const quint32 serial = d->display->nextSerial(); | ||
683 | QSet<PointerInterface *> framePointers; | ||||
675 | for (auto it = d->globalPointer.focus.pointers.constBegin(), end = d->globalPointer.focus.pointers.constEnd(); it != end; ++it) { | 684 | for (auto it = d->globalPointer.focus.pointers.constBegin(), end = d->globalPointer.focus.pointers.constEnd(); it != end; ++it) { | ||
676 | (*it)->setFocusedSurface(nullptr, serial); | 685 | (*it)->setFocusedSurface(nullptr, serial); | ||
686 | framePointers << *it; | ||||
677 | } | 687 | } | ||
678 | if (d->globalPointer.focus.surface) { | 688 | if (d->globalPointer.focus.surface) { | ||
679 | disconnect(d->globalPointer.focus.destroyConnection); | 689 | disconnect(d->globalPointer.focus.destroyConnection); | ||
680 | } | 690 | } | ||
681 | d->globalPointer.focus = Private::Pointer::Focus(); | 691 | d->globalPointer.focus = Private::Pointer::Focus(); | ||
682 | d->globalPointer.focus.surface = surface; | 692 | d->globalPointer.focus.surface = surface; | ||
683 | auto p = d->pointersForSurface(surface); | 693 | auto p = d->pointersForSurface(surface); | ||
684 | d->globalPointer.focus.pointers = p; | 694 | d->globalPointer.focus.pointers = p; | ||
685 | if (d->globalPointer.focus.surface) { | 695 | if (d->globalPointer.focus.surface) { | ||
686 | d->globalPointer.focus.destroyConnection = connect(surface, &QObject::destroyed, this, | 696 | d->globalPointer.focus.destroyConnection = connect(surface, &QObject::destroyed, this, | ||
687 | [this] { | 697 | [this] { | ||
688 | Q_D(); | 698 | Q_D(); | ||
689 | d->globalPointer.focus = Private::Pointer::Focus(); | 699 | d->globalPointer.focus = Private::Pointer::Focus(); | ||
690 | emit focusedPointerChanged(nullptr); | 700 | emit focusedPointerChanged(nullptr); | ||
691 | } | 701 | } | ||
692 | ); | 702 | ); | ||
693 | d->globalPointer.focus.offset = QPointF(); | 703 | d->globalPointer.focus.offset = QPointF(); | ||
694 | d->globalPointer.focus.transformation = transformation; | 704 | d->globalPointer.focus.transformation = transformation; | ||
695 | d->globalPointer.focus.serial = serial; | 705 | d->globalPointer.focus.serial = serial; | ||
696 | } | 706 | } | ||
697 | if (p.isEmpty()) { | 707 | if (p.isEmpty()) { | ||
698 | emit focusedPointerChanged(nullptr); | 708 | emit focusedPointerChanged(nullptr); | ||
709 | for (auto p : qAsConst(framePointers)) | ||||
710 | { | ||||
711 | p->d_func()->sendFrame(); | ||||
712 | } | ||||
699 | return; | 713 | return; | ||
700 | } | 714 | } | ||
701 | // TODO: signal with all pointers | 715 | // TODO: signal with all pointers | ||
702 | emit focusedPointerChanged(p.first()); | 716 | emit focusedPointerChanged(p.first()); | ||
703 | for (auto it = p.constBegin(), end = p.constEnd(); it != end; ++it) { | 717 | for (auto it = p.constBegin(), end = p.constEnd(); it != end; ++it) { | ||
704 | (*it)->setFocusedSurface(surface, serial); | 718 | (*it)->setFocusedSurface(surface, serial); | ||
719 | framePointers << *it; | ||||
720 | } | ||||
721 | for (auto p : qAsConst(framePointers)) | ||||
722 | { | ||||
723 | p->d_func()->sendFrame(); | ||||
705 | } | 724 | } | ||
706 | } | 725 | } | ||
707 | 726 | | |||
708 | PointerInterface *SeatInterface::focusedPointer() const | 727 | PointerInterface *SeatInterface::focusedPointer() const | ||
709 | { | 728 | { | ||
710 | Q_D(); | 729 | Q_D(); | ||
711 | if (d->globalPointer.focus.pointers.isEmpty()) { | 730 | if (d->globalPointer.focus.pointers.isEmpty()) { | ||
712 | return nullptr; | 731 | return nullptr; | ||
▲ Show 20 Lines • Show All 589 Lines • ▼ Show 20 Line(s) | 1320 | const bool result = forEachInterface<PointerInterface>(focusedTouchSurface(), d->pointers, | |||
1302 | [this, pos, serial] (PointerInterface *p) { | 1321 | [this, pos, serial] (PointerInterface *p) { | ||
1303 | wl_pointer_send_enter(p->resource(), serial, | 1322 | wl_pointer_send_enter(p->resource(), serial, | ||
1304 | focusedTouchSurface()->resource(), | 1323 | focusedTouchSurface()->resource(), | ||
1305 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | 1324 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | ||
1306 | wl_pointer_send_motion(p->resource(), timestamp(), | 1325 | wl_pointer_send_motion(p->resource(), timestamp(), | ||
1307 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | 1326 | wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); | ||
1308 | 1327 | | |||
1309 | wl_pointer_send_button(p->resource(), serial, timestamp(), BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); | 1328 | wl_pointer_send_button(p->resource(), serial, timestamp(), BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); | ||
1329 | p->d_func()->sendFrame(); | ||||
1310 | } | 1330 | } | ||
1311 | ); | 1331 | ); | ||
1312 | if (!result) { | 1332 | if (!result) { | ||
1313 | return id; | 1333 | return id; | ||
1314 | } | 1334 | } | ||
1315 | #endif | 1335 | #endif | ||
1316 | } | 1336 | } | ||
1317 | 1337 | | |||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |