Skip to content

Commit 2b8bd0d

Browse files
committed
wip: snowcap: make WlrTaskList output aware
1 parent 772c031 commit 2b8bd0d

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

snowcap/src/widget.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod input_region;
2+
pub mod output;
23
pub mod wlr_tasklist;
34

45
use iced::{Color, Theme, event::Status};

snowcap/src/widget/output.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use smithay_client_toolkit::reexports::client::protocol::wl_output::WlOutput;
2+
3+
#[derive(Default, Debug, Clone)]
4+
pub struct OutputState {
5+
pub output: Option<WlOutput>,
6+
}
7+
8+
impl OutputState {
9+
pub fn enter(&mut self, output: WlOutput) {
10+
self.output = Some(output);
11+
}
12+
13+
pub fn leave(&mut self, output: WlOutput) {
14+
if self.output == Some(output) {
15+
self.output = None;
16+
}
17+
}
18+
}
19+
20+
pub mod operation {
21+
use iced_wgpu::core::widget::Operation;
22+
use smithay_client_toolkit::reexports::client::protocol::wl_output::WlOutput;
23+
24+
pub fn enter_output(handle: WlOutput) -> impl Operation {
25+
struct EnterOutput {
26+
handle: WlOutput,
27+
}
28+
29+
impl Operation for EnterOutput {
30+
fn traverse(&mut self, operate: &mut dyn FnMut(&mut dyn Operation)) {
31+
operate(self);
32+
}
33+
34+
fn custom(
35+
&mut self,
36+
_id: Option<&iced::widget::Id>,
37+
_bounds: iced::Rectangle,
38+
state: &mut dyn std::any::Any,
39+
) {
40+
let Some(state) = state.downcast_mut::<super::OutputState>() else {
41+
return;
42+
};
43+
44+
state.enter(self.handle.clone());
45+
}
46+
}
47+
48+
EnterOutput { handle }
49+
}
50+
51+
pub fn leave_output(handle: WlOutput) -> impl Operation {
52+
struct LeaveOutput {
53+
handle: WlOutput,
54+
}
55+
56+
impl Operation for LeaveOutput {
57+
fn traverse(&mut self, operate: &mut dyn FnMut(&mut dyn Operation)) {
58+
operate(self);
59+
}
60+
61+
fn custom(
62+
&mut self,
63+
_id: Option<&iced::widget::Id>,
64+
_bounds: iced::Rectangle,
65+
state: &mut dyn std::any::Any,
66+
) {
67+
let Some(state) = state.downcast_mut::<super::OutputState>() else {
68+
return;
69+
};
70+
71+
state.leave(self.handle.clone());
72+
}
73+
}
74+
75+
LeaveOutput { handle }
76+
}
77+
}

snowcap/src/widget/wlr_tasklist.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ use smithay_client_toolkit::{
1616
},
1717
};
1818

19-
use crate::handlers::foreign_toplevel_management::{
20-
ForeignToplevelData, ForeignToplevelInfo, ToplevelState,
21-
WeakZwlrForeignToplevelManagementState, ZwlrForeignToplevelManagementState,
19+
use crate::{
20+
handlers::foreign_toplevel_management::{
21+
ForeignToplevelData, ForeignToplevelInfo, ToplevelState,
22+
WeakZwlrForeignToplevelManagementState, ZwlrForeignToplevelManagementState,
23+
},
24+
widget::output::OutputState,
2225
};
2326

2427
pub mod operation {
@@ -136,6 +139,7 @@ pub struct WlrTaskList<'a, Message, Theme = iced::Theme, Renderer = iced::Render
136139
/// Local state of the [`WlrTaskList`].
137140
#[derive(Default)]
138141
pub struct State {
142+
output_state: OutputState,
139143
toplevel_list: Vec<Weak<ZwlrForeignToplevelHandleV1>>,
140144

141145
pending_enter: Vec<(WlrTaskState, Weak<ZwlrForeignToplevelHandleV1>)>,
@@ -272,6 +276,7 @@ where
272276
) {
273277
let state = tree.state.downcast_mut::<State>();
274278

279+
operation.custom(None, layout.bounds(), &mut state.output_state);
275280
operation.custom(None, layout.bounds(), state);
276281

277282
operation.traverse(&mut |operation| {

0 commit comments

Comments
 (0)