Skip to content

Commit 526c1aa

Browse files
committed
refactor: Rearrange GetCursorPosition and GetAll methods in DisplayManager for consistency across platforms
1 parent 6f8471a commit 526c1aa

4 files changed

+45
-60
lines changed

src/display_manager.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class DisplayManager {
2424
DisplayManager();
2525
virtual ~DisplayManager();
2626

27-
// Get the current cursor position
28-
Point GetCursorPosition();
29-
3027
// Get all displays information
3128
std::vector<Display> GetAll();
3229

3330
// Get the primary display information
3431
Display GetPrimary();
3532

33+
// Get the current cursor position
34+
Point GetCursorPosition();
35+
3636
// Add a listener to the display manager
3737
void AddListener(DisplayListener* listener);
3838

src/display_manager_linux.cpp

+16-21
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,11 @@ DisplayManager::DisplayManager() {
3636
std::cout << "DisplayManager initialized" << std::endl;
3737
}
3838

39-
DisplayManager::~DisplayManager() {
40-
// Destructor implementation
41-
std::cout << "DisplayManager destroyed" << std::endl;
42-
}
43-
44-
Point DisplayManager::GetCursorPosition() {
45-
GdkDisplay* display = gdk_display_get_default();
46-
GdkSeat* seat = gdk_display_get_default_seat(display);
47-
GdkDevice* pointer = gdk_seat_get_pointer(seat);
48-
49-
int x, y;
50-
gdk_device_get_position(pointer, NULL, &x, &y);
51-
39+
std::vector<Display> DisplayManager::GetAll() {
5240
// Empty implementation
53-
Point point;
54-
point.x = x;
55-
point.y = y;
56-
return point;
41+
std::vector<Display> displayList;
42+
displayList.push_back(GetPrimary());
43+
return displayList;
5744
}
5845

5946
Display DisplayManager::GetPrimary() {
@@ -71,11 +58,19 @@ Display DisplayManager::GetPrimary() {
7158
return CreateDisplayFromGdkMonitor(monitor, true);
7259
}
7360

74-
std::vector<Display> DisplayManager::GetAll() {
61+
Point DisplayManager::GetCursorPosition() {
62+
GdkDisplay* display = gdk_display_get_default();
63+
GdkSeat* seat = gdk_display_get_default_seat(display);
64+
GdkDevice* pointer = gdk_seat_get_pointer(seat);
65+
66+
int x, y;
67+
gdk_device_get_position(pointer, NULL, &x, &y);
68+
7569
// Empty implementation
76-
std::vector<Display> displayList;
77-
displayList.push_back(GetPrimary());
78-
return displayList;
70+
Point point;
71+
point.x = x;
72+
point.y = y;
73+
return point;
7974
}
8075

8176
} // namespace nativeapi

src/display_manager_macos.mm

+8-8
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ static Display CreateDisplayFromNSScreen(NSScreen* screen, bool isPrimary) {
9191
}
9292
}
9393

94-
Point DisplayManager::GetCursorPosition() {
95-
NSPoint mouseLocation = [NSEvent mouseLocation];
96-
Point point;
97-
point.x = mouseLocation.x;
98-
point.y = mouseLocation.y;
99-
return point;
100-
}
101-
10294
std::vector<Display> DisplayManager::GetAll() {
10395
std::vector<Display> displayList;
10496
NSArray<NSScreen*>* screens = [NSScreen screens];
@@ -116,4 +108,12 @@ static Display CreateDisplayFromNSScreen(NSScreen* screen, bool isPrimary) {
116108
return CreateDisplayFromNSScreen(screens[0], true);
117109
}
118110

111+
Point DisplayManager::GetCursorPosition() {
112+
NSPoint mouseLocation = [NSEvent mouseLocation];
113+
Point point;
114+
point.x = mouseLocation.x;
115+
point.y = mouseLocation.y;
116+
return point;
117+
}
118+
119119
} // namespace nativeapi

src/display_manager_windows.cpp

+18-28
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,6 @@ Display CreateDisplayFromMonitor(HMONITOR monitor, bool isMainScreen) {
6565

6666
return display;
6767
}
68-
DisplayManager::DisplayManager() {
69-
// Constructor implementation
70-
std::cout << "DisplayManager initialized" << std::endl;
71-
}
72-
73-
DisplayManager::~DisplayManager() {
74-
// Destructor implementation
75-
std::cout << "DisplayManager destroyed" << std::endl;
76-
}
77-
78-
Point DisplayManager::GetCursorScreenPoint() {
79-
POINT cursorPos;
80-
GetCursorPos(&cursorPos);
81-
82-
Point point;
83-
point.x = cursorPos.x;
84-
point.y = cursorPos.y;
85-
return point;
86-
}
87-
88-
Display DisplayManager::GetPrimaryDisplay() {
89-
POINT ptZero = {0, 0};
90-
HMONITOR monitor = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
91-
Display display = CreateDisplayFromMonitor(monitor, true);
92-
display.id = "";
93-
return display;
94-
}
9568

9669
BOOL CALLBACK MonitorRepresentationEnumProc(HMONITOR monitor,
9770
HDC hdc,
@@ -104,11 +77,28 @@ BOOL CALLBACK MonitorRepresentationEnumProc(HMONITOR monitor,
10477
return TRUE;
10578
}
10679

107-
std::vector<Display> DisplayManager::GetAllDisplays() {
80+
std::vector<Display> DisplayManager::GetAll() {
10881
std::vector<Display> displayList;
10982
::EnumDisplayMonitors(nullptr, nullptr, MonitorRepresentationEnumProc,
11083
reinterpret_cast<LPARAM>(&displayList));
11184
return displayList;
11285
}
11386

87+
Display DisplayManager::GetPrimary() {
88+
POINT ptZero = {0, 0};
89+
HMONITOR monitor = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
90+
Display display = CreateDisplayFromMonitor(monitor, true);
91+
display.id = "";
92+
return display;
93+
}
94+
95+
Point DisplayManager::GetCursorPosition() {
96+
POINT cursorPos;
97+
GetCursorPos(&cursorPos);
98+
99+
Point point;
100+
point.x = cursorPos.x;
101+
point.y = cursorPos.y;
102+
return point;
103+
}
114104
} // namespace nativeapi

0 commit comments

Comments
 (0)