diff --git a/Services/Compositor/SwayService.qml b/Services/Compositor/SwayService.qml index 32c49574f..0e0157cb6 100644 --- a/Services/Compositor/SwayService.qml +++ b/Services/Compositor/SwayService.qml @@ -37,7 +37,6 @@ Item { return; try { I3.refreshWorkspaces(); - I3.dispatch('(["input"])'); Qt.callLater(() => { safeUpdateWorkspaces(); safeUpdateWindows(); @@ -111,16 +110,6 @@ Item { } } - Timer { - id: keyboardLayoutUpdateTimer - interval: 1000 - running: true - repeat: true - onTriggered: { - queryKeyboardLayout(); - } - } - function queryKeyboardLayout() { swayInputsProcess.running = true; } @@ -290,22 +279,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); } } @@ -338,10 +322,13 @@ Item { if (event.type === "output") { Qt.callLater(queryDisplayScales); } + } + } - if (event.type == "get_inputs") { - handleInputEvent(event.data); - } + I3IpcListener { + subscriptions: ["input"] + onIpcEvent: function (event) { + handleInputEvent(event.data); } }