Panel applets jammy (#41)
This commit is contained in:
parent
162ff02b12
commit
82ac6aac1c
11 changed files with 1845 additions and 62 deletions
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
use apply::Apply;
|
||||
|
||||
use cosmic_panel_config::CosmicPanelConfig;
|
||||
use cosmic_settings_page::{self as page, section};
|
||||
|
||||
use cosmic::{
|
||||
cosmic_config::config_subscription,
|
||||
iced::{
|
||||
self,
|
||||
event::wayland::{self, WindowEvent, WindowState},
|
||||
|
|
@ -30,13 +32,20 @@ use cosmic::{
|
|||
use crate::{
|
||||
config::Config,
|
||||
pages::{
|
||||
desktop::{self, panel},
|
||||
desktop::{
|
||||
self,
|
||||
panel::{
|
||||
self,
|
||||
applets::{self, APPLET_DND_ICON_ID},
|
||||
},
|
||||
},
|
||||
sound, system, time,
|
||||
},
|
||||
subscription::desktop_files,
|
||||
widget::{page_title, parent_page_button, search_header, sub_page_button},
|
||||
};
|
||||
|
||||
use std::process;
|
||||
use std::{borrow::Cow, process};
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
|
|
@ -77,6 +86,8 @@ pub enum Message {
|
|||
ToggleNavBarCondensed,
|
||||
WindowResize(u32, u32),
|
||||
WindowState(WindowState),
|
||||
PanelConfig(CosmicPanelConfig),
|
||||
DesktopInfo,
|
||||
}
|
||||
|
||||
impl Application for SettingsApp {
|
||||
|
|
@ -114,6 +125,8 @@ impl Application for SettingsApp {
|
|||
// app.insert_page::<bluetooth::Page>();
|
||||
|
||||
let desktop_id = app.insert_page::<desktop::Page>().id();
|
||||
// app.insert_page::<panel::Page>();
|
||||
// app.insert_page::<applets::Page>();
|
||||
|
||||
// app.insert_page::<input::Page>();
|
||||
|
||||
|
|
@ -174,9 +187,22 @@ impl Application for SettingsApp {
|
|||
Subscription::batch(vec![
|
||||
window_break,
|
||||
keyboard_nav::subscription().map(Message::KeyboardNav),
|
||||
desktop_files(0).map(|_| Message::DesktopInfo),
|
||||
config_subscription(0, "com.system76.CosmicPanel.panel".into(), 1).map(
|
||||
|(_, e)| match e {
|
||||
Ok(config) => Message::PanelConfig(config),
|
||||
Err((errors, config)) => {
|
||||
for error in errors {
|
||||
log::error!("Error loading panel config: {:?}", error);
|
||||
}
|
||||
Message::PanelConfig(config)
|
||||
}
|
||||
},
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn update(&mut self, message: Message) -> iced::Command<Self::Message> {
|
||||
let mut ret = Command::none();
|
||||
match message {
|
||||
|
|
@ -257,17 +283,53 @@ impl Application for SettingsApp {
|
|||
page.update(message);
|
||||
}
|
||||
}
|
||||
crate::pages::Message::Applet(message) => {
|
||||
if let Some(page) = self.pages.page_mut::<applets::Page>() {
|
||||
ret = page.update(message);
|
||||
}
|
||||
}
|
||||
},
|
||||
Message::WindowState(state) => {
|
||||
dbg!(&state);
|
||||
self.sharp_corners = matches!(state, WindowState::Activated);
|
||||
}
|
||||
Message::PanelConfig(config) if config.name.to_lowercase().contains("panel") => {
|
||||
if let Some(page) = self.pages.page_mut::<panel::Page>() {
|
||||
page.update(panel::Message::PanelConfig(config.clone()));
|
||||
}
|
||||
if let Some(page) = self.pages.page_mut::<applets::Page>() {
|
||||
_ = page.update(applets::Message::PanelConfig(config));
|
||||
}
|
||||
}
|
||||
Message::PanelConfig(_) => {} // ignore other config changes for now,
|
||||
Message::DesktopInfo => {
|
||||
if let Some(page) = self.pages.page_mut::<applets::Page>() {
|
||||
// collect the potential applets
|
||||
ret = page.update(applets::Message::Applets(
|
||||
freedesktop_desktop_entry::Iter::new(
|
||||
freedesktop_desktop_entry::default_paths(),
|
||||
)
|
||||
.filter_map(|p| applets::Applet::try_from(Cow::from(p)).ok())
|
||||
.collect(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn view(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view(&self, id: window::Id) -> Element<Message> {
|
||||
if let Some(Some(page)) =
|
||||
(id == APPLET_DND_ICON_ID).then(|| self.pages.page::<applets::Page>())
|
||||
{
|
||||
return page.dnd_icon();
|
||||
}
|
||||
if let Some(Some(page)) =
|
||||
(id == applets::ADD_APPLET_DIALOGUE_ID).then(|| self.pages.page::<applets::Page>())
|
||||
{
|
||||
return page.add_applet_view();
|
||||
}
|
||||
|
||||
let (nav_bar_message, nav_bar_toggled) = if self.is_condensed {
|
||||
(
|
||||
Message::ToggleNavBarCondensed,
|
||||
|
|
@ -335,7 +397,7 @@ impl Application for SettingsApp {
|
|||
);
|
||||
}
|
||||
|
||||
let content = container(row(widgets))
|
||||
let content = container(row(widgets).spacing(8))
|
||||
.padding([0, 8, 8, 8])
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue