1
+ #include < gtk/gtk.h>
1
2
#include < iostream>
2
3
#include " screen_retriever.h"
3
4
4
5
namespace nativeapi {
5
6
7
+ static Display CreateDisplayFromGdkMonitor (GdkMonitor* monitor,
8
+ bool isFirstScreen) {
9
+ Display display;
10
+
11
+ display.id = " " ;
12
+ display.name = gdk_monitor_get_model (monitor);
13
+
14
+ GdkRectangle frame;
15
+ gdk_monitor_get_geometry (monitor, &frame);
16
+
17
+ display.width = frame.width ;
18
+ display.height = frame.height ;
19
+
20
+ GdkRectangle workarea_rect;
21
+ gdk_monitor_get_workarea (monitor, &workarea_rect);
22
+
23
+ display.visibleSizeWidth = workarea_rect.width ;
24
+ display.visibleSizeHeight = workarea_rect.height ;
25
+ display.visiblePositionX = workarea_rect.x ;
26
+ display.visiblePositionY = workarea_rect.y ;
27
+
28
+ display.scaleFactor = gdk_monitor_get_scale_factor (monitor);
29
+
30
+ return display;
31
+ }
32
+
6
33
ScreenRetriever::ScreenRetriever () {
34
+ gtk_init (nullptr , nullptr );
7
35
// Constructor implementation
8
36
std::cout << " ScreenRetriever initialized" << std::endl;
9
37
}
@@ -14,26 +42,33 @@ ScreenRetriever::~ScreenRetriever() {
14
42
}
15
43
16
44
Point ScreenRetriever::GetCursorScreenPoint () {
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
+
17
52
// Empty implementation
18
53
Point point;
19
- point.x = 0.0 ;
20
- point.y = 0.0 ;
54
+ point.x = x ;
55
+ point.y = y ;
21
56
return point;
22
57
}
23
58
24
59
Display ScreenRetriever::GetPrimaryDisplay () {
25
- // Empty implementation
26
- Display display;
27
- display. id = " display-1 " ;
28
- display. name = " Linux Display " ;
29
- display. width = 1920.0 ;
30
- display. height = 1080.0 ;
31
- display. visiblePositionX = 0.0 ;
32
- display. visiblePositionY = 0.0 ;
33
- display. visibleSizeWidth = 1920.0 ;
34
- display. visibleSizeHeight = 1080.0 ;
35
- display. scaleFactor = 1.0 ;
36
- return display ;
60
+ GdkDisplay* display = gdk_display_get_default ();
61
+ GdkMonitor* monitor = gdk_display_get_primary_monitor ( display) ;
62
+
63
+ // opt: fallback if there's no primary monitor
64
+ if (monitor == nullptr ) {
65
+ int monitor_count = gdk_display_get_n_monitors (display) ;
66
+ if (monitor_count > 0 ) {
67
+ monitor = gdk_display_get_monitor (display, 0 ) ;
68
+ }
69
+ }
70
+
71
+ return CreateDisplayFromGdkMonitor (monitor, true ) ;
37
72
}
38
73
39
74
std::vector<Display> ScreenRetriever::GetAllDisplays () {
0 commit comments