Merge pull request #833 from 3akev/main

KeyboardLayout: subscribe to Sway events to update keyboard layout
This commit is contained in:
Lemmy
2026-03-01 15:29:17 -05:00
committed by GitHub
+16 -34
View File
@@ -45,8 +45,7 @@ Item {
if (initialized)
return;
try {
I3.refreshWorkspaces();
I3.dispatch('(["input"])');
I3.refreshWorkspaces()
Qt.callLater(() => {
safeUpdateWorkspaces();
queryWindowWorkspaces();
@@ -235,16 +234,6 @@ Item {
}
}
Timer {
id: keyboardLayoutUpdateTimer
interval: 1000
running: true
repeat: true
onTriggered: {
queryKeyboardLayout();
}
}
function queryKeyboardLayout() {
swayInputsProcess.running = true;
}
@@ -459,22 +448,17 @@ Item {
function handleInputEvent(ev) {
try {
let beforeParenthesis;
const parenthesisPos = ev.lastIndexOf('(');
if (parenthesisPos === -1) {
beforeParenthesis = ev;
} else {
beforeParenthesis = ev.substring(0, parenthesisPos);
const eventData = JSON.parse(ev)
if (eventData.change == "xkb_layout" && eventData.input != null) {
const input = eventData.input
if (input.type == "keyboard" && input.xkb_active_layout_name != null) {
const layoutName = input.xkb_active_layout_name
KeyboardLayoutService.setCurrentLayout(layoutName)
Logger.d("SwayService", "Keyboard layout switched:", layoutName)
}
}
const layoutNameStart = beforeParenthesis.lastIndexOf(',') + 1;
const layoutName = ev.substring(layoutNameStart);
KeyboardLayoutService.setCurrentLayout(layoutName);
Logger.d("HyprlandService", "Keyboard layout switched:", layoutName);
} catch (e) {
Logger.e("HyprlandService", "Error handling activelayout:", e);
Logger.e("SwayService", "Error handling input event:", e)
}
}
@@ -516,15 +500,13 @@ Item {
if (event.type === "output") {
Qt.callLater(queryDisplayScales);
}
}
}
if (event.type == "get_inputs") {
handleInputEvent(event.data);
}
// Query window workspaces on relevant events
if (event.type === "window" || event.type === "workspace") {
Qt.callLater(queryWindowWorkspaces);
}
I3IpcListener {
subscriptions: ["input"]
onIpcEvent: function (event) {
handleInputEvent(event.data)
}
}