From e9aa969e61ba812416dceeb15bc7926986e1e793 Mon Sep 17 00:00:00 2001 From: Ryan Brue Date: Mon, 6 May 2024 15:56:13 -0500 Subject: [PATCH] feat(applet): add panel type attribute to applet context This will allow applets to know whether they are on a Panel, Dock, or other named panel. --- src/applet/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/applet/mod.rs b/src/applet/mod.rs index 8d6acde..d89535a 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -32,6 +32,7 @@ pub struct Context { pub anchor: PanelAnchor, pub background: CosmicPanelBackground, pub output_name: String, + pub panel_type: PanelType, } #[derive(Clone, Debug)] @@ -41,6 +42,23 @@ pub enum Size { Hardcoded((u16, u16)), } +#[derive(Clone, Debug, PartialEq)] +pub enum PanelType { + Panel, + Dock, + Other(String), +} + +impl From for PanelType { + fn from(value: String) -> Self { + match value.as_str() { + "Panel" => PanelType::Panel, + "Dock" => PanelType::Dock, + other => PanelType::Other(other.to_string()), + } + } +} + impl Default for Context { fn default() -> Self { Self { @@ -59,6 +77,7 @@ impl Default for Context { .and_then(|size| ron::from_str(size.as_str()).ok()) .unwrap_or(CosmicPanelBackground::ThemeDefault), output_name: std::env::var("COSMIC_PANEL_OUTPUT").unwrap_or_default(), + panel_type: PanelType::from(std::env::var("COSMIC_PANEL_NAME").unwrap_or_default()), } } }