Hello all!
I've been spending the last few hours
determined to get clipboard support working on Linux. You can check my progress here:
https://github.com/Mischa-Alff/SFML/feature/clipboard(NOTE: I won't push my current progress with support for X11 until it's finished. There's no point in making tiny little commits for every two lines of code)
I'm not 100% familiar with everything, so this is essentially all to the extend of my understanding. I might be wrong. God, I hope I'm wrong, but using X is a land of sadomasochism, and if I were wrong, it wouldn't be sadomasochism anymore.
The problems- To receive the clipboard's contents, you must request ownership of the clipboard, request its contents, and then wait for an event containing the property that points to the contents of the clipboard. (This is apparently to prevent uselessly sending data around all the time)
- Once you've obtained ownership of the clipboard, you need to store its contents and send them to the next client who requests the data, until someone else requests ownership. (According to ICCCM sec. 2.6.1.3, you must request ownership to request contents, but not everyone follows ICCCM)
The potential solutionsObviously, the only solution to the second one is to stick the selection sending code in the
sf::WindowImplX11::processEvent function.
The solution to the first one is slightly more complex: Most software waits for a
selection_notify_event in the
getClipboard function, therefore driving the CPU up to 100% and sending all possible events to the event handler until it reaches a
selection_*_event, then processing that event and returning the data sent in the event. The problem with this method is that it will completely block execution until it gets to the event it wants, which might be never.
References:I'm looking for recommendations as to how I should proceed on this, what would be best for the API, and what would be best for the codebase.
Please don't reply with your ideal vision of how the clipboard API should be, without any real advice. I'm trying to solve a problem that has been plaguing me for hours, and I would like a constructive discussion on how this could be solved.
Other than that, any help is appreciated and much needed. SFML needs clipboard support.
Thanks!