KeyboardLayout: add toast to inform the user about changed layout

This commit is contained in:
Ly-sec
2025-11-10 18:21:47 +01:00
parent 5f50bad53b
commit 54f8b3574d
9 changed files with 68 additions and 10 deletions
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Deaktiviert",
"enabled": "Aktiviert"
},
"keyboard-layout": {
"changed": "Tastaturlayout geändert zu {layout}"
},
"kofi": {
"opened": "Ko-fi-Seite in Ihrem Browser geöffnet"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Disabled",
"enabled": "Enabled"
},
"keyboard-layout": {
"changed": "Keyboard layout changed to {layout}"
},
"kofi": {
"opened": "Ko-fi page opened in your browser"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Desactivado",
"enabled": "Activado"
},
"keyboard-layout": {
"changed": "Distribución de teclado cambiada a {layout}"
},
"kofi": {
"opened": "Página de Ko-fi abierta en tu navegador"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Désactivé",
"enabled": "Activé"
},
"keyboard-layout": {
"changed": "Disposition du clavier changée vers {layout}"
},
"kofi": {
"opened": "Page Ko-fi ouverte dans votre navigateur"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Desativado",
"enabled": "Ativado"
},
"keyboard-layout": {
"changed": "Layout de teclado alterado para {layout}"
},
"kofi": {
"opened": "Página do Ko-fi aberta no seu navegador"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Devre dışı",
"enabled": "Etkin"
},
"keyboard-layout": {
"changed": "Klavye düzeni {layout} olarak değiştirildi"
},
"kofi": {
"opened": "Ko-fi sayfası tarayıcınızda açıldı"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "Вимкнено",
"enabled": "Увімкнено"
},
"keyboard-layout": {
"changed": "Розкладка клавіатури змінена на {layout}"
},
"kofi": {
"opened": "Сторінка Ko-fi відкрита у вашому браузері"
},
+3
View File
@@ -1736,6 +1736,9 @@
"disabled": "已禁用",
"enabled": "已启用"
},
"keyboard-layout": {
"changed": "键盘布局已更改为 {layout}"
},
"kofi": {
"opened": "Ko-fi 页面已在您的浏览器中打开"
},
+44 -10
View File
@@ -5,10 +5,13 @@ import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Services.Compositor
import qs.Services.UI
Singleton {
id: root
property string currentLayout: I18n.tr("system.unknown-layout")
property string previousLayout: ""
property bool isInitialized: false
property int updateInterval: 1000 // Update every second
// Timer to periodically update the layout
@@ -34,7 +37,7 @@ Singleton {
const layoutName = data.names[data.current_idx]
root.currentLayout = extractLayoutCode(layoutName)
} catch (e) {
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
}
}
}
@@ -54,10 +57,10 @@ Singleton {
if (mainKeyboard && mainKeyboard.active_keymap) {
root.currentLayout = extractLayoutCode(mainKeyboard.active_keymap)
} else {
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
}
} catch (e) {
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
}
}
}
@@ -79,9 +82,9 @@ Singleton {
return
}
}
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
} catch (e) {
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
}
}
}
@@ -112,9 +115,9 @@ Singleton {
}
}
}
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
} catch (e) {
root.currentLayout = "Unknown"
root.currentLayout = I18n.tr("system.unknown-layout")
}
}
}
@@ -170,7 +173,7 @@ Singleton {
// Extract layout code from various format strings using Commons data
function extractLayoutCode(layoutString) {
if (!layoutString)
return "Unknown"
return I18n.tr("system.unknown-layout")
const str = layoutString.toLowerCase()
@@ -197,12 +200,43 @@ Singleton {
// If nothing matches, try first 2-3 characters if they look like a code
const codeMatch = str.match(/^([a-z]{2,3})/)
return codeMatch ? codeMatch[1] : "unknown"
return codeMatch ? codeMatch[1] : I18n.tr("system.unknown-layout")
}
// Watch for layout changes and show toast
onCurrentLayoutChanged: {
// Update previousLayout after checking for changes
const layoutChanged = isInitialized && currentLayout !== previousLayout && currentLayout !== I18n.tr("system.unknown-layout") && previousLayout !== "" && previousLayout !== I18n.tr("system.unknown-layout")
if (layoutChanged) {
const message = I18n.tr("toast.keyboard-layout.changed", {
"layout": currentLayout.toUpperCase()
})
ToastService.showNotice(message, "", "", 2000)
Logger.d("KeyboardLayout", "Layout changed from", previousLayout, "to", currentLayout)
}
// Update previousLayout for next comparison
previousLayout = currentLayout
}
Component.onCompleted: {
Logger.i("KeyboardLayout", "Service started")
updateLayout()
// Mark as initialized after a delay to allow first layout update to complete
// This prevents showing a toast on the initial load
initializationTimer.start()
}
Timer {
id: initializationTimer
interval: 2000 // Wait 2 seconds for first layout update to complete
onTriggered: {
isInitialized = true
// Set previousLayout to current value after initialization
previousLayout = currentLayout
Logger.d("KeyboardLayout", "Service initialized, current layout:", currentLayout)
}
}
function updateLayout() {
@@ -225,7 +259,7 @@ Singleton {
gsettingsProcess.running = true
}
} else {
currentLayout = "Unknown"
currentLayout = I18n.tr("system.unknown-layout")
}
}
}