chore: update libcosmic

This commit is contained in:
Ashley Wulber 2023-10-26 17:27:52 -04:00 committed by Ashley Wulber
parent 0b74b0e586
commit d15ebbd340
5 changed files with 469 additions and 547 deletions

841
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -117,7 +117,8 @@ impl Default for Page {
config_helper, config_helper,
panel_config, panel_config,
container_config, container_config,
outputs: HashMap::new(), outputs_map: HashMap::new(),
..Default::default()
}, },
} }
} }

View file

@ -5,7 +5,7 @@ use cosmic::{
sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy}, sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy},
theme, theme,
widget::{ widget::{
button, container, horizontal_space, icon, list, pick_list, row, settings, text, toggler, button, container, dropdown, horizontal_space, icon, list, row, settings, text, toggler,
}, },
Element, Element,
}; };
@ -16,14 +16,40 @@ use cosmic_panel_config::{
CosmicPanelOuput, PanelAnchor, PanelSize, CosmicPanelOuput, PanelAnchor, PanelSize,
}; };
use cosmic_settings_page::{self as page, Section}; use cosmic_settings_page::{self as page, Section};
use std::{borrow::Cow, collections::HashMap}; use std::collections::HashMap;
pub struct PageInner { pub struct PageInner {
pub(crate) config_helper: Option<cosmic_config::Config>, pub(crate) config_helper: Option<cosmic_config::Config>,
pub(crate) panel_config: Option<CosmicPanelConfig>, pub(crate) panel_config: Option<CosmicPanelConfig>,
pub outputs: Vec<String>,
pub anchors: Vec<String>,
pub backgrounds: Vec<String>,
pub(crate) container_config: Option<CosmicPanelContainerConfig>, pub(crate) container_config: Option<CosmicPanelContainerConfig>,
// TODO move these into panel config // TODO move these into panel config
pub(crate) outputs: HashMap<ObjectId, (String, WlOutput)>, pub(crate) outputs_map: HashMap<ObjectId, (String, WlOutput)>,
}
impl Default for PageInner {
fn default() -> Self {
Self {
config_helper: Default::default(),
panel_config: Default::default(),
outputs: vec![fl!("all")],
anchors: vec![
Anchor(PanelAnchor::Left).to_string(),
Anchor(PanelAnchor::Right).to_string(),
Anchor(PanelAnchor::Top).to_string(),
Anchor(PanelAnchor::Bottom).to_string(),
],
backgrounds: vec![
Appearance::Match.to_string(),
Appearance::Light.to_string(),
Appearance::Dark.to_string(),
],
container_config: Default::default(),
outputs_map: Default::default(),
}
}
} }
pub trait PanelPage { pub trait PanelPage {
@ -71,30 +97,20 @@ pub(crate) fn behavior_and_position<
)) ))
.add(settings::item( .add(settings::item(
&descriptions[1], &descriptions[1],
pick_list( dropdown(
Cow::from(vec![ page.anchors.as_slice(),
Anchor(PanelAnchor::Top), Some(panel_config.anchor as usize),
Anchor(PanelAnchor::Left), Message::PanelAnchor,
Anchor(PanelAnchor::Right),
Anchor(PanelAnchor::Bottom),
]),
Some(Anchor(panel_config.anchor)),
|a| Message::PanelAnchor(a.0),
), ),
)) ))
.add(settings::item( .add(settings::item(
&descriptions[2], &descriptions[2],
pick_list( dropdown(
Cow::from( page.outputs.as_slice(),
Some(fl!("all"))
.into_iter()
.chain(page.outputs.values().map(|(name, _)| name.clone()))
.collect::<Vec<_>>(),
),
match &panel_config.output { match &panel_config.output {
CosmicPanelOuput::All => Some(fl!("all")), CosmicPanelOuput::All => Some(0),
CosmicPanelOuput::Active => None, CosmicPanelOuput::Active => None,
CosmicPanelOuput::Name(ref name) => Some(name.clone()), CosmicPanelOuput::Name(n) => page.outputs.iter().position(|o| o == n),
}, },
Message::Output, Message::Output,
), ),
@ -141,9 +157,14 @@ pub(crate) fn style<
)) ))
.add(settings::item( .add(settings::item(
&descriptions[2], &descriptions[2],
pick_list( dropdown(
Cow::from(vec![Appearance::Match, Appearance::Light, Appearance::Dark]), inner.backgrounds.as_slice(),
panel_config.background.clone().try_into().ok(), match panel_config.background {
CosmicPanelBackground::ThemeDefault => Some(0),
CosmicPanelBackground::Dark => Some(1),
CosmicPanelBackground::Light => Some(2),
CosmicPanelBackground::Color(_) => None,
},
Message::Appearance, Message::Appearance,
), ),
)) ))
@ -312,11 +333,11 @@ impl From<Appearance> for CosmicPanelBackground {
pub enum Message { pub enum Message {
// panel messages // panel messages
AutoHidePanel(bool), AutoHidePanel(bool),
PanelAnchor(PanelAnchor), PanelAnchor(usize),
Output(String), Output(usize),
AnchorGap(bool), AnchorGap(bool),
PanelSize(PanelSize), PanelSize(PanelSize),
Appearance(Appearance), Appearance(usize),
ExtendToEdge(bool), ExtendToEdge(bool),
Opacity(f32), Opacity(f32),
OutputAdded(String, WlOutput), OutputAdded(String, WlOutput),
@ -346,14 +367,25 @@ impl PageInner {
panel_config.autohide = None; panel_config.autohide = None;
} }
} }
Message::PanelAnchor(anchor) => { Message::PanelAnchor(i) => {
panel_config.anchor = anchor; if let Some(anchor) = [
PanelAnchor::Left,
PanelAnchor::Right,
PanelAnchor::Top,
PanelAnchor::Bottom,
]
.iter()
.find(|a| a.to_string() == self.anchors[i])
{
panel_config.anchor = *anchor;
}
} }
Message::Output(name) => { Message::Output(i) => {
panel_config.output = match name { if i == 0 {
s if s == fl!("all") => CosmicPanelOuput::All, panel_config.output = CosmicPanelOuput::All;
_ => CosmicPanelOuput::Name(name), } else {
}; panel_config.output = CosmicPanelOuput::Name(self.outputs[i].clone())
}
} }
Message::AnchorGap(enabled) => { Message::AnchorGap(enabled) => {
panel_config.anchor_gap = enabled; panel_config.anchor_gap = enabled;
@ -368,7 +400,12 @@ impl PageInner {
panel_config.size = size; panel_config.size = size;
} }
Message::Appearance(a) => { Message::Appearance(a) => {
panel_config.background = a.into(); if let Some(b) = [Appearance::Match, Appearance::Light, Appearance::Dark]
.iter()
.find(|b| b.to_string() == self.backgrounds[a])
{
panel_config.background = b.clone().into();
}
} }
Message::ExtendToEdge(enabled) => { Message::ExtendToEdge(enabled) => {
panel_config.expand_to_edges = enabled; panel_config.expand_to_edges = enabled;
@ -377,10 +414,15 @@ impl PageInner {
panel_config.opacity = opacity; panel_config.opacity = opacity;
} }
Message::OutputAdded(name, output) => { Message::OutputAdded(name, output) => {
self.outputs.insert(output.id(), (name, output)); self.outputs.push(name.clone());
self.outputs_map.insert(output.id(), (name, output));
} }
Message::OutputRemoved(output) => { Message::OutputRemoved(output) => {
self.outputs.remove(&output.id()); if let Some((name, _)) = self.outputs_map.remove(&output.id()) {
if let Some(pos) = self.outputs.iter().position(|o| o == &name) {
self.outputs.remove(pos);
}
}
} }
Message::PanelConfig(c) => { Message::PanelConfig(c) => {
self.panel_config = Some(c); self.panel_config = Some(c);

View file

@ -75,7 +75,8 @@ impl Default for Page {
config_helper, config_helper,
panel_config, panel_config,
container_config, container_config,
outputs: HashMap::new(), outputs_map: HashMap::new(),
..Default::default()
}, },
} }
} }

View file

@ -11,7 +11,7 @@ use std::{
use apply::Apply; use apply::Apply;
use cosmic::widget::{ use cosmic::widget::{
list_column, dropdown, list_column,
segmented_button::{self, SingleSelectModel}, segmented_button::{self, SingleSelectModel},
segmented_selection, settings, text, toggler, segmented_selection, settings, text, toggler,
}; };
@ -44,11 +44,11 @@ const HOUR_2: usize = 5;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Message { pub enum Message {
ChangeCategory(String), ChangeCategory(usize),
ColorSelect(wallpaper::Color), ColorSelect(wallpaper::Color),
Fit(String), Fit(String),
Output(segmented_button::Entity), Output(segmented_button::Entity),
RotationFrequency(String), RotationFrequency(usize),
SameBackground(bool), SameBackground(bool),
Select(DefaultKey), Select(DefaultKey),
Slideshow(bool), Slideshow(bool),
@ -322,21 +322,19 @@ impl Page {
} }
/// Changes the selection category, such as wallpaper select or color select. /// Changes the selection category, such as wallpaper select or color select.
fn change_category(&mut self, category: &str) { fn change_category(&mut self, pos: usize) {
if let Some(pos) = self.categories.iter().position(|c| c == category) { self.active_category = pos;
self.active_category = pos; match pos {
match pos { CATEGORY_SYSTEM_WALLPAPERS => {
CATEGORY_SYSTEM_WALLPAPERS => { self.select_first_background();
self.select_first_background();
}
CATEGORY_COLOR => {
self.selection.active = Choice::Color(wallpaper::DEFAULT_COLORS[0].clone());
self.cache_display_image();
}
_ => (),
} }
CATEGORY_COLOR => {
self.selection.active = Choice::Color(wallpaper::DEFAULT_COLORS[0].clone());
self.cache_display_image();
}
_ => (),
} }
} }
@ -349,13 +347,8 @@ impl Page {
} }
// Changes the slideshow background rotation frequency // Changes the slideshow background rotation frequency
pub fn change_rotation_frequency(&mut self, option: &str) { pub fn change_rotation_frequency(&mut self, option: usize) {
self.selected_rotation = self self.selected_rotation = option;
.rotation_options
.iter()
.enumerate()
.find(|(_, key)| **key == option)
.map_or(0, |(indice, _)| indice);
self.rotation_frequency = match self.selected_rotation { self.rotation_frequency = match self.selected_rotation {
MINUTES_5 => 300, MINUTES_5 => 300,
@ -382,7 +375,7 @@ impl Page {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
pub fn update(&mut self, message: Message) { pub fn update(&mut self, message: Message) {
match message { match message {
Message::ChangeCategory(category) => self.change_category(&category), Message::ChangeCategory(pos) => self.change_category(pos),
Message::ColorSelect(color) => { Message::ColorSelect(color) => {
self.selection.active = Choice::Color(color); self.selection.active = Choice::Color(color);
@ -402,7 +395,7 @@ impl Page {
Message::Output(id) => self.change_output(id), Message::Output(id) => self.change_output(id),
Message::RotationFrequency(option) => self.change_rotation_frequency(&option), Message::RotationFrequency(pos) => self.change_rotation_frequency(pos),
Message::SameBackground(value) => { Message::SameBackground(value) => {
self.config.same_on_all = value; self.config.same_on_all = value;
@ -633,9 +626,9 @@ pub fn settings() -> Section<crate::pages::Message> {
column column
.add(settings::item( .add(settings::item(
&descriptions[3], &descriptions[3],
cosmic::iced::widget::pick_list( dropdown(
&page.rotation_options, &page.rotation_options,
page.rotation_options.get(page.selected_rotation).cloned(), Some(page.selected_rotation),
Message::RotationFrequency, Message::RotationFrequency,
), ),
)) ))
@ -645,9 +638,9 @@ pub fn settings() -> Section<crate::pages::Message> {
} }
}); });
let category_selection = cosmic::iced::widget::pick_list( let category_selection = dropdown(
&page.categories, &page.categories,
Some(page.categories[page.active_category].clone()), Some(page.active_category),
Message::ChangeCategory, Message::ChangeCategory,
); );