Skip to content

Commit 39cdbb6

Browse files
feat: add subscriber for wayland (#86)
* feat: subscription finish just a demo, We need add other information into it * chore: remove unwrap in order not to panic * chore: remove all unwrap
1 parent 3194339 commit 39cdbb6

File tree

8 files changed

+1015
-4
lines changed

8 files changed

+1015
-4
lines changed

Cargo.lock

Lines changed: 13 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: 48 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, WaylandEvent};
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)]
@@ -59,6 +66,22 @@ enum WindowDirection {
5966
Bottom(Id),
6067
}
6168

69+
#[derive(Debug, Clone)]
70+
enum WayEvent {
71+
OutputInsert(OutputInfo),
72+
#[allow(unused)]
73+
Stop(String),
74+
}
75+
76+
impl From<WaylandEvent> for WayEvent {
77+
fn from(value: WaylandEvent) -> Self {
78+
match value {
79+
WaylandEvent::Stop(e) => WayEvent::Stop(e.to_string()),
80+
WaylandEvent::OutputInsert(output) => WayEvent::OutputInsert(output),
81+
}
82+
}
83+
}
84+
6285
#[to_layer_message(multi)]
6386
#[derive(Debug, Clone)]
6487
enum Message {
@@ -71,6 +94,7 @@ enum Message {
7194
TextInput(String),
7295
Direction(WindowDirection),
7396
IcedEvent(Event),
97+
Wayland(WayEvent),
7498
}
7599

76100
impl Counter {
@@ -85,11 +109,12 @@ impl Counter {
85109
}
86110

87111
impl Counter {
88-
fn new(text: &str) -> Self {
112+
fn new(text: &str, connection: Connection) -> Self {
89113
Self {
90114
value: 0,
91115
text: text.to_string(),
92116
ids: HashMap::new(),
117+
connection,
93118
}
94119
}
95120

@@ -116,6 +141,8 @@ impl Counter {
116141
iced::Subscription::batch(vec![
117142
event::listen().map(Message::IcedEvent),
118143
iced::window::close_events().map(Message::WindowClosed),
144+
iced_wayland_subscriber::listen(self.connection.clone())
145+
.map(|message| Message::Wayland(message.into())),
119146
])
120147
}
121148

@@ -155,6 +182,21 @@ impl Counter {
155182
}
156183
Command::none()
157184
}
185+
Message::Wayland(WayEvent::OutputInsert(OutputInfo { wl_output, .. })) => {
186+
let id = iced::window::Id::unique();
187+
self.ids.insert(id, WindowInfo::TopBar);
188+
Command::done(Message::NewLayerShell {
189+
settings: NewLayerShellSettings {
190+
anchor: Anchor::Left | Anchor::Right | Anchor::Top,
191+
layer: Layer::Top,
192+
exclusive_zone: Some(30),
193+
size: Some((0, 30)),
194+
output_option: OutputOption::Output(wl_output),
195+
..Default::default()
196+
},
197+
id,
198+
})
199+
}
158200
Message::IncrementPressed => {
159201
self.value += 1;
160202
Command::none()
@@ -236,6 +278,9 @@ impl Counter {
236278
.height(Length::Fill)
237279
.into();
238280
}
281+
if let Some(WindowInfo::TopBar) = self.id_info(id) {
282+
return text("hello here is topbar").into();
283+
}
239284
if let Some(WindowInfo::PopUp) = self.id_info(id) {
240285
return container(button("close PopUp").on_press(Message::Close(id)))
241286
.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)