1+ #include < gtk/gtk.h>
12#include < iostream>
23#include " screen_retriever.h"
34
45namespace nativeapi {
56
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+
633ScreenRetriever::ScreenRetriever () {
34+ gtk_init (nullptr , nullptr );
735 // Constructor implementation
836 std::cout << " ScreenRetriever initialized" << std::endl;
937}
@@ -14,26 +42,33 @@ ScreenRetriever::~ScreenRetriever() {
1442}
1543
1644Point 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+
1752 // Empty implementation
1853 Point point;
19- point.x = 0.0 ;
20- point.y = 0.0 ;
54+ point.x = x ;
55+ point.y = y ;
2156 return point;
2257}
2358
2459Display 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 ) ;
3772}
3873
3974std::vector<Display> ScreenRetriever::GetAllDisplays () {
0 commit comments