mirror of
https://github.com/YaLTeR/niri.git
synced 2024-09-11 20:37:25 +03:00
keyboard configs
This commit is contained in:
parent
bc3d6cac80
commit
b12396d8a1
@ -59,8 +59,8 @@ pub struct Config {
|
||||
// FIXME: Add other devices.
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
|
||||
pub struct Input {
|
||||
#[knuffel(child, default)]
|
||||
pub keyboard: Keyboard,
|
||||
#[knuffel(children(name = "keyboard"), default)]
|
||||
pub keyboards: Vec<Keyboard>,
|
||||
#[knuffel(child, default)]
|
||||
pub touchpad: Touchpad,
|
||||
#[knuffel(child, default)]
|
||||
@ -81,8 +81,28 @@ pub struct Input {
|
||||
pub workspace_auto_back_and_forth: bool,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, PartialEq, Eq)]
|
||||
impl Input {
|
||||
pub fn default_keyboard(&self) -> Keyboard {
|
||||
self.keyboards
|
||||
.iter()
|
||||
.find(|keyboard| keyboard.name.is_none())
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn keyboard_named<K: AsRef<str>>(&self, name: K) -> Keyboard {
|
||||
self.keyboards
|
||||
.iter()
|
||||
.find(|keyboard| keyboard.name.as_deref() == Some(name.as_ref()))
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Keyboard {
|
||||
#[knuffel(argument, unwrap(argument))]
|
||||
pub name: Option<String>,
|
||||
#[knuffel(child, default)]
|
||||
pub xkb: Xkb,
|
||||
// The defaults were chosen to match wlroots and sway.
|
||||
@ -97,6 +117,7 @@ pub struct Keyboard {
|
||||
impl Default for Keyboard {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: None,
|
||||
xkb: Default::default(),
|
||||
repeat_delay: 600,
|
||||
repeat_rate: 25,
|
||||
@ -143,7 +164,7 @@ pub enum CenterFocusedColumn {
|
||||
OnOverflow,
|
||||
}
|
||||
|
||||
#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq, Clone)]
|
||||
pub enum TrackLayout {
|
||||
/// The layout change is global.
|
||||
#[default]
|
||||
@ -2509,7 +2530,7 @@ mod tests {
|
||||
"##,
|
||||
Config {
|
||||
input: Input {
|
||||
keyboard: Keyboard {
|
||||
keyboards: Keyboard {
|
||||
xkb: Xkb {
|
||||
layout: "us,ru".to_owned(),
|
||||
options: Some("grp:win_space_toggle".to_owned()),
|
||||
@ -2518,6 +2539,7 @@ mod tests {
|
||||
repeat_delay: 600,
|
||||
repeat_rate: 25,
|
||||
track_layout: TrackLayout::Window,
|
||||
..Default::default()
|
||||
},
|
||||
touchpad: Touchpad {
|
||||
off: false,
|
||||
|
@ -269,6 +269,23 @@ impl State {
|
||||
}
|
||||
|
||||
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
|
||||
{
|
||||
let device = event.device();
|
||||
let xkb = self
|
||||
.niri
|
||||
.config
|
||||
.borrow()
|
||||
.input
|
||||
.keyboard_named(device.name())
|
||||
.xkb;
|
||||
|
||||
let keyboard = self.niri.seat.get_keyboard().unwrap();
|
||||
|
||||
if let Err(err) = keyboard.set_xkb_config(self, xkb.to_xkb_config()) {
|
||||
warn!("error updating xkb config: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
let comp_mod = self.backend.mod_key();
|
||||
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
|
32
src/niri.rs
32
src/niri.rs
@ -808,7 +808,15 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
if self.niri.config.borrow().input.keyboard.track_layout == TrackLayout::Window {
|
||||
if self
|
||||
.niri
|
||||
.config
|
||||
.borrow()
|
||||
.input
|
||||
.default_keyboard()
|
||||
.track_layout
|
||||
== TrackLayout::Window
|
||||
{
|
||||
let current_layout =
|
||||
keyboard.with_xkb_state(self, |context| context.active_layout());
|
||||
|
||||
@ -908,19 +916,23 @@ impl State {
|
||||
self.niri.cursor_texture_cache.clear();
|
||||
}
|
||||
|
||||
let default_keyboard = config.input.default_keyboard();
|
||||
|
||||
let old_keyboard = old_config.input.default_keyboard();
|
||||
|
||||
// We need &mut self to reload the xkb config, so just store it here.
|
||||
if config.input.keyboard.xkb != old_config.input.keyboard.xkb {
|
||||
reload_xkb = Some(config.input.keyboard.xkb.clone());
|
||||
if default_keyboard.xkb != old_keyboard.xkb {
|
||||
reload_xkb = Some(default_keyboard.xkb.clone());
|
||||
}
|
||||
|
||||
// Reload the repeat info.
|
||||
if config.input.keyboard.repeat_rate != old_config.input.keyboard.repeat_rate
|
||||
|| config.input.keyboard.repeat_delay != old_config.input.keyboard.repeat_delay
|
||||
if default_keyboard.repeat_rate != old_keyboard.repeat_rate
|
||||
|| default_keyboard.repeat_delay != old_keyboard.repeat_delay
|
||||
{
|
||||
let keyboard = self.niri.seat.get_keyboard().unwrap();
|
||||
keyboard.change_repeat_info(
|
||||
config.input.keyboard.repeat_rate.into(),
|
||||
config.input.keyboard.repeat_delay.into(),
|
||||
default_keyboard.repeat_rate.into(),
|
||||
default_keyboard.repeat_delay.into(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1375,9 +1387,9 @@ impl Niri {
|
||||
|
||||
let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());
|
||||
seat.add_keyboard(
|
||||
config_.input.keyboard.xkb.to_xkb_config(),
|
||||
config_.input.keyboard.repeat_delay.into(),
|
||||
config_.input.keyboard.repeat_rate.into(),
|
||||
config_.input.default_keyboard().xkb.to_xkb_config(),
|
||||
config_.input.default_keyboard().repeat_delay.into(),
|
||||
config_.input.default_keyboard().repeat_rate.into(),
|
||||
)
|
||||
.unwrap();
|
||||
seat.add_pointer();
|
||||
|
Loading…
Reference in New Issue
Block a user