tray latest
Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.
Overview

GitHub Workflow Status (CI) Codecov GitHub stars

About

Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.

The code is C++ friendly and will compile fine in C++98 and up. This is a fork of dmikushin/tray and is intended to add additional features required for our own Sunshine project.

This fork adds the following features:

  • system tray notifications
  • support for both linux appindicator versions
  • unit tests
  • code coverage
  • refactored code, e.g. moved source code into the src directory
  • doxygen documentation, and readthedocs configuration

Screenshots

  • Linux
  • macOS
  • Windows

Supported platforms

  • Linux/Gtk (libayatana-appindicator3 or libappindicator3)
  • Windows XP or newer (shellapi.h)
  • MacOS (Cocoa/AppKit)

Prerequisites

  • CMake
  • Ninja, in order to have the same build commands on all platforms

Linux Dependencies

  • Arch
    sudo pacman -S libayatana-appindicator
  • Debian/Ubuntu
    sudo apt install libappindicator3-dev
  • Fedora
    sudo dnf install libappindicator-gtk3-devel

Building

mkdir -p build
cmake -G Ninja -B build -S .
ninja -C build

Demo

Execute the tray_example application:

./build/tray_example

Tests

Execute the tests application:

./build/tests/test_tray

API

Tray structure defines an icon and a menu. Menu is a NULL-terminated array of items. Menu item defines menu text, menu checked and disabled (grayed) flags and a callback with some optional context pointer.

struct tray {
char *icon;
struct tray_menu *menu;
};
struct tray_menu {
char *text;
int disabled;
int checked;
void (*cb)(struct tray_menu *);
void *context;
struct tray_menu *submenu;
};
Tray menu item.
Definition tray.h:35
void * context
Context to pass to the callback.
Definition tray.h:42
struct tray_menu * submenu
Submenu items.
Definition tray.h:44
void(* cb)(struct tray_menu *)
Callback to invoke when the item is clicked.
Definition tray.h:41
int disabled
Whether the item is disabled.
Definition tray.h:37
const char * text
Text to display.
Definition tray.h:36
int checked
Whether the item is checked.
Definition tray.h:38
Tray icon.
Definition tray.h:20
struct tray_menu * menu
Menu items.
Definition tray.h:27
const char * icon
Icon to display.
Definition tray.h:21

All functions are meant to be called from the UI thread only.

Menu arrays must be terminated with a NULL item, e.g. the last item in the array must have text field set to NULL.

License

This software is distributed under MIT license, so feel free to integrate it in your commercial products.