Something went wrong. Try again.
Some shell. slowshell.bushyice.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161use iced::{ Element, widget::{container, row, text::Wrapping},};use slowshell_commons::desktop::DesktopEntries;use slowshell_commons::panels::PanelOrientation;use slowshell_compositor::CompositorStore;use slowshell_config::Config;use slowshell_core::{ Store, listeners::CompositorEvent, message::{EventFilter, ItemMessage},};use slowshell_widgets::{Icon, separator};
use crate::{Component, ComponentContext, ComponentOptions, spaced_component};
#[derive(Default)]pub struct Window;
impl Component for Window { fn events(&self) -> Vec<EventFilter> { vec![EventFilter::Compositor( CompositorEvent::WINDOWS | CompositorEvent::FOCUS, )] }
fn check_view(&self, store: &Store, _options: Option<&ComponentOptions>) -> bool { let Some(Ok(state)) = store.borrow::<CompositorStore>().map(|x| x.state()) else { return false; };
state.active_window.is_some() }
fn view<'a>( &'a self, config: &'a Config, store: &'a Store, ctx: &ComponentContext, options: Option<&ComponentOptions>, ) -> Element<'a, ItemMessage> { let Some(Ok(state)) = store.borrow::<CompositorStore>().map(|x| x.state()) else { return row![].into(); };
let Some(window) = state.active_window.as_ref() else { return row![].into(); };
let show_icon = options.and_then(|o| o.bool("icon")).unwrap_or(true);
let style = config.computed(ctx.classes()); let theme = config.palette();
let icon_size = style.length("icon-size").unwrap_or(14.0); let color = style .color("color") .map(|c| c.to_iced()) .unwrap_or(theme.text); let name_width = options .and_then(|o| o.number("name-width")) .unwrap_or(180.0); let title_width = options .and_then(|o| o.number("title-width")) .unwrap_or(320.0);
if ctx.orientation == PanelOrientation::Vertical { let icon_elem: Element<'_, ItemMessage> = if show_icon { window_icon(window, icon_size, color) } else { row![].into() }; return spaced_component(config, ctx, icon_elem, false); }
let show_name = options.and_then(|o| o.bool("name")).unwrap_or(true);
let show_title = options.and_then(|o| o.bool("title")).unwrap_or(true);
let mut content = row![].spacing(6);
if show_icon { content = content.push(window_icon(window, icon_size, color)); }
let class = window.class.clone(); let title = window.title.clone();
if show_name { let name = if let Some(name) = store .borrow::<DesktopEntries>() .map(|d| d.resolve_name(&class)) { name.to_string() } else { class };
content = content.push(clipped( config.text(name, ctx.classes()).wrapping(Wrapping::None), name_width, )); }
if show_title { if show_name { content = content.push( separator() .circle(true) .vertical(true) .opacity(0.3) .size(5.0), ); } content = content.push(clipped( config.text(title, ctx.classes()).wrapping(Wrapping::None), title_width, )); }
spaced_component(config, ctx, content.into(), false) }}
fn clipped<'a>( content: impl Into<Element<'a, ItemMessage>>, max_width: f32,) -> Element<'a, ItemMessage> { if max_width > 0.0 { container(content).max_width(max_width).clip(true).into() } else { content.into() }}
fn window_icon<'a>( window: &slowshell_core::Window, size: f32, color: iced::Color,) -> Element<'a, ItemMessage> { let icon = Icon::any([ &window.class, "window", "application-x-executable", "window-symbolic", "application-x-executable-symbolic", ]) .size(size as u16);
let symbolic = icon .resolved_name() .is_some_and(|name| name.contains("symbolic"));
if symbolic { icon.color(color).into() } else { icon.into() }}