summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm21
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm25
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp20
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp2
4 files changed, 47 insertions, 21 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index adad12a4242..be05249c1b8 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -265,19 +265,26 @@ void QCocoaGLContext::updateSurfaceFormat()
return value;
};
- int colorSize = pixelFormatAttribute(NSOpenGLPFAColorSize);
- colorSize /= 4; // The attribute includes the alpha component
- m_format.setRedBufferSize(colorSize);
- m_format.setGreenBufferSize(colorSize);
- m_format.setBlueBufferSize(colorSize);
+ // Resolve color channel bits from GL, rather than NSOpenGLPFAColorSize,
+ // as the latter is not specific enough (combines all channels).
+ GLint redBits, greenBits, blueBits;
+ glGetIntegerv(GL_RED_BITS, &redBits);
+ glGetIntegerv(GL_GREEN_BITS, &greenBits);
+ glGetIntegerv(GL_BLUE_BITS, &blueBits);
+ m_format.setRedBufferSize(redBits);
+ m_format.setGreenBufferSize(greenBits);
+ m_format.setBlueBufferSize(blueBits);
// Surfaces on macOS always have an alpha channel, but unless the user requested
// one via setAlphaBufferSize(), which triggered setting NSOpenGLCPSurfaceOpacity
// to make the surface non-opaque, we don't want to report back the actual alpha
// size, as that will make the user believe the alpha channel can be used for
// something useful, when in reality it can't, due to the surface being opaque.
- if (m_format.alphaBufferSize() > 0)
- m_format.setAlphaBufferSize(pixelFormatAttribute(NSOpenGLPFAAlphaSize));
+ if (m_format.alphaBufferSize() > 0) {
+ GLint alphaBits;
+ glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
+ m_format.setAlphaBufferSize(alphaBits);
+ }
m_format.setDepthBufferSize(pixelFormatAttribute(NSOpenGLPFADepthSize));
m_format.setStencilBufferSize(pixelFormatAttribute(NSOpenGLPFAStencilSize));
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 0905ba3e644..1b34490e358 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -330,6 +330,13 @@ QMargins QCocoaWindow::safeAreaMargins() const
// merge them.
auto screenRect = m_view.window.screen.frame;
auto screenInsets = m_view.window.screen.safeAreaInsets;
+ auto screenSafeArea = QCocoaScreen::mapFromNative(NSMakeRect(
+ NSMinX(screenRect) + screenInsets.left,
+ NSMinY(screenRect) + screenInsets.bottom, // Non-flipped
+ NSWidth(screenRect) - screenInsets.left - screenInsets.right,
+ NSHeight(screenRect) - screenInsets.top - screenInsets.bottom
+ ));
+
auto screenRelativeViewBounds = QCocoaScreen::mapFromNative(
[m_view.window convertRectToScreen:
[m_view convertRect:m_view.bounds toView:nil]]
@@ -339,20 +346,10 @@ QMargins QCocoaWindow::safeAreaMargins() const
// Note that we do not want represent the area outside of the
// screen as being outside of the safe area.
QMarginsF screenSafeAreaMargins = {
- screenInsets.left ?
- qMax(0.0f, screenInsets.left - screenRelativeViewBounds.left())
- : 0.0f,
- screenInsets.top ?
- qMax(0.0f, screenInsets.top - screenRelativeViewBounds.top())
- : 0.0f,
- screenInsets.right ?
- qMax(0.0f, screenInsets.right
- - (screenRect.size.width - screenRelativeViewBounds.right()))
- : 0.0f,
- screenInsets.bottom ?
- qMax(0.0f, screenInsets.bottom
- - (screenRect.size.height - screenRelativeViewBounds.bottom()))
- : 0.0f
+ qMin(screenSafeArea.left() - screenRelativeViewBounds.left(), screenInsets.left),
+ qMin(screenSafeArea.top() - screenRelativeViewBounds.top(), screenInsets.top),
+ qMin(screenRelativeViewBounds.right() - screenSafeArea.right(), screenInsets.right),
+ qMin(screenRelativeViewBounds.bottom() - screenSafeArea.bottom(), screenInsets.bottom)
};
return (screenSafeAreaMargins | viewSafeAreaMargins).toMargins();
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 0236669d6fb..23bbe409caa 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -450,6 +450,26 @@ QPixmap QWindowsScreen::grabWindow(WId window, int xIn, int yIn, int width, int
hwnd = GetDesktopWindow();
const QRect screenGeometry = geometry();
windowSize = screenGeometry.size();
+ // When dpi awareness is not set to PerMonitor, windows reports primary display or dummy
+ // DPI for all displays, so xIn and yIn and windowSize are calculated with a wrong DPI,
+ // so we need to recalculate them using the actual screen size we get from
+ // EnumDisplaySettings api.
+ const auto dpiAwareness = QWindowsContext::instance()->processDpiAwareness();
+ if (dpiAwareness != QtWindows::DpiAwareness::PerMonitor &&
+ dpiAwareness != QtWindows::DpiAwareness::PerMonitorVersion2) {
+ MONITORINFOEX info = {};
+ info.cbSize = sizeof(MONITORINFOEX);
+ if (GetMonitorInfo(handle(), &info)) {
+ DEVMODE dm = {};
+ dm.dmSize = sizeof(dm);
+ if (EnumDisplaySettings(info.szDevice, ENUM_CURRENT_SETTINGS, &dm)) {
+ qreal scale = static_cast<qreal>(dm.dmPelsWidth) / windowSize.width();
+ x = static_cast<int>(static_cast<qreal>(x) * scale);
+ y = static_cast<int>(static_cast<qreal>(y) * scale);
+ windowSize = QSize(dm.dmPelsWidth, dm.dmPelsHeight);
+ }
+ }
+ }
x += screenGeometry.x();
y += screenGeometry.y();
}
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index b77e985c965..2816982b1a8 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -1732,8 +1732,10 @@ void QWindowsWindow::destroyWindow()
m_surface = nullptr;
}
#endif
+ DestroyWindow(m_data.hwndTitlebar);
DestroyWindow(m_data.hwnd);
context->removeWindow(m_data.hwnd);
+ m_data.hwndTitlebar = nullptr;
m_data.hwnd = nullptr;
}
}