Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||
|
||||
// A small on/off button in the grab bar; lit while on. The icon goes inside
|
||||
// and should draw in `foreground`.
|
||||
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.
|
||||
// The grab bar under the floating keyboard. Moving the window is up to the
|
||||
// owner (the window manager's move, so it works for mouse and touch alike).
|
||||
Item {
|
||||
id: handle
|
||||
|
||||
signal moved(real dx, real dy)
|
||||
// Narrower when the bar's buttons leave less room in the middle.
|
||||
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
|
||||
|
||||
// The dismiss key left floating while the keyboard is shrunk; see-through so
|
||||
// it hides less. Tap to bring the keyboard back; dragging is up to the owner
|
||||
// (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
|
||||
// The move ends with a release that would otherwise count 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+42
-6
@@ -7,7 +7,10 @@ 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.
|
||||
readonly property real keysHeight: keyboard.height
|
||||
@@ -15,23 +18,31 @@ Window {
|
||||
// Transparent room above the keyboard for long-press popups on the top row.
|
||||
readonly property real popupMargin: 90
|
||||
// Outside this, input passes through to whatever is below the window.
|
||||
readonly property rect inputRegion: keyboard.alternates.open
|
||||
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
|
||||
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
|
||||
// None while shrunk to the floating button.
|
||||
minimumWidth: collapsed ? 0 : 480
|
||||
minimumHeight: collapsed ? 0 : 180 + popupMargin
|
||||
visible: false
|
||||
color: "transparent"
|
||||
|
||||
onInputRegionChanged: placement?.setInputRegion(inputRegion)
|
||||
onBlurRegionChanged: placement?.setBlurRegion(blurRegion, Theme.windowRadius)
|
||||
// For CollapseController.
|
||||
function dismissKeyRect() {
|
||||
return keyboard.keyRect("dismiss");
|
||||
}
|
||||
|
||||
onPlacementChanged: {
|
||||
placement?.setInputRegion(inputRegion);
|
||||
placement?.setBlurRegion(blurRegion, Theme.windowRadius);
|
||||
@@ -40,6 +51,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 +70,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)
|
||||
// Over the key while the window is full size, then in the shrunk window.
|
||||
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
|
||||
|
||||
// One-tap switches for the most changed key options, beside the gear.
|
||||
// Icons are drawn from boxes so they don't depend on the fonts installed.
|
||||
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 one of the template's optional sections; absent from
|
||||
// layouts without it.
|
||||
component SectionToggle: BarToggle {
|
||||
required property string section
|
||||
|
||||
visible: toggles.hasSection(section)
|
||||
checked: toggles.settings.visibleSections.includes(section)
|
||||
onToggled: checked => toggles.settings.setSectionVisible(section, checked)
|
||||
}
|
||||
|
||||
// A grid of tiny keys, optionally in 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A key outline with a label on it.
|
||||
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
|
||||
// A fingertip resting on a key, holding it down.
|
||||
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")
|
||||
// The inverted T of the arrow keys.
|
||||
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. Resizing is up to the owner (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
|
||||
// The grab bar lies underneath and would take the drag over.
|
||||
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
|
||||
// Something doesn't work (see Diagnostics): a dot invites a look in settings.
|
||||
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()
|
||||
|
||||
+24
-4
@@ -8,18 +8,29 @@ Flickable {
|
||||
|
||||
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")
|
||||
@@ -107,4 +126,5 @@ Flickable {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 globals KWin already announced on construction, so the first
|
||||
// check is final unless 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,14 @@
|
||||
#pragma once
|
||||
|
||||
class Diagnostics;
|
||||
class KWinInputMethod;
|
||||
class SystemLayouts;
|
||||
|
||||
// Reports to `diagnostics` what this session doesn't allow, and keeps the
|
||||
// reports current as protocols and services come and go.
|
||||
// KWin offers the input-method global to every client but only activates
|
||||
// the process it launched, which it hands a connection: `launchedByKWin` is
|
||||
// whether WAYLAND_SOCKET was set at startup.
|
||||
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,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <functional>
|
||||
|
||||
// KWin's virtual keyboard policy (the tray toggle, System Settings →
|
||||
// Virtual Keyboard): KWin activates the input method for every text field
|
||||
// and the policy only gates its input panel, which sloposk doesn't use, so
|
||||
// sloposk asks it over org.kde.KWin /VirtualKeyboard instead.
|
||||
class KWinVirtualKeyboard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KWinVirtualKeyboard(QObject *parent = nullptr);
|
||||
|
||||
// Calls `answer` with whether a field focused now should show the
|
||||
// keyboard: never when it's off, only after touch or a pen in the
|
||||
// default mode. True if KWin can't be asked.
|
||||
void askShowOnActive(QObject *context, std::function<void(bool)> answer);
|
||||
|
||||
Q_SIGNALS:
|
||||
void modeChanged();
|
||||
};
|
||||
@@ -27,7 +27,7 @@ SystemLayouts::SystemLayouts(QObject *parent)
|
||||
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)
|
||||
|
||||
@@ -19,12 +19,15 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentChanged();
|
||||
// After each attempt to reach the service, and when it goes away.
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
// keyboard_keysym, which everything here uses, needs this version.
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
// 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;
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ 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
|
||||
// system's key repeat). Shift, Ctrl, Alt, Super and AltGr 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.
|
||||
class HardwareKeys
|
||||
@@ -25,11 +25,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 and AltGr shown while held, caps lock while on.
|
||||
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:
|
||||
|
||||
@@ -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,7 +68,7 @@ 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()) {
|
||||
@@ -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)
|
||||
@@ -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();
|
||||
@@ -227,7 +227,12 @@ void KeyboardController::typeCharacter(const KeyDef &key, KeyOutput output, cons
|
||||
return;
|
||||
}
|
||||
|
||||
const ShiftLevel level = shiftLevel();
|
||||
const KeyLevel level = keyLevel();
|
||||
if (level.altGr) {
|
||||
// Used up by this key, 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(); });
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ enum class KeyOutput { Primary, Flick, Alternate };
|
||||
// receives key presses and text-field context, and talks 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
|
||||
// modifiers) instead of text; AltGr instead types a key's AltGr symbol. 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.
|
||||
class KeyboardController : public QObject
|
||||
@@ -34,7 +34,7 @@ class KeyboardController : public QObject
|
||||
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:
|
||||
@@ -78,10 +78,12 @@ private:
|
||||
// Sends a non-text key or shortcut with the active modifiers, then uses them up.
|
||||
void sendKey(quint32 keysym);
|
||||
Qt::KeyboardModifiers shortcutModifiers() const;
|
||||
ShiftLevel shiftLevel() const;
|
||||
KeyLevel keyLevel() const;
|
||||
// Hold-keys mode: forwards the key to m_hardware; false if it isn't one it presses.
|
||||
bool holdKey(const KeyDef &key, bool pressed);
|
||||
void useModifiers();
|
||||
// The modifiers changed: refreshes the labels and tells the view.
|
||||
void modifiersUpdated();
|
||||
void deleteBackward(bool wholeWord);
|
||||
void sendRepeatedKeysym();
|
||||
void stopRepeating(const KeyDef &key);
|
||||
|
||||
@@ -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, hold while typing with another finger.
|
||||
// The first three turn keys into shortcuts; AltGr picks 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.
|
||||
void keyTyped();
|
||||
void clear();
|
||||
|
||||
// Ctrl, Alt and Super: what makes 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())) {
|
||||
// From the press point: the slop 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;
|
||||
}
|
||||
@@ -63,7 +69,8 @@ QPoint PointerTracker::takeTrackpadSteps()
|
||||
|
||||
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));
|
||||
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;
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
// Tap pressed, not (yet) anything else
|
||||
// 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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
+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>;
|
||||
|
||||
@@ -34,6 +34,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -54,7 +58,8 @@ 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.
|
||||
// A full row: every typing key, the shifted symbol shown (and flickable) above;
|
||||
// for letters, whose shift only capitalizes, the AltGr symbol (sk: ' on j).
|
||||
// `withLessGreater` tells whether the ISO key left of Z is among them.
|
||||
QList<KeyDef> rowKeys(const KeymapKeys &keymap, int row, bool *withLessGreater)
|
||||
{
|
||||
@@ -76,6 +81,8 @@ QList<KeyDef> rowKeys(const KeymapKeys &keymap, int row, bool *withLessGreater)
|
||||
// Show (and flick for) a shifted level that isn't 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;
|
||||
|
||||
@@ -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);
|
||||
// A shifted or AltGr key may already show its flick symbol (! on 1): don't repeat it.
|
||||
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});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+61
-13
@@ -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"
|
||||
|
||||
@@ -78,17 +83,44 @@ void connectKeySettings(Settings &settings, LayoutModel &model, FloatingWindow &
|
||||
[keepingKeySize, rebuild] { keepingKeySize(rebuild); });
|
||||
}
|
||||
|
||||
void restoreAndPersistGeometry(FloatingWindow &placement, WindowSettings &settings)
|
||||
// The shrunk button's geometry isn't the keyboard's: not saved.
|
||||
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());
|
||||
});
|
||||
}
|
||||
|
||||
// A focused field shows the keyboard only if KWin's policy wants one now;
|
||||
// asked before showing, so a "no" doesn't flash the keyboard.
|
||||
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; // left the field 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)
|
||||
{
|
||||
// First, so the initial state below reaches the window too.
|
||||
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()); });
|
||||
@@ -96,14 +128,19 @@ void connectVisibility(VisibilityController &visibility, KWinInputMethod &backen
|
||||
// work) there is no focus signal: stay visible so it can be tried out.
|
||||
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,6 +154,8 @@ void connectTextContext(KWinInputMethod &backend, KeyboardController &controller
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
blockQuitSignals();
|
||||
// libwayland unsets it once connected.
|
||||
const bool launchedByKWin = qEnvironmentVariableIsSet("WAYLAND_SOCKET");
|
||||
QGuiApplication app(argc, argv);
|
||||
quitOnSignal();
|
||||
QGuiApplication::setApplicationName(QStringLiteral("sloposk"));
|
||||
@@ -129,7 +168,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 +182,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 +192,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 +201,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();
|
||||
|
||||
@@ -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)
|
||||
@@ -49,6 +51,8 @@ public:
|
||||
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();
|
||||
// After the next frame, once the compositor knows the lower minimum size.
|
||||
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(); // never shrank: nothing to move
|
||||
return;
|
||||
}
|
||||
// Stays collapsed until the window has grown, so the keys don't flash 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); // no KWin to do it
|
||||
m_collapsed = false;
|
||||
Q_EMIT collapsedChanged();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QRectF>
|
||||
#include <QSize>
|
||||
#include <QTimer>
|
||||
|
||||
class FloatingWindow;
|
||||
class QQuickWindow;
|
||||
|
||||
// Shrinks the keyboard window to just its dismiss key, floating on its own,
|
||||
// and grows it back with the key under the button again (kept on screen).
|
||||
// The window itself shrinks, so it can be dragged anywhere and covers
|
||||
// nothing else. QML draws from `collapsed` and `keyRect`.
|
||||
class CollapseController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool collapsed READ isCollapsed NOTIFY collapsedChanged)
|
||||
// The key in the full window; the button stays there until the window shrinks.
|
||||
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; // waits for KWin; runs out without it
|
||||
};
|
||||
@@ -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 means mapped, so KWin knows the window by now.
|
||||
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();
|
||||
}
|
||||
|
||||
// The window manager keeps the button's release: without one, the pressed
|
||||
// item holds on to the mouse and eats 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 a keyboard window a frameless, always-on-top window that never takes
|
||||
// focus. The window manager places it and moves it (Super+drag included);
|
||||
// on KWin Wayland that relies on the rule from installKWinRule().
|
||||
// Each time it appears, it's moved back on screen: KWin remembers where it
|
||||
// was, which may be somewhere it was smaller. 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 its size,
|
||||
// optionally clamped to the screen's free area. Done by KWin (Wayland
|
||||
// clients can't place themselves), so it applies later.
|
||||
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);
|
||||
// Unloading from within: `stop` right after `run` could beat the script.
|
||||
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;
|
||||
@@ -40,7 +46,7 @@ void VisibilityController::toggle()
|
||||
|
||||
void VisibilityController::update()
|
||||
{
|
||||
const bool visible = m_override.value_or(m_alwaysVisible || m_standalone || m_fieldActive);
|
||||
const bool visible = m_override.value_or(m_alwaysVisible || m_standalone || (m_fieldActive && m_showOnField));
|
||||
if (visible == m_visible)
|
||||
return;
|
||||
m_visible = visible;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <optional>
|
||||
|
||||
// Decides whether the keyboard is shown:
|
||||
// - while a text field is focused
|
||||
// - while a text field is focused, if the system wants a keyboard for it
|
||||
// - 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
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
|
||||
// Called on every focus change, even when a field follows a field.
|
||||
void setFieldActive(bool active);
|
||||
// KWin's policy (off, or touch only) for fields focused from now on.
|
||||
void setShowOnField(bool show);
|
||||
void setStandalone(bool standalone);
|
||||
void setAlwaysVisible(bool always);
|
||||
|
||||
@@ -34,6 +36,7 @@ private:
|
||||
void update();
|
||||
|
||||
bool m_fieldActive = false;
|
||||
bool m_showOnField = true;
|
||||
bool m_standalone = false;
|
||||
bool m_alwaysVisible = false;
|
||||
std::optional<bool> m_override;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user