Move attach_buffer_and_commit
This commit is contained in:
parent
6f1b391b00
commit
43e9ef390a
2 changed files with 28 additions and 23 deletions
|
|
@ -35,7 +35,7 @@ pub struct Capture {
|
||||||
pub buffer: Mutex<Option<Buffer>>,
|
pub buffer: Mutex<Option<Buffer>>,
|
||||||
pub source: CaptureSource,
|
pub source: CaptureSource,
|
||||||
first_frame: AtomicBool,
|
first_frame: AtomicBool,
|
||||||
session: Mutex<Option<zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1>>,
|
pub session: Mutex<Option<zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Capture {
|
impl Capture {
|
||||||
|
|
@ -64,6 +64,10 @@ impl Capture {
|
||||||
self.session.lock().unwrap().is_some()
|
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 {
|
pub fn first_frame(&self) -> bool {
|
||||||
self.first_frame.load(Ordering::SeqCst)
|
self.first_frame.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
@ -108,26 +112,6 @@ impl Capture {
|
||||||
}
|
}
|
||||||
*self.buffer.lock().unwrap() = None;
|
*self.buffer.lock().unwrap() = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn attach_buffer_and_commit(&self, conn: &Connection) {
|
|
||||||
let session = self.session.lock().unwrap();
|
|
||||||
let buffer = self.buffer.lock().unwrap();
|
|
||||||
let (Some(session), Some(buffer)) = (session.as_ref(), buffer.as_ref()) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let node = buffer
|
|
||||||
.node()
|
|
||||||
.and_then(|x| x.to_str().map(|x| x.to_string()));
|
|
||||||
|
|
||||||
session.attach_buffer(&buffer.buffer, node, 0); // XXX age?
|
|
||||||
if self.first_frame() {
|
|
||||||
session.commit(zcosmic_screencopy_session_v1::Options::empty());
|
|
||||||
} else {
|
|
||||||
session.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
|
||||||
}
|
|
||||||
conn.flush().unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Capture {
|
impl Drop for Capture {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,27 @@ use cosmic::cctk;
|
||||||
|
|
||||||
use super::{AppData, Capture, CaptureImage, CaptureSource, Event};
|
use super::{AppData, Capture, CaptureImage, CaptureSource, Event};
|
||||||
|
|
||||||
|
fn attach_buffer_and_commit(capture: &Capture, conn: &Connection) {
|
||||||
|
let session = capture.session.lock().unwrap();
|
||||||
|
let buffer = capture.buffer.lock().unwrap();
|
||||||
|
let (Some(session), Some(buffer)) = (session.as_ref(), buffer.as_ref()) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let node = buffer
|
||||||
|
.node()
|
||||||
|
.and_then(|x| x.to_str().map(|x| x.to_string()));
|
||||||
|
|
||||||
|
session.attach_buffer(&buffer.buffer, node, 0); // XXX age?
|
||||||
|
if capture.first_frame() {
|
||||||
|
session.commit(zcosmic_screencopy_session_v1::Options::empty());
|
||||||
|
capture.unset_first_frame();
|
||||||
|
} else {
|
||||||
|
session.commit(zcosmic_screencopy_session_v1::Options::OnDamage);
|
||||||
|
}
|
||||||
|
conn.flush().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
impl ScreencopyHandler for AppData {
|
impl ScreencopyHandler for AppData {
|
||||||
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
||||||
&mut self.screencopy_state
|
&mut self.screencopy_state
|
||||||
|
|
@ -34,7 +55,7 @@ impl ScreencopyHandler for AppData {
|
||||||
|
|
||||||
drop(buffer);
|
drop(buffer);
|
||||||
|
|
||||||
capture.attach_buffer_and_commit(conn);
|
attach_buffer_and_commit(&capture, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ready(
|
fn ready(
|
||||||
|
|
@ -73,7 +94,7 @@ impl ScreencopyHandler for AppData {
|
||||||
drop(buffer);
|
drop(buffer);
|
||||||
|
|
||||||
// Capture again on damage
|
// Capture again on damage
|
||||||
capture.attach_buffer_and_commit(conn);
|
attach_buffer_and_commit(&capture, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn failed(
|
fn failed(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue