Skip to content

Commit

Permalink
wip stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanabx committed Sep 1, 2024
1 parent a159b92 commit 5c84402
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 45 deletions.
93 changes: 48 additions & 45 deletions src/app_tray/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<DesktopEntryCache<'a>>,
backend: CompositorBackend,
config: AppTrayConfig,
context_menu: Option<Id>,
Expand All @@ -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<AppTrayMessage> {
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<AppTrayMessage> {
fn view(&self) -> iced::Element<Self::Message> {
let active_window = self.backend.active_window();
// Get app tray apps
let app_tray_apps = self
Expand Down Expand Up @@ -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<Self::Message> {
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::Message> {
self.backend
.wayland_subscription()
.map(AppTrayMessage::WaylandIn)
// iced::Subscription::none()
}
}

impl<'a> AppTray<'a> {
pub fn new(config: AppTrayConfig, de_cache: Rc<DesktopEntryCache<'a>>) -> Self {
Self {
de_cache,
backend: CompositorBackend::new(),
config,
context_menu: None,
}
}

fn view_tray_item(
&self,
app_id: &str,
Expand Down Expand Up @@ -266,11 +276,4 @@ impl<'a> AppTray<'a> {
..Default::default()
}
}

pub fn subscription(&self) -> iced::Subscription<AppTrayMessage> {
self.backend
.wayland_subscription()
.map(AppTrayMessage::WaylandIn)
// iced::Subscription::none()
}
}
9 changes: 9 additions & 0 deletions src/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub trait Component {
type Message;

fn view(&self) -> iced::Element<Self::Message>;

fn handle_message(&mut self, message: Self::Message) -> iced::Task<Self::Message>;

fn subscription(&self) -> iced::Subscription<Self::Message>;
}
File renamed without changes.
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
36 changes: 36 additions & 0 deletions src/start_menu/mod.rs
Original file line number Diff line number Diff line change
@@ -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<DesktopEntryCache<'a>>,
}

impl<'a> StartMenu<'a> {
pub fn new(de_cache: Rc<DesktopEntryCache<'a>>) -> Self {
Self { de_cache }
}
}

impl<'a> Component for StartMenu<'a> {
type Message = StartMenuMessage;

fn view(&self) -> iced::Element<Self::Message> {
todo!()
}

fn handle_message(&mut self, message: Self::Message) -> iced::Task<Self::Message> {
match message {
StartMenuMessage::MenuOpened => todo!(),
}
}

fn subscription(&self) -> iced::Subscription<Self::Message> {
todo!()
}
}

0 comments on commit 5c84402

Please sign in to comment.