bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, Qt::TouchPointState state, Qt::KeyboardModifiers mods) { Q_UNUSED(inputDevice); Q_UNUSED(global); Q_UNUSED(mods); bool handled = state == Qt::TouchPointPressed; if (handled) { if (closeButtonRect().contains(local)) QWindowSystemInterface::handleCloseEvent(window()); else if (maximizeButtonRect().contains(local)) window()->setWindowState(waylandWindow()->isMaximized() ? Qt::WindowNoState : Qt::WindowMaximized); else if (minimizeButtonRect().contains(local)) window()->setWindowState(Qt::WindowMinimized); else if (local.y() <= margins().top()) waylandWindow()->shellSurface()->move(inputDevice); else handled = false; } return handled; }
bool QWaylandMaterialDecoration::handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { Q_UNUSED(global); // Figure out what area mouse is in if (closeButtonRect().contains(local)) { if (clickButton(b, Close)) QWindowSystemInterface::handleCloseEvent(window()); } else if (maximizeButtonRect().contains(local)) { if (clickButton(b, Maximize)) window()->setWindowState(waylandWindow()->isMaximized() ? Qt::WindowNoState : Qt::WindowMaximized); } else if (minimizeButtonRect().contains(local)) { if (clickButton(b, Minimize)) window()->setWindowState(Qt::WindowMinimized); } else if (local.y() <= margins().top()) { processMouseTop(inputDevice, local, b, mods); } else if (local.y() > window()->height() - margins().bottom() + margins().top()) { processMouseBottom(inputDevice, local, b, mods); } else if (local.x() <= margins().left()) { processMouseLeft(inputDevice, local, b, mods); } else if (local.x() > window()->width() - margins().right() + margins().left()) { processMouseRight(inputDevice, local, b, mods); } else { waylandWindow()->restoreMouseCursor(inputDevice); setMouseButtons(b); return false; } setMouseButtons(b); return true; }
void QWaylandShmBackingStore::beginPaint(const QRegion &) { mPainting = true; ensureSize(); if (waylandWindow()->attached() && mBackBuffer == waylandWindow()->attached() && mFrameCallback) { QWaylandShmWindow *waylandWindow = static_cast<QWaylandShmWindow *>(window()->handle()); Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); waylandWindow->waitForFrameSync(); } }
void QWaylandMaterialDecoration::processMouseRight(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { Q_UNUSED(local); Q_UNUSED(mods); waylandWindow()->setMouseCursor(inputDevice, Qt::SplitHCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_RIGHT, b); }
void QWaylandMaterialDecoration::processMouseBottom(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { Q_UNUSED(mods); if (local.x() <= margins().left()) { // bottom left bit waylandWindow()->setMouseCursor(inputDevice, Qt::SizeBDiagCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, b); } else if (local.x() > window()->width() - margins().right()) { // bottom right bit waylandWindow()->setMouseCursor(inputDevice, Qt::SizeFDiagCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, b); } else { // bottom bit waylandWindow()->setMouseCursor(inputDevice, Qt::SplitVCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_BOTTOM, b); } }
void QWaylandMaterialDecoration::processMouseTop(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { Q_UNUSED(mods); if (local.y() <= margins().bottom()) { if (local.x() <= margins().left()) { // top left bit waylandWindow()->setMouseCursor(inputDevice, Qt::SizeFDiagCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_TOP_LEFT, b); } else if (local.x() > window()->width() - margins().right()) { // top right bit waylandWindow()->setMouseCursor(inputDevice, Qt::SizeBDiagCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, b); } else { // top reszie bit waylandWindow()->setMouseCursor(inputDevice, Qt::SplitVCursor); startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_TOP, b); } } else { waylandWindow()->restoreMouseCursor(inputDevice); startMove(inputDevice, b); } }
void QWaylandShmBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) { Q_UNUSED(window); Q_UNUSED(offset); Q_ASSERT(waylandWindow()->windowType() == QWaylandWindow::Shm); if (windowDecoration() && windowDecoration()->isDirty()) updateDecorations(); mFrontBuffer = mBackBuffer; if (mFrameCallback) { mFrontBufferIsDirty = true; return; } mFrameCallback = waylandWindow()->frame(); wl_callback_add_listener(mFrameCallback,&frameCallbackListener,this); QMargins margins = windowDecorationMargins(); bool damageAll = false; if (waylandWindow()->attached() != mFrontBuffer) { delete waylandWindow()->attached(); damageAll = true; } waylandWindow()->attachOffset(mFrontBuffer); if (damageAll) { //need to damage it all, otherwise the attach offset may screw up waylandWindow()->damage(QRect(QPoint(0,0),mFrontBuffer->size())); } else { QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); i++) { QRect rect = rects.at(i); rect.translate(margins.left(),margins.top()); waylandWindow()->damage(rect); } } mFrontBufferIsDirty = false; waylandWindow()->doResize(); }
void QWaylandShmBackingStore::ensureSize() { waylandWindow()->setBackingStore(this); waylandWindow()->createDecoration(); resize(mRequestedSize); }
void QWaylandMaterialDecoration::paint(QPaintDevice *device) { const QRect frameGeometry = window()->frameGeometry(); QRect top(QPoint(WINDOW_BORDER, WINDOW_BORDER), QSize(frameGeometry.width(), margins().top())); QPainter p(device); p.setRenderHint(QPainter::Antialiasing); // Title bar int radius = waylandWindow()->isMaximized() ? 0 : dp(3); QPainterPath roundedRect; roundedRect.addRoundedRect(0, 0, frameGeometry.width(), margins().top() * 1.5, radius, radius); p.fillPath(roundedRect.simplified(), m_backgroundColor); // Borders QPainterPath borderPath; borderPath.addRect(0, margins().top(), margins().left(), frameGeometry.height() - margins().top()); borderPath.addRect(0, frameGeometry.height() - margins().bottom(), frameGeometry.width(), margins().bottom()); borderPath.addRect(frameGeometry.width() - margins().right(), margins().top(), margins().right(), frameGeometry.height() - margins().bottom()); p.fillPath(borderPath, m_backgroundColor); // Window title QString windowTitleText = window()->title(); if (!windowTitleText.isEmpty()) { if (m_windowTitle.text() != windowTitleText) { m_windowTitle.setText(windowTitleText); m_windowTitle.prepare(); } QRect titleBar = top; titleBar.setLeft(margins().left() + BUTTON_SPACING); titleBar.setRight(minimizeButtonRect().left() - BUTTON_SPACING); p.save(); p.setClipRect(titleBar); p.setPen(m_textColor); QSizeF size = m_windowTitle.size(); int dx = (top.width() - size.width()) / 2; int dy = (top.height() - size.height()) / 2; QFont font = p.font(); font.setBold(true); font.setFamily("Roboto"); p.setFont(font); QPoint windowTitlePoint(top.topLeft().x() + dx, top.topLeft().y() + dy); p.drawStaticText(windowTitlePoint, m_windowTitle); p.restore(); } p.save(); p.setPen(m_iconColor); // Close button QBitmap closeIcon = buttonIcon("window-close"); p.drawPixmap(closeButtonRect(), closeIcon, closeIcon.rect()); // Maximize button if (window()->flags() & Qt::WindowMaximizeButtonHint) { QBitmap maximizeIcon = buttonIcon(waylandWindow()->isMaximized() ? "window-restore" : "window-maximize"); p.drawPixmap(maximizeButtonRect(), maximizeIcon, maximizeIcon.rect()); } // Minimize button if (window()->flags() & Qt::WindowMinimizeButtonHint) { QBitmap minimizeIcon = buttonIcon("window-minimize"); p.drawPixmap(minimizeButtonRect(), minimizeIcon, minimizeIcon.rect()); } p.restore(); }
void QWaylandMaterialDecoration::paint(QPaintDevice *device) { QRect surfaceRect(QPoint(), window()->frameGeometry().size()); QRect top(QPoint(), QSize(window()->frameGeometry().width(), margins().top())); QPainter p(device); p.setRenderHint(QPainter::Antialiasing); // Title bar int radius = waylandWindow()->isMaximized() ? 0 : dp(3); QPainterPath roundedRect; roundedRect.addRoundedRect(0, 0, window()->frameGeometry().width(), margins().top() * 1.5, radius, radius); p.fillPath(roundedRect.simplified(), m_backgroundColor); // Window icon QIcon icon = waylandWindow()->windowIcon(); if (!icon.isNull()) { QPixmap pixmap = icon.pixmap(QSize(128, 128)); QPixmap scaled = pixmap.scaled(22, 22, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QRectF iconRect(0, 0, 22, 22); p.drawPixmap(iconRect.adjusted(margins().left() + BUTTON_SPACING, 4, margins().left() + BUTTON_SPACING, 4), scaled, iconRect); } // Window title QString windowTitleText = window()->title(); if (!windowTitleText.isEmpty()) { if (m_windowTitle.text() != windowTitleText) { m_windowTitle.setText(windowTitleText); m_windowTitle.prepare(); } QRect titleBar = top; titleBar.setLeft(margins().left() + BUTTON_SPACING + (icon.isNull() ? 0 : 22 + BUTTON_SPACING)); titleBar.setRight(minimizeButtonRect().left() - BUTTON_SPACING); p.save(); p.setClipRect(titleBar); p.setPen(m_textColor); QSizeF size = m_windowTitle.size(); int dx = (top.width() - size.width()) / 2; int dy = (top.height() - size.height()) / 2; QFont font = p.font(); font.setBold(true); font.setFamily("Roboto"); p.setFont(font); QPoint windowTitlePoint(top.topLeft().x() + dx, top.topLeft().y() + dy); p.drawStaticText(windowTitlePoint, m_windowTitle); p.restore(); } p.save(); p.setPen(m_iconColor); // Close button QBitmap closeIcon = buttonIcon("window-close"); p.drawPixmap(closeButtonRect(), closeIcon, closeIcon.rect()); // Maximize button QBitmap maximizeIcon = buttonIcon(waylandWindow()->isMaximized() ? "window-restore" : "window-maximize"); p.drawPixmap(maximizeButtonRect(), maximizeIcon, maximizeIcon.rect()); // Minimize button QBitmap minimizeIcon = buttonIcon("window-minimize"); p.drawPixmap(minimizeButtonRect(), minimizeIcon, minimizeIcon.rect()); p.restore(); }
void QWaylandShmBackingStore::endPaint() { mPainting = false; waylandWindow()->setCanResize(true); }