5#include <QuartzCore/QuartzCore.h>
19#include <QtCore/qfileinfo.h>
20#include <QtCore/private/qcore_mac_p.h>
22#include <private/qwindow_p.h>
23#include <qpa/qwindowsysteminterface.h>
24#include <qpa/qplatformscreen.h>
25#include <QtGui/private/qcoregraphics_p.h>
26#include <QtGui/private/qhighdpiscaling_p.h>
45 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
53 if (!methodTag.startsWith(notificationHandlerPrefix))
56 const QString notificationName = methodTag.
mid(notificationHandlerPrefix.size());
57 [center addObserverForName:notificationName.toNSString()
object:nil
queue:nil
58 usingBlock:^(NSNotification *notification) {
60 QVarLengthArray<QCocoaWindow *, 32> cocoaWindows;
61 if ([notification.object isKindOfClass:[NSWindow
class]]) {
62 NSWindow *nsWindow = notification.object;
65 if (cocoaWindow->nativeWindow() == nsWindow)
66 cocoaWindows += cocoaWindow;
68 }
else if ([notification.object isKindOfClass:[NSView
class]]) {
70 cocoaWindows += qnsView.platformWindow;
72 qCWarning(lcCocoaNotifications) <<
"Unhandled notification"
73 << notification.name <<
"for" << notification.object;
77 if (lcCocoaNotifications().isDebugEnabled() && !cocoaWindows.isEmpty()) {
78 QVector<QCocoaWindow *> debugWindows;
80 debugWindows += cocoaWindow;
89 qCWarning(lcQpaWindow) <<
"Failed to invoke NSNotification callback for"
90 << notification.name <<
"on" << cocoaWindow;
103 qCDebug(lcQpaWindow) <<
"QCocoaWindow::QCocoaWindow" <<
window();
106 m_view =
reinterpret_cast<NSView *
>(nativeHandle);
113 qCDebug(lcQpaWindow) <<
"QCocoaWindow::initialize" <<
window();
148 qCDebug(lcQpaWindow) <<
"QCocoaWindow::~QCocoaWindow" <<
window();
157 [
m_view removeFromSuperview];
162 [[NSNotificationCenter defaultCenter] removeObserver:
m_view];
166 auto vulcanInstance = cocoaIntegration->getCocoaVulkanInstance();
168 vulcanInstance->destroySurface(m_vulkanSurface);
175 [NSNotificationCenter.defaultCenter
185 return window()->requestedFormat();
190 qCDebug(lcQpaWindow) <<
"QCocoaWindow::setGeometry" <<
window() << rectIn;
219 NSPoint windowPoint = [
m_view convertPoint:NSMakePoint(0, 0) toView:nil];
220 NSRect screenRect = [[
m_view window] convertRectToScreen:NSMakeRect(windowPoint.x, windowPoint.y, 1, 1)];
221 NSPoint screenPoint = screenRect.origin;
223 QSize size = QRectF::fromCGRect(NSRectToCGRect([
m_view bounds])).toRect().size();
280 [
m_view.window setFrame:[
m_view.window frameRectForContentRect:bounds]
display:YES animate:NO];
290 switch (NSApp.currentEvent.type) {
291 case NSEventTypeLeftMouseDown:
292 case NSEventTypeRightMouseDown:
293 case NSEventTypeOtherMouseDown:
294 case NSEventTypeMouseMoved:
295 case NSEventTypeLeftMouseDragged:
296 case NSEventTypeRightMouseDragged:
297 case NSEventTypeOtherMouseDragged:
300 [
m_view.window performWindowDragWithEvent:NSApp.currentEvent];
309 qCDebug(lcQpaWindow) <<
"QCocoaWindow::setVisible" <<
window() << visible;
322 qCDebug(lcQpaWindow) <<
"Window still initializing, skipping setting visibility";
327 qCDebug(lcQpaWindow) <<
"No change in visible status. Ignoring.";
332 qCWarning(lcQpaWindow) <<
"Already setting window visible!";
340 if (
window()->transientParent())
341 parentCocoaWindow =
static_cast<QCocoaWindow *
>(
window()->transientParent()->handle());
343 auto eventDispatcher = [] {
357 if (parentCocoaWindow) {
365 NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow();
366 NSUInteger parentStyleMask = nativeParentWindow.styleMask;
368 && !(nativeParentWindow.styleMask & NSWindowStyleMaskFullScreen))
369 nativeParentWindow.styleMask &= ~NSWindowStyleMaskResizable;
387 NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow();
388 if (!nativeParentWindow.attachedSheet)
389 [nativeParentWindow beginSheet:
m_view.window completionHandler:nil];
391 [nativeParentWindow beginCriticalSheet:
m_view.window completionHandler:nil];
394 eventDispatcher()->beginModalSession(
window());
395 }
else if (
m_view.window.canBecomeKeyWindow) {
396 bool shouldBecomeKeyNow = !NSApp.modalWindow
397 ||
m_view.window.worksWhenModal
398 || !NSApp.modalWindow.visible;
402 if ([
m_view.window isKindOfClass:[NSPanel
class]])
403 shouldBecomeKeyNow &= !(
static_cast<NSPanel*
>(
m_view.window).becomesKeyOnlyIfNeeded);
405 if (shouldBecomeKeyNow)
406 [
m_view.window makeKeyAndOrderFront:nil];
408 [
m_view.window orderFront:nil];
410 [
m_view.window orderFront:nil];
417 if (eventDispatcher()->hasModalSession()) {
418 eventDispatcher()->endModalSession(
window());
420 if ([
m_view.window isSheet]) {
421 Q_ASSERT_X(parentCocoaWindow,
"QCocoaWindow",
"Window modal dialog has no transient parent.");
422 [parentCocoaWindow->nativeWindow() endSheet:
m_view.window];
431 [
m_view.window orderOut:nil];
433 if (
m_view.window == [NSApp keyWindow] && !eventDispatcher()->hasModalSession()) {
438 NSWindow *mainWindow = [NSApp mainWindow];
439 if (mainWindow && [mainWindow canBecomeKeyWindow])
440 [mainWindow makeKeyWindow];
456 qCDebug(lcQpaWindow) <<
"Detected nextValidKeyView" <<
m_view.nextValidKeyView
457 <<
"in different window" <<
m_view.nextValidKeyView.window
458 <<
"Resetting" <<
m_view.window <<
"first responder to nil.";
459 [
m_view.window makeFirstResponder:nil];
465 NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow();
467 && !(nativeParentWindow.styleMask & NSWindowStyleMaskFullScreen))
469 nativeParentWindow.styleMask |= NSWindowStyleMaskResizable;
492 auto *transientParent =
window()->transientParent();
493 if (transientParent && transientParent->handle()) {
513 auto *transientCocoaWindow =
static_cast<QCocoaWindow *
>(transientParent->handle());
537 return NSWindowStyleMaskBorderless;
541 return NSWindowStyleMaskBorderless;
547 ? NSWindowStyleMaskTitled
548 : NSWindowStyleMaskBorderless;
551 return NSWindowStyleMaskTitled;
560 styleMask |= NSWindowStyleMaskClosable
561 | NSWindowStyleMaskMiniaturizable;
564 styleMask |= NSWindowStyleMaskResizable;
567 styleMask |= NSWindowStyleMaskUtilityWindow;
571 styleMask |= NSWindowStyleMaskTexturedBackground;
574 if (
m_view.window.styleMask & NSWindowStyleMaskFullScreen)
575 styleMask |= NSWindowStyleMaskFullScreen;
576 if (
m_view.window.styleMask & NSWindowStyleMaskFullSizeContentView)
577 styleMask |= NSWindowStyleMaskFullSizeContentView;
593 static constexpr std::pair<NSWindowButton, Qt::WindowFlags> buttons[] = {
599 bool hideButtons =
true;
600 for (
const auto &[
button, buttonHint] : buttons) {
603 if (
button == NSWindowMiniaturizeButton)
608 enabled = windowFlags & buttonHint;
631 for (
const auto &[
button, buttonHint] : buttons)
632 [
m_view.window standardWindowButton:
button].hidden = hideButtons;
654 NSWindowCollectionBehavior behavior =
m_view.window.collectionBehavior;
655 const bool enableFullScreen =
m_view.window.qt_fullScreen
658 if (enableFullScreen) {
659 behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
660 behavior &= ~NSWindowCollectionBehaviorFullScreenAuxiliary;
662 behavior |= NSWindowCollectionBehaviorFullScreenAuxiliary;
663 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
665 m_view.window.collectionBehavior = behavior;
687 if (
m_view.window.ignoresMouseEvents != ignoreMouse)
688 m_view.window.ignoresMouseEvents = ignoreMouse;
719 const NSSize contentSize =
m_view.frame.size;
720 if (contentSize.width <= 0 || contentSize.height <= 0) {
723 qWarning(
"invalid window content view size, check your window geometry");
728 const NSWindow *nsWindow =
m_view.window;
730 if (nsWindow.styleMask & NSWindowStyleMaskUtilityWindow
737 const id sender = nsWindow;
740 switch (currentState) {
742 [nsWindow deminiaturize:
sender];
769 [nsWindow miniaturize:
sender];
790 if (
window.qt_fullScreen) {
809 const bool wasResizable =
window.styleMask & NSWindowStyleMaskResizable;
810 window.styleMask |= NSWindowStyleMaskResizable;
816 window.styleMask &= ~NSWindowStyleMaskResizable;
831 window.collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
837void QCocoaWindow::windowWillEnterFullScreen()
847 m_view.window.styleMask |= NSWindowStyleMaskResizable;
853 return window.styleMask & NSWindowStyleMaskFullScreen && !
window.qt_fullScreen;
856void QCocoaWindow::windowDidEnterFullScreen()
862 "FullScreen category processes window notifications first");
870void QCocoaWindow::windowWillExitFullScreen()
877 m_view.window.styleMask |= NSWindowStyleMaskResizable;
880void QCocoaWindow::windowDidExitFullScreen()
886 "FullScreen category processes window notifications first");
903void QCocoaWindow::windowDidMiniaturize()
911void QCocoaWindow::windowDidDeminiaturize()
933 qCDebug(lcQpaWindow) <<
"QCocoaWindow::handleWindowStateChanged" <<
936 QWindowSystemInterface::handleWindowStateChanged<QWindowSystemInterface::SynchronousDelivery>(
965 [
m_view.window setTitleWithRepresentedFilename:filePath.toNSString()];
967 m_view.window.representedFilename = filePath.toNSString();
978 NSButton *iconButton = [
m_view.window standardWindowButton:NSWindowDocumentIconButton];
987 iconButton.image = [NSWorkspace.sharedWorkspace iconForFile:
m_view.window.representedFilename];
990 auto fallbackSize = iconButton.frame.size.height *
qGuiApp->devicePixelRatio();
991 iconButton.image = [NSImage imageFromQIcon:
icon withSize:fallbackSize];
1016 if (
m_view.window.visible) {
1026 static bool raiseProcess = qt_mac_resolveOption(
true,
"QT_MAC_SET_RAISE_PROCESS");
1028 [NSApp activateIgnoringOtherApps:YES];
1031 [
m_view.superview addSubview:
m_view positioned:NSWindowAbove relativeTo:nil];
1040 if (
m_view.window.visible)
1043 [
m_view.superview addSubview:
m_view positioned:NSWindowBelow relativeTo:nil];
1072 static GLint openglSourfaceOrder = qt_mac_resolveOption(1,
"QT_MAC_OPENGL_SURFACE_ORDER");
1078 return !translucent;
1087 qCDebug(lcQpaWindow) <<
"QCocoaWindow::propagateSizeHints" <<
window()
1097 minimumSize =
QSize(0, 0);
1098 window.contentMinSize = NSSizeFromCGSize(minimumSize.toCGSize());
1110 sizeIncrement =
QSize(1, 1);
1111 window.resizeIncrements = NSSizeFromCGSize(sizeIncrement.toCGSize());
1121 qCDebug(lcQpaWindow) <<
"QCocoaWindow::setOpacity" <<
level;
1130 qCDebug(lcQpaWindow) <<
"QCocoaWindow::setMask" <<
window() << region;
1133 QCFType<CGMutablePathRef> maskPath = CGPathCreateMutable();
1134 for (
const QRect &
r : region)
1135 CGPathAddRect(maskPath,
nullptr,
r.toCGRect());
1136 CAShapeLayer *maskLayer = [CAShapeLayer
layer];
1137 maskLayer.path = maskPath;
1138 m_view.layer.mask = maskLayer;
1161 qCDebug(lcQpaWindow) <<
"QCocoaWindow::setParent" <<
window() << (parentWindow ? parentWindow->
window() : 0);
1188void QCocoaWindow::viewDidChangeFrame()
1205void QCocoaWindow::viewDidChangeGlobalFrame()
1207 [
m_view setNeedsDisplay:YES];
1217void QCocoaWindow::windowDidMove()
1228void QCocoaWindow::windowDidResize()
1235 if (!
m_view.inLiveResize)
1239void QCocoaWindow::windowDidEndLiveResize()
1247void QCocoaWindow::windowDidBecomeKey()
1254 qCDebug(lcQpaWindow) <<
m_view.window <<
"became key window."
1255 <<
"Updating focus window to" <<
this <<
"with view" <<
m_view;
1258 qCDebug(lcQpaWindow) <<
"Window is popup. Skipping focus window change.";
1263 QWindowSystemInterface::handleFocusWindowChanged<QWindowSystemInterface::SynchronousDelivery>(
1267void QCocoaWindow::windowDidResignKey()
1274 qCDebug(lcQpaWindow) <<
m_view.window <<
"resigned key window."
1275 <<
"Clearing focus window" <<
this <<
"with view" <<
m_view;
1284 NSWindow *newKeyWindow = [NSApp keyWindow];
1285 if (newKeyWindow && newKeyWindow !=
m_view.window
1286 && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)]) {
1287 qCDebug(lcQpaWindow) <<
"New key window" << newKeyWindow
1288 <<
"is Qt window. Deferring focus window change.";
1294 QWindowSystemInterface::handleFocusWindowChanged<QWindowSystemInterface::SynchronousDelivery>(
1299void QCocoaWindow::windowDidOrderOnScreen()
1304 QWindowSystemInterface::handleLeaveEvent<QWindowSystemInterface::SynchronousDelivery>
1308 [
m_view setNeedsDisplay:YES];
1311void QCocoaWindow::windowDidOrderOffScreen()
1320 const auto windowPoint = windowUnderMouse->mapFromGlobal(screenPoint);
1322 QWindowSystemInterface::handleEnterEvent<QWindowSystemInterface::AsynchronousDelivery>
1323 (windowUnderMouse, windowPoint, screenPoint);
1329void QCocoaWindow::windowDidChangeOcclusionState()
1335 bool visible =
m_view.window.occlusionState & NSWindowOcclusionStateVisible;
1336 qCDebug(lcQpaWindow) <<
"Occlusion state of" <<
m_view.window <<
"for"
1337 <<
window() <<
"changed to" << (visible ?
"visible" :
"occluded");
1340 [
m_view setNeedsDisplay:YES];
1345void QCocoaWindow::windowDidChangeScreen()
1351 NSScreen *nsScreen =
m_view.window.screen;
1353 qCDebug(lcQpaWindow) <<
window() <<
"did change" << nsScreen;
1354 QCocoaScreen::updateScreens();
1359 qCDebug(lcQpaWindow) <<
"Screen changed for" <<
window() <<
"from" << previousScreen <<
"to" << currentScreen;
1372 QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(
1373 window(), currentScreen ? currentScreen->screen() :
nullptr);
1380 currentScreen->requestUpdate();
1388 qCDebug(lcQpaWindow) <<
"QCocoaWindow::windowShouldClose" <<
window();
1400 [[
m_view.window retain] autorelease];
1402 return QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(
window());
1424 CGRect contentRect = [
m_view.window contentRectForFrameRect:
m_view.window.frame];
1430 newGeometry = QRectF::fromCGRect(
m_view.frame).toRect();
1433 qCDebug(lcQpaWindow) <<
"QCocoaWindow::handleGeometryChange" <<
window()
1434 <<
"current" <<
geometry() <<
"new" << newGeometry;
1459 && !
m_view.hiddenOrHasHiddenAncestor) {
1465 qCDebug(lcQpaDrawing) <<
"QCocoaWindow::handleExposeEvent" <<
window() << region <<
"isExposed" <<
isExposed();
1466 QWindowSystemInterface::handleExposeEvent<QWindowSystemInterface::SynchronousDelivery>(
window(), region);
1506 auto *parentCocoaWindow =
static_cast<QCocoaWindow *
>(parentWindow);
1510 oldParentCocoaWindow = qnsView.platformWindow;
1516 qCDebug(lcQpaWindow) <<
"Skipping NSWindow management for foreign window" <<
this;
1519 if (parentCocoaWindow)
1520 [parentCocoaWindow->m_view addSubview:
m_view];
1521 else if (oldParentCocoaWindow)
1522 [
m_view removeFromSuperview];
1530 if (parentWindow != oldParentCocoaWindow)
1542 const bool shouldBeContentView = !parentWindow
1549 const bool shouldBePanel = shouldBeContentView &&
1552 if (isPanel != shouldBePanel)
1555 qCDebug(lcQpaWindow) <<
"QCocoaWindow::recreateWindowIfNeeded" <<
window() << recreateReason;
1570 m_view.window.contentView = nil;
1579 qCDebug(lcQpaWindow) <<
"Ensuring that" <<
m_view <<
"is content view for" << newWindow;
1580 [
m_view setPostsFrameChangedNotifications:NO];
1581 [newWindow setContentView:
m_view];
1582 [
m_view setPostsFrameChangedNotifications:YES];
1589 if (parentCocoaWindow) {
1591 [parentCocoaWindow->m_view addSubview:
m_view];
1597 qCDebug(lcQpaDrawing) <<
"QCocoaWindow::requestUpdate" <<
window()
1602 qCDebug(lcQpaDrawing) <<
"Falling back to timer-based update request";
1619 qCDebug(lcQpaDrawing) <<
"Delivering update request to" <<
window();
1627 [
m_view.window makeKeyWindow];
1661 constexpr NSEventMask mouseButtonMask = NSEventTypeLeftMouseDown | NSEventTypeLeftMouseUp
1662 | NSEventMaskRightMouseDown | NSEventMaskOtherMouseDown
1663 | NSEventMaskMouseMoved;
1665 handler:^(NSEvent *e){
1677 const auto localPoint =
window->mapFromGlobal(globalPoint.toPoint());
1679 buttons,
button, eventType);
1691 addObserverForName:NSWorkspaceDidActivateApplicationNotification
1693 usingBlock:^(NSNotification *){
1708 QScreen *targetScreen =
nullptr;
1718 if (!targetScreen) {
1719 qCWarning(lcQpaWindow) <<
"Window position" <<
rect <<
"outside any known screen, using primary screen";
1724 styleMask = NSWindowStyleMaskBorderless;
1727 rect.translate(-targetScreen->geometry().topLeft());
1728 auto *targetCocoaScreen =
static_cast<QCocoaScreen *
>(targetScreen->handle());
1736 if (styleMask && (contentRect.origin.y + 24 > targetScreen->geometry().width())) {
1737 qCDebug(lcQpaWindow) <<
"Window positioned on portrait screen."
1738 <<
"Adjusting style mask during creation";
1739 styleMask = NSWindowStyleMaskBorderless;
1745 QCocoaNSWindow *nsWindow = [[windowClass alloc] initWithContentRect:contentRect
1750 backing:NSBackingStoreBuffered defer:NO
1751 screen:targetCocoaScreen->nativeScreen()
1752 platformWindow:
this];
1761 if (!resultingScreen)
1762 resultingScreen = targetCocoaScreen;
1771 nsWindow.delegate = sharedDelegate.get();
1777 [nsWindow setReleasedWhenClosed:NO];
1780 static dispatch_once_t onceToken;
1781 dispatch_once(&onceToken, ^{
1782 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
1783 [center addObserver:[
QNSWindow class]
selector:
@selector(applicationActivationChanged:)
1784 name:NSApplicationWillResignActiveNotification
object:nil];
1785 [center addObserver:[
QNSWindow class]
selector:
@selector(applicationActivationChanged:)
1786 name:NSApplicationWillBecomeActiveNotification
object:nil];
1790 nsWindow.restorable = NO;
1792 nsWindow.tabbingMode = NSWindowTabbingModeDisallowed;
1794 if (shouldBePanel) {
1799 nsWindow.collectionBehavior = NSWindowCollectionBehaviorFullScreenAuxiliary
1800 | NSWindowCollectionBehaviorMoveToActiveSpace;
1803 nsWindow.hasShadow = YES;
1804 nsWindow.animationBehavior = NSWindowAnimationBehaviorUtilityWindow;
1823 nsWindow.colorSpace = qtView.colorSpace;
1830 return qt_mac_resolveOption(
false,
window(),
"_q_macAlwaysShowToolWindow",
"");
1838 m_view.window.documentEdited = modified;
1858 qCInfo(lcQpaMouse) <<
"Setting" <<
this <<
"cursor to" <<
cursor;
1877 auto locationInWindow =
m_view.window.mouseLocationOutsideOfEventStream;
1878 auto locationInSuperview = [
m_view.superview convertPoint:locationInWindow fromView:nil];
1879 bool mouseIsOverView = [
m_view hitTest:locationInSuperview] ==
m_view;
1880 auto utilityMask = NSWindowStyleMaskUtilityWindow | NSWindowStyleMaskTitled;
1881 bool isUtilityWindow = (
m_view.window.styleMask & utilityMask) == utilityMask;
1882 if (mouseIsOverView && (
m_view.window.keyWindow || isUtilityWindow)) {
1883 qCDebug(lcQpaMouse) <<
"Synthesizing cursor update";
1884 [
m_view cursorUpdate:[NSEvent enterExitEventWithType:NSEventTypeCursorUpdate
1885 location:locationInWindow modifierFlags:0 timestamp:0
1887 eventNumber:0 trackingNumber:0 userData:0]];
1895 m_view.allowedTouchTypes |= NSTouchTypeMaskIndirect;
1897 m_view.allowedTouchTypes &= ~NSTouchTypeMaskIndirect;
1927 window.styleMask =
window.styleMask & ~NSWindowStyleMaskTexturedBackground;
1928 [
window.contentView.superview setNeedsDisplay:YES];
1929 window.titlebarAppearsTransparent = NO;
1935 std::sort(ranges.begin(), ranges.end());
1936 int effectiveTopContentBorderThickness = 0;
1945 if (
range.upper <= (effectiveTopContentBorderThickness + 1))
1946 effectiveTopContentBorderThickness =
qMax(effectiveTopContentBorderThickness,
range.lower);
1951 int effectiveBottomContentBorderThickness = 0;
1953 [
window setStyleMask:[
window styleMask] | NSWindowStyleMaskTexturedBackground];
1954 window.titlebarAppearsTransparent = YES;
1959 const NSRect frameRect =
window.frame;
1960 const NSRect contentRect = [
window contentRectForFrameRect:frameRect];
1961 const CGFloat titlebarHeight = frameRect.size.height - contentRect.size.height;
1962 effectiveTopContentBorderThickness += titlebarHeight;
1964 [
window setContentBorderThickness:effectiveTopContentBorderThickness forEdge:NSMaxYEdge];
1965 [
window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
1967 [
window setContentBorderThickness:effectiveBottomContentBorderThickness forEdge:NSMinYEdge];
1968 [
window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
1970 [[[
window contentView] superview] setNeedsDisplay:YES];
1981 const int contentBorderThickness = [
m_view.window contentBorderThicknessForEdge:NSMaxYEdge];
1982 const NSRect frameRect =
m_view.window.frame;
1983 const NSRect contentRect = [
m_view.window contentRectForFrameRect:frameRect];
1984 const CGFloat titlebarHeight = frameRect.size.height - contentRect.size.height;
1985 return 0 <=
position &&
position < (contentBorderThickness - titlebarHeight);
1995 NSSize backingSize = [
m_view convertSizeToBacking:NSMakeSize(1.0, 1.0)];
1996 return backingSize.height;
2003 if (
QWindow *childWindow = qobject_cast<QWindow *>(
child))
2005 if (
handle->isExposed() && childWindow->geometry().contains(windowPoint))
2008 return targetWindow;
2026 QWindow *modalWindow =
nullptr;
2029 qCDebug(lcQpaWindow) <<
"Refusing key window for" <<
this <<
"due to being"
2030 <<
"blocked by" << modalWindow;
2037 if (showWithoutActivating.
isValid() && showWithoutActivating.
toBool())
2046 switch (
event->type()) {
2063 : NSMakePoint(0, 0);
2064 const NSRect visibleRect = [
m_view visibleRect];
2066 return QPoint(visibleRect.origin.x, -visibleRect.origin.y + (origin.y - visibleRect.size.height));
2074 NSRect frameW =
m_view.window.frame;
2075 NSRect frameC = [
m_view.window contentRectForFrameRect:frameW];
2077 return QMargins(frameW.origin.x - frameC.origin.x,
2078 (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
2079 (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
2080 frameC.origin.y - frameW.origin.y);
2088#ifndef QT_NO_DEBUG_STREAM
2103#include "moc_qcocoawindow.cpp"
static QCocoaIntegration * instance()
static CGPoint mapToNative(const QPointF &pos, QCocoaScreen *screen=QCocoaScreen::primaryScreen())
static QCocoaScreen * get(NSScreen *nsScreen)
static QPointF mapFromNative(CGPoint pos, QCocoaScreen *screen=QCocoaScreen::primaryScreen())
void handleWindowStateChanged(HandleFlags flags=NoHandleFlags)
static void setupPopupMonitor()
void setContentBorderAreaEnabled(quintptr identifier, bool enable)
bool alwaysShowToolWindow() const
void setMenubar(QCocoaMenuBar *mb)
QWindow * childWindowAt(QPoint windowPoint)
void setAlertState(bool enabled) override
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
Qt::WindowModality m_windowModality
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void setWindowCursor(NSCursor *cursor)
bool testContentBorderAreaPosition(int position) const
QRect normalGeometry() const override
the geometry of the window as it will appear when shown as a normal (not maximized or full screen) to...
bool updatesWithDisplayLink() const
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
bool isForeignWindow() const override
bool setMouseGrabEnabled(bool grab) override
QCocoaNSWindow * m_nsWindow
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
QCocoaNSWindow * createNSWindow(bool shouldBePanel)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
static id s_globalMouseMonitor
void setMask(const QRegion ®ion) override
Reimplement to be able to let Qt set the mask of a window.
QHash< quintptr, bool > m_enabledContentBorderAreas
QCocoaWindow(QWindow *tlw, WId nativeHandle=0)
void setFrameStrutEventsEnabled(bool enabled) override
Reimplement this method to set whether frame strut events should be sent to enabled.
QCocoaMenuBar * menubar() const
void setWindowFilePath(const QString &filePath) override
Reimplement to set the window file path to filePath.
void setCocoaGeometry(const QRect &rect)
QRect geometry() const override
Returns the current geometry of a window.
NSInteger windowLevel(Qt::WindowFlags flags)
void setContentBorderEnabled(bool enable) override
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
static void removePopupMonitor()
bool m_frameStrutEventsEnabled
bool setWindowModified(bool modified) override
Reimplement to be able to let Qt indicate that the window has been modified.
NSWindow * nativeWindow() const
void applyContentBorderThickness(NSWindow *window=nullptr)
void setWindowState(Qt::WindowStates state) override
Changes the state of the NSWindow, going in/out of minimize/zoomed/fullscreen.
void registerTouch(bool enable)
void updateTitleBarButtons(Qt::WindowFlags flags)
QMargins frameMargins() const override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void updateNormalGeometry()
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
void deliverUpdateRequest() override
Delivers an QEvent::UpdateRequest event to the window.
bool isEmbedded() const override
Returns true if the window is a child of a non-Qt window.
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
bool shouldRefuseKeyWindowAndFirstResponder()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
static QPointer< QCocoaWindow > s_windowUnderMouse
static void closeAllPopups()
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
bool isContentView() const
Checks if the window is the content view of its immediate NSWindow.
void recreateWindowIfNeeded()
Recreates (or removes) the NSWindow for this QWindow, if needed.
void handleGeometryChange()
bool m_drawContentBorderGradient
bool m_resizableTransientParent
NSUInteger windowStyleMask(Qt::WindowFlags flags)
QCocoaMenuBar * m_menubar
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
static const int NoAlertRequest
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
bool setKeyboardGrabEnabled(bool grab) override
bool windowIsPopupType(Qt::WindowType type=Qt::Widget) const
void registerContentBorderArea(quintptr identifier, int upper, int lower)
void setEmbeddedInForeignView()
void applyWindowState(Qt::WindowStates newState)
QPoint bottomLeftClippedByNSWindowOffset() const override
bool isTransitioningToFullScreen() const
QHash< quintptr, BorderRange > m_contentBorderAreas
Qt::WindowStates windowState() const
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
Qt::WindowStates m_lastReportedWindowState
QSurfaceFormat format() const override
Returns the actual surface format of the window.
static id s_applicationActivationObserver
void handleExposeEvent(const QRegion ®ion)
static QGuiApplicationPrivate * instance()
static QWindow * currentMouseWindow
static Qt::ApplicationState applicationState()
static QWindow * topLevelAt(const QPoint &pos)
Returns the top level window at the given position pos, if any.
static QWindowList allWindows()
Returns a list of all the windows in the application.
QScreen * primaryScreen
the primary (or default) screen of the application.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QIcon class provides scalable icons in different modes and states.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
constexpr int left() const noexcept
Returns the left margin.
constexpr int top() const noexcept
Returns the top margin.
static QObjectPrivate * get(QObject *o)
const QObjectList & children() const
Returns a list of child objects.
QObject * parent() const
Returns a pointer to the parent object.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
QVariant property(const char *name) const
Returns the value of the object's name property.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
The QRegion class specifies a clip region for a painter.
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
The QScreen class is used to query screen properties. \inmodule QtGui.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isNull() const noexcept
Returns true if both the width and height is 0; otherwise returns false.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
bool supportsOpenGL() const
Returns true if the surface is OpenGL compatible and can be used in conjunction with QOpenGLContext; ...
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
static QWindowPrivate * get(QWindow *window)
static Qt::WindowState effectiveState(Qt::WindowStates)
static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Make Qt Gui process all events on the event queue immediately.
static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void handleGeometryChange(QWindow *window, const QRect &newRect)
Qt::WindowFlags flags
the window flags of the window
QSurfaceFormat format() const override
Returns the actual format of this window.
QString title
the window's title in the windowing system
Qt::WindowModality modality
the modality of the window
qreal opacity
The opacity of the window in the windowing system.
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
struct wl_display * display
QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *window)
Combined button and popup list for selecting options.
@ WindowDoesNotAcceptFocus
@ WindowFullscreenButtonHint
@ WindowMaximizeButtonHint
@ WindowMinimizeButtonHint
@ WindowTransparentForInput
@ ActiveWindowFocusReason
QNSView * qnsview_cast(NSView *view)
Returns the view cast to a QNSview if possible.
QEvent::Type cocoaEvent2QtMouseEvent(NSEvent *event)
Returns the QEvent::Type that corresponds to an NSEvent.type.
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
Returns the Qt::Button that corresponds to an NSEvent.buttonNumber.
Qt::MouseButtons currentlyPressedMouseButtons()
Returns the Qt::MouseButtons that corresponds to an NSEvent.pressedMouseButtons.
#define Q_NOTIFICATION_PREFIX
const NSNotificationName QCocoaWindowWillReleaseQNSViewNotification
static void qRegisterNotificationCallbacks()
QDebug operator<<(QDebug debug, const QCocoaWindow *window)
const NSNotificationName QCocoaWindowWillReleaseQNSViewNotification
Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
constexpr const T & qMax(const T &a, const T &b)
typedef GLint(GL_APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXEXTPROC)(GLuint program
GLuint64 GLenum void * handle
GLenum GLuint GLint level
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT_X(cond, x, msg)
#define qPrintable(string)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
QFileSelector selector
[1]
obj metaObject() -> className()