From 57201140f2df4ea156fb99167cf18fa44c194f29 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sun, 20 Oct 2024 23:54:08 -0700 Subject: [PATCH] Force all enum variants to be valid. Until https://github.com/Smithay/wayland-rs/issues/764 is fixed, this is the only solution that works. --- src/complete.rs | 4 ++-- src/main.rs | 60 ++++++++++++++++++++++++++++--------------------- src/partial.rs | 4 ++-- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/complete.rs b/src/complete.rs index 620f4b1..f143322 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -34,9 +34,9 @@ pub struct HeadIdentity { pub struct HeadConfiguration { pub current_mode: ObjectId, pub position: (u32, u32), - pub transform: WEnum, + pub transform: Transform, pub scale: f64, - pub adaptive_sync: Option>, + pub adaptive_sync: Option, } impl Head { diff --git a/src/main.rs b/src/main.rs index 8239704..77927cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use wayland_client::{ wl_output::Transform, wl_registry::{self, WlRegistry}, }, - Connection, Dispatch, Proxy, WEnum, + Connection, Dispatch, Proxy, }; use wayland_protocols_wlr::output_management::v1::client::{ zwlr_output_head_v1::{self, AdaptiveSyncState, ZwlrOutputHeadV1}, @@ -49,9 +49,9 @@ struct AppData { struct SavedConfiguration { mode: Mode, position: (u32, u32), - transform: WEnum, + transform: Transform, scale: f64, - adaptive_sync: Option>, + adaptive_sync: Option, } impl SavedConfiguration { @@ -366,18 +366,23 @@ impl Dispatch for AppData { configuration.position = (x as u32, y as u32); } }, - zwlr_output_head_v1::Event::Transform { transform } => match head_state { - HeadState::Partial(partial_head) => { - partial_head.transform = Some(transform); - } - HeadState::Full(head) => { - let configuration = head - .configuration - .as_mut() - .expect("Received a Transform event while head is disabled"); - configuration.transform = transform; + zwlr_output_head_v1::Event::Transform { transform } => { + let transform = transform + .into_result() + .expect("Transform is an invalid variant"); + match head_state { + HeadState::Partial(partial_head) => { + partial_head.transform = Some(transform); + } + HeadState::Full(head) => { + let configuration = head + .configuration + .as_mut() + .expect("Received a Transform event while head is disabled"); + configuration.transform = transform; + } } - }, + } zwlr_output_head_v1::Event::Scale { scale } => match head_state { HeadState::Partial(partial_head) => { partial_head.scale = Some(scale); @@ -390,18 +395,23 @@ impl Dispatch for AppData { configuration.scale = scale; } }, - zwlr_output_head_v1::Event::AdaptiveSync { state } => match head_state { - HeadState::Partial(partial_head) => { - partial_head.adaptive_sync = Some(state); - } - HeadState::Full(head) => { - let configuration = head - .configuration - .as_mut() - .expect("Received a AdaptiveSync event while head is disabled"); - configuration.adaptive_sync = Some(state); + zwlr_output_head_v1::Event::AdaptiveSync { state } => { + let state = state + .into_result() + .expect("Adaptive sync is an invalid variant"); + match head_state { + HeadState::Partial(partial_head) => { + partial_head.adaptive_sync = Some(state); + } + HeadState::Full(head) => { + let configuration = head + .configuration + .as_mut() + .expect("Received a AdaptiveSync event while head is disabled"); + configuration.adaptive_sync = Some(state); + } } - }, + } _ => {} } } diff --git a/src/partial.rs b/src/partial.rs index 2bf25d0..31c1bdf 100644 --- a/src/partial.rs +++ b/src/partial.rs @@ -18,9 +18,9 @@ pub struct PartialHead { pub modes: Vec, pub current_mode: Option, pub position: Option<(u32, u32)>, - pub transform: Option>, + pub transform: Option, pub scale: Option, - pub adaptive_sync: Option>, + pub adaptive_sync: Option, } pub struct PartialHeadState {