Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session_lock: Change surface to Weak #1573

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wayland/session_lock/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
}

let data = ExtLockSurfaceUserData {
surface: surface.clone(),
surface: surface.downgrade(),
};
let lock_surface = data_init.init(id, data);

Expand Down
15 changes: 11 additions & 4 deletions src/wayland/session_lock/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use crate::wayland::compositor;
use _session_lock::ext_session_lock_surface_v1::{Error, ExtSessionLockSurfaceV1, Request};
use wayland_protocols::ext::session_lock::v1::server::{self as _session_lock, ext_session_lock_surface_v1};
use wayland_server::protocol::wl_surface::WlSurface;
use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, Resource};
use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, Resource, Weak};

use crate::wayland::session_lock::{SessionLockHandler, SessionLockManagerState};

/// User data for ext-session-lock surfaces.
#[derive(Debug)]
pub struct ExtLockSurfaceUserData {
pub(crate) surface: WlSurface,
// `LockSurfaceAttributes` stored in the surface `data_map` contains a
// `ExtSessionLockSurfaceV1`. So this reference needs to be weak to avoid a
// cycle.
pub(crate) surface: Weak<WlSurface>,
}

impl<D> Dispatch<ExtSessionLockSurfaceV1, ExtLockSurfaceUserData, D> for SessionLockManagerState
Expand All @@ -34,15 +37,19 @@ where
) {
match request {
Request::AckConfigure { serial } => {
let Ok(surface) = data.surface.upgrade() else {
return;
};

// Find configure for this serial.
let serial = Serial::from(serial);
let configure = compositor::with_states(&data.surface, |states| {
let configure = compositor::with_states(&surface, |states| {
let surface_data = states.data_map.get::<Mutex<LockSurfaceAttributes>>();
surface_data.unwrap().lock().unwrap().ack_configure(serial)
});

match configure {
Some(configure) => state.ack_configure(data.surface.clone(), configure),
Some(configure) => state.ack_configure(surface.clone(), configure),
None => lock_surface.post_error(
Error::InvalidSerial,
format!("wrong configure serial: {}", <u32>::from(serial)),
Expand Down
Loading