Skip to content

Commit b89bd9f

Browse files
committed
[*] update normally
1 parent cb467ce commit b89bd9f

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

lib/capture/src/backend.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ pub(crate) struct OutputInfo {
5252
pub image_ready: bool,
5353
}
5454

55+
impl Drop for OutputInfo {
56+
fn drop(&mut self) {
57+
log::debug!("Cleaning up OutputInfo resources");
58+
59+
// Release Wayland output object
60+
self.wl_output.release();
61+
62+
// Clean up memory mapping first
63+
if let Some(mmap) = self.image_mmap.take() {
64+
drop(mmap);
65+
}
66+
67+
// Clean up memory file descriptor
68+
if let Some(memfd) = self.image_memfd.take() {
69+
drop(memfd);
70+
}
71+
72+
log::debug!("OutputInfo resources cleaned up");
73+
}
74+
}
75+
5576
/// Global state for Wayland connection and screen capture.
5677
///
5778
/// This struct maintains the global state for the Wayland connection,
@@ -70,6 +91,23 @@ pub(crate) struct State {
7091
pub output_infos: Vec<OutputInfo>,
7192
}
7293

94+
impl Drop for State {
95+
fn drop(&mut self) {
96+
log::debug!("Cleaning up State resources");
97+
98+
// Wayland objects will be automatically cleaned up when dropped
99+
// No need to explicitly call release() on them
100+
self.wlr_screencopy_manager.take();
101+
self.xdg_output_manager.take();
102+
self.wl_shm.take();
103+
104+
// OutputInfo objects will be cleaned up automatically through their Drop implementation
105+
self.output_infos.clear();
106+
107+
log::debug!("State resources cleaned up");
108+
}
109+
}
110+
73111
/// Handle Wayland registry events to discover available globals.
74112
///
75113
/// This implementation processes Wayland registry events to bind to the necessary

lib/capture/src/capture.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub fn capture_output_iter(
222222
// Check for cancellation signal
223223
if config.cancel_sig.load(Ordering::Relaxed) {
224224
log::info!("Exit capture_iter process after Stopped");
225+
drop(state);
225226
return Ok(CaptureIterStatus::Stopped);
226227
}
227228

lib/capture/src/screen_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn protocol_get() -> Result<Vec<ScreenInfo>, Error> {
270270
let (state, _) = backend::connect_and_get_output_info()?;
271271
let mut infos = vec![];
272272

273-
for output_info in state.output_infos.into_iter() {
273+
for output_info in state.output_infos.iter() {
274274
if let OutputInfo {
275275
name: Some(name),
276276
output_logical_position: Some(output_logical_position),
@@ -281,7 +281,7 @@ fn protocol_get() -> Result<Vec<ScreenInfo>, Error> {
281281
} = output_info
282282
{
283283
infos.push(ScreenInfo {
284-
name,
284+
name: name.clone(),
285285
position: Position {
286286
x: output_logical_position.x,
287287
y: output_logical_position.y,
@@ -291,8 +291,8 @@ fn protocol_get() -> Result<Vec<ScreenInfo>, Error> {
291291
height: output_logical_size.height,
292292
},
293293
physical_size: None,
294-
scale_factor: scale_factor as f32,
295-
transform,
294+
scale_factor: *scale_factor as f32,
295+
transform: *transform,
296296
});
297297
}
298298
}

0 commit comments

Comments
 (0)