feat: configurable keyboard repeat rate and delay

This commit is contained in:
LazyTanuki 2024-05-19 18:19:43 +02:00 committed by Victoria Brekenfeld
parent b3c606fdf6
commit dcc4873e60
3 changed files with 29 additions and 3 deletions

View file

@ -54,6 +54,10 @@ pub struct XkbConfig {
pub layout: String, pub layout: String,
pub variant: String, pub variant: String,
pub options: Option<String>, pub options: Option<String>,
#[serde(default = "default_repeat_delay")]
pub repeat_delay: u32,
#[serde(default = "default_repeat_rate")]
pub repeat_rate: u32,
} }
impl Default for XkbConfig { impl Default for XkbConfig {
@ -64,6 +68,16 @@ impl Default for XkbConfig {
layout: String::new(), layout: String::new(),
variant: String::new(), variant: String::new(),
options: None, options: None,
repeat_delay: default_repeat_delay(),
repeat_rate: default_repeat_rate(),
} }
} }
} }
fn default_repeat_rate() -> u32 {
25
}
fn default_repeat_delay() -> u32 {
600
}

View file

@ -584,6 +584,10 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for seat in seats.into_iter() { for seat in seats.into_iter() {
if let Some(keyboard) = seat.get_keyboard() { if let Some(keyboard) = seat.get_keyboard() {
keyboard.change_repeat_info(
(value.repeat_rate as i32).abs(), // Negative values are illegal
(value.repeat_delay as i32).abs(),
);
if let Err(err) = keyboard.set_xkb_config(state, xkb_config_to_wl(&value)) { if let Err(err) = keyboard.set_xkb_config(state, xkb_config_to_wl(&value)) {
error!(?err, "Failed to load provided xkb config"); error!(?err, "Failed to load provided xkb config");
// TODO Revert to default? // TODO Revert to default?

View file

@ -186,13 +186,21 @@ pub fn create_seat(
// So instead of doing the right thing (and initialize these capabilities as matching // So instead of doing the right thing (and initialize these capabilities as matching
// devices appear), we have to surrender to reality and just always expose a keyboard and pointer. // devices appear), we have to surrender to reality and just always expose a keyboard and pointer.
let conf = config.xkb_config(); let conf = config.xkb_config();
if let Err(err) = seat.add_keyboard(xkb_config_to_wl(&conf), 600, 25) { if let Err(err) = seat.add_keyboard(
xkb_config_to_wl(&conf),
(conf.repeat_delay as i32).abs(),
(conf.repeat_rate as i32).abs(),
) {
warn!( warn!(
?err, ?err,
"Failed to load provided xkb config. Trying default...", "Failed to load provided xkb config. Trying default...",
); );
seat.add_keyboard(XkbConfig::default(), 600, 25) seat.add_keyboard(
.expect("Failed to load xkb configuration files"); XkbConfig::default(),
(conf.repeat_delay as i32).abs(),
(conf.repeat_rate as i32).abs(),
)
.expect("Failed to load xkb configuration files");
} }
seat.add_pointer(); seat.add_pointer();
seat.add_touch(); seat.add_touch();