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];
64 if ([
window conformsToProtocol:
@protocol(QNSWindowProtocol)])
65 return static_cast<QCocoaNSWindow *
>(
window);
71#define QNSWINDOW_PROTOCOL_IMPLMENTATION 1
73#undef QNSWINDOW_PROTOCOL_IMPLMENTATION
75+ (
void)applicationActivationChanged:(NSNotification*)notification
77 const id sender = self;
78 NSEnumerator<NSWindow*> *windowEnumerator =
nullptr;
79 NSApplication *application = [NSApplication sharedApplication];
83 NSMutableArray<NSWindow *> *windows = [[NSMutableArray<NSWindow *> new] autorelease];
84 [application enumerateWindowsWithOptions:NSWindowListOrderedFrontToBack
85 usingBlock:^(NSWindow *window, BOOL *) {
90 [windows addObject:window];
94 windowEnumerator = windows.reverseObjectEnumerator;
96 for (NSWindow *
window in windowEnumerator) {
98 if (!(
window.level == NSNormalWindowLevel ||
window.level == NSFloatingWindowLevel))
106 if (
window.hidesOnDeactivate)
109 if ([
window conformsToProtocol:
@protocol(QNSWindowProtocol)]) {
110 if (
QCocoaWindow *cocoaWindow =
static_cast<QCocoaNSWindow *
>(
window).platformWindow) {
111 window.level = notification.name == NSApplicationWillResignActiveNotification ?
112 NSNormalWindowLevel : cocoaWindow->windowLevel(cocoaWindow->window()->flags());
128 [window orderFront:sender];
135#define QNSWINDOW_PROTOCOL_IMPLMENTATION 1
137#undef QNSWINDOW_PROTOCOL_IMPLMENTATION
139- (BOOL)worksWhenModal
141 if (!m_platformWindow)
155 if (!NSApp.modalWindow)
168 if (![NSApp.modalWindow conformsToProtocol:
@protocol(QNSWindowProtocol)])
171 if (
auto *modalWindow =
static_cast<QCocoaNSWindow *
>(NSApp.modalWindow).platformWindow) {
172 if (modalWindow->window()->isAncestorOf(m_platformWindow->window(), QWindow::IncludeTransients))
186 QPointer<QCocoaWindow> m_platformWindow;
190- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style
191 backing:(NSBackingStoreType)backingStoreType defer:(BOOL)defer screen:(NSScreen *)screen
197 m_platformWindow =
window;
199 m_isMinimizing =
false;
201 return [
super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:defer screen:screen];
206 return m_platformWindow;
209- (
void)setContentView:(NSView*)view
211 [
super setContentView:view];
223 m_platformWindow->propagateSizeHints();
224 m_platformWindow->setWindowFlags(
window->flags());
225 m_platformWindow->setWindowTitle(
window->title());
226 m_platformWindow->setWindowFilePath(
window->filePath());
227 m_platformWindow->setWindowState(
window->windowState());
228 m_platformWindow->setOpacity(
window->opacity());
229 m_platformWindow->setVisible(
window->isVisible());
232- (NSString *)description
234 NSMutableString *description = [NSMutableString stringWithString:[
super description]];
236#ifndef QT_NO_DEBUG_STREAM
237 QString contentViewDescription;
241 NSRange lastCharacter = [description rangeOfComposedCharacterSequenceAtIndex:description.length - 1];
242 [description replaceCharactersInRange:lastCharacter withString:contentViewDescription.toNSString()];
248- (BOOL)canBecomeKeyWindow
250 if (!m_platformWindow)
253 if (m_platformWindow->shouldRefuseKeyWindowAndFirstResponder())
256 if ([self isKindOfClass:[
QNSPanel class]]) {
271- (BOOL)canBecomeMainWindow
275 if (!m_platformWindow || m_platformWindow->window()->transientParent())
278 return [
super canBecomeMainWindow];
283 return m_platformWindow ? m_platformWindow->isOpaque() : [
super isOpaque];
292 const QWindow *
window = m_platformWindow ? m_platformWindow->window() :
nullptr;
298 return [NSColor clearColor];
304 return [
super backgroundColor];
307- (
void)sendEvent:(NSEvent*)theEvent
309 qCDebug(lcQpaEvents) <<
"Sending" << theEvent <<
"to" <<
self;
316 if (!m_platformWindow)
321 [[
self retain] autorelease];
323 const char *eventType = object_getClassName(theEvent);
329 const bool mouseEventInFrameStrut = [theEvent, self]{
331 const NSPoint loc = theEvent.locationInWindow;
332 const NSRect windowFrame = [
self convertRectFromScreen:self.frame];
333 const NSRect contentFrame =
self.contentView.frame;
334 if (NSMouseInRect(loc, windowFrame, NO) && !NSMouseInRect(loc, contentFrame, NO))
342 if (theEvent.type == NSEventTypeLeftMouseDown && mouseEventInFrameStrut)
345 [
super sendEvent:theEvent];
347 if (!m_platformWindow)
356 qCDebug(lcQpaWindow) <<
"Mouse event over modally blocked window" << m_platformWindow->window()
357 <<
"while popup is open - redirecting";
358 [qnsview_cast(m_platformWindow->view()) handleMouseEvent:theEvent];
360 if (m_platformWindow->frameStrutEventsEnabled() && mouseEventInFrameStrut)
361 [qnsview_cast(m_platformWindow->view()) handleFrameStrutMouseEvent:theEvent];
364- (
void)miniaturize:(
id)sender
367 [
super miniaturize:sender];
370- (NSButton *)standardWindowButton:(NSWindowButton)buttonType
372 NSButton *
button = [
super standardWindowButton:buttonType];
383 if (buttonType == NSWindowMiniaturizeButton && m_isMinimizing && !
button.
enabled)
384 return [NSWindow standardWindowButton:buttonType forStyleMask:self.styleMask];
389- (
void)closeAndRelease
391 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.
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.
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,...)
NSWindow< QNSWindowProtocol > * qnswindow_cast(NSWindow *window)
static bool isMouseEvent(NSEvent *ev)