1212
1313namespace nativeapi {
1414
15- // Event classes for display changes
15+ /* *
16+ * Event class for display addition
17+ */
1618class DisplayAddedEvent : public TypedEvent <DisplayAddedEvent> {
1719 public:
1820 explicit DisplayAddedEvent (const Display& display) : display_(display) {}
@@ -23,6 +25,9 @@ class DisplayAddedEvent : public TypedEvent<DisplayAddedEvent> {
2325 Display display_;
2426};
2527
28+ /* *
29+ * Event class for display removal
30+ */
2631class DisplayRemovedEvent : public TypedEvent <DisplayRemovedEvent> {
2732 public:
2833 explicit DisplayRemovedEvent (const Display& display) : display_(display) {}
@@ -33,15 +38,9 @@ class DisplayRemovedEvent : public TypedEvent<DisplayRemovedEvent> {
3338 Display display_;
3439};
3540
36- // DisplayListener is an interface that can be implemented by classes that want
37- // to listen for display events.
38- class DisplayListener {
39- public:
40- virtual void OnDisplayAdded (const Display& display) = 0;
41- virtual void OnDisplayRemoved (const Display& display) = 0;
42- };
43-
44- // DisplayManager is a singleton that manages all displays on the system.
41+ /* *
42+ * DisplayManager is a singleton that manages all displays on the system.
43+ */
4544class DisplayManager {
4645 public:
4746 DisplayManager ();
@@ -56,60 +55,27 @@ class DisplayManager {
5655 // Get the current cursor position
5756 Point GetCursorPosition ();
5857
59- // Add a listener to the display manager
60- void AddListener (DisplayListener* listener);
61-
62- // Remove a listener from the display manager
63- void RemoveListener (DisplayListener* listener);
64-
6558 // Event dispatcher methods for the new system
6659 template <typename EventType>
67- size_t AddEventListener (TypedEventListener<EventType>* listener) {
60+ size_t AddListener (TypedEventListener<EventType>* listener) {
6861 return event_dispatcher_.AddListener <EventType>(listener);
6962 }
7063
7164 template <typename EventType>
72- size_t AddEventListener (std::function<void (const EventType&)> callback) {
65+ size_t AddListener (std::function<void (const EventType&)> callback) {
7366 return event_dispatcher_.AddListener <EventType>(std::move (callback));
7467 }
7568
76- bool RemoveEventListener (size_t listener_id) {
69+ bool RemoveListener (size_t listener_id) {
7770 return event_dispatcher_.RemoveListener (listener_id);
7871 }
7972
8073 // Get the event dispatcher (for advanced usage)
8174 EventDispatcher& GetEventDispatcher () { return event_dispatcher_; }
8275
8376 private:
77+ EventDispatcher event_dispatcher_;
8478 std::vector<Display> displays_;
85- std::vector<DisplayListener*> listeners_; // For backward compatibility
86- EventDispatcher event_dispatcher_; // New event system
87-
88- void NotifyListeners (std::function<void (DisplayListener*)> callback);
89-
90- // New event dispatch methods
91- void DispatchDisplayAddedEvent (const Display& display);
92- void DispatchDisplayRemovedEvent (const Display& display);
93- };
94-
95- // DisplayEventHandler is an implementation of DisplayListener that uses
96- // callbacks to handle display events.
97- class DisplayEventHandler : public DisplayListener {
98- public:
99- // Constructor that takes callbacks for display events
100- DisplayEventHandler (
101- std::function<void (const Display&)> onDisplayAddedCallback,
102- std::function<void (const Display&)> onDisplayRemovedCallback);
103-
104- // Implementation of OnDisplayAdded from DisplayListener interface
105- void OnDisplayAdded (const Display& display) override ;
106-
107- // Implementation of OnDisplayRemoved from DisplayListener interface
108- void OnDisplayRemoved (const Display& display) override ;
109-
110- private:
111- std::function<void (const Display&)> onDisplayAddedCallback_;
112- std::function<void (const Display&)> onDisplayRemovedCallback_;
11379};
11480
11581} // namespace nativeapi
0 commit comments