Skip to content

Commit 009f83e

Browse files
committed
feat: seems finished
1 parent 5436276 commit 009f83e

File tree

4 files changed

+76
-37
lines changed

4 files changed

+76
-37
lines changed

iced_examples/counter_muti/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ impl MultiApplication for Counter {
210210
Command::done(Message::NewLayerShell {
211211
settings: NewLayerShellSettings {
212212
size: Some((0, 20)),
213-
exclusive_zone: None,
213+
exclusive_zone: Some(20),
214214
anchor: Anchor::Top | Anchor::Right | Anchor::Left,
215215
layer: Layer::Top,
216216
margin: None,
217-
keyboard_interactivity: KeyboardInteractivity::Exclusive,
217+
keyboard_interactivity: KeyboardInteractivity::None,
218218
output_setting: LayerOutputSetting::ChosenOutput(output),
219219
},
220220
info: WindowInfo::TopBar,
@@ -232,7 +232,7 @@ impl MultiApplication for Counter {
232232
return button("close right").on_press(Message::Close(id)).into();
233233
}
234234
if let Some(WindowInfo::TopBar) = self.id_info(id) {
235-
return text("topbar").into();
235+
return text("hello here is topbar").into();
236236
}
237237
if let Some(WindowInfo::PopUp) = self.id_info(id) {
238238
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
@@ -1656,55 +1656,41 @@ impl<T> Dispatch<zxdg_output_v1::ZxdgOutputV1, ()> for WindowState<T> {
16561656
_conn: &Connection,
16571657
_qhandle: &QueueHandle<Self>,
16581658
) {
1659-
if state.is_with_target() && !state.init_finished {
1660-
let Some((_, xdg_info)) = state
1661-
.xdg_info_cache
1662-
.iter_mut()
1663-
.find(|(_, info)| info.zxdgoutput == *proxy)
1664-
else {
1665-
return;
1666-
};
1667-
match event {
1668-
zxdg_output_v1::Event::LogicalSize { width, height } => {
1669-
xdg_info.logical_size = (width, height);
1670-
}
1671-
zxdg_output_v1::Event::LogicalPosition { x, y } => {
1672-
xdg_info.position = (x, y);
1673-
}
1674-
zxdg_output_v1::Event::Name { name } => {
1675-
xdg_info.name = name;
1676-
}
1677-
zxdg_output_v1::Event::Description { description } => {
1678-
xdg_info.description = description;
1679-
}
1680-
_ => {}
1681-
};
1682-
return;
1683-
}
16841659
let Some(index) = state.units.iter().position(|info| {
16851660
info.zxdgoutput
16861661
.as_ref()
16871662
.is_some_and(|zxdgoutput| zxdgoutput.zxdgoutput == *proxy)
16881663
}) else {
16891664
return;
16901665
};
1666+
let Some((_, xdg_info_cached)) = state
1667+
.xdg_info_cache
1668+
.iter_mut()
1669+
.find(|(_, info)| info.zxdgoutput == *proxy)
1670+
else {
1671+
return;
1672+
};
16911673
let info = &mut state.units[index];
16921674
let xdg_info = info.zxdgoutput.as_mut().unwrap();
16931675
let change_type = match event {
16941676
zxdg_output_v1::Event::LogicalSize { width, height } => {
16951677
xdg_info.logical_size = (width, height);
1678+
xdg_info_cached.logical_size = (width, height);
16961679
XdgInfoChangedType::Size
16971680
}
16981681
zxdg_output_v1::Event::LogicalPosition { x, y } => {
16991682
xdg_info.position = (x, y);
1683+
xdg_info_cached.position = (x, y);
17001684
XdgInfoChangedType::Position
17011685
}
17021686
zxdg_output_v1::Event::Name { name } => {
1703-
xdg_info.name = name;
1687+
xdg_info.name = name.clone();
1688+
xdg_info_cached.name = name;
17041689
XdgInfoChangedType::Name
17051690
}
17061691
zxdg_output_v1::Event::Description { description } => {
1707-
xdg_info.description = description;
1692+
xdg_info.description = description.clone();
1693+
xdg_info_cached.description = description;
17081694
XdgInfoChangedType::Description
17091695
}
17101696
_ => {
@@ -1849,7 +1835,6 @@ impl<T: 'static> WindowState<T> {
18491835
// clear binded_output_name, it is not used anymore
18501836
}
18511837

1852-
self.xdg_info_cache.clear();
18531838
let binded_output = output.as_ref().map(|(output, _)| output);
18541839
let binded_xdginfo = output.as_ref().map(|(_, xdginfo)| xdginfo);
18551840

@@ -2429,7 +2414,11 @@ impl<T: 'static> WindowState<T> {
24292414
events::LayerOutputSetting::FollowLastOutput => {
24302415
self.last_wloutput.clone()
24312416
}
2432-
events::LayerOutputSetting::ChosenOutput(output) => Some(output),
2417+
events::LayerOutputSetting::ChosenOutput(output) => self
2418+
.xdg_info_cache
2419+
.iter()
2420+
.find(|(_, xdg_output_info)| xdg_output_info.name == output)
2421+
.map(|(output, _)| output.clone()),
24332422
};
24342423

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

0 commit comments

Comments
 (0)