set wayvr keymap

This commit is contained in:
galister
2025-12-14 21:29:23 +09:00
parent 9c71917b2a
commit 12e5749bda
4 changed files with 21 additions and 14 deletions

View File

@@ -10,17 +10,16 @@ use crate::{
overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier}, overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier},
state::AppState, state::AppState,
subsystem::hid::{ subsystem::hid::{
wayland::WlKeymapMonitor, KeyModifier, VirtualKey, WheelDelta, XkbKeymap, ALT, CTRL, META, ALT, CTRL, KeyModifier, META, SHIFT, SUPER, VirtualKey, WheelDelta, XkbKeymap,
SHIFT, SUPER, wayland::WlKeymapMonitor,
}, },
windowing::{ windowing::{
backend::{FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender}, backend::{FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender},
window::OverlayWindowConfig, window::OverlayWindowConfig,
}, },
}; };
use dbus::message::MatchRule; use glam::{Affine3A, Quat, Vec3, vec3};
use glam::{vec3, Affine3A, Quat, Vec3}; use slotmap::{SlotMap, new_key_type};
use slotmap::{new_key_type, SlotMap};
use wgui::{ use wgui::{
drawing, drawing,
event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex}, event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex},
@@ -51,6 +50,10 @@ pub fn create_keyboard(
processes: vec![], processes: vec![],
}; };
if let Some(keymap) = keymap.as_ref() {
app.hid_provider.keymap_changed(keymap);
}
if !layout.auto_labels.unwrap_or(true) { if !layout.auto_labels.unwrap_or(true) {
keymap = None; keymap = None;
} }
@@ -117,6 +120,10 @@ impl KeyboardBackend {
} }
fn switch_keymap(&mut self, keymap: &XkbKeymap, app: &mut AppState) -> anyhow::Result<bool> { fn switch_keymap(&mut self, keymap: &XkbKeymap, app: &mut AppState) -> anyhow::Result<bool> {
if !self.layout.auto_labels.unwrap_or(true) {
return Ok(false);
}
let Some(layout_name) = keymap.inner.layouts().next() else { let Some(layout_name) = keymap.inner.layouts().next() else {
log::error!("XKB keymap without a layout!"); log::error!("XKB keymap without a layout!");
return Ok(false); return Ok(false);
@@ -161,6 +168,7 @@ impl OverlayBackend for KeyboardBackend {
} }
fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> { fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
if let Some(keymap) = self.wkm.check() { if let Some(keymap) = self.wkm.check() {
app.hid_provider.keymap_changed(&keymap);
if self.switch_keymap(&keymap, app)? { if self.switch_keymap(&keymap, app)? {
return Ok(match self.panel().should_render(app)? { return Ok(match self.panel().should_render(app)? {
ShouldRender::Should | ShouldRender::Can => ShouldRender::Should, ShouldRender::Should | ShouldRender::Can => ShouldRender::Should,

View File

@@ -1,5 +1,5 @@
use glam::Vec2; use glam::Vec2;
use idmap::{idmap, IdMap}; use idmap::{IdMap, idmap};
use idmap_derive::IntegerId; use idmap_derive::IntegerId;
use input_linux::{ use input_linux::{
AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind, InputId, Key, RelativeAxis, AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind, InputId, Key, RelativeAxis,

View File

@@ -1,13 +1,13 @@
use anyhow::Context; use anyhow::Context;
use wayland_client::{globals::GlobalList, EventQueue}; use wayland_client::{EventQueue, globals::GlobalList};
use wlx_capture::wayland::wayland_client::{ use wlx_capture::wayland::wayland_client::{
globals::{registry_queue_init, GlobalListContents}, Connection, Dispatch, Proxy, QueueHandle,
globals::{GlobalListContents, registry_queue_init},
protocol::{ protocol::{
wl_keyboard::{self, WlKeyboard}, wl_keyboard::{self, WlKeyboard},
wl_registry::WlRegistry, wl_registry::WlRegistry,
wl_seat::{self, Capability, WlSeat}, wl_seat::{self, Capability, WlSeat},
}, },
Connection, Dispatch, Proxy, QueueHandle,
}; };
use xkbcommon::xkb; use xkbcommon::xkb;

View File

@@ -1,9 +1,8 @@
use super::hid::{self, HidProvider, VirtualKey}; use super::hid::{self, HidProvider, VirtualKey};
use xkbcommon::xkb;
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use crate::overlays::wayvr::WayVRData; use crate::overlays::wayvr::WayVRData;
use crate::subsystem::hid::XkbKeymap;
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
@@ -50,20 +49,20 @@ impl HidWrapper {
} }
} }
pub fn keymap_changed(&self, keymap: &xkb::Keymap) { pub fn keymap_changed(&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
.borrow_mut() .borrow_mut()
.data .data
.state .state
.set_keymap(keymap) .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:?}"));
} }
log::info!( log::info!(
"Keymap changed: {}", "Keymap changed: {}",
keymap.layouts().next().unwrap_or("Unknown") keymap.inner.layouts().next().unwrap_or("Unknown")
); );
} }