|
| 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 | +} |
0 commit comments