Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2265 +/- ##
==========================================
- Coverage 14.98% 14.83% -0.15%
==========================================
Files 213 208 -5
Lines 15255 15317 +62
Branches 4072 4087 +15
==========================================
- Hits 2286 2273 -13
- Misses 12821 12914 +93
+ Partials 148 130 -18
Continue to review full report at Codecov.
|
2f18789 to
d51b787
Compare
e6552cf to
f49594a
Compare
|
I think the main thing needed here (along with #1222) is a decision on whether to support multiple types or not. Otherwise it looks reasonable. For what it's worth I would suggesting starting with support for files and text, then it can be expanded later if desired |
|
I agree, only supporting files and text is enough for most people right now. The only thing we still need to do is agree on an API which works on all platforms, and make sure file dropping works on all the platforms that support it. |
Bromeon
left a comment
There was a problem hiding this comment.
Thanks for the PR!
This seems like yet another PR which might suffer from having no modern sf::Event API (see comment). I would advocate we do not block it on that issue though, since that may take forever. Also, SFML 3 APIs are in flux and can be modified at any time.
But we should probably write a TODO and possibly a GitHub issue, so we don't forget this.
| // Get the dropped item by getting the XdndSelection property | ||
| m_droppedItem = getWindowStringProperty(m_display, m_window, windowEvent.xselection.property); | ||
|
|
||
| Event event; | ||
| event.type = Event::ItemDropped; | ||
| event.itemDropped.item = &m_droppedItem; | ||
| event.itemDropped.x = m_dropPosition.x; | ||
| event.itemDropped.y = m_dropPosition.y; |
There was a problem hiding this comment.
Storing the event string in the window is asking for trouble.
If another ItemDroppedEvent is processed while the first one is still alive, the string is suddenly wrong. In other words, it's possible that a const ItemDroppedEvent suddenly changes contents only by external means. You will also get UB through dangling pointer if e.g. the underlying sf::Window is moved while the event is still around.
Granted, these are edge cases, but ideally we'd have an API that's robust enough to not fall apart when a user wants to do more unconventional things.
I'm aware that the union approach we're using here is very limited, and this is actually a good example to show why. I don't know yet what a good API would look like. std::variant is unfortunately verbose as hell and really not fun to work with.
There was a problem hiding this comment.
I'm not sure if it is possible to get multiple drop events at once, because I don't think XdndDrop can be called multiple times per frame. (It might be possible if the user is deliberately trying, but I'm not really sure what could be done about that)
About the dangling pointer, I don't really know what could be done about that.
| // Signal the selection owner that we have successfully read the data. | ||
| XDeleteProperty(dpy, w, p); |
There was a problem hiding this comment.
We have two XGetWindowProperty calls, but only one XDeleteProperty.
Is this correct? Do we not leak memory?
There was a problem hiding this comment.
| XGetWindowProperty(dpy, w, p, 0, static_cast<long>(size), false, AnyPropertyType, &da, &di, &dul, &dul, &prop_ret); | ||
|
|
||
| String value = reinterpret_cast<char*>(prop_ret); | ||
|
|
||
| XFree(prop_ret); |
There was a problem hiding this comment.
These statements could be grouped (no empty lines) so we know they are closely related.
There was a problem hiding this comment.
| Atom da, incr, type; | ||
| int di; | ||
| unsigned long size, dul; | ||
| unsigned char* prop_ret = NULL; |
There was a problem hiding this comment.
Please declare variables as late as possible -- only once you need them. If possible, initialize them immediately during declaration.
Declaring everything at the beginning of the function is relatively outdated C practice, either mandated by old compilers or a way to measure stack memory usage.
There was a problem hiding this comment.
I took this code from https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTING-en.html, and i didn't test it very thoroughly, I just wanted to make a quick draft PR so we could figure out how to get it to work on multiple platforms, and then I would go and polish it up before merging it into master.
There was a problem hiding this comment.
I'd also like to see Bromeon's comments be addressed even if this is just a draft PR.
There was a problem hiding this comment.
Ok, I've completely changed how the selection is converted. I modded the conversion code from https://github.com/SFML/SFML/blob/master/src/SFML/Window/Unix/ClipboardImpl.cpp to work with mine.
0182953 to
66c75c1
Compare
|
I see you're using |
|
Ah, that's why it changed some random stuff. I upgraded from Leap 15.4 to Tumbleweed, so that's why it changed. I'll try to see if I can get 14 on my machine. |
|
Ok, I've used |
| class WindowImplCocoa; | ||
| } | ||
| } | ||
| } // namespace sf |
There was a problem hiding this comment.
I'm guessing these got added because you used clang-format-15 to format. You can remove these since we now disallow using clang-format-15.
There was a problem hiding this comment.
Visual Studio formatted everything for me, and I guess it used clang-format-15.
| &remainingBytes, | ||
| &data); | ||
|
|
||
| sf::String value; |
ChrisThrasher
left a comment
There was a problem hiding this comment.
The previous CI run succeeded minus formatting failing. Please try to get a copy of clang-format 12, 13, or 14 and build the format target to fix this.
include/SFML/Window/Event.hpp
Outdated
| #include <SFML/Window/Mouse.hpp> | ||
| #include <SFML/Window/Sensor.hpp> | ||
|
|
||
| #include <memory> |
There was a problem hiding this comment.
I think you can remove this header
|
is there a way to get clang-format to reformat the whole codebase? because clang-format-13 isn't fixing everything, and I don't want to mess with visual studio's clang-format version |
|
should I merge all the commits together and start a new pr on a new branch? (not named X11DnD) |
Yes, that's what happens when you build the EDIT: The formatting CI jobs are passing now so I think you're good.
Please don't make a new branch or PR. If you want to clean up the commit history then go for it, but you can wait to do that later if you want. If you do that, you can just |
Ok, I wasn't sure if it was fine that a branch named "X11DnD" also had windows support. |
|
You're good. Branches names aren't that important since they don't appear in the commit history after a merge. |
da762ae to
60b6dc3
Compare
Pull Request Test Coverage Report for Build 10754038072Details
💛 - Coveralls |
| [self updateCursorGrabbed]; // update for fullscreen | ||
|
|
||
| // Register the drag types that this view can accept | ||
| //[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]]; |
There was a problem hiding this comment.
Do you recall why this is commented out?
Description
Edited to reflect new changes
This pull request adds file dropping support on Windows, X11, and MacOS. Unfortunately, this does not work on Wayland, even under xWayland.
Notes:
Example