Use subscription for cosmic-bg-config
Works, as long as a `config_state_subscription` is used. Should also try caching image handles.
This commit is contained in:
parent
6cca5476ab
commit
ccef25c40c
2 changed files with 32 additions and 37 deletions
57
src/main.rs
57
src/main.rs
|
|
@ -130,6 +130,7 @@ enum Msg {
|
||||||
NewWorkspace,
|
NewWorkspace,
|
||||||
CompConfig(Box<CosmicCompConfig>),
|
CompConfig(Box<CosmicCompConfig>),
|
||||||
Config(CosmicWorkspacesConfig),
|
Config(CosmicWorkspacesConfig),
|
||||||
|
BgConfig(cosmic_bg_config::state::State),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -176,27 +177,11 @@ enum DragSurface {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct Conf {
|
struct Conf {
|
||||||
workspace_config: cosmic_comp_config::workspace::WorkspaceConfig,
|
workspace_config: cosmic_comp_config::workspace::WorkspaceConfig,
|
||||||
config: CosmicWorkspacesConfig,
|
config: CosmicWorkspacesConfig,
|
||||||
bg_config: Option<cosmic_config::Config>,
|
bg: cosmic_bg_config::state::State,
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Conf {
|
|
||||||
fn default() -> Self {
|
|
||||||
let bg_config = cosmic::cosmic_config::Config::new_state(
|
|
||||||
cosmic_bg_config::NAME,
|
|
||||||
cosmic_bg_config::state::State::version(),
|
|
||||||
);
|
|
||||||
if let Err(err) = &bg_config {
|
|
||||||
log::error!("failed to load bg config: {}", err);
|
|
||||||
}
|
|
||||||
Self {
|
|
||||||
workspace_config: cosmic_comp_config::workspace::WorkspaceConfig::default(),
|
|
||||||
config: CosmicWorkspacesConfig::default(),
|
|
||||||
bg_config: bg_config.ok(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -212,7 +197,6 @@ struct App {
|
||||||
conf: Conf,
|
conf: Conf,
|
||||||
core: cosmic::app::Core,
|
core: cosmic::app::Core,
|
||||||
drop_target: Option<(ZcosmicWorkspaceHandleV1, wl_output::WlOutput)>,
|
drop_target: Option<(ZcosmicWorkspaceHandleV1, wl_output::WlOutput)>,
|
||||||
bg_state: Option<cosmic_bg_config::state::State>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -294,18 +278,6 @@ impl App {
|
||||||
);
|
);
|
||||||
self.update_capture_filter();
|
self.update_capture_filter();
|
||||||
|
|
||||||
if let Some(config) = &self.conf.bg_config {
|
|
||||||
match cosmic_bg_config::state::State::get_entry(&config) {
|
|
||||||
Ok(state) => {
|
|
||||||
self.bg_state = Some(state);
|
|
||||||
}
|
|
||||||
Err((err, state)) => {
|
|
||||||
log::error!("failed to load bg config: {:?}", err);
|
|
||||||
self.bg_state = Some(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
} else {
|
} else {
|
||||||
Command::none()
|
Command::none()
|
||||||
|
|
@ -593,6 +565,9 @@ impl Application for App {
|
||||||
Msg::CompConfig(c) => {
|
Msg::CompConfig(c) => {
|
||||||
self.conf.workspace_config = c.workspaces;
|
self.conf.workspace_config = c.workspaces;
|
||||||
}
|
}
|
||||||
|
Msg::BgConfig(c) => {
|
||||||
|
self.conf.bg = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
|
|
@ -646,7 +621,25 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Msg::CompConfig(Box::new(update.config))
|
Msg::CompConfig(Box::new(update.config))
|
||||||
});
|
});
|
||||||
let mut subscriptions = vec![events, config_subscription, comp_config_subscription];
|
let bg_subscription =
|
||||||
|
cosmic_config::config_state_subscription::<_, cosmic_bg_config::state::State>(
|
||||||
|
"bg-sub",
|
||||||
|
cosmic_bg_config::NAME.into(),
|
||||||
|
cosmic_bg_config::state::State::version(),
|
||||||
|
)
|
||||||
|
.map(|update| {
|
||||||
|
if !update.errors.is_empty() {
|
||||||
|
log::error!("Failed to load bg config: {:?}", update.errors);
|
||||||
|
}
|
||||||
|
Msg::BgConfig(update.config)
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut subscriptions = vec![
|
||||||
|
events,
|
||||||
|
config_subscription,
|
||||||
|
comp_config_subscription,
|
||||||
|
bg_subscription,
|
||||||
|
];
|
||||||
if let Some(conn) = self.conn.clone() {
|
if let Some(conn) = self.conn.clone() {
|
||||||
subscriptions.push(backend::subscription(conn).map(Msg::Wayland));
|
subscriptions.push(backend::subscription(conn).map(Msg::Wayland));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ pub(crate) fn layer_surface<'a>(
|
||||||
.iter()
|
.iter()
|
||||||
.find(|x| x.handle == surface.output)
|
.find(|x| x.handle == surface.output)
|
||||||
.map_or("", |o| &o.name);
|
.map_or("", |o| &o.name);
|
||||||
let bg = bg_element(app.bg_state.as_ref(), output_name);
|
let bg = bg_element(&app.conf.bg, output_name);
|
||||||
crate::widgets::image_bg(container, bg).into()
|
crate::widgets::image_bg(container, bg).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,7 +125,9 @@ pub(crate) fn workspace_item<'a>(
|
||||||
.selected(workspace.is_active)
|
.selected(workspace.is_active)
|
||||||
.style(cosmic::theme::Button::Custom {
|
.style(cosmic::theme::Button::Custom {
|
||||||
active: Box::new(move |_focused, theme| workspace_item_appearance(
|
active: Box::new(move |_focused, theme| workspace_item_appearance(
|
||||||
theme, is_active, is_drop_target
|
theme,
|
||||||
|
is_active,
|
||||||
|
is_drop_target
|
||||||
)),
|
)),
|
||||||
disabled: Box::new(|_theme| { unreachable!() }),
|
disabled: Box::new(|_theme| { unreachable!() }),
|
||||||
hovered: Box::new(move |_focused, theme| workspace_item_appearance(
|
hovered: Box::new(move |_focused, theme| workspace_item_appearance(
|
||||||
|
|
@ -332,12 +334,12 @@ fn toplevel_previews<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bg_element<'a>(
|
fn bg_element<'a>(
|
||||||
bg_state: Option<&'a cosmic_bg_config::state::State>,
|
bg_state: &'a cosmic_bg_config::state::State,
|
||||||
output_name: &'a str,
|
output_name: &'a str,
|
||||||
) -> cosmic::Element<'a, Msg> {
|
) -> cosmic::Element<'a, Msg> {
|
||||||
let bg_source = bg_state
|
let bg_source = bg_state
|
||||||
.into_iter()
|
.wallpapers
|
||||||
.flat_map(|x| x.wallpapers.iter())
|
.iter()
|
||||||
.find(|(n, _)| n == output_name)
|
.find(|(n, _)| n == output_name)
|
||||||
.map(|(_, v)| v.clone());
|
.map(|(_, v)| v.clone());
|
||||||
match bg_source {
|
match bg_source {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue