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

Add system tray support #10873

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add system tray support #10873

wants to merge 11 commits into from

Conversation

Semphriss
Copy link
Contributor

@Semphriss Semphriss commented Sep 16, 2024

Description

This adds support for system tray (or equivalent) on Windows, macOS and Unix using AppIndicator.

Windows screenshot
macOS screenshot
Unix screenshot

Currently supported:

  • Custom tray icon (I used test/trashcan.bmp as an example)
  • Tooltip on the tray icon
  • Menus including:
    • Items
    • Disabled items
    • Checkboxes
    • Separators
    • Submenus
    • Custom callbacks on any item

Notes

The Unix implementation uses AppIndicator, which in turn uses GTK. I've done my best to keep SDL and the other libraries at arm length; nothing is required at compilation, and runtime will dynamically check for the libraries with dlopen and fail gracefully if they're not found.

Due to the lack of headers, I had to copy over some function declarations and macros into SDL (only the bare minimum). I added the macro APPINDICATOR_HEADER that should expand to <path/to/appindicator.h> if it is set. I currently did not implement looking for the header and setting the macro, so the macro is always unset for now.

On macOS, SDL_INIT_VIDEO is needed.

On all platforms, there is an "inner thread" that runs the tray that feels like it should be part of the main thread. It currently does not need to change anything outside src/tray, but it would be good to review the best practices there, and update anything that needs updates.

TODO & FIXME

  • Add various SDL functions to read, move and delete menu items as necessary
  • Document the functions
  • Review the need for a new subsystem? (Possibly integrate it to the Video subsystem)
  • Change OR'able enums to ints
  • Review the less-than-pretty AppIndicator implementation
  • If the APPINDICATOR_HEADER feature is retained, adapt the code so that the function names don't clash with dlsym
  • Move the function that converts an SDL_Surface to a Win32 HICON somewhere where it can be re-used?
  • Use a better mktemp-like mechanism with AppIndicator (SDL_CreateTempFolder?) (Not possible/worth it)
  • Properly set the ID of the tray on Unix
  • Properly integrate tests/testtray.c
  • Document the need for SDL_INIT_VIDEO on macOS
  • Review memory management (I wasn't particularly careful)
  • Remove the icon file generated for AppIndicator?
  • Convert windows functions ending in A (or without letter) to functions ending in W?
  • Decide how to handle the behavior of creating a system tray but failing to set an icon
  • Support DBus on Unix?

Existing Issue(s)

Closes #7822

Semphris added 7 commits September 23, 2024 14:31
- Windows: comparing int and size_t
- SDL_tray.h: int of (1 << 31) sets the sign bit, which causes an overflow warning
The image needs to be preserved throughout the lifetime of the indicator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for system tray icon?
1 participant