~dandrader/qtmir/stopRaiseSpam

« back to all changes in this revision

Viewing changes to src/platforms/mirserver/qteventfeeder.cpp

  • Committer: Bileto Bot
  • Date: 2016-12-16 08:24:08 UTC
  • mfrom: (569.6.21 miral-qt-integration)
  • Revision ID: ci-train-bot@canonical.com-20161216082408-rjt0z7s1fljnhb0k
First release using MirAL

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <qpa/qplatforminputcontext.h>
27
27
#include <qpa/qplatformintegration.h>
 
28
#include <qpa/qwindowsysteminterface_p.h>
28
29
#include <QGuiApplication>
29
30
#include <private/qguiapplication_p.h>
30
31
#include <QTextCodec>
413
414
                quint32 nativeModifiers,
414
415
                const QString& text, bool autorep, ushort count) override
415
416
    {
 
417
 
 
418
#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0)) || (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
416
419
        QWindowSystemInterface::handleExtendedKeyEvent(window, timestamp, type, key, modifiers,
417
420
                nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
 
421
#else
 
422
        // The version above is the right one, but we have to workaround a FIXME hack in
 
423
        // QWindowSystemInterface::handleShortcutEvent which forcibly sets sync mode from the GUI thread.
 
424
        // Sending an event synchronously from the mir input thread risks a deadlock with the main/GUI thread
 
425
        // from a miral mutex locked by both thread (eg. holding Alt + dragging a window with the the mouse)
 
426
        // See: https://bugreports.qt.io/browse/QTBUG-56274
 
427
        // Bug was introduced by commit c7e5e1d9e01849347a9e59b8285477a20d82002b and fixed by commit
 
428
        // 33d748bb88676b69e596ae77badfeaf5a69a33d1
 
429
        QWindowSystemInterfacePrivate::KeyEvent *e =
 
430
                new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, type, key, modifiers,
 
431
                    nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
 
432
        QWindowSystemInterfacePrivate::postWindowSystemEvent(e);
 
433
#endif
 
434
 
418
435
    }
419
436
 
420
437
    void handleTouchEvent(QWindow *window, ulong timestamp, QTouchDevice *device,
421
438
            const QList<struct QWindowSystemInterface::TouchPoint> &points, Qt::KeyboardModifiers mods) override
422
439
    {
 
440
        // See comment in handleExtendedKeyEvent
 
441
#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0)) || (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
423
442
        QWindowSystemInterface::handleTouchEvent(window, timestamp, device, points, mods);
 
443
#else
 
444
        {
 
445
            if (!points.size()) // Touch events must have at least one point
 
446
                return;
 
447
            QEvent::Type type;
 
448
            QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
 
449
 
 
450
            QWindowSystemInterfacePrivate::TouchEvent *e =
 
451
                    new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, type, device, touchPoints, mods);
 
452
            QWindowSystemInterfacePrivate::postWindowSystemEvent(e);
 
453
        }
 
454
#endif
424
455
    }
425
456
 
426
457
    void handleMouseEvent(ulong timestamp, QPointF relative, QPointF absolute, Qt::MouseButtons buttons,
510
541
 
511
542
    switch (mir_input_event_get_type(iev)) {
512
543
    case mir_input_event_type_key:
513
 
        dispatchKey(iev);
 
544
        dispatchKey(mir_input_event_get_keyboard_event(iev));
514
545
        break;
515
546
    case mir_input_event_type_touch:
516
 
        dispatchTouch(iev);
 
547
        dispatchTouch(mir_input_event_get_touch_event(iev));
517
548
        break;
518
549
    case mir_input_event_type_pointer:
519
 
        dispatchPointer(iev);
 
550
        dispatchPointer(mir_input_event_get_pointer_event(iev));
520
551
    default:
521
552
        break;
522
553
    }
564
595
 
565
596
    return buttons;
566
597
}
567
 
}
 
598
} // namespace
568
599
 
569
 
void QtEventFeeder::dispatchPointer(MirInputEvent const* ev)
 
600
void QtEventFeeder::dispatchPointer(const MirPointerEvent *pev)
570
601
{
571
 
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(std::chrono::nanoseconds(mir_input_event_get_event_time(ev)));
572
 
    auto pev = mir_input_event_get_pointer_event(ev);
 
602
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(
 
603
                std::chrono::nanoseconds(mir_input_event_get_event_time(
 
604
                                             mir_pointer_event_input_event(pev))));
573
605
    auto action = mir_pointer_event_action(pev);
574
606
    qCDebug(QTMIR_MIR_INPUT) << "Received" << qPrintable(mirPointerEventToString(pev));
575
607
 
604
636
    }
605
637
}
606
638
 
607
 
void QtEventFeeder::dispatchKey(MirInputEvent const* event)
 
639
void QtEventFeeder::dispatchKey(const MirKeyboardEvent *kev)
608
640
{
609
 
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(std::chrono::nanoseconds(mir_input_event_get_event_time(event)));
 
641
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(
 
642
                std::chrono::nanoseconds(mir_input_event_get_event_time(
 
643
                                             mir_keyboard_event_input_event(kev))));
610
644
 
611
 
    auto kev = mir_input_event_get_keyboard_event(event);
612
645
    xkb_keysym_t xk_sym = mir_keyboard_event_key_code(kev);
613
646
 
614
647
    // Key modifier and unicode index mapping.
669
702
        mir_keyboard_event_modifiers(kev), text, is_auto_rep);
670
703
}
671
704
 
672
 
void QtEventFeeder::dispatchTouch(MirInputEvent const* event)
 
705
void QtEventFeeder::dispatchTouch(const MirTouchEvent *tev)
673
706
{
674
 
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(std::chrono::nanoseconds(mir_input_event_get_event_time(event)));
 
707
    auto timestamp = qtmir::compressTimestamp<qtmir::Timestamp>(
 
708
                std::chrono::nanoseconds(mir_input_event_get_event_time(
 
709
                                             mir_touch_event_input_event(tev))));
675
710
 
676
711
    tracepoint(qtmirserver, touchEventDispatch_start, std::chrono::nanoseconds(timestamp).count());
677
712
 
678
 
    auto tev = mir_input_event_get_touch_event(event);
679
713
    qCDebug(QTMIR_MIR_INPUT) << "Received" << qPrintable(mirTouchEventToString(tev));
680
714
 
681
715
    // FIXME(loicm) Max pressure is device specific. That one is for the Samsung Galaxy Nexus. That
746
780
    tracepoint(qtmirserver, touchEventDispatch_end, std::chrono::nanoseconds(timestamp).count());
747
781
}
748
782
 
749
 
void QtEventFeeder::start()
750
 
{
751
 
    // not used
752
 
}
753
 
 
754
 
void QtEventFeeder::stop()
755
 
{
756
 
    // not used
757
 
}
758
 
 
759
783
void QtEventFeeder::validateTouches(QWindow *window, ulong timestamp,
760
784
        QList<QWindowSystemInterface::TouchPoint> &touchPoints)
761
785
{