1. Overview
StatusNotifierItem and DBusMenu implementation built directly on systemd sd-bus. It exposes the BastionGuard tray icon, tooltip, activation actions, persistent-startup action, and quit command.
File role: Header Interface. The file contains 131 lines and belongs to the TrayIcon.hpp path.
The companion file is TrayIcon.cpp.
2. Component Responsibilities
- Declare the component API, owned state, callbacks, and data structures.
- Generate a unique D-Bus service name
- Acquire the user session bus and request the service name
- Export StatusNotifierItem and DBusMenu objects
- Register with the desktop StatusNotifierWatcher
- Process D-Bus traffic in a dedicated worker thread
- Marshal menu callbacks back to the bound GLib UI context
- Unexport objects and release the bus during shutdown
3. Dependencies and Integration
Project-level dependencies:
systemd/sd-bus.hglib.h
System and library dependencies:
atomicfunctionalstringthreadvector
4. Declared Types
TrayIcon
Declares a class.
5. Constants and Fixed Configuration
The file declares or uses the following fixed values:
static constexpr int MENU_ROOT = 0;
static constexpr int MENU_SHOW = 1;
static constexpr int MENU_PERSIST_STARTUP = 2;
static constexpr int MENU_QUIT = 3;
6. Owned State and UI Members
Threading, dispatch, and callback state
GMainContext* ui_ctx_ = nullptr;std::thread bus_thread_;std::atomic_bool running_{false};
Data and configuration state
std::string service_name_;std::string id_ = "bastionguard-sc";std::string title_ = "BastionGuard⢠Secure Connection";std::string icon_name_ = "security-high";std::string tooltip_ = "BastionGuard⢠Secure Connection";std::string status_ = "Active";bool have_pixmap_ = false;int pix_w_ = 0;int pix_h_ = 0;std::vector<uint8_t> pix_rgba_;sd_bus* bus_ = nullptr;sd_bus_slot* sni_slot_ = nullptr;sd_bus_slot* menu_slot_ = nullptr;static constexpr int MENU_ROOT = 0;static constexpr int MENU_SHOW = 1;static constexpr int MENU_PERSIST_STARTUP = 2;static constexpr int MENU_QUIT = 3;
7. Signals and Event Integration
The file exposes or connects the following signal-related elements:
void emit_sni_signal(const char* signal_name);
GTK-facing callbacks must execute on the main UI context. Components with worker threads use dispatchers or idle callbacks to cross the thread boundary.
8. Functions and Methods
The file exposes or implements 36 detected function or method signatures.
1. TrayIcon
TrayIcon()
Implements the tray icon operation declared by this component.
2. ~TrayIcon
~TrayIcon()
Releases resources owned by the object and stops any active background integration.
3. start
bool start()
Starts start and activates the associated runtime resources.
4. stop
void stop()
Stops stop and releases or signals its active resources.
5. set_icon
void set_icon(const std::string& icon_name)
Updates icon and synchronizes dependent state.
6. set_icon_file
void set_icon_file(const std::string& png_path, int target_px = 22)
Updates icon file and synchronizes dependent state.
7. set_tooltip
void set_tooltip(const std::string& text)
Updates tooltip and synchronizes dependent state.
8. set_title
void set_title(const std::string& title)
Updates title and synchronizes dependent state.
9. bind_ui_context
void bind_ui_context()
Binds ui context to the active execution context.
10. sni_method_activate
static int sni_method_activate(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
11. sni_method_context_menu
static int sni_method_context_menu(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
12. sni_method_secondary_activate
static int sni_method_secondary_activate(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
13. sni_prop_get
static int sni_prop_get(sd_bus* bus, const char* path, const char* interface, const char* property, sd_bus_message* reply, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
14. dbusmenu_method_event_group
static int dbusmenu_method_event_group(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
15. dbusmenu_method_about_to_show_group
static int dbusmenu_method_about_to_show_group(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
16. dbusmenu_method_get_layout
static int dbusmenu_method_get_layout(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
17. dbusmenu_method_get_children
static int dbusmenu_method_get_children(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
18. dbusmenu_method_get_group_properties
static int dbusmenu_method_get_group_properties(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
19. dbusmenu_method_get_property
static int dbusmenu_method_get_property(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
20. dbusmenu_method_get_status
static int dbusmenu_method_get_status(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
21. dbusmenu_method_event
static int dbusmenu_method_event(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
22. dbusmenu_method_about_to_show
static int dbusmenu_method_about_to_show(sd_bus_message* m, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
23. dbusmenu_prop_get
static int dbusmenu_prop_get(sd_bus* bus, const char* path, const char* interface, const char* property, sd_bus_message* reply, void* userdata, sd_bus_error* ret_error)
Implements the corresponding D-Bus method or property callback required by the StatusNotifierItem/DBusMenu protocol.
24. make_service_name
static std::string make_service_name()
Creates or derives service name.
25. acquire_bus
bool acquire_bus()
Acquires bus and stores the resulting handle.
26. request_name
bool request_name()
Implements the request name operation declared by this component.
27. release_bus
void release_bus()
Releases bus.
28. export_objects
bool export_objects()
Exports objects through the relevant interface.
29. unexport_objects
void unexport_objects()
Removes the exported objects.
30. register_to_watcher
bool register_to_watcher()
Registers to watcher with the external subsystem.
31. bus_loop
void bus_loop()
Runs the bus loop until shutdown or disconnection.
32. emit_sni_signal
void emit_sni_signal(const char* signal_name)
Emits sni signal to subscribed components.
33. emit_dbusmenu_layout_updated
void emit_dbusmenu_layout_updated()
Emits dbusmenu layout updated to subscribed components.
34. set_on_activate
void set_on_activate(std::function<void()> cb)
Updates on activate and synchronizes dependent state.
35. set_on_make_startup_persistent
void set_on_make_startup_persistent(std::function<void()> cb)
Updates on make startup persistent and synchronizes dependent state.
36. set_on_quit
void set_on_quit(std::function<void()> cb)
Updates on quit and synchronizes dependent state.
9. Runtime Flow
- Generate a unique D-Bus service name
- Acquire the user session bus and request the service name
- Export StatusNotifierItem and DBusMenu objects
- Register with the desktop StatusNotifierWatcher
- Process D-Bus traffic in a dedicated worker thread
- Marshal menu callbacks back to the bound GLib UI context
- Unexport objects and release the bus during shutdown
10. Concurrency and Main-Loop Behavior
- Uses one or more C++ worker threads.
- Uses atomic state for cross-thread lifecycle control.
11. Runtime and Security Considerations
- Runs D-Bus handling in a dedicated thread guarded by an atomic running flag.
- Marshals callbacks to the GTK main context instead of directly invoking UI operations from the bus thread.
- Exports a fixed and minimal tray-menu command set.
12. Error Handling and Operational Notes
- Errors are propagated through the return type, callbacks, or the owning controller.
13. Source Integrity
Relative source path: TrayIcon.hpp
SHA-256:
a31e9ccd0ff22305818246ae605a60f2b59a2ed9f6c35f034b017e6adcb41622
14. Licensing
The source header identifies this component as distributed under the GNU General Public License version 3. BastionGuard branding and trademarks remain subject to the notices stated in the source file.
