diff --git a/Services/Compositor/SwayService.qml b/Services/Compositor/SwayService.qml index e244bf8e1..2abaca89a 100644 --- a/Services/Compositor/SwayService.qml +++ b/Services/Compositor/SwayService.qml @@ -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) } }