Skip to content

Commit 997e911

Browse files
committed
Move display event classes to display_event.h
1 parent 782e7ab commit 997e911

File tree

3 files changed

+149
-36
lines changed

3 files changed

+149
-36
lines changed

include/nativeapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../src/accessibility_manager.h"
44
#include "../src/app_runner.h"
55
#include "../src/display.h"
6+
#include "../src/display_event.h"
67
#include "../src/display_manager.h"
78
#include "../src/event.h"
89
#include "../src/event_dispatcher.h"

src/display_event.h

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#pragma once
2+
#include <string>
3+
#include "display.h"
4+
#include "event.h"
5+
#include "geometry.h"
6+
7+
namespace nativeapi {
8+
9+
/**
10+
* Base class for all display-related events
11+
*
12+
* This class provides common functionality for display events,
13+
* including access to the display that triggered the event.
14+
*/
15+
class DisplayEvent : public Event {
16+
public:
17+
/**
18+
* Constructor for DisplayEvent
19+
* @param display The display associated with this event
20+
*/
21+
explicit DisplayEvent(const Display& display) : display_(display) {}
22+
23+
/**
24+
* Virtual destructor
25+
*/
26+
virtual ~DisplayEvent() = default;
27+
28+
/**
29+
* Get the display associated with this event
30+
* @return Reference to the display
31+
*/
32+
const Display& GetDisplay() const { return display_; }
33+
34+
/**
35+
* Get a string representation of the event type (for debugging)
36+
* Default implementation returns "DisplayEvent"
37+
*/
38+
std::string GetTypeName() const override { return "DisplayEvent"; }
39+
40+
private:
41+
Display display_;
42+
};
43+
44+
/**
45+
* Event class for display addition
46+
*
47+
* This event is emitted when a new display is connected to the system.
48+
*/
49+
class DisplayAddedEvent : public DisplayEvent {
50+
public:
51+
explicit DisplayAddedEvent(const Display& display) : DisplayEvent(display) {}
52+
53+
/**
54+
* Get a string representation of the event type
55+
*/
56+
std::string GetTypeName() const override { return "DisplayAddedEvent"; }
57+
58+
/**
59+
* Get the static type index for this event type
60+
*/
61+
static std::type_index GetStaticType() {
62+
return std::type_index(typeid(DisplayAddedEvent));
63+
}
64+
65+
/**
66+
* Get the type index for this event instance
67+
*/
68+
std::type_index GetType() const {
69+
return GetStaticType();
70+
}
71+
};
72+
73+
/**
74+
* Event class for display removal
75+
*
76+
* This event is emitted when a display is disconnected from the system.
77+
*/
78+
class DisplayRemovedEvent : public DisplayEvent {
79+
public:
80+
explicit DisplayRemovedEvent(const Display& display) : DisplayEvent(display) {}
81+
82+
/**
83+
* Get a string representation of the event type
84+
*/
85+
std::string GetTypeName() const override { return "DisplayRemovedEvent"; }
86+
87+
/**
88+
* Get the static type index for this event type
89+
*/
90+
static std::type_index GetStaticType() {
91+
return std::type_index(typeid(DisplayRemovedEvent));
92+
}
93+
94+
/**
95+
* Get the type index for this event instance
96+
*/
97+
std::type_index GetType() const {
98+
return GetStaticType();
99+
}
100+
};
101+
102+
/**
103+
* Event class for display configuration changes
104+
*
105+
* This event is emitted when a display's properties change (resolution, orientation, etc.).
106+
*/
107+
class DisplayChangedEvent : public DisplayEvent {
108+
public:
109+
DisplayChangedEvent(const Display& old_display, const Display& new_display)
110+
: DisplayEvent(new_display), old_display_(old_display) {}
111+
112+
/**
113+
* Get the display information before the change
114+
* @return Reference to the old display state
115+
*/
116+
const Display& GetOldDisplay() const { return old_display_; }
117+
118+
/**
119+
* Get the display information after the change
120+
* @return Reference to the new display state
121+
*/
122+
const Display& GetNewDisplay() const { return GetDisplay(); }
123+
124+
/**
125+
* Get a string representation of the event type
126+
*/
127+
std::string GetTypeName() const override { return "DisplayChangedEvent"; }
128+
129+
/**
130+
* Get the static type index for this event type
131+
*/
132+
static std::type_index GetStaticType() {
133+
return std::type_index(typeid(DisplayChangedEvent));
134+
}
135+
136+
/**
137+
* Get the type index for this event instance
138+
*/
139+
std::type_index GetType() const {
140+
return GetStaticType();
141+
}
142+
143+
private:
144+
Display old_display_;
145+
};
146+
147+
} // namespace nativeapi

src/display_manager.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,14 @@
66
#include <vector>
77

88
#include "display.h"
9+
#include "display_event.h"
910
#include "event.h"
1011
#include "event_emitter.h"
1112
#include "geometry.h"
1213

1314
namespace nativeapi {
1415

15-
/**
16-
* Event class for display addition
17-
*
18-
* This event is emitted when a new display is connected to the system.
19-
*/
20-
class DisplayAddedEvent : public TypedEvent<DisplayAddedEvent> {
21-
public:
22-
explicit DisplayAddedEvent(const Display& display) : display_(display) {}
23-
24-
/**
25-
* Get the added display information
26-
* @return Reference to the added display
27-
*/
28-
const Display& GetDisplay() const { return display_; }
29-
30-
private:
31-
Display display_;
32-
};
3316

34-
/**
35-
* Event class for display removal
36-
*
37-
* This event is emitted when a display is disconnected from the system.
38-
*/
39-
class DisplayRemovedEvent : public TypedEvent<DisplayRemovedEvent> {
40-
public:
41-
explicit DisplayRemovedEvent(const Display& display) : display_(display) {}
42-
43-
/**
44-
* Get the removed display information
45-
* @return Reference to the removed display
46-
*/
47-
const Display& GetDisplay() const { return display_; }
48-
49-
private:
50-
Display display_;
51-
};
5217

5318
/**
5419
* DisplayManager is a singleton that manages all displays on the system.

0 commit comments

Comments
 (0)