image-copy: Don't panic if ImageCaptureSourceKind udata is undefined
We want to merge this when updating Smithay to have https://github.com/Smithay/smithay/pull/1961, so that we don't panic the the output/toplevel already has no strong references when the source is created.
This commit is contained in:
parent
53e0db28ac
commit
472ffa5f30
2 changed files with 15 additions and 42 deletions
|
|
@ -50,14 +50,13 @@ impl ImageCopyCaptureHandler for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_constraints(&mut self, source: &ImageCaptureSource) -> Option<BufferConstraints> {
|
fn capture_constraints(&mut self, source: &ImageCaptureSource) -> Option<BufferConstraints> {
|
||||||
let kind = source.user_data().get::<ImageCaptureSourceKind>().unwrap();
|
match ImageCaptureSourceKind::from_source(source) {
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => weak
|
ImageCaptureSourceKind::Output(weak) => weak
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.and_then(|output| constraints_for_output(&output, &mut self.backend)),
|
.and_then(|output| constraints_for_output(&output, &mut self.backend)),
|
||||||
ImageCaptureSourceKind::Workspace(handle) => {
|
ImageCaptureSourceKind::Workspace(handle) => {
|
||||||
let shell = self.common.shell.read();
|
let shell = self.common.shell.read();
|
||||||
let output = shell.workspaces.space_for_handle(handle)?.output();
|
let output = shell.workspaces.space_for_handle(&handle)?.output();
|
||||||
constraints_for_output(output, &mut self.backend)
|
constraints_for_output(output, &mut self.backend)
|
||||||
}
|
}
|
||||||
ImageCaptureSourceKind::Toplevel(window) => {
|
ImageCaptureSourceKind::Toplevel(window) => {
|
||||||
|
|
@ -67,7 +66,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
ImageCaptureSourceKind::Destroyed => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,13 +96,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_session(&mut self, session: Session) {
|
fn new_session(&mut self, session: Session) {
|
||||||
let kind = session
|
match ImageCaptureSourceKind::from_source(&session.source()) {
|
||||||
.source()
|
|
||||||
.user_data()
|
|
||||||
.get::<ImageCaptureSourceKind>()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => {
|
ImageCaptureSourceKind::Output(weak) => {
|
||||||
let Some(mut output) = weak.upgrade() else {
|
let Some(mut output) = weak.upgrade() else {
|
||||||
session.stop();
|
session.stop();
|
||||||
|
|
@ -180,13 +173,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
)))
|
)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let kind = session
|
match ImageCaptureSourceKind::from_source(&session.source()) {
|
||||||
.source()
|
|
||||||
.user_data()
|
|
||||||
.get::<ImageCaptureSourceKind>()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => {
|
ImageCaptureSourceKind::Output(weak) => {
|
||||||
let Some(mut output) = weak.upgrade() else {
|
let Some(mut output) = weak.upgrade() else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -281,13 +268,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn frame(&mut self, session: &SessionRef, frame: Frame) {
|
fn frame(&mut self, session: &SessionRef, frame: Frame) {
|
||||||
let kind = session
|
match ImageCaptureSourceKind::from_source(&session.source()) {
|
||||||
.source()
|
|
||||||
.user_data()
|
|
||||||
.get::<ImageCaptureSourceKind>()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => {
|
ImageCaptureSourceKind::Output(weak) => {
|
||||||
let Some(mut output) = weak.upgrade() else {
|
let Some(mut output) = weak.upgrade() else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -330,13 +311,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn session_destroyed(&mut self, session: SessionRef) {
|
fn session_destroyed(&mut self, session: SessionRef) {
|
||||||
let kind = session
|
match ImageCaptureSourceKind::from_source(&session.source()) {
|
||||||
.source()
|
|
||||||
.user_data()
|
|
||||||
.get::<ImageCaptureSourceKind>()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => {
|
ImageCaptureSourceKind::Output(weak) => {
|
||||||
if let Some(mut output) = weak.upgrade() {
|
if let Some(mut output) = weak.upgrade() {
|
||||||
output.remove_session(&session);
|
output.remove_session(&session);
|
||||||
|
|
@ -363,13 +338,7 @@ impl ImageCopyCaptureHandler for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_session_destroyed(&mut self, session: CursorSessionRef) {
|
fn cursor_session_destroyed(&mut self, session: CursorSessionRef) {
|
||||||
let kind = session
|
match ImageCaptureSourceKind::from_source(&session.source()) {
|
||||||
.source()
|
|
||||||
.user_data()
|
|
||||||
.get::<ImageCaptureSourceKind>()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
match kind {
|
|
||||||
ImageCaptureSourceKind::Output(weak) => {
|
ImageCaptureSourceKind::Output(weak) => {
|
||||||
if let Some(mut output) = weak.upgrade() {
|
if let Some(mut output) = weak.upgrade() {
|
||||||
output.remove_cursor_session(&session);
|
output.remove_cursor_session(&session);
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,13 @@ pub enum ImageCaptureSourceKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageCaptureSourceKind {
|
impl ImageCaptureSourceKind {
|
||||||
pub fn from_resource(resource: &ExtImageCaptureSourceV1) -> Option<Self> {
|
pub fn from_source(source: &ImageCaptureSource) -> Self {
|
||||||
let source = ImageCaptureSource::from_resource(resource)?;
|
// If no user-data, assume source was created for a destroyed output, etc.
|
||||||
source.user_data().get::<ImageCaptureSourceKind>().cloned()
|
source
|
||||||
|
.user_data()
|
||||||
|
.get::<ImageCaptureSourceKind>()
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or(Self::Destroyed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue