wip: use cosmic-config

This commit is contained in:
Ashley Wulber 2023-05-23 16:08:39 -04:00 committed by Michael Aaron Murphy
parent e7996f69dd
commit 215648324a
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
4 changed files with 132 additions and 53 deletions

106
Cargo.lock generated
View file

@ -427,9 +427,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.12.2"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "byte-unit"
@ -752,13 +752,13 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
source = "git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"atomicwrites",
"cosmic-config-derive",
"cosmic-config-derive 0.1.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)",
"dirs 5.0.1",
"iced_futures",
"notify 6.0.0",
"iced_futures 0.6.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)",
"notify",
"ron",
"serde",
]
@ -766,15 +766,26 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#98ec1bbd487cf5412c0e94ef9ae7694c9b72edbd"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"atomicwrites",
"dirs 4.0.0",
"notify 5.2.0",
"cosmic-config-derive 0.1.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"dirs 5.0.1",
"iced_futures 0.6.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"notify",
"ron",
"serde",
]
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"quote",
"syn 1.0.109",
]
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
@ -787,10 +798,10 @@ dependencies = [
[[package]]
name = "cosmic-panel-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-panel#f342e53f95aee2a26c8cc6578cfe5c39a1ed99b5"
source = "git+https://github.com/pop-os/cosmic-panel#aae46287cdb349381743fe530f281333c7ebfa83"
dependencies = [
"anyhow",
"cosmic-config 0.1.0 (git+https://github.com/pop-os/libcosmic)",
"cosmic-config 0.1.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)",
"ron",
"serde",
"tracing",
@ -806,6 +817,7 @@ dependencies = [
"async-channel",
"bytecheck",
"color-eyre",
"cosmic-config 0.1.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)",
"cosmic-panel-config",
"cosmic-settings-page",
"cosmic-settings-system",
@ -2084,8 +2096,8 @@ name = "iced"
version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"iced_core",
"iced_futures",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"iced_futures 0.6.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"iced_renderer",
"iced_sctk",
"iced_widget",
@ -2103,6 +2115,18 @@ dependencies = [
"accesskit_unix",
]
[[package]]
name = "iced_core"
version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"bitflags 1.3.2",
"instant",
"log",
"thiserror",
"twox-hash",
]
[[package]]
name = "iced_core"
version = "0.9.0"
@ -2118,13 +2142,25 @@ dependencies = [
"twox-hash",
]
[[package]]
name = "iced_futures"
version = "0.6.0"
source = "git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"futures",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)",
"log",
"wasm-bindgen-futures",
"wasm-timer",
]
[[package]]
name = "iced_futures"
version = "0.6.0"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"futures",
"iced_core",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"log",
"tokio",
"wasm-bindgen-futures",
@ -2139,7 +2175,7 @@ dependencies = [
"bitflags 1.3.2",
"bytemuck",
"glam",
"iced_core",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"image",
"kamadak-exif",
"log",
@ -2166,8 +2202,8 @@ version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"iced_accessibility",
"iced_core",
"iced_futures",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"iced_futures 0.6.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"smithay-client-toolkit 0.17.0",
"thiserror",
]
@ -2180,7 +2216,7 @@ dependencies = [
"enum-repr",
"float-cmp",
"futures",
"iced_futures",
"iced_futures 0.6.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"iced_graphics",
"iced_runtime",
"iced_style",
@ -2198,7 +2234,7 @@ name = "iced_style"
version = "0.8.0"
source = "git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text#bf1c474d0846e31c647444ff7bd5ecb7f361efcd"
dependencies = [
"iced_core",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"once_cell",
"palette",
]
@ -2573,7 +2609,7 @@ dependencies = [
"fraction",
"freedesktop-icons",
"iced",
"iced_core",
"iced_core 0.9.0 (git+https://github.com/pop-os/libcosmic?branch=cosmic-advanced-text)",
"iced_runtime",
"iced_style",
"iced_widget",
@ -2920,24 +2956,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "notify"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "729f63e1ca555a43fe3efa4f3efdf4801c479da85b432242a7b726f353c88486"
dependencies = [
"bitflags 1.3.2",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",
"kqueue",
"libc",
"mio",
"walkdir",
"windows-sys 0.45.0",
]
[[package]]
name = "notify"
version = "6.0.0"
@ -3639,9 +3657,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.8.1"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
checksum = "d1a59b5d8e97dee33696bf13c5ba8ab85341c002922fba050069326b9c498974"
dependencies = [
"aho-corasick",
"memchr",
@ -3650,9 +3668,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rend"
@ -5623,9 +5641,9 @@ dependencies = [
[[package]]
name = "xml-rs"
version = "0.8.11"
version = "0.8.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1690519550bfa95525229b9ca2350c63043a4857b3b0013811b2ccf4a2420b01"
checksum = "2d8f380ae16a37b30e6a2cf67040608071384b1450c189e61bea3ff57cde922d"
[[package]]
name = "xmlparser"

View file

@ -28,6 +28,7 @@ downcast-rs = "1.2.0"
log = "0.4"
env_logger = "0.10"
cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic", tag = "cosmic-config-derive" }
[dependencies.i18n-embed]
version = "0.13.8"

View file

@ -6,14 +6,33 @@ use cosmic::{
};
use apply::Apply;
use cosmic_config::CosmicConfigEntry;
use cosmic_panel_config::{AutoHide, CosmicPanelConfig, CosmicPanelOuput, PanelAnchor, PanelSize};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use slotmap::SlotMap;
#[derive(Default)]
pub struct Page {
panel_config: CosmicPanelConfig,
config_helper: Option<cosmic_config::Config>,
panel_config: Option<CosmicPanelConfig>,
}
impl Default for Page {
fn default() -> Self {
// TODO CosmicPanelConfig should return its own version
let config_helper = cosmic_config::Config::new("com.system76.CosmicPanel.panel", 1).ok();
let panel_config = config_helper.as_ref().and_then(|config_helper| {
// TODO error handling...
let panel_config = CosmicPanelConfig::get_entry(config_helper).ok()?;
(panel_config.name == "panel").then_some(panel_config)
});
// If the config is not present, it will be created with the default values and the name will not match
Self {
config_helper,
panel_config,
}
}
}
impl page::Page<crate::pages::Message> for Page {
@ -22,11 +41,15 @@ impl page::Page<crate::pages::Message> for Page {
&self,
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
) -> Option<page::Content> {
Some(vec![
sections.insert(behavior_and_position()),
sections.insert(style()),
sections.insert(configuration()),
])
Some(if self.panel_config.is_some() {
vec![
sections.insert(behavior_and_position()),
sections.insert(style()),
sections.insert(configuration()),
]
} else {
vec![sections.insert(add_panel())]
})
}
fn info(&self) -> page::Info {
@ -44,10 +67,11 @@ pub fn behavior_and_position() -> Section<crate::pages::Message> {
.descriptions(vec![fl!("panel-behavior-and-position", "autohide")])
.view::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
let panel_config = page.panel_config.as_ref().unwrap();
settings::view_section(&section.title)
.add(settings::item(
&descriptions[0],
toggler(None, page.panel_config.autohide.is_some(), |value| {
toggler(None, panel_config.autohide.is_some(), |value| {
Message::AutoHidePanel(value)
}),
))
@ -88,6 +112,22 @@ pub fn configuration() -> Section<crate::pages::Message> {
})
}
pub fn add_panel() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("hot-corner"))
.descriptions(vec![fl!("hot-corner", "top-left-corner")])
.view::<Page>(|binder, _page, section| {
let desktop = binder
.page::<super::Page>()
.expect("desktop page not found");
let descriptions = &section.descriptions;
settings::view_section(&section.title)
.apply(Element::from)
.map(crate::pages::Message::Desktop)
})
}
#[derive(Clone, Debug)]
pub enum Message {
// panel messages
@ -106,11 +146,16 @@ impl Page {
pub fn update(&mut self, message: Message) {
match message {
Message::AutoHidePanel(enabled) => {
self.panel_config.autohide = enabled.then_some(AutoHide {
let helper = self.config_helper.as_ref().unwrap();
let panel_config = self.panel_config.as_mut().unwrap();
panel_config.autohide = enabled.then_some(AutoHide {
wait_time: 1000,
transition_time: 200,
handle_size: 4,
});
let _ = panel_config.write_entry(helper);
}
Message::PanelAnchor(_) => todo!(),
Message::Output(_) => todo!(),

View file

@ -57,6 +57,21 @@ panel-behavior-and-position = Behavior and Positions
.autohide = Automatically hide panel
.position = Position on screen
.display = Show on display
panel-style = Style
.anchor-gap = Gap between panel and screen edges
.extend = Extend panel to screen edges
.appearance = Appearance
.size = Size
.background-opacity = Background opacity
panel-applets = Configuration
.desc = Configure panel applets.
panel-missing = Panel Configuration is Missing
.desc = The panel configuration file is missing due to use of a custom configuration or it is corrupted.
.fix = Reset to default
## Desktop: Wallpaper
wallpaper = Wallpaper