Use subscriptions to monitor cosmic-panel configs
This commit is contained in:
parent
e56db2bae8
commit
41a940660c
3 changed files with 65 additions and 0 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
|
@ -1149,6 +1149,20 @@ dependencies = [
|
||||||
"xdg",
|
"xdg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cosmic-panel-config"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/pop-os/cosmic-panel#8f445a4ce944b6422e6310da06ad15a311c2bbf8"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"cosmic-config",
|
||||||
|
"serde",
|
||||||
|
"smithay-client-toolkit 0.20.0",
|
||||||
|
"tracing",
|
||||||
|
"wayland-protocols-wlr",
|
||||||
|
"xdg-shell-wrapper-config",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-protocols"
|
name = "cosmic-protocols"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -1238,6 +1252,7 @@ dependencies = [
|
||||||
"cosmic-comp-config",
|
"cosmic-comp-config",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
"cosmic-freedesktop-icons",
|
"cosmic-freedesktop-icons",
|
||||||
|
"cosmic-panel-config",
|
||||||
"delegate",
|
"delegate",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
|
|
@ -6765,6 +6780,15 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xdg-shell-wrapper-config"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/pop-os/cosmic-panel#8f445a4ce944b6422e6310da06ad15a311c2bbf8"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"wayland-protocols-wlr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xkbcommon"
|
name = "xkbcommon"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ zbus = "5.9.0"
|
||||||
tokio-stream = { version = "0.1.17", features = ["sync"] }
|
tokio-stream = { version = "0.1.17", features = ["sync"] }
|
||||||
ash = { version = "0.38.0", features = ["loaded"] }
|
ash = { version = "0.38.0", features = ["loaded"] }
|
||||||
bytemuck = "1.23.2"
|
bytemuck = "1.23.2"
|
||||||
|
cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel" }
|
||||||
|
|
||||||
[dependencies.i18n-embed]
|
[dependencies.i18n-embed]
|
||||||
version = "0.16"
|
version = "0.16"
|
||||||
|
|
|
||||||
40
src/main.rs
40
src/main.rs
|
|
@ -31,6 +31,7 @@ use cosmic::{
|
||||||
};
|
};
|
||||||
use cosmic_comp_config::CosmicCompConfig;
|
use cosmic_comp_config::CosmicCompConfig;
|
||||||
use cosmic_config::{CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry};
|
use cosmic_config::{CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry};
|
||||||
|
use cosmic_panel_config::{CosmicPanelConfig, CosmicPanelContainerConfigEntry};
|
||||||
use i18n_embed::DesktopLanguageRequester;
|
use i18n_embed::DesktopLanguageRequester;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
|
|
@ -117,6 +118,8 @@ enum Msg {
|
||||||
EnteredWorkspaceSidebarEntry(ExtWorkspaceHandleV1, bool),
|
EnteredWorkspaceSidebarEntry(ExtWorkspaceHandleV1, bool),
|
||||||
DbusInterface(zbus::Result<dbus::Interface>),
|
DbusInterface(zbus::Result<dbus::Interface>),
|
||||||
DBus(dbus::Event),
|
DBus(dbus::Event),
|
||||||
|
PanelContainerEntries(Vec<String>),
|
||||||
|
PanelConfig(CosmicPanelConfig),
|
||||||
Ignore,
|
Ignore,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,6 +199,7 @@ struct App {
|
||||||
drop_target: Option<DropTarget>,
|
drop_target: Option<DropTarget>,
|
||||||
scroll: Option<(f32, Instant)>,
|
scroll: Option<(f32, Instant)>,
|
||||||
dbus_interface: Option<dbus::Interface>,
|
dbus_interface: Option<dbus::Interface>,
|
||||||
|
panel_configs: HashMap<String, Option<CosmicPanelConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
|
@ -735,6 +739,17 @@ impl Application for App {
|
||||||
dbus::Event::Hide => self.hide(),
|
dbus::Event::Hide => self.hide(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Msg::PanelContainerEntries(entries) => {
|
||||||
|
self.panel_configs.retain(|k, _| entries.contains(&k));
|
||||||
|
for entry in entries {
|
||||||
|
if !self.panel_configs.contains_key(&entry) {
|
||||||
|
self.panel_configs.insert(entry, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg::PanelConfig(config) => {
|
||||||
|
self.panel_configs.insert(config.name.clone(), Some(config));
|
||||||
|
}
|
||||||
Msg::Ignore => {}
|
Msg::Ignore => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -822,6 +837,7 @@ impl Application for App {
|
||||||
if let Some(interface) = &self.dbus_interface {
|
if let Some(interface) = &self.dbus_interface {
|
||||||
subscriptions.push(interface.subscription().map(Msg::DBus));
|
subscriptions.push(interface.subscription().map(Msg::DBus));
|
||||||
}
|
}
|
||||||
|
subscriptions.push(panel_subscriptions(self.panel_configs.keys()));
|
||||||
iced::Subscription::batch(subscriptions)
|
iced::Subscription::batch(subscriptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -850,6 +866,30 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn panel_subscriptions<'a>(
|
||||||
|
container_entries: impl Iterator<Item = &'a String>,
|
||||||
|
) -> Subscription<Msg> {
|
||||||
|
let mut subscriptions = vec![
|
||||||
|
cosmic_config::config_subscription::<_, CosmicPanelContainerConfigEntry>(
|
||||||
|
"panel-config-subscription",
|
||||||
|
"com.system76.CosmicPanel".into(),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
.map(|update| Msg::PanelContainerEntries(update.config.entries)),
|
||||||
|
];
|
||||||
|
for entry in container_entries {
|
||||||
|
subscriptions.push(
|
||||||
|
cosmic_config::config_subscription::<_, CosmicPanelConfig>(
|
||||||
|
("panel-config-subscription", entry.to_owned()),
|
||||||
|
format!("com.system76.CosmicPanel.{}", entry).into(),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
.map(|update| Msg::PanelConfig(update.config)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
iced::Subscription::batch(subscriptions)
|
||||||
|
}
|
||||||
|
|
||||||
fn init_localizer() {
|
fn init_localizer() {
|
||||||
let localizer = crate::localize::localizer();
|
let localizer = crate::localize::localizer();
|
||||||
let requested_languages = DesktopLanguageRequester::requested_languages();
|
let requested_languages = DesktopLanguageRequester::requested_languages();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue