Compare commits
12
Commits
cfea9ece99
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23e957660f | ||
|
|
5e4d4051f3 | ||
|
|
032fbd8ba4 | ||
|
|
ac5f43ca5f | ||
|
|
b94463a277 | ||
|
|
b50667e508 | ||
|
|
441c1d615b | ||
|
|
b745e9da1b | ||
|
|
499e5ee76e | ||
|
|
6164839886 | ||
|
|
daab2fe0ab | ||
|
|
cef7d384bb |
@@ -0,0 +1,19 @@
|
||||
# Audit — 2026-10-14
|
||||
|
||||
Open items only; fixed ones are in the history (`3576dd8`..`6ff86fb`).
|
||||
|
||||
## Medium
|
||||
|
||||
1. **Fake input can't type characters missing from the keymap.** `KWinFakeInput::typeText` (`src/backend/KWinFakeInput.cpp`) sends keysyms, and KWin has to find each one in the active keymap. Probably all of these do nothing when no text field is focused: long-press alternates (ť on a US keymap) and template symbols missing from the layout. Nothing tells the user it failed. A fix likely needs a temporary keymap (e.g. the virtual-keyboard protocol).
|
||||
|
||||
## Low
|
||||
|
||||
2. **Hold-keys caps lock is tracked locally.** `HardwareKeys::m_capsLock` toggles on its own, so a hardware Caps Lock (or a missed event) puts the shown state out of sync. The window never has keyboard focus, so it gets no modifier events to read the real state from.
|
||||
|
||||
## Untested
|
||||
|
||||
Fixed without automated tests; check on a live KWin session:
|
||||
|
||||
- Focus moving from field to field and deactivate ordering (`KWinInputMethod`)
|
||||
- `org.kde.keyboard` appearing after startup or KWin restarting (`SystemLayouts`)
|
||||
- Fake-input version checks on a KWin older than fake-input v6 (`KWinFakeInput`)
|
||||
+1
-1
@@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
find_package(Qt6 6.8 REQUIRED COMPONENTS Gui Quick Widgets Test DBus WaylandClient)
|
||||
find_package(LayerShellQt REQUIRED)
|
||||
find_package(KF6WindowSystem REQUIRED)
|
||||
find_package(KF6Config REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(XKB REQUIRED IMPORTED_TARGET xkbcommon)
|
||||
pkg_check_modules(WAYLAND REQUIRED IMPORTED_TARGET wayland-client)
|
||||
|
||||
@@ -8,11 +8,14 @@ iPad-style floating on-screen keyboard for Plasma Wayland. Qt 6, C++ core, QML U
|
||||
- "Hold Keys" (⚙): keys stay down while touched, like a hardware keyboard (games, Shift+click, system key repeat); modifiers are plain keys, dead keys compose in the app; touch conveniences off
|
||||
- Letters follow the system keyboard layout; the globe key switches it
|
||||
- Auto-capitalization, double-space → ". " (both optional, ⚙ on the bottom bar), backspace repeat → word delete
|
||||
- Long-press space = trackpad; slide from `.?123` onto a symbol and release
|
||||
- Compact (iPad) or full (iPad Pro) keyboard: number row, punctuation, tab, caps lock, ctrl/alt/super, dead keys
|
||||
- Slide sideways on space to move the cursor; long-press space = trackpad (lines too); slide from `.?123` onto a symbol and release
|
||||
- Compact (iPad) or full (iPad Pro) keyboard: number row, punctuation, tab, caps lock, ctrl/alt/super/alt gr, dead keys
|
||||
- Ctrl/Alt/Super stick like shift (tap, double-tap, hold) and turn keys into shortcuts; a tapped or held shift joins them (Shift+F5, Shift+Tab, Shift+arrows), auto-shift and caps lock don't
|
||||
- Alt Gr (right of space in full mode) types the keymap's AltGr symbols (sk: Alt Gr+J = '), sticky like the others
|
||||
- Optional PC key blocks: function row, navigation (ins/home/pg up, del/end/pg dn, arrows), numeric keypad; any mix, typing keys included (⚙)
|
||||
- Floating: drag the bottom bar, resize from the corner; geometry is remembered per screen
|
||||
- "Shrink to Button" (⚙): ⌨ leaves just itself as a see-through floating button (drag it anywhere); tap it for the keyboard back, around the button and kept on screen
|
||||
- Follows Plasma's virtual keyboard setting (tray toggle): off never pops up on focus, the default only after touch or a pen; "Always Show" and D-Bus `Show`/`Toggle` still show it
|
||||
- See-through background (opacity slider in ⚙) with optional blur behind it (KWin's blur effect)
|
||||
|
||||
## Build & test
|
||||
@@ -22,18 +25,21 @@ cmake -B build -G Ninja && cmake --build build
|
||||
ctest --test-dir build
|
||||
```
|
||||
|
||||
Needs Qt ≥ 6.8 (Quick, WaylandClient, DBus, Test), LayerShellQt, KF6 WindowSystem, xkbcommon, wayland-protocols.
|
||||
Needs Qt ≥ 6.8 (Quick, WaylandClient, DBus, Test), KF6 WindowSystem, KF6 Config, xkbcommon, wayland-protocols.
|
||||
|
||||
## Run
|
||||
|
||||
KWin only offers the input-method protocol to the process it launches itself.
|
||||
KWin offers the input-method protocol and fake input (held keys, shortcuts, typing outside text fields) to the keyboard it launches itself, so launch sloposk through KWin.
|
||||
|
||||
| Where | How |
|
||||
|---|---|
|
||||
| Nested session (safe) | `kwin_wayland --no-lockscreen --socket sloposk-dev --width 1400 --height 900 --inputmethod $PWD/build/src/sloposk kwrite` |
|
||||
| Desktop | `cmake --install build --prefix ~/.local`, then System Settings → Keyboard → Virtual Keyboard → **sloposk** |
|
||||
| Desktop, from the build | `ln -s $PWD/build/src/org.sloposk.keyboard.desktop ~/.local/share/applications/`, then pick **sloposk** as above |
|
||||
| UI only | `build/src/sloposk` (stays visible, types nowhere) |
|
||||
|
||||
Started any other way (e.g. `kioclient exec`), KWin grants neither protocol; the ⚙ panel lists what's missing.
|
||||
|
||||
Show/hide, e.g. from a global shortcut: `qdbus org.sloposk.Keyboard /Keyboard org.sloposk.Keyboard.Toggle`
|
||||
|
||||
Dev hooks: `SLOPOSK_AUTOTYPE=text` commits on focus; `SLOPOSK_SCREENSHOT=file.png` saves the window and quits.
|
||||
@@ -42,7 +48,7 @@ Dev hooks: `SLOPOSK_AUTOTYPE=text` commits on focus; `SLOPOSK_SCREENSHOT=file.pn
|
||||
|
||||
Letters come from the system keymap (what KWin sends to every client): its Q/A/Z rows become the three letter rows. Letters elsewhere, e.g. Slovak ľščťž on the number row, become long-press alternates. The globe key switches the system layout over `org.kde.keyboard`, so the physical keyboard follows.
|
||||
|
||||
In full mode every typing key comes from the keymap (number row, `[ ] \ ; ' , . /` or the layout's equivalents), with the shifted symbol shown above. Dead keys compose with the locale's XKB compose table.
|
||||
In full mode every typing key comes from the keymap (number row, `[ ] \ ; ' , . /` or the layout's equivalents), with the shifted symbol shown above (and flickable); letters, whose shift only capitalizes, show their AltGr symbol instead. Dead keys compose with the locale's XKB compose table.
|
||||
|
||||
Everything else is `layouts/template.json`; `~/.local/share/sloposk/template.json` replaces it.
|
||||
|
||||
@@ -55,7 +61,7 @@ Everything else is `layouts/template.json`; `~/.local/share/sloposk/template.jso
|
||||
- `keysym`: sends the XKB keysym named by `keysym` (`Home`, `F5`, `Left`...) on press; `repeat` auto-repeats while held
|
||||
- `letters`: the keymap's letters in row `row` (0–2), with `flicks` handed out left to right
|
||||
- `keys`: every typing key in keymap row `row` (0 = number row … 3 = bottom)
|
||||
- `modifier`: `"modifier": "ctrl" | "alt" | "super"`; `capslock`
|
||||
- `modifier`: `"modifier": "ctrl" | "alt" | "super" | "altgr"`; `capslock`
|
||||
- Layer `full`: rows used instead of `rows` in full-keyboard mode
|
||||
- `stretch`: the key grows so its row is as wide as the layer's widest (letter counts vary by layout)
|
||||
- Top-level `alternates`: long-press choices per letter, after the keymap's own
|
||||
@@ -73,7 +79,7 @@ input/ touch → PointerTracker gestures → KeyboardController rules
|
||||
engine/ key output → text ops (DirectEngine; prediction/swipe later)
|
||||
backend/ text ops → compositor (KWin input-method-v1, or fake input with no text field); the compositor's keymap
|
||||
layout/ template JSON + keymap letters → Layout → LayoutModel (geometry, hit testing)
|
||||
window/ floating layer-shell placement, visibility, saved geometry
|
||||
window/ floating window (KWin rule: on top, no focus), visibility, saved geometry
|
||||
app/ D-Bus control and system layouts, dev hooks
|
||||
settings/ persisted user preferences
|
||||
```
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
[Desktop Entry]
|
||||
Name=sloposk
|
||||
Comment=iPad-style floating on-screen keyboard
|
||||
Exec=sloposk
|
||||
Exec=@SLOPOSK_EXEC@
|
||||
Type=Application
|
||||
Icon=input-keyboard-virtual
|
||||
NoDisplay=true
|
||||
X-KDE-Wayland-VirtualKeyboard=true
|
||||
# Key events for windows without a text field (fake input is restricted).
|
||||
# Key events for windows without a text field and held keys (fake input is
|
||||
# restricted). KWin matches Exec by absolute path, so it must not be bare.
|
||||
X-KDE-Wayland-Interfaces=org_kde_kwin_fake_input
|
||||
@@ -109,7 +109,7 @@
|
||||
{"type": "modifier", "modifier": "alt", "label": "alt", "width": 1.25},
|
||||
{"type": "globe"},
|
||||
{"type": "space", "width": 6, "stretch": true},
|
||||
{"type": "modifier", "modifier": "alt", "label": "alt", "width": 1.25},
|
||||
{"type": "modifier", "modifier": "altgr", "label": "alt gr", "width": 1.25},
|
||||
{"type": "layer", "label": ".?123", "target": "numbers", "width": 1.25},
|
||||
{"type": "dismiss"}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import QtQuick
|
||||
|
||||
// On/off button in the grab bar, highlighted while on.
|
||||
// Child items form the icon and should use `foreground` as their color.
|
||||
Item {
|
||||
id: toggle
|
||||
|
||||
required property string label
|
||||
property bool checked: false
|
||||
readonly property color foreground: checked ? Theme.accentText : (tap.pressed ? Theme.text : Theme.handle)
|
||||
default property alias icon: iconArea.data
|
||||
signal toggled(bool checked)
|
||||
|
||||
implicitWidth: 34
|
||||
implicitHeight: 22
|
||||
Accessible.role: Accessible.CheckBox
|
||||
Accessible.name: label
|
||||
Accessible.checked: checked
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
width: 30
|
||||
height: 20
|
||||
radius: 5
|
||||
color: Theme.accent
|
||||
visible: toggle.checked
|
||||
}
|
||||
|
||||
Item {
|
||||
id: iconArea
|
||||
anchors.centerIn: parent
|
||||
width: 20
|
||||
height: 14
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
id: tap
|
||||
onTapped: toggle.toggled(!toggle.checked)
|
||||
}
|
||||
}
|
||||
+7
-11
@@ -1,17 +1,19 @@
|
||||
import QtQuick
|
||||
|
||||
// The grab bar under the floating keyboard. Emits how far it was dragged;
|
||||
// moving the window is up to the owner.
|
||||
// Grab bar below the keyboard. Only emits dragStarted(); the parent starts
|
||||
// the window manager's move (works for mouse and touch).
|
||||
Item {
|
||||
id: handle
|
||||
|
||||
signal moved(real dx, real dy)
|
||||
// Set smaller when the bar's buttons take up more width.
|
||||
property real pillWidth: 120
|
||||
signal dragStarted()
|
||||
|
||||
implicitHeight: 22
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
width: 120
|
||||
width: handle.pillWidth
|
||||
height: 5
|
||||
radius: height / 2
|
||||
color: Theme.handle
|
||||
@@ -19,12 +21,6 @@ Item {
|
||||
|
||||
DragHandler {
|
||||
target: null
|
||||
// The window follows the pointer, so the pointer stays near its press
|
||||
// position in window coordinates: measure each step from there.
|
||||
onCentroidChanged: {
|
||||
if (active)
|
||||
handle.moved(centroid.scenePosition.x - centroid.scenePressPosition.x,
|
||||
centroid.scenePosition.y - centroid.scenePressPosition.y)
|
||||
}
|
||||
onActiveChanged: if (active) handle.dragStarted()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import QtQuick
|
||||
|
||||
// Button shown in place of the keyboard while it is collapsed. Semi-transparent
|
||||
// so it covers less. Tap emits tapped() (expand); drag emits dragStarted() and
|
||||
// the parent starts the window manager's move.
|
||||
Item {
|
||||
id: button
|
||||
|
||||
signal tapped()
|
||||
signal dragStarted()
|
||||
|
||||
opacity: 0.6
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: qsTr("Show Keyboard")
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: Theme.keyRadius
|
||||
color: tap.pressed ? Theme.characterKey : Theme.functionKey
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "⌨"
|
||||
font.pixelSize: button.height * 0.4
|
||||
color: Theme.text
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
id: tap
|
||||
// Set during a drag, so the release that ends the drag isn't treated as a tap.
|
||||
property bool moved: false
|
||||
onPressedChanged: if (pressed) moved = false
|
||||
onTapped: if (!moved) button.tapped()
|
||||
}
|
||||
|
||||
DragHandler {
|
||||
target: null
|
||||
onActiveChanged: {
|
||||
if (!active)
|
||||
return;
|
||||
tap.moved = true;
|
||||
button.dragStarted();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -30,9 +30,9 @@ Item {
|
||||
return modifierModes[modifier] ?? KeyboardController.Off
|
||||
return KeyboardController.Off
|
||||
}
|
||||
// Shift shows locking with its glyph; the others turn accent-coloured.
|
||||
// Accent color for locked modifiers. Shift is excluded: its glyph shows the lock.
|
||||
readonly property bool locked: latch === KeyboardController.Locked && keyType !== "shift"
|
||||
// Character keys darken when pressed; function keys lighten (as on iPad).
|
||||
// Light background: character keys at rest, function keys while pressed or latched (as on iPad).
|
||||
readonly property bool lit: (isCharacter !== pressed) || latch !== KeyboardController.Off
|
||||
|
||||
readonly property var defaultGlyphs: ({
|
||||
@@ -46,7 +46,7 @@ Item {
|
||||
return ["⇧", "⬆", "⇪"][shiftMode]
|
||||
return label !== "" ? label : (defaultGlyphs[keyType] ?? "")
|
||||
}
|
||||
// Count code points, not UTF-16 units, so emoji glyphs aren't treated as words.
|
||||
// Multi-character label (e.g. "return"). Counts code points, not UTF-16 units, so an emoji counts as one.
|
||||
readonly property bool isWord: [...displayLabel].length > 1 && !isCharacter
|
||||
|
||||
x: keyX
|
||||
|
||||
@@ -4,7 +4,18 @@ import Sloposk
|
||||
KeyboardSurface {
|
||||
id: surface
|
||||
|
||||
// Window-relative rect of the first key of `type`; empty if there is none.
|
||||
function keyRect(type) {
|
||||
for (let i = 0; i < keys.count; ++i) {
|
||||
const key = keys.itemAt(i);
|
||||
if (key?.keyType === type)
|
||||
return key.mapToItem(null, 0, 0, key.width, key.height);
|
||||
}
|
||||
return Qt.rect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: keys
|
||||
model: surface.model
|
||||
delegate: Key {
|
||||
shiftMode: surface.controller ? surface.controller.shiftMode : KeyboardController.Off
|
||||
|
||||
+49
-10
@@ -7,31 +7,45 @@ Window {
|
||||
required property LayoutModel layoutModel
|
||||
required property KeyboardController controller
|
||||
required property Settings settings
|
||||
required property Diagnostics diagnostics
|
||||
property var placement: null // FloatingWindow, set from C++
|
||||
property var collapse: null // CollapseController, set from C++
|
||||
readonly property bool collapsed: collapse?.collapsed ?? false
|
||||
property bool settingsOpen: false
|
||||
// Height of the key area, for C++ keeping key sizes when rows change.
|
||||
// Read by C++ to keep key size constant when rows are added or removed.
|
||||
readonly property real keysHeight: keyboard.height
|
||||
|
||||
// Transparent room above the keyboard for long-press popups on the top row.
|
||||
// Transparent space above the keyboard for the top row's long-press popups.
|
||||
readonly property real popupMargin: 90
|
||||
// Outside this, input passes through to whatever is below the window.
|
||||
readonly property rect inputRegion: keyboard.alternates.open
|
||||
// Input outside this rect goes to the window underneath.
|
||||
readonly property rect inputRegion: collapsed
|
||||
? Qt.rect(floatingButton.x, floatingButton.y, floatingButton.width, floatingButton.height)
|
||||
: keyboard.alternates.open
|
||||
? Qt.rect(0, 0, width, height)
|
||||
: Qt.rect(panel.x, panel.y, panel.width, panel.height)
|
||||
// Empty when nothing shows through, so the compositor skips the blur.
|
||||
readonly property rect blurRegion: settings.blurBackground && settings.backgroundOpacity < 1
|
||||
// Empty (no blur) when collapsed, blur is off, or the background is opaque.
|
||||
readonly property rect blurRegion: !collapsed && settings.blurBackground && settings.backgroundOpacity < 1
|
||||
? Qt.rect(panel.x, panel.y, panel.width, panel.height)
|
||||
: Qt.rect(0, 0, 0, 0)
|
||||
|
||||
width: 1000
|
||||
height: 340 + popupMargin
|
||||
minimumWidth: 480
|
||||
minimumHeight: 180 + popupMargin
|
||||
// No minimum while collapsed, so the window can shrink to the button.
|
||||
minimumWidth: collapsed ? 0 : 480
|
||||
minimumHeight: collapsed ? 0 : 180 + popupMargin
|
||||
visible: false
|
||||
color: "transparent"
|
||||
|
||||
// Ignore close requests (Alt+F4, task manager): they would hide the window
|
||||
// without VisibilityController knowing. Hiding goes through the dismiss key or tray toggle.
|
||||
onClosing: close => close.accepted = false
|
||||
onInputRegionChanged: placement?.setInputRegion(inputRegion)
|
||||
onBlurRegionChanged: placement?.setBlurRegion(blurRegion, Theme.windowRadius)
|
||||
// Called by CollapseController.
|
||||
function dismissKeyRect() {
|
||||
return keyboard.keyRect("dismiss");
|
||||
}
|
||||
|
||||
onPlacementChanged: {
|
||||
placement?.setInputRegion(inputRegion);
|
||||
placement?.setBlurRegion(blurRegion, Theme.windowRadius);
|
||||
@@ -40,6 +54,7 @@ Window {
|
||||
Rectangle {
|
||||
id: panel
|
||||
anchors { fill: parent; topMargin: root.popupMargin }
|
||||
visible: !root.collapsed
|
||||
radius: Theme.windowRadius
|
||||
color: Qt.rgba(Theme.background.r, Theme.background.g, Theme.background.b, root.settings.backgroundOpacity)
|
||||
|
||||
@@ -58,23 +73,47 @@ Window {
|
||||
visible: root.settingsOpen
|
||||
settings: root.settings
|
||||
layoutModel: root.layoutModel
|
||||
diagnostics: root.diagnostics
|
||||
}
|
||||
|
||||
DragHandle {
|
||||
id: handle
|
||||
anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
|
||||
onMoved: (dx, dy) => root.placement?.moveBy(dx, dy)
|
||||
pillWidth: Math.min(120, width - 2 * (quickToggles.x + quickToggles.width + 12))
|
||||
onDragStarted: root.placement.startMove()
|
||||
}
|
||||
|
||||
SettingsButton {
|
||||
id: settingsButton
|
||||
anchors { left: parent.left; leftMargin: 8; bottom: parent.bottom }
|
||||
checked: root.settingsOpen
|
||||
alert: root.diagnostics.problems.length > 0
|
||||
onClicked: root.settingsOpen = !root.settingsOpen
|
||||
}
|
||||
|
||||
QuickToggles {
|
||||
id: quickToggles
|
||||
anchors { left: settingsButton.right; bottom: parent.bottom }
|
||||
settings: root.settings
|
||||
layoutModel: root.layoutModel
|
||||
}
|
||||
|
||||
ResizeHandle {
|
||||
anchors { right: parent.right; bottom: parent.bottom }
|
||||
onResized: (dw, dh) => root.placement?.resizeBy(dw, dh)
|
||||
onDragStarted: root.placement.startResize(Qt.RightEdge | Qt.BottomEdge)
|
||||
}
|
||||
}
|
||||
|
||||
FloatingButton {
|
||||
id: floatingButton
|
||||
readonly property rect keyRect: root.collapse?.keyRect ?? Qt.rect(0, 0, 0, 0)
|
||||
// keyRect is in full-window coordinates; the clamp keeps the button inside the window once it has shrunk.
|
||||
x: Math.max(0, Math.min(keyRect.x, root.width - width))
|
||||
y: Math.max(0, Math.min(keyRect.y, root.height - height))
|
||||
width: keyRect.width
|
||||
height: keyRect.height
|
||||
visible: root.collapsed
|
||||
onTapped: root.collapse.expand()
|
||||
onDragStarted: root.placement.startMove()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import QtQuick
|
||||
|
||||
// What doesn't work in this session and why (see Diagnostics); hidden when all is well.
|
||||
Column {
|
||||
id: list
|
||||
|
||||
property list<string> problems
|
||||
|
||||
visible: problems.length > 0
|
||||
spacing: 4
|
||||
|
||||
SectionHeader { text: qsTr("Not Available"); color: Theme.warning }
|
||||
|
||||
Repeater {
|
||||
model: list.problems
|
||||
|
||||
Text {
|
||||
required property string modelData
|
||||
width: list.width
|
||||
text: "⚠ " + modelData
|
||||
color: Theme.text
|
||||
font.pixelSize: 13
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import QtQuick
|
||||
import Sloposk
|
||||
|
||||
// Toggle buttons for frequently changed key options, next to the settings button.
|
||||
// Icons are built from Rectangles, so they don't depend on installed fonts.
|
||||
Row {
|
||||
id: toggles
|
||||
|
||||
required property Settings settings
|
||||
required property LayoutModel layoutModel
|
||||
|
||||
function hasSection(id) {
|
||||
return layoutModel.sections.some(s => s.id === id);
|
||||
}
|
||||
|
||||
// Shows or hides an optional template section. Not displayed if the
|
||||
// layout has no such section.
|
||||
component SectionToggle: BarToggle {
|
||||
required property string section
|
||||
|
||||
visible: toggles.hasSection(section)
|
||||
checked: toggles.settings.visibleSections.includes(section)
|
||||
onToggled: checked => toggles.settings.setSectionVisible(section, checked)
|
||||
}
|
||||
|
||||
// Icon: grid of small keys, optionally inside a keyboard outline.
|
||||
component KeyGrid: Item {
|
||||
id: keyGrid
|
||||
required property color color
|
||||
required property int columns
|
||||
required property int rows
|
||||
property bool framed: false
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: keyGrid.framed
|
||||
radius: 2
|
||||
color: "transparent"
|
||||
border { width: 1.5; color: keyGrid.color }
|
||||
}
|
||||
|
||||
Grid {
|
||||
readonly property real key: keyGrid.framed ? 2 : 3
|
||||
anchors.centerIn: parent
|
||||
columns: keyGrid.columns
|
||||
spacing: 1
|
||||
Repeater {
|
||||
model: keyGrid.columns * keyGrid.rows
|
||||
Rectangle {
|
||||
width: parent.key
|
||||
height: parent.key
|
||||
radius: 0.5
|
||||
color: keyGrid.color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Icon: key outline with a text label.
|
||||
component LabelledKey: Rectangle {
|
||||
property alias label: caption.text
|
||||
property alias textColor: caption.color
|
||||
|
||||
anchors.centerIn: parent
|
||||
width: 20
|
||||
height: 14
|
||||
radius: 3
|
||||
color: "transparent"
|
||||
border { width: 1.5; color: caption.color }
|
||||
|
||||
Text {
|
||||
id: caption
|
||||
anchors.centerIn: parent
|
||||
font { pixelSize: 9; bold: true }
|
||||
}
|
||||
}
|
||||
|
||||
BarToggle {
|
||||
id: full
|
||||
label: qsTr("Full Keyboard")
|
||||
checked: toggles.settings.fullKeyboard
|
||||
onToggled: checked => toggles.settings.fullKeyboard = checked
|
||||
KeyGrid { color: full.foreground; columns: 6; rows: 3; framed: true }
|
||||
}
|
||||
|
||||
BarToggle {
|
||||
id: hold
|
||||
label: qsTr("Hold Keys")
|
||||
checked: toggles.settings.holdKeys
|
||||
onToggled: checked => toggles.settings.holdKeys = checked
|
||||
// Icon: finger pressing a key (hold-keys mode).
|
||||
Rectangle {
|
||||
anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom }
|
||||
width: 18
|
||||
height: 8
|
||||
radius: 2
|
||||
color: "transparent"
|
||||
border { width: 1.5; color: hold.foreground }
|
||||
}
|
||||
Rectangle {
|
||||
anchors { horizontalCenter: parent.horizontalCenter; top: parent.top; topMargin: 1 }
|
||||
width: 8
|
||||
height: 11
|
||||
radius: 4
|
||||
color: hold.foreground
|
||||
}
|
||||
}
|
||||
|
||||
SectionToggle {
|
||||
id: numpad
|
||||
section: "numpad"
|
||||
label: qsTr("Numeric Keypad")
|
||||
KeyGrid { color: numpad.foreground; columns: 3; rows: 3 }
|
||||
}
|
||||
|
||||
SectionToggle {
|
||||
id: navigation
|
||||
section: "navigation"
|
||||
label: qsTr("Navigation Keys")
|
||||
// Icon: arrow keys in an inverted T.
|
||||
Repeater {
|
||||
model: [[1, 0], [0, 1], [1, 1], [2, 1]]
|
||||
Rectangle {
|
||||
required property var modelData
|
||||
x: 1.5 + modelData[0] * 6
|
||||
y: 1.5 + modelData[1] * 6
|
||||
width: 5
|
||||
height: 5
|
||||
radius: 1
|
||||
color: navigation.foreground
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SectionToggle {
|
||||
id: fn
|
||||
section: "function"
|
||||
label: qsTr("Function Keys")
|
||||
LabelledKey { label: "Fn"; textColor: fn.foreground }
|
||||
}
|
||||
}
|
||||
+5
-13
@@ -1,11 +1,10 @@
|
||||
import QtQuick
|
||||
|
||||
// Corner grip. The window grows from its top-left corner, so window
|
||||
// coordinates stay put while resizing: report each step's delta.
|
||||
// Corner grip. Only emits dragStarted(); the parent starts the window manager's resize.
|
||||
Item {
|
||||
id: grip
|
||||
|
||||
signal resized(real dw, real dh)
|
||||
signal dragStarted()
|
||||
|
||||
implicitWidth: 28
|
||||
implicitHeight: 28
|
||||
@@ -28,17 +27,10 @@ Item {
|
||||
}
|
||||
|
||||
DragHandler {
|
||||
property point last
|
||||
|
||||
target: null
|
||||
// Prevent the grab bar underneath from taking over the drag.
|
||||
grabPermissions: PointerHandler.TakeOverForbidden
|
||||
cursorShape: Qt.SizeFDiagCursor
|
||||
onActiveChanged: last = centroid.scenePressPosition
|
||||
onCentroidChanged: {
|
||||
if (!active)
|
||||
return
|
||||
const p = centroid.scenePosition
|
||||
grip.resized(p.x - last.x, p.y - last.y)
|
||||
last = p
|
||||
}
|
||||
onActiveChanged: if (active) grip.dragStarted()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ Item {
|
||||
id: button
|
||||
|
||||
property bool checked: false
|
||||
// Shows a dot when Diagnostics reports a problem.
|
||||
property bool alert: false
|
||||
signal clicked()
|
||||
|
||||
implicitWidth: 36
|
||||
@@ -17,6 +19,16 @@ Item {
|
||||
color: tap.pressed ? Theme.text : Theme.handle
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
visible: button.alert && !button.checked
|
||||
width: 6
|
||||
height: 6
|
||||
radius: 3
|
||||
color: Theme.warning
|
||||
x: parent.width / 2 + 6
|
||||
y: 3
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
id: tap
|
||||
onTapped: button.clicked()
|
||||
|
||||
+27
-7
@@ -1,25 +1,36 @@
|
||||
import QtQuick
|
||||
import Sloposk
|
||||
|
||||
// Replaces the keys while open, over the window's own background so
|
||||
// opacity changes show live. Binds straight to Settings, which persists.
|
||||
// Shown instead of the keys while open. Drawn on the window background, so
|
||||
// opacity changes are visible immediately. Bound directly to Settings, which saves to disk.
|
||||
Flickable {
|
||||
id: panel
|
||||
|
||||
required property Settings settings
|
||||
required property LayoutModel layoutModel
|
||||
required property Diagnostics diagnostics
|
||||
|
||||
clip: true
|
||||
contentHeight: columns.height + 2 * columns.y
|
||||
contentHeight: content.height + 2 * content.y
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
|
||||
Column {
|
||||
id: content
|
||||
x: 16
|
||||
y: 16
|
||||
width: panel.width - 2 * x
|
||||
spacing: 16
|
||||
|
||||
ProblemList {
|
||||
width: parent.width
|
||||
problems: panel.diagnostics.problems
|
||||
}
|
||||
|
||||
Row {
|
||||
id: columns
|
||||
readonly property real columnWidth: (width - spacing) / 2
|
||||
|
||||
x: 16
|
||||
y: 16
|
||||
width: panel.width - 2 * x
|
||||
width: parent.width
|
||||
spacing: 32
|
||||
|
||||
Column {
|
||||
@@ -52,6 +63,14 @@ Flickable {
|
||||
onToggled: checked => panel.settings.alwaysVisible = checked
|
||||
}
|
||||
|
||||
ToggleRow {
|
||||
width: parent.width
|
||||
text: qsTr("Shrink to Button")
|
||||
detail: qsTr("⌨ leaves a floating button instead of hiding; tap it to bring the keyboard back")
|
||||
checked: panel.settings.collapseToButton
|
||||
onToggled: checked => panel.settings.collapseToButton = checked
|
||||
}
|
||||
|
||||
ToggleRow {
|
||||
width: parent.width
|
||||
text: qsTr("“.” Shortcut")
|
||||
@@ -94,7 +113,7 @@ Flickable {
|
||||
}
|
||||
|
||||
Repeater {
|
||||
// "main" is the typing keys; the rest come from the template.
|
||||
// "main" = the typing keys; other ids are template sections.
|
||||
model: [{ id: "main", name: qsTr("Typing keys") }].concat(panel.layoutModel.sections)
|
||||
|
||||
ToggleRow {
|
||||
@@ -108,3 +127,4 @@ Flickable {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import QtQuick
|
||||
|
||||
// A labelled slider in the iOS style; value runs from `from` to 1.
|
||||
// iOS-style labelled slider; value range is `from`..1.
|
||||
Item {
|
||||
id: row
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ QtObject {
|
||||
readonly property color accent: dark ? "#0a84ff" : "#007aff"
|
||||
readonly property color accentText: "#ffffff"
|
||||
readonly property color toggleOn: dark ? "#30d158" : "#34c759"
|
||||
readonly property color warning: dark ? "#ff9f0a" : "#ff9500"
|
||||
|
||||
readonly property real windowRadius: 14
|
||||
readonly property real keyRadius: 6
|
||||
|
||||
+22
-2
@@ -26,6 +26,7 @@ qt_add_library(sloposk_core STATIC
|
||||
window/WindowSettings.h window/WindowSettings.cpp
|
||||
settings/DebouncedStore.h settings/DebouncedStore.cpp
|
||||
settings/Settings.h settings/Settings.cpp
|
||||
diagnostics/Diagnostics.h diagnostics/Diagnostics.cpp
|
||||
)
|
||||
|
||||
# QML lives in the top-level qml/ dir; alias each file so the module sees it at its root.
|
||||
@@ -35,10 +36,14 @@ set(SLOPOSK_QML_FILES
|
||||
Key.qml
|
||||
AlternatesPopup.qml
|
||||
DragHandle.qml
|
||||
FloatingButton.qml
|
||||
ResizeHandle.qml
|
||||
SectionHeader.qml
|
||||
SettingsButton.qml
|
||||
BarToggle.qml
|
||||
QuickToggles.qml
|
||||
SettingsPanel.qml
|
||||
ProblemList.qml
|
||||
ToggleRow.qml
|
||||
SliderRow.qml
|
||||
Theme.qml
|
||||
@@ -68,6 +73,7 @@ target_include_directories(sloposk_core PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/input
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/layout
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/settings
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics
|
||||
)
|
||||
target_link_libraries(sloposk_core PUBLIC Qt6::Quick PkgConfig::XKB)
|
||||
|
||||
@@ -77,6 +83,8 @@ qt_add_executable(sloposk
|
||||
main.cpp
|
||||
app/DevHooks.h app/DevHooks.cpp
|
||||
app/DBusControl.h app/DBusControl.cpp
|
||||
app/Checks.h app/Checks.cpp
|
||||
app/KWinVirtualKeyboard.h app/KWinVirtualKeyboard.cpp
|
||||
app/QuitOnSignal.h app/QuitOnSignal.cpp
|
||||
app/SystemLayouts.h app/SystemLayouts.cpp
|
||||
backend/InputMethodProtocol.h
|
||||
@@ -84,7 +92,10 @@ qt_add_executable(sloposk
|
||||
backend/KWinInputContext.h backend/KWinInputContext.cpp
|
||||
backend/KWinFakeInput.h backend/KWinFakeInput.cpp
|
||||
backend/WaylandKeymap.h backend/WaylandKeymap.cpp
|
||||
window/CollapseController.h window/CollapseController.cpp
|
||||
window/FloatingWindow.h window/FloatingWindow.cpp
|
||||
window/KWinScript.h window/KWinScript.cpp
|
||||
window/KWinRule.h window/KWinRule.cpp
|
||||
)
|
||||
|
||||
qt6_generate_wayland_protocol_client_sources(sloposk PRIVATE_CODE FILES
|
||||
@@ -100,10 +111,19 @@ target_link_libraries(sloposk PRIVATE
|
||||
sloposk_coreplugin
|
||||
Qt6::DBus
|
||||
Qt6::WaylandClient
|
||||
LayerShellQt::Interface
|
||||
KF6::ConfigCore
|
||||
KF6::WindowSystem
|
||||
PkgConfig::WAYLAND
|
||||
)
|
||||
|
||||
install(TARGETS sloposk)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/data/org.sloposk.keyboard.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
||||
# KWin grants restricted protocols by matching Exec to the absolute executable
|
||||
# path. One file runs the installed binary; the other the build's, for development.
|
||||
set(SLOPOSK_EXEC ${CMAKE_INSTALL_FULL_BINDIR}/sloposk)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/data/org.sloposk.keyboard.desktop.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/install/org.sloposk.keyboard.desktop @ONLY)
|
||||
set(SLOPOSK_EXEC ${CMAKE_CURRENT_BINARY_DIR}/sloposk)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/data/org.sloposk.keyboard.desktop.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/org.sloposk.keyboard.desktop @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install/org.sloposk.keyboard.desktop
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "Checks.h"
|
||||
|
||||
#include "SystemLayouts.h"
|
||||
#include "backend/KWinInputMethod.h"
|
||||
#include "diagnostics/Diagnostics.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace {
|
||||
|
||||
QString tr(const char *text)
|
||||
{
|
||||
return QCoreApplication::translate("Checks", text);
|
||||
}
|
||||
|
||||
QString fakeInputProblem(const KWinFakeInput &fakeInput)
|
||||
{
|
||||
const QString lost = tr("Hold Keys, shortcuts like Ctrl+A and typing outside text fields don't work.");
|
||||
if (!fakeInput.isActive())
|
||||
return tr("KWin doesn't let sloposk send key events (it allows the virtual keyboard it launched). ") + lost;
|
||||
return tr("KWin's fake input is too old (version %1, needs %2). ")
|
||||
.arg(fakeInput.boundVersion())
|
||||
.arg(KWinFakeInput::RequiredVersion)
|
||||
+ lost;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void watchInputMethod(Diagnostics &diagnostics, const KWinInputMethod &backend, bool launchedByKWin)
|
||||
{
|
||||
// Qt binds the globals KWin has already announced during construction, so
|
||||
// this result only changes if KWin restarts.
|
||||
const auto checkInputMethod = [&] {
|
||||
diagnostics.check(QStringLiteral("input-method"), launchedByKWin && backend.isAvailable(),
|
||||
tr("Not running as KWin's virtual keyboard, so it can't type into text fields: "
|
||||
"choose sloposk in System Settings → Keyboard → Virtual Keyboard."));
|
||||
};
|
||||
const KWinFakeInput &fakeInput = backend.fakeInput();
|
||||
const auto checkFakeInput = [&] {
|
||||
diagnostics.check(QStringLiteral("fake-input"), fakeInput.canSendKeysyms(), fakeInputProblem(fakeInput));
|
||||
};
|
||||
QObject::connect(&backend, &KWinInputMethod::availableChanged, &diagnostics, checkInputMethod);
|
||||
QObject::connect(&fakeInput, &QWaylandClientExtension::activeChanged, &diagnostics, checkFakeInput);
|
||||
checkInputMethod();
|
||||
checkFakeInput();
|
||||
}
|
||||
|
||||
void watchSystemLayouts(Diagnostics &diagnostics, const SystemLayouts &layouts)
|
||||
{
|
||||
QObject::connect(&layouts, &SystemLayouts::serviceChecked, &diagnostics, [&](bool available) {
|
||||
diagnostics.check(QStringLiteral("system-layouts"), available,
|
||||
tr("KWin's keyboard layout service (org.kde.keyboard) isn't reachable: "
|
||||
"the globe key switches only the on-screen layout."));
|
||||
});
|
||||
}
|
||||
|
||||
void reportDBusControl(Diagnostics &diagnostics, bool registered)
|
||||
{
|
||||
diagnostics.check(QStringLiteral("dbus-control"), registered,
|
||||
tr("Couldn't claim org.sloposk.Keyboard on D-Bus (is another sloposk running?): "
|
||||
"show/hide commands won't reach this one."));
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
class Diagnostics;
|
||||
class KWinInputMethod;
|
||||
class SystemLayouts;
|
||||
|
||||
// Reports missing protocols and D-Bus services to `diagnostics`, and updates
|
||||
// the reports when they appear or disappear.
|
||||
// `launchedByKWin`: WAYLAND_SOCKET was set at startup. KWin advertises the
|
||||
// input-method global to every client, but only activates the process it launched.
|
||||
void watchInputMethod(Diagnostics &diagnostics, const KWinInputMethod &backend, bool launchedByKWin);
|
||||
void watchSystemLayouts(Diagnostics &diagnostics, const SystemLayouts &layouts);
|
||||
void reportDBusControl(Diagnostics &diagnostics, bool registered);
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "KWinVirtualKeyboard.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusPendingCallWatcher>
|
||||
#include <QDBusPendingReply>
|
||||
|
||||
namespace {
|
||||
const QString Service = QStringLiteral("org.kde.KWin");
|
||||
const QString Path = QStringLiteral("/VirtualKeyboard");
|
||||
const QString Interface = QStringLiteral("org.kde.kwin.VirtualKeyboard");
|
||||
} // namespace
|
||||
|
||||
KWinVirtualKeyboard::KWinVirtualKeyboard(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QDBusConnection::sessionBus().connect(Service, Path, Interface, QStringLiteral("modeChanged"), this,
|
||||
SIGNAL(modeChanged()));
|
||||
}
|
||||
|
||||
void KWinVirtualKeyboard::askShowOnActive(QObject *context, std::function<void(bool)> answer)
|
||||
{
|
||||
const QDBusMessage call = QDBusMessage::createMethodCall(Service, Path, Interface, QStringLiteral("willShowOnActive"));
|
||||
auto *watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(call), context);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, context, [answer = std::move(answer)](QDBusPendingCallWatcher *watcher) {
|
||||
watcher->deleteLater();
|
||||
const QDBusPendingReply<bool> reply = *watcher;
|
||||
answer(reply.isError() || reply.value());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <functional>
|
||||
|
||||
// Queries KWin's virtual keyboard policy (tray toggle, System Settings →
|
||||
// Virtual Keyboard) over org.kde.KWin /VirtualKeyboard.
|
||||
// Needed because KWin activates the input method for every text field and
|
||||
// applies the policy only to the input panel surface, which sloposk doesn't use.
|
||||
class KWinVirtualKeyboard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KWinVirtualKeyboard(QObject *parent = nullptr);
|
||||
|
||||
// Asynchronously asks KWin whether to show the keyboard for the currently
|
||||
// focused field and calls `answer` with the result:
|
||||
// - false if the virtual keyboard is disabled
|
||||
// - in the default (touch-only) mode, true only if the last input was touch or pen
|
||||
// - true if KWin can't be reached
|
||||
void askShowOnActive(QObject *context, std::function<void(bool)> answer);
|
||||
|
||||
Q_SIGNALS:
|
||||
void modeChanged();
|
||||
};
|
||||
@@ -23,11 +23,11 @@ SystemLayouts::SystemLayouts(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
// Follows the service's owner, so it survives KWin restarting.
|
||||
// Watches the service owner, so it reconnects after KWin restarts.
|
||||
bus.connect(Service, Path, Interface, QStringLiteral("layoutChanged"), this, SLOT(setCurrent(uint)));
|
||||
auto *watcher = new QDBusServiceWatcher(Service, bus, QDBusServiceWatcher::WatchForOwnerChange, this);
|
||||
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &SystemLayouts::fetchCurrent);
|
||||
connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this] { m_system = false; });
|
||||
connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this] { setSystem(false); });
|
||||
fetchCurrent();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ void SystemLayouts::fetchCurrent()
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
|
||||
watcher->deleteLater();
|
||||
const QDBusPendingReply<uint> reply = *watcher;
|
||||
if (reply.isError())
|
||||
return;
|
||||
m_system = true;
|
||||
setSystem(!reply.isError());
|
||||
if (m_system)
|
||||
setCurrent(reply.value());
|
||||
});
|
||||
}
|
||||
@@ -56,6 +55,12 @@ void SystemLayouts::next(quint32 count)
|
||||
setCurrent(index);
|
||||
}
|
||||
|
||||
void SystemLayouts::setSystem(bool system)
|
||||
{
|
||||
m_system = system;
|
||||
Q_EMIT serviceChecked(system);
|
||||
}
|
||||
|
||||
void SystemLayouts::setCurrent(uint index)
|
||||
{
|
||||
if (index == m_current)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
// Which of the system's keyboard layouts is active, followed and switched
|
||||
// over KWin's org.kde.keyboard D-Bus interface, so the on-screen and the
|
||||
// physical keyboard always agree. Without that service it switches locally,
|
||||
// until the service appears (KWin starting late or restarting).
|
||||
// Tracks and switches the active system keyboard layout via KWin's
|
||||
// org.kde.keyboard D-Bus interface, so the on-screen and physical keyboards
|
||||
// use the same layout. While the service is missing (KWin not started yet or
|
||||
// restarting), switching only changes the local index.
|
||||
class SystemLayouts : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -19,12 +19,15 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentChanged();
|
||||
// Emitted after each attempt to reach the service, and when it disappears.
|
||||
void serviceChecked(bool available);
|
||||
|
||||
private Q_SLOTS:
|
||||
void setCurrent(uint index);
|
||||
|
||||
private:
|
||||
void fetchCurrent();
|
||||
void setSystem(bool system);
|
||||
|
||||
bool m_system = false;
|
||||
quint32 m_current = 0;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "KWinFakeInput.h"
|
||||
|
||||
#include <QtLogging>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t KeysymVersion = 6; // keyboard_keysym; keyboard_key is 4
|
||||
constexpr uint32_t DestroyVersion = 5;
|
||||
|
||||
constexpr uint32_t Released = 0;
|
||||
constexpr uint32_t Pressed = 1;
|
||||
|
||||
constexpr uint32_t RightAlt = 100; // KEY_RIGHTALT
|
||||
|
||||
// Modifiers are held with real keys (evdev codes) so they combine with any keysym.
|
||||
struct ModifierKey {
|
||||
Qt::KeyboardModifier flag;
|
||||
@@ -26,14 +26,10 @@ constexpr ModifierKey ModifierKeys[] = {
|
||||
} // namespace
|
||||
|
||||
KWinFakeInput::KWinFakeInput()
|
||||
: QWaylandClientExtensionTemplate(KeysymVersion)
|
||||
: QWaylandClientExtensionTemplate(RequiredVersion)
|
||||
{
|
||||
connect(this, &QWaylandClientExtension::activeChanged, this, [this] {
|
||||
if (!isActive())
|
||||
return;
|
||||
if (!canSendKeysyms())
|
||||
qWarning("KWin's fake input is too old (version %u, need %u): typing outside text fields is off",
|
||||
boundVersion(), KeysymVersion);
|
||||
if (isActive())
|
||||
authenticate(QStringLiteral("sloposk"), QStringLiteral("On-screen keyboard: type into any window"));
|
||||
});
|
||||
initialize();
|
||||
@@ -52,7 +48,7 @@ uint32_t KWinFakeInput::boundVersion() const
|
||||
|
||||
bool KWinFakeInput::canSendKeysyms() const
|
||||
{
|
||||
return isActive() && boundVersion() >= KeysymVersion;
|
||||
return isActive() && boundVersion() >= RequiredVersion;
|
||||
}
|
||||
|
||||
void KWinFakeInput::sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers)
|
||||
@@ -71,9 +67,16 @@ void KWinFakeInput::sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers)
|
||||
}
|
||||
}
|
||||
|
||||
// KWin resets the modifier state after each keysym except Shift, Ctrl, Alt
|
||||
// and Super, so a held AltGr keysym would never shift the next key: hold
|
||||
// the physical key instead (AltGr is right Alt on the layouts that have it).
|
||||
void KWinFakeInput::setKeyPressed(quint32 keysym, bool pressed)
|
||||
{
|
||||
if (canSendKeysyms())
|
||||
if (!canSendKeysyms())
|
||||
return;
|
||||
if (keysym == XKB_KEY_ISO_Level3_Shift)
|
||||
keyboard_key(RightAlt, pressed ? Pressed : Released);
|
||||
else
|
||||
keyboard_keysym(keysym, pressed ? Pressed : Released);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "qwayland-fake-input.h"
|
||||
|
||||
// Key events for whatever window has focus, as from a hardware keyboard:
|
||||
// KWin's fake-input protocol, which it offers to the input-method process.
|
||||
// Sends key events to the focused window, as a hardware keyboard would, via
|
||||
// KWin's fake-input protocol (offered to the input-method process).
|
||||
// Used when no text field is focused, so shortcuts, terminals and games work.
|
||||
class KWinFakeInput : public QWaylandClientExtensionTemplate<KWinFakeInput>, public QtWayland::org_kde_kwin_fake_input
|
||||
{
|
||||
@@ -24,10 +24,12 @@ public:
|
||||
void setKeyPressed(quint32 keysym, bool pressed);
|
||||
// Types each character as its keysym.
|
||||
void typeText(const QString &text);
|
||||
|
||||
private:
|
||||
// KWin offers the protocol only to clients whose desktop file lists it
|
||||
// (see the .desktop.in); isActive() says whether it did.
|
||||
// Minimum version: required for keyboard_keysym, which all requests here use.
|
||||
static constexpr uint32_t RequiredVersion = 6;
|
||||
bool canSendKeysyms() const;
|
||||
// The version KWin bound, which may be older than the one asked for:
|
||||
// sending a request it lacks makes libwayland abort.
|
||||
uint32_t boundVersion() const;
|
||||
bool canSendKeysyms() const;
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ void KWinInputMethod::replaceBeforeCursor(const QString &before, const QString &
|
||||
m_context->replaceBeforeCursor(before, text);
|
||||
return;
|
||||
}
|
||||
// Key events are one ordered stream, so plain Backspaces are safe here.
|
||||
// Key events are delivered in order, so sending Backspace keys is safe here.
|
||||
for (qsizetype i = 0; i < before.toUcs4().size(); ++i)
|
||||
m_fakeInput.sendKeysym(XKB_KEY_BackSpace);
|
||||
m_fakeInput.typeText(text);
|
||||
@@ -70,9 +70,11 @@ void KWinInputMethod::setPreedit(const QString &text)
|
||||
m_context->preedit(text);
|
||||
}
|
||||
|
||||
// KWin drops the input method's modifier mask for most clients (it forwards
|
||||
// only the key), so Ctrl+A would type "a": combos hold real modifier keys.
|
||||
void KWinInputMethod::sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
if (m_context)
|
||||
if (m_context && (modifiers == Qt::NoModifier || !m_fakeInput.canSendKeysyms()))
|
||||
m_context->sendKeysym(keysym, modifiers);
|
||||
else
|
||||
m_fakeInput.sendKeysym(keysym, modifiers);
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
// False when the compositor didn't hand us the input-method global.
|
||||
bool isAvailable() const;
|
||||
// Used for key events outside text fields, held keys and modifier combos.
|
||||
const KWinFakeInput &fakeInput() const { return m_fakeInput; }
|
||||
|
||||
bool isActive() const override;
|
||||
TextContext context() const override;
|
||||
@@ -62,6 +64,7 @@ private:
|
||||
KWinInputMethodGlobal m_global;
|
||||
KWinFakeInput m_fakeInput;
|
||||
std::unique_ptr<KWinInputContext> m_context;
|
||||
// Replaced by an activate before KWin deactivated it; kept until it does.
|
||||
// Context replaced by a new activate before KWin deactivated it. Kept
|
||||
// until KWin sends its deactivate, then destroyed.
|
||||
std::unique_ptr<KWinInputContext> m_previous;
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
virtual void setKeyPressed(quint32 keysym, bool pressed) = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
// Also when focus moves straight from one field to another.
|
||||
// Also emitted when focus moves directly from one field to another.
|
||||
void activeChanged();
|
||||
void contextChanged();
|
||||
};
|
||||
|
||||
@@ -29,7 +29,8 @@ struct TextContext {
|
||||
Purpose purpose = Purpose::Normal;
|
||||
quint32 hints = 0;
|
||||
|
||||
// Prose fields get iOS conveniences; codes, addresses and secrets don't.
|
||||
// Whether typing aids (auto-capitalization, double-space period) apply:
|
||||
// yes for normal text and names, no for passwords, URLs, emails, numbers etc.
|
||||
bool isProse() const
|
||||
{
|
||||
const bool prosePurpose = purpose == Purpose::Normal || purpose == Purpose::Alpha
|
||||
@@ -37,8 +38,8 @@ struct TextContext {
|
||||
return field && prosePurpose && !(hints & (HiddenText | SensitiveData));
|
||||
}
|
||||
|
||||
// Fields that state any text preference must ask for capitals; most that
|
||||
// state none (hints 0) still want them.
|
||||
// Fields that set any text hint get auto-capitalization only if they set
|
||||
// AutoCapitalization. Fields with no hints get it by default.
|
||||
bool allowsAutoCapitalization() const
|
||||
{
|
||||
constexpr quint32 Preferences = AutoCompletion | AutoCorrection | AutoCapitalization | Lowercase
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "Diagnostics.h"
|
||||
|
||||
#include <QtLogging>
|
||||
|
||||
void Diagnostics::check(const QString &id, bool ok, const QString &message)
|
||||
{
|
||||
if (ok) {
|
||||
if (m_problems.remove(id) == 0)
|
||||
return;
|
||||
qInfo("Resolved: %s", qPrintable(id));
|
||||
} else {
|
||||
if (m_problems.value(id) == message)
|
||||
return;
|
||||
m_problems.insert(id, message);
|
||||
qWarning("%s", qPrintable(message));
|
||||
}
|
||||
Q_EMIT problemsChanged();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
// Features that don't work in this session (a protocol KWin doesn't offer, a
|
||||
// missing D-Bus service...), each with a sentence for the user. Logged when
|
||||
// they appear or clear, and listed in the settings panel.
|
||||
class Diagnostics : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_UNCREATABLE("Created in C++")
|
||||
Q_PROPERTY(QStringList problems READ problems NOTIFY problemsChanged)
|
||||
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
// Records the problem `id` with `message` unless `ok`; clears it if `ok`.
|
||||
void check(const QString &id, bool ok, const QString &message);
|
||||
|
||||
QStringList problems() const { return m_problems.values(); }
|
||||
|
||||
Q_SIGNALS:
|
||||
void problemsChanged();
|
||||
|
||||
private:
|
||||
QMap<QString, QString> m_problems; // id → message, ordered by id
|
||||
};
|
||||
@@ -26,10 +26,11 @@ public:
|
||||
int selected() const { return m_selected; }
|
||||
QString selectedText() const { return m_choices.value(m_selected); }
|
||||
|
||||
// Places one key-sized cell per choice just above the key, starting over it
|
||||
// and extending right (shifted left near the edge to stay within
|
||||
// [0, boundsWidth]; lowered, over the key, to stay below minTop). The cell
|
||||
// above the finger starts selected.
|
||||
// Lays out one key-sized cell per choice in a row above the key, starting
|
||||
// at the key's x and extending right.
|
||||
// - shifted left if needed to stay within [0, boundsWidth]
|
||||
// - moved down (overlapping the key) if needed to stay below minTop
|
||||
// Selects the cell above the finger.
|
||||
void open(const QRectF &keyRect, const QStringList &choices, qreal boundsWidth, qreal minTop, qreal gap);
|
||||
void selectAt(qreal x);
|
||||
void close();
|
||||
|
||||
@@ -51,7 +51,8 @@ QString DeadKeys::press(quint32 deadKeysym)
|
||||
return composed;
|
||||
}
|
||||
case XKB_COMPOSE_CANCELLED: {
|
||||
// No sequence goes on like this: type the old accents, start anew.
|
||||
// No compose sequence continues with this key: flush the pending accents
|
||||
// and start a new sequence.
|
||||
const QString accents = m_pending;
|
||||
cancel();
|
||||
return accents + press(deadKeysym);
|
||||
|
||||
@@ -17,12 +17,13 @@ public:
|
||||
~DeadKeys();
|
||||
|
||||
bool isPending() const { return !m_pending.isEmpty(); }
|
||||
// A dead key was typed: starts or extends the sequence. Returns text to
|
||||
// type now: what two dead keys composed (´´ → ´), or the accents of a
|
||||
// sequence the new one can't continue; empty while still pending.
|
||||
// Dead key pressed: starts or extends the sequence. Returns text to type now:
|
||||
// - the result if the dead keys composed (´´ → ´)
|
||||
// - the pending accents if this key can't continue the sequence
|
||||
// - empty while the sequence is still pending
|
||||
QString press(quint32 deadKeysym);
|
||||
// `text` typed while pending: the composed character, or the accents
|
||||
// followed by `text` when nothing composes. Ends the sequence.
|
||||
// Text key pressed while a sequence is pending. Returns the composed
|
||||
// character, or the pending accents + `text` if nothing composes. Ends the sequence.
|
||||
QString compose(const QString &text);
|
||||
void cancel();
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ quint32 modifierKeysym(const QString &name)
|
||||
return XKB_KEY_Control_L;
|
||||
if (name == u"alt")
|
||||
return XKB_KEY_Alt_L;
|
||||
if (name == u"altgr")
|
||||
return XKB_KEY_ISO_Level3_Shift;
|
||||
return XKB_KEY_Super_L;
|
||||
}
|
||||
|
||||
@@ -80,17 +82,18 @@ bool HardwareKeys::isShiftHeld() const
|
||||
return m_down.contains(XKB_KEY_Shift_L);
|
||||
}
|
||||
|
||||
ShiftLevel HardwareKeys::shiftLevel() const
|
||||
KeyLevel HardwareKeys::keyLevel() const
|
||||
{
|
||||
const bool altGr = m_down.contains(XKB_KEY_ISO_Level3_Shift);
|
||||
if (isShiftHeld())
|
||||
return ShiftLevel::Shifted;
|
||||
return m_capsLock ? ShiftLevel::Capitals : ShiftLevel::None;
|
||||
return {ShiftLevel::Shifted, altGr};
|
||||
return {m_capsLock ? ShiftLevel::Capitals : ShiftLevel::None, altGr};
|
||||
}
|
||||
|
||||
QVariantMap HardwareKeys::modifierModes() const
|
||||
{
|
||||
QVariantMap modes;
|
||||
for (const char *name : {"ctrl", "alt", "super"}) {
|
||||
for (const char *name : {"ctrl", "alt", "super", "altgr"}) {
|
||||
const QString key = QString::fromLatin1(name);
|
||||
modes.insert(key, m_down.contains(modifierKeysym(key)) ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
|
||||
class InputEngine;
|
||||
|
||||
// The "hold keys" mode: the keyboard acts like a hardware one. A key is down
|
||||
// while the finger is, so apps see held keys (games, Shift+click, the
|
||||
// system's key repeat). Shift, Ctrl, Alt and Super are plain keys, caps lock
|
||||
// is the system's, and dead keys compose in the app; none of the touch
|
||||
// conveniences (sticky shift, auto-capitalization, accents) apply.
|
||||
// "Hold keys" mode: behaves like a hardware keyboard.
|
||||
// - a key is pressed while touched and released on lift, so apps see held
|
||||
// keys (games, Shift+click, system key repeat)
|
||||
// - Shift, Ctrl, Alt, Super and AltGr are normal keys; caps lock is the system's
|
||||
// - dead keys are sent as-is and composed by the app
|
||||
// - no sticky modifiers, auto-capitalization or long-press accents
|
||||
class HardwareKeys
|
||||
{
|
||||
public:
|
||||
@@ -25,11 +26,11 @@ public:
|
||||
// Lets go of everything still down, e.g. when the mode is turned off.
|
||||
void releaseAll();
|
||||
|
||||
// For the view: shift shown while held, caps lock while on.
|
||||
ShiftLevel shiftLevel() const;
|
||||
// For the view: shift/AltGr are on while held, caps lock while active.
|
||||
KeyLevel keyLevel() const;
|
||||
bool isShiftHeld() const;
|
||||
bool isCapsLockOn() const { return m_capsLock; }
|
||||
// "ctrl"/"alt"/"super" → 1 while held (ShiftState::Mode::Once), else 0.
|
||||
// "ctrl"/"alt"/"super"/"altgr" → 1 while held (ShiftState::Mode::Once), else 0.
|
||||
QVariantMap modifierModes() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -14,10 +14,10 @@ static_assert(int(KeyboardController::ShiftMode::Locked) == int(ShiftState::Mode
|
||||
namespace {
|
||||
// Enough history for the text rules; fields may report megabytes.
|
||||
constexpr qsizetype MaxTextBefore = 256;
|
||||
// Stands for text we can't see: neither a sentence start nor a word, so no
|
||||
// rule fires on it. For fields that don't report text, after cursor moves.
|
||||
// Placeholder for unknown text before the cursor (field doesn't report text,
|
||||
// or the cursor moved). Neither a sentence start nor a word, so no text rule triggers.
|
||||
constexpr QChar UnknownText = u'\uFFFC';
|
||||
// Like a hardware key: no word mode, a faster rate than Backspace.
|
||||
// Same as a hardware key repeat: no word mode, faster than Backspace.
|
||||
constexpr KeyRepeater::Timing KeysymRepeat{.intervalMs = 50, .wordModeAfterMs = std::numeric_limits<int>::max()};
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ bool KeyboardController::holdKey(const KeyDef &key, bool pressed)
|
||||
if (!m_options.holdKeys || !HardwareKeys::handles(key))
|
||||
return false;
|
||||
pressed ? m_hardware.press(key) : m_hardware.release(key);
|
||||
m_model.setShiftLevel(shiftLevel());
|
||||
m_model.setKeyLevel(keyLevel());
|
||||
Q_EMIT shiftChanged();
|
||||
Q_EMIT modifiersChanged();
|
||||
return true;
|
||||
@@ -68,11 +68,11 @@ void KeyboardController::keyDown(const KeyDef &key, qint64 timeMs)
|
||||
break;
|
||||
case KeyType::Modifier:
|
||||
m_modifiers.press(key.modifier, timeMs);
|
||||
Q_EMIT modifiersChanged();
|
||||
modifiersUpdated();
|
||||
break;
|
||||
case KeyType::Backspace:
|
||||
if (m_deadKeys.isPending()) {
|
||||
m_deadKeys.cancel(); // backspace takes back the accent
|
||||
m_deadKeys.cancel(); // backspace discards the pending accent
|
||||
} else if (m_modifiers.active()) {
|
||||
sendKey(XKB_KEY_BackSpace);
|
||||
} else {
|
||||
@@ -110,7 +110,7 @@ void KeyboardController::keyUp(const KeyDef &key, KeyOutput output, const QStrin
|
||||
break;
|
||||
case KeyType::Modifier:
|
||||
m_modifiers.release(key.modifier);
|
||||
Q_EMIT modifiersChanged();
|
||||
modifiersUpdated();
|
||||
break;
|
||||
case KeyType::Backspace:
|
||||
m_backspaceRepeater.stop();
|
||||
@@ -147,7 +147,7 @@ void KeyboardController::keyCancelled(const KeyDef &key)
|
||||
changeShift([&] { m_shift.release(); });
|
||||
else if (key.type == KeyType::Modifier) {
|
||||
m_modifiers.release(key.modifier);
|
||||
Q_EMIT modifiersChanged();
|
||||
modifiersUpdated();
|
||||
} else if (key.type == KeyType::Backspace)
|
||||
m_backspaceRepeater.stop();
|
||||
else if (key.type == KeyType::Keysym)
|
||||
@@ -156,7 +156,7 @@ void KeyboardController::keyCancelled(const KeyDef &key)
|
||||
|
||||
void KeyboardController::slideReleased(const KeyDef &target, qint64 timeMs)
|
||||
{
|
||||
holdKey(target, true); // only in hold-keys mode: the slide never pressed it
|
||||
holdKey(target, true); // hold-keys mode only: the slide target was never pressed, press it now
|
||||
keyUp(target, KeyOutput::Primary, {}, timeMs);
|
||||
m_model.setLayer(m_layerBeforeSwitch);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ void KeyboardController::setContext(const TextContext &context)
|
||||
if (context.hasSurroundingText) {
|
||||
m_textBefore = context.textBeforeCursor.right(MaxTextBefore);
|
||||
} else if (m_context.hasSurroundingText) {
|
||||
// The field stopped reporting (an input-method reset): what we knew is stale.
|
||||
// The field stopped reporting text (input-method reset): drop the tracked text.
|
||||
m_deadKeys.cancel();
|
||||
m_textBefore.clear();
|
||||
}
|
||||
@@ -210,7 +210,7 @@ void KeyboardController::setOptions(const TypingOptions &options)
|
||||
m_shift = {};
|
||||
}
|
||||
m_options = options;
|
||||
m_model.setShiftLevel(shiftLevel());
|
||||
m_model.setKeyLevel(keyLevel());
|
||||
Q_EMIT shiftChanged();
|
||||
Q_EMIT modifiersChanged();
|
||||
autoCapitalize();
|
||||
@@ -220,14 +220,19 @@ void KeyboardController::typeCharacter(const KeyDef &key, KeyOutput output, cons
|
||||
{
|
||||
const QString base = key.type == KeyType::Space ? QStringLiteral(" ") : key.label;
|
||||
if (m_modifiers.active()) {
|
||||
// A shortcut such as Ctrl+C: the key's unshifted symbol, with modifiers;
|
||||
// for a dead key its dead keysym, as the physical key sends.
|
||||
// Shortcut such as Ctrl+C: send the key's unshifted keysym with modifiers
|
||||
// (for a dead key, its dead keysym, same as the physical key).
|
||||
m_deadKeys.cancel();
|
||||
sendKey(key.dead ? key.dead : xkb_utf32_to_keysym(base.toLower().toUcs4().value(0)));
|
||||
return;
|
||||
}
|
||||
|
||||
const ShiftLevel level = shiftLevel();
|
||||
const KeyLevel level = keyLevel();
|
||||
if (level.altGr) {
|
||||
// Clear one-shot modifiers, like a one-shot shift.
|
||||
m_modifiers.keyTyped();
|
||||
modifiersUpdated();
|
||||
}
|
||||
if (const quint32 dead = key.deadAt(level); dead && output == KeyOutput::Primary) {
|
||||
if (const QString done = m_deadKeys.press(dead); !done.isEmpty())
|
||||
typeText(done);
|
||||
@@ -260,7 +265,7 @@ Qt::KeyboardModifiers KeyboardController::shortcutModifiers() const
|
||||
void KeyboardController::useModifiers()
|
||||
{
|
||||
m_modifiers.keyTyped();
|
||||
Q_EMIT modifiersChanged();
|
||||
modifiersUpdated();
|
||||
if (m_shift.appliesToShortcuts())
|
||||
changeShift([&] { m_shift.characterTyped(); });
|
||||
}
|
||||
@@ -290,7 +295,7 @@ void KeyboardController::deleteBackward(bool wholeWord)
|
||||
autoCapitalize();
|
||||
}
|
||||
|
||||
// Only the key that started the repeat stops it; another finger's key doesn't.
|
||||
// Only releasing the key that started the repeat stops it, not another finger's key.
|
||||
void KeyboardController::stopRepeating(const KeyDef &key)
|
||||
{
|
||||
if (key.keysym == m_repeatingKeysym)
|
||||
@@ -309,23 +314,30 @@ void KeyboardController::autoCapitalize()
|
||||
changeShift([&] { m_shift.setAutomatic(capitalize); });
|
||||
}
|
||||
|
||||
ShiftLevel KeyboardController::shiftLevel() const
|
||||
KeyLevel KeyboardController::keyLevel() const
|
||||
{
|
||||
if (m_options.holdKeys)
|
||||
return m_hardware.shiftLevel();
|
||||
return m_hardware.keyLevel();
|
||||
const bool altGr = m_modifiers.isAltGrActive();
|
||||
if (m_shift.appliesToShortcuts())
|
||||
return ShiftLevel::Shifted;
|
||||
return m_shift.isActive() ? ShiftLevel::Capitals : ShiftLevel::None;
|
||||
return {ShiftLevel::Shifted, altGr};
|
||||
return {m_shift.isActive() ? ShiftLevel::Capitals : ShiftLevel::None, altGr};
|
||||
}
|
||||
|
||||
void KeyboardController::modifiersUpdated()
|
||||
{
|
||||
m_model.setKeyLevel(keyLevel()); // AltGr changes the labels
|
||||
Q_EMIT modifiersChanged();
|
||||
}
|
||||
|
||||
template<typename Change>
|
||||
void KeyboardController::changeShift(Change change)
|
||||
{
|
||||
const ShiftState::Mode mode = m_shift.mode();
|
||||
const ShiftLevel level = shiftLevel();
|
||||
const KeyLevel level = keyLevel();
|
||||
change();
|
||||
if (m_shift.mode() == mode && shiftLevel() == level)
|
||||
if (m_shift.mode() == mode && keyLevel() == level)
|
||||
return;
|
||||
m_model.setShiftLevel(shiftLevel());
|
||||
m_model.setKeyLevel(keyLevel());
|
||||
Q_EMIT shiftChanged();
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ class LayoutModel;
|
||||
// Which of a key's outputs the gesture selected.
|
||||
enum class KeyOutput { Primary, Flick, Alternate };
|
||||
|
||||
// Keyboard rules: what each key does, shift and the other modifiers, dead
|
||||
// keys, layers and the iOS conveniences (auto-capitalization, double-space
|
||||
// period, backspace repeat). Knows nothing about touch or Wayland: it
|
||||
// receives key presses and text-field context, and talks to an InputEngine.
|
||||
// Keyboard logic: key actions, shift and other modifiers, dead keys, layers
|
||||
// and iOS-style typing aids (auto-capitalization, double-space period,
|
||||
// backspace repeat). Independent of touch and Wayland: input is key presses
|
||||
// and text-field context, output goes to an InputEngine.
|
||||
//
|
||||
// With Ctrl, Alt or Super active, keys become shortcuts (keysyms with those
|
||||
// modifiers) instead of text. Shift joins shortcuts and non-text keys
|
||||
// (Shift+F5, Shift+Tab, Shift+arrows) only when the user turned it on, not
|
||||
// when auto-capitalization did.
|
||||
// With Ctrl, Alt or Super active, keys send shortcuts (keysym + modifiers)
|
||||
// instead of text. AltGr types the key's AltGr symbol.
|
||||
// Shift is added to shortcuts and non-text keys (Shift+F5, Shift+Tab,
|
||||
// Shift+arrows) only if the user enabled it, not if auto-capitalization did.
|
||||
class KeyboardController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_UNCREATABLE("Created in C++")
|
||||
Q_PROPERTY(ShiftMode shiftMode READ shiftMode NOTIFY shiftChanged)
|
||||
// "ctrl"/"alt"/"super" → ShiftMode
|
||||
// "ctrl"/"alt"/"super"/"altgr" → ShiftMode
|
||||
Q_PROPERTY(QVariantMap modifierModes READ modifierModes NOTIFY modifiersChanged)
|
||||
|
||||
public:
|
||||
@@ -45,19 +45,19 @@ public:
|
||||
|
||||
ShiftMode shiftMode() const;
|
||||
QVariantMap modifierModes() const;
|
||||
// Hold-keys mode: no long-press, flick or trackpad gestures, no rollover.
|
||||
// Hold-keys mode disables long-press, flick and trackpad gestures, and rollover.
|
||||
bool holdsKeys() const { return m_options.holdKeys; }
|
||||
|
||||
void keyDown(const KeyDef &key, qint64 timeMs);
|
||||
void keyUp(const KeyDef &key, KeyOutput output, const QString &alternate, qint64 timeMs);
|
||||
void keyCancelled(const KeyDef &key);
|
||||
// Finger slid from a layer key onto `target`: type it, then switch back.
|
||||
// Finger slid from a layer key onto `target` and lifted: type it, then switch back to the previous layer.
|
||||
void slideReleased(const KeyDef &target, qint64 timeMs);
|
||||
// Space-bar trackpad: move the text cursor by whole steps.
|
||||
void moveCursor(QPoint steps);
|
||||
|
||||
// A field was focused (context.field) or unfocused: forget what we knew
|
||||
// about the text and start over from what it reported.
|
||||
// Field focused (context.field) or unfocused: discard tracked text and
|
||||
// start from `context`.
|
||||
void resetContext(const TextContext &context);
|
||||
// The focused field reported new text/content type.
|
||||
void setContext(const TextContext &context);
|
||||
@@ -67,21 +67,23 @@ Q_SIGNALS:
|
||||
void shiftChanged();
|
||||
void modifiersChanged();
|
||||
void dismissRequested();
|
||||
void nextLayoutRequested(); // the globe key: switching is the system's job
|
||||
// Hold-keys mode is about to flip: keys still down must be cancelled now,
|
||||
// under the rules they were pressed with.
|
||||
void nextLayoutRequested(); // globe key; SystemLayouts does the switch
|
||||
// Hold-keys mode is about to change: release keys still down now, using
|
||||
// the mode they were pressed in.
|
||||
void holdKeysAboutToChange();
|
||||
|
||||
private:
|
||||
void typeCharacter(const KeyDef &key, KeyOutput output, const QString &alternate);
|
||||
void typeText(const QString &text);
|
||||
// Sends a non-text key or shortcut with the active modifiers, then uses them up.
|
||||
// Sends a non-text key or shortcut with the active modifiers, then clears one-shot modifiers.
|
||||
void sendKey(quint32 keysym);
|
||||
Qt::KeyboardModifiers shortcutModifiers() const;
|
||||
ShiftLevel shiftLevel() const;
|
||||
// Hold-keys mode: forwards the key to m_hardware; false if it isn't one it presses.
|
||||
KeyLevel keyLevel() const;
|
||||
// Hold-keys mode: forwards the key to m_hardware. Returns false if m_hardware doesn't handle it.
|
||||
bool holdKey(const KeyDef &key, bool pressed);
|
||||
void useModifiers();
|
||||
// Call after modifiers change: updates key labels and notifies the view.
|
||||
void modifiersUpdated();
|
||||
void deleteBackward(bool wholeWord);
|
||||
void sendRepeatedKeysym();
|
||||
void stopRepeating(const KeyDef &key);
|
||||
@@ -103,7 +105,7 @@ private:
|
||||
QString m_layerBeforeSwitch;
|
||||
|
||||
TextContext m_context;
|
||||
// Best guess of the text before the cursor: the field's last report plus
|
||||
// what we typed since. Fields that don't report text rely on the latter.
|
||||
// Estimated text before the cursor: the field's last report plus what we
|
||||
// typed since. For fields that don't report text, only what we typed.
|
||||
QString m_textBefore;
|
||||
};
|
||||
|
||||
@@ -104,13 +104,13 @@ void KeyboardSurface::pointerDown(int id, QPointF pos, qint64 timeMs)
|
||||
m_lastEventMs = timeMs;
|
||||
if (!m_model || !m_controller)
|
||||
return;
|
||||
// A press for an id still down means its release was lost.
|
||||
// A press for an id that is already down means its release was lost.
|
||||
if (const auto stale = m_pointers.constFind(id); stale != m_pointers.cend()) {
|
||||
const Pointer pointer = *stale;
|
||||
m_pointers.erase(stale);
|
||||
cancel(pointer);
|
||||
}
|
||||
// Rollover would let go of keys still held, which hold-keys mode must not.
|
||||
// No rollover in hold-keys mode: it would release keys that are still held.
|
||||
if (!m_controller->holdsKeys())
|
||||
commitPendingTaps(timeMs);
|
||||
|
||||
@@ -179,7 +179,7 @@ void KeyboardSurface::longPressElapsed(int id, quint64 serial)
|
||||
if (it->tracker.gesture() == Gesture::Trackpad)
|
||||
setTrackpadActive(true);
|
||||
else if (it->tracker.gesture() == Gesture::LongPress)
|
||||
openAlternates(Pointer(*it), m_lastEventMs); // a copy: opening may erase from m_pointers
|
||||
openAlternates(Pointer(*it), m_lastEventMs); // copy: openAlternates() may erase from m_pointers
|
||||
}
|
||||
|
||||
// --- Gesture outcomes
|
||||
@@ -198,7 +198,7 @@ void KeyboardSurface::finish(const Pointer &pointer, qint64 timeMs)
|
||||
m_controller->keyUp(key, tracker.flickCommitted() ? KeyOutput::Flick : KeyOutput::Primary, {}, timeMs);
|
||||
break;
|
||||
case Gesture::LongPress: {
|
||||
// Without the popup (it never opened), the key types its primary output.
|
||||
// Popup never opened: type the key's primary output.
|
||||
const QString alternate = ownsAlternates(pointer) ? m_alternates.selectedText() : QString();
|
||||
if (ownsAlternates(pointer))
|
||||
closeAlternates();
|
||||
@@ -230,7 +230,7 @@ void KeyboardSurface::cancel(const Pointer &pointer)
|
||||
m_controller->keyCancelled(pointer.tracker.key());
|
||||
}
|
||||
|
||||
// Clears the visual state a pointer left on the model.
|
||||
// Clears the pointer's pressed/hover state in the model.
|
||||
void KeyboardSurface::release(const Pointer &pointer)
|
||||
{
|
||||
m_model->setPressed(pointer.index, false);
|
||||
@@ -261,12 +261,12 @@ void KeyboardSurface::updateSlideHover(Pointer &pointer)
|
||||
pointer.hoverIndex = hover;
|
||||
}
|
||||
|
||||
// One popup: a second long-press first finishes the one showing it, as a new
|
||||
// press commits pending taps.
|
||||
// Only one popup at a time: a second long-press first commits the open popup,
|
||||
// the same way a new press commits pending taps.
|
||||
void KeyboardSurface::openAlternates(const Pointer &pointer, qint64 timeMs)
|
||||
{
|
||||
if (pointer.index < 0)
|
||||
return; // the layout changed under the finger: no key to place it over
|
||||
return; // layer changed during the press: the key is gone
|
||||
for (auto it = m_pointers.begin(); it != m_pointers.end(); ++it) {
|
||||
if (it->serial != pointer.serial && ownsAlternates(*it)) {
|
||||
const Pointer owner = *it;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
#include <QQuickItem>
|
||||
#include <limits>
|
||||
|
||||
// Receives all touch points (and the mouse) over the keyboard, runs one
|
||||
// PointerTracker per finger, and turns finished gestures into controller
|
||||
// calls. Several fingers can type at once: a new press commits pending taps
|
||||
// (rollover), as on iOS.
|
||||
// Handles touch points and the mouse over the keyboard. Runs one
|
||||
// PointerTracker per finger and turns finished gestures into controller calls.
|
||||
// Rollover (as on iOS): a new press commits the other fingers' pending taps.
|
||||
class KeyboardSurface : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -22,8 +21,8 @@ class KeyboardSurface : public QQuickItem
|
||||
Q_PROPERTY(KeyboardController *controller READ controller WRITE setController NOTIFY controllerChanged)
|
||||
Q_PROPERTY(AlternatesPicker *alternates READ alternates CONSTANT)
|
||||
Q_PROPERTY(bool trackpadActive READ isTrackpadActive NOTIFY trackpadActiveChanged)
|
||||
// Room above the surface that long-press popups may use; taller keys put
|
||||
// top-row popups lower, over their key, instead of cutting them off.
|
||||
// Space above the surface available to long-press popups. If a popup
|
||||
// doesn't fit, it is moved down over its key instead of being clipped.
|
||||
Q_PROPERTY(qreal popupHeadroom MEMBER m_popupHeadroom NOTIFY popupHeadroomChanged)
|
||||
|
||||
public:
|
||||
@@ -53,10 +52,10 @@ protected:
|
||||
|
||||
private:
|
||||
struct Pointer {
|
||||
PointerTracker tracker; // holds a copy of the key: layers may change mid-press
|
||||
PointerTracker tracker; // has its own copy of the key: the layer may change mid-press
|
||||
int index = -1; // pressed key in the model, -1 once the layer changed
|
||||
int hoverIndex = -1; // key under the finger while sliding
|
||||
quint64 serial = 0; // tells a reused touch id from the original
|
||||
quint64 serial = 0; // distinguishes a reused touch id from the original
|
||||
};
|
||||
|
||||
void pointerDown(int id, QPointF pos, qint64 timeMs);
|
||||
@@ -82,7 +81,7 @@ private:
|
||||
quint64 m_alternatesSerial = 0; // the pointer the popup belongs to
|
||||
QHash<int, Pointer> m_pointers;
|
||||
quint64 m_nextSerial = 1;
|
||||
qint64 m_lastEventMs = 0; // timers have no event time; they use this
|
||||
qint64 m_lastEventMs = 0; // timestamp of the last event; used as "now" in timer callbacks
|
||||
bool m_trackpadActive = false;
|
||||
qreal m_popupHeadroom = std::numeric_limits<qreal>::max();
|
||||
};
|
||||
|
||||
@@ -40,7 +40,12 @@ Qt::KeyboardModifiers Modifiers::active() const
|
||||
if (entry.state.isActive())
|
||||
flags |= entry.flag;
|
||||
}
|
||||
return flags;
|
||||
return flags & ~Qt::GroupSwitchModifier;
|
||||
}
|
||||
|
||||
bool Modifiers::isAltGrActive() const
|
||||
{
|
||||
return m_entries.back().state.isActive();
|
||||
}
|
||||
|
||||
QVariantMap Modifiers::modes() const
|
||||
|
||||
@@ -8,19 +8,22 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
// Ctrl, Alt and Super, each sticky like shift (see ShiftState): tap for the
|
||||
// next key, double-tap to lock, hold while typing with another finger.
|
||||
// Ctrl, Alt, Super and AltGr, each sticky like shift (see ShiftState): tap
|
||||
// for the next key, double-tap to lock, or hold while typing with another finger.
|
||||
// Ctrl/Alt/Super make keys send shortcuts; AltGr selects their AltGr symbols.
|
||||
class Modifiers
|
||||
{
|
||||
public:
|
||||
// Names as used in layouts: "ctrl", "alt", "super".
|
||||
// Names as used in layouts: "ctrl", "alt", "super", "altgr".
|
||||
void press(const QString &name, qint64 timeMs);
|
||||
void release(const QString &name);
|
||||
// A key was typed: one-shot modifiers are used up.
|
||||
// Call after a key is typed: clears one-shot modifiers.
|
||||
void keyTyped();
|
||||
void clear();
|
||||
|
||||
// Active Ctrl/Alt/Super, i.e. the ones that make a key a shortcut.
|
||||
Qt::KeyboardModifiers active() const;
|
||||
bool isAltGrActive() const;
|
||||
// name → ShiftState::Mode as int, for the view.
|
||||
QVariantMap modes() const;
|
||||
|
||||
@@ -32,9 +35,10 @@ private:
|
||||
};
|
||||
ShiftState *find(const QString &name);
|
||||
|
||||
std::array<Entry, 3> m_entries{{
|
||||
std::array<Entry, 4> m_entries{{
|
||||
{"ctrl", Qt::ControlModifier, {}},
|
||||
{"alt", Qt::AltModifier, {}},
|
||||
{"super", Qt::MetaModifier, {}},
|
||||
{"altgr", Qt::GroupSwitchModifier, {}},
|
||||
}};
|
||||
};
|
||||
|
||||
@@ -26,8 +26,14 @@ void PointerTracker::moveTo(QPointF pos)
|
||||
return;
|
||||
m_moved = true;
|
||||
|
||||
if (m_key.type == KeyType::LayerSwitch)
|
||||
if (m_key.type == KeyType::LayerSwitch) {
|
||||
m_gesture = Gesture::Slide;
|
||||
} else if (m_config.gestures && m_key.type == KeyType::Space && qAbs(delta.x()) > qAbs(delta.y())) {
|
||||
// Measured from the press point, so the slop distance counts towards the first step.
|
||||
m_gesture = Gesture::Trackpad;
|
||||
m_trackpadOrigin = m_start;
|
||||
m_trackpadLines = false;
|
||||
}
|
||||
else if (m_config.gestures && !m_key.flick.isEmpty() && delta.y() > qAbs(delta.x()))
|
||||
m_gesture = Gesture::Flick;
|
||||
}
|
||||
@@ -62,8 +68,9 @@ QPoint PointerTracker::takeTrackpadSteps()
|
||||
return {};
|
||||
|
||||
const QPointF travel = m_position - m_trackpadOrigin;
|
||||
// Truncate towards zero so jitter around the origin doesn't step.
|
||||
const QPoint total(int(travel.x() / m_config.trackpadStep), int(travel.y() / m_config.trackpadRowStep));
|
||||
// Truncate towards zero so jitter around the origin doesn't produce steps.
|
||||
const int rows = m_trackpadLines ? int(travel.y() / m_config.trackpadRowStep) : 0;
|
||||
const QPoint total(int(travel.x() / m_config.trackpadStep), rows);
|
||||
const QPoint steps = total - m_trackpadStepsTaken;
|
||||
m_trackpadStepsTaken = total;
|
||||
return steps;
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
// Gesture recognition for one finger on one key. Pure logic: the caller feeds
|
||||
// positions and tells it when the long-press delay has elapsed.
|
||||
//
|
||||
// Tap pressed, not (yet) anything else
|
||||
// Tap pressed, no other gesture recognized (yet)
|
||||
// Flick moved down on a key with a flick symbol
|
||||
// LongPress held still on a key with alternates
|
||||
// Trackpad held still on space; movement moves the text cursor
|
||||
// Trackpad held still on space; movement moves the text cursor. Sliding
|
||||
// sideways on space moves it too, along the line only.
|
||||
// Slide moved off a layer key (type a symbol, then switch back)
|
||||
class PointerTracker
|
||||
{
|
||||
@@ -56,5 +57,6 @@ private:
|
||||
Gesture m_gesture = Gesture::Tap;
|
||||
bool m_moved = false;
|
||||
QPointF m_trackpadOrigin;
|
||||
bool m_trackpadLines = true; // vertical travel moves between lines
|
||||
QPoint m_trackpadStepsTaken;
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
void ShiftState::press(qint64 timeMs)
|
||||
{
|
||||
// Locks whatever the first tap did: at a sentence start that tap turns
|
||||
// auto-shift off, and the second must still lock.
|
||||
// A double tap always locks, even when the first tap turned auto-shift off
|
||||
// (at a sentence start).
|
||||
const bool doubleTap = timeMs - m_lastPress <= DoubleTapMs && !m_lastPressUnlocked;
|
||||
m_lastPress = timeMs;
|
||||
m_lastPressUnlocked = m_mode == Mode::Locked;
|
||||
@@ -28,7 +28,7 @@ void ShiftState::release()
|
||||
|
||||
void ShiftState::characterTyped()
|
||||
{
|
||||
m_lastPress = NoPress; // shift, type, shift is not a double tap
|
||||
m_lastPress = NoPress; // shift, type, shift must not count as a double tap
|
||||
m_userChoice = false;
|
||||
if (m_held)
|
||||
m_typedWhileHeld = true;
|
||||
|
||||
@@ -18,20 +18,19 @@ public:
|
||||
|
||||
Mode mode() const { return m_mode; }
|
||||
bool isActive() const { return m_mode != Mode::Off; }
|
||||
// Whether shift joins shortcuts and non-text keys (Shift+F5): only when
|
||||
// tapped or held by the user. Neither auto-capitalization nor caps lock
|
||||
// does, as on a PC.
|
||||
// Whether shift is added to shortcuts and non-text keys (Shift+F5): only
|
||||
// if the user tapped or held it, not for auto-capitalization or caps lock (as on a PC).
|
||||
bool appliesToShortcuts() const { return m_held || (m_mode == Mode::Once && !m_automatic); }
|
||||
|
||||
void press(qint64 timeMs);
|
||||
void release();
|
||||
void characterTyped();
|
||||
|
||||
// Auto-capitalization hint; ignored while shift is held or locked. A shift
|
||||
// the user tapped stays until a character is typed or the hint changes,
|
||||
// so a field re-reporting the same context doesn't undo it.
|
||||
// Auto-capitalization hint; ignored while shift is held or locked. A
|
||||
// user-tapped shift is kept until a character is typed or the hint value
|
||||
// changes, so the field re-sending the same context doesn't reset it.
|
||||
void setAutomatic(bool capitalize);
|
||||
// A new field: the user's shift choice no longer applies.
|
||||
// New field focused: discard the user's manual shift.
|
||||
void forgetUserChoice() { m_userChoice = false; }
|
||||
// Caps lock key: locks, or unlocks if locked.
|
||||
void toggleLock();
|
||||
@@ -43,7 +42,7 @@ private:
|
||||
bool m_userChoice = false; // the user set the mode since the last character
|
||||
bool m_held = false;
|
||||
bool m_typedWhileHeld = false;
|
||||
bool m_lastPressUnlocked = false; // a tap leaving caps lock doesn't start a double tap
|
||||
bool m_lastPressUnlocked = false; // the tap that unlocks caps lock must not start a double tap
|
||||
static constexpr qint64 NoPress = std::numeric_limits<qint64>::min() / 2;
|
||||
qint64 m_lastPress = NoPress;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
// Pure text heuristics behind the iOS conveniences.
|
||||
// Text heuristics for the iOS-style typing aids. No state.
|
||||
namespace TextRules {
|
||||
|
||||
// True at the start of a sentence: empty text, after a newline, or after
|
||||
|
||||
@@ -13,7 +13,7 @@ qreal blockUnits(const Block &block)
|
||||
return units;
|
||||
}
|
||||
|
||||
// Key widths in units once stretch keys take up the row's slack.
|
||||
// Key widths in units, after stretch keys are widened to fill the row.
|
||||
QList<qreal> stretchedWidths(const Row &row, qreal targetUnits)
|
||||
{
|
||||
const auto stretchy = std::ranges::count_if(row, &KeyDef::stretch);
|
||||
@@ -44,7 +44,7 @@ qreal totalUnits(const QList<Block> &blocks)
|
||||
|
||||
qsizetype totalRows(const QList<Block> &blocks)
|
||||
{
|
||||
// Filling blocks only count when nothing else is shown.
|
||||
// fillHeight blocks are ignored, unless all blocks are fillHeight.
|
||||
const bool allFill = std::ranges::all_of(blocks, &Block::fillHeight);
|
||||
qsizetype rows = 0;
|
||||
for (const Block &block : blocks) {
|
||||
@@ -78,7 +78,7 @@ QList<QRectF> computeKeyRects(const QList<Block> &blocks, QSizeF size, KeyboardM
|
||||
const auto rows = block.rows.size();
|
||||
const qreal span = block.fillHeight ? innerHeight : spanOf(std::max(rows, block.minRows));
|
||||
const qsizetype fixed = std::min(block.fixedRows, rows);
|
||||
// Rows after the fixed ones share what's left; with none, the block sits at the bottom.
|
||||
// Rows after fixedRows split the remaining height; if there are none, the block is bottom-aligned.
|
||||
const qreal flexHeight = rows > fixed
|
||||
? (span - qreal(fixed) * (sharedRowHeight + metrics.gap) - qreal(rows - fixed - 1) * metrics.gap)
|
||||
/ qreal(rows - fixed)
|
||||
|
||||
@@ -12,8 +12,8 @@ struct KeyboardMetrics {
|
||||
};
|
||||
|
||||
// The keys on screen: blocks of rows, side by side.
|
||||
// A block can reserve room (minUnits, minRows) so that swapping its rows, e.g.
|
||||
// switching layers, moves nothing else; its keys stretch into the room.
|
||||
// A block can reserve space (minUnits, minRows), so swapping its rows (e.g.
|
||||
// switching layers) doesn't move other blocks. Its keys stretch to fill it.
|
||||
struct Block {
|
||||
QList<Row> rows;
|
||||
bool fillHeight = false; // spans the full height instead of max(rows, minRows) shared rows
|
||||
|
||||
@@ -66,6 +66,8 @@ std::optional<KeymapKey> keyAt(xkb_keymap *keymap, int code, xkb_layout_index_t
|
||||
return std::nullopt;
|
||||
if (!readLevel(symbolAt(keymap, code, layout, 1), key.upper, key.deadUpper))
|
||||
key.upper = key.lower.toUpper();
|
||||
readLevel(symbolAt(keymap, code, layout, 2), key.altGr, key.deadAltGr);
|
||||
readLevel(symbolAt(keymap, code, layout, 3), key.altGrUpper, key.deadAltGrUpper);
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
struct xkb_keymap;
|
||||
|
||||
// One typing key of a keymap layout, at its two shift levels. A level is
|
||||
// either text or a dead key (then `text` is its spacing accent, for labels).
|
||||
// One typing key of a keymap layout, at its shift and AltGr levels. A level
|
||||
// is either text or a dead key (then the text is its spacing accent, for labels).
|
||||
struct KeymapKey {
|
||||
enum class Position { Regular, Backslash, LessGreater }; // BKSL, LSGT: not on every keyboard
|
||||
|
||||
@@ -15,6 +15,10 @@ struct KeymapKey {
|
||||
QString upper;
|
||||
quint32 deadLower = 0; // dead keysym, 0 if the level types text
|
||||
quint32 deadUpper = 0;
|
||||
QString altGr; // third level (AltGr), empty if it types nothing
|
||||
QString altGrUpper; // fourth level (AltGr+Shift)
|
||||
quint32 deadAltGr = 0;
|
||||
quint32 deadAltGrUpper = 0;
|
||||
|
||||
bool isLetter() const;
|
||||
};
|
||||
@@ -30,5 +34,5 @@ struct KeymapKeys {
|
||||
|
||||
KeymapKeys readKeymapKeys(xkb_keymap *keymap, quint32 layoutIndex);
|
||||
|
||||
// What a dead key shows and types when nothing composes: ´ for dead_acute.
|
||||
// Spacing accent for a dead keysym, used as its label and when nothing composes: ´ for dead_acute.
|
||||
QString deadKeyText(quint32 keysym);
|
||||
|
||||
+33
-4
@@ -27,6 +27,14 @@ enum class KeyType {
|
||||
// (Shift+1 = !), as on a PC.
|
||||
enum class ShiftLevel { None, Capitals, Shifted };
|
||||
|
||||
// Shift plus AltGr, which picks a key's third (and, shifted, fourth) keymap level.
|
||||
struct KeyLevel {
|
||||
KeyLevel(ShiftLevel shift = ShiftLevel::None, bool altGr = false) : shift(shift), altGr(altGr) {}
|
||||
ShiftLevel shift;
|
||||
bool altGr;
|
||||
friend bool operator==(const KeyLevel &, const KeyLevel &) = default;
|
||||
};
|
||||
|
||||
struct KeyDef {
|
||||
KeyType type = KeyType::Character;
|
||||
QString label; // shown and typed (for character keys)
|
||||
@@ -37,6 +45,10 @@ struct KeyDef {
|
||||
QString modifier; // Modifier only: "ctrl", "alt" or "super"
|
||||
quint32 dead = 0; // character keys: dead keysym typed instead of `label`, 0 if none
|
||||
quint32 deadShifted = 0; // same for the shifted level
|
||||
QString altGr; // keymap keys: typed with AltGr, empty if nothing
|
||||
QString altGrShifted; // with AltGr and shift, empty if nothing
|
||||
quint32 deadAltGr = 0; // dead keysyms of those levels (then the texts are their accents)
|
||||
quint32 deadAltGrShifted = 0;
|
||||
qreal width = 1.0; // in key units
|
||||
bool stretch = false; // grows so the row is as wide as its block's widest
|
||||
quint32 keysym = 0; // Keysym keys only
|
||||
@@ -47,17 +59,34 @@ struct KeyDef {
|
||||
QStringList flicks; // flick symbol per letter, left to right
|
||||
|
||||
// Text this key shows/types; only character keys change.
|
||||
QString text(ShiftLevel level) const
|
||||
// Without an AltGr symbol, AltGr leaves the key as it is (as on a PC).
|
||||
QString text(KeyLevel level) const
|
||||
{
|
||||
if (level == ShiftLevel::None || type != KeyType::Character)
|
||||
if (type != KeyType::Character)
|
||||
return label;
|
||||
if (level == ShiftLevel::Capitals)
|
||||
if (usesAltGr(level))
|
||||
return usesAltGrShifted(level) ? altGrShifted : altGr;
|
||||
if (level.shift == ShiftLevel::None)
|
||||
return label;
|
||||
if (level.shift == ShiftLevel::Capitals)
|
||||
return isLetter() ? label.toUpper() : label;
|
||||
return shifted.isEmpty() ? label.toUpper() : shifted;
|
||||
}
|
||||
// The dead keysym typed at `level`, 0 if it types text.
|
||||
quint32 deadAt(ShiftLevel level) const { return level == ShiftLevel::Shifted ? deadShifted : dead; }
|
||||
quint32 deadAt(KeyLevel level) const
|
||||
{
|
||||
if (usesAltGr(level))
|
||||
return usesAltGrShifted(level) ? deadAltGrShifted : deadAltGr;
|
||||
return level.shift == ShiftLevel::Shifted ? deadShifted : dead;
|
||||
}
|
||||
bool isLetter() const { return !dead && label.size() == 1 && label.front().isLetter(); }
|
||||
|
||||
private:
|
||||
bool usesAltGr(KeyLevel level) const { return level.altGr && !altGr.isEmpty(); }
|
||||
bool usesAltGrShifted(KeyLevel level) const
|
||||
{
|
||||
return level.shift == ShiftLevel::Shifted && !altGrShifted.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
using Row = QList<KeyDef>;
|
||||
|
||||
@@ -19,7 +19,7 @@ const QHash<QString, QString> &baseOverrides()
|
||||
return bases;
|
||||
}
|
||||
|
||||
// "š" → "s": the letter an accented letter is a variant of.
|
||||
// Base letter of an accented letter: "š" → "s".
|
||||
QString baseLetter(const QString &letter)
|
||||
{
|
||||
if (const auto it = baseOverrides().constFind(letter); it != baseOverrides().cend())
|
||||
@@ -34,10 +34,14 @@ KeyDef characterKey(const KeymapKey &source)
|
||||
key.shifted = source.upper;
|
||||
key.dead = source.deadLower;
|
||||
key.deadShifted = source.deadUpper;
|
||||
key.altGr = source.altGr;
|
||||
key.altGrShifted = source.altGrUpper;
|
||||
key.deadAltGr = source.deadAltGr;
|
||||
key.deadAltGrShifted = source.deadAltGrUpper;
|
||||
return key;
|
||||
}
|
||||
|
||||
// The compact letter rows: letters only, and not the keys some keyboards lack.
|
||||
// Compact-mode letter rows: letters only, without keys missing on some keyboards (BKSL, LSGT).
|
||||
QList<KeyDef> letterKeys(const KeymapKeys &keymap, int row, const QStringList &flicks)
|
||||
{
|
||||
QList<KeyDef> keys;
|
||||
@@ -45,7 +49,7 @@ QList<KeyDef> letterKeys(const KeymapKeys &keymap, int row, const QStringList &f
|
||||
if (!source.isLetter() || source.position != KeymapKey::Position::Regular)
|
||||
continue;
|
||||
KeyDef key = characterKey(source);
|
||||
// iPad letters always uppercase; the keymap may shift some to a symbol (sk: ô → ").
|
||||
// Shifted letters are always uppercased (as on iPad), even where the keymap's shift level is a symbol (sk: ô → ").
|
||||
key.shifted = source.lower.toUpper();
|
||||
key.deadShifted = 0;
|
||||
key.flick = flicks.value(keys.size());
|
||||
@@ -54,12 +58,13 @@ QList<KeyDef> letterKeys(const KeymapKeys &keymap, int row, const QStringList &f
|
||||
return keys;
|
||||
}
|
||||
|
||||
// A full row: every typing key, the shifted symbol shown (and flickable) above.
|
||||
// `withLessGreater` tells whether the ISO key left of Z is among them.
|
||||
// Full-mode row: every typing key. The secondary (flick) symbol is the shifted
|
||||
// symbol, or for letters (where shift only capitalizes) the AltGr symbol (sk: ' on j).
|
||||
// `withLessGreater` is set if the row contains the ISO key left of Z.
|
||||
QList<KeyDef> rowKeys(const KeymapKeys &keymap, int row, bool *withLessGreater)
|
||||
{
|
||||
*withLessGreater = false;
|
||||
QSet<QString> elsewhere; // LSGT often repeats a pair that exists elsewhere (US: < >)
|
||||
QSet<QString> elsewhere; // LSGT often duplicates symbols on other keys (US: < >)
|
||||
for (const auto &keys : keymap.rows) {
|
||||
for (const KeymapKey &key : keys) {
|
||||
if (key.position != KeymapKey::Position::LessGreater)
|
||||
@@ -73,9 +78,11 @@ QList<KeyDef> rowKeys(const KeymapKeys &keymap, int row, bool *withLessGreater)
|
||||
continue;
|
||||
*withLessGreater |= source.position == KeymapKey::Position::LessGreater;
|
||||
KeyDef key = characterKey(source);
|
||||
// Show (and flick for) a shifted level that isn't just the capital letter: ! on 1, " on sk ô.
|
||||
// Use the shifted level as the flick symbol unless it's just the capital letter: ! on 1, " on sk ô.
|
||||
if (!source.deadUpper && source.upper != source.lower && source.upper != source.lower.toUpper())
|
||||
key.flick = source.upper;
|
||||
else if (!source.deadAltGr && source.altGr != source.lower)
|
||||
key.flick = source.altGr;
|
||||
keys.append(key);
|
||||
}
|
||||
return keys;
|
||||
@@ -90,7 +97,7 @@ Row expandPlaceholders(const Row &row, const KeymapKeys &keymap)
|
||||
else if (key.type == KeyType::Keys) {
|
||||
bool withLessGreater = false;
|
||||
const QList<KeyDef> keys = rowKeys(keymap, key.lettersRow, &withLessGreater);
|
||||
// As on ISO keyboards, that key takes its room from the one before it (left shift).
|
||||
// As on ISO keyboards, LSGT's width is taken from the key before it (left shift).
|
||||
if (withLessGreater && !result.isEmpty())
|
||||
result.back().width = std::max(1.0, result.back().width - 1);
|
||||
result += keys;
|
||||
@@ -101,9 +108,9 @@ Row expandPlaceholders(const Row &row, const KeymapKeys &keymap)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Long-press choices per letter: the keymap's letters that have no letter key
|
||||
// first (they're what this language types), then the template's. Letters on the
|
||||
// number row (sk: ť) stay choices in full mode too: they're out of the way there.
|
||||
// Long-press choices per letter: first the keymap's letters that have no key of
|
||||
// their own in the letter rows (the language's own letters), then the template's.
|
||||
// Number-row letters (sk: ť) are kept as choices in full mode too, since the number row is hard to reach.
|
||||
void addAlternates(Layer &layer, const Layout &tmpl, const KeymapKeys &keymap)
|
||||
{
|
||||
QSet<QString> onKeys;
|
||||
|
||||
@@ -8,7 +8,7 @@ enum class KeyboardMode {
|
||||
Full, // iPad Pro / PC: number row, punctuation, tab, modifiers
|
||||
};
|
||||
|
||||
// Turns the template into the layout shown: picks each layer's rows for the
|
||||
// mode, fills the keymap placeholders, and gives letters their long-press
|
||||
// choices (letters of the keymap without a key of their own come first).
|
||||
// Builds the displayed layout from the template: picks each layer's rows for
|
||||
// the mode, fills the keymap placeholders, and assigns long-press choices to
|
||||
// letters (keymap letters without their own key first).
|
||||
Layout buildLayout(const Layout &tmpl, const KeymapKeys &keymap, KeyboardMode mode = KeyboardMode::Compact);
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace {
|
||||
|
||||
constexpr int LetterRows = 3;
|
||||
constexpr int KeyRows = 4;
|
||||
const QStringList ModifierNames = {QStringLiteral("ctrl"), QStringLiteral("alt"), QStringLiteral("super")};
|
||||
const QStringList ModifierNames = {QStringLiteral("ctrl"), QStringLiteral("alt"), QStringLiteral("super"),
|
||||
QStringLiteral("altgr")};
|
||||
|
||||
QStringList toStringList(const QJsonValue &value)
|
||||
{
|
||||
|
||||
@@ -48,9 +48,9 @@ QVariant LayoutModel::data(const QModelIndex &index, int role) const
|
||||
const KeyDef &key = m_keys.at(index.row());
|
||||
const QRectF rect = m_rects.value(index.row());
|
||||
switch (role) {
|
||||
case LabelRole: return key.text(m_shiftLevel);
|
||||
// A shifted key already shows its shifted symbol (! on 1): don't repeat it.
|
||||
case FlickLabelRole: return m_shiftLevel == ShiftLevel::Shifted && key.flick == key.shifted ? QString() : key.flick;
|
||||
case LabelRole: return key.text(m_keyLevel);
|
||||
// Hide the flick symbol if the main label already shows it (shifted or AltGr: ! on 1).
|
||||
case FlickLabelRole: return key.flick == key.text(m_keyLevel) ? QString() : key.flick;
|
||||
case ModifierRole: return key.modifier;
|
||||
case KeyTypeRole: return keyTypeName(key.type);
|
||||
case KeyXRole: return rect.x();
|
||||
@@ -133,11 +133,11 @@ void LayoutModel::setSize(QSizeF size)
|
||||
Q_EMIT dataChanged(index(0), index(rowCount() - 1), {KeyXRole, KeyYRole, KeyWidthRole, KeyHeightRole});
|
||||
}
|
||||
|
||||
void LayoutModel::setShiftLevel(ShiftLevel level)
|
||||
void LayoutModel::setKeyLevel(KeyLevel level)
|
||||
{
|
||||
if (level == m_shiftLevel)
|
||||
if (level == m_keyLevel)
|
||||
return;
|
||||
m_shiftLevel = level;
|
||||
m_keyLevel = level;
|
||||
if (!m_keys.isEmpty())
|
||||
Q_EMIT dataChanged(index(0), index(rowCount() - 1), {LabelRole, FlickLabelRole});
|
||||
}
|
||||
@@ -185,7 +185,7 @@ QList<Block> LayoutModel::composeBlocks() const
|
||||
main.rows += section.rows;
|
||||
}
|
||||
if (layer && shown(MainSectionId)) {
|
||||
// Room for the biggest layer, so switching layers keeps the other blocks still.
|
||||
// Reserve space for the largest layer, so switching layers doesn't move other blocks.
|
||||
main.fixedRows = main.rows.size();
|
||||
for (const Layer &other : m_layout.layers) {
|
||||
main.minRows = std::max(main.minRows, main.fixedRows + other.rows.size());
|
||||
@@ -202,7 +202,7 @@ QList<Block> LayoutModel::composeBlocks() const
|
||||
if (section.placement == Section::Placement::Right && shown(section.id))
|
||||
blocks.append({section.rows, section.fillHeight});
|
||||
}
|
||||
// Never show nothing.
|
||||
// If no block is shown, fall back to the current layer.
|
||||
if (blocks.isEmpty() && layer)
|
||||
blocks.append({layer->rows});
|
||||
return blocks;
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
// Section ids to show; MainSectionId stands for the layers.
|
||||
void setVisibleSections(const QStringList &ids);
|
||||
void setSize(QSizeF size);
|
||||
void setShiftLevel(ShiftLevel level);
|
||||
void setKeyLevel(KeyLevel level);
|
||||
void setPressed(int index, bool pressed);
|
||||
void setFlickProgress(int index, qreal progress);
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
int keyAt(QPointF pos) const;
|
||||
const KeyDef &key(int index) const { return m_keys.at(index); }
|
||||
QRectF keyRect(int index) const { return m_rects.value(index); }
|
||||
bool isUppercase() const { return m_shiftLevel != ShiftLevel::None; }
|
||||
bool isUppercase() const { return m_keyLevel.shift != ShiftLevel::None; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void layoutChanged();
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
QStringList m_visibleSections{MainSectionId};
|
||||
QList<Block> m_blocks;
|
||||
QSizeF m_size;
|
||||
ShiftLevel m_shiftLevel = ShiftLevel::None;
|
||||
KeyLevel m_keyLevel;
|
||||
|
||||
QList<KeyDef> m_keys;
|
||||
QList<QRectF> m_rects;
|
||||
|
||||
+68
-18
@@ -1,16 +1,21 @@
|
||||
#include "app/Checks.h"
|
||||
#include "app/DBusControl.h"
|
||||
#include "app/DevHooks.h"
|
||||
#include "app/KWinVirtualKeyboard.h"
|
||||
#include "app/QuitOnSignal.h"
|
||||
#include "app/SystemLayouts.h"
|
||||
#include "backend/KWinInputMethod.h"
|
||||
#include "backend/WaylandKeymap.h"
|
||||
#include "diagnostics/Diagnostics.h"
|
||||
#include "engine/DirectEngine.h"
|
||||
#include "input/KeyboardController.h"
|
||||
#include "layout/LayoutBuilder.h"
|
||||
#include "layout/LayoutLoader.h"
|
||||
#include "layout/LayoutModel.h"
|
||||
#include "settings/Settings.h"
|
||||
#include "window/CollapseController.h"
|
||||
#include "window/FloatingWindow.h"
|
||||
#include "window/KWinRule.h"
|
||||
#include "window/VisibilityController.h"
|
||||
#include "window/WindowSettings.h"
|
||||
|
||||
@@ -41,8 +46,8 @@ std::optional<Layout> loadTemplate()
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// The shown layout is the template filled with the active system layout's
|
||||
// keys. Returns the rebuild, for settings that change the result.
|
||||
// Builds the displayed layout from the template and the active system layout.
|
||||
// Returns the rebuild function, for settings that affect the result.
|
||||
std::function<void()> connectLayouts(const Layout &tmpl, WaylandKeymap &keymap, SystemLayouts &systemLayouts,
|
||||
const Settings &settings, KeyboardController &controller, LayoutModel &model)
|
||||
{
|
||||
@@ -58,7 +63,7 @@ std::function<void()> connectLayouts(const Layout &tmpl, WaylandKeymap &keymap,
|
||||
return rebuild;
|
||||
}
|
||||
|
||||
// Settings that add or remove keys resize the window so keys keep their size.
|
||||
// Settings that add or remove keys resize the window, so key size stays the same.
|
||||
void connectKeySettings(Settings &settings, LayoutModel &model, FloatingWindow &placement, const QQuickWindow &window,
|
||||
const std::function<void()> &rebuild)
|
||||
{
|
||||
@@ -78,32 +83,64 @@ void connectKeySettings(Settings &settings, LayoutModel &model, FloatingWindow &
|
||||
[keepingKeySize, rebuild] { keepingKeySize(rebuild); });
|
||||
}
|
||||
|
||||
void restoreAndPersistGeometry(FloatingWindow &placement, WindowSettings &settings)
|
||||
// Geometry isn't saved while collapsed (it's the button's, not the keyboard's).
|
||||
void restoreAndPersistGeometry(FloatingWindow &placement, WindowSettings &settings, const CollapseController &collapse)
|
||||
{
|
||||
if (const auto geometry = settings.load(placement.screenName()))
|
||||
placement.setGeometry(*geometry);
|
||||
QObject::connect(&placement, &FloatingWindow::geometryChanged, &settings,
|
||||
[&] { settings.save(placement.screenName(), placement.geometry()); });
|
||||
QObject::connect(&placement, &FloatingWindow::geometryChanged, &settings, [&] {
|
||||
if (!collapse.isCollapsed())
|
||||
settings.save(placement.screenName(), placement.geometry());
|
||||
});
|
||||
}
|
||||
|
||||
// On field focus, ask KWin's policy first and show the keyboard only if it
|
||||
// agrees. Asking before showing avoids a brief flash when the answer is no.
|
||||
void connectFieldFocus(VisibilityController &visibility, KWinInputMethod &backend, KWinVirtualKeyboard &policy)
|
||||
{
|
||||
QObject::connect(&backend, &TextBackend::activeChanged, &visibility, [&] {
|
||||
if (!backend.isActive()) {
|
||||
visibility.setFieldActive(false);
|
||||
return;
|
||||
}
|
||||
policy.askShowOnActive(&visibility, [&](bool show) {
|
||||
if (!backend.isActive())
|
||||
return; // field lost focus before KWin answered
|
||||
visibility.setShowOnField(show);
|
||||
visibility.setFieldActive(true);
|
||||
});
|
||||
});
|
||||
QObject::connect(&policy, &KWinVirtualKeyboard::modeChanged, &visibility, [&] {
|
||||
policy.askShowOnActive(&visibility, [&](bool show) { visibility.setShowOnField(show); });
|
||||
});
|
||||
}
|
||||
|
||||
void connectVisibility(VisibilityController &visibility, KWinInputMethod &backend, const Settings &settings,
|
||||
KeyboardController &controller, FloatingWindow &placement)
|
||||
FloatingWindow &placement)
|
||||
{
|
||||
// Connect first, so the initial state set below is applied to the window.
|
||||
QObject::connect(&visibility, &VisibilityController::visibleChanged, &placement,
|
||||
[&](bool visible) { visible ? placement.show() : placement.hide(); });
|
||||
visibility.setAlwaysVisible(settings.alwaysVisible());
|
||||
QObject::connect(&settings, &Settings::alwaysVisibleChanged, &visibility,
|
||||
[&] { visibility.setAlwaysVisible(settings.alwaysVisible()); });
|
||||
// Without the input-method global (run outside KWin's control, e.g. for UI
|
||||
// work) there is no focus signal: stay visible so it can be tried out.
|
||||
// Without the input-method global (not launched by KWin, e.g. during UI
|
||||
// development) there are no focus events: stay visible.
|
||||
const auto updateStandalone = [&] { visibility.setStandalone(!backend.isAvailable()); };
|
||||
QObject::connect(&backend, &KWinInputMethod::availableChanged, &visibility, updateStandalone);
|
||||
QObject::connect(&backend, &TextBackend::activeChanged, &visibility,
|
||||
[&] { visibility.setFieldActive(backend.isActive()); });
|
||||
QObject::connect(&controller, &KeyboardController::dismissRequested, &visibility, &VisibilityController::hide);
|
||||
QObject::connect(&visibility, &VisibilityController::visibleChanged, &placement,
|
||||
[&](bool visible) { visible ? placement.show() : placement.hide(); });
|
||||
updateStandalone();
|
||||
}
|
||||
|
||||
// The dismiss key hides the keyboard, or shrinks it to a floating button.
|
||||
void connectDismiss(KeyboardController &controller, const Settings &settings, CollapseController &collapse,
|
||||
VisibilityController &visibility)
|
||||
{
|
||||
QObject::connect(&controller, &KeyboardController::dismissRequested, &visibility, [&] {
|
||||
if (!settings.collapseToButton() || !collapse.collapse())
|
||||
visibility.hide();
|
||||
});
|
||||
}
|
||||
|
||||
void connectTextContext(KWinInputMethod &backend, KeyboardController &controller)
|
||||
{
|
||||
QObject::connect(&backend, &TextBackend::activeChanged, &controller,
|
||||
@@ -117,7 +154,11 @@ void connectTextContext(KWinInputMethod &backend, KeyboardController &controller
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
blockQuitSignals();
|
||||
// Read before connecting: libwayland unsets it.
|
||||
const bool launchedByKWin = qEnvironmentVariableIsSet("WAYLAND_SOCKET");
|
||||
QGuiApplication app(argc, argv);
|
||||
// Don't quit when the window closes: KWin only restarts the input method after a crash.
|
||||
QGuiApplication::setQuitOnLastWindowClosed(false);
|
||||
quitOnSignal();
|
||||
QGuiApplication::setApplicationName(QStringLiteral("sloposk"));
|
||||
QGuiApplication::setOrganizationName(QStringLiteral("sloposk")); // ~/.config/sloposk/sloposk.conf
|
||||
@@ -129,7 +170,9 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
Diagnostics diagnostics;
|
||||
KWinInputMethod backend;
|
||||
watchInputMethod(diagnostics, backend, launchedByKWin);
|
||||
DirectEngine engine(backend);
|
||||
LayoutModel model;
|
||||
KeyboardController controller(engine, model);
|
||||
@@ -141,6 +184,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
WaylandKeymap keymap;
|
||||
SystemLayouts systemLayouts;
|
||||
watchSystemLayouts(diagnostics, systemLayouts);
|
||||
const auto rebuildLayout = connectLayouts(*layoutTemplate, keymap, systemLayouts, settings, controller, model);
|
||||
QObject::connect(&settings, &Settings::typingOptionsChanged, &controller,
|
||||
[&] { controller.setOptions(settings.typingOptions()); });
|
||||
@@ -150,6 +194,7 @@ int main(int argc, char *argv[])
|
||||
{QStringLiteral("layoutModel"), QVariant::fromValue(&model)},
|
||||
{QStringLiteral("controller"), QVariant::fromValue(&controller)},
|
||||
{QStringLiteral("settings"), QVariant::fromValue(&settings)},
|
||||
{QStringLiteral("diagnostics"), QVariant::fromValue(&diagnostics)},
|
||||
});
|
||||
qml.loadFromModule("Sloposk", "Main");
|
||||
auto *window = qml.rootObjects().isEmpty() ? nullptr : qobject_cast<QQuickWindow *>(qml.rootObjects().first());
|
||||
@@ -158,18 +203,23 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
installKWinRule(QGuiApplication::desktopFileName());
|
||||
FloatingWindow placement(window);
|
||||
window->setProperty("placement", QVariant::fromValue(&placement));
|
||||
CollapseController collapse(*window, placement);
|
||||
window->setProperty("collapse", QVariant::fromValue(&collapse));
|
||||
WindowSettings windowSettings;
|
||||
restoreAndPersistGeometry(placement, windowSettings);
|
||||
restoreAndPersistGeometry(placement, windowSettings, collapse);
|
||||
connectKeySettings(settings, model, placement, *window, rebuildLayout);
|
||||
|
||||
VisibilityController visibility;
|
||||
connectVisibility(visibility, backend, settings, controller, placement);
|
||||
KWinVirtualKeyboard virtualKeyboardPolicy;
|
||||
connectFieldFocus(visibility, backend, virtualKeyboardPolicy);
|
||||
connectVisibility(visibility, backend, settings, placement);
|
||||
connectDismiss(controller, settings, collapse, visibility);
|
||||
|
||||
DBusControl dbus(visibility);
|
||||
if (!dbus.registerOnSessionBus())
|
||||
qWarning("D-Bus control unavailable (is another instance running?)");
|
||||
reportDBusControl(diagnostics, dbus.registerOnSessionBus());
|
||||
|
||||
installDevHooks(backend, *window);
|
||||
return app.exec();
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <QTimer>
|
||||
#include <QVariantMap>
|
||||
|
||||
// QSettings writes that arrive in bursts (dragging a slider or the window),
|
||||
// saved once the burst ends instead of on every step. Flushes on destruction.
|
||||
// Debounced QSettings writes: values that change rapidly (slider or window
|
||||
// drag) are saved once changes stop. Flushes on destruction.
|
||||
class DebouncedStore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -11,6 +11,7 @@ constexpr auto HoldKeysKey = "typing/holdKeys";
|
||||
constexpr auto VisibleSectionsKey = "layout/visibleSections";
|
||||
constexpr auto FullKeyboardKey = "layout/fullKeyboard";
|
||||
constexpr auto AlwaysVisibleKey = "window/alwaysVisible";
|
||||
constexpr auto CollapseToButtonKey = "window/collapseToButton";
|
||||
constexpr auto BackgroundOpacityKey = "appearance/backgroundOpacity";
|
||||
constexpr auto BlurBackgroundKey = "appearance/blurBackground";
|
||||
}
|
||||
@@ -28,6 +29,7 @@ Settings::Settings(QObject *parent)
|
||||
m_visibleSections = {MainSectionId};
|
||||
m_fullKeyboard = store.value(FullKeyboardKey, false).toBool();
|
||||
m_alwaysVisible = store.value(AlwaysVisibleKey, false).toBool();
|
||||
m_collapseToButton = store.value(CollapseToButtonKey, false).toBool();
|
||||
m_backgroundOpacity = qBound(MinBackgroundOpacity, store.value(BackgroundOpacityKey, 1.0).toReal(), 1.0);
|
||||
m_blurBackground = store.value(BlurBackgroundKey, true).toBool();
|
||||
}
|
||||
@@ -60,6 +62,15 @@ void Settings::setAlwaysVisible(bool always)
|
||||
Q_EMIT alwaysVisibleChanged();
|
||||
}
|
||||
|
||||
void Settings::setCollapseToButton(bool collapse)
|
||||
{
|
||||
if (collapse == m_collapseToButton)
|
||||
return;
|
||||
m_collapseToButton = collapse;
|
||||
QSettings().setValue(CollapseToButtonKey, collapse);
|
||||
Q_EMIT collapseToButtonChanged();
|
||||
}
|
||||
|
||||
void Settings::setFullKeyboard(bool full)
|
||||
{
|
||||
if (full == m_fullKeyboard)
|
||||
|
||||
@@ -23,6 +23,8 @@ class Settings : public QObject
|
||||
Q_PROPERTY(bool fullKeyboard READ fullKeyboard WRITE setFullKeyboard NOTIFY fullKeyboardChanged)
|
||||
// Shown even without a focused text field, to type into any window.
|
||||
Q_PROPERTY(bool alwaysVisible READ alwaysVisible WRITE setAlwaysVisible NOTIFY alwaysVisibleChanged)
|
||||
// The dismiss key shrinks the keyboard to a floating button instead of hiding it.
|
||||
Q_PROPERTY(bool collapseToButton READ collapseToButton WRITE setCollapseToButton NOTIFY collapseToButtonChanged)
|
||||
// Opacity of the panel behind the keys (MinBackgroundOpacity–1); keys stay opaque.
|
||||
Q_PROPERTY(qreal backgroundOpacity READ backgroundOpacity WRITE setBackgroundOpacity NOTIFY appearanceChanged)
|
||||
Q_PROPERTY(qreal minBackgroundOpacity READ minBackgroundOpacity CONSTANT)
|
||||
@@ -42,13 +44,15 @@ public:
|
||||
void setHoldKeys(bool enabled);
|
||||
|
||||
QStringList visibleSections() const { return m_visibleSections; }
|
||||
// Hiding the last visible section is refused: something must stay on screen.
|
||||
// Refuses to hide the last visible section.
|
||||
Q_INVOKABLE void setSectionVisible(const QString &id, bool visible);
|
||||
|
||||
bool fullKeyboard() const { return m_fullKeyboard; }
|
||||
void setFullKeyboard(bool full);
|
||||
bool alwaysVisible() const { return m_alwaysVisible; }
|
||||
void setAlwaysVisible(bool always);
|
||||
bool collapseToButton() const { return m_collapseToButton; }
|
||||
void setCollapseToButton(bool collapse);
|
||||
|
||||
static constexpr qreal MinBackgroundOpacity = 0.1;
|
||||
static qreal minBackgroundOpacity() { return MinBackgroundOpacity; }
|
||||
@@ -62,6 +66,7 @@ Q_SIGNALS:
|
||||
void visibleSectionsChanged();
|
||||
void fullKeyboardChanged();
|
||||
void alwaysVisibleChanged();
|
||||
void collapseToButtonChanged();
|
||||
void appearanceChanged();
|
||||
|
||||
private:
|
||||
@@ -72,6 +77,7 @@ private:
|
||||
QStringList m_visibleSections;
|
||||
bool m_fullKeyboard = false;
|
||||
bool m_alwaysVisible = false;
|
||||
bool m_collapseToButton = false;
|
||||
qreal m_backgroundOpacity = 1.0;
|
||||
bool m_blurBackground = true;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "CollapseController.h"
|
||||
|
||||
#include "FloatingWindow.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
namespace {
|
||||
constexpr int ExpandTimeoutMs = 500;
|
||||
|
||||
bool roughlyEqual(QSize a, QSize b)
|
||||
{
|
||||
return qAbs(a.width() - b.width()) <= 1 && qAbs(a.height() - b.height()) <= 1;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CollapseController::CollapseController(QQuickWindow &window, FloatingWindow &placement, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_window(window)
|
||||
, m_placement(placement)
|
||||
{
|
||||
m_expanding.setSingleShot(true);
|
||||
m_expanding.setInterval(ExpandTimeoutMs);
|
||||
connect(&m_expanding, &QTimer::timeout, this, &CollapseController::finishExpanding);
|
||||
connect(&window, &QWindow::widthChanged, this, &CollapseController::windowResized);
|
||||
connect(&window, &QWindow::heightChanged, this, &CollapseController::windowResized);
|
||||
}
|
||||
|
||||
bool CollapseController::collapse()
|
||||
{
|
||||
if (m_collapsed)
|
||||
return true;
|
||||
QVariant rect;
|
||||
QMetaObject::invokeMethod(&m_window, "dismissKeyRect", Q_RETURN_ARG(QVariant, rect));
|
||||
if (rect.toRectF().isEmpty())
|
||||
return false;
|
||||
m_keyRect = rect.toRectF();
|
||||
m_expandedSize = m_window.size();
|
||||
m_collapsed = true;
|
||||
Q_EMIT collapsedChanged();
|
||||
// Wait one frame, so the compositor has the new (lower) minimum size before the resize.
|
||||
connect(&m_window, &QQuickWindow::frameSwapped, this, [this] {
|
||||
if (m_collapsed)
|
||||
m_placement.moveResize(m_keyRect, false);
|
||||
}, Qt::SingleShotConnection);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CollapseController::expand()
|
||||
{
|
||||
if (!m_collapsed || m_expanding.isActive())
|
||||
return;
|
||||
if (roughlyEqual(m_window.size(), m_expandedSize)) {
|
||||
finishExpanding(); // window never shrank: nothing to resize
|
||||
return;
|
||||
}
|
||||
// Stay collapsed until the window has grown, so the keys aren't drawn squeezed.
|
||||
m_placement.moveResize(QRectF(-m_keyRect.topLeft(), m_expandedSize), true);
|
||||
m_expanding.start();
|
||||
}
|
||||
|
||||
void CollapseController::windowResized()
|
||||
{
|
||||
if (m_expanding.isActive() && roughlyEqual(m_window.size(), m_expandedSize))
|
||||
finishExpanding();
|
||||
}
|
||||
|
||||
void CollapseController::finishExpanding()
|
||||
{
|
||||
m_expanding.stop();
|
||||
if (!roughlyEqual(m_window.size(), m_expandedSize))
|
||||
m_window.resize(m_expandedSize); // KWin didn't resize (timeout): resize directly
|
||||
m_collapsed = false;
|
||||
Q_EMIT collapsedChanged();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QRectF>
|
||||
#include <QSize>
|
||||
#include <QTimer>
|
||||
|
||||
class FloatingWindow;
|
||||
class QQuickWindow;
|
||||
|
||||
// Collapses the keyboard window to the size of its dismiss key (a floating
|
||||
// button) and expands it back, positioned so the dismiss key is where the
|
||||
// button was (clamped to the screen). The window itself is resized, so the
|
||||
// button can be dragged anywhere and covers nothing else.
|
||||
// QML uses `collapsed` and `keyRect`.
|
||||
class CollapseController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool collapsed READ isCollapsed NOTIFY collapsedChanged)
|
||||
// Dismiss key rect in the full window. The button is drawn there until the window has shrunk.
|
||||
Q_PROPERTY(QRectF keyRect READ keyRect NOTIFY collapsedChanged)
|
||||
|
||||
public:
|
||||
CollapseController(QQuickWindow &window, FloatingWindow &placement, QObject *parent = nullptr);
|
||||
|
||||
bool isCollapsed() const { return m_collapsed; }
|
||||
QRectF keyRect() const { return m_keyRect; }
|
||||
|
||||
// False if the keyboard has no dismiss key to shrink to.
|
||||
bool collapse();
|
||||
Q_INVOKABLE void expand();
|
||||
|
||||
Q_SIGNALS:
|
||||
void collapsedChanged();
|
||||
|
||||
private:
|
||||
void windowResized();
|
||||
void finishExpanding();
|
||||
|
||||
QQuickWindow &m_window;
|
||||
FloatingWindow &m_placement;
|
||||
bool m_collapsed = false;
|
||||
QRectF m_keyRect;
|
||||
QSize m_expandedSize;
|
||||
QTimer m_expanding; // timeout for KWin's resize; fires if KWin never resizes
|
||||
};
|
||||
@@ -1,68 +1,45 @@
|
||||
#include "FloatingWindow.h"
|
||||
|
||||
#include "KWinScript.h"
|
||||
|
||||
#include <KWindowEffects>
|
||||
#include <LayerShellQt/Window>
|
||||
#include <QPainterPath>
|
||||
#include <QCursor>
|
||||
#include <QGuiApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainterPath>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
|
||||
namespace {
|
||||
|
||||
bool isWayland()
|
||||
{
|
||||
return QGuiApplication::platformName().startsWith(QLatin1String("wayland"));
|
||||
}
|
||||
|
||||
constexpr int BottomGap = 24;
|
||||
|
||||
} // namespace
|
||||
|
||||
FloatingWindow::FloatingWindow(QWindow *window, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_window(window)
|
||||
{
|
||||
if (isWayland()) {
|
||||
m_layerSurface = LayerShellQt::Window::get(window);
|
||||
m_layerSurface->setLayer(LayerShellQt::Window::LayerOverlay);
|
||||
m_layerSurface->setKeyboardInteractivity(LayerShellQt::Window::KeyboardInteractivityNone);
|
||||
m_layerSurface->setAnchors({LayerShellQt::Window::AnchorTop | LayerShellQt::Window::AnchorLeft});
|
||||
m_layerSurface->setExclusiveZone(-1);
|
||||
m_layerSurface->setScope(QStringLiteral("sloposk-keyboard"));
|
||||
m_layerSurface->setActivateOnShow(false);
|
||||
} else {
|
||||
window->setFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint
|
||||
| Qt::WindowDoesNotAcceptFocus);
|
||||
}
|
||||
m_position = defaultPosition();
|
||||
apply();
|
||||
followScreen(window->screen());
|
||||
connect(window, &QWindow::screenChanged, this, &FloatingWindow::followScreen);
|
||||
window->setFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
|
||||
for (const auto changed : {&QWindow::xChanged, &QWindow::yChanged, &QWindow::widthChanged, &QWindow::heightChanged})
|
||||
connect(window, changed, this, &FloatingWindow::geometryChanged);
|
||||
window->installEventFilter(this);
|
||||
}
|
||||
|
||||
// Re-fits the window (not saved: the stored geometry is the user's choice).
|
||||
void FloatingWindow::followScreen(QScreen *screen)
|
||||
bool FloatingWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (m_screen)
|
||||
disconnect(m_screen, nullptr, this, nullptr);
|
||||
m_screen = screen;
|
||||
if (!m_screen)
|
||||
return;
|
||||
connect(m_screen, &QScreen::geometryChanged, this, [this] { setGeometry(geometry()); });
|
||||
setGeometry(geometry());
|
||||
// Exposed implies mapped, so KWin knows the window at this point.
|
||||
if (watched == m_window && event->type() == QEvent::Expose) {
|
||||
if (m_window->isExposed() && !m_exposed)
|
||||
moveResize(QRectF(QPointF(), m_window->size()), true);
|
||||
m_exposed = m_window->isExposed();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QRect FloatingWindow::geometry() const
|
||||
{
|
||||
return {m_position, m_window->size()};
|
||||
return m_window->geometry().translated(-screenArea().topLeft());
|
||||
}
|
||||
|
||||
void FloatingWindow::setGeometry(const QRect &geometry)
|
||||
{
|
||||
const QSize size = geometry.size().expandedTo(m_window->minimumSize()).boundedTo(screenArea().size());
|
||||
m_window->resize(size);
|
||||
m_position = clamped(geometry.topLeft(), size);
|
||||
apply();
|
||||
m_window->setGeometry({screenArea().topLeft() + geometry.topLeft(), size});
|
||||
}
|
||||
|
||||
QString FloatingWindow::screenName() const
|
||||
@@ -70,26 +47,36 @@ QString FloatingWindow::screenName() const
|
||||
return m_window->screen()->name();
|
||||
}
|
||||
|
||||
void FloatingWindow::moveBy(qreal dx, qreal dy)
|
||||
{
|
||||
const QPoint position = clamped(m_position + QPoint(qRound(dx), qRound(dy)), m_window->size());
|
||||
if (position == m_position)
|
||||
return;
|
||||
m_position = position;
|
||||
apply();
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
void FloatingWindow::resizeBy(qreal dw, qreal dh)
|
||||
{
|
||||
const QSize maximum = screenArea().size() - QSize(m_position.x(), m_position.y());
|
||||
const QSize size = (m_window->size() + QSize(qRound(dw), qRound(dh)))
|
||||
.expandedTo(m_window->minimumSize())
|
||||
.boundedTo(maximum);
|
||||
if (size == m_window->size())
|
||||
return;
|
||||
.boundedTo(screenArea().size());
|
||||
m_window->resize(size);
|
||||
Q_EMIT geometryChanged();
|
||||
}
|
||||
|
||||
void FloatingWindow::moveResize(const QRectF &relative, bool keepOnScreen)
|
||||
{
|
||||
runKWinScript(QStringLiteral(R"(
|
||||
for (const w of workspace.windowList()) {
|
||||
if (w.resourceClass !== "%1")
|
||||
continue;
|
||||
const width = %4, height = %5;
|
||||
let x = w.frameGeometry.x + %2, y = w.frameGeometry.y + %3;
|
||||
if (%6) {
|
||||
const area = workspace.clientArea(KWin.MaximizeArea, w);
|
||||
x = Math.max(area.x, Math.min(x, area.x + area.width - width));
|
||||
y = Math.max(area.y, Math.min(y, area.y + area.height - height));
|
||||
}
|
||||
w.frameGeometry = {x: x, y: y, width: width, height: height};
|
||||
}
|
||||
)")
|
||||
.arg(QGuiApplication::desktopFileName())
|
||||
.arg(relative.x())
|
||||
.arg(relative.y())
|
||||
.arg(relative.width())
|
||||
.arg(relative.height())
|
||||
.arg(keepOnScreen ? QStringLiteral("true") : QStringLiteral("false")));
|
||||
}
|
||||
|
||||
void FloatingWindow::setInputRegion(const QRectF ®ion)
|
||||
@@ -108,6 +95,30 @@ void FloatingWindow::setBlurRegion(const QRectF ®ion, qreal radius)
|
||||
KWindowEffects::enableBlurBehind(m_window, true, QRegion(path.toFillPolygon().toPolygon()));
|
||||
}
|
||||
|
||||
void FloatingWindow::startMove()
|
||||
{
|
||||
if (m_window->startSystemMove())
|
||||
releaseMouse();
|
||||
}
|
||||
|
||||
void FloatingWindow::startResize(Qt::Edges edges)
|
||||
{
|
||||
if (m_window->startSystemResize(edges))
|
||||
releaseMouse();
|
||||
}
|
||||
|
||||
// After a system move/resize the window never gets the mouse release. Send
|
||||
// one, otherwise the pressed item keeps the mouse grab and swallows the next press.
|
||||
void FloatingWindow::releaseMouse()
|
||||
{
|
||||
if (!(QGuiApplication::mouseButtons() & Qt::LeftButton))
|
||||
return; // touch
|
||||
const QPointF global = QCursor::pos(m_window->screen());
|
||||
QMouseEvent release(QEvent::MouseButtonRelease, m_window->mapFromGlobal(global), global, Qt::LeftButton,
|
||||
Qt::NoButton, QGuiApplication::keyboardModifiers());
|
||||
QCoreApplication::sendEvent(m_window, &release);
|
||||
}
|
||||
|
||||
void FloatingWindow::show()
|
||||
{
|
||||
m_window->setVisible(true);
|
||||
@@ -122,26 +133,3 @@ QRect FloatingWindow::screenArea() const
|
||||
{
|
||||
return m_window->screen()->geometry();
|
||||
}
|
||||
|
||||
QPoint FloatingWindow::clamped(QPoint position, QSize size) const
|
||||
{
|
||||
const QRect area = screenArea();
|
||||
const int maxX = qMax(0, area.width() - size.width());
|
||||
const int maxY = qMax(0, area.height() - size.height());
|
||||
return {qBound(0, position.x(), maxX), qBound(0, position.y(), maxY)};
|
||||
}
|
||||
|
||||
QPoint FloatingWindow::defaultPosition() const
|
||||
{
|
||||
const QRect area = screenArea();
|
||||
return clamped({(area.width() - m_window->width()) / 2, area.height() - m_window->height() - BottomGap},
|
||||
m_window->size());
|
||||
}
|
||||
|
||||
void FloatingWindow::apply()
|
||||
{
|
||||
if (m_layerSurface)
|
||||
m_layerSurface->setMargins({m_position.x(), m_position.y(), 0, 0});
|
||||
else
|
||||
m_window->setPosition(screenArea().topLeft() + m_position);
|
||||
}
|
||||
|
||||
+19
-16
@@ -4,15 +4,14 @@
|
||||
#include <QRect>
|
||||
#include <QRectF>
|
||||
|
||||
class QScreen;
|
||||
class QWindow;
|
||||
namespace LayerShellQt { class Window; }
|
||||
|
||||
// Places a keyboard window as a free-floating overlay that never takes focus.
|
||||
// On Wayland: a layer-shell surface anchored top-left, positioned via margins.
|
||||
// On X11: a frameless, non-focusable, always-on-top tool window.
|
||||
// Geometry is relative to the window's screen and always kept on it, also
|
||||
// when the screen's resolution changes or the window moves to another one.
|
||||
// Makes the keyboard window frameless, always on top and never focused.
|
||||
// The window manager places and moves it (including Super+drag); on KWin
|
||||
// Wayland this needs the rule from installKWinRule().
|
||||
// On each show, the window is moved back onto the screen: KWin restores the
|
||||
// last position, which may be off-screen at the current size.
|
||||
// Geometry is relative to the window's screen.
|
||||
class FloatingWindow : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -22,32 +21,36 @@ public:
|
||||
explicit FloatingWindow(QWindow *window, QObject *parent = nullptr);
|
||||
|
||||
QRect geometry() const;
|
||||
// Wayland clients can't place themselves: only the size applies there.
|
||||
void setGeometry(const QRect &geometry);
|
||||
QString screenName() const;
|
||||
|
||||
Q_INVOKABLE void moveBy(qreal dx, qreal dy);
|
||||
// Grows from the top-left corner; respects the window's minimum size.
|
||||
Q_INVOKABLE void resizeBy(qreal dw, qreal dh);
|
||||
// Moves the window by `relative`'s offset and resizes it to `relative`'s
|
||||
// size, optionally clamped to the screen's available area. Done by KWin
|
||||
// (Wayland clients can't position themselves), so it's asynchronous.
|
||||
void moveResize(const QRectF &relative, bool keepOnScreen);
|
||||
// Only this part of the window takes input; the rest passes through.
|
||||
Q_INVOKABLE void setInputRegion(const QRectF ®ion);
|
||||
// Asks the compositor to blur behind this rounded rect; an empty rect turns blur off.
|
||||
Q_INVOKABLE void setBlurRegion(const QRectF ®ion, qreal radius);
|
||||
// The window manager's move and resize, for mouse and touch alike.
|
||||
Q_INVOKABLE void startMove();
|
||||
Q_INVOKABLE void startResize(Qt::Edges edges);
|
||||
Q_INVOKABLE void show();
|
||||
Q_INVOKABLE void hide();
|
||||
|
||||
Q_SIGNALS:
|
||||
// Only for user-initiated changes (move/resize), not for restores.
|
||||
void geometryChanged();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
QRect screenArea() const;
|
||||
QPoint clamped(QPoint position, QSize size) const;
|
||||
QPoint defaultPosition() const;
|
||||
void apply();
|
||||
void followScreen(QScreen *screen);
|
||||
void releaseMouse();
|
||||
|
||||
QWindow *m_window;
|
||||
LayerShellQt::Window *m_layerSurface = nullptr;
|
||||
QPoint m_position;
|
||||
QScreen *m_screen = nullptr;
|
||||
bool m_exposed = false;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "KWinRule.h"
|
||||
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusPendingCall>
|
||||
|
||||
namespace {
|
||||
|
||||
const QString RuleName = QStringLiteral("sloposk");
|
||||
|
||||
// KWin rule policies.
|
||||
constexpr auto Force = "2";
|
||||
constexpr auto Remember = "4";
|
||||
|
||||
bool writeEntry(KConfigGroup &group, const QString &key, const QString &value)
|
||||
{
|
||||
if (group.readEntry(key, QString()) == value)
|
||||
return false;
|
||||
group.writeEntry(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void installKWinRule(const QString &appId)
|
||||
{
|
||||
KConfig config(QStringLiteral("kwinrulesrc"), KConfig::NoGlobals);
|
||||
KConfigGroup rule = config.group(RuleName);
|
||||
const QList<std::pair<QString, QString>> entries = {
|
||||
{QStringLiteral("Description"), QStringLiteral("sloposk keyboard: on top, never focused, remembered position")},
|
||||
{QStringLiteral("wmclass"), appId},
|
||||
{QStringLiteral("wmclassmatch"), QStringLiteral("1")}, // exact
|
||||
{QStringLiteral("wmclasscomplete"), QStringLiteral("false")},
|
||||
{QStringLiteral("above"), QStringLiteral("true")},
|
||||
{QStringLiteral("aboverule"), QString::fromLatin1(Force)},
|
||||
{QStringLiteral("acceptfocus"), QStringLiteral("false")},
|
||||
{QStringLiteral("acceptfocusrule"), QString::fromLatin1(Force)},
|
||||
{QStringLiteral("skiptaskbar"), QStringLiteral("true")},
|
||||
{QStringLiteral("skiptaskbarrule"), QString::fromLatin1(Force)},
|
||||
{QStringLiteral("skippager"), QStringLiteral("true")},
|
||||
{QStringLiteral("skippagerrule"), QString::fromLatin1(Force)},
|
||||
{QStringLiteral("skipswitcher"), QStringLiteral("true")},
|
||||
{QStringLiteral("skipswitcherrule"), QString::fromLatin1(Force)},
|
||||
{QStringLiteral("positionrule"), QString::fromLatin1(Remember)},
|
||||
};
|
||||
bool changed = false;
|
||||
for (const auto &[key, value] : entries)
|
||||
changed |= writeEntry(rule, key, value);
|
||||
|
||||
KConfigGroup general = config.group(QStringLiteral("General"));
|
||||
QStringList rules = general.readEntry("rules", QStringList());
|
||||
if (!rules.contains(RuleName)) {
|
||||
rules.append(RuleName);
|
||||
general.writeEntry("rules", rules);
|
||||
general.writeEntry("count", rules.size());
|
||||
changed = true;
|
||||
}
|
||||
if (!changed)
|
||||
return;
|
||||
config.sync();
|
||||
QDBusConnection::sessionBus().asyncCall(QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.kde.KWin"), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("reconfigure")));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
// Adds (or repairs) a KWin window rule for the keyboard's app id in
|
||||
// kwinrulesrc: keep above, never take focus, skip taskbar/pager/switcher,
|
||||
// remember the position. Wayland gives clients no other way to stay
|
||||
// unfocused. Reloads KWin's rules when anything changed.
|
||||
void installKWinRule(const QString &appId);
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "KWinScript.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusPendingCallWatcher>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QDir>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTimer>
|
||||
#include <memory>
|
||||
|
||||
namespace {
|
||||
|
||||
const QString Service = QStringLiteral("org.kde.KWin");
|
||||
const QString ScriptingPath = QStringLiteral("/Scripting");
|
||||
const QString ScriptingInterface = QStringLiteral("org.kde.kwin.Scripting");
|
||||
|
||||
// KWin reads the file on a worker thread some time after `run`.
|
||||
constexpr int KeepFileMs = 10'000;
|
||||
|
||||
QDBusMessage kwinCall(const QString &path, const QString &interface, const QString &method, const QVariantList &args = {})
|
||||
{
|
||||
QDBusMessage call = QDBusMessage::createMethodCall(Service, path, interface, method);
|
||||
call.setArguments(args);
|
||||
return call;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void runKWinScript(const QString &source)
|
||||
{
|
||||
static int count = 0;
|
||||
const QString plugin = QStringLiteral("sloposk-%1").arg(++count);
|
||||
// The script unloads itself: calling `stop` right after `run` could unload it before it runs.
|
||||
const QString unload = QStringLiteral("\ncallDBus(\"%1\", \"%2\", \"%3\", \"unloadScript\", \"%4\");\n")
|
||||
.arg(Service, ScriptingPath, ScriptingInterface, plugin);
|
||||
|
||||
auto file = std::make_shared<QTemporaryFile>(QDir::tempPath() + QStringLiteral("/sloposk-XXXXXX.js"));
|
||||
if (!file->open() || file->write((source + unload).toUtf8()) < 0 || !file->flush()) {
|
||||
qWarning("Can't write a KWin script: %s", qPrintable(file->errorString()));
|
||||
return;
|
||||
}
|
||||
auto *watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(
|
||||
kwinCall(ScriptingPath, ScriptingInterface, QStringLiteral("loadScript"), {file->fileName(), plugin})));
|
||||
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, [file](QDBusPendingCallWatcher *watcher) {
|
||||
watcher->deleteLater();
|
||||
const QDBusPendingReply<int> reply = *watcher;
|
||||
if (reply.isError() || reply.value() < 0) {
|
||||
qWarning("KWin didn't load a script: %s", qPrintable(reply.error().message()));
|
||||
return;
|
||||
}
|
||||
const QString path = ScriptingPath + QStringLiteral("/Script") + QString::number(reply.value());
|
||||
QDBusConnection::sessionBus().asyncCall(kwinCall(path, QStringLiteral("org.kde.kwin.Script"), QStringLiteral("run")));
|
||||
QTimer::singleShot(KeepFileMs, [file] {});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
// Runs a one-off KWin script (JavaScript) over D-Bus; it unloads itself when
|
||||
// done. Asynchronous; failures are only logged.
|
||||
void runKWinScript(const QString &source);
|
||||
@@ -7,6 +7,12 @@ void VisibilityController::setFieldActive(bool active)
|
||||
update();
|
||||
}
|
||||
|
||||
void VisibilityController::setShowOnField(bool show)
|
||||
{
|
||||
m_showOnField = show;
|
||||
update();
|
||||
}
|
||||
|
||||
void VisibilityController::setStandalone(bool standalone)
|
||||
{
|
||||
m_standalone = standalone;
|
||||
@@ -20,6 +26,13 @@ void VisibilityController::setAlwaysVisible(bool always)
|
||||
update();
|
||||
}
|
||||
|
||||
void VisibilityController::setEnabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
m_override.reset();
|
||||
update();
|
||||
}
|
||||
|
||||
void VisibilityController::show()
|
||||
{
|
||||
m_override = true;
|
||||
@@ -40,7 +53,8 @@ void VisibilityController::toggle()
|
||||
|
||||
void VisibilityController::update()
|
||||
{
|
||||
const bool visible = m_override.value_or(m_alwaysVisible || m_standalone || m_fieldActive);
|
||||
const bool visible =
|
||||
m_enabled && m_override.value_or(m_alwaysVisible || m_standalone || (m_fieldActive && m_showOnField));
|
||||
if (visible == m_visible)
|
||||
return;
|
||||
m_visible = visible;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <QObject>
|
||||
#include <optional>
|
||||
|
||||
// Decides whether the keyboard is shown:
|
||||
// - while a text field is focused
|
||||
// - always, if the user wants it (to type into any window) or when running
|
||||
// standalone (no input-method connection)
|
||||
// - show()/hide()/toggle() override that until the focus changes, also
|
||||
// from one field straight to another
|
||||
// Decides whether the keyboard is visible:
|
||||
// - hidden while the system virtual keyboard toggle is off (overrides everything)
|
||||
// - show()/hide()/toggle() override the rules below until the next focus change
|
||||
// (including focus moving directly from one field to another)
|
||||
// - shown if "always visible" is set, or when standalone (no input-method connection)
|
||||
// - shown while a text field is focused, if KWin's policy allows it
|
||||
class VisibilityController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -18,10 +18,15 @@ public:
|
||||
|
||||
bool isVisible() const { return m_visible; }
|
||||
|
||||
// Called on every focus change, even when a field follows a field.
|
||||
// Call on every focus change, including field-to-field.
|
||||
void setFieldActive(bool active);
|
||||
// Whether KWin's policy (disabled / touch only) allows showing for the focused field.
|
||||
void setShowOnField(bool show);
|
||||
void setStandalone(bool standalone);
|
||||
void setAlwaysVisible(bool always);
|
||||
// System virtual keyboard toggle (KWin tray icon). When false, the keyboard
|
||||
// is always hidden, regardless of the other settings. Clears show()/hide() overrides.
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
void show();
|
||||
void hide();
|
||||
@@ -34,8 +39,10 @@ private:
|
||||
void update();
|
||||
|
||||
bool m_fieldActive = false;
|
||||
bool m_showOnField = true;
|
||||
bool m_standalone = false;
|
||||
bool m_alwaysVisible = false;
|
||||
bool m_enabled = true;
|
||||
std::optional<bool> m_override;
|
||||
bool m_visible = false;
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <QRect>
|
||||
#include <optional>
|
||||
|
||||
// Remembers the keyboard's geometry per screen (~/.config/sloposk.conf).
|
||||
// Saving is debounced so dragging doesn't hammer the disk.
|
||||
// Stores the keyboard's geometry per screen (~/.config/sloposk/sloposk.conf).
|
||||
// Saving is debounced, so dragging doesn't write on every step.
|
||||
class WindowSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -16,6 +16,7 @@ sloposk_add_test(tst_textrules)
|
||||
sloposk_add_test(tst_deadkeys)
|
||||
sloposk_add_test(tst_keyrepeater)
|
||||
sloposk_add_test(tst_visibility)
|
||||
sloposk_add_test(tst_diagnostics)
|
||||
|
||||
# Needs the QML module itself, not just the C++ backing library.
|
||||
sloposk_add_test(tst_keyboardsurface)
|
||||
|
||||
@@ -10,7 +10,7 @@ using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
|
||||
const TextContext Field{.field = true};
|
||||
const TextContext Field{.field = true, .hasSurroundingText = false, .textBeforeCursor = {}}; // reports no text
|
||||
// A field with some text already: no auto-shift until a test asks for it.
|
||||
const TextContext MidSentence{.field = true, .hasSurroundingText = true, .textBeforeCursor = u"so"_s};
|
||||
|
||||
@@ -328,6 +328,29 @@ private Q_SLOTS:
|
||||
QCOMPARE(controller->modifierModes().value(u"alt"_s).toInt(), int(KeyboardController::ShiftMode::Off));
|
||||
}
|
||||
|
||||
void altGrTypesTheThirdLevel()
|
||||
{
|
||||
KeyDef j = makeKey(KeyType::Character, u"j"_s);
|
||||
j.altGr = u"'"_s;
|
||||
tap(modifierKey(u"altgr"_s));
|
||||
tap(j);
|
||||
QCOMPARE(engine.output, u"'");
|
||||
QVERIFY(engine.keysyms.isEmpty()); // text, not an Alt shortcut
|
||||
tap(j); // one-shot
|
||||
QCOMPARE(engine.output, u"'j");
|
||||
}
|
||||
|
||||
void altGrDeadKeyComposes()
|
||||
{
|
||||
KeyDef three = makeKey(KeyType::Character, u"3"_s);
|
||||
three.altGr = u"^"_s;
|
||||
three.deadAltGr = XKB_KEY_dead_circumflex;
|
||||
tap(modifierKey(u"altgr"_s));
|
||||
tap(three);
|
||||
tap(makeKey(KeyType::Character, u"a"_s));
|
||||
QCOMPARE(engine.output, u"â");
|
||||
}
|
||||
|
||||
void tappedShiftAppliesToFunctionKeys()
|
||||
{
|
||||
tap(makeKey(KeyType::Character, u"a"_s)); // mid-sentence: no auto-shift
|
||||
@@ -420,7 +443,7 @@ private Q_SLOTS:
|
||||
QCOMPARE(controller->modifierModes().value(u"ctrl"_s).toInt(), 1);
|
||||
controller->setOptions({}); // turned off while held
|
||||
QVERIFY(engine.held.isEmpty());
|
||||
controller->keyUp(ctrl, KeyOutput::Primary, {}, 10); // back to sticky rules: harmless
|
||||
controller->keyUp(ctrl, KeyOutput::Primary, {}, 10); // released under sticky rules: no effect
|
||||
QVERIFY(engine.held.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "diagnostics/Diagnostics.h"
|
||||
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
class TestDiagnostics : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void reportsAndClears()
|
||||
{
|
||||
Diagnostics diagnostics;
|
||||
QSignalSpy changed(&diagnostics, &Diagnostics::problemsChanged);
|
||||
QTest::ignoreMessage(QtWarningMsg, "broken");
|
||||
diagnostics.check(QStringLiteral("a"), false, QStringLiteral("broken"));
|
||||
QCOMPARE(diagnostics.problems(), QStringList{QStringLiteral("broken")});
|
||||
diagnostics.check(QStringLiteral("a"), true, QStringLiteral("broken"));
|
||||
QVERIFY(diagnostics.problems().isEmpty());
|
||||
QCOMPARE(changed.count(), 2);
|
||||
}
|
||||
|
||||
void repeatsAreQuiet()
|
||||
{
|
||||
Diagnostics diagnostics;
|
||||
QSignalSpy changed(&diagnostics, &Diagnostics::problemsChanged);
|
||||
diagnostics.check(QStringLiteral("a"), true, QStringLiteral("fine"));
|
||||
QTest::ignoreMessage(QtWarningMsg, "broken");
|
||||
diagnostics.check(QStringLiteral("a"), false, QStringLiteral("broken"));
|
||||
diagnostics.check(QStringLiteral("a"), false, QStringLiteral("broken")); // no second warning
|
||||
QCOMPARE(changed.count(), 1);
|
||||
}
|
||||
|
||||
void listsByIdNotArrival()
|
||||
{
|
||||
Diagnostics diagnostics;
|
||||
QTest::ignoreMessage(QtWarningMsg, "second");
|
||||
QTest::ignoreMessage(QtWarningMsg, "first");
|
||||
diagnostics.check(QStringLiteral("b"), false, QStringLiteral("second"));
|
||||
diagnostics.check(QStringLiteral("a"), false, QStringLiteral("first"));
|
||||
QCOMPARE(diagnostics.problems(), (QStringList{QStringLiteral("first"), QStringLiteral("second")}));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(TestDiagnostics)
|
||||
#include "tst_diagnostics.moc"
|
||||
@@ -131,11 +131,11 @@ private Q_SLOTS:
|
||||
QTest::touchEvent(&window, touchscreen).press(0, e);
|
||||
QTest::qWait(LongPressWaitMs);
|
||||
QTest::touchEvent(&window, touchscreen).stationary(0).press(1, u);
|
||||
QTest::qWait(LongPressWaitMs); // u's popup replaces e's, which types its choice
|
||||
QTest::qWait(LongPressWaitMs); // u's popup opens; e's popup closes and types its selection
|
||||
QCOMPARE(engine.output, u"é");
|
||||
QVERIFY(surface->alternates()->isOpen());
|
||||
QTest::touchEvent(&window, touchscreen).release(0, e).stationary(1);
|
||||
QCOMPARE(engine.output, u"é"); // the first finger's lift does nothing more
|
||||
QCOMPARE(engine.output, u"é"); // lifting the first finger types nothing more
|
||||
QVERIFY(surface->alternates()->isOpen());
|
||||
QTest::touchEvent(&window, touchscreen).release(1, u);
|
||||
QCOMPARE(engine.output.size(), 2);
|
||||
@@ -208,6 +208,17 @@ private Q_SLOTS:
|
||||
QCOMPARE(engine.output, QString());
|
||||
QCOMPARE(engine.keysyms, (QList<quint32>{XKB_KEY_Right, XKB_KEY_Right, XKB_KEY_Right}));
|
||||
}
|
||||
|
||||
void spaceSlideMovesCursorAtOnce()
|
||||
{
|
||||
const QPoint space = keyCenter({}, u"space"_s);
|
||||
QTest::touchEvent(&window, touchscreen).press(0, space);
|
||||
QTest::touchEvent(&window, touchscreen).move(0, space - QPoint(30, 0));
|
||||
QVERIFY(!qobject_cast<KeyboardSurface *>(keyboard)->isTrackpadActive()); // keys keep their labels
|
||||
QTest::touchEvent(&window, touchscreen).release(0, space - QPoint(30, 0));
|
||||
QCOMPARE(engine.output, QString());
|
||||
QCOMPARE(engine.keysyms, (QList<quint32>{XKB_KEY_Left, XKB_KEY_Left}));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestKeyboardSurface)
|
||||
|
||||
@@ -15,6 +15,14 @@ KeyDef key(qreal width = 1.0, KeyType type = KeyType::Character)
|
||||
return k;
|
||||
}
|
||||
|
||||
Layer layerOf(const QList<Row> &rows)
|
||||
{
|
||||
Layer layer;
|
||||
layer.name = u"l"_s;
|
||||
layer.rows = rows;
|
||||
return layer;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class TestKeyGeometry : public QObject
|
||||
@@ -24,7 +32,7 @@ class TestKeyGeometry : public QObject
|
||||
private Q_SLOTS:
|
||||
void fillsWidthAndHeight()
|
||||
{
|
||||
const Layer layer{u"l"_s, {{key(), key()}, {key(2)}}};
|
||||
const Layer layer = layerOf({{key(), key()}, {key(2)}});
|
||||
const KeyboardMetrics metrics{.padding = 10, .gap = 10};
|
||||
const auto rects = computeKeyRects(layer, {210, 110}, metrics);
|
||||
|
||||
@@ -36,7 +44,7 @@ private Q_SLOTS:
|
||||
|
||||
void spacersShiftFollowingKeys()
|
||||
{
|
||||
const Layer layer{u"l"_s, {{key(), key(), key()}, {key(0.5, KeyType::Spacer), key(), key(1.5)}}};
|
||||
const Layer layer = layerOf({{key(), key(), key()}, {key(0.5, KeyType::Spacer), key(), key(1.5)}});
|
||||
const auto rects = computeKeyRects(layer, {300, 100}, {.padding = 0, .gap = 0});
|
||||
QCOMPARE(rects[4].left(), 50.0);
|
||||
QCOMPARE(rects[5].right(), 300.0);
|
||||
@@ -44,7 +52,7 @@ private Q_SLOTS:
|
||||
|
||||
void shorterRowsAreCentered()
|
||||
{
|
||||
const Layer layer{u"l"_s, {{key(), key(), key(), key()}, {key(), key()}}};
|
||||
const Layer layer = layerOf({{key(), key(), key(), key()}, {key(), key()}});
|
||||
const auto rects = computeKeyRects(layer, {400, 100}, {.padding = 0, .gap = 0});
|
||||
QCOMPARE(rects[4].left(), 100.0);
|
||||
QCOMPARE(rects[5].right(), 300.0);
|
||||
@@ -54,7 +62,7 @@ private Q_SLOTS:
|
||||
{
|
||||
KeyDef wide = key();
|
||||
wide.stretch = true;
|
||||
const Layer layer{u"l"_s, {{key(), key(), key(), key()}, {key(), wide}}};
|
||||
const Layer layer = layerOf({{key(), key(), key(), key()}, {key(), wide}});
|
||||
const auto rects = computeKeyRects(layer, {400, 100}, {.padding = 0, .gap = 0});
|
||||
QCOMPARE(rects[4].left(), 0.0);
|
||||
QCOMPARE(rects[5].width(), 300.0);
|
||||
|
||||
@@ -127,7 +127,7 @@ private Q_SLOTS:
|
||||
void fullModeKeepsDeadKeysAndKeymapShift()
|
||||
{
|
||||
const Layout sk = TestLayouts::build("sk", KeyboardMode::Full);
|
||||
const KeyDef ´ = letterKey(sk, u"´"_s);
|
||||
const KeyDef acute = letterKey(sk, u"´"_s);
|
||||
QCOMPARE(acute.dead, quint32(XKB_KEY_dead_acute));
|
||||
QCOMPARE(acute.deadShifted, quint32(XKB_KEY_dead_caron));
|
||||
QCOMPARE(letterKey(sk, u"ô"_s).shifted, u"\""); // as the physical key
|
||||
@@ -137,6 +137,19 @@ private Q_SLOTS:
|
||||
QCOMPARE(letterKey(sk, u"l"_s).alternates.first(), u"ľ");
|
||||
}
|
||||
|
||||
void fullModeLettersFlickToTheirAltGrSymbol()
|
||||
{
|
||||
const Layout sk = TestLayouts::build("sk", KeyboardMode::Full);
|
||||
const KeyDef j = letterKey(sk, u"j"_s);
|
||||
QCOMPARE(j.altGr, u"'");
|
||||
QCOMPARE(j.flick, u"'");
|
||||
QCOMPARE(j.text({ShiftLevel::None, true}), u"'");
|
||||
QCOMPARE(letterKey(sk, u"ô"_s).flick, u"\""); // keys with a shifted symbol keep it
|
||||
const KeyDef plus = letterKey(sk, u"+"_s);
|
||||
QCOMPARE(plus.deadAt({ShiftLevel::Shifted, true}), quint32(XKB_KEY_dead_tilde));
|
||||
QCOMPARE(plus.text({ShiftLevel::None, true}), u"!");
|
||||
}
|
||||
|
||||
void noPlaceholdersRemain()
|
||||
{
|
||||
for (const Layer &layer : TestLayouts::build("us").layers) {
|
||||
|
||||
@@ -111,6 +111,33 @@ private Q_SLOTS:
|
||||
QCOMPARE(t.takeTrackpadSteps(), QPoint(-3, -1));
|
||||
}
|
||||
|
||||
void spaceSlideSidewaysMovesAlongTheLine()
|
||||
{
|
||||
PointerTracker t(ofType(KeyType::Space), {100, 0}, config());
|
||||
t.moveTo({112, 5});
|
||||
QCOMPARE(t.gesture(), Gesture::Trackpad);
|
||||
QCOMPARE(t.takeTrackpadSteps(), QPoint(1, 0)); // the slop counts
|
||||
t.moveTo({75, -50});
|
||||
QCOMPARE(t.takeTrackpadSteps(), QPoint(-3, 0)); // no line changes
|
||||
QVERIFY(!t.longPressElapsed());
|
||||
}
|
||||
|
||||
void spaceSlideVerticallyStaysTap()
|
||||
{
|
||||
PointerTracker t(ofType(KeyType::Space), {100, 0}, config());
|
||||
t.moveTo({105, -20});
|
||||
QCOMPARE(t.gesture(), Gesture::Tap);
|
||||
}
|
||||
|
||||
void spaceSlideNeedsGestures()
|
||||
{
|
||||
PointerTracker::Config c = config();
|
||||
c.gestures = false;
|
||||
PointerTracker t(ofType(KeyType::Space), {100, 0}, c);
|
||||
t.moveTo({140, 0});
|
||||
QCOMPARE(t.gesture(), Gesture::Tap);
|
||||
}
|
||||
|
||||
void layerKeySlides()
|
||||
{
|
||||
PointerTracker t(ofType(KeyType::LayerSwitch), {0, 0}, config());
|
||||
|
||||
@@ -16,6 +16,19 @@ private Q_SLOTS:
|
||||
QVERIFY(!v.isVisible());
|
||||
}
|
||||
|
||||
void fieldShowsOnlyWhenTheSystemWantsIt()
|
||||
{
|
||||
VisibilityController v;
|
||||
v.setShowOnField(false);
|
||||
v.setFieldActive(true);
|
||||
QVERIFY(!v.isVisible());
|
||||
v.show(); // explicit requests still work
|
||||
QVERIFY(v.isVisible());
|
||||
v.setShowOnField(true);
|
||||
v.setFieldActive(true);
|
||||
QVERIFY(v.isVisible());
|
||||
}
|
||||
|
||||
void dismissLastsUntilFocusChanges()
|
||||
{
|
||||
VisibilityController v;
|
||||
@@ -57,6 +70,19 @@ private Q_SLOTS:
|
||||
QVERIFY(!v.isVisible());
|
||||
}
|
||||
|
||||
void systemToggleGatesEverything()
|
||||
{
|
||||
VisibilityController v;
|
||||
v.setAlwaysVisible(true);
|
||||
v.setEnabled(false);
|
||||
QVERIFY(!v.isVisible());
|
||||
v.show();
|
||||
QVERIFY(!v.isVisible());
|
||||
v.hide();
|
||||
v.setEnabled(true); // re-enabling clears the earlier hide()
|
||||
QVERIFY(v.isVisible());
|
||||
}
|
||||
|
||||
void standaloneAlwaysVisible()
|
||||
{
|
||||
VisibilityController v;
|
||||
|
||||
Reference in New Issue
Block a user