Skip to content

Commit cc8586e

Browse files
git-f0xmmstick
authored andcommittedMar 21, 2025·
feat: add applications page
1 parent 5f8e9d1 commit cc8586e

15 files changed

+274
-120
lines changed
 

‎cosmic-settings/src/app.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::config::Config;
55
#[cfg(feature = "page-accessibility")]
66
use crate::pages::accessibility;
7+
use crate::pages::applications;
78
#[cfg(feature = "page-bluetooth")]
89
use crate::pages::bluetooth;
910
use crate::pages::desktop::{self, appearance};
@@ -84,12 +85,13 @@ impl SettingsApp {
8485
#[cfg(feature = "page-about")]
8586
PageCommands::About => self.pages.page_id::<system::about::Page>(),
8687
PageCommands::Appearance => self.pages.page_id::<desktop::appearance::Page>(),
88+
PageCommands::Applications => self.pages.page_id::<applications::Page>(),
8789
#[cfg(feature = "page-bluetooth")]
8890
PageCommands::Bluetooth => self.pages.page_id::<bluetooth::Page>(),
8991
#[cfg(feature = "page-date")]
9092
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
9193
#[cfg(feature = "page-default-apps")]
92-
PageCommands::DefaultApps => self.pages.page_id::<system::default_apps::Page>(),
94+
PageCommands::DefaultApps => self.pages.page_id::<applications::default_apps::Page>(),
9395
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
9496
#[cfg(feature = "page-display")]
9597
PageCommands::Displays => self.pages.page_id::<display::Page>(),
@@ -100,6 +102,9 @@ impl SettingsApp {
100102
PageCommands::Input => self.pages.page_id::<input::Page>(),
101103
#[cfg(feature = "page-input")]
102104
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
105+
PageCommands::LegacyApplications => self
106+
.pages
107+
.page_id::<applications::legacy_applications::Page>(),
103108
#[cfg(feature = "page-input")]
104109
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
105110
#[cfg(feature = "page-networking")]
@@ -214,6 +219,7 @@ impl cosmic::Application for SettingsApp {
214219
app.insert_page::<power::Page>();
215220
#[cfg(feature = "page-input")]
216221
app.insert_page::<input::Page>();
222+
app.insert_page::<applications::Page>();
217223
app.insert_page::<time::Page>();
218224
app.insert_page::<system::Page>();
219225

@@ -390,6 +396,10 @@ impl cosmic::Application for SettingsApp {
390396
}
391397
}
392398

399+
crate::pages::Message::Applications(message) => {
400+
page::update!(self.pages, message, applications::Page);
401+
}
402+
393403
#[cfg(feature = "page-bluetooth")]
394404
crate::pages::Message::Bluetooth(message) => {
395405
if let Some(page) = self.pages.page_mut::<bluetooth::Page>() {
@@ -406,7 +416,7 @@ impl cosmic::Application for SettingsApp {
406416

407417
#[cfg(feature = "page-default-apps")]
408418
crate::pages::Message::DefaultApps(message) => {
409-
if let Some(page) = self.pages.page_mut::<system::default_apps::Page>() {
419+
if let Some(page) = self.pages.page_mut::<applications::default_apps::Page>() {
410420
return page.update(message).map(Into::into);
411421
}
412422
}
@@ -478,6 +488,10 @@ impl cosmic::Application for SettingsApp {
478488
}
479489
}
480490

491+
crate::pages::Message::LegacyApplications(message) => {
492+
page::update!(self.pages, message, applications::legacy_applications::Page);
493+
}
494+
481495
#[cfg(feature = "page-input")]
482496
crate::pages::Message::ManageWindowShortcuts(message) => {
483497
if let Some(page) = self
@@ -614,7 +628,7 @@ impl cosmic::Application for SettingsApp {
614628
}
615629

616630
crate::pages::Message::StartupApps(message) => {
617-
if let Some(page) = self.pages.page_mut::<system::startup_apps::Page>() {
631+
if let Some(page) = self.pages.page_mut::<applications::startup_apps::Page>() {
618632
return page.update(message).map(Into::into);
619633
}
620634
}

‎cosmic-settings/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub enum PageCommands {
4949
About,
5050
/// Appearance settings page
5151
Appearance,
52+
/// Applications settings page
53+
Applications,
5254
/// Bluetooth settings page
5355
#[cfg(feature = "page-bluetooth")]
5456
Bluetooth,
@@ -74,6 +76,8 @@ pub enum PageCommands {
7476
/// Keyboard settings page
7577
#[cfg(feature = "page-input")]
7678
Keyboard,
79+
/// Legacy Applications settings page
80+
LegacyApplications,
7781
/// Mouse settings page
7882
#[cfg(feature = "page-input")]
7983
Mouse,

‎cosmic-settings/src/pages/accessibility/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use cosmic::{
2-
app,
32
cosmic_theme::{CosmicPalette, ThemeBuilder},
43
iced_core::text::Wrapping,
54
theme::{self, CosmicTheme},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2023 System76 <info@system76.com>
2+
// SPDX-License-Identifier: GPL-3.0-only
3+
4+
use cosmic::{
5+
cosmic_config::{self, ConfigGet, ConfigSet},
6+
iced::Length,
7+
widget::{self, text},
8+
Apply, Element,
9+
};
10+
use cosmic_settings_page::Section;
11+
use cosmic_settings_page::{self as page, section};
12+
use slab::Slab;
13+
use slotmap::SlotMap;
14+
use tracing::error;
15+
16+
#[derive(Clone, Debug)]
17+
pub enum Message {
18+
SetXwaylandDescaling(bool),
19+
}
20+
21+
pub struct Page {
22+
comp_config: cosmic_config::Config,
23+
comp_config_descale_xwayland: bool,
24+
}
25+
26+
impl Default for Page {
27+
fn default() -> Self {
28+
let comp_config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
29+
let comp_config_descale_xwayland =
30+
comp_config.get("descale_xwayland").unwrap_or_else(|err| {
31+
if err.is_err() {
32+
error!(?err, "Failed to read config 'descale_xwayland'");
33+
}
34+
35+
false
36+
});
37+
Self {
38+
comp_config,
39+
comp_config_descale_xwayland,
40+
}
41+
}
42+
}
43+
44+
impl page::Page<crate::pages::Message> for Page {
45+
fn content(
46+
&self,
47+
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
48+
) -> Option<page::Content> {
49+
Some(vec![sections.insert(
50+
// Xwayland scaling options
51+
legacy_application_scaling(),
52+
)])
53+
}
54+
55+
fn info(&self) -> page::Info {
56+
page::Info::new(
57+
"legacy-applications",
58+
"preferences-X11-applications-symbolic",
59+
)
60+
.title(fl!("legacy-applications"))
61+
.description(fl!("legacy-applications", "desc"))
62+
}
63+
}
64+
65+
impl page::AutoBind<crate::pages::Message> for Page {}
66+
67+
impl Page {
68+
pub fn update(&mut self, message: Message) {
69+
match message {
70+
Message::SetXwaylandDescaling(descale) => {
71+
self.comp_config_descale_xwayland = descale;
72+
if let Err(err) = self
73+
.comp_config
74+
.set("descale_xwayland", self.comp_config_descale_xwayland)
75+
{
76+
error!(?err, "Failed to set config 'descale_xwayland'");
77+
}
78+
}
79+
}
80+
}
81+
}
82+
83+
pub fn legacy_application_scaling() -> Section<crate::pages::Message> {
84+
let mut descriptions = Slab::new();
85+
86+
let system = descriptions.insert(fl!("legacy-app-scaling", "scaled-by-system"));
87+
let system_desc = descriptions.insert(fl!("legacy-app-scaling", "system-description"));
88+
let native = descriptions.insert(fl!("legacy-app-scaling", "scaled-natively"));
89+
let native_desc = descriptions.insert(fl!("legacy-app-scaling", "native-description"));
90+
91+
Section::default()
92+
.title(fl!("legacy-app-scaling"))
93+
.descriptions(descriptions)
94+
.view::<Page>(move |_binder, page, section| {
95+
let descriptions = &section.descriptions;
96+
widget::settings::section()
97+
.title(&section.title)
98+
.add(widget::settings::item_row(vec![widget::radio(
99+
widget::column()
100+
.push(text::body(&descriptions[system]))
101+
.push(text::caption(&descriptions[system_desc])),
102+
false,
103+
Some(page.comp_config_descale_xwayland),
104+
Message::SetXwaylandDescaling,
105+
)
106+
.width(Length::Fill)
107+
.into()]))
108+
.add(widget::settings::item_row(vec![widget::radio(
109+
widget::column()
110+
.push(text::body(&descriptions[native]))
111+
.push(text::caption(&descriptions[native_desc])),
112+
true,
113+
Some(page.comp_config_descale_xwayland),
114+
Message::SetXwaylandDescaling,
115+
)
116+
.width(Length::Fill)
117+
.into()]))
118+
.apply(Element::from)
119+
.map(crate::pages::Message::LegacyApplications)
120+
})
121+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2023 System76 <info@system76.com>
2+
// SPDX-License-Identifier: GPL-3.0-only
3+
4+
#[cfg(feature = "page-default-apps")]
5+
pub mod default_apps;
6+
7+
pub mod startup_apps;
8+
9+
pub mod legacy_applications;
10+
11+
use cosmic_settings_page as page;
12+
13+
#[derive(Default)]
14+
pub struct Page {
15+
entity: page::Entity,
16+
}
17+
18+
impl page::Page<crate::pages::Message> for Page {
19+
fn set_id(&mut self, entity: page::Entity) {
20+
self.entity = entity;
21+
}
22+
23+
fn info(&self) -> page::Info {
24+
page::Info::new("applications", "preferences-applications-symbolic")
25+
.title(fl!("applications"))
26+
}
27+
}
28+
29+
impl page::AutoBind<crate::pages::Message> for Page {
30+
fn sub_pages(
31+
mut page: page::Insert<crate::pages::Message>,
32+
) -> page::Insert<crate::pages::Message> {
33+
#[cfg(feature = "page-default-apps")]
34+
{
35+
page = page.sub_page::<default_apps::Page>();
36+
}
37+
38+
page = page.sub_page::<startup_apps::Page>();
39+
40+
page = page.sub_page::<legacy_applications::Page>();
41+
42+
page
43+
}
44+
}
45+
46+
#[derive(Copy, Clone, Debug)]
47+
pub enum Message {}
48+
49+
impl Page {
50+
pub fn update(&mut self, _message: Message) {}
51+
}

‎cosmic-settings/src/pages/system/startup_apps.rs ‎cosmic-settings/src/pages/applications/startup_apps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl page::AutoBind<crate::pages::Message> for Page {}
9797

9898
impl page::Page<crate::pages::Message> for Page {
9999
fn info(&self) -> Info {
100-
page::Info::new("startup-apps", "preferences-default-applications-symbolic")
100+
page::Info::new("startup-apps", "system-reboot-symbolic")
101101
.title(fl!("startup-apps"))
102102
.description(fl!("startup-apps", "desc"))
103103
}

0 commit comments

Comments
 (0)
Please sign in to comment.