default_keymap setting, set wayvr keymap when wayvr starts
This commit is contained in:
@@ -132,6 +132,7 @@ pub struct GeneralConfig {
|
|||||||
pub color_accent: Option<String>,
|
pub color_accent: Option<String>,
|
||||||
pub color_danger: Option<String>,
|
pub color_danger: Option<String>,
|
||||||
pub color_faded: Option<String>,
|
pub color_faded: Option<String>,
|
||||||
|
pub default_keymap: Option<String>,
|
||||||
|
|
||||||
#[serde(default = "def_click_freeze_time_ms")]
|
#[serde(default = "def_click_freeze_time_ms")]
|
||||||
pub click_freeze_time_ms: u32,
|
pub click_freeze_time_ms: u32,
|
||||||
|
|||||||
@@ -72,6 +72,18 @@ pub fn create_keyboard(app: &mut AppState, wayland: bool) -> anyhow::Result<Over
|
|||||||
let mut maybe_keymap = backend
|
let mut maybe_keymap = backend
|
||||||
.get_effective_keymap(app)
|
.get_effective_keymap(app)
|
||||||
.inspect_err(|e| log::warn!("{e:?}"))
|
.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();
|
.ok();
|
||||||
|
|
||||||
if let Some(keymap) = maybe_keymap.as_ref() {
|
if let Some(keymap) = maybe_keymap.as_ref() {
|
||||||
@@ -186,7 +198,7 @@ impl KeyboardBackend {
|
|||||||
.dbus
|
.dbus
|
||||||
.fcitx_keymap()
|
.fcitx_keymap()
|
||||||
.context("Could not keymap via fcitx5, falling back to wayland")
|
.context("Could not keymap via fcitx5, falling back to wayland")
|
||||||
.inspect_err(|e| log::warn!("{e:?}"))
|
.inspect_err(|e| log::info!("{e:?}"))
|
||||||
else {
|
else {
|
||||||
return get_system_keymap(self.wayland);
|
return get_system_keymap(self.wayland);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -573,6 +573,7 @@ pub const fn get_key_type(key: VirtualKey) -> KeyType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct XkbKeymap {
|
pub struct XkbKeymap {
|
||||||
pub inner: xkb::Keymap,
|
pub inner: xkb::Keymap,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl Dispatch<WlKeyboard, ()> for MonitorState {
|
|||||||
.unwrap_or(wl_keyboard::KeymapFormat::NoKeymap);
|
.unwrap_or(wl_keyboard::KeymapFormat::NoKeymap);
|
||||||
|
|
||||||
if matches!(format, wl_keyboard::KeymapFormat::XkbV1) {
|
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 {
|
let maybe_keymap = unsafe {
|
||||||
xkb::Keymap::new_from_fd(
|
xkb::Keymap::new_from_fd(
|
||||||
&context,
|
&context,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub enum KeyboardFocus {
|
|||||||
pub struct HidWrapper {
|
pub struct HidWrapper {
|
||||||
pub keyboard_focus: KeyboardFocus,
|
pub keyboard_focus: KeyboardFocus,
|
||||||
pub inner: Box<dyn HidProvider>,
|
pub inner: Box<dyn HidProvider>,
|
||||||
|
pub keymap: Option<XkbKeymap>,
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
pub wayvr: Option<Rc<RefCell<WayVRData>>>, // Dynamically created if requested
|
pub wayvr: Option<Rc<RefCell<WayVRData>>>, // Dynamically created if requested
|
||||||
}
|
}
|
||||||
@@ -28,11 +29,20 @@ impl HidWrapper {
|
|||||||
inner: hid::initialize(),
|
inner: hid::initialize(),
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
wayvr: None,
|
wayvr: None,
|
||||||
|
keymap: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayvr")]
|
#[cfg(feature = "wayvr")]
|
||||||
pub fn set_wayvr(&mut self, wayvr: Rc<RefCell<WayVRData>>) {
|
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);
|
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")]
|
#[cfg(feature = "wayvr")]
|
||||||
if let Some(wayvr) = &self.wayvr {
|
if let Some(wayvr) = &self.wayvr {
|
||||||
let _ = wayvr
|
let _ = wayvr
|
||||||
@@ -58,6 +68,8 @@ impl HidWrapper {
|
|||||||
.state
|
.state
|
||||||
.set_keymap(&keymap.inner)
|
.set_keymap(&keymap.inner)
|
||||||
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
|
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
|
||||||
|
} else {
|
||||||
|
self.keymap = Some(keymap.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|||||||
Reference in New Issue
Block a user