default_keymap setting, set wayvr keymap when wayvr starts

This commit is contained in:
galister
2025-12-18 01:29:36 +09:00
parent 595b59b865
commit 2d3c1bb2a3
5 changed files with 29 additions and 3 deletions

View File

@@ -132,6 +132,7 @@ pub struct GeneralConfig {
pub color_accent: Option<String>,
pub color_danger: Option<String>,
pub color_faded: Option<String>,
pub default_keymap: Option<String>,
#[serde(default = "def_click_freeze_time_ms")]
pub click_freeze_time_ms: u32,

View File

@@ -72,6 +72,18 @@ pub fn create_keyboard(app: &mut AppState, wayland: bool) -> anyhow::Result<Over
let mut maybe_keymap = backend
.get_effective_keymap(app)
.inspect_err(|e| log::warn!("{e:?}"))
.or_else(|_| {
if let Some(layout_variant) = app.session.config.default_keymap.as_ref() {
let mut splat = layout_variant.split('-');
XkbKeymap::from_layout_variant(
splat.next().unwrap_or(""),
splat.next().unwrap_or(""),
)
.context("invalid value for default_keymap")
} else {
anyhow::bail!("no default_keymap set")
}
})
.ok();
if let Some(keymap) = maybe_keymap.as_ref() {
@@ -186,7 +198,7 @@ impl KeyboardBackend {
.dbus
.fcitx_keymap()
.context("Could not keymap via fcitx5, falling back to wayland")
.inspect_err(|e| log::warn!("{e:?}"))
.inspect_err(|e| log::info!("{e:?}"))
else {
return get_system_keymap(self.wayland);
};

View File

@@ -573,6 +573,7 @@ pub const fn get_key_type(key: VirtualKey) -> KeyType {
}
}
#[derive(Clone)]
pub struct XkbKeymap {
pub inner: xkb::Keymap,
}

View File

@@ -104,7 +104,7 @@ impl Dispatch<WlKeyboard, ()> for MonitorState {
.unwrap_or(wl_keyboard::KeymapFormat::NoKeymap);
if matches!(format, wl_keyboard::KeymapFormat::XkbV1) {
let context = xkb::Context::new(xkb::CONTEXT_NO_DEFAULT_INCLUDES);
let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
let maybe_keymap = unsafe {
xkb::Keymap::new_from_fd(
&context,

View File

@@ -17,6 +17,7 @@ pub enum KeyboardFocus {
pub struct HidWrapper {
pub keyboard_focus: KeyboardFocus,
pub inner: Box<dyn HidProvider>,
pub keymap: Option<XkbKeymap>,
#[cfg(feature = "wayvr")]
pub wayvr: Option<Rc<RefCell<WayVRData>>>, // Dynamically created if requested
}
@@ -28,11 +29,20 @@ impl HidWrapper {
inner: hid::initialize(),
#[cfg(feature = "wayvr")]
wayvr: None,
keymap: None,
}
}
#[cfg(feature = "wayvr")]
pub fn set_wayvr(&mut self, wayvr: Rc<RefCell<WayVRData>>) {
if let Some(keymap) = self.keymap.take() {
let _ = wayvr
.borrow_mut()
.data
.state
.set_keymap(&keymap.inner)
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
}
self.wayvr = Some(wayvr);
}
@@ -49,7 +59,7 @@ impl HidWrapper {
}
}
pub fn keymap_changed(&self, keymap: &XkbKeymap) {
pub fn keymap_changed(&mut self, keymap: &XkbKeymap) {
#[cfg(feature = "wayvr")]
if let Some(wayvr) = &self.wayvr {
let _ = wayvr
@@ -58,6 +68,8 @@ impl HidWrapper {
.state
.set_keymap(&keymap.inner)
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
} else {
self.keymap = Some(keymap.clone());
}
log::info!(