Handling key events in Wayland compositor (IviApplication)
-
I am working on this IviApplication example on Ubuntu 22.04 desktop. I am using Qt5.15.2.
https://doc.qt.io/qt-6.5/qtwaylandcompositor-ivi-compositor-example.html
Example source code:
https://code.qt.io/cgit/qt/qtwayland.git/tree/examples/wayland/ivi-compositor?h=5.15I successfully run it. I can see two programs running on the left and right area.
By adding onFocusChanged and Keys.onReleased signal handlers to the ShellSurfaceItem, I can see the program getting focus when I mouse-click on its area and the program getting key events when I press keyboard.
My question is how to move focus from one program to another by using keyboard? It is essential on a device without touch screen.
I tried the WaylandSeat but always got error no matter where I put it. The QML engine cannot create it.Thank you for your help.
-
Answering my own question...
- Pass WaylandCompositor's property - defaultSeat into C++ as QWaylandSeat*.
https://doc.qt.io/archives/qt-5.15/qml-qtwayland-compositor-waylandcompositor.html#defaultSeat-prop
WaylandCompositor { id: iCompositor Component.onCompleted: { CppHelper.setDefaultWaylandSeat( iCompositor.defaultSeat ); } }
-
Use QWaylandSeat's setKeyboardFocus(), which takes QWaylandSurface*.
https://doc.qt.io/archives/qt-5.15/qwaylandseat.html#setKeyboardFocus -
QWaylandSurface* can be found in the onIviSurfaceCreated() as iviSurface. You can pass it into C++.
IviApplication { onIviSurfaceCreated: { var surfaceArea = iviSurface.iviId === 1337 ? leftArea : rightArea; var item = chromeComponent.createObject(surfaceArea, { "shellSurface": iviSurface } ); item.handleResized(); // Pass QWaylandSurface* into C++. CppHelper.registerIviSurface( iviSurface ); } }
- The signal keyboardFocusChanged can be used to observe the change.
https://doc.qt.io/archives/qt-5.15/qwaylandseat.html#keyboardFocusChanged
However, setKeyboardFocus() doesn't work very well. I do get the signal keyboard focus changed, but the focus jump back to the original window if I actually press a keyboard key.
- Pass WaylandCompositor's property - defaultSeat into C++ as QWaylandSeat*.
-
H Horatio has marked this topic as solved