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

Allow setting cursors with colors on Linux #1693

Closed
cschreib opened this issue Aug 20, 2020 · 8 comments
Closed

Allow setting cursors with colors on Linux #1693

cschreib opened this issue Aug 20, 2020 · 8 comments

Comments

@cschreib
Copy link
Contributor

Subject of the issue

SFML 2.5 added the Cursor class to allow changing the system cursor to an arbitrary bitmap using sf::Cursor::loadFromPixels(). On Linux, the implementation with X11 only supports "monochrome" cursors (black, white, or transparent pixels). This should be improved to support full ARGB, which is possible with X11. See reference implementation in GDK which supports both methods: http://web.mit.edu/ghudson/dev/nokrb/third/gtk2/gdk/x11/gdkcursor-x11.c

The monochrome implementation seems available on all/most platforms, but the ARGB implementation is not. I suspect, however, that most desktop distributions do support it.

Your environment

  • Linux Mint 19
  • 2.5.0
  • Clang-10 / GCC-8
  • None

Steps to reproduce

Use sf::Cursor::loadFromPixels() on a Linux platform, with an input image that contains color.

Expected behavior

Color is displayed correctly.

Actual behavior

Only monochrome output.

@cschreib
Copy link
Contributor Author

FYI I'm keen to look into providing an implementation for this, if no one is already working on it.

@eXpl0it3r
Copy link
Member

Would be awesome if you could write an implementation. I'm not aware of anyone working on one right now.

Keep in mind that the linked code is licensed under GPL and as such incompatible with zlib, but it's a good way to see an example of the API usage. 😉

@cschreib
Copy link
Contributor Author

@eXpl0it3r Ok great!

I see the original implementation is from @binary1248 and @fundies. Asking them: is there any particular reason why Linux only got the monochrome implementation? Or was it just a practical decision to get the feature merged in quickly?

@cschreib
Copy link
Contributor Author

That was way easier than I expected. I've opened a PR: #1694

@binary1248
Copy link
Member

To be honest, I wasn't even aware of this limitation. When I initially wrote the XCB implementation many years ago it supported BGRA images from the start. During the refactor in f65459d and 34ea68b, the implementation was moved to where it lives now, however the new implementation only supported monochrome cursors. Since @mantognini wrote the new implementation, only he will be able to answer the question.

@mantognini
Copy link
Member

That wasn't yesterday, so my memory is a bit fuzzy... It was one of the first and rare time I had to implement something for Linux and the documentation I had mentioned that only monochrome was supported (ref). I guess for a first implementation it was agreed to be fine and peer review failed to show the loss of functionality. Glad to see this being addressed! :)

@cschreib
Copy link
Contributor Author

Ok, glad to hear there weren't major problems that were blocking this :) While testing, I also realized the monochrome implementation is broken if the input image has non-power-of-two dimensions (I assume power-of-two images were used for testing, as these indeed worked fine). I've added the fix to the PR linked above.

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Nov 22, 2020
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Nov 22, 2020
@eXpl0it3r eXpl0it3r moved this from Discussion to Ready in SFML 2.6.0 Nov 22, 2020
@eXpl0it3r
Copy link
Member

Implemented with #1694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
Development

No branches or pull requests

4 participants