| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qwaylandqtkey_p.h" |
| 5 | #include "qwaylandinputdevice_p.h" |
| 6 | #include "qwaylanddisplay_p.h" |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace QtWaylandClient { |
| 11 | |
| 12 | QWaylandQtKeyExtension::QWaylandQtKeyExtension(QWaylandDisplay *display, uint32_t id) |
| 13 | : QtWayland::zqt_key_v1(display->wl_registry(), id, 1) |
| 14 | , m_display(display) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | QWaylandQtKeyExtension::~QWaylandQtKeyExtension() |
| 19 | { |
| 20 | zqt_key_v1_destroy(object()); |
| 21 | } |
| 22 | |
| 23 | void QWaylandQtKeyExtension::zqt_key_v1_key(struct wl_surface *surface, |
| 24 | uint32_t time, |
| 25 | uint32_t type, |
| 26 | uint32_t key, |
| 27 | uint32_t modifiers, |
| 28 | uint32_t nativeScanCode, |
| 29 | uint32_t nativeVirtualKey, |
| 30 | uint32_t nativeModifiers, |
| 31 | const QString &text, |
| 32 | uint32_t autorep, |
| 33 | uint32_t count) |
| 34 | { |
| 35 | QList<QWaylandInputDevice *> inputDevices = m_display->inputDevices(); |
| 36 | if (!surface && inputDevices.isEmpty()) { |
| 37 | qWarning(msg: "qt_key_extension: handle_qtkey: No input device" ); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | QWaylandInputDevice *dev = inputDevices.first(); |
| 42 | |
| 43 | auto *win = surface ? QWaylandWindow::fromWlSurface(surface) : nullptr; |
| 44 | |
| 45 | if (!win) |
| 46 | win = dev->keyboardFocus(); |
| 47 | |
| 48 | if (!win || !win->window()) { |
| 49 | qWarning(msg: "qt_key_extension: handle_qtkey: No keyboard focus" ); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | QWindow *window = win->window(); |
| 54 | QWindowSystemInterface::handleExtendedKeyEvent(window, timestamp: time, type: QEvent::Type(type), key, modifiers: Qt::KeyboardModifiers(modifiers), |
| 55 | nativeScanCode, nativeVirtualKey, nativeModifiers, text, |
| 56 | autorep, count); |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | |
| 61 | QT_END_NAMESPACE |
| 62 | |