Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
linux-wayland: handle unsupported content filter
Browse files Browse the repository at this point in the history
+ treat virtual sources as display
  • Loading branch information
MAlba124 committed Jul 26, 2024
1 parent ef062a1 commit 0bb9858
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
37 changes: 28 additions & 9 deletions src/platform/linux_wayland/capture_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ impl WaylandCapturableContent {
fn source_types_filter(filter: CapturableContentFilter) -> BitFlags<SourceType> {
let mut bitflags = BitFlags::empty();
if filter.displays {
bitflags |= SourceType::Monitor;
bitflags |= SourceType::Monitor | SourceType::Virtual;
}
if let Some(windows_filter) = filter.windows {
if windows_filter.desktop_windows || windows_filter.onscreen_only {
bitflags |= SourceType::Window | SourceType::Virtual;
bitflags |= SourceType::Window;
}
}
bitflags
Expand All @@ -136,6 +136,10 @@ impl WaylandCapturableContent {
.map_err(|e| CapturableContentError::Other(e.to_string()))?
.contains(CursorMode::Metadata);

let source_types = Self::source_types_filter(filter)
// Some portal implementations freak out when we include supported an not supported source types
& screencast.available_source_types().await.map_err(|e| CapturableContentError::Other(e.to_string()))?;

let session = screencast
.create_session()
.await
Expand All @@ -144,13 +148,13 @@ impl WaylandCapturableContent {
screencast
.select_sources(
&session,
// TODO: Show cursor as default when metadata-mode is not available?
// INVESTIGATE: Show cursor as default when metadata-mode is not available?
if cursor_as_metadata {
CursorMode::Metadata
} else {
CursorMode::Embedded
},
Self::source_types_filter(filter),
source_types,
false,
None,
ashpd::desktop::PersistMode::DoNot,
Expand Down Expand Up @@ -235,7 +239,7 @@ mod tests {

use crate::{
platform::platform_impl::{
wayland::capture_content::WaylandCapturableContent, ImplCapturableContentFilter,
capture_content::WaylandCapturableContent, ImplCapturableContentFilter,
},
prelude::{CapturableContentFilter, CapturableWindowFilter},
};
Expand All @@ -248,7 +252,7 @@ mod tests {
displays: true,
impl_capturable_content_filter: ImplCapturableContentFilter::default(),
}),
SourceType::Monitor
SourceType::Monitor | SourceType::Virtual
);
}

Expand All @@ -263,7 +267,7 @@ mod tests {
displays: false,
impl_capturable_content_filter: ImplCapturableContentFilter::default(),
}),
SourceType::Window | SourceType::Virtual
SourceType::Window
);
assert_eq!(
WaylandCapturableContent::source_types_filter(CapturableContentFilter {
Expand All @@ -274,7 +278,7 @@ mod tests {
displays: false,
impl_capturable_content_filter: ImplCapturableContentFilter::default(),
}),
SourceType::Window | SourceType::Virtual
SourceType::Window
);
assert_eq!(
WaylandCapturableContent::source_types_filter(CapturableContentFilter {
Expand All @@ -285,7 +289,7 @@ mod tests {
displays: false,
impl_capturable_content_filter: ImplCapturableContentFilter::default(),
}),
SourceType::Window | SourceType::Virtual
SourceType::Window
);
}

Expand All @@ -300,4 +304,19 @@ mod tests {
BitFlags::empty()
);
}

#[test]
fn source_type_filter_conversion_all() {
assert_eq!(
WaylandCapturableContent::source_types_filter(CapturableContentFilter {
windows: Some(CapturableWindowFilter {
desktop_windows: true,
onscreen_only: true
}),
displays: true,
impl_capturable_content_filter: ImplCapturableContentFilter::default(),
}),
SourceType::Monitor | SourceType::Virtual | SourceType::Window
);
}
}
6 changes: 3 additions & 3 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub(crate) use macos as platform_impl;
pub mod windows;

#[cfg(target_os = "windows")]
pub(crate) use windows as platform_impl;
pub(crate) use windows as platform_impl;

#[cfg(target_os = "linux")]
pub mod linux;
pub mod linux_wayland;

#[cfg(target_os = "linux")]
pub(crate) use linux as platform_impl;
pub(crate) use linux_wayland as platform_impl;

0 comments on commit 0bb9858

Please sign in to comment.