Skip to content

Commit 8bf4721

Browse files
committed
refactor: Update screen retriever implementation to use nativeapi namespace and adjust header inclusions
1 parent 659ec73 commit 8bf4721

13 files changed

+111
-53
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
build/
1+
.idea/
2+
build/
3+
cmake-build-debug/

examples/screen_info/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include "libnativeapi.h"
33

44
int main() {
5-
auto screenRetriever = ScreenRetriever::Create();
5+
auto screenRetriever = nativeapi::ScreenRetriever::Create();
66

77
// Get primary display information
8-
Display primaryDisplay = screenRetriever->GetPrimaryDisplay();
8+
nativeapi::Display primaryDisplay = screenRetriever->GetPrimaryDisplay();
99
std::cout << "Primary Display Information:" << std::endl;
1010
std::cout << "ID: " << primaryDisplay.id << std::endl;
1111
std::cout << "Name: " << primaryDisplay.name << std::endl;
@@ -19,10 +19,10 @@ int main() {
1919
std::cout << std::endl;
2020

2121
// Get all displays information
22-
DisplayList allDisplays = screenRetriever->GetAllDisplays();
22+
nativeapi::DisplayList allDisplays = screenRetriever->GetAllDisplays();
2323
std::cout << "All Displays Information:" << std::endl;
2424
for (int i = 0; i < allDisplays.count; i++) {
25-
Display& display = allDisplays.displays[i];
25+
nativeapi::Display& display = allDisplays.displays[i];
2626
std::cout << "Display " << (i + 1) << ":" << std::endl;
2727
std::cout << "ID: " << display.id << std::endl;
2828
std::cout << "Name: " << display.name << std::endl;
@@ -34,10 +34,10 @@ int main() {
3434
std::cout << "Visible Size: " << display.visibleSizeWidth << "x"
3535
<< display.visibleSizeHeight << std::endl;
3636
std::cout << std::endl;
37-
}
37+
}
3838

3939
// Get cursor position
40-
CursorPoint cursorPoint = screenRetriever->GetCursorScreenPoint();
40+
nativeapi::Point cursorPoint = screenRetriever->GetCursorScreenPoint();
4141
std::cout << "Current Cursor Position: (" << cursorPoint.x << ", "
4242
<< cursorPoint.y << ")" << std::endl;
4343

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ add_library(libnativeapi STATIC
3333

3434
# Set library properties
3535
set_target_properties(libnativeapi PROPERTIES
36-
PUBLIC_HEADER "libnativeapi.h;screen_retriever.h;screen_retriever_linux.h;screen_retriever_macos.h;screen_retriever_windows.h"
36+
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libnativeapi/src/**/*.h"
3737
)
3838

3939
# Set library include directories

src/screen_retriever.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "screen_retriever_linux.h"
1010
#endif
1111

12+
namespace nativeapi {
13+
1214
std::unique_ptr<ScreenRetriever> ScreenRetriever::Create() {
1315
#ifdef __APPLE__
1416
return std::unique_ptr<ScreenRetriever>(new ScreenRetrieverMacOS());
@@ -19,8 +21,4 @@ std::unique_ptr<ScreenRetriever> ScreenRetriever::Create() {
1921
#endif
2022
}
2123

22-
// This file is left intentionally empty as the implementations
23-
// have been moved to platform-specific files:
24-
// - screen_retriever_linux.cpp
25-
// - screen_retriever_macos.mm
26-
// - screen_retriever_windows.cpp
24+
} // namespace nativeapi

src/screen_retriever.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,10 @@
33
#include <memory>
44
#include <vector>
55

6-
// Representation of a display
7-
struct Display {
8-
char* id;
9-
char* name;
10-
double width;
11-
double height;
12-
double visiblePositionX;
13-
double visiblePositionY;
14-
double visibleSizeWidth;
15-
double visibleSizeHeight;
16-
double scaleFactor;
17-
};
18-
19-
// Representation of a list of displays
20-
struct DisplayList {
21-
Display* displays;
22-
int count;
23-
};
24-
25-
// Representation of a cursor position
26-
struct CursorPoint {
27-
double x;
28-
double y;
29-
};
6+
#include "ui/display.h"
7+
#include "ui/geometry.h"
308

9+
namespace nativeapi {
3110
// Abstract base class for ScreenRetriever
3211
class ScreenRetriever {
3312
public:
@@ -37,11 +16,13 @@ class ScreenRetriever {
3716
static std::unique_ptr<ScreenRetriever> Create();
3817

3918
// Get the current cursor screen point
40-
virtual CursorPoint GetCursorScreenPoint() = 0;
19+
virtual Point GetCursorScreenPoint() = 0;
4120

4221
// Get the primary display information
4322
virtual Display GetPrimaryDisplay() = 0;
4423

4524
// Get all displays information
4625
virtual DisplayList GetAllDisplays() = 0;
4726
};
27+
28+
} // namespace nativeapi

src/screen_retriever_linux.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "screen_retriever_linux.h"
22
#include <iostream>
33

4+
namespace nativeapi {
5+
46
ScreenRetrieverLinux::ScreenRetrieverLinux() {
57
// Constructor implementation
68
std::cout << "ScreenRetrieverLinux initialized" << std::endl;
@@ -11,9 +13,9 @@ ScreenRetrieverLinux::~ScreenRetrieverLinux() {
1113
std::cout << "ScreenRetrieverLinux destroyed" << std::endl;
1214
}
1315

14-
CursorPoint ScreenRetrieverLinux::GetCursorScreenPoint() {
16+
Point ScreenRetrieverLinux::GetCursorScreenPoint() {
1517
// Empty implementation
16-
CursorPoint point;
18+
Point point;
1719
point.x = 0.0;
1820
point.y = 0.0;
1921
return point;
@@ -41,4 +43,6 @@ DisplayList ScreenRetrieverLinux::GetAllDisplays() {
4143
displayList.displays[0] = GetPrimaryDisplay();
4244
displayList.count = 1;
4345
return displayList;
44-
}
46+
}
47+
48+
} // namespace nativeapi

src/screen_retriever_linux.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
#include "screen_retriever.h"
44

5+
namespace nativeapi {
6+
57
// Linux implementation of ScreenRetriever
68
class ScreenRetrieverLinux : public ScreenRetriever {
79
public:
810
ScreenRetrieverLinux();
911
~ScreenRetrieverLinux() override;
1012

11-
CursorPoint GetCursorScreenPoint() override;
13+
Point GetCursorScreenPoint() override;
1214
Display GetPrimaryDisplay() override;
1315
DisplayList GetAllDisplays() override;
14-
};
16+
};
17+
18+
} // namespace nativeapi

src/screen_retriever_macos.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
// Import Cocoa headers
66
#import <Cocoa/Cocoa.h>
77

8+
namespace nativeapi {
9+
810
// macOS implementation of ScreenRetriever
911
class ScreenRetrieverMacOS : public ScreenRetriever {
1012
public:
1113
ScreenRetrieverMacOS();
1214
~ScreenRetrieverMacOS() override;
1315

14-
CursorPoint GetCursorScreenPoint() override;
16+
Point GetCursorScreenPoint() override;
1517
Display GetPrimaryDisplay() override;
1618
DisplayList GetAllDisplays() override;
1719

1820
private:
1921
// Helper method to create Display struct from NSScreen
2022
Display CreateDisplayFromNSScreen(NSScreen* screen, bool isMainScreen);
2123
};
24+
25+
} // namespace nativeapi

src/screen_retriever_macos.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Import Cocoa headers
77
#import <Cocoa/Cocoa.h>
88

9+
namespace nativeapi {
10+
911
// Helper function to convert NSString to char*
1012
static char* ConvertNSStringToCString(NSString* nsString) {
1113
if (nsString == nil) {
@@ -25,8 +27,8 @@
2527
std::cout << "ScreenRetrieverMacOS destroyed" << std::endl;
2628
}
2729

28-
CursorPoint ScreenRetrieverMacOS::GetCursorScreenPoint() {
29-
CursorPoint point;
30+
Point ScreenRetrieverMacOS::GetCursorScreenPoint() {
31+
Point point;
3032

3133
// Get the current mouse position
3234
NSPoint mouseLocation = [NSEvent mouseLocation];
@@ -49,7 +51,7 @@
4951
NSArray<NSScreen*>* screens = [NSScreen screens];
5052
bool isFirstScreen = true;
5153

52-
int count = (int) screens.count;
54+
int count = (int)screens.count;
5355
displayList.displays = new Display[count];
5456
displayList.count = count;
5557
int index = 0;
@@ -96,4 +98,6 @@
9698
display.scaleFactor = scaleFactor;
9799

98100
return display;
99-
}
101+
}
102+
103+
} // namespace nativeapi

src/screen_retriever_windows.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "screen_retriever_windows.h"
22
#include <iostream>
33

4+
namespace nativeapi {
5+
46
ScreenRetrieverWindows::ScreenRetrieverWindows() {
57
// Constructor implementation
68
std::cout << "ScreenRetrieverWindows initialized" << std::endl;
@@ -11,9 +13,9 @@ ScreenRetrieverWindows::~ScreenRetrieverWindows() {
1113
std::cout << "ScreenRetrieverWindows destroyed" << std::endl;
1214
}
1315

14-
CursorPoint ScreenRetrieverWindows::GetCursorScreenPoint() {
16+
Point ScreenRetrieverWindows::GetCursorScreenPoint() {
1517
// Empty implementation
16-
CursorPoint point;
18+
Point point;
1719
point.x = 0.0;
1820
point.y = 0.0;
1921
return point;
@@ -41,4 +43,6 @@ DisplayList ScreenRetrieverWindows::GetAllDisplays() {
4143
displayList.displays[0] = GetPrimaryDisplay();
4244
displayList.count = 1;
4345
return displayList;
44-
}
46+
}
47+
48+
} // namespace nativeapi

0 commit comments

Comments
 (0)