Files
Devin Lin c4fe01beaf Wrap keyboard layouts in KeyboardLayoutDefinition
Currently layouts are created with the KeyboardLayout component. When we
switch to alternate layouts (i.e. numpad, symbols), the Keyboard switches out the
KeyboardLayout completely to the alternate layout's KeyboardLayout.

We currently don't have a "holding" object for a keyboard layout,
preventing us from having a shared TextComposer session between all of
the "sublayouts" within a layout (ex. QWERTY <-> symbols <-> numpad)

This is problematic for CJK because the TextComposer gets reset when we
switch to other pages, like the symbols page.

---

This MR introduces a "KeyboardLayoutDefinition" holding component for
layouts, so that we can retain state within a keyboard layout. In this
case, we keep the TextComposer on the KeyboardLayoutDefinition rather
than the KeyboardLayout so it isn't reset when we switch to other
keyboard pages.

I also replaced the JSON-specified alternate layouts with it now being
specified on the KeyboardLayoutDefinition, which makes things a bit more
centralized.

---

Kind of annoying that I had to do this after porting the layouts, but
this was a big oversight I missed that came up during CJK testing :/
2026-10-25 14:00:43 -04:00

40 lines
1.2 KiB
QML

/*
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick
import org.kde.plasma.keyboard.virtualkeyboard
Loader {
id: root
property string packageId: ""
property string layoutId: ""
property var virtualKeyboardContext: null
readonly property var inputEngine: virtualKeyboardContext ? virtualKeyboardContext.inputEngine : VirtualKeyboard.inputEngine
readonly property var textComposer: item && item.textComposer !== undefined ? item.textComposer : null
function applyLayoutProperties() {
if (!item) {
return;
}
if (item.virtualKeyboardContext !== undefined) {
item.virtualKeyboardContext = virtualKeyboardContext;
}
if (item.layoutId !== undefined) {
item.layoutId = layoutId;
}
if (item.packageId !== undefined) {
item.packageId = packageId;
}
}
onLoaded: applyLayoutProperties()
onVirtualKeyboardContextChanged: applyLayoutProperties()
onPackageIdChanged: applyLayoutProperties()
onLayoutIdChanged: applyLayoutProperties()
}