From 5c6b2ede3bdfb5ba5eefb6e7cd7c5d3286a1e1b3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 21 Mar 2013 17:17:44 +0100 Subject: OSX: WindowTransparentForInput QNSView pass events to next responder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default implementation (in the super class) passes the event to the next responder. This seems to be one valid way to handle the Qt::WindowTransparentForInput flag. So if a non-alien widget for which a native NSView is created has the flag WA_TransparentForMouseEvents, that means the window will have Qt::WindowTransparentForInput, and the NSView which is created on its behalf will pass on each event so that other NSViews have a chance to handle it. (It will also try to reject becoming first responder, but that doesn't seem to be enough for the following events to be passed on.) This is a followup to I979be9f72f7d225d7b960fc5db4c3956d2749982 which purported to obey the WindowTransparentForInput flag, but actually doesn't. Change-Id: Ia72a3573c2e3cbfa7ede70bee41ac36df6924598 Task-number: QTBUG-28816 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview.mm | 39 ++++++++++++++++++++++++++++++++-- src/widgets/kernel/qwidget.cpp | 3 ++- 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index a16e6c837a..4ff44ca7f5 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -410,6 +410,8 @@ static QTouchDevice *touchDevice = 0; - (BOOL)becomeFirstResponder { + if (m_window->flags() & Qt::WindowTransparentForInput) + return NO; QWindow *focusWindow = m_window; // For widgets we need to do a bit of trickery as the window @@ -427,6 +429,8 @@ static QTouchDevice *touchDevice = 0; { if (m_window->flags() & Qt::WindowDoesNotAcceptFocus) return NO; + if (m_window->flags() & Qt::WindowTransparentForInput) + return NO; if ((m_window->flags() & Qt::ToolTip) == Qt::ToolTip) return NO; return YES; @@ -434,7 +438,9 @@ static QTouchDevice *touchDevice = 0; - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { - Q_UNUSED(theEvent); + Q_UNUSED(theEvent) + if (m_window->flags() & Qt::WindowTransparentForInput) + return NO; return YES; } @@ -539,6 +545,8 @@ static QTouchDevice *touchDevice = 0; - (void)mouseDown:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseDown:theEvent]; m_sendUpAsRightButton = false; if (m_platformWindow->m_activePopupWindow) { QWindowSystemInterface::handleCloseEvent(m_platformWindow->m_activePopupWindow); @@ -563,6 +571,8 @@ static QTouchDevice *touchDevice = 0; - (void)mouseDragged:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseDragged:theEvent]; if (!(m_buttons & Qt::LeftButton)) qWarning("QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)"); [self handleMouseEvent:theEvent]; @@ -570,6 +580,8 @@ static QTouchDevice *touchDevice = 0; - (void)mouseUp:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseUp:theEvent]; if (m_sendUpAsRightButton) { m_buttons &= ~Qt::RightButton; m_sendUpAsRightButton = false; @@ -614,11 +626,15 @@ static QTouchDevice *touchDevice = 0; - (void)mouseMoved:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseMoved:theEvent]; [self handleMouseEvent:theEvent]; } - (void)mouseEntered:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseEntered:theEvent]; QPoint windowPoint, screenPoint; [self convertFromEvent:theEvent toWindowPoint:&windowPoint andScreenPoint:&screenPoint]; QWindowSystemInterface::handleEnterEvent(m_window, windowPoint, screenPoint); @@ -626,18 +642,23 @@ static QTouchDevice *touchDevice = 0; - (void)mouseExited:(NSEvent *)theEvent { - Q_UNUSED(theEvent); + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super mouseExited:theEvent]; QWindowSystemInterface::handleLeaveEvent(m_window); } - (void)rightMouseDown:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super rightMouseDown:theEvent]; m_buttons |= Qt::RightButton; [self handleMouseEvent:theEvent]; } - (void)rightMouseDragged:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super rightMouseDragged:theEvent]; if (!(m_buttons & Qt::RightButton)) qWarning("QNSView rightMouseDragged: Internal mouse button tracking invalid (missing Qt::RightButton)"); [self handleMouseEvent:theEvent]; @@ -645,18 +666,24 @@ static QTouchDevice *touchDevice = 0; - (void)rightMouseUp:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super rightMouseUp:theEvent]; m_buttons &= ~Qt::RightButton; [self handleMouseEvent:theEvent]; } - (void)otherMouseDown:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super otherMouseDown:theEvent]; m_buttons |= cocoaButton2QtButton([theEvent buttonNumber]); [self handleMouseEvent:theEvent]; } - (void)otherMouseDragged:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super otherMouseDragged:theEvent]; if (!(m_buttons & ~(Qt::LeftButton | Qt::RightButton))) qWarning("QNSView otherMouseDragged: Internal mouse button tracking invalid (missing Qt::MiddleButton or Qt::ExtraButton*)"); [self handleMouseEvent:theEvent]; @@ -664,6 +691,8 @@ static QTouchDevice *touchDevice = 0; - (void)otherMouseUp:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super otherMouseUp:theEvent]; m_buttons &= ~cocoaButton2QtButton([theEvent buttonNumber]); [self handleMouseEvent:theEvent]; } @@ -699,6 +728,8 @@ static QTouchDevice *touchDevice = 0; #ifndef QT_NO_WHEELEVENT - (void)scrollWheel:(NSEvent *)theEvent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super scrollWheel:theEvent]; const EventRef carbonEvent = (EventRef)[theEvent eventRef]; const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0; const bool scrollEvent = carbonEventKind == kEventMouseScroll; @@ -864,11 +895,15 @@ static QTouchDevice *touchDevice = 0; - (void)keyDown:(NSEvent *)nsevent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super keyDown:nsevent]; [self handleKeyEvent:nsevent eventType:int(QEvent::KeyPress)]; } - (void)keyUp:(NSEvent *)nsevent { + if (m_window->flags() & Qt::WindowTransparentForInput) + return [super keyUp:nsevent]; [self handleKeyEvent:nsevent eventType:int(QEvent::KeyRelease)]; } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 3e1e0f592c..0ef6b1735b 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1083,7 +1083,8 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) else flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint; - + if (w->testAttribute(Qt::WA_TransparentForMouseEvents)) + flags |= Qt::WindowTransparentForInput; } void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) -- cgit v1.2.3