Skip to content

Commit

Permalink
Use WeakOutput instead of Option<WeakOutput>
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 authored and Drakulix committed Nov 18, 2024
1 parent 1b96256 commit 8d7f491
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/wayland/protocols/output_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl OutputPowerState {
let mut output_powers = mem::take(&mut state.output_power_state().output_powers);
for (output_power, old_mode) in output_powers.iter_mut() {
let data = output_power.data::<OutputPowerData>().unwrap();
if let Some(output) = data.output.as_ref().and_then(|o| o.upgrade()) {
if let Some(output) = data.output.upgrade() {
if let Some(on) = state.get_dpms(&output) {
let mode = output_power_mode(on);
if mode != *old_mode {
Expand All @@ -77,7 +77,7 @@ pub struct OutputPowerManagerGlobalData {
}

pub struct OutputPowerData {
output: Option<WeakOutput>,
output: WeakOutput,
}

impl<D> GlobalDispatch<ZwlrOutputPowerManagerV1, OutputPowerManagerGlobalData, D>
Expand Down Expand Up @@ -126,7 +126,7 @@ where
let output_power = data_init.init(
id,
OutputPowerData {
output: output.as_ref().map(|o| o.downgrade()),
output: output.as_ref().map(|o| o.downgrade()).unwrap_or_default(),
},
);
if let Some(on) = output.as_ref().and_then(|o| state.get_dpms(o)) {
Expand Down Expand Up @@ -161,7 +161,7 @@ where
) {
match request {
zwlr_output_power_v1::Request::SetMode { mode } => {
if let Some(output) = data.output.as_ref().and_then(|o| o.upgrade()) {
if let Some(output) = data.output.upgrade() {
let on = match mode {
WEnum::Value(zwlr_output_power_v1::Mode::On) => true,
WEnum::Value(zwlr_output_power_v1::Mode::Off) => false,
Expand All @@ -176,11 +176,9 @@ where
state.output_power_state().output_powers.iter_mut()
{
let data = output_power.data::<OutputPowerData>().unwrap();
if let Some(o) = data.output.as_ref() {
if o == &output && mode != *old_mode {
output_power.mode(mode);
*old_mode = mode;
}
if data.output == output && mode != *old_mode {
output_power.mode(mode);
*old_mode = mode;
}
}
} else {
Expand Down

0 comments on commit 8d7f491

Please sign in to comment.