Skip to content

Commit

Permalink
fix: single_tone layer cannot be controlled
Browse files Browse the repository at this point in the history
use the latest iced_layershell to fix it
  • Loading branch information
Decodetalkers committed Nov 28, 2024
1 parent 1fa0350 commit ffe25e1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 78 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions iced_zbus_notification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Id {
}

/// Describe the image information.
#[derive(Type, Debug, SerializeDict, OwnedValue, Clone)]
#[derive(Type, Debug, SerializeDict, OwnedValue, Clone, PartialEq)]
struct ImageData {
width: i32,
height: i32,
Expand Down Expand Up @@ -127,14 +127,14 @@ fn get_jpeg_icon(theme: &str, icon: &str) -> Option<PathBuf> {
}

/// storage the hint of notification
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct NotifyHint {
image_data: Option<ImageData>,
desktop_entry: Option<String>,
urgency: Urgency,
}

#[derive(Deserialize, Serialize, Type, Debug, Clone, OwnedValue)]
#[derive(Deserialize, Serialize, Type, Debug, Clone, OwnedValue, PartialEq)]
#[repr(u8)]
pub enum Urgency {
Low = 0,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl NotifyHint {
}

/// Describe the information in every time notify send
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct NotifyUnit {
/// application from
pub app_name: String,
Expand Down
2 changes: 1 addition & 1 deletion lala_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ iced = { version = "0.13.1", features = [
"markdown",
] }
iced_runtime = "0.13.2"
iced_layershell = "0.9.7"
iced_layershell = "0.10.0"
tokio = { version = "1.41", features = ["full"] }
iced_futures = "0.13.2"
env_logger = "0.11.5"
Expand Down
2 changes: 1 addition & 1 deletion lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn main() -> Result<(), iced_layershell::Error> {
})
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum LaLaInfo {
Launcher,
Notify(Box<NotifyUnitWidgetInfo>),
Expand Down
86 changes: 27 additions & 59 deletions lala_bar/src/music_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub struct LalaMusicBar {
launcher: Option<launcher::Launcher>,
launcherid: Option<iced::window::Id>,
hiddenid: Option<iced::window::Id>,
hiddenid_lock: bool,
right_panel: Option<iced::window::Id>,
notifications: HashMap<u32, NotifyUnitWidgetInfo>,
pub(crate) notifications_markdown: HashMap<u32, Vec<markdown::Item>>,
Expand All @@ -52,9 +51,7 @@ pub struct LalaMusicBar {
datetime: DateTime<Local>,
calendar_id: Option<iced::window::Id>,
date: Date,
is_calendar_open: bool,
time: Time,
is_time_picker_open: bool,
time_picker_id: Option<iced::window::Id>,
}

Expand Down Expand Up @@ -499,7 +496,6 @@ impl MultiApplication for LalaMusicBar {
launcherid: None,
right_panel: None,
hiddenid: None,
hiddenid_lock: false,
notifications: HashMap::new(),
notifications_markdown: HashMap::new(),
showned_notifications: HashMap::new(),
Expand All @@ -510,8 +506,6 @@ impl MultiApplication for LalaMusicBar {
datetime: Local::now(),
calendar_id: None,
date: Date::today(),
is_calendar_open: false,
is_time_picker_open: false,
time: Time::now_hm(true),
time_picker_id: None,
},
Expand Down Expand Up @@ -561,7 +555,6 @@ impl MultiApplication for LalaMusicBar {
self.showned_notifications.insert(id, notify.unit.id);
}
LaLaInfo::HiddenInfo => {
self.hiddenid_lock = false;
self.hiddenid = Some(id);
}
LaLaInfo::RightPanel => self.right_panel = Some(id),
Expand All @@ -582,6 +575,12 @@ impl MultiApplication for LalaMusicBar {
if self.hiddenid.is_some_and(|lid| lid == id) {
self.hiddenid.take();
}
if self.calendar_id.is_some_and(|lid| lid == id) {
self.calendar_id.take();
}
if self.time_picker_id.is_some_and(|lid| lid == id) {
self.time_picker_id.take();
}
'clear_nid: {
if let Some(nid) = self.showned_notifications.remove(&id) {
if let Some(NotifyUnitWidgetInfo {
Expand All @@ -606,33 +605,15 @@ impl MultiApplication for LalaMusicBar {
return Command::perform(get_metadata(), Message::DBusInfoUpdate)
}
Message::ToggleCalendar => {
if self.is_calendar_open && self.calendar_id.is_some() {
self.is_calendar_open = false;
if let Some(calendar_id) = self.calendar_id {
return iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
calendar_id,
)));
} else if self.is_calendar_open
&& self.is_time_picker_open
&& self.calendar_id.is_some()
&& self.time_picker_id.is_some()
{
self.is_time_picker_open = false;
self.is_calendar_open = false;
return iced_runtime::task::Task::batch([
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
))),
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.time_picker_id.unwrap(),
))),
]);
} else {
if self.is_time_picker_open && self.time_picker_id.is_some() {
self.is_time_picker_open = false;
self.is_calendar_open = true;
if let Some(time_picker_id) = self.time_picker_id {
return iced_runtime::task::Task::batch([
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.time_picker_id.unwrap(),
time_picker_id,
))),
Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
Expand All @@ -646,10 +627,10 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::Calendar,
single_tone: true,
}),
]);
}
self.is_calendar_open = true;
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((350, 350)),
Expand All @@ -662,38 +643,21 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::Calendar,
single_tone: true,
});
}
}

Message::ToggleTime => {
if self.is_time_picker_open && self.time_picker_id.is_some() {
self.is_time_picker_open = false;
return iced_runtime::task::Task::batch([iced_runtime::task::effect(
Action::Window(WindowAction::Close(self.time_picker_id.unwrap())),
)]);
} else if self.is_calendar_open
&& self.is_time_picker_open
&& self.calendar_id.is_some()
&& self.time_picker_id.is_some()
{
self.is_time_picker_open = false;
self.is_calendar_open = false;
return iced_runtime::task::Task::batch([
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
))),
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.time_picker_id.unwrap(),
))),
]);
if let Some(time_picker_id) = self.time_picker_id {
return iced_runtime::task::effect(Action::Window(WindowAction::Close(
time_picker_id,
)));
} else {
if self.is_calendar_open && self.calendar_id.is_some() {
self.is_calendar_open = false;
self.is_time_picker_open = true;
if let Some(calendar_id) = self.calendar_id {
return iced_runtime::task::Task::batch([
iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
calendar_id,
))),
Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
Expand All @@ -707,10 +671,10 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::TimePicker,
single_tone: true,
}),
]);
}
self.is_time_picker_open = true;
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((350, 350)),
Expand All @@ -723,19 +687,18 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::TimePicker,
single_tone: true,
});
}
}
// NOTE: it is meaningless to pick the date now
Message::SubmitDate(_) | Message::CancelDate => {
if let Some(id) = self.calendar_id {
self.is_calendar_open = false;
return iced_runtime::task::effect(Action::Window(WindowAction::Close(id)));
}
}
Message::SubmitTime(_) | Message::CancelTime => {
if let Some(id) = self.time_picker_id {
self.is_time_picker_open = false;
return iced_runtime::task::effect(Action::Window(WindowAction::Close(id)));
}
}
Expand Down Expand Up @@ -840,6 +803,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::Launcher,
single_tone: true,
}),
self.launcher.as_ref().unwrap().focus_input(),
]);
Expand All @@ -866,6 +830,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::Launcher,
single_tone: true,
}),
self.launcher.as_ref().unwrap().focus_input(),
]);
Expand All @@ -889,6 +854,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::RightPanel,
single_tone: true,
});
}
Message::Notify(NotifyMessage::UnitAdd(notify)) => {
Expand Down Expand Up @@ -970,6 +936,7 @@ impl MultiApplication for LalaMusicBar {
inline_reply: String::new(),
unit: *notify.clone(),
})),
single_tone: false,
}));

// NOTE: remove the new one
Expand All @@ -990,9 +957,7 @@ impl MultiApplication for LalaMusicBar {
if !self.hidden_notification().is_empty()
&& !self.quite_mode
&& self.hiddenid.is_none()
&& !self.hiddenid_lock
{
self.hiddenid_lock = true;
commands.push(Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((300, 25)),
Expand All @@ -1005,6 +970,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::HiddenInfo,
single_tone: true,
}));
}

Expand Down Expand Up @@ -1043,6 +1009,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::Notify(Box::new(notify_info.clone())),
single_tone: false,
}));
}
if self.notifications.len() > MAX_SHOWN_NOTIFICATIONS_COUNT
Expand All @@ -1060,6 +1027,7 @@ impl MultiApplication for LalaMusicBar {
..Default::default()
},
info: LaLaInfo::HiddenInfo,
single_tone: true,
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lala_bar/src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iced::{Font, Length};
use iced_layershell::MultiApplication;
use iced_zbus_notification::{ImageInfo, NotifyUnit};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct NotifyUnitWidgetInfo {
pub to_delete: bool,
pub upper: i32,
Expand Down

0 comments on commit ffe25e1

Please sign in to comment.