mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
KeyboardLayout: subscribe to Sway events to update keyboard layout
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user