Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove the usage of windowinfo #103

Merged
merged 7 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions iced_examples/application_launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use applications::{all_apps, App};
use iced::widget::{column, scrollable, text_input};
use iced::{event, Element, Event, Length, Task as Command, Theme};
mod applications;
use iced_layershell::actions::LayershellCustomActionsWithInfo;
use iced_layershell::actions::LayershellCustomActions;
use iced_layershell::reexport::{Anchor, KeyboardInteractivity};
use iced_layershell::settings::{LayerShellSettings, Settings};
use iced_layershell::Application;
Expand All @@ -27,9 +27,9 @@ fn main() -> Result<(), iced_layershell::Error> {
Ok(())
}

impl TryInto<LayershellCustomActionsWithInfo<()>> for Message {
impl TryInto<LayershellCustomActions> for Message {
type Error = Self;
fn try_into(self) -> Result<LayershellCustomActionsWithInfo<()>, Self::Error> {
fn try_into(self) -> Result<LayershellCustomActions, Self::Error> {
Err(self)
}
}
Expand Down
84 changes: 40 additions & 44 deletions iced_examples/counter_mulit_pattern/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ use iced_runtime::{task, Action};
use iced_layershell::build_pattern::{daemon, MainSettings};
use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings};
use iced_layershell::settings::{LayerShellSettings, StartMode};
use iced_layershell::{to_layer_message, WindowInfoMarker};
use iced_layershell::to_layer_message;

pub fn main() -> Result<(), iced_layershell::Error> {
tracing_subscriber::fmt().init();
daemon(
Counter::namespace,
Counter::update,
Counter::view,
Counter::id_info,
Counter::set_id_info,
Counter::remove_id,
)
.subscription(Counter::subscription)
Expand All @@ -43,15 +41,11 @@ struct Counter {
ids: HashMap<iced::window::Id, WindowInfo>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, WindowInfoMarker)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum WindowInfo {
#[singleton]
Left,
#[singleton]
Right,
PopUp,
#[main]
Main,
}

#[derive(Debug, Clone, Copy)]
Expand All @@ -62,7 +56,7 @@ enum WindowDirection {
Bottom(Id),
}

#[to_layer_message(multi, info_name = "WindowInfo")]
#[to_layer_message(multi)]
#[derive(Debug, Clone)]
enum Message {
IncrementPressed,
Expand Down Expand Up @@ -102,14 +96,6 @@ impl Counter {
self.ids.get(&id).cloned()
}

fn set_id_info(&mut self, id: iced::window::Id, info: WindowInfo) {
if let WindowInfo::Main = info {
println!("it is main window: {id}");
return;
}
self.ids.insert(id, info);
}

fn remove_id(&mut self, id: iced::window::Id) {
self.ids.remove(&id);
}
Expand Down Expand Up @@ -140,12 +126,14 @@ impl Counter {
}
}
Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Right)) => {
let id = iced::window::Id::unique();
self.ids.insert(id, WindowInfo::PopUp);
return Command::done(Message::NewMenu {
settings: IcedNewMenuSettings {
size: (100, 100),
direction: MenuDirection::Up,
},
info: WindowInfo::PopUp,
id,
});
}
_ => {}
Expand Down Expand Up @@ -186,32 +174,40 @@ impl Counter {
size: (0, 400),
}),
},
Message::NewWindowLeft => Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((100, 100)),
exclusive_zone: None,
anchor: Anchor::Left | Anchor::Bottom,
layer: Layer::Top,
margin: None,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
..Default::default()
},
info: WindowInfo::Left,
}),
Message::NewWindowRight => Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((100, 100)),
exclusive_zone: None,
anchor: Anchor::Right | Anchor::Bottom,
layer: Layer::Top,
margin: None,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
..Default::default()
},
info: WindowInfo::Right,
}),
Message::NewWindowLeft => {
let id = iced::window::Id::unique();
self.ids.insert(id, WindowInfo::Left);
Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((100, 100)),
exclusive_zone: None,
anchor: Anchor::Left | Anchor::Bottom,
layer: Layer::Top,
margin: None,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
..Default::default()
},
id,
})
}
Message::NewWindowRight => {
let id = iced::window::Id::unique();
self.ids.insert(id, WindowInfo::Right);
Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((100, 100)),
exclusive_zone: None,
anchor: Anchor::Right | Anchor::Bottom,
layer: Layer::Top,
margin: None,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
..Default::default()
},
id,
})
}
Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))),
_ => unreachable!(),
}
Expand Down
Loading
Loading