Skip to content

Commit

Permalink
Force all enum variants to be valid.
Browse files Browse the repository at this point in the history
Until Smithay/wayland-rs#764 is fixed, this is the only solution that works.
  • Loading branch information
andriyDev committed Oct 21, 2024
1 parent 1b8375b commit 5720114
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub struct HeadIdentity {
pub struct HeadConfiguration {
pub current_mode: ObjectId,
pub position: (u32, u32),
pub transform: WEnum<Transform>,
pub transform: Transform,
pub scale: f64,
pub adaptive_sync: Option<WEnum<AdaptiveSyncState>>,
pub adaptive_sync: Option<AdaptiveSyncState>,
}

impl Head {
Expand Down
60 changes: 35 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -49,9 +49,9 @@ struct AppData {
struct SavedConfiguration {
mode: Mode,
position: (u32, u32),
transform: WEnum<Transform>,
transform: Transform,
scale: f64,
adaptive_sync: Option<WEnum<AdaptiveSyncState>>,
adaptive_sync: Option<AdaptiveSyncState>,
}

impl SavedConfiguration {
Expand Down Expand Up @@ -366,18 +366,23 @@ impl Dispatch<ZwlrOutputHeadV1, ()> 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);
Expand All @@ -390,18 +395,23 @@ impl Dispatch<ZwlrOutputHeadV1, ()> 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);
}
}
},
}
_ => {}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub struct PartialHead {
pub modes: Vec<ObjectId>,
pub current_mode: Option<ObjectId>,
pub position: Option<(u32, u32)>,
pub transform: Option<WEnum<Transform>>,
pub transform: Option<Transform>,
pub scale: Option<f64>,
pub adaptive_sync: Option<WEnum<AdaptiveSyncState>>,
pub adaptive_sync: Option<AdaptiveSyncState>,
}

pub struct PartialHeadState {
Expand Down

0 comments on commit 5720114

Please sign in to comment.