OS X - unified toolbar and AA_NativeWindows

In some cases QToolBar creates a child window (a child borderless NSWindow)
placed on top of the toolbar's  main window. As a result it's not possible
to drag this main window using its toolbar - the window "jumps" on the screen.
The reason is quite subtle - QNSView -handleMouseEvent: uses
[NSEvent mouseLocation] and this location is invalid:

- we have an NSWindow (parent)
- we have a child NSWindow ([parent addChildWindow:child ....]
- we handle drag event in a child window
- we move a parent window as a result of drag event
- Cocoa also moves a child window for us
- when handling the  next drag event, location [NSEvent mouseLocation]
  differs from the real event's location.

Task-number: QTBUG-40106
Change-Id: Ic68cb92ab4233a1e0746b478820c1e33fd37a462
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Timur Pocheptsov 2014-10-16 12:53:04 +02:00
parent a6ebc9b34a
commit ae5f3df59b

View File

@ -686,7 +686,23 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
m_platformWindow->m_forwardWindow = 0;
}
[targetView convertFromScreen:[NSEvent mouseLocation] toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
NSPoint globalPos = [NSEvent mouseLocation];
if ([self.window parentWindow]
&& (theEvent.type == NSLeftMouseDragged || theEvent.type == NSLeftMouseUp)) {
// QToolBar can be implemented as a child window on top of its main window
// (with a borderless NSWindow). If an option "unified toolbar" set on the main window,
// it's possible to drag such a window using this toolbar.
// While handling mouse drag events, QToolBar moves the window (QWidget::move).
// In such a combination [NSEvent mouseLocation] is very different from the
// real event location and as a result a window will move chaotically.
NSPoint winPoint = [theEvent locationInWindow];
NSRect tmpRect = NSMakeRect(winPoint.x, winPoint.y, 1., 1.);
tmpRect = [[theEvent window] convertRectToScreen:tmpRect];
globalPos = tmpRect.origin;
}
[targetView convertFromScreen:globalPos toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
ulong timestamp = [theEvent timestamp] * 1000;
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();