Fix output geometry in qwindow-compositor
[profile/ivi/qtwayland.git] / examples / qwindow-compositor / qwindowcompositor.cpp
index b9661f0..65aafb0 100644 (file)
@@ -48,6 +48,7 @@
 #include <QCursor>
 #include <QPixmap>
 #include <QLinkedList>
+#include <QScreen>
 
 #include <QtCompositor/waylandinput.h>
 
@@ -58,6 +59,7 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
     , m_renderScheduler(this)
     , m_draggingWindow(0)
     , m_dragKeyIsPressed(false)
+    , m_modifiers(Qt::NoModifier)
 {
     enableSubSurfaceExtension();
     m_window->makeCurrent();
@@ -74,6 +76,9 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
     window->installEventFilter(this);
 
     setRetainedSelectionEnabled(true);
+
+    setOutputGeometry(QRect(QPoint(0, 0), window->size()));
+    setOutputRefreshRate(qGuiApp->primaryScreen()->refreshRate());
 }
 
 QWindowCompositor::~QWindowCompositor()
@@ -242,8 +247,7 @@ void QWindowCompositor::render()
 
     m_textureBlitter->release();
     frameFinished();
-    glFinish();
-
+    // N.B. Never call glFinish() here as the busylooping with vsync 'feature' of the nvidia binary driver is not desirable.
     m_window->swapBuffers();
 }
 
@@ -257,6 +261,19 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
     switch (event->type()) {
     case QEvent::Expose:
         m_renderScheduler.start(0);
+        if (m_window->isExposed()) {
+            // Alt-tabbing away normally results in the alt remaining in
+            // pressed state in the clients xkb state. Prevent this by sending
+            // a release. This is not an issue in a "real" compositor but
+            // is very annoying when running in a regular window on xcb.
+            Qt::KeyboardModifiers mods = QGuiApplication::queryKeyboardModifiers();
+            if (m_modifiers != mods && input->keyboardFocus()) {
+                Qt::KeyboardModifiers stuckMods = m_modifiers ^ mods;
+                if (stuckMods & Qt::AltModifier)
+                    input->sendKeyReleaseEvent(64); // native scancode for left alt
+                m_modifiers = mods;
+            }
+        }
         break;
     case QEvent::MouseButtonPress: {
         QPointF local;
@@ -302,11 +319,17 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
         }
         break;
     }
+    case QEvent::Wheel: {
+        QWheelEvent *we = static_cast<QWheelEvent *>(event);
+        input->sendMouseWheelEvent(we->orientation(), we->delta());
+        break;
+    }
     case QEvent::KeyPress: {
         QKeyEvent *ke = static_cast<QKeyEvent *>(event);
         if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
             m_dragKeyIsPressed = true;
         }
+        m_modifiers = ke->modifiers();
         WaylandSurface *targetSurface = input->keyboardFocus();
         if (targetSurface)
             input->sendKeyPressEvent(ke->nativeScanCode());
@@ -317,6 +340,7 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
         if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
             m_dragKeyIsPressed = false;
         }
+        m_modifiers = ke->modifiers();
         WaylandSurface *targetSurface = input->keyboardFocus();
         if (targetSurface)
             input->sendKeyReleaseEvent(ke->nativeScanCode());