summaryrefslogtreecommitdiff
path: root/src/xwayland/XWM.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-10-21 19:11:11 +0100
committerVaxry <vaxry@vaxry.net>2025-10-21 19:11:18 +0100
commit02b0c563f37bf55d0211e06b286505cd562d0630 (patch)
tree9d62691abf00e7f26f2cb61fc9f4ff60ea15e97c /src/xwayland/XWM.cpp
parent4926332c37d609beae0aa97021094ad977b7f1ec (diff)
xwm: attempt to guess mime in sendData for DnD
Diffstat (limited to 'src/xwayland/XWM.cpp')
-rw-r--r--src/xwayland/XWM.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp
index c43a20eb..cadf66af 100644
--- a/src/xwayland/XWM.cpp
+++ b/src/xwayland/XWM.cpp
@@ -1486,8 +1486,54 @@ bool SXSelection::sendData(xcb_selection_request_event_t* e, std::string mime) {
}
if (std::ranges::find(MIMES, mime) == MIMES.end()) {
- Debug::log(ERR, "[xwm] X client asked for unknown MIME '{}', falling back to '{}'", mime, *MIMES.begin());
- mime = *MIMES.begin();
+ // try to guess mime, don't just blindly send random-ass shit that the app will have no fucking
+ // clue what to do with
+ Debug::log(ERR, "[xwm] X client asked for MIME '{}' that this selection doesn't support, guessing.", mime);
+
+ auto needle = mime;
+ auto selectedMime = *MIMES.begin();
+ if (mime.contains('/'))
+ needle = mime.substr(0, mime.find('/'));
+
+ Debug::log(TRACE, "[xwm] X MIME needle '{}'", needle);
+
+ if (Debug::m_trace) {
+ std::string mimeList = "";
+ for (const auto& m : MIMES) {
+ mimeList += "'" + m + "', ";
+ }
+
+ if (!MIMES.empty())
+ mimeList = mimeList.substr(0, mimeList.size() - 2);
+
+ Debug::log(TRACE, "[xwm] X MIME supported: {}", mimeList);
+ }
+
+ bool found = false;
+
+ for (const auto& m : MIMES) {
+ if (m.starts_with(needle)) {
+ selectedMime = m;
+ Debug::log(TRACE, "[xwm] X MIME needle found type '{}'", m);
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ for (const auto& m : MIMES) {
+ if (m.contains(needle)) {
+ selectedMime = m;
+ Debug::log(TRACE, "[xwm] X MIME needle found type '{}'", m);
+ found = true;
+ break;
+ }
+ }
+ }
+
+ Debug::log(ERR, "[xwm] Guessed mime: '{}'. Hopefully we're right enough.", selectedMime);
+
+ mime = selectedMime;
}
auto transfer = makeUnique<SXTransfer>(*this);