rework mime types, support pasting file lists, SIP when dropping single files
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Failing after 5m18s
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 6m48s
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 6m37s
ContinuousIntegration / linux (push) Successful in 4m29s
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 6m16s
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 6m6s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Failing after 5m18s
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 6m48s
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 6m37s
ContinuousIntegration / linux (push) Successful in 4m29s
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 6m16s
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 6m6s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
This commit is contained in:
@@ -2,22 +2,67 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
const char* clipboardHasImage(void) {
|
||||
const static std::vector<const char*> image_mime_types {
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/bmp",
|
||||
};
|
||||
|
||||
for (const char* mime_type : image_mime_types) {
|
||||
if (SDL_HasClipboardData(mime_type) == SDL_TRUE) {
|
||||
return mime_type;
|
||||
static const char* clipboardHas(const std::vector<std::string_view>& filter_mime_types) {
|
||||
for (const auto& mime_type : filter_mime_types) {
|
||||
// ASSERTS that stringview is null terminated
|
||||
if (SDL_HasClipboardData(mime_type.data()) == SDL_TRUE) {
|
||||
return mime_type.data();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const static std::vector<std::string_view> image_mime_types {
|
||||
"image/svg+xml",
|
||||
"image/jxl",
|
||||
"image/avif",
|
||||
"image/apng",
|
||||
"image/webp",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/qoi",
|
||||
"image/bmp",
|
||||
// tiff?
|
||||
};
|
||||
|
||||
const static std::vector<std::string_view> file_list_mime_types {
|
||||
"text/uri-list",
|
||||
"text/x-moz-url",
|
||||
};
|
||||
|
||||
const char* clipboardHasImage(void) {
|
||||
return clipboardHas(image_mime_types);
|
||||
}
|
||||
|
||||
const char* clipboardHasFileList(void) {
|
||||
return clipboardHas(file_list_mime_types);
|
||||
}
|
||||
|
||||
bool mimeIsImage(const char* mime_type) {
|
||||
if (mime_type == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string_view mt_sv {mime_type};
|
||||
auto it = std::find(image_mime_types.cbegin(), image_mime_types.cend(), mime_type);
|
||||
|
||||
return it != image_mime_types.cend();
|
||||
}
|
||||
|
||||
bool mimeIsFileList(const char* mime_type) {
|
||||
if (mime_type == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string_view mt_sv {mime_type};
|
||||
auto it = std::find(file_list_mime_types.cbegin(), file_list_mime_types.cend(), mime_type);
|
||||
|
||||
return it != image_mime_types.cend();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user