Skip to content

Commit 6b2a693

Browse files
committed
feat: subscription finish
just a demo, We need add other information into it
1 parent 0f9f031 commit 6b2a693

File tree

8 files changed

+973
-4
lines changed

8 files changed

+973
-4
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"iced_layershell_macros",
77
"iced_sessionlock",
88
"iced_sessionlock_macros",
9+
"iced_wayland_subscriber",
910
"starcolorkeyboard",
1011
"sessionlockev",
1112
"waycrate_xkbkeycode",
@@ -29,7 +30,7 @@ readme = "README.md"
2930
[workspace.dependencies]
3031
layershellev = { version = "0.14.2", path = "./layershellev" }
3132
sessionlockev = { version = "0.14.2", path = "./sessionlockev" }
32-
33+
iced_wayland_subscriber = { version = "0.14.2", path = "./iced_wayland_subscriber" }
3334
iced_layershell = { version = "0.14.2", path = "./iced_layershell" }
3435
iced_exdevtools = { version = "0.14.2", path = "./iced_exdevtools" }
3536
iced_layershell_macros = { version = "0.14.2", path = "./iced_layershell_macros" }

iced_examples/counter_multi/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ iced.workspace = true
1616
iced_runtime.workspace = true
1717
iced_layershell = { workspace = true, features = ["debug"] }
1818
tracing-subscriber.workspace = true
19+
iced_wayland_subscriber.workspace = true
20+
wayland-client.workspace = true

iced_examples/counter_multi/src/main.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ use iced_layershell::reexport::{
1313
};
1414
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
1515
use iced_layershell::to_layer_message;
16+
use iced_wayland_subscriber::{OutputInfo, WaylandEvents};
17+
use wayland_client::Connection;
1618

1719
pub fn main() -> Result<(), iced_layershell::Error> {
1820
tracing_subscriber::fmt().init();
21+
let connection = Connection::connect_to_env().unwrap();
22+
let connection2 = connection.clone();
1923
daemon(
20-
|| Counter::new("hello"),
24+
move || Counter::new("hello", connection.clone()),
2125
Counter::namespace,
2226
Counter::update,
2327
Counter::view,
@@ -32,23 +36,26 @@ pub fn main() -> Result<(), iced_layershell::Error> {
3236
start_mode: StartMode::AllScreens,
3337
..Default::default()
3438
},
39+
with_connection: Some(connection2),
3540
..Default::default()
3641
})
3742
.run()
3843
}
3944

40-
#[derive(Debug, Default)]
45+
#[derive(Debug)]
4146
struct Counter {
4247
value: i32,
4348
text: String,
4449
ids: HashMap<iced::window::Id, WindowInfo>,
50+
connection: Connection,
4551
}
4652

4753
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4854
enum WindowInfo {
4955
Left,
5056
NormalWindow,
5157
PopUp,
58+
TopBar,
5259
}
5360

5461
#[derive(Debug, Clone, Copy)]
@@ -71,6 +78,7 @@ enum Message {
7178
TextInput(String),
7279
Direction(WindowDirection),
7380
IcedEvent(Event),
81+
Wayland(WaylandEvents),
7482
}
7583

7684
impl Counter {
@@ -85,11 +93,12 @@ impl Counter {
8593
}
8694

8795
impl Counter {
88-
fn new(text: &str) -> Self {
96+
fn new(text: &str, connection: Connection) -> Self {
8997
Self {
9098
value: 0,
9199
text: text.to_string(),
92100
ids: HashMap::new(),
101+
connection,
93102
}
94103
}
95104

@@ -116,6 +125,7 @@ impl Counter {
116125
iced::Subscription::batch(vec![
117126
event::listen().map(Message::IcedEvent),
118127
iced::window::close_events().map(Message::WindowClosed),
128+
iced_wayland_subscriber::listen(self.connection.clone().into()).map(Message::Wayland),
119129
])
120130
}
121131

@@ -155,6 +165,21 @@ impl Counter {
155165
}
156166
Command::none()
157167
}
168+
Message::Wayland(WaylandEvents::OutputInsert(OutputInfo { wl_output, .. })) => {
169+
let id = iced::window::Id::unique();
170+
self.ids.insert(id, WindowInfo::TopBar);
171+
Command::done(Message::NewLayerShell {
172+
settings: NewLayerShellSettings {
173+
anchor: Anchor::Left | Anchor::Right | Anchor::Top,
174+
layer: Layer::Top,
175+
exclusive_zone: Some(30),
176+
size: Some((0, 30)),
177+
output_option: OutputOption::Output(wl_output),
178+
..Default::default()
179+
},
180+
id,
181+
})
182+
}
158183
Message::IncrementPressed => {
159184
self.value += 1;
160185
Command::none()
@@ -236,6 +261,9 @@ impl Counter {
236261
.height(Length::Fill)
237262
.into();
238263
}
264+
if let Some(WindowInfo::TopBar) = self.id_info(id) {
265+
return text("hello here is topbar").into();
266+
}
239267
if let Some(WindowInfo::PopUp) = self.id_info(id) {
240268
return container(button("close PopUp").on_press(Message::Close(id)))
241269
.center_x(Length::Fill)

iced_wayland_subscriber/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)