Skip to content

Commit 2c9f60c

Browse files
authored
feat(sound): redesign with separate device profiles page (#1500)
1 parent 6ebc220 commit 2c9f60c

File tree

65 files changed

+3152
-1944
lines changed

Some content is hidden

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

65 files changed

+3152
-1944
lines changed

Cargo.lock

Lines changed: 173 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["cosmic-settings", "page", "pages/*", "subscriptions/*"]
2+
members = ["cosmic-settings", "crates/*", "page", "pages/*", "subscriptions/*"]
33
default-members = ["cosmic-settings"]
44
resolver = "3"
55

cosmic-settings/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cosmic-settings"
3-
version = "0.1.0"
3+
version = "1.0.0-beta6"
44
edition = "2024"
55
license = "GPL-3.0-only"
66
publish = false
@@ -72,7 +72,7 @@ tachyonix = "0.3.1"
7272
timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
7373
tokio = { workspace = true, features = ["fs", "io-util", "sync"] }
7474
tracing = "0.1.41"
75-
tracing-subscriber = "0.3.20"
75+
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
7676
udev = { version = "0.9.3", optional = true }
7777
upower_dbus = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
7878
bluez-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }

cosmic-settings/src/app.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,13 @@ impl cosmic::Application for SettingsApp {
550550
}
551551
}
552552

553+
#[cfg(feature = "page-sound")]
554+
crate::pages::Message::SoundDeviceProfiles(message) => {
555+
if let Some(page) = self.pages.page_mut::<sound::device_profiles::Page>() {
556+
return page.update(message).map(Into::into);
557+
}
558+
}
559+
553560
crate::pages::Message::StartupApps(message) => {
554561
if let Some(page) = self.pages.page_mut::<applications::startup_apps::Page>() {
555562
return page.update(message).map(Into::into);

cosmic-settings/src/main.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,6 @@ fn init_localizer() {
201201
}
202202

203203
fn init_logger() {
204-
let log_level = std::env::var("RUST_LOG")
205-
.ok()
206-
.and_then(|level| level.parse::<tracing::Level>().ok())
207-
.unwrap_or(tracing::Level::INFO);
208-
209204
let log_format = tracing_subscriber::fmt::format()
210205
.pretty()
211206
.without_time()
@@ -214,17 +209,14 @@ fn init_logger() {
214209
.with_target(false)
215210
.with_thread_names(true);
216211

217-
let log_filter = tracing_subscriber::fmt::Layer::default()
212+
let log_layer = tracing_subscriber::fmt::Layer::default()
218213
.with_writer(std::io::stderr)
219-
.event_format(log_format)
220-
.with_filter(tracing_subscriber::filter::filter_fn(move |metadata| {
221-
let target = metadata.target();
222-
metadata.level() == &tracing::Level::ERROR
223-
|| ((target.starts_with("cosmic_settings") || target.starts_with("cosmic_bg"))
224-
&& metadata.level() <= &log_level)
225-
}));
226-
227-
tracing_subscriber::registry().with(log_filter).init();
214+
.event_format(log_format);
215+
216+
tracing_subscriber::registry()
217+
.with(tracing_subscriber::EnvFilter::from_env("RUST_LOG"))
218+
.with(log_layer)
219+
.init();
228220
}
229221

230222
#[macro_export]

cosmic-settings/src/pages/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub enum Message {
8484
Region(time::region::Message),
8585
#[cfg(feature = "page-sound")]
8686
Sound(sound::Message),
87+
#[cfg(feature = "page-sound")]
88+
SoundDeviceProfiles(sound::device_profiles::Message),
8789
StartupApps(applications::startup_apps::Message),
8890
#[cfg(feature = "page-users")]
8991
User(system::users::Message),
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2025 System76 <[email protected]>
2+
// SPDX-License-Identifier: GPL-3.0-only
3+
4+
use cosmic::{Apply, widget};
5+
use cosmic_settings_page::{self as page, Section, section};
6+
use cosmic_settings_sound_subscription::{self as subscription};
7+
use slotmap::SlotMap;
8+
9+
#[derive(Clone, Debug)]
10+
pub enum Message {}
11+
12+
impl From<Message> for crate::pages::Message {
13+
fn from(message: Message) -> Self {
14+
crate::pages::Message::SoundDeviceProfiles(message)
15+
}
16+
}
17+
18+
impl From<Message> for crate::Message {
19+
fn from(message: Message) -> Self {
20+
crate::Message::PageMessage(message.into())
21+
}
22+
}
23+
24+
#[derive(Default)]
25+
pub struct Page {
26+
entity: page::Entity,
27+
}
28+
29+
impl page::AutoBind<crate::pages::Message> for Page {}
30+
31+
impl page::Page<crate::pages::Message> for Page {
32+
fn info(&self) -> page::Info {
33+
page::Info::new("sound-device-profiles", "preferences-sound-symbolic")
34+
.title(fl!("sound-device-profiles"))
35+
}
36+
37+
fn content(
38+
&self,
39+
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
40+
) -> Option<page::Content> {
41+
Some(vec![sections.insert(view())])
42+
}
43+
44+
fn on_leave(&mut self) -> cosmic::Task<crate::pages::Message> {
45+
cosmic::Task::done(crate::pages::Message::Sound(super::Message::Reload))
46+
}
47+
48+
fn set_id(&mut self, entity: cosmic_settings_page::Entity) {
49+
self.entity = entity;
50+
}
51+
52+
fn subscription(
53+
&self,
54+
_core: &cosmic::Core,
55+
) -> cosmic::iced::Subscription<crate::pages::Message> {
56+
cosmic::iced::Subscription::run(subscription::watch)
57+
.map(|message| super::Message::Subscription(message).into())
58+
}
59+
}
60+
61+
impl Page {
62+
pub fn update(&mut self, _message: Message) -> cosmic::Task<crate::app::Message> {
63+
cosmic::Task::none()
64+
}
65+
}
66+
67+
pub fn view() -> Section<crate::pages::Message> {
68+
Section::default().view::<Page>(move |binder, _page, _section| {
69+
let sound_page_id = binder.find_page_by_id("sound").unwrap().0;
70+
let sound_page = binder.page[sound_page_id]
71+
.downcast_ref::<super::Page>()
72+
.unwrap();
73+
74+
let devices = sound_page
75+
.model
76+
.device_profile_dropdowns
77+
.iter()
78+
.cloned()
79+
.map(|(device_id, name, active_profile, indexes, descriptions)| {
80+
let dropdown = widget::dropdown::popup_dropdown(
81+
descriptions,
82+
active_profile,
83+
move |id| super::Message::SetProfile(device_id, indexes[id]),
84+
cosmic::iced::window::Id::RESERVED,
85+
super::Message::Surface,
86+
crate::Message::from,
87+
)
88+
.apply(cosmic::Element::from)
89+
.map(crate::pages::Message::from);
90+
91+
widget::settings::item::builder(name).control(dropdown)
92+
});
93+
94+
widget::settings::section().extend(devices).into()
95+
})
96+
}

0 commit comments

Comments
 (0)