Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland : Fix multithreading bug + fix segfault in libdubs on certain systems. #156

Merged
merged 2 commits into from
Oct 8, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ windows = { version = "0.58", features = [
[target.'cfg(target_os="linux")'.dependencies]
percent-encoding = "2.3"
xcb = { version = "1.4", features = ["randr"] }
dbus = { version = "0.9", features = ["vendored"] }
dbus = { version = "0.9.7" }

[dev-dependencies]
fs_extra = "1.3"
33 changes: 28 additions & 5 deletions src/linux/wayland_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl SignalArgs for OrgFreedesktopPortalRequestResponse {
const NAME: &'static str = "Response";
const INTERFACE: &'static str = "org.freedesktop.portal.Request";
}

static DBUS_LOCK: Mutex<()> = Mutex::new(());
fn org_gnome_shell_screenshot(
conn: &Connection,
x: i32,
Expand Down Expand Up @@ -172,9 +172,32 @@ pub fn wayland_capture(impl_monitor: &ImplMonitor) -> XCapResult<RgbaImage> {
let y = ((impl_monitor.y as f32) * impl_monitor.scale_factor) as i32;
let width = ((impl_monitor.width as f32) * impl_monitor.scale_factor) as i32;
let height = ((impl_monitor.height as f32) * impl_monitor.scale_factor) as i32;

let lock = DBUS_LOCK.lock();
let conn = Connection::new_session()?;

org_gnome_shell_screenshot(&conn, x, y, width, height)
.or_else(|_| org_freedesktop_portal_screenshot(&conn, x, y, width, height))
let res = org_gnome_shell_screenshot(&conn, x, y, width, height)
.or_else(|_| org_freedesktop_portal_screenshot(&conn, x, y, width, height));
drop(lock);
res
}
#[test]
fn screnshot_multithreaded() {
fn make_screenshots() {
let monitors = crate::monitor::Monitor::all().unwrap();
for monitor in monitors {
monitor.capture_image().unwrap();
}
}
// Try making screenshots in paralel. If this times out, then this means that there is a threading issue.
const PARALELISM: usize = 10;
let handles: Vec<_> = (0..PARALELISM)
.map(|_| {
std::thread::spawn(|| {
make_screenshots();
})
})
.collect();
make_screenshots();
handles
.into_iter()
.for_each(|handle| handle.join().unwrap());
}
Loading