layout indicator in top right

This commit is contained in:
スケベ
2025-06-19 18:14:05 +03:00
parent 16ed1f107f
commit ad7fdd1d3f
2 changed files with 42 additions and 0 deletions
+7
View File
@@ -416,6 +416,13 @@ Scope {
color: rightSidebarButton.colText color: rightSidebarButton.colText
} }
} }
Label {
Layout.rightMargin: indicatorsRowLayout.realSpacing
text: LayoutService.currentLayout
visible: LayoutService.currentLayout !== ""
font.pixelSize: Appearance.font.pixelSize.larger - 3
color: rightSidebarButton.colText
}
MaterialSymbol { MaterialSymbol {
Layout.rightMargin: indicatorsRowLayout.realSpacing Layout.rightMargin: indicatorsRowLayout.realSpacing
text: Network.materialSymbol text: Network.materialSymbol
@@ -0,0 +1,35 @@
pragma Singleton
import QtQuick
import Quickshell.Hyprland
QtObject {
id: layoutService
property string currentLayout: "" // This is empty on startup. We could default it to "en", but we don't know the user's configured layout order (e.g. "en,ru" vs "ru,en").
// I haven't found a way to query the initial layout from QML without external bash scripts, so this is the safest compromise for now.
function parseLayout(fullLayoutName) {
if (!fullLayoutName) return;
const shortName = fullLayoutName.substring(0, 2).toLowerCase();
if (currentLayout !== shortName) {
currentLayout = shortName;
}
}
function handleRawEvent(event) {
if (event.name === "activelayout") {
const dataString = event.data;
const layoutInfo = dataString.split(",");
const fullLayoutName = layoutInfo[layoutInfo.length - 1];
parseLayout(fullLayoutName);
}
}
Component.onCompleted: {
Hyprland.rawEvent.connect(handleRawEvent);
}
}