diff --git a/src/app_tray/mod.rs b/src/app_tray/mod.rs index a5e0a46..c07f371 100644 --- a/src/app_tray/mod.rs +++ b/src/app_tray/mod.rs @@ -1,10 +1,10 @@ -use std::{collections::HashMap, path::PathBuf}; +use std::{collections::HashMap, path::PathBuf, rc::Rc}; +use super::desktop_entry::DesktopEntryCache; use cctk::wayland_client::protocol::wl_seat::WlSeat; use compositor::{ CompositorBackend, CompositorToplevelInfo, ToplevelHandle, WaylandIncoming, WaylandOutgoing, }; -use desktop_entry::DesktopEntryCache; use freedesktop_desktop_entry::DesktopEntry; use iced::{ border::Radius, @@ -13,14 +13,13 @@ use iced::{ Background, Border, Element, Length, Task, Theme, }; -use crate::config::AppTrayConfig; +use crate::{component::Component, config::AppTrayConfig}; pub mod compositor; -pub mod desktop_entry; #[derive(Clone, Debug)] pub struct AppTray<'a> { - pub de_cache: DesktopEntryCache<'a>, + de_cache: Rc>, backend: CompositorBackend, config: AppTrayConfig, context_menu: Option, @@ -35,40 +34,10 @@ pub enum AppTrayMessage { ContextMenu(String), } -impl<'a> AppTray<'a> { - pub fn new(config: AppTrayConfig) -> Self { - Self { - de_cache: DesktopEntryCache::new(), - backend: CompositorBackend::new(), - config, - context_menu: None, - } - } +impl<'a> Component for AppTray<'a> { + type Message = AppTrayMessage; - pub fn handle_message(&mut self, app_tray_message: AppTrayMessage) -> Task { - match app_tray_message { - AppTrayMessage::WaylandIn(evt) => { - self.backend.handle_incoming(evt).unwrap_or(Task::none()) - } - AppTrayMessage::WaylandOut(evt) => { - self.backend.handle_outgoing(evt).unwrap_or(Task::none()) - } - AppTrayMessage::NewSeat(_) => { - log::trace!("New seat!"); - Task::none() - } - AppTrayMessage::RemovedSeat(_) => { - log::trace!("Removed seat!"); - Task::none() - } - AppTrayMessage::ContextMenu(app_id) => { - log::trace!("App id requested: {}", &app_id); - Task::none() - } - } - } - - pub fn view(&self) -> iced::Element { + fn view(&self) -> iced::Element { let active_window = self.backend.active_window(); // Get app tray apps let app_tray_apps = self @@ -120,6 +89,47 @@ impl<'a> AppTray<'a> { iced::widget::row(app_tray_apps).into() } + fn handle_message(&mut self, message: Self::Message) -> iced::Task { + match message { + AppTrayMessage::WaylandIn(evt) => { + self.backend.handle_incoming(evt).unwrap_or(Task::none()) + } + AppTrayMessage::WaylandOut(evt) => { + self.backend.handle_outgoing(evt).unwrap_or(Task::none()) + } + AppTrayMessage::NewSeat(_) => { + log::trace!("New seat!"); + Task::none() + } + AppTrayMessage::RemovedSeat(_) => { + log::trace!("Removed seat!"); + Task::none() + } + AppTrayMessage::ContextMenu(app_id) => { + log::trace!("App id requested: {}", &app_id); + Task::none() + } + } + } + + fn subscription(&self) -> iced::Subscription { + self.backend + .wayland_subscription() + .map(AppTrayMessage::WaylandIn) + // iced::Subscription::none() + } +} + +impl<'a> AppTray<'a> { + pub fn new(config: AppTrayConfig, de_cache: Rc>) -> Self { + Self { + de_cache, + backend: CompositorBackend::new(), + config, + context_menu: None, + } + } + fn view_tray_item( &self, app_id: &str, @@ -266,11 +276,4 @@ impl<'a> AppTray<'a> { ..Default::default() } } - - pub fn subscription(&self) -> iced::Subscription { - self.backend - .wayland_subscription() - .map(AppTrayMessage::WaylandIn) - // iced::Subscription::none() - } } diff --git a/src/component.rs b/src/component.rs new file mode 100644 index 0000000..62e50a3 --- /dev/null +++ b/src/component.rs @@ -0,0 +1,9 @@ +pub trait Component { + type Message; + + fn view(&self) -> iced::Element; + + fn handle_message(&mut self, message: Self::Message) -> iced::Task; + + fn subscription(&self) -> iced::Subscription; +} diff --git a/src/app_tray/desktop_entry.rs b/src/desktop_entry.rs similarity index 100% rename from src/app_tray/desktop_entry.rs rename to src/desktop_entry.rs diff --git a/src/main.rs b/src/main.rs index fc54950..252d0a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,9 +16,12 @@ use env_logger::Env; use panel::Panel; pub mod app_tray; +pub mod component; mod config; +pub mod desktop_entry; mod panel; mod settings_tray; +pub mod start_menu; /// ryanabx desktop shell for wayland desktops #[derive(Parser, Debug)] diff --git a/src/start_menu/mod.rs b/src/start_menu/mod.rs new file mode 100644 index 0000000..b333fcc --- /dev/null +++ b/src/start_menu/mod.rs @@ -0,0 +1,36 @@ +use std::rc::Rc; + +use crate::{component::Component, desktop_entry::DesktopEntryCache}; + +#[derive(Clone, Debug)] +pub enum StartMenuMessage { + MenuOpened, +} + +pub struct StartMenu<'a> { + de_cache: Rc>, +} + +impl<'a> StartMenu<'a> { + pub fn new(de_cache: Rc>) -> Self { + Self { de_cache } + } +} + +impl<'a> Component for StartMenu<'a> { + type Message = StartMenuMessage; + + fn view(&self) -> iced::Element { + todo!() + } + + fn handle_message(&mut self, message: Self::Message) -> iced::Task { + match message { + StartMenuMessage::MenuOpened => todo!(), + } + } + + fn subscription(&self) -> iced::Subscription { + todo!() + } +}