1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-10 07:42:09 -04:00

lock/greeter: fix keyboard layout on Hyprland

fixes #1650
fixes #672
fixes #1600
This commit is contained in:
bbedward
2026-02-11 08:57:24 -05:00
parent 4d316007af
commit 535d0bb0f0
2 changed files with 26 additions and 34 deletions

View File

@@ -92,22 +92,19 @@ Item {
try { try {
const data = JSON.parse(text); const data = JSON.parse(text);
const mainKeyboard = data.keyboards.find(kb => kb.main === true); const mainKeyboard = data.keyboards.find(kb => kb.main === true);
if (!mainKeyboard) {
hyprlandCurrentLayout = "";
hyprlandLayoutCount = 0;
return;
}
hyprlandKeyboard = mainKeyboard.name; hyprlandKeyboard = mainKeyboard.name;
if (mainKeyboard && mainKeyboard.active_keymap) { if (mainKeyboard.active_keymap) {
const parts = mainKeyboard.active_keymap.split(" "); const parts = mainKeyboard.active_keymap.split(" ");
if (parts.length > 0) { hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase();
hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase();
} else {
hyprlandCurrentLayout = mainKeyboard.active_keymap.substring(0, 2).toUpperCase();
}
} else { } else {
hyprlandCurrentLayout = ""; hyprlandCurrentLayout = "";
} }
if (mainKeyboard && mainKeyboard.layout_names) { hyprlandLayoutCount = mainKeyboard.layout ? mainKeyboard.layout.split(",").length : 0;
hyprlandLayoutCount = mainKeyboard.layout_names.length;
} else {
hyprlandLayoutCount = 0;
}
} catch (e) { } catch (e) {
hyprlandCurrentLayout = ""; hyprlandCurrentLayout = "";
hyprlandLayoutCount = 0; hyprlandLayoutCount = 0;

View File

@@ -5,6 +5,7 @@ import QtQuick.Effects
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Window import QtQuick.Window
import Quickshell import Quickshell
import Quickshell.Hyprland
import Quickshell.Io import Quickshell.Io
import Quickshell.Services.Mpris import Quickshell.Services.Mpris
import qs.Common import qs.Common
@@ -44,19 +45,14 @@ Item {
WeatherService.addRef(); WeatherService.addRef();
UserInfoService.getUserInfo(); UserInfoService.getUserInfo();
if (CompositorService.isHyprland) { if (CompositorService.isHyprland)
updateHyprlandLayout(); updateHyprlandLayout();
hyprlandLayoutUpdateTimer.start();
}
lockerReadyArmed = true; lockerReadyArmed = true;
} }
Component.onDestruction: { Component.onDestruction: {
WeatherService.removeRef(); WeatherService.removeRef();
if (CompositorService.isHyprland) {
hyprlandLayoutUpdateTimer.stop();
}
} }
function sendLockerReadyOnce() { function sendLockerReadyOnce() {
@@ -118,22 +114,19 @@ Item {
try { try {
const data = JSON.parse(text); const data = JSON.parse(text);
const mainKeyboard = data.keyboards.find(kb => kb.main === true); const mainKeyboard = data.keyboards.find(kb => kb.main === true);
if (!mainKeyboard) {
hyprlandCurrentLayout = "";
hyprlandLayoutCount = 0;
return;
}
hyprlandKeyboard = mainKeyboard.name; hyprlandKeyboard = mainKeyboard.name;
if (mainKeyboard && mainKeyboard.active_keymap) { if (mainKeyboard.active_keymap) {
const parts = mainKeyboard.active_keymap.split(" "); const parts = mainKeyboard.active_keymap.split(" ");
if (parts.length > 0) { hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase();
hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase();
} else {
hyprlandCurrentLayout = mainKeyboard.active_keymap.substring(0, 2).toUpperCase();
}
} else { } else {
hyprlandCurrentLayout = ""; hyprlandCurrentLayout = "";
} }
if (mainKeyboard && mainKeyboard.layout_names) { hyprlandLayoutCount = mainKeyboard.layout ? mainKeyboard.layout.split(",").length : 0;
hyprlandLayoutCount = mainKeyboard.layout_names.length;
} else {
hyprlandLayoutCount = 0;
}
} catch (e) { } catch (e) {
hyprlandCurrentLayout = ""; hyprlandCurrentLayout = "";
hyprlandLayoutCount = 0; hyprlandLayoutCount = 0;
@@ -142,12 +135,14 @@ Item {
} }
} }
Timer { Connections {
id: hyprlandLayoutUpdateTimer target: CompositorService.isHyprland ? Hyprland : null
interval: 1000 enabled: CompositorService.isHyprland
running: false
repeat: true function onRawEvent(event) {
onTriggered: updateHyprlandLayout() if (event.name === "activelayout")
updateHyprlandLayout();
}
} }
Loader { Loader {