fix(touchpad): update page to match design

This commit is contained in:
Vukašin Vojinović 2024-08-25 16:43:18 +02:00 committed by Michael Murphy
parent ddbdc6251b
commit 852f554763
7 changed files with 117 additions and 79 deletions

View file

@ -57,8 +57,8 @@ impl page::AutoBind<crate::pages::Message> for Page {
#[derive(Copy, Clone, Debug)]
pub enum Message {
ShowMinimizeButton(bool),
ShowMaximizeButton(bool),
ShowMinimizeButton(bool),
}
impl Page {

View file

@ -107,8 +107,8 @@ pub fn super_key_action() -> Section<crate::pages::Message> {
pub fn window_controls() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();
let minimize = descriptions.insert(fl!("window-controls", "minimize"));
let maximize = descriptions.insert(fl!("window-controls", "maximize"));
let minimize = descriptions.insert(fl!("window-controls", "minimize"));
Section::default()
.title(fl!("window-controls"))
@ -120,14 +120,6 @@ pub fn window_controls() -> Section<crate::pages::Message> {
let descriptions = &section.descriptions;
settings::view_section(&section.title)
.add(settings::item(
&descriptions[minimize],
toggler(
None,
desktop.cosmic_tk.show_minimize,
super::Message::ShowMinimizeButton,
),
))
.add(settings::item(
&descriptions[maximize],
toggler(
@ -136,6 +128,14 @@ pub fn window_controls() -> Section<crate::pages::Message> {
super::Message::ShowMaximizeButton,
),
))
.add(settings::item(
&descriptions[minimize],
toggler(
None,
desktop.cosmic_tk.show_minimize,
super::Message::ShowMinimizeButton,
),
))
.apply(Element::from)
.map(crate::pages::Message::Desktop)
})

View file

@ -76,9 +76,9 @@ pub enum Message {
/// Configures mirroring status of a display.
Mirroring(Mirroring),
/// Handle night light preferences.
// NightLight(NightLight),
// NightLight(NightLight),
/// Show the night light mode context drawer.
// NightLightContext,
// NightLightContext,
/// Set the orientation of a display.
Orientation(Transform),
/// Pan the displays view
@ -128,7 +128,7 @@ pub struct Page {
background_service: Option<tokio::task::JoinHandle<()>>,
config: Config,
cache: ViewCache,
// context: Option<ContextDrawer>,
// context: Option<ContextDrawer>,
display_arrangement_scrollable: widget::Id,
/// Tracks the last pan status.
last_pan: f32,
@ -150,7 +150,7 @@ impl Default for Page {
background_service: None,
config: Config::default(),
cache: ViewCache::default(),
// context: None,
// context: None,
display_arrangement_scrollable: widget::Id::unique(),
last_pan: 0.5,
dialog: None,
@ -163,7 +163,7 @@ impl Default for Page {
#[derive(Default)]
struct Config {
/// Whether night light is enabled.
// night_light_enabled: bool,
// night_light_enabled: bool,
refresh_rate: Option<u32>,
resolution: Option<(u32, u32)>,
scale: u32,
@ -191,15 +191,15 @@ impl page::Page<crate::pages::Message> for Page {
) -> Option<page::Content> {
Some(vec![
// Night light
// sections.insert(
// Section::default()
// .descriptions(vec![
// text::NIGHT_LIGHT.as_str().into(),
// text::NIGHT_LIGHT_AUTO.as_str().into(),
// text::NIGHT_LIGHT_DESCRIPTION.as_str().into(),
// ])
// .view::<Page>(move |_binder, page, _section| page.night_light_view()),
// ),
// sections.insert(
// Section::default()
// .descriptions(vec![
// text::NIGHT_LIGHT.as_str().into(),
// text::NIGHT_LIGHT_AUTO.as_str().into(),
// text::NIGHT_LIGHT_DESCRIPTION.as_str().into(),
// ])
// .view::<Page>(move |_binder, page, _section| page.night_light_view()),
// ),
// Display arrangement
sections.insert(display_arrangement()),
// Display configuration
@ -305,14 +305,14 @@ impl page::Page<crate::pages::Message> for Page {
})
}
// fn context_drawer(&self) -> Option<Element<pages::Message>> {
// Some(match self.context {
// fn context_drawer(&self) -> Option<Element<pages::Message>> {
// Some(match self.context {
// Some(ContextDrawer::NightLight) => self.night_light_context_view(),
// Some(ContextDrawer::NightLight) => self.night_light_context_view(),
// None => return None,
// })
// }
// None => return None,
// })
// }
/// Opens a dialog to confirm the display settings.
///
@ -413,14 +413,14 @@ impl Page {
} // Mirroring::ProjectToAll => (),
},
// Message::NightLight(night_light) => {}
// Message::NightLight(night_light) => {}
//
// Message::NightLightContext => {
// self.context = Some(ContextDrawer::NightLight);
// return cosmic::command::message(app::Message::OpenContextDrawer(
// text::NIGHT_LIGHT.clone().into(),
// ));
// }
// Message::NightLightContext => {
// self.context = Some(ContextDrawer::NightLight);
// return cosmic::command::message(app::Message::OpenContextDrawer(
// text::NIGHT_LIGHT.clone().into(),
// ));
// }
Message::Orientation(orientation) => return self.set_orientation(orientation),
Message::Pan(pan) => {
@ -480,9 +480,9 @@ impl Page {
}
/// Displays the night light context drawer.
// pub fn night_light_context_view(&self) -> Element<pages::Message> {
// column().into()
// }
// pub fn night_light_context_view(&self) -> Element<pages::Message> {
// column().into()
// }
/// Reloads the display list, and all information relevant to the active display.
pub fn update_displays(&mut self, list: List) {

View file

@ -1,16 +1,36 @@
use cosmic::cosmic_config::ConfigGet;
use cosmic::iced::{Alignment, Length};
use cosmic::widget::{self, row, settings, text};
use cosmic::{Apply, Element};
use cosmic_comp_config::input::{AccelProfile, ClickMethod, ScrollMethod};
use cosmic_comp_config::workspace::{WorkspaceConfig, WorkspaceLayout};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use slab::Slab;
use slotmap::SlotMap;
use tracing::error;
use super::Message;
#[derive(Default)]
pub struct Page;
pub struct Page {
comp_workspace_config: WorkspaceConfig,
}
impl Default for Page {
fn default() -> Self {
let comp_config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
let comp_workspace_config = comp_config.get("workspaces").unwrap_or_else(|err| {
if !matches!(err, cosmic_config::Error::NoConfigDirectory) {
error!(?err, "Failed to read config 'workspaces'");
}
WorkspaceConfig::default()
});
Self {
comp_workspace_config,
}
}
}
impl page::Page<crate::pages::Message> for Page {
fn content(
@ -21,7 +41,7 @@ impl page::Page<crate::pages::Message> for Page {
sections.insert(touchpad()),
sections.insert(click_behavior()),
sections.insert(scrolling()),
sections.insert(swiping()),
sections.insert(gestures()),
])
}
@ -38,6 +58,7 @@ fn touchpad() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();
let primary_button = descriptions.insert(fl!("primary-button"));
let primary_button_desc = descriptions.insert(fl!("primary-button", "desc"));
let touchpad_speed = descriptions.insert(fl!("touchpad", "speed"));
let acceleration = descriptions.insert(fl!("touchpad", "acceleration"));
let acceleration_desc = descriptions.insert(fl!("acceleration-desc"));
@ -51,12 +72,17 @@ fn touchpad() -> Section<crate::pages::Message> {
let theme = cosmic::theme::active();
settings::view_section(&section.title)
.add(settings::flex_item(
&descriptions[primary_button],
cosmic::widget::segmented_control::horizontal(&input.touchpad_primary_button)
.minimum_button_width(0)
.on_activate(|x| Message::PrimaryButtonSelected(x, true)),
))
.add(
settings::item::builder(&descriptions[primary_button])
.description(&descriptions[primary_button_desc])
.flex_control(
cosmic::widget::segmented_control::horizontal(
&input.touchpad_primary_button,
)
.minimum_button_width(0)
.on_activate(|x| Message::PrimaryButtonSelected(x, true)),
),
)
.add(
settings::item::builder(&descriptions[touchpad_speed]).flex_control({
let value = (input
@ -238,25 +264,27 @@ fn scrolling() -> Section<crate::pages::Message> {
})
}
fn swiping() -> Section<crate::pages::Message> {
fn gestures() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();
let four_finger_down = descriptions.insert(fl!("gestures", "four-finger-down"));
// let four_finger_down = descriptions.insert(fl!("gestures", "four-finger-down"));
// let four_finger_left = descriptions.insert(fl!("gestures", "four-finger-left"));
// let four_finger_right = descriptions.insert(fl!("gestures", "four-finger-right"));
let four_finger_up = descriptions.insert(fl!("gestures", "four-finger-up"));
// let four_finger_up = descriptions.insert(fl!("gestures", "four-finger-up"));
// let three_finger_any = descriptions.insert(fl!("gestures", "three-finger-any"));
let switch_workspaces = descriptions.insert(fl!("switch-workspaces"));
let switch_workspaces_horizontal = descriptions.insert(fl!("switch-workspaces", "horizontal"));
let switch_workspaces_vertical = descriptions.insert(fl!("switch-workspaces", "vertical"));
// let open_application_library = descriptions.insert(fl!("open-application-library"));
// let open_workspaces_view = descriptions.insert(fl!("open-workspaces-view"));
// let switch_between_windows = descriptions.insert(fl!("switch-between-windows"));
let switch_to_next_workspace = descriptions.insert(fl!("switch-to-next-workspace"));
let switch_to_prev_workspace = descriptions.insert(fl!("switch-to-prev-workspace"));
Section::default()
.title(fl!("gestures"))
.descriptions(descriptions)
.view::<Page>(move |_binder, _page, section| {
.view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions;
settings::view_section(&*section.title)
@ -265,12 +293,13 @@ fn swiping() -> Section<crate::pages::Message> {
// .flex_control(text(&descriptions[switch_between_windows])),
// )
.add(
settings::item::builder(&descriptions[four_finger_up])
.flex_control(text(&descriptions[switch_to_prev_workspace])),
)
.add(
settings::item::builder(&descriptions[four_finger_down])
.flex_control(text(&descriptions[switch_to_next_workspace])),
settings::item::builder(
&descriptions[match page.comp_workspace_config.workspace_layout {
WorkspaceLayout::Horizontal => switch_workspaces_horizontal,
WorkspaceLayout::Vertical => switch_workspaces_vertical,
}],
)
.flex_control(text(&descriptions[switch_workspaces])),
)
// .add(
// settings::item::builder(&descriptions[four_finger_left])