From 2d3c1bb2a3b93049278ef9b039de60c450a48753 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Thu, 18 Dec 2025 01:29:36 +0900 Subject: [PATCH] default_keymap setting, set wayvr keymap when wayvr starts --- wlx-common/src/config.rs | 1 + wlx-overlay-s/src/overlays/keyboard/mod.rs | 14 +++++++++++++- wlx-overlay-s/src/subsystem/hid/mod.rs | 1 + wlx-overlay-s/src/subsystem/hid/wayland.rs | 2 +- wlx-overlay-s/src/subsystem/input.rs | 14 +++++++++++++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/wlx-common/src/config.rs b/wlx-common/src/config.rs index 144ece4..c3462b7 100644 --- a/wlx-common/src/config.rs +++ b/wlx-common/src/config.rs @@ -132,6 +132,7 @@ pub struct GeneralConfig { pub color_accent: Option, pub color_danger: Option, pub color_faded: Option, + pub default_keymap: Option, #[serde(default = "def_click_freeze_time_ms")] pub click_freeze_time_ms: u32, diff --git a/wlx-overlay-s/src/overlays/keyboard/mod.rs b/wlx-overlay-s/src/overlays/keyboard/mod.rs index e12b711..9470e33 100644 --- a/wlx-overlay-s/src/overlays/keyboard/mod.rs +++ b/wlx-overlay-s/src/overlays/keyboard/mod.rs @@ -72,6 +72,18 @@ pub fn create_keyboard(app: &mut AppState, wayland: bool) -> anyhow::Result KeyType { } } +#[derive(Clone)] pub struct XkbKeymap { pub inner: xkb::Keymap, } diff --git a/wlx-overlay-s/src/subsystem/hid/wayland.rs b/wlx-overlay-s/src/subsystem/hid/wayland.rs index 1ac255f..c118863 100644 --- a/wlx-overlay-s/src/subsystem/hid/wayland.rs +++ b/wlx-overlay-s/src/subsystem/hid/wayland.rs @@ -104,7 +104,7 @@ impl Dispatch 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, diff --git a/wlx-overlay-s/src/subsystem/input.rs b/wlx-overlay-s/src/subsystem/input.rs index 36e006b..ae96726 100644 --- a/wlx-overlay-s/src/subsystem/input.rs +++ b/wlx-overlay-s/src/subsystem/input.rs @@ -17,6 +17,7 @@ pub enum KeyboardFocus { pub struct HidWrapper { pub keyboard_focus: KeyboardFocus, pub inner: Box, + pub keymap: Option, #[cfg(feature = "wayvr")] pub wayvr: Option>>, // 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>) { + 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!(