wayland_protocols_async/zwlr_output_management_v1/output/
output_mode.rs1use wayland_client::{Connection, Dispatch, Proxy, QueueHandle};
2use wayland_protocols_wlr::output_management::v1::client::zwlr_output_mode_v1::{ZwlrOutputModeV1, self};
3
4use crate::zwlr_output_management_v1::handler::{OutputManagementEvent, OutputManagementState};
5
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct WlOutputMode {
8 pub width: i32,
9 pub height: i32,
10 pub refresh: i32,
11 pub preferred: bool,
12 pub wlr_mode: ZwlrOutputModeV1,
13}
14
15impl WlOutputMode {
16 pub fn new(wlr_mode: ZwlrOutputModeV1) -> Self {
17 Self {
18 width: 0,
19 height: 0,
20 refresh: 0,
21 preferred: false,
22 wlr_mode,
23 }
24 }
25}
26
27impl Dispatch<ZwlrOutputModeV1, ()> for OutputManagementState {
28 fn event(
29 state: &mut Self,
30 mode: &ZwlrOutputModeV1,
31 event: <ZwlrOutputModeV1 as Proxy>::Event,
32 _data: &(),
33 _conn: &Connection,
34 _handle: &QueueHandle<Self>,
35 ) {
36 let output_mode = state
37 .output_modes
38 .entry(mode.id())
39 .or_insert_with(|| WlOutputMode::new(mode.clone()));
40
41 match event {
42 zwlr_output_mode_v1::Event::Size { width, height } => {
43 output_mode.width = width;
44 output_mode.height = height;
45 state.dispatch_event(OutputManagementEvent::ModeSize { height, width });
46 },
47 zwlr_output_mode_v1::Event::Refresh { refresh } => {
48 output_mode.refresh = refresh;
49 state.dispatch_event(OutputManagementEvent::ModeRefresh { refresh });
50
51 },
52 zwlr_output_mode_v1::Event::Preferred => {
53 output_mode.preferred = true;
54 state.dispatch_event(OutputManagementEvent::ModePreferred);
55 },
56 zwlr_output_mode_v1::Event::Finished => {
57 mode.release();
58 let _ = state.remove_mode(&mode.id());
59 state.dispatch_event(OutputManagementEvent::ModeFinished);
60 },
61 _ => {}
62 }
63 }
64}