First-pass Avalonia copy-to-clipboard #5167
Draft
+93
β1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now that AvaloniaUI/Avalonia#19930 has been merged I can tick a feature off my list (5 years later π). We'll have to think about how we ought to disable this behaviour on earlier Avalonia versions, or just require a version that has this.
This implementation is hacky and I haven't cleaned it up yet, I mostly wanted to see what the capabilities were and what we would have to do to support it. It's mostly the same as other implementations (call
GetImageBytes, turn it into a platform-specific image, and then pass it to a platform-specific function).The problem is that Avalonia requires we pass them a bitmap, which even with the device-independent-bitmap (DIB) that we have implemented is only a pseudo-standardized format. That wouldn't be a problem if Avalonia weren't cross-platform, where the preferred byte order of bitmaps can differ. Plus Avalonia seems to be ignoring the pixelFormat parameter, at least on Mac where I'm currently testing, so switching byte orders must be done by hand.
On an ARM Mac it seems that all we need to do is strip out the DIB header and it will have the correct colours. But I would want to test on Windows and Linux as well to make sure it does the right thing everywhere. I'm hoping that x86 vs ARM doesn't change the byte order for any OS, because I can't test Windows on ARM, and testing Mac on x86 or Linux on ARM is inconvenient but doable for me.
Once I've done that I'd like to think about how we ought to change this code, I would probably like to make the
BitmapHeaderstructinternalagain and just expose a method to get only the pixel array for a bitmap. And then come to a decision about how we release this and if we require a newer Avalonia version.