chore: update libcosmic
This commit is contained in:
parent
0b74b0e586
commit
d15ebbd340
5 changed files with 469 additions and 547 deletions
841
Cargo.lock
generated
841
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -117,7 +117,8 @@ impl Default for Page {
|
|||
config_helper,
|
||||
panel_config,
|
||||
container_config,
|
||||
outputs: HashMap::new(),
|
||||
outputs_map: HashMap::new(),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use cosmic::{
|
|||
sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy},
|
||||
theme,
|
||||
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,
|
||||
};
|
||||
|
|
@ -16,14 +16,40 @@ use cosmic_panel_config::{
|
|||
CosmicPanelOuput, PanelAnchor, PanelSize,
|
||||
};
|
||||
use cosmic_settings_page::{self as page, Section};
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct PageInner {
|
||||
pub(crate) config_helper: Option<cosmic_config::Config>,
|
||||
pub(crate) panel_config: Option<CosmicPanelConfig>,
|
||||
pub outputs: Vec<String>,
|
||||
pub anchors: Vec<String>,
|
||||
pub backgrounds: Vec<String>,
|
||||
pub(crate) container_config: Option<CosmicPanelContainerConfig>,
|
||||
// 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 {
|
||||
|
|
@ -71,30 +97,20 @@ pub(crate) fn behavior_and_position<
|
|||
))
|
||||
.add(settings::item(
|
||||
&descriptions[1],
|
||||
pick_list(
|
||||
Cow::from(vec![
|
||||
Anchor(PanelAnchor::Top),
|
||||
Anchor(PanelAnchor::Left),
|
||||
Anchor(PanelAnchor::Right),
|
||||
Anchor(PanelAnchor::Bottom),
|
||||
]),
|
||||
Some(Anchor(panel_config.anchor)),
|
||||
|a| Message::PanelAnchor(a.0),
|
||||
dropdown(
|
||||
page.anchors.as_slice(),
|
||||
Some(panel_config.anchor as usize),
|
||||
Message::PanelAnchor,
|
||||
),
|
||||
))
|
||||
.add(settings::item(
|
||||
&descriptions[2],
|
||||
pick_list(
|
||||
Cow::from(
|
||||
Some(fl!("all"))
|
||||
.into_iter()
|
||||
.chain(page.outputs.values().map(|(name, _)| name.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
dropdown(
|
||||
page.outputs.as_slice(),
|
||||
match &panel_config.output {
|
||||
CosmicPanelOuput::All => Some(fl!("all")),
|
||||
CosmicPanelOuput::All => Some(0),
|
||||
CosmicPanelOuput::Active => None,
|
||||
CosmicPanelOuput::Name(ref name) => Some(name.clone()),
|
||||
CosmicPanelOuput::Name(n) => page.outputs.iter().position(|o| o == n),
|
||||
},
|
||||
Message::Output,
|
||||
),
|
||||
|
|
@ -141,9 +157,14 @@ pub(crate) fn style<
|
|||
))
|
||||
.add(settings::item(
|
||||
&descriptions[2],
|
||||
pick_list(
|
||||
Cow::from(vec![Appearance::Match, Appearance::Light, Appearance::Dark]),
|
||||
panel_config.background.clone().try_into().ok(),
|
||||
dropdown(
|
||||
inner.backgrounds.as_slice(),
|
||||
match panel_config.background {
|
||||
CosmicPanelBackground::ThemeDefault => Some(0),
|
||||
CosmicPanelBackground::Dark => Some(1),
|
||||
CosmicPanelBackground::Light => Some(2),
|
||||
CosmicPanelBackground::Color(_) => None,
|
||||
},
|
||||
Message::Appearance,
|
||||
),
|
||||
))
|
||||
|
|
@ -312,11 +333,11 @@ impl From<Appearance> for CosmicPanelBackground {
|
|||
pub enum Message {
|
||||
// panel messages
|
||||
AutoHidePanel(bool),
|
||||
PanelAnchor(PanelAnchor),
|
||||
Output(String),
|
||||
PanelAnchor(usize),
|
||||
Output(usize),
|
||||
AnchorGap(bool),
|
||||
PanelSize(PanelSize),
|
||||
Appearance(Appearance),
|
||||
Appearance(usize),
|
||||
ExtendToEdge(bool),
|
||||
Opacity(f32),
|
||||
OutputAdded(String, WlOutput),
|
||||
|
|
@ -346,14 +367,25 @@ impl PageInner {
|
|||
panel_config.autohide = None;
|
||||
}
|
||||
}
|
||||
Message::PanelAnchor(anchor) => {
|
||||
panel_config.anchor = anchor;
|
||||
Message::PanelAnchor(i) => {
|
||||
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) => {
|
||||
panel_config.output = match name {
|
||||
s if s == fl!("all") => CosmicPanelOuput::All,
|
||||
_ => CosmicPanelOuput::Name(name),
|
||||
};
|
||||
Message::Output(i) => {
|
||||
if i == 0 {
|
||||
panel_config.output = CosmicPanelOuput::All;
|
||||
} else {
|
||||
panel_config.output = CosmicPanelOuput::Name(self.outputs[i].clone())
|
||||
}
|
||||
}
|
||||
Message::AnchorGap(enabled) => {
|
||||
panel_config.anchor_gap = enabled;
|
||||
|
|
@ -368,7 +400,12 @@ impl PageInner {
|
|||
panel_config.size = size;
|
||||
}
|
||||
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) => {
|
||||
panel_config.expand_to_edges = enabled;
|
||||
|
|
@ -377,10 +414,15 @@ impl PageInner {
|
|||
panel_config.opacity = opacity;
|
||||
}
|
||||
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) => {
|
||||
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) => {
|
||||
self.panel_config = Some(c);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ impl Default for Page {
|
|||
config_helper,
|
||||
panel_config,
|
||||
container_config,
|
||||
outputs: HashMap::new(),
|
||||
outputs_map: HashMap::new(),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use std::{
|
|||
|
||||
use apply::Apply;
|
||||
use cosmic::widget::{
|
||||
list_column,
|
||||
dropdown, list_column,
|
||||
segmented_button::{self, SingleSelectModel},
|
||||
segmented_selection, settings, text, toggler,
|
||||
};
|
||||
|
|
@ -44,11 +44,11 @@ const HOUR_2: usize = 5;
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Message {
|
||||
ChangeCategory(String),
|
||||
ChangeCategory(usize),
|
||||
ColorSelect(wallpaper::Color),
|
||||
Fit(String),
|
||||
Output(segmented_button::Entity),
|
||||
RotationFrequency(String),
|
||||
RotationFrequency(usize),
|
||||
SameBackground(bool),
|
||||
Select(DefaultKey),
|
||||
Slideshow(bool),
|
||||
|
|
@ -322,21 +322,19 @@ impl Page {
|
|||
}
|
||||
|
||||
/// Changes the selection category, such as wallpaper select or color select.
|
||||
fn change_category(&mut self, category: &str) {
|
||||
if let Some(pos) = self.categories.iter().position(|c| c == category) {
|
||||
self.active_category = pos;
|
||||
match pos {
|
||||
CATEGORY_SYSTEM_WALLPAPERS => {
|
||||
self.select_first_background();
|
||||
}
|
||||
|
||||
CATEGORY_COLOR => {
|
||||
self.selection.active = Choice::Color(wallpaper::DEFAULT_COLORS[0].clone());
|
||||
self.cache_display_image();
|
||||
}
|
||||
|
||||
_ => (),
|
||||
fn change_category(&mut self, pos: usize) {
|
||||
self.active_category = pos;
|
||||
match pos {
|
||||
CATEGORY_SYSTEM_WALLPAPERS => {
|
||||
self.select_first_background();
|
||||
}
|
||||
|
||||
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
|
||||
pub fn change_rotation_frequency(&mut self, option: &str) {
|
||||
self.selected_rotation = self
|
||||
.rotation_options
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, key)| **key == option)
|
||||
.map_or(0, |(indice, _)| indice);
|
||||
pub fn change_rotation_frequency(&mut self, option: usize) {
|
||||
self.selected_rotation = option;
|
||||
|
||||
self.rotation_frequency = match self.selected_rotation {
|
||||
MINUTES_5 => 300,
|
||||
|
|
@ -382,7 +375,7 @@ impl Page {
|
|||
#[allow(clippy::too_many_lines)]
|
||||
pub fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::ChangeCategory(category) => self.change_category(&category),
|
||||
Message::ChangeCategory(pos) => self.change_category(pos),
|
||||
|
||||
Message::ColorSelect(color) => {
|
||||
self.selection.active = Choice::Color(color);
|
||||
|
|
@ -402,7 +395,7 @@ impl Page {
|
|||
|
||||
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) => {
|
||||
self.config.same_on_all = value;
|
||||
|
|
@ -633,9 +626,9 @@ pub fn settings() -> Section<crate::pages::Message> {
|
|||
column
|
||||
.add(settings::item(
|
||||
&descriptions[3],
|
||||
cosmic::iced::widget::pick_list(
|
||||
dropdown(
|
||||
&page.rotation_options,
|
||||
page.rotation_options.get(page.selected_rotation).cloned(),
|
||||
Some(page.selected_rotation),
|
||||
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,
|
||||
Some(page.categories[page.active_category].clone()),
|
||||
Some(page.active_category),
|
||||
Message::ChangeCategory,
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue