Skip to content

Commit e23ab87

Browse files
committed
Remove legacy display listener system and related code
1 parent 5bea6ba commit e23ab87

File tree

6 files changed

+16
-118
lines changed

6 files changed

+16
-118
lines changed

examples/window_example/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ int main() {
1919
options.size.height = 600;
2020
std::shared_ptr<Window> window_ptr = window_manager.Create(options);
2121

22-
2322
std::shared_ptr<Tray> tray_ptr = tray_manager.Create();
2423
if (tray_ptr != nullptr) {
2524
Tray& tray = *tray_ptr;

src/display_manager.cpp

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,3 @@
11
#include "display_manager.h"
2-
#include <algorithm>
32

4-
namespace nativeapi {
5-
6-
void DisplayManager::AddListener(DisplayListener* listener) {
7-
listeners_.push_back(listener);
8-
}
9-
10-
void DisplayManager::RemoveListener(DisplayListener* listener) {
11-
listeners_.erase(std::remove(listeners_.begin(), listeners_.end(), listener),
12-
listeners_.end());
13-
}
14-
15-
void DisplayManager::NotifyListeners(
16-
std::function<void(DisplayListener*)> callback) {
17-
for (const auto& listener : listeners_) {
18-
callback(listener);
19-
}
20-
}
21-
22-
void DisplayManager::DispatchDisplayAddedEvent(const Display& display) {
23-
// Dispatch through the new event system
24-
event_dispatcher_.DispatchSync<DisplayAddedEvent>(display);
25-
26-
// Also notify old-style listeners for backward compatibility
27-
NotifyListeners([&display](DisplayListener* listener) {
28-
listener->OnDisplayAdded(display);
29-
});
30-
}
31-
32-
void DisplayManager::DispatchDisplayRemovedEvent(const Display& display) {
33-
// Dispatch through the new event system
34-
event_dispatcher_.DispatchSync<DisplayRemovedEvent>(display);
35-
36-
// Also notify old-style listeners for backward compatibility
37-
NotifyListeners([&display](DisplayListener* listener) {
38-
listener->OnDisplayRemoved(display);
39-
});
40-
}
41-
42-
DisplayEventHandler::DisplayEventHandler(
43-
std::function<void(const Display&)> onDisplayAddedCallback,
44-
std::function<void(const Display&)> onDisplayRemovedCallback)
45-
: onDisplayAddedCallback_(onDisplayAddedCallback),
46-
onDisplayRemovedCallback_(onDisplayRemovedCallback) {}
47-
48-
void DisplayEventHandler::OnDisplayAdded(const Display& display) {
49-
if (onDisplayAddedCallback_) {
50-
onDisplayAddedCallback_(display);
51-
}
52-
}
53-
54-
void DisplayEventHandler::OnDisplayRemoved(const Display& display) {
55-
if (onDisplayRemovedCallback_) {
56-
onDisplayRemovedCallback_(display);
57-
}
58-
}
59-
60-
} // namespace nativeapi
3+
namespace nativeapi {}

src/display_manager.h

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace nativeapi {
1414

15-
// Event classes for display changes
15+
/**
16+
* Event class for display addition
17+
*/
1618
class 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+
*/
2631
class 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+
*/
4544
class 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

src/event_dispatcher.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,4 @@ void EventDispatcher::ProcessAsyncEvents() {
180180
}
181181
}
182182

183-
EventDispatcher& GetGlobalEventDispatcher() {
184-
static EventDispatcher global_dispatcher;
185-
return global_dispatcher;
186-
}
187-
188183
} // namespace nativeapi

src/event_dispatcher.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,4 @@ class EventDispatcher {
179179
std::atomic<size_t> next_listener_id_;
180180
};
181181

182-
/**
183-
* Convenience function to create a global event dispatcher instance.
184-
* This is useful for applications that need a single, shared event system.
185-
*/
186-
EventDispatcher& GetGlobalEventDispatcher();
187182
} // namespace nativeapi

src/platform/macos/display_manager_macos.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static Display CreateDisplayFromNSScreen(NSScreen* screen, bool isPrimary) {
111111
old_ids.insert(d.id);
112112
for (const auto& d : new_displays) {
113113
if (old_ids.find(d.id) == old_ids.end()) {
114-
DispatchDisplayAddedEvent(d);
114+
GetEventDispatcher().DispatchSync<DisplayAddedEvent>(d);
115115
}
116116
}
117117

@@ -121,7 +121,7 @@ static Display CreateDisplayFromNSScreen(NSScreen* screen, bool isPrimary) {
121121
new_ids.insert(d.id);
122122
for (const auto& d : old_displays) {
123123
if (new_ids.find(d.id) == new_ids.end()) {
124-
DispatchDisplayRemovedEvent(d);
124+
GetEventDispatcher().DispatchSync<DisplayRemovedEvent>(d);
125125
}
126126
}
127127

0 commit comments

Comments
 (0)