Something went wrong. Try again.
Some shell. slowshell.bushyice.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299pub mod audio;pub mod bluetooth;pub mod clock;pub mod icon;pub mod network;pub mod notifications;pub mod power;pub mod separator;pub mod sysmon;pub mod tray;pub mod window;pub mod workspaces;
use std::collections::HashMap;
use iced::{Element, Event, mouse};use slowshell_commons::panels::{PanelEdge, PanelOrientation};use slowshell_config::Config;use slowshell_core::{ Store, listeners::ListenerAction, message::{EventFilter, ItemEffect, ItemMessage}, types::{ToUstr, Ustr},};use slowshell_widgets::EventWrapper;
pub trait Component: Send { fn events(&self) -> Vec<EventFilter> { Vec::new() }
fn watch(&mut self, store: &mut Store, options: Option<&ComponentOptions>) { let _ = (store, options); }
fn stop(&mut self, store: &Store, options: Option<&ComponentOptions>) { let _ = (store, options); }
fn update( &mut self, config: &Config, store: &mut Store, event: &ListenerAction, options: Option<&ComponentOptions>, ) -> anyhow::Result<ItemEffect> { let _ = (config, store, event, options); Ok(ItemEffect::None) }
fn check_view(&self, store: &Store, options: Option<&ComponentOptions>) -> bool { let _ = (store, options); true }
fn view<'a>( &self, config: &Config, store: &Store, ctx: &ComponentContext, options: Option<&ComponentOptions>, ) -> Element<'a, ItemMessage>;}
pub struct ComponentOptions { inner: HashMap<Ustr, toml::Value>,}
impl ComponentOptions { pub fn number(&self, id: impl Into<Ustr>) -> Option<f32> { self .inner .get(&id.into()) .and_then(|s| s.as_float().map(|x| x as f32)) }
pub fn int(&self, id: impl Into<Ustr>) -> Option<i32> { self .inner .get(&id.into()) .and_then(|s| s.as_integer().map(|x| x as i32)) }
pub fn str(&self, id: impl Into<Ustr>) -> Option<&str> { self.inner.get(&id.into()).and_then(|s| s.as_str()) }
pub fn bool(&self, id: impl Into<Ustr>) -> Option<bool> { self.inner.get(&id.into()).and_then(|b| b.as_bool()) }
pub fn table(&self, id: impl Into<Ustr>) -> Option<&toml::Table> { self .inner .get(&id.into()) .and_then(|value| value.as_table()) }
pub fn strings(&self, id: impl Into<Ustr>) -> Option<Vec<&str>> { self .inner .get(&id.into()) .and_then(|value| value.as_str()) .map(|s| s.split(",").collect::<Vec<_>>()) }}
impl From<HashMap<Ustr, toml::Value>> for ComponentOptions { fn from(value: HashMap<Ustr, toml::Value>) -> Self { ComponentOptions { inner: value } }}
pub struct ComponentContext<'a> { pub panel_name: &'a str, pub position: PanelEdge, pub orientation: PanelOrientation, pub monitor: &'a str,}
impl<'a> ComponentContext<'a> { pub fn resolve_style(&self, config: &slowshell_config::Config) -> slowshell_config::style::Style { if self.orientation == PanelOrientation::Horizontal { config.style("component") } else { config.style_any(&["component.vertical", "component"]) } }}
pub fn vertical_text<'a, Message: 'a>( content: &str, font_size: f32, color: iced::Color,) -> Element<'a, Message> { use iced::widget::{column, text}; let items: Vec<Element<'a, Message>> = content .chars() .map(|ch| text(ch.to_string()).size(font_size).color(color).into()) .collect(); column(items).spacing(0).align_x(iced::Alignment::Center).into()}
pub struct MenuConfig { pub content: String, pub panel_name: Option<String>, pub position: PanelEdge,}
pub fn popup_open_action(config: &MenuConfig, cursor: iced::Point) -> ListenerAction { let mut payload: HashMap<Ustr, Ustr> = HashMap::new(); payload.insert("content".to_ustr(), config.content.to_ustr());
let (x, y) = match config.position { PanelEdge::Top { .. } | PanelEdge::Bottom { .. } => ( format!("fixed,{}", cursor.x), if let Some(panel) = &config.panel_name { format!("panel,{}", panel) } else { format!("fixed,0.0") }, ), PanelEdge::Left { width } => { payload.insert("edge".to_ustr(), "left".to_ustr()); ( format!("fixed,{}", width as f32), format!("fixed,{}", cursor.y), ) } PanelEdge::Right { .. } => { payload.insert("edge".to_ustr(), "right".to_ustr()); ( format!("fixed,0.0"), format!("fixed,{}", cursor.y), ) } };
payload.insert("x".to_ustr(), x.to_ustr()); payload.insert("y".to_ustr(), y.to_ustr());
ListenerAction::Payload { name: "popup.open".to_ustr(), payload: Some(payload), }}
pub fn menu_trigger<'a>( content: Element<'a, ItemMessage>, config: MenuConfig,) -> Element<'a, ItemMessage> { let action = move |event: &Event, layout: iced::advanced::layout::Layout<'_>, cursor: mouse::Cursor| { if !cursor.is_over(layout.bounds()) { return None; } let Event::Mouse(mouse::Event::ButtonPressed(button)) = event else { return None; }; if !matches!(button, mouse::Button::Left | mouse::Button::Right) { return None; } let Some(point) = cursor.position() else { return None; }; Some(ItemMessage::Action(popup_open_action(&config, point))) };
EventWrapper::new(content, action).into()}
pub type ComponentFactory = Box<dyn Fn() -> Box<dyn Component> + Send + Sync>;pub type Components = HashMap<Ustr, ComponentFactory>;
pub fn register_all(components: &mut Components) { components.insert( "core/audio".into(), Box::new(|| Box::new(audio::Audio::new())), ); components.insert( "core/sound".into(), Box::new(|| Box::new(audio::Audio::new())), ); components.insert( "core/clock".into(), Box::new(|| Box::new(clock::Clock::new())), ); components.insert( "core/power".into(), Box::new(|| Box::new(power::Power::new())), ); components.insert( "core/system".into(), Box::new(|| Box::new(sysmon::SystemMon::new())), ); components.insert( "core/network".into(), Box::new(|| Box::new(network::Network::new())), ); components.insert( "core/bluetooth".into(), Box::new(|| Box::new(bluetooth::Bluetooth::new())), ); components.insert( "core/notifications".into(), Box::new(|| Box::new(notifications::Notifications::new())), ); components.insert( "core/icon".into(), Box::new(|| Box::new(icon::IconComp::default())), ); components.insert( "core/tray".into(), Box::new(|| Box::new(tray::SystemTray::new())), ); components.insert( "core/separator".into(), Box::new(|| Box::new(separator::Separator)), ); components.insert( "core/workspaces".into(), Box::new(|| Box::new(workspaces::Workspaces)), ); components.insert("core/window".into(), Box::new(|| Box::new(window::Window)));}
slowshell_registry::register_resources!( component: Style( slowshell_config::style! { "color" => "text", "color.faded" => "subtext", "color.invert" => "base", "color.primary" => "primary", "font.size" => 12, "icon.size" => 14, "spacing" => 5, "padding.x" => 9, "padding.y" => 5, } ));
pub fn register_vertical_style() { slowshell_config::style::new_default_style( "component.vertical".into(), slowshell_config::style! { "color" => "text", "color.faded" => "subtext", "color.invert" => "base", "color.primary" => "primary", "font.size" => 15, "icon.size" => 18, "spacing" => 8, "padding.x" => 5, "padding.y" => 4, }, );}