KeyboardLayout: update on keyboard layout change events (niri)

This commit is contained in:
Ala Alkhafaji
2025-11-10 21:33:33 +01:00
parent 36d9dabb02
commit 9921e1a09f
2 changed files with 37 additions and 19 deletions
+6 -19
View File
@@ -25,24 +25,6 @@ Singleton {
}
}
// Process to get current keyboard layout using niri msg (Wayland native)
Process {
id: niriLayoutProcess
running: false
command: ["niri", "msg", "-j", "keyboard-layouts"]
stdout: StdioCollector {
onStreamFinished: {
try {
const data = JSON.parse(text)
const layoutName = data.names[data.current_idx]
root.currentLayout = extractLayoutCode(layoutName)
} catch (e) {
root.currentLayout = I18n.tr("system.unknown-layout")
}
}
}
}
// Process to get current keyboard layout using hyprctl (Hyprland)
Process {
id: hyprlandLayoutProcess
@@ -170,6 +152,11 @@ Singleton {
localectlProcess.running = true
}
// Updates current layout from various format strings. Called by compositors
function setCurrentLayout(layoutString) {
root.currentLayout = extractLayoutCode(layoutString)
}
// Extract layout code from various format strings using Commons data
function extractLayoutCode(layoutString) {
if (!layoutString)
@@ -244,7 +231,7 @@ Singleton {
if (CompositorService.isHyprland) {
hyprlandLayoutProcess.running = true
} else if (CompositorService.isNiri) {
niriLayoutProcess.running = true
// do nothing, niri calls setCurrentLayout
} else {
// Try detection methods in order of preference
if (Qt.platform.os === "linux") {