-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdisplay_linux.cpp
More file actions
123 lines (100 loc) · 3.42 KB
/
Copy pathdisplay_linux.cpp
File metadata and controls
123 lines (100 loc) · 3.42 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "../../display.h"
#include <gdk/gdk.h>
#include <gtk/gtk.h>
namespace nativeapi {
// Private implementation class
class Display::Impl {
public:
Impl() = default;
Impl(GdkMonitor* monitor) : gdk_monitor_(monitor) {}
GdkMonitor* gdk_monitor_ = nullptr;
};
Display::Display() : pimpl_(std::make_unique<Impl>()) {}
Display::Display(void* display) : pimpl_(std::make_unique<Impl>()) {
if (display) {
pimpl_->gdk_monitor_ = (GdkMonitor*)display;
}
}
Display::Display(const Display& other) : pimpl_(std::make_unique<Impl>(*other.pimpl_)) {}
Display& Display::operator=(const Display& other) {
if (this != &other) {
*pimpl_ = *other.pimpl_;
}
return *this;
}
Display::Display(Display&& other) noexcept : pimpl_(std::move(other.pimpl_)) {}
Display& Display::operator=(Display&& other) noexcept {
if (this != &other) {
pimpl_ = std::move(other.pimpl_);
}
return *this;
}
Display::~Display() = default;
void* Display::GetNativeObjectInternal() const {
return pimpl_->gdk_monitor_;
}
// Getters - directly read from GdkMonitor
std::string Display::GetId() const {
if (!pimpl_->gdk_monitor_)
return "";
// Use monitor pointer as ID since GDK doesn't provide direct monitor IDs
return std::to_string(reinterpret_cast<uintptr_t>(pimpl_->gdk_monitor_));
}
std::string Display::GetName() const {
if (!pimpl_->gdk_monitor_)
return "";
const char* model = gdk_monitor_get_model(pimpl_->gdk_monitor_);
return model ? model : "Unknown";
}
Point Display::GetPosition() const {
if (!pimpl_->gdk_monitor_)
return {0.0, 0.0};
GdkRectangle geometry;
gdk_monitor_get_geometry(pimpl_->gdk_monitor_, &geometry);
return {static_cast<double>(geometry.x), static_cast<double>(geometry.y)};
}
Size Display::GetSize() const {
if (!pimpl_->gdk_monitor_)
return {0.0, 0.0};
GdkRectangle geometry;
gdk_monitor_get_geometry(pimpl_->gdk_monitor_, &geometry);
return {static_cast<double>(geometry.width), static_cast<double>(geometry.height)};
}
Rectangle Display::GetWorkArea() const {
if (!pimpl_->gdk_monitor_)
return {0.0, 0.0, 0.0, 0.0};
GdkRectangle workarea;
gdk_monitor_get_workarea(pimpl_->gdk_monitor_, &workarea);
return {static_cast<double>(workarea.x), static_cast<double>(workarea.y),
static_cast<double>(workarea.width), static_cast<double>(workarea.height)};
}
double Display::GetScaleFactor() const {
if (!pimpl_->gdk_monitor_)
return 1.0;
return gdk_monitor_get_scale_factor(pimpl_->gdk_monitor_);
}
bool Display::IsPrimary() const {
if (!pimpl_->gdk_monitor_)
return false;
GdkDisplay* display = gdk_monitor_get_display(pimpl_->gdk_monitor_);
GdkMonitor* primary = gdk_display_get_primary_monitor(display);
return primary == pimpl_->gdk_monitor_;
}
DisplayOrientation Display::GetOrientation() const {
if (!pimpl_->gdk_monitor_)
return DisplayOrientation::kPortrait;
GdkRectangle geometry;
gdk_monitor_get_geometry(pimpl_->gdk_monitor_, &geometry);
return (geometry.width > geometry.height) ? DisplayOrientation::kLandscape
: DisplayOrientation::kPortrait;
}
int Display::GetRefreshRate() const {
if (!pimpl_->gdk_monitor_)
return 60;
int refresh_rate = gdk_monitor_get_refresh_rate(pimpl_->gdk_monitor_);
return refresh_rate > 0 ? refresh_rate / 1000 : 60; // Convert from millihertz to hertz
}
int Display::GetBitDepth() const {
return 32; // Default for modern displays
}
} // namespace nativeapi