feat: add typing assist section with keyboard repeat rate and delay

This commit is contained in:
LazyTanuki 2024-05-19 20:58:46 +02:00 committed by Michael Murphy
parent 2f54c11604
commit 79b01f211d
2 changed files with 84 additions and 1 deletions

View file

@ -5,7 +5,7 @@ use cosmic::{
iced::{self, Length},
iced_core::Border,
iced_style, theme,
widget::{self, button, container, icon, radio, settings},
widget::{self, button, container, icon, radio, row, settings},
Apply, Command, Element,
};
use cosmic_comp_config::XkbConfig;
@ -48,6 +48,8 @@ pub enum Message {
SourceAdd(DefaultKey),
SourceContext(SourceContext),
SpecialCharacterSelect(Option<&'static str>),
SetRepeatKeysDelay(u32),
SetRepeatKeysRate(u32),
}
#[derive(Clone, Debug)]
@ -63,6 +65,13 @@ pub type Locale = String;
pub type Variant = String;
pub type Description = String;
const KB_REPEAT_DELAY_DEFAULT: u32 = 600;
const KB_REPEAT_RATE_DEFAULT: u32 = 25;
const KB_REPEAT_DELAY_MAX: u32 = 1000;
const KB_REPEAT_DELAY_MIN: u32 = 200;
const KB_REPEAT_RATE_MAX: u32 = 45;
const KB_REPEAT_RATE_MIN: u32 = 5;
pub struct Page {
config: cosmic_config::Config,
context: Option<Context>,
@ -233,6 +242,7 @@ impl page::Page<crate::pages::Message> for Page {
sections.insert(input_sources()),
sections.insert(special_character_entry()),
sections.insert(keyboard_shortcuts()),
sections.insert(keyboard_typing_assist()),
])
}
@ -440,6 +450,14 @@ impl Page {
}
}
}
Message::SetRepeatKeysDelay(delay) => {
self.xkb.repeat_delay = delay;
self.update_xkb_config();
}
Message::SetRepeatKeysRate(rate) => {
self.xkb.repeat_rate = rate;
self.update_xkb_config();
}
}
Command::none()
@ -623,6 +641,63 @@ fn keyboard_shortcuts() -> Section<crate::pages::Message> {
})
}
fn keyboard_typing_assist() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("keyboard-typing-assist"))
.descriptions(vec![
fl!("keyboard-typing-assist", "repeat-delay").into(),
fl!("keyboard-typing-assist", "repeat-rate").into(),
fl!("short").into(),
fl!("long").into(),
fl!("slow").into(),
fl!("fast").into(),
])
.view::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
let theme = cosmic::theme::active();
settings::view_section(&section.title)
.add(settings::item(&*descriptions[0], {
// Delay
let delay_slider = cosmic::widget::slider(
KB_REPEAT_DELAY_MIN..=KB_REPEAT_DELAY_MAX,
page.xkb.repeat_delay,
Message::SetRepeatKeysDelay,
)
.width(250.0)
.breakpoints(&[KB_REPEAT_DELAY_DEFAULT])
.step(50_u32);
row::with_capacity(3)
.align_items(iced::Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(&*descriptions[2])
.push(delay_slider)
.push(&*descriptions[3])
}))
.add(settings::item(&*descriptions[1], {
// Repeat rate
let rate_slider = cosmic::widget::slider(
KB_REPEAT_RATE_MIN..=KB_REPEAT_RATE_MAX,
page.xkb.repeat_rate,
Message::SetRepeatKeysRate,
)
.width(250.0)
.breakpoints(&[KB_REPEAT_RATE_DEFAULT])
.step(5_u32);
row::with_capacity(3)
.align_items(iced::Alignment::Center)
.spacing(theme.cosmic().space_s())
.push(&*descriptions[4])
.push(rate_slider)
.push(&*descriptions[5])
}))
.apply(cosmic::Element::from)
.map(crate::pages::Message::Keyboard)
})
}
fn go_next_control<Msg: Clone + 'static>() -> cosmic::Element<'static, Msg> {
widget::row::with_children(vec![
widget::horizontal_space(Length::Fill).into(),

View file

@ -369,6 +369,10 @@ scrolling = Scrolling
## Input: Keyboard
slow = Slow
fast = Fast
short = Short
long = Long
keyboard = Keyboard
.desc = Keyboard input
@ -385,6 +389,10 @@ keyboard-special-char = Special Character Entry
.alternate = Alternate characters key
.compose = Compose key
keyboard-typing-assist = Typing
.repeat-rate = Repeat rate
.repeat-delay = Repeat delay
added = Added
type-to-search = Type to search...