feat: settings application architecture
This commit is contained in:
commit
2709dcfee5
43 changed files with 7244 additions and 0 deletions
24
src/page/desktop/appearance.rs
Normal file
24
src/page/desktop/appearance.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
use slotmap::SlotMap;
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "appearance";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("appearance"))
|
||||
.description(fl!("appearance", "desc"))
|
||||
.icon_name("preferences-pop-desktop-appearance-symbolic")
|
||||
}
|
||||
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![sections.insert(Section::new())])
|
||||
}
|
||||
}
|
||||
25
src/page/desktop/dock.rs
Normal file
25
src/page/desktop/dock.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use slotmap::SlotMap;
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "dock";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("dock"))
|
||||
.description(fl!("dock", "desc"))
|
||||
.icon_name("preferences-pop-desktop-dock-symbolic")
|
||||
}
|
||||
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![sections.insert(Section::new())])
|
||||
}
|
||||
}
|
||||
119
src/page/desktop/mod.rs
Normal file
119
src/page/desktop/mod.rs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
pub mod appearance;
|
||||
pub mod dock;
|
||||
pub mod notifications;
|
||||
pub mod options;
|
||||
pub mod wallpaper;
|
||||
pub mod workspaces;
|
||||
|
||||
use crate::page;
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "desktop";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("desktop"))
|
||||
.icon_name("video-display-symbolic")
|
||||
}
|
||||
|
||||
fn sub_pages(page: page::Insert) -> page::Insert {
|
||||
page.sub_page::<options::Page>()
|
||||
.sub_page::<wallpaper::Page>()
|
||||
.sub_page::<appearance::Page>()
|
||||
.sub_page::<dock::Page>()
|
||||
.sub_page::<workspaces::Page>()
|
||||
.sub_page::<notifications::Page>()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Message {
|
||||
Slideshow(bool),
|
||||
SameBackground(bool),
|
||||
ShowWorkspacesButton(bool),
|
||||
ShowApplicationsButton(bool),
|
||||
ShowMinimizeButton(bool),
|
||||
ShowMaximizeButton(bool),
|
||||
TopLeftHotCorner(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct Model {
|
||||
pub top_left_hot_corner: bool,
|
||||
pub show_workspaces_button: bool,
|
||||
pub show_applications_button: bool,
|
||||
pub show_minimize_button: bool,
|
||||
pub show_maximize_button: bool,
|
||||
pub slideshow: bool,
|
||||
pub same_background: bool,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::SameBackground(value) => self.same_background = value,
|
||||
Message::ShowApplicationsButton(value) => self.show_applications_button = value,
|
||||
Message::ShowMaximizeButton(value) => self.show_maximize_button = value,
|
||||
Message::ShowMinimizeButton(value) => self.show_minimize_button = value,
|
||||
Message::ShowWorkspacesButton(value) => self.show_workspaces_button = value,
|
||||
Message::Slideshow(value) => self.slideshow = value,
|
||||
Message::TopLeftHotCorner(value) => self.top_left_hot_corner = value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl From<Page> for Message {
|
||||
// fn from(page: Page) -> Message {
|
||||
// Message::Page(page)
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub enum Output {
|
||||
// Page(Page),
|
||||
// }
|
||||
|
||||
// impl SubPage for DesktopPage {
|
||||
// //TODO: translate
|
||||
// fn title(&self) -> &'static str {
|
||||
// use DesktopPage::*;
|
||||
// match self {
|
||||
// Workspaces => "Workspaces",
|
||||
// Notifications => "Notifications",
|
||||
// }
|
||||
// }
|
||||
|
||||
// //TODO: translate
|
||||
// fn description(&self) -> &'static str {
|
||||
// use DesktopPage::*;
|
||||
// match self {
|
||||
// Workspaces => "Set workspace number, behavior, and placement.",
|
||||
// Notifications => {
|
||||
// "Do Not Disturb, lockscreen notifications, and per-application settings."
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn icon_name(&self) -> &'static str {
|
||||
// use DesktopPage::*;
|
||||
// match self {
|
||||
// Workspaces => "preferences-pop-desktop-workspaces-symbolic",
|
||||
// Notifications => "preferences-system-notifications-symbolic",
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn parent_page(&self) -> Page {
|
||||
// Page::Desktop(None)
|
||||
// }
|
||||
|
||||
// fn into_page(self) -> Page {
|
||||
// Page::Desktop(Some(self))
|
||||
// }
|
||||
// }
|
||||
25
src/page/desktop/notifications.rs
Normal file
25
src/page/desktop/notifications.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use slotmap::SlotMap;
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "notifications";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("notifications"))
|
||||
.description(fl!("notifications", "desc"))
|
||||
.icon_name("preferences-system-notifications-symbolic")
|
||||
}
|
||||
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![sections.insert(Section::new())])
|
||||
}
|
||||
}
|
||||
167
src/page/desktop/options.rs
Normal file
167
src/page/desktop/options.rs
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::Message;
|
||||
use apply::Apply;
|
||||
use cosmic::{
|
||||
iced::widget::horizontal_space,
|
||||
iced::Length,
|
||||
widget::{settings, toggler},
|
||||
Element,
|
||||
};
|
||||
|
||||
use slotmap::SlotMap;
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "desktop-options";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("desktop-options"))
|
||||
.description(fl!("desktop-options", "desc"))
|
||||
.icon_name("video-display-symbolic")
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![
|
||||
sections.insert(super_key_action()),
|
||||
sections.insert(hot_corner()),
|
||||
sections.insert(top_panel()),
|
||||
sections.insert(window_controls()),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hot_corner() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("hot-corner"))
|
||||
.descriptions(vec![fl!("hot-corner", "top-left-corner")])
|
||||
.view_fn(|app, section| {
|
||||
let desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
let descriptions = §ion.descriptions;
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
toggler(None, desktop.top_left_hot_corner, |value| {
|
||||
Message::TopLeftHotCorner(value)
|
||||
}),
|
||||
))
|
||||
.apply(Element::from)
|
||||
.map(crate::Message::Desktop)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn super_key_action() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("super-key-action"))
|
||||
.descriptions(vec![
|
||||
fl!("super-key-action", "launcher"),
|
||||
fl!("super-key-action", "workspaces"),
|
||||
fl!("super-key-action", "applications"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let _desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
|
||||
let descriptions = §ion.descriptions;
|
||||
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[2],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn top_panel() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("top-panel"))
|
||||
.descriptions(vec![
|
||||
fl!("top-panel", "workspaces"),
|
||||
fl!("top-panel", "applications"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
let descriptions = §ion.descriptions;
|
||||
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
toggler(
|
||||
None,
|
||||
desktop.show_workspaces_button,
|
||||
Message::ShowWorkspacesButton,
|
||||
),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
toggler(
|
||||
None,
|
||||
desktop.show_applications_button,
|
||||
Message::ShowApplicationsButton,
|
||||
),
|
||||
))
|
||||
.apply(Element::from)
|
||||
.map(crate::Message::Desktop)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn window_controls() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("window-controls"))
|
||||
.descriptions(vec![
|
||||
fl!("window-controls", "minimize"),
|
||||
fl!("window-controls", "maximize"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
let descriptions = §ion.descriptions;
|
||||
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
toggler(
|
||||
None,
|
||||
desktop.show_minimize_button,
|
||||
Message::ShowMinimizeButton,
|
||||
),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
toggler(
|
||||
None,
|
||||
desktop.show_maximize_button,
|
||||
Message::ShowMaximizeButton,
|
||||
),
|
||||
))
|
||||
.apply(Element::from)
|
||||
.map(crate::Message::Desktop)
|
||||
})
|
||||
}
|
||||
98
src/page/desktop/wallpaper.rs
Normal file
98
src/page/desktop/wallpaper.rs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::Message;
|
||||
use apply::Apply;
|
||||
use cosmic::{
|
||||
iced::widget::{column, container, horizontal_space, image, row, svg, text},
|
||||
iced::Length,
|
||||
theme,
|
||||
widget::{list_column, settings, toggler},
|
||||
Element,
|
||||
};
|
||||
use slotmap::SlotMap;
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "wallpaper";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("wallpaper"))
|
||||
.description(fl!("wallpaper", "desc"))
|
||||
.icon_name("preferences-desktop-wallpaper-symbolic")
|
||||
}
|
||||
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![sections.insert(settings())])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn settings() -> Section {
|
||||
Section::new()
|
||||
.descriptions(vec![
|
||||
fl!("wallpaper", "same"),
|
||||
fl!("wallpaper", "fit"),
|
||||
fl!("wallpaper", "slide"),
|
||||
fl!("wallpaper", "change"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let descriptions = §ion.descriptions;
|
||||
let desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
let image_paths: Vec<std::path::PathBuf> = Vec::new();
|
||||
|
||||
let mut image_column = Vec::with_capacity(image_paths.len() / 4);
|
||||
for chunk in image_paths.chunks(4) {
|
||||
let mut image_row = Vec::with_capacity(chunk.len());
|
||||
for image_path in chunk.iter() {
|
||||
image_row.push(if image_path.ends_with(".svg") {
|
||||
svg(svg::Handle::from_path(image_path))
|
||||
.width(Length::Units(150))
|
||||
.into()
|
||||
} else {
|
||||
image(image_path).width(Length::Units(150)).into()
|
||||
});
|
||||
}
|
||||
image_column.push(row(image_row).spacing(16).into());
|
||||
}
|
||||
|
||||
let children = vec![
|
||||
row!(
|
||||
horizontal_space(Length::Fill),
|
||||
container(
|
||||
image("/usr/share/backgrounds/pop/kate-hazen-COSMIC-desktop-wallpaper.png")
|
||||
.width(Length::Units(300))
|
||||
)
|
||||
.padding(4)
|
||||
.style(theme::Container::Box),
|
||||
horizontal_space(Length::Fill),
|
||||
)
|
||||
.into(),
|
||||
list_column()
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
toggler(None, desktop.same_background, Message::SameBackground),
|
||||
))
|
||||
.add(settings::item(&descriptions[1], text("TODO")))
|
||||
.add(settings::item(
|
||||
&descriptions[2],
|
||||
toggler(None, desktop.slideshow, Message::Slideshow),
|
||||
))
|
||||
.into(),
|
||||
column(image_column).spacing(16).into(),
|
||||
];
|
||||
|
||||
settings::view_column(children)
|
||||
.padding(0)
|
||||
.apply(Element::from)
|
||||
.map(crate::Message::Desktop)
|
||||
})
|
||||
}
|
||||
84
src/page/desktop/workspaces.rs
Normal file
84
src/page/desktop/workspaces.rs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::iced::{widget::horizontal_space, Length};
|
||||
use cosmic::widget::settings;
|
||||
use slotmap::SlotMap;
|
||||
|
||||
use crate::page::{self, section, Content, Section};
|
||||
|
||||
pub struct Page;
|
||||
|
||||
impl page::Page for Page {
|
||||
type Model = super::Model;
|
||||
|
||||
const PERSISTENT_ID: &'static str = "workspaces";
|
||||
|
||||
fn page() -> page::Meta {
|
||||
page::Meta::default()
|
||||
.title(fl!("workspaces"))
|
||||
.description(fl!("workspaces", "desc"))
|
||||
.icon_name("preferences-pop-desktop-workspaces-symbolic")
|
||||
}
|
||||
|
||||
fn content(sections: &mut SlotMap<section::Entity, Section>) -> Option<Content> {
|
||||
Some(vec![
|
||||
sections.insert(behavior()),
|
||||
sections.insert(multi_behavior()),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
fn behavior() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("workspaces-behavior"))
|
||||
.descriptions(vec![
|
||||
fl!("workspaces-behavior", "dynamic"),
|
||||
fl!("workspaces-behavior", "fixed"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let _desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
|
||||
let descriptions = §ion.descriptions;
|
||||
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
fn multi_behavior() -> Section {
|
||||
Section::new()
|
||||
.title(fl!("workspaces-multi-behavior"))
|
||||
.descriptions(vec![
|
||||
fl!("workspaces-multi-behavior", "span"),
|
||||
fl!("workspaces-multi-behavior", "separate"),
|
||||
])
|
||||
.view_fn(|app, section| {
|
||||
let _desktop = app
|
||||
.pages
|
||||
.resource::<super::Model>()
|
||||
.expect("desktop model is missing");
|
||||
let descriptions = §ion.descriptions;
|
||||
settings::view_section(§ion.title)
|
||||
.add(settings::item(
|
||||
&descriptions[0],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
horizontal_space(Length::Fill),
|
||||
))
|
||||
.into()
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue