mirror of
https://github.com/YaLTeR/niri.git
synced 2024-09-11 20:37:25 +03:00
keyboard device config cache
This commit is contained in:
parent
176de91342
commit
7bcb649d7a
@ -268,7 +268,10 @@ impl State {
|
||||
Some(pos + output_geo.loc.to_f64())
|
||||
}
|
||||
|
||||
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
|
||||
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent)
|
||||
where
|
||||
I::Device: 'static,
|
||||
{
|
||||
self.apply_keyboard_config::<I>(&event);
|
||||
|
||||
let comp_mod = self.backend.mod_key();
|
||||
@ -321,27 +324,52 @@ impl State {
|
||||
self.handle_bind(bind);
|
||||
}
|
||||
|
||||
fn apply_keyboard_config<I: InputBackend>(&mut self, event: &I::KeyboardKeyEvent) {
|
||||
fn apply_keyboard_config<I: InputBackend>(&mut self, event: &I::KeyboardKeyEvent)
|
||||
where
|
||||
I::Device: 'static,
|
||||
{
|
||||
let device = event.device();
|
||||
|
||||
let keyboard_config = self
|
||||
.niri
|
||||
.config
|
||||
.borrow()
|
||||
.input
|
||||
.keyboard_named(device.name());
|
||||
let keyboard_config =
|
||||
if let Some(input_device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
|
||||
if let Some(cached) = self.niri.keyboard_device_cache.get(input_device).cloned() {
|
||||
cached
|
||||
} else {
|
||||
let keyboard_config = self
|
||||
.niri
|
||||
.config
|
||||
.borrow()
|
||||
.input
|
||||
.keyboard_named(device.name());
|
||||
|
||||
self.niri
|
||||
.keyboard_device_cache
|
||||
.insert(input_device.clone(), keyboard_config.clone());
|
||||
|
||||
keyboard_config
|
||||
}
|
||||
} else {
|
||||
self.niri.config.borrow().input.fallback_keyboard()
|
||||
};
|
||||
|
||||
if keyboard_config != self.niri.current_keyboard {
|
||||
let keyboard = self.niri.seat.get_keyboard().unwrap();
|
||||
|
||||
if let Err(err) = keyboard.set_xkb_config(self, keyboard_config.xkb.to_xkb_config()) {
|
||||
warn!("error updating xkb config: {err:?}");
|
||||
if keyboard_config.xkb != self.niri.current_keyboard.xkb {
|
||||
if let Err(err) = keyboard.set_xkb_config(self, keyboard_config.xkb.to_xkb_config())
|
||||
{
|
||||
warn!("error updating xkb config: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
keyboard.change_repeat_info(
|
||||
keyboard_config.repeat_rate.into(),
|
||||
keyboard_config.repeat_delay.into(),
|
||||
);
|
||||
if keyboard_config.repeat_rate != self.niri.current_keyboard.repeat_rate
|
||||
|| keyboard_config.repeat_delay != self.niri.current_keyboard.repeat_delay
|
||||
{
|
||||
keyboard.change_repeat_info(
|
||||
keyboard_config.repeat_rate.into(),
|
||||
keyboard_config.repeat_delay.into(),
|
||||
);
|
||||
}
|
||||
|
||||
self.niri.current_keyboard = keyboard_config;
|
||||
}
|
||||
|
@ -184,6 +184,7 @@ pub struct Niri {
|
||||
|
||||
pub current_keyboard: niri_config::Keyboard,
|
||||
pub devices: HashSet<input::Device>,
|
||||
pub keyboard_device_cache: HashMap<input::Device, niri_config::Keyboard>,
|
||||
pub tablets: HashMap<input::Device, TabletData>,
|
||||
pub touch: HashSet<input::Device>,
|
||||
|
||||
@ -1506,7 +1507,9 @@ impl Niri {
|
||||
root_surface: HashMap::new(),
|
||||
monitors_active: true,
|
||||
|
||||
current_keyboard: Default::default(),
|
||||
devices: HashSet::new(),
|
||||
keyboard_device_cache: HashMap::new(),
|
||||
tablets: HashMap::new(),
|
||||
touch: HashSet::new(),
|
||||
|
||||
@ -1588,8 +1591,6 @@ impl Niri {
|
||||
|
||||
pipewire,
|
||||
casts: vec![],
|
||||
|
||||
current_keyboard: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user