void LipstickCompositorWindow::touchEvent(QTouchEvent *event) { QWaylandSurface *m_surface = surface(); if (touchEventsEnabled() && m_surface) { QList<QTouchEvent::TouchPoint> points = event->touchPoints(); if (m_mouseRegionValid && points.count() == 1 && event->touchPointStates() & Qt::TouchPointPressed && !m_mouseRegion.contains(points.at(0).pos().toPoint())) { event->ignore(); return; } QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); event->accept(); if (inputDevice->mouseFocus() != m_surface) { QPoint pointPos; if (!points.isEmpty()) pointPos = points.at(0).pos().toPoint(); inputDevice->setMouseFocus(m_surface, pointPos, pointPos); } inputDevice->sendFullTouchEvent(event); } else { event->ignore(); } }
void QWaylandWindow::unfocus() { QWaylandInputDevice *inputDevice = mDisplay->currentInputDevice(); if (inputDevice && inputDevice->dataDevice()) { inputDevice->dataDevice()->invalidateSelectionOffer(); } }
void QWaylandDisplay::setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y) { /* Qt doesn't tell us which input device we should set the cursor * for, so set it for all devices. */ for (int i = 0; i < mInputDevices.count(); i++) { QWaylandInputDevice *inputDevice = mInputDevices.at(i); inputDevice->attach(buffer, x, y); } }
void QWaylandDisplay::setCursor(wl_surface *surface, int32_t x, int32_t y) { /* Qt doesn't tell us which input device we should set the cursor * for, so set it for all devices. */ for (int i = 0; i < mInputDevices.count(); i++) { QWaylandInputDevice *inputDevice = mInputDevices.at(i); inputDevice->setCursor(surface, x, y); } }
void LipstickCompositorWindow::mouseReleaseEvent(QMouseEvent *event) { QWaylandSurface *m_surface = surface(); if (m_surface && event->source() != Qt::MouseEventSynthesizedByQt) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); inputDevice->sendMouseReleaseEvent(event->button(), event->pos(), event->globalPos()); } else { event->ignore(); } }
void LipstickCompositorWindow::mouseMoveEvent(QMouseEvent *event) { QWaylandSurface *m_surface = surface(); if (m_surface){ QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); inputDevice->sendMouseMoveEvent(m_surface, event->pos(), event->globalPos()); } else { event->ignore(); } }
void LipstickCompositorWindow::wheelEvent(QWheelEvent *event) { QWaylandSurface *m_surface = surface(); if (m_surface) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); inputDevice->sendMouseWheelEvent(event->orientation(), event->delta()); } else { event->ignore(); } }
bool LipstickCompositorWindow::eventFilter(QObject *obj, QEvent *event) { #if QT_VERSION >= 0x050202 if (obj == window() && m_interceptingTouch) { switch (event->type()) { case QEvent::TouchUpdate: { QTouchEvent *te = static_cast<QTouchEvent *>(event); // If we get press/release, don't intercept the event, but send it through QQuickWindow. // These are sent through to QQuickWindow so that the integrity of the touch // handling is maintained. if (te->touchPointStates() & (Qt::TouchPointPressed | Qt::TouchPointReleased)) return false; handleTouchEvent(static_cast<QTouchEvent *>(event)); return true; } case QEvent::TouchEnd: // Intentional fall through... case QEvent::TouchCancel: obj->removeEventFilter(this); m_interceptingTouch = false; default: break; } return false; } #else Q_UNUSED(obj); #endif if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); QWaylandSurface *m_surface = surface(); if (m_surface && (m_grabbedKeys.contains(ke->key()) || m_pressedGrabbedKeys.keys.contains(ke->key())) && !ke->isAutoRepeat()) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); if (event->type() == QEvent::KeyPress) { if (m_pressedGrabbedKeys.keys.isEmpty()) { QWaylandSurface *old = inputDevice->keyboardFocus(); m_pressedGrabbedKeys.oldFocus = old; inputDevice->setKeyboardFocus(m_surface); } m_pressedGrabbedKeys.keys << ke->key(); } inputDevice->sendFullKeyEvent(ke); if (event->type() == QEvent::KeyRelease) { m_pressedGrabbedKeys.keys.removeOne(ke->key()); if (m_pressedGrabbedKeys.keys.isEmpty()) { inputDevice->setKeyboardFocus(m_pressedGrabbedKeys.oldFocus); if (m_grabbedKeys.isEmpty()) qApp->removeEventFilter(this); } } return true; } } return false; }
void LipstickCompositorWindow::handleTouchCancel() { QWaylandSurface *m_surface = surface(); if (!m_surface) return; QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); if (inputDevice->mouseFocus() == m_surface && (!isVisible() || !isEnabled() || !touchEventsEnabled())) { inputDevice->sendTouchCancelEvent(); inputDevice->setMouseFocus(0, QPointF()); } }
void LipstickCompositorWindow::mousePressEvent(QMouseEvent *event) { QWaylandSurface *m_surface = surface(); if (m_surface && (!m_mouseRegionValid || m_mouseRegion.contains(event->pos()))) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); if (inputDevice->mouseFocus() != m_surface) inputDevice->setMouseFocus(m_surface, event->pos(), event->globalPos()); inputDevice->sendMousePressEvent(event->button(), event->pos(), event->globalPos()); } else { event->ignore(); } }
bool LipstickCompositorWindow::eventFilter(QObject *, QEvent *event) { if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); QWaylandSurface *m_surface = surface(); if (m_surface && m_grabbedKeys.contains(ke->key())) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); inputDevice->sendFullKeyEvent(m_surface, ke); return true; } } return false; }
void CompositorSettings::setKeyboardRepeatDelay(quint32 delay) { Q_D(CompositorSettings); if (d->repeatDelay == delay) return; d->repeatDelay = delay; Q_EMIT keyboardRepeatDelayChanged(); if (d->compositor) { QWaylandInputDevice *inputDevice = d->compositor->defaultInputDevice(); if (inputDevice && inputDevice->keyboard()) inputDevice->keyboard()->setRepeatDelay(d->repeatDelay); } }
void CompositorSettings::setKeyboardRepeatRate(quint32 rate) { Q_D(CompositorSettings); if (d->repeatRate == rate) return; d->repeatRate = rate; Q_EMIT keyboardRepeatRateChanged(); if (d->compositor) { QWaylandInputDevice *inputDevice = d->compositor->defaultInputDevice(); if (inputDevice && inputDevice->keyboard()) inputDevice->keyboard()->setRepeatRate(d->repeatRate); } }
void LipstickCompositorWindow::mousePressEvent(QMouseEvent *event) { QWaylandSurface *m_surface = surface(); if (m_surface && (!m_mouseRegionValid || m_mouseRegion.contains(event->pos())) && m_surface->inputRegionContains(event->pos()) && event->source() != Qt::MouseEventSynthesizedByQt) { QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice(); if (inputDevice->mouseFocus() != this) { inputDevice->setMouseFocus(this, event->pos(), event->globalPos()); if (m_focusOnTouch && inputDevice->keyboardFocus() != m_surface) { takeFocus(); } } inputDevice->sendMousePressEvent(event->button(), event->pos(), event->globalPos()); } else { event->ignore(); } }
void CompositorSettingsPrivate::_q_setupKeymap() { if (!compositor || !keymap || !initialized) return; QWaylandInputDevice *inputDevice = compositor->defaultInputDevice(); if (inputDevice && inputDevice->keyboard()) { qCDebug(gLcCore, "Setting keymap to '%s' (variant '%s', options '%s', model '%s', rules '%s')", qPrintable(keymap->layout()), qPrintable(keymap->variant()), qPrintable(keymap->options()), qPrintable(keymap->model()), qPrintable(keymap->rules())); QWaylandKeymap wlKeymap(keymap->layout(), keymap->variant(), keymap->options(), keymap->model(), keymap->rules()); inputDevice->keyboard()->setKeymap(wlKeymap); inputDevice->keyboard()->setRepeatRate(repeatRate); inputDevice->keyboard()->setRepeatDelay(repeatDelay); } }
bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event) { if (obj != m_window) return false; QWaylandInputDevice *input = defaultInputDevice(); 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; QMouseEvent *me = static_cast<QMouseEvent *>(event); QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local); if (m_dragKeyIsPressed && targetSurface) { m_draggingWindow = targetSurface; m_drag_diff = local; } else { if (targetSurface && input->keyboardFocus() != targetSurface) { input->setKeyboardFocus(targetSurface); m_surfaces.removeOne(targetSurface); m_surfaces.append(targetSurface); m_renderScheduler.start(0); } input->sendMousePressEvent(me->button(), local, me->localPos()); } return true; } case QEvent::MouseButtonRelease: { QWaylandSurface *targetSurface = input->mouseFocus(); if (m_draggingWindow) { m_draggingWindow = 0; m_drag_diff = QPointF(); } else { QMouseEvent *me = static_cast<QMouseEvent *>(event); QPointF localPos; if (targetSurface) localPos = toSurface(targetSurface, me->localPos()); input->sendMouseReleaseEvent(me->button(), localPos, me->localPos()); } return true; } case QEvent::MouseMove: { QMouseEvent *me = static_cast<QMouseEvent *>(event); if (m_draggingWindow) { m_draggingWindow->setPos(me->localPos() - m_drag_diff); m_renderScheduler.start(0); } else { QPointF local; QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local); input->sendMouseMoveEvent(targetSurface, local, me->localPos()); } 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(); QWaylandSurface *targetSurface = input->keyboardFocus(); if (targetSurface) input->sendKeyPressEvent(ke->nativeScanCode()); break; } case QEvent::KeyRelease: { QKeyEvent *ke = static_cast<QKeyEvent *>(event); if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) { m_dragKeyIsPressed = false; } m_modifiers = ke->modifiers(); QWaylandSurface *targetSurface = input->keyboardFocus(); if (targetSurface) input->sendKeyReleaseEvent(ke->nativeScanCode()); break; } case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { QWaylandSurface *targetSurface = 0; QTouchEvent *te = static_cast<QTouchEvent *>(event); QList<QTouchEvent::TouchPoint> points = te->touchPoints(); QPoint pointPos; if (!points.isEmpty()) { pointPos = points.at(0).pos().toPoint(); targetSurface = surfaceAt(pointPos); } if (targetSurface && targetSurface != input->mouseFocus()) input->setMouseFocus(targetSurface, pointPos, pointPos); if (input->mouseFocus()) input->sendFullTouchEvent(te); break; } default: break; } return false; }
bool QtWaylandMotorcarCompositor::eventFilter(QObject *obj, QEvent *event) { if (obj != m_glData->m_window) return false; QWaylandInputDevice *input = defaultInputDevice(); switch (event->type()) { case QEvent::Expose: m_renderScheduler.start(0); if (m_glData->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; // QMouseEvent *me = static_cast<QMouseEvent *>(event); // QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local); // if (m_dragKeyIsPressed && targetSurface) { // m_draggingWindow = targetSurface; // m_drag_diff = local; // } else { // if (targetSurface && input->keyboardFocus() != targetSurface) { // input->setKeyboardFocus(targetSurface); // // m_surfaces.removeOne(targetSurface); // // m_surfaces.append(targetSurface); // //m_renderScheduler.start(0); // } // input->sendMousePressEvent(me->button(), local, me->localPos()); // } // return true; // } // case QEvent::MouseButtonRelease: { // QWaylandSurface *targetSurface = input->mouseFocus(); // if (m_draggingWindow) { // m_draggingWindow = 0; // m_drag_diff = QPointF(); // } else { // QMouseEvent *me = static_cast<QMouseEvent *>(event); // QPointF localPos; // if (targetSurface) // localPos = toSurface(targetSurface, me->localPos()); // input->sendMouseReleaseEvent(me->button(), localPos, me->localPos()); // } // return true; // } // case QEvent::MouseMove: { // QMouseEvent *me = static_cast<QMouseEvent *>(event); // if (m_draggingWindow) { // m_draggingWindow->setPos(me->localPos() - m_drag_diff); // //m_renderScheduler.start(0); // } else { // QPointF local; // QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local); // input->sendMouseMoveEvent(targetSurface, local, me->localPos()); // } // 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; // }/*else if(ke->key() == Qt::Key_Up){ // m_glData->m_cameraNode->setTransform(glm::translate(glm::mat4(1), glm::vec3(0,0,0.001f)) * m_glData->m_cameraNode->transform()); // }else if(ke->key() == Qt::Key_Down){ // m_glData->m_cameraNode->setTransform(glm::translate(glm::mat4(1), glm::vec3(0,0,-0.001f)) * m_glData->m_cameraNode->transform()); // }*/ // m_modifiers = ke->modifiers(); // QWaylandSurface *targetSurface = input->keyboardFocus(); // if (targetSurface) // input->sendKeyPressEvent(ke->nativeScanCode()); this->scene()->windowManager()->sendEvent(motorcar::KeyboardEvent(motorcar::KeyboardEvent::Event::KEY_PRESS, ke->nativeScanCode(), defaultSeat())); break; } case QEvent::KeyRelease: { QKeyEvent *ke = static_cast<QKeyEvent *>(event); // if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) { // m_dragKeyIsPressed = false; // } // m_modifiers = ke->modifiers(); // QWaylandSurface *targetSurface = input->keyboardFocus(); // if (targetSurface) // input->sendKeyReleaseEvent(ke->nativeScanCode()); this->scene()->windowManager()->sendEvent(motorcar::KeyboardEvent(motorcar::KeyboardEvent::Event::KEY_RELEASE, ke->nativeScanCode(), defaultSeat())); break; } // case QEvent::TouchBegin: // case QEvent::TouchUpdate: // case QEvent::TouchEnd: // { // QWaylandSurface *targetSurface = 0; // QTouchEvent *te = static_cast<QTouchEvent *>(event); // QList<QTouchEvent::TouchPoint> points = te->touchPoints(); // QPoint pointPos; // if (!points.isEmpty()) { // pointPos = points.at(0).pos().toPoint(); // targetSurface = surfaceAt(pointPos); // } // if (targetSurface && targetSurface != input->mouseFocus()) // input->setMouseFocus(targetSurface, pointPos, pointPos); // if (input->mouseFocus()) // input->sendFullTouchEvent(te); // break; // } default: break; } return false; }