mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Switched to qmlformat.
This commit is contained in:
@@ -15,76 +15,76 @@ Singleton {
|
||||
|
||||
// Updates current layout from various format strings. Called by compositors
|
||||
function setCurrentLayout(layoutString) {
|
||||
root.currentLayout = extractLayoutCode(layoutString)
|
||||
root.currentLayout = extractLayoutCode(layoutString);
|
||||
}
|
||||
|
||||
// Extract layout code from various format strings using Commons data
|
||||
function extractLayoutCode(layoutString) {
|
||||
if (!layoutString)
|
||||
return I18n.tr("system.unknown-layout")
|
||||
return I18n.tr("system.unknown-layout");
|
||||
|
||||
const str = layoutString.toLowerCase()
|
||||
const str = layoutString.toLowerCase();
|
||||
|
||||
// If it's already a short code (2-3 chars), return as-is
|
||||
if (/^[a-z]{2,3}(\+.*)?$/.test(str)) {
|
||||
return str.split('+')[0]
|
||||
return str.split('+')[0];
|
||||
}
|
||||
|
||||
// Extract from parentheses like "English (US)"
|
||||
const parenMatch = str.match(/\(([a-z]{2,3})\)/)
|
||||
const parenMatch = str.match(/\(([a-z]{2,3})\)/);
|
||||
if (parenMatch) {
|
||||
return parenMatch[1]
|
||||
return parenMatch[1];
|
||||
}
|
||||
|
||||
// Check for exact matches or partial matches in language map from Commons
|
||||
const entries = Object.entries(languageMap)
|
||||
const entries = Object.entries(languageMap);
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
const lang = entries[i][0]
|
||||
const code = entries[i][1]
|
||||
const lang = entries[i][0];
|
||||
const code = entries[i][1];
|
||||
if (str.includes(lang)) {
|
||||
return code
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
// 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] : I18n.tr("system.unknown-layout")
|
||||
const codeMatch = str.match(/^([a-z]{2,3})/);
|
||||
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")
|
||||
const layoutChanged = isInitialized && currentLayout !== previousLayout && currentLayout !== I18n.tr("system.unknown-layout") && previousLayout !== "" && previousLayout !== I18n.tr("system.unknown-layout");
|
||||
|
||||
if (layoutChanged) {
|
||||
if (Settings.data.notifications.enableKeyboardLayoutToast) {
|
||||
const message = I18n.tr("toast.keyboard-layout.changed", {
|
||||
"layout": currentLayout.toUpperCase()
|
||||
})
|
||||
ToastService.showNotice(message, "", "", 2000)
|
||||
});
|
||||
ToastService.showNotice(message, "", "", 2000);
|
||||
}
|
||||
Logger.d("KeyboardLayout", "Layout changed from", previousLayout, "to", currentLayout)
|
||||
Logger.d("KeyboardLayout", "Layout changed from", previousLayout, "to", currentLayout);
|
||||
}
|
||||
|
||||
// Update previousLayout for next comparison
|
||||
previousLayout = currentLayout
|
||||
previousLayout = currentLayout;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
Logger.i("KeyboardLayout", "Service started")
|
||||
Logger.i("KeyboardLayout", "Service started");
|
||||
// Mark as initialized after a delay to allow first layout update to complete
|
||||
// This prevents showing a toast on the initial load
|
||||
initializationTimer.start()
|
||||
initializationTimer.start();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: initializationTimer
|
||||
interval: 2000 // Wait 2 seconds for first layout update to complete
|
||||
onTriggered: {
|
||||
isInitialized = true
|
||||
isInitialized = true;
|
||||
// Set previousLayout to current value after initialization
|
||||
previousLayout = currentLayout
|
||||
Logger.d("KeyboardLayout", "Service initialized, current layout:", currentLayout)
|
||||
previousLayout = currentLayout;
|
||||
Logger.d("KeyboardLayout", "Service initialized, current layout:", currentLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user