Position windows with transient parents properly
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Sat, 19 May 2012 10:24:10 +0000 (13:24 +0300)
committerJørgen Lind <jorgen.lind@nokia.com>
Mon, 21 May 2012 06:40:52 +0000 (08:40 +0200)
Both the transient position calculation and the global mouse
position had to be fixed.

Combo box contents, menus, etc. will now all appear at the
correct position. With qwindow-compositor they will
keep the proper position even when the parent is moved
via the decoration. Not sure how this could be achieved
with weston as there is no notification when the window
is dragged with Super+Mouse. Nevertheless the initial
position will be correct.

Change-Id: I66eca9faa930af71b9b540018d5057af7f5f22e5
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
src/plugins/platforms/wayland/qwaylandinputdevice.cpp
src/plugins/platforms/wayland/qwaylandshellsurface.cpp
src/plugins/platforms/wayland/qwaylandwindow.cpp

index d0c6d79..b96035d 100644 (file)
@@ -271,7 +271,7 @@ void QWaylandInputDevice::pointer_motion(void *data,
     window->handleMouse(inputDevice,
                         time,
                         inputDevice->mSurfacePos,
-                        inputDevice->mSurfacePos,
+                        inputDevice->mGlobalPos,
                         inputDevice->mButtons,
                         Qt::NoModifier);
 }
@@ -321,7 +321,7 @@ void QWaylandInputDevice::pointer_button(void *data,
         window->handleMouse(inputDevice,
                             time,
                             inputDevice->mSurfacePos,
-                            inputDevice->mSurfacePos,
+                            inputDevice->mGlobalPos,
                             inputDevice->mButtons,
                             Qt::NoModifier);
     }
@@ -446,7 +446,6 @@ void QWaylandInputDevice::keyboard_leave(void *data,
     Q_UNUSED(surface);
 
     QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
-
     inputDevice->mKeyboardFocus = NULL;
     inputDevice->mQDisplay->setLastKeyboardFocusInputDevice(0);
     QWindowSystemInterface::handleWindowActivated(0);
index 8d7498a..3a85a19 100644 (file)
@@ -80,7 +80,10 @@ void QWaylandShellSurface::updateTransientParent(QWindow *parent)
     if (!parent_wayland_window || !parent_wayland_window->shellSurface())
         return;
 
-    QPoint transientPos = m_window->geometry().topLeft();
+    // set_transient expects a position relative to the parent
+    QPoint transientPos = m_window->geometry().topLeft(); // this is absolute
+    QWindow *parentWin = m_window->window()->transientParent();
+    transientPos -= parentWin->geometry().topLeft();
     if (parent_wayland_window->decoration()) {
         transientPos.setX(transientPos.x() + parent_wayland_window->decoration()->margins().left());
         transientPos.setY(transientPos.y() + parent_wayland_window->decoration()->margins().top());
index fffdd52..f90e3f5 100644 (file)
@@ -360,20 +360,23 @@ void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDe
         return;
     }
 
-    QPointF localTranslated = local;
     QMargins marg = frameMargins();
     QRect windowRect(0 + marg.left(),
                      0 + marg.top(),
                      geometry().size().width() - marg.right(),
                      geometry().size().height() - marg.bottom());
     if (windowRect.contains(local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
+        QPointF localTranslated = local;
+        QPointF globalTranslated = global;
         localTranslated.setX(localTranslated.x() - marg.left());
         localTranslated.setY(localTranslated.y() - marg.top());
+        globalTranslated.setX(localTranslated.x() - marg.left());
+        globalTranslated.setY(localTranslated.y() - marg.top());
         if (!mMouseEventsInContentArea) {
             mWindowDecoration->restoreMouseCursor();
             QWindowSystemInterface::handleEnterEvent(window());
         }
-        QWindowSystemInterface::handleMouseEvent(window(),timestamp,localTranslated,global,b,mods);
+        QWindowSystemInterface::handleMouseEvent(window(), timestamp, localTranslated, globalTranslated, b, mods);
         mMouseEventsInContentArea = true;
         mMousePressedInContentArea = b;
     } else {