libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10.01k stars 1.85k forks source link

Support for system tray icon? #7822

Open Semphriss opened 1 year ago

Semphriss commented 1 year ago

Would it be useful to support system tray icons within SDL?


Screenshots for Windows, macOS and Ubuntu Windows: Windows system tray macOS: macOS system tray Ubuntu: Ubuntu system tray

Some potentially useful repositories:

icculus commented 1 year ago

I want to say no here, because this probably either gets watered down to an array of strings that represent possible menu items, or it starts really getting into the specifics of various OSes in ways we don't want to expose in the API.

smcv commented 1 year ago

The API for "system tray" icons on Linux is a bit of a disaster area, even if we assume that a "system tray" is even desirable, which not everyone agrees; so supporting anything non-trivial in a portable way is going to be a struggle.

(Link is from 2019, there has been more recent work but nothing very conclusive)

slouken commented 1 year ago

Yeah, I think this is outside the scope of SDL for now.

Semphriss commented 1 year ago

Generally speaking, what sorts of idea should I consider worth suggesting to add in SDL?

I have a few changes I'm making for my personal projects and I'd like to contribute them back, but I don't want to flood the issue tracker with my ideas. How should I decide what to share and what not to share?

slouken commented 1 year ago

Feel free to share and we'll let you know if we think it's appropriate. Even if we don't include it in mainline, having it here will let other people find your changes and use them.

Semphriss commented 2 months ago

For future reference, I managed to implement system trays on Windows, macOS, and Unix.

The source is available at https://github.com/Semphriss/SDL/tree/tray

Windows screenshot macOS screenshot Unix screenshot

It supports:

I still have a few rough edges to iron out, but it generally works well at the moment. If anybody would need help to use it, please let me know!

slouken commented 2 months ago

This actually looks pretty good! I'm going to go ahead and reopen this.

Semphriss commented 2 months ago

Should I open it as a pull request?

slouken commented 2 months ago

Should I open it as a pull request?

Sure!

slouken commented 2 months ago

One thing I expected to see was a show/hide or some way of letting the system know you're done creating the menus. It looks like right now you can keep adding entries over time and they dynamically show up, and if you need to remove one, you have to destroy the tray and start over.

I don't know if you actually need that, just an observation.

Semphriss commented 2 months ago

One thing I expected to see was a show/hide or some way of letting the system know you're done creating the menus. It looks like right now you can keep adding entries over time and they dynamically show up, and if you need to remove one, you have to destroy the tray and start over.

I haven't created all the possible functions, I went for the easiest path to quick results. AFAIK, all platforms support dynamically removing items at any position, so it's just a matter of adding what's missing.

icculus commented 2 months ago

This actually looks pretty good! I'm going to go ahead and reopen this.

Nothing changes minds faster than working code. :)