Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion apps/desktop-gpui/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,15 @@ pub fn topmost_foreign_window_at_cursor() -> Option<Window> {
candidates.into_iter().next().map(|(window, _)| window)
}

#[cfg(not(target_os = "macos"))]
#[cfg(target_os = "linux")]
pub fn topmost_foreign_window_at_cursor() -> Option<Window> {
match scap_targets::WindowImpl::topmost_x11_snapshot_at_cursor() {
Some(found) => found.map(|snapshot| snapshot.window),
None => Window::get_topmost_at_cursor(),
}
}

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
pub fn topmost_foreign_window_at_cursor() -> Option<Window> {
Window::get_topmost_at_cursor()
}
Expand Down Expand Up @@ -880,6 +888,11 @@ pub fn list_windows() -> Vec<WindowOption> {
/// `collect_windows_with_thumbnails` (`thumbnails/mod.rs:107-137`), which needs
/// the handle for both the ScreenCaptureKit filter and `Window::app_icon()`.
pub fn list_window_targets() -> Vec<(WindowOption, Window)> {
#[cfg(target_os = "linux")]
if let Some(targets) = linux_window_targets_from_snapshot() {
return targets;
}

Window::list()
.into_iter()
.filter_map(|window| {
Expand Down Expand Up @@ -942,6 +955,40 @@ pub fn list_window_targets() -> Vec<(WindowOption, Window)> {
.collect()
}

#[cfg(target_os = "linux")]
fn linux_window_targets_from_snapshot() -> Option<Vec<(WindowOption, Window)>> {
let snapshots = scap_targets::WindowImpl::list_x11_snapshots()?;
Some(
snapshots
.into_iter()
.filter_map(|snapshot| {
let size = snapshot.logical_size();
let position = snapshot.display_relative_origin();
let refresh_rate = snapshot.refresh_rate();
let id = snapshot.window.id();
if snapshot.name.trim().is_empty() {
return None;
}
let app = snapshot.owner_name?;
if app == "Window Server" {
return None;
}
Some((
WindowOption {
id,
label: snapshot.name,
app,
size: Some((size.width() as u32, size.height() as u32)),
position,
refresh_rate: Some(refresh_rate),
},
snapshot.window,
))
})
.collect(),
)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 4 additions & 0 deletions crates/scap-targets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ windows = { workspace = true, features = [
"Win32_Storage_FileSystem",
] }

[[bin]]
name = "x11-window-list-bench"
path = "src/bin/x11_window_list_bench.rs"

[target.'cfg(target_os = "linux")'.dependencies]
x11rb = { version = "0.13.2", features = ["randr"] }
rustix = { version = "1.1", features = ["event"] }
Expand Down
Loading
Loading