![]() |
tray latest
Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.
|
System tray implementation for Linux using Qt. More...
#include <atomic>#include <cstdint>#include <cstring>#include <filesystem>#include <memory>#include <mutex>#include <string>#include <thread>#include <utility>#include <libnotify/notify.h>#include "QtTrayMenu.h"#include "tray.h"Classes | |
| struct | tray_linux::notification_data |
Functions | |
| void | tray_linux::acknowledge_notifications (bool run_callback=false) |
| Acknowledge/click current notifications. | |
| void | tray_linux::async_tray_notification_acknowledge_ (const std::shared_ptr< notification_data > ¬ification, int timeout=1000) |
| Acknowledge notification asynchronously with timeout to avoid Dbus lockups. | |
| void | tray_linux::async_tray_notification_show_ (const std::shared_ptr< notification_data > ¬ification, int timeout=1000) |
| Show notification asynchronously with timeout to avoid Dbus lockups. | |
| bool | tray_linux::init_notify (const char *app_name) |
| Initialize notifications. | |
| void | tray_linux::notify (struct tray *tray) |
| Show tray notification via desktop-independent interface. | |
| void | tray_linux::qt_message_handler (QtMsgType type, const QMessageLogContext &, const QString &msg) |
| Qt message handler that forwards to the registered log callback. | |
| void | tray_linux::set_notify_app_info (const char *app_name) |
| Update notification app name. | |
| void | tray_exit (void) |
| Terminate UI loop. | |
| int | tray_init (struct tray *tray) |
| Create tray icon. | |
| int | tray_loop (int blocking) |
| Run one iteration of the UI loop. | |
| void | tray_set_app_info (const char *app_name, const char *app_display_name, const char *desktop_name) |
| Set application metadata used by the tray library. | |
| void | tray_set_log_callback (void(*cb)(int level, const char *msg)) |
| Set a callback for log messages produced by the tray library. | |
| void | tray_show_menu (void) |
| Force show the tray menu (for testing purposes). | |
| void | tray_simulate_menu_item_click (int index) |
| Simulate clicking a top-level menu item by index (for testing purposes). | |
| void | tray_simulate_notification_click (void) |
| Simulate a notification click, invoking the notification callback (for testing purposes). | |
| void | tray_update (struct tray *tray) |
| Update the tray icon and menu. | |
| void | tray_linux::uninit_notify () |
| Uninitialize notifications. | |
Variables | |
| void(* | tray_linux::log_callback )(int, const char *) = nullptr |
| std::vector< std::shared_ptr< notification_data > > | tray_linux::notifications |
| std::mutex | tray_linux::notifications_mutex |
| std::unique_ptr< QtTrayMenu > | tray_linux::qt_tray_menu = nullptr |
System tray implementation for Linux using Qt.
| void tray_linux::acknowledge_notifications | ( | bool | run_callback = false | ) |
Acknowledge/click current notifications.
| run_callback | - Run notification callback when acknowledging |
| void tray_linux::async_tray_notification_acknowledge_ | ( | const std::shared_ptr< notification_data > & | notification, |
| int | timeout = 1000 ) |
Acknowledge notification asynchronously with timeout to avoid Dbus lockups.
| notification | - Tray notification to close |
| timeout | - optional timeout for async run in ms (default: 1000) |
| void tray_linux::async_tray_notification_show_ | ( | const std::shared_ptr< notification_data > & | notification, |
| int | timeout = 1000 ) |
Show notification asynchronously with timeout to avoid Dbus lockups.
| notification | - Tray notification to show |
| timeout | - optional timeout for async run in ms (default: 1000) |
| bool tray_linux::init_notify | ( | const char * | app_name | ) |
Initialize notifications.
| app_name | application name for notifications |
| void tray_linux::notify | ( | struct tray * | tray | ) |
Show tray notification via desktop-independent interface.
| tray | Tray structure containing notification information |
| void tray_linux::qt_message_handler | ( | QtMsgType | type, |
| const QMessageLogContext & | , | ||
| const QString & | msg ) |
Qt message handler that forwards to the registered log callback.
| type | The Qt message type. |
| msg | The message string. |
| void tray_linux::set_notify_app_info | ( | const char * | app_name | ) |
Update notification app name.
| app_name | the current application name |
| int tray_init | ( | struct tray * | tray | ) |
Create tray icon.
| tray | The tray to initialize. |
| int tray_loop | ( | int | blocking | ) |
Run one iteration of the UI loop.
| blocking | Whether to block the call or not. |
| void tray_set_app_info | ( | const char * | app_name, |
| const char * | app_display_name, | ||
| const char * | desktop_name ) |
Set application metadata used by the tray library.
Must be called before tray_init(). On Linux (Qt), sets the Qt application name, display name, and desktop file name used for D-Bus registration. On other platforms this function is a no-op.
| app_name | Application name used as a technical identifier (e.g., for D-Bus registration). Converted to lowercase automatically. NULL uses the default ("tray"). |
| app_display_name | Human-readable name shown in notifications and UI. NULL derives from the tray tooltip or falls back to app_name. |
| desktop_name | Desktop file name for D-Bus. NULL appends ".desktop" to app_name. |
| void tray_set_log_callback | ( | void(* | cb )(int level, const char *msg) | ) |
Set a callback for log messages produced by the tray library.
On Linux the callback is installed as a Qt message handler so all Qt diagnostic output is routed through it. On other platforms this function is a no-op.
| cb | Callback invoked with level (0=debug, 1=info, 2=warning, 3=error) and the message string. Pass NULL to restore the default logging behaviour. |
| void tray_simulate_menu_item_click | ( | int | index | ) |
Simulate clicking a top-level menu item by index (for testing purposes).
On Linux (Qt): triggers the QAction associated with the given top-level menu index (separators and submenus are ignored). On other platforms: no-op.
| index | Zero-based index in the top-level tray menu. |
| void tray_simulate_notification_click | ( | void | ) |
Simulate a notification click, invoking the notification callback (for testing purposes).
On Linux (Qt): triggers the stored notification callback as if the user clicked the notification. On other platforms: no-op.
| void tray_update | ( | struct tray * | tray | ) |
Update the tray icon and menu.
| tray | The tray to update. |
| void(* tray_linux::log_callback) (int, const char *) | ( | int | , |
| const char * | ) = nullptr |
Logging callback for qt_message_handler
| std::vector<std::shared_ptr<notification_data> > tray_linux::notifications |
Currently shown notifications
| std::mutex tray_linux::notifications_mutex |
Lock for currently shown notifications vector
| std::unique_ptr<QtTrayMenu> tray_linux::qt_tray_menu = nullptr |
QtTrayMenu instance