Skip to content

Commit 27d0e7b

Browse files
committed
Fix Rectangle field order and work area construction
Corrects the order of width and height fields in the Rectangle struct and updates platform-specific Display::GetWorkArea implementations to match the new order. Also adds coordinate system conversion for macOS to ensure consistent top-left origin handling.
1 parent 8c455f8 commit 27d0e7b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/geometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct Size {
2424
struct Rectangle {
2525
double x;
2626
double y;
27-
double height;
2827
double width;
28+
double height;
2929
};
3030

3131
} // namespace nativeapi

src/platform/linux/display_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Rectangle Display::GetWorkArea() const {
7878
GdkRectangle workarea;
7979
gdk_monitor_get_workarea(pimpl_->gdk_monitor_, &workarea);
8080
return {static_cast<double>(workarea.x), static_cast<double>(workarea.y),
81-
static_cast<double>(workarea.height), static_cast<double>(workarea.width)};
81+
static_cast<double>(workarea.width), static_cast<double>(workarea.height)};
8282
}
8383

8484
double Display::GetScaleFactor() const {

src/platform/macos/display_macos.mm

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
namespace nativeapi {
88

9+
// NSRect extension-like helper for coordinate system conversion
10+
struct NSRectExt {
11+
static CGPoint topLeft(NSRect rect) {
12+
NSRect primaryScreenFrame = [[NSScreen screens][0] frame];
13+
return CGPointMake(rect.origin.x,
14+
primaryScreenFrame.size.height - rect.origin.y - rect.size.height);
15+
}
16+
};
17+
918
// Private implementation class
1019
class Display::Impl {
1120
public:
@@ -105,7 +114,11 @@
105114
Point Display::GetPosition() const {
106115
if (!pimpl_->ns_screen_) return {0.0, 0.0};
107116
NSRect frame = [pimpl_->ns_screen_ frame];
108-
return {frame.origin.x, frame.origin.y};
117+
118+
// Convert from bottom-left (macOS default) to top-left coordinate system
119+
CGPoint topLeft = NSRectExt::topLeft(frame);
120+
121+
return {topLeft.x, topLeft.y};
109122
}
110123

111124
Size Display::GetSize() const {
@@ -117,8 +130,12 @@
117130
Rectangle Display::GetWorkArea() const {
118131
if (!pimpl_->ns_screen_) return {0.0, 0.0, 0.0, 0.0};
119132
NSRect visibleFrame = [pimpl_->ns_screen_ visibleFrame];
120-
return {visibleFrame.origin.x, visibleFrame.origin.y,
121-
visibleFrame.size.height, visibleFrame.size.width};
133+
134+
// Convert from bottom-left (macOS default) to top-left coordinate system
135+
CGPoint topLeft = NSRectExt::topLeft(visibleFrame);
136+
137+
return {topLeft.x, topLeft.y,
138+
visibleFrame.size.width, visibleFrame.size.height};
122139
}
123140

124141
double Display::GetScaleFactor() const {

src/platform/windows/display_windows.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ Rectangle Display::GetWorkArea() const {
8585
MONITORINFOEX monitorInfo = GetMonitorInfo(pimpl_->h_monitor_);
8686
RECT workRect = monitorInfo.rcWork;
8787
return {static_cast<double>(workRect.left), static_cast<double>(workRect.top),
88-
static_cast<double>(workRect.bottom - workRect.top),
89-
static_cast<double>(workRect.right - workRect.left)};
88+
static_cast<double>(workRect.right - workRect.left),
89+
static_cast<double>(workRect.bottom - workRect.top)};
9090
}
9191

9292
double Display::GetScaleFactor() const {

0 commit comments

Comments
 (0)