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

For consistency use png on macOS #110

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
24 changes: 0 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ edition = "2018"

[features]
default = ["image-data"]
image-data = ["core-graphics", "image", "winapi/minwindef", "winapi/wingdi", "winapi/winnt"]
wayland-data-control = ["wl-clipboard-rs"]
image-data = ["dep:core-graphics", "dep:image", "winapi/minwindef", "winapi/wingdi", "winapi/winnt"]
Copy link
Author

Choose a reason for hiding this comment

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

This makes the feature flags in the docs a bit more readable as right now it shows image, core-graphics and wl-clipboard-rs as "features" but they are just optional dependencies

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, this requires a bump to Rust 1.60 to support:

The dep: syntax is only available starting with Rust 1.60. Previous versions can only use the implicit feature name.

arboard doesn't currently have an MSRV, and 1.60 is over a year old at this point, so I don't think its a big deal. Its also easy enough to rollback if it causes someone problems. I'm mentioning it just in case though.

wayland-data-control = ["dep:wl-clipboard-rs"]

[dependencies]
thiserror = "1.0"
Expand All @@ -36,7 +36,7 @@ objc_id = "0.1"
objc-foundation = "0.1"
once_cell = "1"
core-graphics = { version = "0.22", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = ["tiff"] }
image = { version = "0.24", optional = true, default-features = false, features = ["png"] }

[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies]
log = "0.4"
Expand Down
8 changes: 4 additions & 4 deletions src/platform/osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ impl<'clipboard> Get<'clipboard> {
Some(_) | None => return Err(Error::ContentNotAvailable),
};

let tiff: &NSArray<NSObject> = unsafe { msg_send![obj, TIFFRepresentation] };
let png: &NSArray<NSObject> = unsafe { msg_send![obj, PNGRepresentation] };
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't believe NSImage supports this representation (and is causing a test failure), unlike UIImage which does.

One alternative may be to wait for #106 to merge which switches to a different method of getting images from the clipboard. That way does support PNG like you'd want.

let data = unsafe {
let len: usize = msg_send![tiff, length];
let bytes: *const u8 = msg_send![tiff, bytes];
let len: usize = msg_send![png, length];
let bytes: *const u8 = msg_send![png, bytes];

Cursor::new(std::slice::from_raw_parts(bytes, len))
};
let reader = image::io::Reader::with_format(data, image::ImageFormat::Tiff);
let reader = image::io::Reader::with_format(data, image::ImageFormat::Png);
match reader.decode() {
Ok(img) => {
let rgba = img.into_rgba8();
Expand Down