feat(input): additional configuration options

This commit is contained in:
Michael Aaron Murphy 2024-02-19 13:12:00 +01:00 committed by Michael Murphy
parent 926692200d
commit 02ff3e6445
12 changed files with 423 additions and 287 deletions

View file

@ -1,24 +1,35 @@
use apply::Apply;
use cosmic::iced::Length;
use cosmic::widget::{self, settings};
use cosmic::Element;
use cosmic_comp_config::input::AccelProfile;
use cosmic::{Apply, Element};
use cosmic_comp_config::input::{AccelProfile, ScrollMethod};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use slotmap::SlotMap;
use std::borrow::Cow;
use super::Message;
crate::cache_dynamic_lazy! {
static MOUSE_SCROLL_SPEED: String = fl!("mouse-scrolling", "speed");
static MOUSE_SCROLL_NATURAL: String = fl!("mouse-scrolling", "natural");
static MOUSE_SCROLL_NATURAL_DESC: String = fl!("mouse-scrolling", "natural-desc");
static TOUCHPAD_PRIMARY_BUTTON: String = fl!("touchpad", "primary-button");
static TOUCHPAD_SPEED: String = fl!("touchpad", "speed");
static EDGE_SCROLLING_DESC: String = fl!("edge-scrolling", "desc");
static EDGE_SCROLLING: String = fl!("edge-scrolling");
static TWO_FINGER_SCROLLING: String = fl!("two-finger-scrolling");
static PINCH_TO_ZOOM_DESC: String = fl!("pinch-to-zoom", "desc");
static PINCH_TO_ZOOM: String = fl!("pinch-to-zoom");
// static SWIPING_FOUR_FINGER_DOWN: String = fl!("swiping", "four-finger-down");
// static SWIPING_FOUR_FINGER_LEFT: String = fl!("swiping", "four-finger-left");
// static SWIPING_FOUR_FINGER_RIGHT: String = fl!("swiping", "four-finger-right");
// static SWIPING_FOUR_FINGER_UP: String = fl!("swiping", "four-finger-up");
// static SWIPING_THREE_FINGER_ANY: String = fl!("swiping", "three-finger-any");
// static SWIPING: String = fl!("swiping");
static TAP_TO_CLICK_DESC: String = fl!("tap-to-click", "desc");
static TAP_TO_CLICK: String = fl!("tap-to-click");
static TAPPING_AND_PINCHING: String = fl!("tapping-and-pinching");
static TOUCHPAD_ACCELERAION: String = fl!("touchpad", "acceleration");
static TOUCHPAD_ACCELERAION_DESC: String = fl!("touchpad", "acceleration-desc");
static TOUCHPAD_DOUBLE_CLICK_SPEED: String = fl!("touchpad", "double-click-speed");
static TOUCHPAD_DOUBLE_CLICK_SPEED_DESC: String = fl!("touchpad", "double-click-speed-desc");
static TOUCHPAD_SPEED: String = fl!("touchpad", "speed");
// static SWITCH_BETWEEN_WINDOWS: String = fl!("switch-between-windows");
// static SWITCH_TO_NEXT_WORKSPACE: String = fl!("switch-to-next-workspace");
// static SWITCH_TO_PREV_WORKSPACE: String = fl!("switch-to-prev-workspace");
// static OPEN_APPLICATION_LIBRARY: String = fl!("open-application-library");
}
#[derive(Default)]
@ -31,7 +42,9 @@ impl page::Page<crate::pages::Message> for Page {
) -> Option<page::Content> {
Some(vec![
sections.insert(touchpad()),
sections.insert(tapping_and_pinching()),
sections.insert(scrolling()),
// sections.insert(swiping()),
])
}
@ -47,20 +60,22 @@ impl page::AutoBind<crate::pages::Message> for Page {}
fn touchpad() -> Section<crate::pages::Message> {
Section::default()
.descriptions(vec![
TOUCHPAD_PRIMARY_BUTTON.as_str().into(),
super::PRIMARY_BUTTON.as_str().into(),
TOUCHPAD_SPEED.as_str().into(),
TOUCHPAD_ACCELERAION.as_str().into(),
TOUCHPAD_ACCELERAION_DESC.as_str().into(),
TOUCHPAD_DOUBLE_CLICK_SPEED.as_str().into(),
TOUCHPAD_DOUBLE_CLICK_SPEED_DESC.as_str().into(),
super::ACCELERAION_DESC.as_str().into(),
super::DISABLE_WHILE_TYPING.as_str().into(),
super::DOUBLE_CLICK_SPEED.as_str().into(),
super::DOUBLE_CLICK_SPEED_DESC.as_str().into(),
])
.view::<Page>(|binder, _page, section| {
let input = binder.page::<super::Page>().expect("input page not found");
settings::view_section(&section.title)
.add(settings::item(
&*TOUCHPAD_PRIMARY_BUTTON,
&*super::PRIMARY_BUTTON,
cosmic::widget::segmented_selection::horizontal(&input.touchpad_primary_button)
.minimum_button_width(0)
.on_activate(|x| Message::PrimaryButtonSelected(x, true)),
))
.add(
@ -78,7 +93,7 @@ fn touchpad() -> Section<crate::pages::Message> {
)
.add(
settings::item::builder(&*TOUCHPAD_ACCELERAION)
.description(&*TOUCHPAD_ACCELERAION_DESC)
.description(&*super::ACCELERAION_DESC)
.toggler(
input
.input_touchpad
@ -88,10 +103,15 @@ fn touchpad() -> Section<crate::pages::Message> {
|x| Message::SetAcceleration(x, true),
),
)
// TODO disable while typing
.add(
settings::item::builder(&*TOUCHPAD_DOUBLE_CLICK_SPEED)
.description(&*TOUCHPAD_DOUBLE_CLICK_SPEED_DESC)
settings::item::builder(&*super::DISABLE_WHILE_TYPING).toggler(
input.input_touchpad.disable_while_typing.unwrap_or(false),
|enabled| Message::DisableWhileTyping(enabled, true),
),
)
.add(
settings::item::builder(&*super::DOUBLE_CLICK_SPEED)
.description(&*super::DOUBLE_CLICK_SPEED_DESC)
.control(widget::slider(0..=100, 0, |x| {
Message::SetDoubleClickSpeed(x, true)
})),
@ -101,26 +121,61 @@ fn touchpad() -> Section<crate::pages::Message> {
})
}
fn tapping_and_pinching() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("tapping-and-pinching"))
.descriptions(vec![
TAP_TO_CLICK.as_str().into(),
TAP_TO_CLICK_DESC.as_str().into(),
PINCH_TO_ZOOM.as_str().into(),
PINCH_TO_ZOOM_DESC.as_str().into(),
])
.view::<Page>(|binder, _page, _section| {
let page = binder
.page::<super::Page>()
.expect("input devices page not found");
settings::view_section(&*TAPPING_AND_PINCHING)
.add(
settings::item::builder(&*TAP_TO_CLICK).toggler(
page.input_touchpad
.tap_config
.as_ref()
.map_or(false, |x| x.enabled),
Message::TapToClick,
),
)
.add(settings::item::builder(&*PINCH_TO_ZOOM).toggler(false, Message::PinchToZoom))
.apply(Element::from)
.map(crate::pages::Message::Input)
})
}
fn scrolling() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("mouse-scrolling"))
.title(fl!("scrolling"))
.descriptions(vec![
MOUSE_SCROLL_SPEED.as_str().into(),
MOUSE_SCROLL_NATURAL.as_str().into(),
MOUSE_SCROLL_NATURAL_DESC.as_str().into(),
super::SCROLLING_SPEED.as_str().into(),
super::SCROLLING_NATURAL.as_str().into(),
super::SCROLLING_NATURAL_DESC.as_str().into(),
TWO_FINGER_SCROLLING.as_str().into(),
EDGE_SCROLLING.as_str().into(),
EDGE_SCROLLING_DESC.as_str().into(),
])
.view::<Page>(|binder, _page, section| {
let input = binder.page::<super::Page>().expect("input page not found");
let page = binder
.page::<super::Page>()
.expect("input devices page not found");
settings::view_section(&section.title)
// Scroll speed slider
.add(settings::item(
&*MOUSE_SCROLL_SPEED,
&*super::SCROLLING_SPEED,
// TODO show numeric value
// TODO desired range?
widget::slider(
1.0..=100.0,
input
.input_touchpad
1.0..=1000.0,
page.input_touchpad
.scroll_config
.as_ref()
.and_then(|x| x.scroll_factor)
@ -131,20 +186,63 @@ fn scrolling() -> Section<crate::pages::Message> {
|value| Message::SetScrollFactor(2f64.powf((value - 50.0) / 10.0), true),
),
))
// Natural scrolling toggle
.add(
settings::item::builder(&*MOUSE_SCROLL_NATURAL)
.description(&*MOUSE_SCROLL_NATURAL_DESC)
settings::item::builder(&*super::SCROLLING_NATURAL)
.description(&*super::SCROLLING_NATURAL_DESC)
.toggler(
input
.input_touchpad
page.input_touchpad
.scroll_config
.as_ref()
.and_then(|x| x.natural_scroll)
.unwrap_or(false),
|x| Message::SetNaturalScroll(x, true),
.map_or(false, |conf| conf.natural_scroll.unwrap_or(false)),
|enabled| Message::SetNaturalScroll(enabled, true),
),
)
// Two-finger scrolling toggle
.add(
settings::item::builder(&*TWO_FINGER_SCROLLING).toggler(
page.input_touchpad
.scroll_config
.as_ref()
.map_or(false, |x| matches!(x.method, Some(ScrollMethod::TwoFinger))),
|enabled| {
Message::SetScrollMethod(
enabled.then_some(ScrollMethod::TwoFinger),
true,
)
},
),
)
// Edge scrolling toggle
.add(
settings::item::builder(&*EDGE_SCROLLING)
.description(&*EDGE_SCROLLING_DESC)
.toggler(
page.input_touchpad
.scroll_config
.as_ref()
.map_or(false, |x| matches!(x.method, Some(ScrollMethod::Edge))),
|enabled| {
Message::SetScrollMethod(
enabled.then_some(ScrollMethod::Edge),
true,
)
},
),
)
.apply(Element::from)
.map(crate::pages::Message::Input)
})
}
// fn swiping() -> Section<crate::pages::Message> {
// Section::default()
// .title(&*SWIPING)
// .descriptions(vec![
// SWIPING_FOUR_FINGER_DOWN.as_str().into(),
// SWIPING_FOUR_FINGER_LEFT.as_str().into(),
// SWIPING_FOUR_FINGER_RIGHT.as_str().into(),
// SWIPING_FOUR_FINGER_UP.as_str().into(),
// SWIPING_THREE_FINGER_ANY.as_str().into(),
// ])
// }