feat: add applications page

This commit is contained in:
Vukašin Vojinović 2025-03-21 19:24:12 +01:00 committed by Michael Murphy
parent 5f8e9d1327
commit cc8586e380
15 changed files with 274 additions and 120 deletions

View file

@ -4,6 +4,7 @@
use crate::config::Config;
#[cfg(feature = "page-accessibility")]
use crate::pages::accessibility;
use crate::pages::applications;
#[cfg(feature = "page-bluetooth")]
use crate::pages::bluetooth;
use crate::pages::desktop::{self, appearance};
@ -84,12 +85,13 @@ impl SettingsApp {
#[cfg(feature = "page-about")]
PageCommands::About => self.pages.page_id::<system::about::Page>(),
PageCommands::Appearance => self.pages.page_id::<desktop::appearance::Page>(),
PageCommands::Applications => self.pages.page_id::<applications::Page>(),
#[cfg(feature = "page-bluetooth")]
PageCommands::Bluetooth => self.pages.page_id::<bluetooth::Page>(),
#[cfg(feature = "page-date")]
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
#[cfg(feature = "page-default-apps")]
PageCommands::DefaultApps => self.pages.page_id::<system::default_apps::Page>(),
PageCommands::DefaultApps => self.pages.page_id::<applications::default_apps::Page>(),
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
#[cfg(feature = "page-display")]
PageCommands::Displays => self.pages.page_id::<display::Page>(),
@ -100,6 +102,9 @@ impl SettingsApp {
PageCommands::Input => self.pages.page_id::<input::Page>(),
#[cfg(feature = "page-input")]
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
PageCommands::LegacyApplications => self
.pages
.page_id::<applications::legacy_applications::Page>(),
#[cfg(feature = "page-input")]
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
#[cfg(feature = "page-networking")]
@ -214,6 +219,7 @@ impl cosmic::Application for SettingsApp {
app.insert_page::<power::Page>();
#[cfg(feature = "page-input")]
app.insert_page::<input::Page>();
app.insert_page::<applications::Page>();
app.insert_page::<time::Page>();
app.insert_page::<system::Page>();
@ -390,6 +396,10 @@ impl cosmic::Application for SettingsApp {
}
}
crate::pages::Message::Applications(message) => {
page::update!(self.pages, message, applications::Page);
}
#[cfg(feature = "page-bluetooth")]
crate::pages::Message::Bluetooth(message) => {
if let Some(page) = self.pages.page_mut::<bluetooth::Page>() {
@ -406,7 +416,7 @@ impl cosmic::Application for SettingsApp {
#[cfg(feature = "page-default-apps")]
crate::pages::Message::DefaultApps(message) => {
if let Some(page) = self.pages.page_mut::<system::default_apps::Page>() {
if let Some(page) = self.pages.page_mut::<applications::default_apps::Page>() {
return page.update(message).map(Into::into);
}
}
@ -478,6 +488,10 @@ impl cosmic::Application for SettingsApp {
}
}
crate::pages::Message::LegacyApplications(message) => {
page::update!(self.pages, message, applications::legacy_applications::Page);
}
#[cfg(feature = "page-input")]
crate::pages::Message::ManageWindowShortcuts(message) => {
if let Some(page) = self
@ -614,7 +628,7 @@ impl cosmic::Application for SettingsApp {
}
crate::pages::Message::StartupApps(message) => {
if let Some(page) = self.pages.page_mut::<system::startup_apps::Page>() {
if let Some(page) = self.pages.page_mut::<applications::startup_apps::Page>() {
return page.update(message).map(Into::into);
}
}

View file

@ -49,6 +49,8 @@ pub enum PageCommands {
About,
/// Appearance settings page
Appearance,
/// Applications settings page
Applications,
/// Bluetooth settings page
#[cfg(feature = "page-bluetooth")]
Bluetooth,
@ -74,6 +76,8 @@ pub enum PageCommands {
/// Keyboard settings page
#[cfg(feature = "page-input")]
Keyboard,
/// Legacy Applications settings page
LegacyApplications,
/// Mouse settings page
#[cfg(feature = "page-input")]
Mouse,

View file

@ -1,5 +1,4 @@
use cosmic::{
app,
cosmic_theme::{CosmicPalette, ThemeBuilder},
iced_core::text::Wrapping,
theme::{self, CosmicTheme},

View file

@ -0,0 +1,121 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use cosmic::{
cosmic_config::{self, ConfigGet, ConfigSet},
iced::Length,
widget::{self, text},
Apply, Element,
};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use slab::Slab;
use slotmap::SlotMap;
use tracing::error;
#[derive(Clone, Debug)]
pub enum Message {
SetXwaylandDescaling(bool),
}
pub struct Page {
comp_config: cosmic_config::Config,
comp_config_descale_xwayland: bool,
}
impl Default for Page {
fn default() -> Self {
let comp_config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
let comp_config_descale_xwayland =
comp_config.get("descale_xwayland").unwrap_or_else(|err| {
if err.is_err() {
error!(?err, "Failed to read config 'descale_xwayland'");
}
false
});
Self {
comp_config,
comp_config_descale_xwayland,
}
}
}
impl page::Page<crate::pages::Message> for Page {
fn content(
&self,
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
) -> Option<page::Content> {
Some(vec![sections.insert(
// Xwayland scaling options
legacy_application_scaling(),
)])
}
fn info(&self) -> page::Info {
page::Info::new(
"legacy-applications",
"preferences-X11-applications-symbolic",
)
.title(fl!("legacy-applications"))
.description(fl!("legacy-applications", "desc"))
}
}
impl page::AutoBind<crate::pages::Message> for Page {}
impl Page {
pub fn update(&mut self, message: Message) {
match message {
Message::SetXwaylandDescaling(descale) => {
self.comp_config_descale_xwayland = descale;
if let Err(err) = self
.comp_config
.set("descale_xwayland", self.comp_config_descale_xwayland)
{
error!(?err, "Failed to set config 'descale_xwayland'");
}
}
}
}
}
pub fn legacy_application_scaling() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();
let system = descriptions.insert(fl!("legacy-app-scaling", "scaled-by-system"));
let system_desc = descriptions.insert(fl!("legacy-app-scaling", "system-description"));
let native = descriptions.insert(fl!("legacy-app-scaling", "scaled-natively"));
let native_desc = descriptions.insert(fl!("legacy-app-scaling", "native-description"));
Section::default()
.title(fl!("legacy-app-scaling"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions;
widget::settings::section()
.title(&section.title)
.add(widget::settings::item_row(vec![widget::radio(
widget::column()
.push(text::body(&descriptions[system]))
.push(text::caption(&descriptions[system_desc])),
false,
Some(page.comp_config_descale_xwayland),
Message::SetXwaylandDescaling,
)
.width(Length::Fill)
.into()]))
.add(widget::settings::item_row(vec![widget::radio(
widget::column()
.push(text::body(&descriptions[native]))
.push(text::caption(&descriptions[native_desc])),
true,
Some(page.comp_config_descale_xwayland),
Message::SetXwaylandDescaling,
)
.width(Length::Fill)
.into()]))
.apply(Element::from)
.map(crate::pages::Message::LegacyApplications)
})
}

View file

@ -0,0 +1,51 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
#[cfg(feature = "page-default-apps")]
pub mod default_apps;
pub mod startup_apps;
pub mod legacy_applications;
use cosmic_settings_page as page;
#[derive(Default)]
pub struct Page {
entity: page::Entity,
}
impl page::Page<crate::pages::Message> for Page {
fn set_id(&mut self, entity: page::Entity) {
self.entity = entity;
}
fn info(&self) -> page::Info {
page::Info::new("applications", "preferences-applications-symbolic")
.title(fl!("applications"))
}
}
impl page::AutoBind<crate::pages::Message> for Page {
fn sub_pages(
mut page: page::Insert<crate::pages::Message>,
) -> page::Insert<crate::pages::Message> {
#[cfg(feature = "page-default-apps")]
{
page = page.sub_page::<default_apps::Page>();
}
page = page.sub_page::<startup_apps::Page>();
page = page.sub_page::<legacy_applications::Page>();
page
}
}
#[derive(Copy, Clone, Debug)]
pub enum Message {}
impl Page {
pub fn update(&mut self, _message: Message) {}
}

View file

@ -97,7 +97,7 @@ impl page::AutoBind<crate::pages::Message> for Page {}
impl page::Page<crate::pages::Message> for Page {
fn info(&self) -> Info {
page::Info::new("startup-apps", "preferences-default-applications-symbolic")
page::Info::new("startup-apps", "system-reboot-symbolic")
.title(fl!("startup-apps"))
.description(fl!("startup-apps", "desc"))
}

View file

@ -12,7 +12,6 @@ use cosmic::widget::{
self, column, container, dropdown, list_column, segmented_button, tab_bar, text, toggler,
};
use cosmic::{surface, Apply, Element, Task};
use cosmic_config::{ConfigGet, ConfigSet};
use cosmic_randr_shell::{
AdaptiveSyncAvailability, AdaptiveSyncState, List, Output, OutputKey, Transform,
};
@ -23,7 +22,6 @@ use slotmap::{Key, SecondaryMap, SlotMap};
use std::sync::atomic::{AtomicBool, Ordering};
use std::{collections::BTreeMap, process::ExitStatus, sync::Arc};
use tokio::sync::oneshot;
use tracing::error;
static DPI_SCALES: &[u32] = &[50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300];
@ -107,7 +105,6 @@ pub enum Message {
/// Available outputs from cosmic-randr.
randr: Arc<Result<List, cosmic_randr_shell::Error>>,
},
SetXwaylandDescaling(bool),
Surface(surface::Action),
}
@ -152,23 +149,11 @@ pub struct Page {
/// the instant the setting was changed.
dialog_countdown: usize,
show_display_options: bool,
comp_config: cosmic_config::Config,
comp_config_descale_xwayland: bool,
adjusted_scale: u32,
}
impl Default for Page {
fn default() -> Self {
let comp_config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
let comp_config_descale_xwayland =
comp_config.get("descale_xwayland").unwrap_or_else(|err| {
if err.is_err() {
error!(?err, "Failed to read config 'descale_xwayland'");
}
false
});
Self {
refreshing_page: Arc::new(AtomicBool::new(false)),
list: List::default(),
@ -187,8 +172,6 @@ impl Default for Page {
dialog_countdown: 0,
show_display_options: true,
adjusted_scale: 0,
comp_config,
comp_config_descale_xwayland,
}
}
}
@ -240,8 +223,6 @@ impl page::Page<crate::pages::Message> for Page {
sections.insert(display_arrangement()),
// Display configuration
sections.insert(display_configuration()),
// Xwayland scaling options
sections.insert(legacy_applications()),
])
}
@ -618,16 +599,6 @@ impl Page {
self.refreshing_page.store(false, Ordering::SeqCst);
}
Message::SetXwaylandDescaling(descale) => {
self.comp_config_descale_xwayland = descale;
if let Err(err) = self
.comp_config
.set("descale_xwayland", self.comp_config_descale_xwayland)
{
error!(?err, "Failed to set config 'descale_xwayland'");
}
}
Message::Surface(a) => {
return cosmic::task::message(crate::app::Message::Surface(a));
}
@ -1378,46 +1349,6 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
})
}
pub fn legacy_applications() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();
let system = descriptions.insert(fl!("legacy-applications", "scaled-by-system"));
let system_desc = descriptions.insert(fl!("legacy-applications", "system-description"));
let native = descriptions.insert(fl!("legacy-applications", "scaled-natively"));
let native_desc = descriptions.insert(fl!("legacy-applications", "native-description"));
Section::default()
.title(fl!("legacy-applications"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions;
widget::settings::section()
.title(&section.title)
.add(widget::settings::item_row(vec![widget::radio(
widget::column()
.push(text::body(&descriptions[system]))
.push(text::caption(&descriptions[system_desc])),
false,
Some(page.comp_config_descale_xwayland),
Message::SetXwaylandDescaling,
)
.width(Length::Fill)
.into()]))
.add(widget::settings::item_row(vec![widget::radio(
widget::column()
.push(text::body(&descriptions[native]))
.push(text::caption(&descriptions[native_desc])),
true,
Some(page.comp_config_descale_xwayland),
Message::SetXwaylandDescaling,
)
.width(Length::Fill)
.into()]))
.apply(Element::from)
.map(crate::pages::Message::Displays)
})
}
fn cache_rates(cached_rates: &mut Vec<String>, rates: &[u32]) {
cached_rates.clear();

View file

@ -5,6 +5,7 @@ use cosmic_settings_page::Entity;
#[cfg(feature = "page-accessibility")]
pub mod accessibility;
pub mod applications;
#[cfg(feature = "page-bluetooth")]
pub mod bluetooth;
pub mod desktop;
@ -30,6 +31,7 @@ pub enum Message {
#[cfg(feature = "page-about")]
About(system::about::Message),
Appearance(desktop::appearance::Message),
Applications(applications::Message),
#[cfg(feature = "page-bluetooth")]
Bluetooth(bluetooth::Message),
#[cfg(feature = "page-input")]
@ -37,7 +39,7 @@ pub enum Message {
#[cfg(feature = "page-date")]
DateAndTime(time::date::Message),
#[cfg(feature = "page-default-apps")]
DefaultApps(system::default_apps::Message),
DefaultApps(applications::default_apps::Message),
Desktop(desktop::Message),
DesktopWallpaper(desktop::wallpaper::Message),
#[cfg(feature = "page-workspaces")]
@ -58,6 +60,7 @@ pub enum Message {
Keyboard(input::keyboard::Message),
#[cfg(feature = "page-input")]
KeyboardShortcuts(input::keyboard::shortcuts::Message),
LegacyApplications(applications::legacy_applications::Message),
#[cfg(feature = "page-input")]
ManageWindowShortcuts(input::keyboard::shortcuts::ShortcutMessage),
#[cfg(feature = "page-input")]
@ -77,7 +80,7 @@ pub enum Message {
Region(time::region::Message),
#[cfg(feature = "page-sound")]
Sound(sound::Message),
StartupApps(system::startup_apps::Message),
StartupApps(applications::startup_apps::Message),
#[cfg(feature = "page-users")]
User(system::users::Message),
#[cfg(feature = "page-input")]

View file

@ -3,14 +3,11 @@
#[cfg(feature = "page-about")]
pub mod about;
#[cfg(feature = "page-default-apps")]
pub mod default_apps;
pub mod firmware;
#[cfg(feature = "page-users")]
pub mod users;
pub mod startup_apps;
use cosmic_settings_page as page;
#[derive(Default)]
@ -44,13 +41,6 @@ impl page::AutoBind<crate::pages::Message> for Page {
page = page.sub_page::<firmware::Page>();
#[cfg(feature = "page-default-apps")]
{
page = page.sub_page::<default_apps::Page>();
}
page = page.sub_page::<startup_apps::Page>();
page
}
}

2
debian/install vendored
View file

@ -3,6 +3,7 @@
/usr/share/applications/com.system76.CosmicSettings.About.desktop
/usr/share/applications/com.system76.CosmicSettings.Accessibility.desktop
/usr/share/applications/com.system76.CosmicSettings.Appearance.desktop
/usr/share/applications/com.system76.CosmicSettings.Applications.desktop
/usr/share/applications/com.system76.CosmicSettings.Bluetooth.desktop
/usr/share/applications/com.system76.CosmicSettings.DateTime.desktop
/usr/share/applications/com.system76.CosmicSettings.DefaultApps.desktop
@ -12,6 +13,7 @@
/usr/share/applications/com.system76.CosmicSettings.Firmware.desktop
/usr/share/applications/com.system76.CosmicSettings.Input.desktop
/usr/share/applications/com.system76.CosmicSettings.Keyboard.desktop
/usr/share/applications/com.system76.CosmicSettings.LegacyApplications.desktop
/usr/share/applications/com.system76.CosmicSettings.Mouse.desktop
/usr/share/applications/com.system76.CosmicSettings.Network.desktop
/usr/share/applications/com.system76.CosmicSettings.Notifications.desktop

View file

@ -142,7 +142,7 @@ magnifier = Magnifier
{$zoom_in} to zoom in,
}{ $zoom_out ->
[zero] {""}
*[other] {""}
*[other] {""}
{$zoom_out} to zoom out,
}
Super + scroll with your mouse
@ -428,12 +428,6 @@ dialog = Dialog
.change-prompt = Settings changes will automatically revert in { $time } seconds.
.revert-settings = Revert Settings
legacy-applications = X11 Window System Application Scaling
.scaled-by-system = Scale all X11 Applications
.system-description = X11 applications will appear blurry on HiDPI screens.
.scaled-natively = Render X11 Applications at native resolution
.native-description = X11 applications that don't support scaling will be small when HiDPI displays are in use. Enable for games to utilize the full monitor resolution.
## Sound
sound = Sound
@ -778,6 +772,47 @@ add-language = Add language
install-additional-languages = Install additional languages
region = Region
## Applications
applications = Applications
## Applications: Default Applications
default-apps = Default Applications
.desc = Default web browser, mail client, file browser, and other applications.
.web-browser = Web browser
.file-manager = File manager
.mail-client = Mail client
.music = Music
.video = Video
.photos = Photos
.calendar = Calendar
.terminal = Terminal
.other-associations = Other Associations
.text-editor = Text Editor
## Applications: Startup Applications
startup-apps = Startup Applications
.desc = Configure applications which run on login.
.add = Add app
.user = User specific applications
.user-description = These applications are launched when you log into your current user.
.remove-dialog-title = Remove { $name }?
.remove-dialog-description = Are you sure you want to remove this as a startup application?
.search-for-application = Search for application
## Applications: Legacy Applications
legacy-applications = X11 Applications Compatibility
.desc = X11 Window system application scaling and Global shortcuts.
legacy-app-scaling = X11 Window System Application Scaling
.scaled-by-system = Scale all X11 Applications
.system-description = X11 applications will appear blurry on HiDPI screens.
.scaled-natively = Render X11 Applications at native resolution
.native-description = X11 applications that don't support scaling will be small when HiDPI displays are in use. Enable for games to utilize the full monitor resolution.
## System
system = System & Accounts
@ -825,29 +860,3 @@ administrator = Administrator
add-user = Add user
remove-user = Remove user
full-name = Full name
## System: Default Applications
default-apps = Default Applications
.desc = Default web browser, mail client, file browser, and other applications.
.web-browser = Web browser
.file-manager = File manager
.mail-client = Mail client
.music = Music
.video = Video
.photos = Photos
.calendar = Calendar
.terminal = Terminal
.other-associations = Other Associations
.text-editor = Text Editor
## System: Startup Applications
startup-apps = Startup Applications
.desc = Configure applications which run on login.
.add = Add app
.user = User specific applications
.user-description = These applications are launched when you log into your current user.
.remove-dialog-title = Remove { $name }?
.remove-dialog-description = Are you sure you want to remove this as a startup application?
.search-for-application = Search for application

View file

@ -34,6 +34,7 @@ entry-settings := appid + '.desktop'
entry-about := appid + '.About.desktop'
entry-accessibility := appid + '.Accessibility.desktop'
entry-appear := appid + '.Appearance.desktop'
entry-apps := appid + '.Applications.desktop'
entry-bluetooth := appid + '.Bluetooth.desktop'
entry-date-time := appid + '.DateTime.desktop'
entry-default-apps := appid + '.DefaultApps.desktop'
@ -43,6 +44,7 @@ entry-dock := appid + '.Dock.desktop'
entry-firmware := appid + '.Firmware.desktop'
entry-input := appid + '.Input.desktop'
entry-keyboard := appid + '.Keyboard.desktop'
entry-legacy-apps := appid + '.LegacyApplications.desktop'
entry-mouse := appid + '.Mouse.desktop'
entry-network := appid + '.Network.desktop'
entry-notifications := appid + '.Notifications.desktop'
@ -71,6 +73,7 @@ install-desktop-entries:
install -Dm0644 'resources/{{entry-about}}' '{{appdir}}/{{entry-about}}'
install -Dm0644 'resources/{{entry-accessibility}}' '{{appdir}}/{{entry-accessibility}}'
install -Dm0644 'resources/{{entry-appear}}' '{{appdir}}/{{entry-appear}}'
install -Dm0644 'resources/{{entry-apps}}' '{{appdir}}/{{entry-apps}}'
install -Dm0644 'resources/{{entry-bluetooth}}' '{{appdir}}/{{entry-bluetooth}}'
install -Dm0644 'resources/{{entry-date-time}}' '{{appdir}}/{{entry-date-time}}'
install -Dm0644 'resources/{{entry-default-apps}}' '{{appdir}}/{{entry-default-apps}}'
@ -80,6 +83,7 @@ install-desktop-entries:
install -Dm0644 'resources/{{entry-firmware}}' '{{appdir}}/{{entry-firmware}}'
install -Dm0644 'resources/{{entry-input}}' '{{appdir}}/{{entry-input}}'
install -Dm0644 'resources/{{entry-keyboard}}' '{{appdir}}/{{entry-keyboard}}'
install -Dm0644 'resources/{{entry-legacy-apps}}' '{{appdir}}/{{entry-legacy-apps}}'
install -Dm0644 'resources/{{entry-mouse}}' '{{appdir}}/{{entry-mouse}}'
install -Dm0644 'resources/{{entry-network}}' '{{appdir}}/{{entry-network}}'
install -Dm0644 'resources/{{entry-notifications}}' '{{appdir}}/{{entry-notifications}}'
@ -122,6 +126,7 @@ uninstall:
'{{appdir}}/{{entry-about}}' \
'{{appdir}}/{{entry-accessibility}}' \
'{{appdir}}/{{entry-appear}}' \
'{{appdir}}/{{entry-apps}}' \
'{{appdir}}/{{entry-bluetooth}}' \
'{{appdir}}/{{entry-date-time}}' \
'{{appdir}}/{{entry-default-apps}}' \
@ -131,6 +136,7 @@ uninstall:
'{{appdir}}/{{entry-firmware}}' \
'{{appdir}}/{{entry-input}}' \
'{{appdir}}/{{entry-keyboard}}' \
'{{appdir}}/{{entry-legacy-apps}}' \
'{{appdir}}/{{entry-mouse}}' \
'{{appdir}}/{{entry-network}}' \
'{{appdir}}/{{entry-notifications}}' \

View file

@ -0,0 +1,12 @@
[Desktop Entry]
Name=Applications
Comment=Manage application settings.
Type=Settings
Exec=cosmic-settings applications
Terminal=false
Categories=COSMIC
Keywords=COSMIC
NoDisplay=true
OnlyShowIn=COSMIC
Icon=preferences-applications
StartupNotify=true

View file

@ -0,0 +1,12 @@
[Desktop Entry]
Name=X11 Applications Compatibility
Comment=X11 Window system application scaling and Global shortcuts.
Type=Settings
Exec=cosmic-settings legacy-applications
Terminal=false
Categories=COSMIC
Keywords=COSMIC
NoDisplay=true
OnlyShowIn=COSMIC
Icon=preferences-x11-applications-compatibility
StartupNotify=true