From 79b01f211d72446b1fb129b0b1946ff123382449 Mon Sep 17 00:00:00 2001 From: LazyTanuki <43273245+lazytanuki@users.noreply.github.com> Date: Sun, 19 May 2024 20:58:46 +0200 Subject: [PATCH] feat: add typing assist section with keyboard repeat rate and delay --- .../src/pages/input/keyboard/mod.rs | 77 ++++++++++++++++++- i18n/en/cosmic_settings.ftl | 8 ++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/cosmic-settings/src/pages/input/keyboard/mod.rs b/cosmic-settings/src/pages/input/keyboard/mod.rs index 55bd870..ea0eb6e 100644 --- a/cosmic-settings/src/pages/input/keyboard/mod.rs +++ b/cosmic-settings/src/pages/input/keyboard/mod.rs @@ -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, @@ -233,6 +242,7 @@ impl page::Page 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 { }) } +fn keyboard_typing_assist() -> Section { + 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::(|_binder, page, section| { + let descriptions = §ion.descriptions; + let theme = cosmic::theme::active(); + + settings::view_section(§ion.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() -> cosmic::Element<'static, Msg> { widget::row::with_children(vec![ widget::horizontal_space(Length::Fill).into(), diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index 7d0d01a..52589bd 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -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...