Skip to content

Commit b4ca8a0

Browse files
authored
Merge branch 'pop-os:master' into master
2 parents 21fb843 + 95e7749 commit b4ca8a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+778
-600
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ lto = "thin"
5252
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols//", rev = "ed2a481" }
5353
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//", rev = "ed2a481" }
5454

55+
# [patch.'https://github.com/pop-os/cosmic-settings-daemon']
56+
# cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon//", branch = "input_nobuild" }
57+
5558
# For development and testing purposes
5659
# [patch.'https://github.com/pop-os/libcosmic']
5760
# libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "font" }

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The settings application for the [COSMIC desktop environment][cosmic-epoch].
66

77
Translation files may be found in the [i18n directory](./i18n). New translations may copy the [English (en) localization](./i18n/en) of the project and rename `en` to the desired [ISO 639-1 language code][iso-codes]. Translations may be submitted through GitHub as an issue or pull request. Submissions by email or other means are also acceptable; with the preferred name and email to associate with the changes.
88

9+
## Distributors
10+
11+
The accent palettes on the Appearance settings page are configurable through the cosmic-config directory at `/usr/share/cosmic/com.system76.CosmicSettings/v1/`. One at `accent_palette_dark`, and another at `accent_palette_light`. Examples can be found at [resources/accent_palette_dark.ron](./resources/accent_palette_dark.ron) and [resources/accent_palette_light.ron](./resources/accent_palette_light.ron). This can be copied locally to `~/.config/cosmic/com.system76.CosmicSettings/v1/` for testing, and then move to `/usr/share/cosmic` for packaging.
12+
913
## Build
1014

1115
### Dependencies

cosmic-settings/Cargo.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ linux = [
132132
# Pages
133133
page-accessibility = ["dep:cosmic-protocols", "dep:sctk"]
134134
page-about = ["dep:cosmic-settings-system", "dep:hostname1-zbus", "dep:zbus"]
135-
page-bluetooth = ["dep:bluez-zbus", "dep:zbus", "dep:cosmic-settings-subscriptions"]
135+
page-bluetooth = [
136+
"dep:bluez-zbus",
137+
"dep:zbus",
138+
"dep:cosmic-settings-subscriptions",
139+
]
136140
page-date = ["dep:timedate-zbus", "dep:zbus"]
137141
page-default-apps = ["dep:mime-apps"]
138142
page-input = [
@@ -142,7 +146,7 @@ page-input = [
142146
"dep:udev",
143147
]
144148
page-networking = [
145-
"ashpd",
149+
"xdg-portal",
146150
"dep:cosmic-dbus-networkmanager",
147151
"dep:cosmic-settings-subscriptions",
148152
"dep:zbus",
@@ -162,4 +166,4 @@ single-instance = ["libcosmic/single-instance"]
162166
test = []
163167
wayland = ["libcosmic/wayland", "dep:cosmic-panel-config", "dep:cosmic-randr"]
164168
wgpu = ["libcosmic/wgpu"]
165-
xdg-portal = ["libcosmic/xdg-portal"]
169+
xdg-portal = ["ashpd", "libcosmic/xdg-portal"]

cosmic-settings/src/app.rs

+15-53
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use cosmic::app::context_drawer::ContextDrawer;
2525
use cosmic::app::DbusActivationMessage;
2626
#[cfg(feature = "wayland")]
2727
use cosmic::cctk::{sctk::output::OutputInfo, wayland_client::protocol::wl_output::WlOutput};
28-
use cosmic::iced::futures::SinkExt;
29-
use cosmic::iced::{stream, Subscription};
28+
use cosmic::iced::Subscription;
3029
use cosmic::widget::{self, button, row, text_input};
3130
use cosmic::{
3231
app::{Core, Task},
@@ -58,13 +57,13 @@ use std::{borrow::Cow, str::FromStr};
5857
#[allow(clippy::struct_excessive_bools)]
5958
#[allow(clippy::module_name_repetitions)]
6059
pub struct SettingsApp {
60+
last_active_page: Box<str>,
6161
active_page: page::Entity,
6262
active_context_page: Option<page::Entity>,
6363
loaded_pages: BTreeSet<page::Entity>,
6464
config: Config,
6565
core: Core,
6666
nav_model: nav_bar::Model,
67-
page_sender: Option<tokio::sync::mpsc::Sender<crate::pages::Message>>,
6867
pages: page::Binder<crate::pages::Message>,
6968
search_active: bool,
7069
search_id: cosmic::widget::Id,
@@ -143,7 +142,6 @@ impl SettingsApp {
143142
#[derive(Clone, Debug)]
144143
pub enum Message {
145144
CloseContextDrawer,
146-
DelayedInit(page::Entity),
147145
#[cfg(feature = "wayland")]
148146
DesktopInfo,
149147
Error(String),
@@ -157,7 +155,6 @@ pub enum Message {
157155
PageMessage(crate::pages::Message),
158156
#[cfg(feature = "wayland")]
159157
PanelConfig(CosmicPanelConfig),
160-
RegisterSubscriptionSender(tokio::sync::mpsc::Sender<pages::Message>),
161158
SearchActivate,
162159
SearchChanged(String),
163160
SearchClear,
@@ -182,14 +179,16 @@ impl cosmic::Application for SettingsApp {
182179
}
183180

184181
fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>) {
182+
let config = Config::new();
183+
185184
let mut app = SettingsApp {
186185
active_page: page::Entity::default(),
187186
active_context_page: None,
187+
last_active_page: config.active_page(),
188188
loaded_pages: BTreeSet::new(),
189-
config: Config::new(),
189+
config,
190190
core,
191191
nav_model: nav_bar::Model::default(),
192-
page_sender: None,
193192
pages: page::Binder::default(),
194193
search_active: false,
195194
search_id: cosmic::widget::Id::unique(),
@@ -219,12 +218,13 @@ impl cosmic::Application for SettingsApp {
219218
Some(p) => app.subtask_to_page(&p),
220219
None => app
221220
.pages
222-
.find_page_by_id(&app.config.active_page)
221+
.find_page_by_id(&app.last_active_page)
223222
.map(|(id, _info)| id),
224223
}
225224
.unwrap_or(desktop_id);
226225

227-
(app, cosmic::task::message(Message::DelayedInit(active_id)))
226+
let task = app.activate_page(active_id);
227+
(app, task)
228228
}
229229

230230
fn nav_model(&self) -> Option<&nav_bar::Model> {
@@ -282,22 +282,6 @@ impl cosmic::Application for SettingsApp {
282282

283283
fn subscription(&self) -> Subscription<Message> {
284284
Subscription::batch(vec![
285-
// Creates a channel that listens to messages from pages.
286-
// The sender is given back to the application so that it may pass it on.
287-
Subscription::run_with_id(
288-
std::any::TypeId::of::<Self>(),
289-
stream::channel(4, move |mut output| async move {
290-
let (tx, mut rx) = tokio::sync::mpsc::channel::<pages::Message>(4);
291-
292-
let _res = output.send(Message::RegisterSubscriptionSender(tx)).await;
293-
294-
while let Some(event) = rx.recv().await {
295-
let _res = output.send(Message::PageMessage(event)).await;
296-
}
297-
298-
futures::future::pending::<()>().await;
299-
}),
300-
),
301285
#[cfg(feature = "ashpd")]
302286
crate::subscription::daytime().map(|daytime| {
303287
Message::PageMessage(pages::Message::Appearance(appearance::Message::Daytime(
@@ -750,19 +734,6 @@ impl cosmic::Application for SettingsApp {
750734
Message::Error(error) => {
751735
tracing::error!(error, "error occurred");
752736
}
753-
754-
Message::RegisterSubscriptionSender(sender) => {
755-
self.page_sender = Some(sender);
756-
}
757-
758-
// It is necessary to delay init to allow time for the page sender to be initialized
759-
Message::DelayedInit(active_id) => {
760-
if self.page_sender.is_none() {
761-
return cosmic::task::message(Message::DelayedInit(active_id));
762-
}
763-
764-
return self.activate_page(active_id);
765-
}
766737
}
767738

768739
Task::none()
@@ -849,25 +820,18 @@ impl SettingsApp {
849820
.unwrap_or(iced::Task::none())
850821
.map(Message::PageMessage)
851822
.map(Into::into);
852-
self.config.active_page = Box::from(&*self.pages.info[page].id);
853-
self.config
854-
.set_active_page(Box::from(&*self.pages.info[page].id));
823+
self.last_active_page = Box::from(&*self.pages.info[page].id);
824+
self.config.set_active_page(self.last_active_page.clone());
855825
}
856826

857827
self.search_clear();
858828
self.search_active = false;
859829
self.activate_navbar(page);
860-
861-
let sender = self
862-
.page_sender
863-
.clone()
864-
.expect("sender should be available");
865-
866830
self.loaded_pages.insert(page);
867831

868832
let page_task = self
869833
.pages
870-
.on_enter(page, sender)
834+
.on_enter(page)
871835
.map(Message::PageMessage)
872836
.map(Into::into);
873837

@@ -1029,11 +993,9 @@ impl SettingsApp {
1029993
}
1030994
}
1031995

1032-
if let Some(ref sender) = self.page_sender {
1033-
for page in load {
1034-
self.loaded_pages.insert(page);
1035-
tasks.push(self.pages.on_enter(page, sender.clone()));
1036-
}
996+
for page in load {
997+
self.loaded_pages.insert(page);
998+
tasks.push(self.pages.on_enter(page));
1037999
}
10381000

10391001
for page in unload {

cosmic-settings/src/config.rs

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
11
// Copyright 2023 System76 <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4-
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
4+
use cosmic::{
5+
cosmic_config::{self, ConfigGet, ConfigSet},
6+
cosmic_theme::palette::Srgba,
7+
};
58

69
const NAME: &str = "com.system76.CosmicSettings";
710

8-
const ACTIVE_PAGE: &str = "active-page";
11+
const ACTIVE_PAGE: &str = "active_page";
12+
const ACCENT_PALETTE_DARK: &str = "accent_palette_dark";
13+
const ACCENT_PALETTE_LIGHT: &str = "accent_palette_light";
914

1015
#[must_use]
11-
#[derive(Debug)]
16+
#[derive(Debug, Clone)]
1217
pub struct Config {
13-
pub cosmic_config: Option<cosmic_config::Config>,
14-
pub active_page: Box<str>,
18+
config: cosmic_config::Config,
19+
state: cosmic_config::Config,
1520
}
1621

1722
impl Config {
1823
pub fn new() -> Self {
19-
let mut config = Self::default();
20-
21-
let context = match cosmic_config::Config::new(NAME, 1) {
22-
Ok(context) => context,
24+
let config = match cosmic_config::Config::new(NAME, 1) {
25+
Ok(config) => config,
2326
Err(why) => {
24-
tracing::warn!(?why, "failed to get config");
25-
return Self::default();
27+
panic!("failed to get {NAME} config: {:?}", why);
2628
}
2729
};
2830

29-
if let Ok(page) = context.get::<Box<str>>(ACTIVE_PAGE) {
30-
config.active_page = page;
31-
}
31+
let state = match cosmic_config::Config::new_state(NAME, 1) {
32+
Ok(state) => state,
33+
Err(why) => {
34+
panic!("failed to get {NAME} state: {:?}", why);
35+
}
36+
};
3237

33-
config.cosmic_config = Some(context);
38+
Self { config, state }
39+
}
3440

35-
config
41+
pub fn accent_palette_dark(&self) -> Result<Vec<Srgba>, cosmic_config::Error> {
42+
self.config.get::<Vec<Srgba>>(ACCENT_PALETTE_DARK)
3643
}
3744

38-
pub fn set_active_page(&mut self, page: Box<str>) {
39-
if let Some(context) = self.cosmic_config.as_ref() {
40-
if let Err(why) = context.set::<Box<str>>(ACTIVE_PAGE, page.clone()) {
41-
tracing::error!(?why, "failed to store active page ID");
42-
}
43-
}
45+
pub fn accent_palette_light(&self) -> Result<Vec<Srgba>, cosmic_config::Error> {
46+
self.config.get::<Vec<Srgba>>(ACCENT_PALETTE_LIGHT)
47+
}
4448

45-
self.active_page = page;
49+
pub fn active_page(&self) -> Box<str> {
50+
self.state
51+
.get::<Box<str>>(ACTIVE_PAGE)
52+
.unwrap_or_else(|_| Box::from("desktop"))
4653
}
47-
}
4854

49-
impl Default for Config {
50-
fn default() -> Self {
51-
Self {
52-
cosmic_config: None,
53-
active_page: Box::from("desktop"),
55+
pub fn set_active_page(&self, page: Box<str>) {
56+
if let Err(why) = self.state.set::<Box<str>>(ACTIVE_PAGE, page.clone()) {
57+
tracing::error!(?why, "failed to store active page ID");
5458
}
5559
}
5660
}

cosmic-settings/src/pages/accessibility/magnifier.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use cosmic_settings_page::{
1414
Entity,
1515
};
1616
use slotmap::SlotMap;
17-
use tokio::sync::mpsc;
1817
use tracing::error;
1918

2019
use super::{wayland, AccessibilityEvent, AccessibilityRequest};
@@ -114,28 +113,29 @@ impl page::Page<crate::pages::Message> for Page {
114113
])
115114
}
116115

117-
fn on_enter(
118-
&mut self,
119-
sender: mpsc::Sender<crate::pages::Message>,
120-
) -> cosmic::Task<crate::pages::Message> {
116+
fn on_enter(&mut self) -> cosmic::Task<crate::pages::Message> {
121117
if self.wayland_thread.is_none() {
122118
match wayland::spawn_wayland_connection() {
123119
Ok((tx, mut rx)) => {
124120
self.wayland_thread = Some(tx);
125-
tokio::task::spawn(async move {
126-
while let Some(event) = rx.recv().await {
127-
let _ = sender
128-
.send(crate::pages::Message::AccessibilityMagnifier(
129-
Message::Event(event),
121+
122+
return cosmic::Task::stream(async_fn_stream::fn_stream(
123+
|emitter| async move {
124+
while let Some(event) = rx.recv().await {
125+
let _ = emitter
126+
.emit(crate::pages::Message::AccessibilityMagnifier(
127+
Message::Event(event),
128+
))
129+
.await;
130+
}
131+
132+
let _ = emitter
133+
.emit(crate::pages::Message::AccessibilityMagnifier(
134+
Message::ProtocolUnavailable,
130135
))
131136
.await;
132-
}
133-
let _ = sender
134-
.send(crate::pages::Message::AccessibilityMagnifier(
135-
Message::ProtocolUnavailable,
136-
))
137-
.await;
138-
});
137+
},
138+
));
139139
}
140140
Err(err) => {
141141
tracing::warn!(

0 commit comments

Comments
 (0)