Skip to content

Commit

Permalink
add new output system
Browse files Browse the repository at this point in the history
  • Loading branch information
MalpenZibo committed Dec 6, 2024
1 parent 77d9c88 commit 964cd34
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 326 deletions.
281 changes: 146 additions & 135 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::{
centerbox,
config::{self, Config},
get_log_spec,
menu::{menu_wrapper, Menu, MenuPosition},
menu::{menu_wrapper, MenuPosition},
modules::{
self, clipboard, clock::Clock, keyboard_layout::KeyboardLayout,
keyboard_submap::KeyboardSubmap, launcher, privacy::PrivacyMessage, settings::Settings,
system_info::SystemInfo, title::Title, updates::Updates, workspaces::Workspaces,
},
outputs::Outputs,
outputs::{HasOutput, Outputs},
services::{privacy::PrivacyService, ReadOnlyService, ServiceEvent},
style::ashell_theme,
utils, HEIGHT,
Expand All @@ -17,7 +17,7 @@ use flexi_logger::LoggerHandle;
use iced::{
daemon::Appearance,
event::{listen_with, wayland::Event as WaylandEvent},
widget::{row, Row},
widget::Row,
window::Id,
Alignment, Color, Element, Length, Subscription, Task, Theme,
};
Expand Down Expand Up @@ -48,7 +48,7 @@ pub enum MenuType {
pub enum Message {
None,
ConfigChanged(Box<Config>),
CloseMenu,
CloseMenu(Id),
OpenLauncher,
OpenClipboard,
Updates(modules::updates::Message),
Expand All @@ -60,7 +60,7 @@ pub enum Message {
Clock(modules::clock::Message),
Privacy(modules::privacy::PrivacyMessage),
Settings(modules::settings::Message),
// WaylandEvent(WaylandEvent),
WaylandEvent(WaylandEvent),
}

impl App {
Expand Down Expand Up @@ -107,19 +107,21 @@ impl App {
Message::None => Task::none(),
Message::ConfigChanged(config) => {
info!("New config: {:?}", config);
let mut tasks = Vec::new();
if self.config.outputs != config.outputs {
tasks.push(self.outputs.sync(&config.outputs, config.position));
}
self.config = *config;
self.logger
.set_new_spec(get_log_spec(&self.config.log_level));
Task::none()
}
Message::CloseMenu => {
// self.menu.close(),
Task::none()

Task::batch(tasks)
}
Message::CloseMenu(id) => self.outputs.close_menu(id),
Message::Updates(message) => {
if let Some(updates_config) = self.config.updates.as_ref() {
// self.updates.update(message, updates_config, &mut self.menu)
Task::none()
self.updates
.update(message, updates_config, &mut self.outputs)
} else {
Task::none()
}
Expand Down Expand Up @@ -178,125 +180,134 @@ impl App {
},
},
Message::Settings(message) => {
// self.settings
// .update(message, &self.config.settings, &mut self.menu)
Task::none()
} // Message::WaylandEvent(event) => match event {
// WaylandEvent::Output(event, wl_output) => match event {
// iced::event::wayland::OutputEvent::Created(info) => {
// info!("Output created: {:?}", info);
// self.outputs.add(
// &self.config.outputs,
// self.config.position,
// info,
// wl_output,
// )
// }
// iced::event::wayland::OutputEvent::Removed => {
// info!("Output destroyed");
// self.outputs.remove(self.config.position, wl_output)
// }
// _ => Task::none(),
// },
// _ => Task::none(),
// },
self.settings
.update(message, &self.config.settings, &mut self.outputs)
}
Message::WaylandEvent(event) => match event {
WaylandEvent::Output(event, wl_output) => match event {
iced::event::wayland::OutputEvent::Created(info) => {
info!("Output created: {:?}", info);
let name = info
.as_ref()
.and_then(|info| info.name.as_deref())
.unwrap_or("");

self.outputs.add(
&self.config.outputs,
self.config.position,
name,
wl_output,
)
}
iced::event::wayland::OutputEvent::Removed => {
info!("Output destroyed");
self.outputs.remove(self.config.position, wl_output)
}
_ => Task::none(),
},
_ => Task::none(),
},
}
}

pub fn view(&self, id: Id) -> Element<Message> {
// if self.menu.is_menu(id) {
// match self.menu.get_menu_type_to_render(id) {
// Some(MenuType::Updates) => menu_wrapper(
// self.updates.menu_view().map(Message::Updates),
// MenuPosition::Left,
// self.config.position,
// ),
// Some(MenuType::Settings) => menu_wrapper(
// self.settings
// .menu_view(&self.config.settings)
// .map(Message::Settings),
// MenuPosition::Right,
// self.config.position,
// ),
// None => Row::new().into(),
// }
// } else {
let left = Row::new()
.push_maybe(
self.config
.app_launcher_cmd
.as_ref()
.map(|_| launcher::launcher()),
)
.push_maybe(
self.config
.clipboard_cmd
.as_ref()
.map(|_| clipboard::clipboard()),
)
.push_maybe(
self.config
.updates
.as_ref()
.map(|_| self.updates.view().map(Message::Updates)),
)
.push(
self.workspaces
.view(
&self.config.appearance.workspace_colors,
self.config.appearance.special_workspace_colors.as_deref(),
match self.outputs.has(id) {
Some(HasOutput::Main) => {
let left = Row::new()
.push_maybe(
self.config
.app_launcher_cmd
.as_ref()
.map(|_| launcher::launcher()),
)
.map(Message::Workspaces),
)
.height(Length::Shrink)
.align_y(Alignment::Center)
.spacing(4);
.push_maybe(
self.config
.clipboard_cmd
.as_ref()
.map(|_| clipboard::clipboard()),
)
.push_maybe(
self.config
.updates
.as_ref()
.map(|_| self.updates.view(id).map(Message::Updates)),
)
.push(
self.workspaces
.view(
&self.config.appearance.workspace_colors,
self.config.appearance.special_workspace_colors.as_deref(),
)
.map(Message::Workspaces),
)
.height(Length::Shrink)
.align_y(Alignment::Center)
.spacing(4);

let center = Row::new()
.push_maybe(self.window_title.view().map(|v| v.map(Message::Title)))
.spacing(4);
let center = Row::new()
.push_maybe(self.window_title.view().map(|v| v.map(Message::Title)))
.spacing(4);

let right = Row::new()
.push_maybe(
self.system_info
.view(&self.config.system)
.map(|c| c.map(Message::SystemInfo)),
)
.push_maybe(
self.keyboard_submap
.view(&self.config.keyboard.submap)
.map(|l| l.map(Message::KeyboardSubmap)),
)
.push_maybe(
self.keyboard_layout
.view(&self.config.keyboard.layout)
.map(|l| l.map(Message::KeyboardLayout)),
)
.push(
Row::new()
.push(
self.clock
.view(&self.config.clock.format)
.map(Message::Clock),
let right = Row::new()
.push_maybe(
self.system_info
.view(&self.config.system)
.map(|c| c.map(Message::SystemInfo)),
)
.push_maybe(
self.privacy
.as_ref()
.and_then(|privacy| privacy.view())
.map(|e| e.map(Message::Privacy)),
self.keyboard_submap
.view(&self.config.keyboard.submap)
.map(|l| l.map(Message::KeyboardSubmap)),
)
.push(self.settings.view().map(Message::Settings)),
)
.spacing(4);
.push_maybe(
self.keyboard_layout
.view(&self.config.keyboard.layout)
.map(|l| l.map(Message::KeyboardLayout)),
)
.push(
Row::new()
.push(
self.clock
.view(&self.config.clock.format)
.map(Message::Clock),
)
.push_maybe(
self.privacy
.as_ref()
.and_then(|privacy| privacy.view())
.map(|e| e.map(Message::Privacy)),
)
.push(self.settings.view(id).map(Message::Settings)),
)
.spacing(4);

centerbox::Centerbox::new([left.into(), center.into(), right.into()])
.spacing(4)
.padding([0, 4])
.width(Length::Fill)
.height(Length::Fixed(HEIGHT as f32))
.align_items(Alignment::Center)
.into()
// }
centerbox::Centerbox::new([left.into(), center.into(), right.into()])
.spacing(4)
.padding([0, 4])
.width(Length::Fill)
.height(Length::Fixed(HEIGHT as f32))
.align_items(Alignment::Center)
.into()
}
Some(HasOutput::Menu(menu_type)) => match menu_type {
Some(MenuType::Updates) => menu_wrapper(
id,
self.updates.menu_view(id).map(Message::Updates),
MenuPosition::Left,
self.config.position,
),
Some(MenuType::Settings) => menu_wrapper(
id,
self.settings
.menu_view(id, &self.config.settings)
.map(Message::Settings),
MenuPosition::Right,
self.config.position,
),
None => Row::new().into(),
},
None => Row::new().into(),
}
}

pub fn subscription(&self) -> Subscription<Message> {
Expand Down Expand Up @@ -326,21 +337,21 @@ impl App {
),
Some(self.settings.subscription().map(Message::Settings)),
Some(config::subscription()),
// Some(listen_with(|evt, _, _| {
// if let iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(
// evt,
// )) = evt
// {
// if matches!(evt, WaylandEvent::Output(_, _)) {
// debug!("Wayland event: {:?}", evt);
// Some(Message::WaylandEvent(evt))
// } else {
// None
// }
// } else {
// None
// }
// })),
Some(listen_with(|evt, _, _| {
if let iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(
evt,
)) = evt
{
if matches!(evt, WaylandEvent::Output(_, _)) {
debug!("Wayland event: {:?}", evt);
Some(Message::WaylandEvent(evt))
} else {
None
}
} else {
None
}
})),
]
.into_iter()
.flatten()
Expand Down
Loading

0 comments on commit 964cd34

Please sign in to comment.