4#if !defined(QNSWINDOW_PROTOCOL_IMPLMENTATION)
14#include <qpa/qwindowsysteminterface.h>
22 case NSEventTypeLeftMouseDown:
23 case NSEventTypeLeftMouseUp:
24 case NSEventTypeRightMouseDown:
25 case NSEventTypeRightMouseUp:
26 case NSEventTypeMouseMoved:
27 case NSEventTypeLeftMouseDragged:
28 case NSEventTypeRightMouseDragged:
35@implementation NSWindow (FullScreenProperty)
39 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
40 [center addObserverForName:NSWindowDidEnterFullScreenNotification object:nil queue:nil
41 usingBlock:^(NSNotification *notification) {
42 objc_setAssociatedObject(notification.object, @selector(qt_fullScreen),
43 @(YES), OBJC_ASSOCIATION_RETAIN);
46 [center addObserverForName:NSWindowDidExitFullScreenNotification object:nil queue:nil
47 usingBlock:^(NSNotification *notification) {
48 objc_setAssociatedObject(notification.object, @selector(qt_fullScreen),
49 nil, OBJC_ASSOCIATION_RETAIN);
56 NSNumber *
number = objc_getAssociatedObject(self,
@selector(qt_fullScreen));
57 return [number boolValue];
62#define QNSWINDOW_PROTOCOL_IMPLMENTATION 1
64#undef QNSWINDOW_PROTOCOL_IMPLMENTATION
66+ (
void)applicationActivationChanged:(NSNotification*)notification
68 const id sender = self;
69 NSEnumerator<NSWindow*> *windowEnumerator =
nullptr;
70 NSApplication *application = [NSApplication sharedApplication];
74 NSMutableArray<NSWindow *> *windows = [[NSMutableArray<NSWindow *> new] autorelease];
75 [application enumerateWindowsWithOptions:NSWindowListOrderedFrontToBack
76 usingBlock:^(NSWindow *window, BOOL *) {
81 [windows addObject:window];
85 windowEnumerator = windows.reverseObjectEnumerator;
87 for (NSWindow *
window in windowEnumerator) {
89 if (!(
window.level == NSNormalWindowLevel ||
window.level == NSFloatingWindowLevel))
97 if (
window.hidesOnDeactivate)
100 if ([
window conformsToProtocol:
@protocol(QNSWindowProtocol)]) {
102 window.level = notification.name == NSApplicationWillResignActiveNotification ?
118 [window orderFront:sender];
125#define QNSWINDOW_PROTOCOL_IMPLMENTATION 1
127#undef QNSWINDOW_PROTOCOL_IMPLMENTATION
129- (BOOL)worksWhenModal
131 if (!m_platformWindow)
145 if (!NSApp.modalWindow)
158 if (![NSApp.modalWindow conformsToProtocol:
@protocol(QNSWindowProtocol)])
161 if (
auto *modalWindow =
static_cast<QCocoaNSWindow *
>(NSApp.modalWindow).platformWindow) {
162 if (modalWindow->window()->isAncestorOf(m_platformWindow->window(), QWindow::IncludeTransients))
180- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style
181 backing:(NSBackingStoreType)backingStoreType defer:(BOOL)defer screen:(NSScreen *)screen
187 m_platformWindow =
window;
189 m_isMinimizing =
false;
191 return [
super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:defer screen:screen];
196 return m_platformWindow;
199- (
void)setContentView:(NSView*)view
201 [
super setContentView:view];
213 m_platformWindow->propagateSizeHints();
214 m_platformWindow->setWindowFlags(
window->flags());
215 m_platformWindow->setWindowTitle(
window->title());
216 m_platformWindow->setWindowFilePath(
window->filePath());
217 m_platformWindow->setWindowState(
window->windowState());
218 m_platformWindow->setOpacity(
window->opacity());
221- (NSString *)description
223 NSMutableString *description = [NSMutableString stringWithString:[
super description]];
225#ifndef QT_NO_DEBUG_STREAM
226 QString contentViewDescription;
230 NSRange lastCharacter = [description rangeOfComposedCharacterSequenceAtIndex:description.length - 1];
231 [description replaceCharactersInRange:lastCharacter withString:contentViewDescription.toNSString()];
237- (BOOL)canBecomeKeyWindow
239 if (!m_platformWindow)
242 if (m_platformWindow->shouldRefuseKeyWindowAndFirstResponder())
245 if ([self isKindOfClass:[
QNSPanel class]]) {
260- (BOOL)canBecomeMainWindow
264 if (!m_platformWindow || m_platformWindow->window()->transientParent())
267 return [
super canBecomeMainWindow];
272 return m_platformWindow ? m_platformWindow->isOpaque() : [
super isOpaque];
281 const QWindow *
window = m_platformWindow ? m_platformWindow->window() :
nullptr;
287 return [NSColor clearColor];
293 return [
super backgroundColor];
296- (
void)sendEvent:(NSEvent*)theEvent
298 qCDebug(lcQpaEvents) <<
"Sending" << theEvent <<
"to" <<
self;
305 if (!m_platformWindow)
310 [[
self retain] autorelease];
312 const char *eventType = object_getClassName(theEvent);
318 const bool mouseEventInFrameStrut = [theEvent, self]{
320 const NSPoint loc = theEvent.locationInWindow;
321 const NSRect windowFrame = [
self convertRectFromScreen:self.frame];
322 const NSRect contentFrame =
self.contentView.frame;
323 if (NSMouseInRect(loc, windowFrame, NO) && !NSMouseInRect(loc, contentFrame, NO))
331 if (theEvent.type == NSEventTypeLeftMouseDown && mouseEventInFrameStrut)
334 [
super sendEvent:theEvent];
336 if (!m_platformWindow)
345 qCDebug(lcQpaWindow) <<
"Mouse event over modally blocked window" << m_platformWindow->window()
346 <<
"while popup is open - redirecting";
347 [qnsview_cast(m_platformWindow->view()) handleMouseEvent:theEvent];
349 if (m_platformWindow->frameStrutEventsEnabled() && mouseEventInFrameStrut)
350 [qnsview_cast(m_platformWindow->view()) handleFrameStrutMouseEvent:theEvent];
353- (
void)miniaturize:(
id)sender
356 [
super miniaturize:sender];
359- (NSButton *)standardWindowButton:(NSWindowButton)buttonType
361 NSButton *
button = [
super standardWindowButton:buttonType];
372 if (buttonType == NSWindowMiniaturizeButton && m_isMinimizing && !
button.
enabled)
373 return [NSWindow standardWindowButton:buttonType forStyleMask:self.styleMask];
378- (
void)closeAndRelease
380 qCDebug(lcQpaWindow) <<
"Closing and releasing" <<
self;
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
NSInteger windowLevel(Qt::WindowFlags flags)
virtual bool closeAllPopups()
static QGuiApplicationPrivate * instance()
\macro QT_RESTRICTED_CAST_FROM_ASCII
static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result)
Passes a native event identified by eventType to the window.
Qt::WindowFlags flags
the window flags of the window
QColor backgroundColor(const QPalette &pal, const QWidget *widget)
size_t qstrlen(const char *str)
QNSView * qnsview_cast(NSView *view)
Returns the view cast to a QNSview if possible.
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 return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
static bool isMouseEvent(NSEvent *ev)