Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions i18n/en/cosmic_tweaks.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ delete-color-scheme = Delete color scheme
open-containing-folder = Open containing folder
installed = Installed

# Panel only
show-panel = Show panel

padding = Padding
padding-description = Padding is the space between the contents and the borders of the dock or panel.

Expand Down
86 changes: 85 additions & 1 deletion src/pages/panel.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use cosmic::{
cosmic_config::{Config, CosmicConfigEntry},
cosmic_config::{self, Config, CosmicConfigEntry},
widget, Command, Element,
};
use cosmic_panel_config::CosmicPanelConfig;
use serde::{Deserialize, Serialize};

use crate::{core::icons, fl};

Expand All @@ -12,6 +13,23 @@ pub struct Panel {
pub panel_config: Option<CosmicPanelConfig>,
pub padding: u32,
pub spacing: u32,
pub show_panel: bool,
pub cosmic_panel_config: CosmicPanel,
pub cosmic_panel_config_helper: Option<Config>,
}

#[derive(
Debug,
Clone,
Default,
Deserialize,
Serialize,
PartialEq,
Eq,
cosmic_config::cosmic_config_derive::CosmicConfigEntry,
)]
pub struct CosmicPanel {
pub entries: Vec<String>,
}

impl Default for Panel {
Expand All @@ -21,6 +39,24 @@ impl Default for Panel {
let panel_config = CosmicPanelConfig::get_entry(config_helper).ok()?;
(panel_config.name == "Panel").then_some(panel_config)
});
let (cosmic_panel_config_helper, cosmic_panel_config) =
match cosmic_config::Config::new("com.system76.CosmicPanel", 1) {
Ok(config_handler) => {
let config = match CosmicPanel::get_entry(&config_handler) {
Ok(ok) => ok,
Err((errs, config)) => {
eprintln!("errors loading config: {:?}", errs);
config
}
};
(Some(config_handler), config)
}
Err(err) => {
eprintln!("failed to create config handler: {}", err);
(None, CosmicPanel::default())
}
};

let padding = panel_config
.clone()
.map(|config| config.padding)
Expand All @@ -29,11 +65,15 @@ impl Default for Panel {
.clone()
.map(|config| config.spacing)
.unwrap_or(0);
let show_panel = cosmic_panel_config.entries.iter().any(|e| e == "Panel");
Self {
panel_helper,
panel_config,
padding,
spacing,
show_panel,
cosmic_panel_config,
cosmic_panel_config_helper,
}
}
}
Expand All @@ -42,6 +82,7 @@ impl Default for Panel {
pub enum Message {
SetPadding(u32),
SetSpacing(u32),
ShowPanel(bool),
}

impl Panel {
Expand All @@ -50,6 +91,10 @@ impl Panel {

widget::scrollable(
widget::settings::view_section("Panel")
.add(
widget::settings::item::builder(fl!("show-panel"))
.toggler(self.show_panel, Message::ShowPanel),
)
.add(
widget::settings::item::builder(fl!("padding"))
.description(fl!("padding-description"))
Expand Down Expand Up @@ -101,6 +146,45 @@ impl Panel {
eprintln!("Error updating panel spacing: {}", err);
}
}
Message::ShowPanel(show) => {
if show {
if !self
.cosmic_panel_config
.entries
.iter()
.any(|e| e == "Panel")
{
let mut entries = self.cosmic_panel_config.entries.clone();
entries.push("Panel".to_owned());
if let Some(helper) = &self.cosmic_panel_config_helper {
let update = self.cosmic_panel_config.set_entries(helper, entries);
if let Err(err) = update {
eprintln!("Error updating cosmic panel entries: {}", err);
} else {
self.show_panel = false;
}
}
}
} else {
if let Some(i) = self
.cosmic_panel_config
.entries
.iter()
.position(|e| e == "Panel")
{
let mut entries = self.cosmic_panel_config.entries.clone();
entries.remove(i);
if let Some(helper) = &self.cosmic_panel_config_helper {
let update = self.cosmic_panel_config.set_entries(helper, entries);
if let Err(err) = update {
eprintln!("Error updating cosmic panel entries: {}", err);
} else {
self.show_panel = true;
}
}
}
}
}
}
Command::none()
}
Expand Down