-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay_manager_c.cpp
More file actions
90 lines (81 loc) · 2.59 KB
/
display_manager_c.cpp
File metadata and controls
90 lines (81 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "display_manager_c.h"
#include <iostream>
#include <memory>
#include <vector>
#include "../display.h"
#include "../display_manager.h"
#include "display_c.h"
using namespace nativeapi;
DisplayManager& g_display_manager = DisplayManager::GetInstance();
FFI_PLUGIN_EXPORT
native_display_list_t native_display_manager_get_all() {
native_display_list_t list = {};
try {
auto displays = g_display_manager.GetAll();
list.count = static_cast<long>(displays.size());
if (list.count > 0) {
// Allocate array for display handles
list.displays = new (std::nothrow) native_display_t[list.count];
if (list.displays) {
for (size_t i = 0; i < displays.size(); i++) {
try {
list.displays[i] = new (std::nothrow) Display(displays[i]);
if (!list.displays[i]) {
// If creation fails, clean up and return empty list
for (size_t j = 0; j < i; j++) {
native_display_free(list.displays[j]);
}
delete[] list.displays;
list.displays = nullptr;
list.count = 0;
break;
}
} catch (const std::exception&) {
// If creation fails, clean up and return empty list
for (size_t j = 0; j < i; j++) {
native_display_free(list.displays[j]);
}
delete[] list.displays;
list.displays = nullptr;
list.count = 0;
break;
}
}
} else {
list.count = 0;
}
} else {
list.displays = nullptr;
}
return list;
} catch (const std::exception& e) {
std::cerr << "Error in native_display_manager_get_all: " << e.what() << std::endl;
list.count = 0;
list.displays = nullptr;
return list;
}
}
FFI_PLUGIN_EXPORT
native_display_t native_display_manager_get_primary() {
try {
auto primary_display = g_display_manager.GetPrimary();
auto* handle = new (std::nothrow) Display(primary_display);
return handle;
} catch (const std::exception& e) {
std::cerr << "Error in native_display_manager_get_primary: " << e.what() << std::endl;
return nullptr;
}
}
FFI_PLUGIN_EXPORT
native_point_t native_display_manager_get_cursor_position() {
native_point_t point = {0.0, 0.0};
try {
auto cursor_position = g_display_manager.GetCursorPosition();
point.x = cursor_position.x;
point.y = cursor_position.y;
return point;
} catch (const std::exception& e) {
std::cerr << "Error in native_display_manager_get_cursor_position: " << e.what() << std::endl;
return point;
}
}