From 626232963537562f94b7ab44aee7be44e8cf0387 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 25 Jan 2024 15:48:40 -0800 Subject: [PATCH] Clean up some of the screencopy code --- src/wayland/capture.rs | 15 --------------- src/wayland/screencopy.rs | 11 +++++------ 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/wayland/capture.rs b/src/wayland/capture.rs index b758ba1..a475caa 100644 --- a/src/wayland/capture.rs +++ b/src/wayland/capture.rs @@ -32,7 +32,6 @@ pub struct CaptureFilter { pub struct Capture { pub source: CaptureSource, - first_frame: AtomicBool, pub session: Mutex>, } @@ -40,7 +39,6 @@ impl Capture { pub fn new(source: CaptureSource) -> Arc { Arc::new(Capture { source, - first_frame: AtomicBool::new(true), session: Mutex::new(None), }) } @@ -53,18 +51,6 @@ impl Capture { session.data::()?.capture.upgrade() } - pub fn running(&self) -> bool { - self.session.lock().unwrap().is_some() - } - - pub fn unset_first_frame(&self) { - self.first_frame.store(false, Ordering::SeqCst); - } - - pub fn first_frame(&self) -> bool { - self.first_frame.load(Ordering::SeqCst) - } - // Start capturing frames pub fn start( self: &Arc, @@ -73,7 +59,6 @@ impl Capture { ) { let mut session = self.session.lock().unwrap(); if session.is_none() { - self.first_frame.store(true, Ordering::SeqCst); *session = Some(ScreencopySession::new(self, manager, qh)); } } diff --git a/src/wayland/screencopy.rs b/src/wayland/screencopy.rs index 68db09c..2614af9 100644 --- a/src/wayland/screencopy.rs +++ b/src/wayland/screencopy.rs @@ -16,6 +16,7 @@ use super::{AppData, Buffer, Capture, CaptureImage, CaptureSource, Event}; pub struct ScreencopySession { buffer: Option, session: zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1, + first_frame: bool, } impl ScreencopySession { @@ -48,10 +49,11 @@ impl ScreencopySession { Self { buffer: None, session, + first_frame: true, } } - fn attach_buffer_and_commit(&self, capture: &Capture, conn: &Connection) { + fn attach_buffer_and_commit(&mut self, capture: &Capture, conn: &Connection) { let Some(buffer) = self.buffer.as_ref() else { return; }; @@ -61,10 +63,10 @@ impl ScreencopySession { .and_then(|x| x.to_str().map(|x| x.to_string())); self.session.attach_buffer(&buffer.buffer, node, 0); // XXX age? - if capture.first_frame() { + if self.first_frame { self.session .commit(zcosmic_screencopy_session_v1::Options::empty()); - capture.unset_first_frame(); + self.first_frame = false; } else { self.session .commit(zcosmic_screencopy_session_v1::Options::OnDamage); @@ -133,9 +135,6 @@ impl ScreencopyHandler for AppData { let Some(capture) = Capture::for_session(session) else { return; }; - if !capture.running() { - return; - } let mut session = capture.session.lock().unwrap(); let Some(session) = session.as_mut() else { return;