File tree 3 files changed +49
-3
lines changed
3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 2
2
#include " nativeapi.h"
3
3
4
4
using nativeapi::Display;
5
- using nativeapi::Point ;
5
+ using nativeapi::DisplayEventHandler ;
6
6
using nativeapi::DisplayManager;
7
+ using nativeapi::Point ;
7
8
8
9
int main () {
9
10
DisplayManager displayManager = DisplayManager ();
10
11
12
+ // DisplayEventHandler displayEventHandler = DisplayEventHandler(
13
+ // [](const Display& display) {
14
+ // std::cout << "Display added: " << display.id << std::endl;
15
+ // },
16
+ // [](const Display& display) {
17
+ // std::cout << "Display removed: " << display.id << std::endl;
18
+ // });
19
+ // displayManager.AddListener(&displayEventHandler);
20
+
11
21
// Get primary display information
12
22
Display primaryDisplay = displayManager.GetPrimary ();
13
23
std::cout << " Primary Display Information:" << std::endl;
Original file line number Diff line number Diff line change 1
- #include < set>
2
-
3
1
#include " display_manager.h"
4
2
5
3
namespace nativeapi {
@@ -25,4 +23,22 @@ void DisplayManager::NotifyDisplayRemoved(const Display& display) {
25
23
}
26
24
}
27
25
26
+ DisplayEventHandler::DisplayEventHandler (
27
+ std::function<void (const Display&)> onDisplayAddedCallback,
28
+ std::function<void (const Display&)> onDisplayRemovedCallback)
29
+ : onDisplayAddedCallback_(onDisplayAddedCallback),
30
+ onDisplayRemovedCallback_ (onDisplayRemovedCallback) {}
31
+
32
+ void DisplayEventHandler::OnDisplayAdded (const Display& display) {
33
+ if (onDisplayAddedCallback_) {
34
+ onDisplayAddedCallback_ (display);
35
+ }
36
+ }
37
+
38
+ void DisplayEventHandler::OnDisplayRemoved (const Display& display) {
39
+ if (onDisplayRemovedCallback_) {
40
+ onDisplayRemovedCallback_ (display);
41
+ }
42
+ }
43
+
28
44
} // namespace nativeapi
Original file line number Diff line number Diff line change @@ -46,4 +46,24 @@ class DisplayManager {
46
46
void NotifyDisplayRemoved (const Display& display);
47
47
};
48
48
49
+ // DisplayEventHandler is an implementation of DisplayListener that uses
50
+ // callbacks to handle display events.
51
+ class DisplayEventHandler : public DisplayListener {
52
+ public:
53
+ // Constructor that takes callbacks for display events
54
+ DisplayEventHandler (
55
+ std::function<void (const Display&)> onDisplayAddedCallback,
56
+ std::function<void (const Display&)> onDisplayRemovedCallback);
57
+
58
+ // Implementation of OnDisplayAdded from DisplayListener interface
59
+ void OnDisplayAdded (const Display& display) override ;
60
+
61
+ // Implementation of OnDisplayRemoved from DisplayListener interface
62
+ void OnDisplayRemoved (const Display& display) override ;
63
+
64
+ private:
65
+ std::function<void (const Display&)> onDisplayAddedCallback_;
66
+ std::function<void (const Display&)> onDisplayRemovedCallback_;
67
+ };
68
+
49
69
} // namespace nativeapi
You can’t perform that action at this time.
0 commit comments