Skip to content

Commit

Permalink
Use WeakOutput in OutputUserData
Browse files Browse the repository at this point in the history
There is no need for this to hold a strong reference to the `Output`.

Presumably `WlOutputData` is freed when the global is removed, so it is
correct to hold a strong reference there.
  • Loading branch information
ids1024 authored and Drakulix committed Nov 13, 2024
1 parent 19f1bcb commit ace2e6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/wayland/output/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
let output = data_init.init(
resource,
OutputUserData {
output: global_data.output.clone(),
output: global_data.output.downgrade(),
last_client_scale: AtomicU32::new(client_scale.load(Ordering::Acquire)),
client_scale,
},
Expand Down Expand Up @@ -124,13 +124,14 @@ where
output: &WlOutput,
data: &OutputUserData,
) {
data.output
.inner
.0
.lock()
.unwrap()
.instances
.retain(|o| o.id() != output.id());
if let Some(o) = data.output.upgrade() {
o.inner
.0
.lock()
.unwrap()
.instances
.retain(|o| o.id() != output.id());
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/wayland/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use std::sync::{
Arc,
};

use crate::output::{Inner, Mode, Output, Scale, Subpixel};
use crate::output::{Inner, Mode, Output, Scale, Subpixel, WeakOutput};

use tracing::info;
use wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_manager_v1::ZxdgOutputManagerV1;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl OutputManagerState {
/// User data for WlOutput
#[derive(Debug)]
pub struct OutputUserData {
pub(crate) output: Output,
pub(crate) output: WeakOutput,
last_client_scale: AtomicU32,
client_scale: Arc<AtomicU32>,
}
Expand Down Expand Up @@ -209,7 +209,7 @@ impl Output {

/// Attempt to retrieve a [`Output`] from an existing resource
pub fn from_resource(output: &WlOutput) -> Option<Output> {
output.data::<OutputUserData>().map(|ud| ud.output.clone())
output.data::<OutputUserData>().and_then(|ud| ud.output.upgrade())
}

pub(crate) fn wl_change_current_state(
Expand Down

0 comments on commit ace2e6a

Please sign in to comment.