Skip to content

Conversation

@BrycensRanch
Copy link
Member

@BrycensRanch BrycensRanch commented Feb 27, 2025

Powered by SharpCapture

With this PR, we call the necessary libraries via a layer known as SharpCapture. It is not a library, just an implementation of virtual methods for each supported platform (Linux, Windows, and macOS in-progress)

Preface

The purpose of this PR is to remove the dependency on Rust. Due to the way Rust compiles, it adds a bunch of build dependencies to link the resulting binary against the necessary libraries it uses. The Rust toolchain is even more GBs that dissuades potential contributors who are only interested in C#. Additionally, the auto-generated file snapxrust.cs is hilariously large piece of code I don't understand. As a nice plus, no more *.so file has to be right next to the SnapX assembly ie snapx-ui.exe snapx-gtk.

Linux

For Linux, xcap used X11's facilities to screenshot on X11. On Wayland, it'd use Gnome Shell's Screenshot DBUS facilities or the FreeDesktop Screenshot Portal. SharpCapture now purely uses the FreeDesktop XDG Screenshot Portal on Wayland or X11. This can be improved later on.

Windows

For Windows, screenshotting should be slightly faster & be able to capture DirectX games that are in fullscreen & are controlling the screen. Previously, xcap used GDI+. Now, it uses Direct3d11 to screenshot.

macOS

Additionally, the minimum supported version of macOS is 12.3 now instead of 11 or 12. Thanks to dropping the outdated avf foundation screenshotting functionality and using the modern ScreenCaptureKit. If possible, I'd like to use the new ScreenshotKit that requires macOS 14+ and fallback to ScreenCaptureKit.

This removes the dependency on the Rust library known as xcap as I am going to do the screenshotting myself in tree. This *will* give greater flexibility to SnapX and ensure we're always up to date using the latest modern & secure API fors Screen Capture. Additionally, all the Rust code has been sent into oblivion. I have been working on this initial implementation for Linux for weeks. Turns out, Wayland is a complicated beast. What a shame it's come against me, though. Poor thing never stood a chance.
@the-label-bot
Copy link

the-label-bot bot commented Feb 27, 2025

The Label Bot has predicted the following:

Category Value Confidence Applied Label


public class WindowsCapture : BaseCapture
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An opening brace should not be followed by a blank line.

Suggested change


public class WindowsCapture : BaseCapture
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An opening brace should not be followed by a blank line.

Suggested change

…no-rust

# Conflicts:
#	SnapX.Avalonia/SnapX.Avalonia.csproj
#	SnapX.Core/FeatureFlags.cs
#	SnapX.Core/Media/Screenshot.cs
#	SnapX.Core/ScreenCapture/Rust/Cargo.lock
#	SnapX.Core/SnapX.Core.csproj
#	SnapX.Core/Utils/CaptureHelpers.cs
#	SnapX.Core/Utils/Native/Clipboard.cs
This was a bug, I forgot to add it to the switch statement.
This only works with the -PrintScreen parameter as I am about to finish work for the day. The colors on the screenshot are messed up but I suspect that's an easy fix
{
break;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A closing brace should not be preceded by a blank line.

Suggested change

{
DebugHelper.WriteException(new InvalidOperationException("Adapter is not initialized."));
factory.EnumAdapters1(0, out Adapter);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A closing brace should not be preceded by a blank line.

Suggested change

@BrycensRanch
Copy link
Member Author

I think Record Methods should return a long-lived or disposable class that handles recording. Much like how there's a BaseCapture, there should be a BaseRecorder or something along those lines. I've been working on a library to bring PipeWire to C# as well to aid in recording on linux.

That works for me. I'll start cooking up a base implementation for Windows. Ironically, it's the easiest to implement.

I have a semi-working implementation for Linux already, I did need to use ffmpeg, for my POC I used FFMpegCore, but I think we could use other ffmpeg .net libraries if needed. We'd need to decide on which one will be used though. Of course it doesn't need to be ffmpeg, I just used it for my test POC for convenience.

Interesting, does it work on Wayland? I've only seen one patch for FFmpeg using Portals and it seems like it was left untouched by the FFmpeg devs.

I've only been testing on Wayland, so yes?

Oh, I think I know what you're asking about now. I'm not using ffmpeg to do any capturing. I'm using XDG Portals to start a screencast session, then I use PipeWireSharp to connect to the pipewire node, then I process the frame data and send it to ffmpeg to encode it into a video.

Awesome, I'm excited for a demo!

…no-rust

# Conflicts:
#	.github/Progress.md
#	SnapX.Core/ScreenCapture/Rust/Cargo.lock
#	SnapX.Core/ScreenCapture/Rust/Cargo.toml
#	SnapX.Core/ScreenCapture/Rust/src/lib.rs
#	SnapX.Core/Utils/Native/Methods.cs
#	SnapX.Core/Utils/OsInfo.cs
@github-actions github-actions bot added the packaging Application packaging ie (RPM, deb, PKGBUILD) label May 30, 2025
@socket-security
Copy link

socket-security bot commented May 30, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmicrosoft.windows.cswinrt@​2.2.068100100100100

View full report

config.showsCursor = true
config.queueDepth = 5

var filter: SCContentFilter? = nil // Initialize filter as optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing an optional variable with nil is redundant

Suggested change
var filter: SCContentFilter? = nil // Initialize filter as optional
var filter: SCContentFilter? // Initialize filter as optional

Replaces my broken attempt. I will RETURN!
No other platforms are affected.
@github-actions github-actions bot added the actions GitHub Actions label May 30, 2025
@github-actions github-actions bot added the build Related to building label May 30, 2025
@BrycensRanch BrycensRanch marked this pull request as ready for review May 30, 2025 21:39
@BrycensRanch
Copy link
Member Author

Once checks pass, this PR shall be merged. I acknowledge the macOS swift sharp capture code does not compile. So, until it does. xcap is back in service for macOS. This PR will be merged as is. It’s an improvement for Windows & Linux. :)

@BrycensRanch BrycensRanch merged commit 9477191 into develop May 30, 2025
15 of 16 checks passed
@github-project-automation github-project-automation bot moved this to Done in SnapX May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

actions GitHub Actions Avalonia Related to SnapX.Avalonia build Related to building Core Related to SnapX.Core documentation Improvements or additions to documentation enhancement New feature or request packaging Application packaging ie (RPM, deb, PKGBUILD) urgent Something that should be dealt with ASAP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile error on Fedora 41 Reimplement GetForegroundWindow Reimplement w/ Windows support & Linux (X11, and KDE Plasma Wayland)

4 participants