@@ -14,11 +14,17 @@ namespace nativeapi {
1414
1515/* *
1616 * Event class for display addition
17+ *
18+ * This event is emitted when a new display is connected to the system.
1719 */
1820class DisplayAddedEvent : public TypedEvent <DisplayAddedEvent> {
1921 public:
2022 explicit DisplayAddedEvent (const Display& display) : display_(display) {}
2123
24+ /* *
25+ * Get the added display information
26+ * @return Reference to the added display
27+ */
2228 const Display& GetDisplay () const { return display_; }
2329
2430 private:
@@ -27,11 +33,17 @@ class DisplayAddedEvent : public TypedEvent<DisplayAddedEvent> {
2733
2834/* *
2935 * Event class for display removal
36+ *
37+ * This event is emitted when a display is disconnected from the system.
3038 */
3139class DisplayRemovedEvent : public TypedEvent <DisplayRemovedEvent> {
3240 public:
3341 explicit DisplayRemovedEvent (const Display& display) : display_(display) {}
3442
43+ /* *
44+ * Get the removed display information
45+ * @return Reference to the removed display
46+ */
3547 const Display& GetDisplay () const { return display_; }
3648
3749 private:
@@ -40,23 +52,98 @@ class DisplayRemovedEvent : public TypedEvent<DisplayRemovedEvent> {
4052
4153/* *
4254 * DisplayManager is a singleton that manages all displays on the system.
55+ *
56+ * This class provides functionality to:
57+ * - Query all connected displays
58+ * - Get primary display information
59+ * - Monitor display changes (addition/removal)
60+ * - Get cursor position across displays
61+ *
62+ * The DisplayManager uses the singleton pattern to ensure there's only one
63+ * instance managing the display system throughout the application lifecycle.
64+ *
65+ * Thread Safety: This class is not thread-safe. External synchronization
66+ * is required if accessed from multiple threads.
67+ *
68+ * Example usage:
69+ * @code
70+ * DisplayManager& manager = DisplayManager::GetInstance();
71+ * std::vector<Display> displays = manager.GetAll();
72+ * Display primary = manager.GetPrimary();
73+ * @endcode
4374 */
4475class DisplayManager : public EventEmitter {
4576 public:
46- DisplayManager ();
77+ /* *
78+ * Get the singleton instance of DisplayManager
79+ * @return Reference to the singleton DisplayManager instance
80+ */
81+ static DisplayManager& GetInstance ();
82+
83+ /* *
84+ * @brief Destructor for DisplayManager.
85+ *
86+ * Cleans up all resources, stops event monitoring.
87+ * This is automatically called when the application terminates.
88+ */
4789 virtual ~DisplayManager ();
4890
49- // Get all displays information
91+ /* *
92+ * Get all connected displays information
93+ *
94+ * @return Vector containing all Display objects representing connected
95+ * displays. The vector may be empty if no displays are detected.
96+ * @note The returned vector is a snapshot of current displays at the time of
97+ * call
98+ */
5099 std::vector<Display> GetAll ();
51100
52- // Get the primary display information
101+ /* *
102+ * Get the primary display information
103+ *
104+ * The primary display is typically the main screen where the desktop
105+ * environment displays its primary interface elements.
106+ *
107+ * @return Display object representing the primary display
108+ * @throws std::runtime_error if no primary display is available
109+ */
53110 Display GetPrimary ();
54111
55- // Get the current cursor position
112+ /* *
113+ * Get the current cursor position in screen coordinates
114+ *
115+ * The coordinates are relative to the top-left corner of the primary display,
116+ * with positive X extending right and positive Y extending down.
117+ *
118+ * @return Point containing the current cursor coordinates (x, y)
119+ * @note The position is captured at the time of the function call
120+ */
56121 Point GetCursorPosition ();
57122
123+ // Prevent copy construction and assignment to maintain singleton property
124+ DisplayManager (const DisplayManager&) = delete ;
125+ DisplayManager& operator =(const DisplayManager&) = delete ;
126+ DisplayManager (DisplayManager&&) = delete ;
127+ DisplayManager& operator =(DisplayManager&&) = delete ;
128+
58129 private:
130+ /* *
131+ * @brief Private constructor to enforce singleton pattern.
132+ *
133+ * Initializes the DisplayManager instance and sets up initial state.
134+ */
135+ DisplayManager ();
136+
137+ /* *
138+ * Cached list of displays
139+ * Updated when display configuration changes are detected.
140+ */
59141 std::vector<Display> displays_;
142+
143+ /* *
144+ * Static instance holder for singleton pattern
145+ */
146+ static DisplayManager* instance_;
60147};
61148
62149} // namespace nativeapi
0 commit comments