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
8QT_BEGIN_NAMESPACE
9
10namespace QtWaylandClient {
11
12QWaylandQtKeyExtension::QWaylandQtKeyExtension(QWaylandDisplay *display, uint32_t id)
13 : QtWayland::zqt_key_v1(display->wl_registry(), id, 1)
14 , m_display(display)
15{
16}
17
18void QWaylandQtKeyExtension::zqt_key_v1_key(struct wl_surface *surface,
19 uint32_t time,
20 uint32_t type,
21 uint32_t key,
22 uint32_t modifiers,
23 uint32_t nativeScanCode,
24 uint32_t nativeVirtualKey,
25 uint32_t nativeModifiers,
26 const QString &text,
27 uint32_t autorep,
28 uint32_t count)
29{
30 QList<QWaylandInputDevice *> inputDevices = m_display->inputDevices();
31 if (!surface && inputDevices.isEmpty()) {
32 qWarning(msg: "qt_key_extension: handle_qtkey: No input device");
33 return;
34 }
35
36 QWaylandInputDevice *dev = inputDevices.first();
37
38 auto *win = surface ? QWaylandWindow::fromWlSurface(surface) : nullptr;
39
40 if (!win)
41 win = dev->keyboardFocus();
42
43 if (!win || !win->window()) {
44 qWarning(msg: "qt_key_extension: handle_qtkey: No keyboard focus");
45 return;
46 }
47
48 QWindow *window = win->window();
49 QWindowSystemInterface::handleExtendedKeyEvent(window, timestamp: time, type: QEvent::Type(type), key, modifiers: Qt::KeyboardModifiers(modifiers),
50 nativeScanCode, nativeVirtualKey, nativeModifiers, text,
51 autorep, count);
52}
53
54}
55
56QT_END_NAMESPACE
57

source code of qtwayland/src/client/qwaylandqtkey.cpp