-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay_manager_linux.cpp
More file actions
78 lines (60 loc) · 1.98 KB
/
display_manager_linux.cpp
File metadata and controls
78 lines (60 loc) · 1.98 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
#include <gtk/gtk.h>
#include <iostream>
#include "../../display_manager.h"
namespace nativeapi {
static Display CreateDisplayFromGdkMonitor(GdkMonitor* monitor,
bool isFirstScreen) {
Display display;
display.id = "";
display.name = gdk_monitor_get_model(monitor);
GdkRectangle frame;
gdk_monitor_get_geometry(monitor, &frame);
display.size.width = frame.width;
display.size.height = frame.height;
display.position.x = frame.x;
display.position.y = frame.y;
GdkRectangle workarea_rect;
gdk_monitor_get_workarea(monitor, &workarea_rect);
display.workArea.width = workarea_rect.width;
display.workArea.height = workarea_rect.height;
display.workArea.x = workarea_rect.x;
display.workArea.y = workarea_rect.y;
display.scaleFactor = gdk_monitor_get_scale_factor(monitor);
return display;
}
DisplayManager::DisplayManager() {
gtk_init(nullptr, nullptr);
// Constructor implementation
std::cout << "DisplayManager initialized" << std::endl;
}
std::vector<Display> DisplayManager::GetAll() {
// Empty implementation
std::vector<Display> displayList;
displayList.push_back(GetPrimary());
return displayList;
}
Display DisplayManager::GetPrimary() {
GdkDisplay* display = gdk_display_get_default();
GdkMonitor* monitor = gdk_display_get_primary_monitor(display);
// opt: fallback if there's no primary monitor
if (monitor == nullptr) {
int monitor_count = gdk_display_get_n_monitors(display);
if (monitor_count > 0) {
monitor = gdk_display_get_monitor(display, 0);
}
}
return CreateDisplayFromGdkMonitor(monitor, true);
}
Point DisplayManager::GetCursorPosition() {
GdkDisplay* display = gdk_display_get_default();
GdkSeat* seat = gdk_display_get_default_seat(display);
GdkDevice* pointer = gdk_seat_get_pointer(seat);
int x, y;
gdk_device_get_position(pointer, NULL, &x, &y);
// Empty implementation
Point point;
point.x = x;
point.y = y;
return point;
}
} // namespace nativeapi