From ad7fdd1d3fcda4dfccef2a0f5afdfd09c705f840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B9=E3=82=B1=E3=83=99?= Date: Thu, 19 Jun 2025 18:14:05 +0300 Subject: [PATCH] layout indicator in top right --- .config/quickshell/modules/bar/Bar.qml | 7 ++++ .config/quickshell/services/LayoutService.qml | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .config/quickshell/services/LayoutService.qml diff --git a/.config/quickshell/modules/bar/Bar.qml b/.config/quickshell/modules/bar/Bar.qml index 925ac1406..3d5062919 100644 --- a/.config/quickshell/modules/bar/Bar.qml +++ b/.config/quickshell/modules/bar/Bar.qml @@ -416,6 +416,13 @@ Scope { 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 { Layout.rightMargin: indicatorsRowLayout.realSpacing text: Network.materialSymbol diff --git a/.config/quickshell/services/LayoutService.qml b/.config/quickshell/services/LayoutService.qml new file mode 100644 index 000000000..df9430e50 --- /dev/null +++ b/.config/quickshell/services/LayoutService.qml @@ -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); + } +} \ No newline at end of file