Skip to content

Commit

Permalink
feat: support single_tone layershell
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Nov 28, 2024
1 parent cd6ebc9 commit c41423c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions iced_examples/counter_muti/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl MultiApplication for Counter {
..Default::default()
},
info: WindowInfo::Left,
single_tone: true,
}),
Message::NewWindowRight => Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
Expand All @@ -197,6 +198,7 @@ impl MultiApplication for Counter {
..Default::default()
},
info: WindowInfo::Right,
single_tone: true,
}),
Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))),
_ => unreachable!(),
Expand Down
1 change: 1 addition & 0 deletions iced_examples/zbus_invoked_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl TryInto<LaLaShellIdAction> for Message {
..Default::default()
},
(),
false,
)),
)),
_ => Err(self),
Expand Down
2 changes: 1 addition & 1 deletion iced_layershell/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum LayershellCustomActionsWithInfo<INFO: Clone> {
time: u32,
key: u32,
},
NewLayerShell((NewLayerShellSettings, INFO)),
NewLayerShell((NewLayerShellSettings, INFO, bool)),
NewPopUp((IcedNewPopupSettings, INFO)),
NewMenu((IcedNewMenuSettings, INFO)),
/// is same with WindowAction::Close(id)
Expand Down
2 changes: 1 addition & 1 deletion iced_layershell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub trait MultiApplication: Sized {
fn run(settings: Settings<Self::Flags>) -> Result<(), error::Error>
where
Self: 'static,
<Self as MultiApplication>::WindowInfo: Clone,
<Self as MultiApplication>::WindowInfo: Clone + PartialEq,
Self::Message: 'static
+ TryInto<LayershellCustomActionsWithIdAndInfo<Self::WindowInfo>, Error = Self::Message>,
{
Expand Down
23 changes: 19 additions & 4 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ where
E: Executor + 'static,
C: Compositor<Renderer = A::Renderer> + 'static,
A::Theme: DefaultStyle,
<A as Application>::WindowInfo: Clone,
<A as Application>::WindowInfo: Clone + PartialEq,
A::Message:
'static + TryInto<LayershellCustomActionsWithIdAndInfo<A::WindowInfo>, Error = A::Message>,
{
Expand Down Expand Up @@ -388,7 +388,7 @@ where
)
.ok();
}
LayershellCustomActionsWithInfo::NewLayerShell((settings, info)) => {
LayershellCustomActionsWithInfo::NewLayerShell((settings, info, _)) => {
ev.append_return_data(ReturnData::NewLayerShell((
settings,
Some(info),
Expand Down Expand Up @@ -481,7 +481,7 @@ async fn run_instance<A, E, C>(
E: Executor + 'static,
C: Compositor<Renderer = A::Renderer> + 'static,
A::Theme: DefaultStyle,
A::WindowInfo: Clone,
A::WindowInfo: Clone + PartialEq,
A::Message:
'static + TryInto<LayershellCustomActionsWithIdAndInfo<A::WindowInfo>, Error = A::Message>,
{
Expand Down Expand Up @@ -512,6 +512,8 @@ async fn run_instance<A, E, C>(
let mut should_exit = false;
let mut messages = Vec::new();

let mut singleton_layers = vec![];

while let Some(event) = event_receiver.next().await {
match event {
MultiWindowIcedLayerEvent(
Expand Down Expand Up @@ -709,6 +711,7 @@ async fn run_instance<A, E, C>(
&mut messages,
&mut clipboard,
&mut custom_actions,
&mut singleton_layers,
&mut should_exit,
&mut debug,
&mut window_manager,
Expand Down Expand Up @@ -830,6 +833,11 @@ async fn run_instance<A, E, C>(
.drain()
.map(|(id, ui)| (id, ui.into_cache()))
.collect();
if let Some(info) = application.id_info(id) {
if let Some(index) = singleton_layers.iter().position(|layer| *layer == info) {
singleton_layers.remove(index);
}
}
application.remove_id(id);
window_manager.remove(id);
cached_interfaces.remove(&id);
Expand Down Expand Up @@ -970,6 +978,7 @@ pub(crate) fn run_action<A, C>(
messages: &mut Vec<A::Message>,
clipboard: &mut LayerShellClipboard,
custom_actions: &mut Vec<LayerShellAction<A::WindowInfo>>,
singleton_layers: &mut Vec<A::WindowInfo>,
should_exit: &mut bool,
debug: &mut Debug,
window_manager: &mut WindowManager<A, C>,
Expand All @@ -980,7 +989,7 @@ pub(crate) fn run_action<A, C>(
A::Theme: DefaultStyle,
A::Message:
'static + TryInto<LayershellCustomActionsWithIdAndInfo<A::WindowInfo>, Error = A::Message>,
A::WindowInfo: Clone + 'static,
A::WindowInfo: Clone + 'static + PartialEq,
{
use iced_core::widget::operation;
use iced_runtime::clipboard;
Expand All @@ -991,6 +1000,12 @@ pub(crate) fn run_action<A, C>(
Action::Output(stream) => match stream.try_into() {
Ok(action) => {
let action: LayershellCustomActionsWithIdAndInfo<A::WindowInfo> = action;
if let LayershellCustomActionsWithInfo::NewLayerShell((_, info, true)) = &action.1 {
if singleton_layers.contains(info) {
return;
}
singleton_layers.push(info.clone());
}
let option_id = if let LayershellCustomActionsWithInfo::RemoveWindow(id) = action.1
{
window_manager.get_layer_id(id)
Expand Down
4 changes: 2 additions & 2 deletions iced_layershell_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
time: u32,
key: u32,
},
NewLayerShell { settings: iced_layershell::reexport::NewLayerShellSettings, info: #info },
NewLayerShell { settings: iced_layershell::reexport::NewLayerShellSettings, info: #info, single_tone: bool },
NewPopUp { settings: iced_layershell::actions::IcedNewPopupSettings, info: #info },
NewMenu { settings: iced_layershell::actions::IcedNewMenuSettings, info: #info },
RemoveWindow(iced::window::Id),
Expand All @@ -69,7 +69,7 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
None,
InnerLayerAction::VirtualKeyboardPressed { time, key })
),
Self::NewLayerShell {settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewLayerShell((settings, info)))),
Self::NewLayerShell {settings, info, single_tone } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewLayerShell((settings, info, single_tone)))),
Self::NewPopUp { settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewPopUp((settings, info)))),
Self::NewMenu { settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewMenu((settings, info)))),
Self::RemoveWindow(id) => Ok(InnerLayerActionId::new(None, InnerLayerAction::RemoveWindow(id))),
Expand Down

0 comments on commit c41423c

Please sign in to comment.