Skip to content

Commit 80f0e61

Browse files
committed
feat: seems finished
1 parent 6a631c1 commit 80f0e61

File tree

4 files changed

+77
-37
lines changed

4 files changed

+77
-37
lines changed

iced_examples/counter_muti/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ impl MultiApplication for Counter {
212212
Command::done(Message::NewLayerShell {
213213
settings: NewLayerShellSettings {
214214
size: Some((0, 20)),
215-
exclusive_zone: None,
215+
exclusive_zone: Some(20),
216216
anchor: Anchor::Top | Anchor::Right | Anchor::Left,
217217
layer: Layer::Top,
218218
margin: None,
219-
keyboard_interactivity: KeyboardInteractivity::Exclusive,
219+
keyboard_interactivity: KeyboardInteractivity::None,
220220
output_setting: LayerOutputSetting::ChosenOutput(output),
221+
..Default::default()
221222
},
222223
info: WindowInfo::TopBar,
223224
})
@@ -234,7 +235,7 @@ impl MultiApplication for Counter {
234235
return button("close right").on_press(Message::Close(id)).into();
235236
}
236237
if let Some(WindowInfo::TopBar) = self.id_info(id) {
237-
return text("topbar").into();
238+
return text("hello here is topbar").into();
238239
}
239240
if let Some(WindowInfo::PopUp) = self.id_info(id) {
240241
return container(button("close PopUp").on_press(Message::Close(id)))

iced_wayland_subscriber/src/lib.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
use futures::SinkExt;
22
use wayland_client::{
33
delegate_noop,
4+
globals::{registry_queue_init, GlobalListContents},
45
protocol::{
56
wl_output::{self, WlOutput},
67
wl_registry,
78
},
89
Connection, Dispatch, Proxy,
910
};
1011

11-
use wayland_protocols::xdg::xdg_output::zv1::client::zxdg_output_manager_v1::ZxdgOutputManagerV1;
12+
use wayland_protocols::xdg::xdg_output::zv1::client::{
13+
zxdg_output_manager_v1::ZxdgOutputManagerV1, zxdg_output_v1,
14+
};
15+
16+
#[derive(Debug)]
17+
struct BaseState;
18+
19+
// so interesting, it is just need to invoke once, it just used to get the globals
20+
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for BaseState {
21+
fn event(
22+
_state: &mut Self,
23+
_proxy: &wl_registry::WlRegistry,
24+
_event: <wl_registry::WlRegistry as wayland_client::Proxy>::Event,
25+
_data: &GlobalListContents,
26+
_conn: &Connection,
27+
_qh: &wayland_client::QueueHandle<Self>,
28+
) {
29+
}
30+
}
1231

1332
#[derive(Debug, Default)]
1433
struct SubscribeState {
1534
events: Vec<WaylandEvents>,
35+
padding_wloutputs: Vec<wl_output::WlOutput>,
1636
}
1737

1838
impl Dispatch<wl_registry::WlRegistry, ()> for SubscribeState {
@@ -32,35 +52,65 @@ impl Dispatch<wl_registry::WlRegistry, ()> for SubscribeState {
3252
} => {
3353
if interface == wl_output::WlOutput::interface().name {
3454
let output = proxy.bind::<wl_output::WlOutput, _, _>(name, version, qh, ());
35-
state.events.push(WaylandEvents::OutputInsert(output));
55+
state.padding_wloutputs.push(output);
3656
}
3757
}
3858
wl_registry::Event::GlobalRemove { .. } => {}
3959
_ => unreachable!(),
4060
}
4161
}
4262
}
63+
impl Dispatch<zxdg_output_v1::ZxdgOutputV1, ()> for SubscribeState {
64+
fn event(
65+
state: &mut Self,
66+
_proxy: &zxdg_output_v1::ZxdgOutputV1,
67+
event: <zxdg_output_v1::ZxdgOutputV1 as Proxy>::Event,
68+
_data: &(),
69+
_conn: &Connection,
70+
_qhandle: &wayland_client::QueueHandle<Self>,
71+
) {
72+
if let zxdg_output_v1::Event::Name { name } = event {
73+
state.events.push(WaylandEvents::OutputInsert(name));
74+
}
75+
}
76+
}
4377
delegate_noop!(SubscribeState: ignore WlOutput); // output is need to place layer_shell, although here
4478
delegate_noop!(SubscribeState: ignore ZxdgOutputManagerV1);
4579

4680
#[derive(Debug, Clone)]
4781
pub enum WaylandEvents {
48-
OutputInsert(wl_output::WlOutput),
82+
OutputInsert(String),
4983
}
5084

5185
pub fn listen() -> iced::Subscription<WaylandEvents> {
5286
iced::Subscription::run(|| {
5387
iced::stream::channel(100, |mut output| async move {
5488
let connection = Connection::connect_to_env().unwrap();
89+
let (globals, _) = registry_queue_init::<BaseState>(&connection).unwrap(); // We just need the
90+
// global, the
91+
// event_queue is
92+
// not needed, we
93+
// do not need
94+
// BaseState after
95+
5596
let mut state = SubscribeState::default();
5697

5798
let mut event_queue = connection.new_event_queue::<SubscribeState>();
5899
let qhandle = event_queue.handle();
59100
let display = connection.display();
60101

102+
let xdg_output_manager = globals
103+
.bind::<ZxdgOutputManagerV1, _, _>(&qhandle, 1..=3, ())
104+
.unwrap(); // b
61105
display.get_registry(&qhandle, ());
62106
loop {
63107
event_queue.blocking_dispatch(&mut state).unwrap();
108+
let mut current_outputs = vec![];
109+
std::mem::swap(&mut current_outputs, &mut state.padding_wloutputs);
110+
for output in current_outputs {
111+
xdg_output_manager.get_xdg_output(&output, &qhandle, ());
112+
}
113+
64114
let mut current_events = vec![];
65115
std::mem::swap(&mut current_events, &mut state.events);
66116
for event in current_events {

layershellev/src/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use wayland_client::{
88
protocol::{
99
wl_buffer::WlBuffer,
1010
wl_compositor::WlCompositor,
11-
wl_output::{self, WlOutput},
11+
wl_output::WlOutput,
1212
wl_pointer::{self, ButtonState, WlPointer},
1313
wl_shm::WlShm,
1414
},
@@ -71,7 +71,7 @@ pub enum LayerEvent<'a, T, Message> {
7171
/// This allow the new layershell can be selected on target output
7272
#[derive(Debug, Clone, PartialEq, Eq)]
7373
pub enum LayerOutputSetting {
74-
ChosenOutput(wl_output::WlOutput),
74+
ChosenOutput(String),
7575
FollowLastOutput,
7676
None,
7777
}

layershellev/src/lib.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,55 +1663,41 @@ impl<T> Dispatch<zxdg_output_v1::ZxdgOutputV1, ()> for WindowState<T> {
16631663
_conn: &Connection,
16641664
_qhandle: &QueueHandle<Self>,
16651665
) {
1666-
if state.is_with_target() && !state.init_finished {
1667-
let Some((_, xdg_info)) = state
1668-
.xdg_info_cache
1669-
.iter_mut()
1670-
.find(|(_, info)| info.zxdgoutput == *proxy)
1671-
else {
1672-
return;
1673-
};
1674-
match event {
1675-
zxdg_output_v1::Event::LogicalSize { width, height } => {
1676-
xdg_info.logical_size = (width, height);
1677-
}
1678-
zxdg_output_v1::Event::LogicalPosition { x, y } => {
1679-
xdg_info.position = (x, y);
1680-
}
1681-
zxdg_output_v1::Event::Name { name } => {
1682-
xdg_info.name = name;
1683-
}
1684-
zxdg_output_v1::Event::Description { description } => {
1685-
xdg_info.description = description;
1686-
}
1687-
_ => {}
1688-
};
1689-
return;
1690-
}
16911666
let Some(index) = state.units.iter().position(|info| {
16921667
info.zxdgoutput
16931668
.as_ref()
16941669
.is_some_and(|zxdgoutput| zxdgoutput.zxdgoutput == *proxy)
16951670
}) else {
16961671
return;
16971672
};
1673+
let Some((_, xdg_info_cached)) = state
1674+
.xdg_info_cache
1675+
.iter_mut()
1676+
.find(|(_, info)| info.zxdgoutput == *proxy)
1677+
else {
1678+
return;
1679+
};
16981680
let info = &mut state.units[index];
16991681
let xdg_info = info.zxdgoutput.as_mut().unwrap();
17001682
let change_type = match event {
17011683
zxdg_output_v1::Event::LogicalSize { width, height } => {
17021684
xdg_info.logical_size = (width, height);
1685+
xdg_info_cached.logical_size = (width, height);
17031686
XdgInfoChangedType::Size
17041687
}
17051688
zxdg_output_v1::Event::LogicalPosition { x, y } => {
17061689
xdg_info.position = (x, y);
1690+
xdg_info_cached.position = (x, y);
17071691
XdgInfoChangedType::Position
17081692
}
17091693
zxdg_output_v1::Event::Name { name } => {
1710-
xdg_info.name = name;
1694+
xdg_info.name = name.clone();
1695+
xdg_info_cached.name = name;
17111696
XdgInfoChangedType::Name
17121697
}
17131698
zxdg_output_v1::Event::Description { description } => {
1714-
xdg_info.description = description;
1699+
xdg_info.description = description.clone();
1700+
xdg_info_cached.description = description;
17151701
XdgInfoChangedType::Description
17161702
}
17171703
_ => {
@@ -1860,7 +1846,6 @@ impl<T: 'static> WindowState<T> {
18601846
// clear binded_output_name, it is not used anymore
18611847
}
18621848

1863-
self.xdg_info_cache.clear();
18641849
let binded_output = output.as_ref().map(|(output, _)| output);
18651850
let binded_xdginfo = output.as_ref().map(|(_, xdginfo)| xdginfo);
18661851

@@ -2451,7 +2436,11 @@ impl<T: 'static> WindowState<T> {
24512436
events::LayerOutputSetting::FollowLastOutput => {
24522437
self.last_wloutput.clone()
24532438
}
2454-
events::LayerOutputSetting::ChosenOutput(output) => Some(output),
2439+
events::LayerOutputSetting::ChosenOutput(output) => self
2440+
.xdg_info_cache
2441+
.iter()
2442+
.find(|(_, xdg_output_info)| xdg_output_info.name == output)
2443+
.map(|(output, _)| output.clone()),
24552444
};
24562445

24572446
let wl_surface = wmcompositer.create_surface(&qh, ()); // and create a surface. if two or more,

0 commit comments

Comments
 (0)