wayvr: interface to set keymap

This commit is contained in:
galister
2025-12-14 13:11:03 +09:00
parent 4bd8cc1955
commit 8418516236
4 changed files with 42 additions and 0 deletions

View File

@@ -1,11 +1,13 @@
use std::{io::Read, os::unix::net::UnixStream, path::PathBuf, sync::Arc};
use anyhow::Context;
use smithay::{
backend::input::Keycode,
input::{keyboard::KeyboardHandle, pointer::PointerHandle},
reexports::wayland_server,
utils::SerialCounter,
};
use xkbcommon::xkb::{self, KEYMAP_FORMAT_USE_ORIGINAL};
use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask};
@@ -207,6 +209,16 @@ impl WayVRCompositor {
|_, _, _| smithay::input::keyboard::FilterResult::Forward,
);
}
pub fn set_keymap(&mut self, keymap: &xkb::Keymap) -> anyhow::Result<()> {
// Smithay only accepts keymaps in a string form due to thread safety concerns
self.seat_keyboard
.set_keymap_from_string(
&mut self.state,
keymap.get_as_string(xkb::KEYMAP_FORMAT_USE_ORIGINAL),
)
.context("Failed to set keymap")
}
}
const STARTING_WAYLAND_ADDR_IDX: u32 = 20;

View File

@@ -32,6 +32,7 @@ use smithay::{
selection::data_device::DataDeviceState,
shell::xdg::{ToplevelSurface, XdgShellState},
shm::ShmState,
xwayland_keyboard_grab::XWaylandKeyboardGrabHandler,
},
};
use std::{
@@ -42,6 +43,7 @@ use std::{
};
use time::get_millis;
use wayvr_ipc::{packet_client, packet_server};
use xkbcommon::xkb;
use crate::{
state::AppState,
@@ -519,6 +521,10 @@ impl WayVRState {
self.manager.send_key(virtual_key, down);
}
pub fn set_keymap(&mut self, keymap: &xkb::Keymap) -> anyhow::Result<()> {
self.manager.set_keymap(keymap)
}
pub fn set_modifiers(&mut self, modifiers: u8) {
let changed = self.cur_modifiers ^ modifiers;
for i in 0..8 {