diff options
author | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-09-14 12:35:52 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-09-14 12:17:05 +0000 |
commit | f5f06c709937b657c66ca4e35f4e3065ba390153 (patch) | |
tree | 1019883bf566cc7de6d86b9cd2ab4f43b342b26c /src/compositor/extensions/qwaylandshell.cpp | |
parent | 2deffa537c82e2f21e01dff5c8f5ba283dd06032 (diff) |
Remove global coordinates
This involves removing:
- pickView and mapView from QWaylandOutput
- requestedPos[X,Y] from QWaylandView
Change-Id: Ie53eef434ac6ae7d0d5474f649f78a59ae857167
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'src/compositor/extensions/qwaylandshell.cpp')
-rw-r--r-- | src/compositor/extensions/qwaylandshell.cpp | 379 |
1 files changed, 36 insertions, 343 deletions
diff --git a/src/compositor/extensions/qwaylandshell.cpp b/src/compositor/extensions/qwaylandshell.cpp index 25e5e4ec8..cb8ccf778 100644 --- a/src/compositor/extensions/qwaylandshell.cpp +++ b/src/compositor/extensions/qwaylandshell.cpp @@ -55,14 +55,6 @@ QWaylandShellPrivate::QWaylandShellPrivate() { } -QWaylandShellSurfacePopupGrabber *QWaylandShellPrivate::getPopupGrabber(QWaylandInputDevice *input) -{ - if (!m_popupGrabber.contains(input)) - m_popupGrabber.insert(input, new QWaylandShellSurfacePopupGrabber(input)); - - return m_popupGrabber.value(input); -} - void QWaylandShellPrivate::shell_get_shell_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface_res) { Q_Q(QWaylandShell); @@ -76,24 +68,12 @@ QWaylandShellSurfacePrivate::QWaylandShellSurfacePrivate() , wl_shell_surface() , m_shell(Q_NULLPTR) , m_surface(Q_NULLPTR) - , m_view(0) - , m_resizeGrabber(0) - , m_moveGrabber(0) - , m_popupGrabber(0) - , m_popupSerial() - , m_surfaceType(QWaylandShellSurface::None) - , m_transientInactive(false) - , m_transientParent(0) - , m_transientOffset() + , m_focusPolicy(QWaylandShellSurface::DefaultFocus) { } QWaylandShellSurfacePrivate::~QWaylandShellSurfacePrivate() { - QPointer<QObject> view(m_view); - if (m_view->renderObject()) - delete m_view->renderObject(); - delete view.data(); } void QWaylandShellSurfacePrivate::ping() @@ -108,89 +88,44 @@ void QWaylandShellSurfacePrivate::ping(uint32_t serial) send_ping(serial); } -void QWaylandShellSurfacePrivate::setSurfaceType(QWaylandShellSurface::SurfaceType type) -{ - Q_Q(QWaylandShellSurface); - if (m_surfaceType == type) - return; - - m_surfaceType = type; - emit q->surfaceTypeChanged(); -} - -void QWaylandShellSurfacePrivate::resetResizeGrabber() -{ - m_resizeGrabber = 0; -} - -void QWaylandShellSurfacePrivate::resetMoveGrabber() -{ - m_moveGrabber = 0; -} - void QWaylandShellSurfacePrivate::shell_surface_destroy_resource(Resource *) { Q_Q(QWaylandShellSurface); - if (m_popupGrabber) - m_popupGrabber->removePopup(q); delete q; } void QWaylandShellSurfacePrivate::shell_surface_move(Resource *resource, struct wl_resource *input_device_super, - uint32_t time) + uint32_t serial) { Q_UNUSED(resource); - Q_UNUSED(time); + Q_UNUSED(serial); Q_Q(QWaylandShellSurface); - if (!m_view) - return; - if (m_resizeGrabber || m_moveGrabber) { - return; - } - QWaylandInputDevice *input_device = QWaylandInputDevice::fromSeatResource(input_device_super); - QWaylandPointer *pointer = input_device->pointer(); - - m_moveGrabber = new QWaylandShellSurfaceMoveGrabber(q, pointer->currentSpacePosition() - m_view->requestedPosition()); - - pointer->startGrab(m_moveGrabber); + emit q->startMove(input_device); } void QWaylandShellSurfacePrivate::shell_surface_resize(Resource *resource, struct wl_resource *input_device_super, - uint32_t time, + uint32_t serial, uint32_t edges) { Q_UNUSED(resource); - Q_UNUSED(time); + Q_UNUSED(serial); Q_Q(QWaylandShellSurface); - if (m_moveGrabber || m_resizeGrabber) { - return; - } - - m_resizeGrabber = new QWaylandShellSurfaceResizeGrabber(q); - QWaylandInputDevice *input_device = QWaylandInputDevice::fromSeatResource(input_device_super); - QWaylandPointer *pointer = input_device->pointer(); - - m_resizeGrabber->point = pointer->currentSpacePosition(); - m_resizeGrabber->resize_edges = static_cast<wl_shell_surface_resize>(edges); - m_resizeGrabber->width = m_surface->size().width(); - m_resizeGrabber->height = m_surface->size().height(); - - pointer->startGrab(m_resizeGrabber); + emit q->startResize(input_device, QWaylandShellSurface::ResizeEdge(edges)); } void QWaylandShellSurfacePrivate::shell_surface_set_toplevel(Resource *resource) { Q_UNUSED(resource); - m_transientParent = 0; - m_transientOffset = QPointF(); - setSurfaceType(QWaylandShellSurface::Toplevel); + Q_Q(QWaylandShellSurface); + setFocusPolicy(QWaylandShellSurface::DefaultFocus); + emit q->setDefaultToplevel(); } void QWaylandShellSurfacePrivate::shell_surface_set_transient(Resource *resource, @@ -201,16 +136,13 @@ void QWaylandShellSurfacePrivate::shell_surface_set_transient(Resource *resource { Q_UNUSED(resource); - Q_UNUSED(flags); + Q_Q(QWaylandShellSurface); QWaylandSurface *parent_surface = QWaylandSurface::fromResource(parent_surface_resource); - m_transientParent = parent_surface; - m_transientOffset= QPointF(x, y); - if (flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE) - m_transientInactive = true; - else - m_transientInactive = false; - - setSurfaceType(QWaylandShellSurface::Transient); + QWaylandShellSurface::FocusPolicy focusPolicy = + flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE ? QWaylandShellSurface::NoKeyboardFocus + : QWaylandShellSurface::DefaultFocus; + setFocusPolicy(focusPolicy); + emit q->setTransient(parent_surface, QPoint(x,y), focusPolicy); } void QWaylandShellSurfacePrivate::shell_surface_set_fullscreen(Resource *resource, @@ -221,45 +153,24 @@ void QWaylandShellSurfacePrivate::shell_surface_set_fullscreen(Resource *resourc Q_UNUSED(resource); Q_UNUSED(method); Q_UNUSED(framerate); + Q_Q(QWaylandShellSurface); + setFocusPolicy(QWaylandShellSurface::DefaultFocus); QWaylandOutput *output = output_resource ? QWaylandOutput::fromResource(output_resource) : Q_NULLPTR; - if (!output) { - // Look for an output that can contain this surface - Q_FOREACH (QWaylandOutput *curOutput, m_surface->compositor()->defaultOutputSpace()->outputs()) { - if (curOutput->geometry().size().width() >= m_surface->size().width() && - curOutput->geometry().size().height() >= m_surface->size().height()) { - output = curOutput; - break; - } - } - } - if (!output) { - qWarning() << "Unable to resize surface full screen, cannot determine output"; - return; - } - QSize outputSize = output->geometry().size(); - - if (m_view) - m_view->setRequestedPosition(output->geometry().topLeft()); - send_configure(resize_bottom_right, outputSize.width(), outputSize.height()); - + emit q->setFullScreen(QWaylandShellSurface::FullScreenMethod(method), framerate, output); } void QWaylandShellSurfacePrivate::shell_surface_set_popup(Resource *resource, wl_resource *input_device, uint32_t serial, wl_resource *parent, int32_t x, int32_t y, uint32_t flags) { Q_UNUSED(resource); - Q_UNUSED(input_device); + Q_UNUSED(serial); Q_UNUSED(flags); - + Q_Q(QWaylandShellSurface); + setFocusPolicy(QWaylandShellSurface::DefaultFocus); QWaylandInputDevice *input = QWaylandInputDevice::fromSeatResource(input_device); - m_popupGrabber = QWaylandShellPrivate::get(m_shell)->getPopupGrabber(input); - - m_popupSerial = serial; - m_transientParent = QWaylandSurface::fromResource(parent); - m_transientOffset = m_transientParent ? QPointF(x,y) : QPointF(); - - setSurfaceType(QWaylandShellSurface::Popup); + QWaylandSurface *parentSurface = QWaylandSurface::fromResource(parent); + emit q->setPopup(input, parentSurface, QPoint(x,y)); } @@ -267,30 +178,12 @@ void QWaylandShellSurfacePrivate::shell_surface_set_maximized(Resource *resource struct wl_resource *output_resource) { Q_UNUSED(resource); - + Q_Q(QWaylandShellSurface); + setFocusPolicy(QWaylandShellSurface::DefaultFocus); QWaylandOutput *output = output_resource ? QWaylandOutput::fromResource(output_resource) : Q_NULLPTR; - if (!output) { - // Look for an output that can contain this surface - Q_FOREACH (QWaylandOutput *curOutput, m_surface->compositor()->defaultOutputSpace()->outputs()) { - if (curOutput->geometry().size().width() >= m_surface->size().width() && - curOutput->geometry().size().height() >= m_surface->size().height()) { - output = curOutput; - break; - } - } - } - if (!output) { - qWarning() << "Unable to maximize surface, cannot determine output"; - return; - } - QSize outputSize = output->availableGeometry().size(); - - if (m_view) - m_view->setRequestedPosition(output->availableGeometry().topLeft()); - send_configure(resize_bottom_right, outputSize.width(), outputSize.height()); - + emit q->setMaximized(output); } void QWaylandShellSurfacePrivate::shell_surface_pong(Resource *resource, @@ -308,6 +201,8 @@ void QWaylandShellSurfacePrivate::shell_surface_set_title(Resource *resource, const QString &title) { Q_UNUSED(resource); + if (title == m_title) + return; Q_Q(QWaylandShellSurface); m_title = title; emit q->titleChanged(); @@ -317,151 +212,13 @@ void QWaylandShellSurfacePrivate::shell_surface_set_class(Resource *resource, const QString &className) { Q_UNUSED(resource); + if (className == m_className) + return; Q_Q(QWaylandShellSurface); m_className = className; emit q->classNameChanged(); } -QWaylandShellSurfaceGrabber::QWaylandShellSurfaceGrabber(QWaylandShellSurface *shellSurface) - : QWaylandPointerGrabber() - , shell_surface(shellSurface) -{ -} - -QWaylandShellSurfaceGrabber::~QWaylandShellSurfaceGrabber() -{ -} - -QWaylandShellSurfaceResizeGrabber::QWaylandShellSurfaceResizeGrabber(QWaylandShellSurface *shellSurface) - : QWaylandShellSurfaceGrabber(shellSurface) -{ -} - -void QWaylandShellSurfaceResizeGrabber::focus() -{ -} - -void QWaylandShellSurfaceResizeGrabber::motion(uint32_t time) -{ - Q_UNUSED(time); - - int width_delta = point.x() - pointer->currentSpacePosition().x(); - int height_delta = point.y() - pointer->currentSpacePosition().y(); - - int new_height = height; - if (resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) - new_height = qMax(new_height + height_delta, 1); - else if (resize_edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) - new_height = qMax(new_height - height_delta, 1); - - int new_width = width; - if (resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) - new_width = qMax(new_width + width_delta, 1); - else if (resize_edges & WL_SHELL_SURFACE_RESIZE_RIGHT) - new_width = qMax(new_width - width_delta, 1); - - QWaylandShellSurfacePrivate::get(shell_surface)->send_configure(resize_edges, new_width, new_height); -} - -void QWaylandShellSurfaceResizeGrabber::button(uint32_t time, Qt::MouseButton button, uint32_t state) -{ - Q_UNUSED(time) - - if (button == Qt::LeftButton && !state) { - pointer->endGrab(); - QWaylandShellSurfacePrivate::get(shell_surface)->resetResizeGrabber(); - delete this; - } -} - -QWaylandShellSurfaceMoveGrabber::QWaylandShellSurfaceMoveGrabber(QWaylandShellSurface *shellSurface, const QPointF &offset) - : QWaylandShellSurfaceGrabber(shellSurface) - , m_offset(offset) -{ -} - -void QWaylandShellSurfaceMoveGrabber::focus() -{ -} - -void QWaylandShellSurfaceMoveGrabber::motion(uint32_t time) -{ - Q_UNUSED(time); - - QPointF pos(pointer->currentSpacePosition() - m_offset); - if (shell_surface->view()) - shell_surface->view()->setRequestedPosition(pos); - if (shell_surface->transientParent()) { - QWaylandView *view = shell_surface->transientParent()->views().first(); - if (view) - QWaylandShellSurfacePrivate::get(shell_surface)->setOffset(pos - view->requestedPosition()); - } - -} - -void QWaylandShellSurfaceMoveGrabber::button(uint32_t time, Qt::MouseButton button, uint32_t state) -{ - Q_UNUSED(time) - - if (button == Qt::LeftButton && !state) { - pointer->endGrab(); - QWaylandShellSurfacePrivate::get(shell_surface)->resetMoveGrabber(); - delete this; - } -} - -QWaylandShellSurfacePopupGrabber::QWaylandShellSurfacePopupGrabber(QWaylandInputDevice *inputDevice) - : QWaylandDefaultPointerGrabber() - , m_inputDevice(inputDevice) - , m_client(0) - , m_surfaces() - , m_initialUp(false) -{ -} - -void QWaylandShellSurfacePopupGrabber::addPopup(QWaylandShellSurface *surface) -{ - if (m_surfaces.isEmpty()) { - m_client = surface->surface()->client()->client(); - - if (m_inputDevice->pointer()->isButtonPressed()) - m_initialUp = false; - - m_surfaces.append(surface); - m_inputDevice->pointer()->startGrab(this); - } else { - m_surfaces.append(surface); - } -} - -void QWaylandShellSurfacePopupGrabber::removePopup(QWaylandShellSurface *surface) -{ - if (m_surfaces.isEmpty()) - return; - - m_surfaces.removeOne(surface); - if (m_surfaces.isEmpty()) - m_inputDevice->pointer()->endGrab(); -} - -void QWaylandShellSurfacePopupGrabber::button(uint32_t time, Qt::MouseButton button, uint32_t state) -{ - if (pointer->focusResource()) { - pointer->sendButton(pointer->focusResource(), time, button, state); - } else if (state == QtWaylandServer::wl_pointer::button_state_pressed && - (m_initialUp || time - pointer->grabTime() > 500) && - pointer->currentGrab() == this) { - pointer->endGrab(); - Q_FOREACH (QWaylandShellSurface *surface, m_surfaces) { - QWaylandShellSurfacePrivate::get(surface)->send_popup_done(); - } - m_surfaces.clear(); - } - - if (state == QtWaylandServer::wl_pointer::button_state_released) - m_initialUp = true; -} - QWaylandShell::QWaylandShell() : QWaylandExtensionTemplate<QWaylandShell>(*new QWaylandShellPrivate()) { } @@ -497,21 +254,18 @@ QWaylandShellSurface::QWaylandShellSurface() { } -QWaylandShellSurface::QWaylandShellSurface(QWaylandShell *shell, QWaylandSurface *surface, QWaylandView *view, QWaylandClient *client, uint id) +QWaylandShellSurface::QWaylandShellSurface(QWaylandShell *shell, QWaylandSurface *surface, QWaylandClient *client, uint id) : QWaylandExtensionTemplate<QWaylandShellSurface>(*new QWaylandShellSurfacePrivate) { - initialize(shell, surface, view, client, id); + initialize(shell, surface, client, id); } -void QWaylandShellSurface::initialize(QWaylandShell *shell, QWaylandSurface *surface, QWaylandView *view, QWaylandClient *client, uint id) +void QWaylandShellSurface::initialize(QWaylandShell *shell, QWaylandSurface *surface, QWaylandClient *client, uint id) { Q_D(QWaylandShellSurface); d->m_shell = shell; d->m_surface = surface; - d->m_view = view; d->init(client->client(), id, 1); - connect(surface, &QWaylandSurface::mappedChanged, this, &QWaylandShellSurface::mappedChanged); - connect(surface, &QWaylandSurface::offsetForNextFrame, this, &QWaylandShellSurface::adjustOffset); setExtensionContainer(surface); QWaylandExtension::initialize(); } @@ -530,50 +284,16 @@ QByteArray QWaylandShellSurface::interfaceName() return QWaylandShellSurfacePrivate::interfaceName(); } -QWaylandShellSurface::SurfaceType QWaylandShellSurface::surfaceType() const -{ - Q_D(const QWaylandShellSurface); - return d->m_surfaceType; -} - -QWaylandView *QWaylandShellSurface::view() const -{ - Q_D(const QWaylandShellSurface); - - return d->m_view; -} - -void QWaylandShellSurface::setView(QWaylandView *view) -{ - Q_D(QWaylandShellSurface); - if (d->m_view == view) - return; - d->m_view = view; - emit viewChanged(); -} - QWaylandSurface *QWaylandShellSurface::surface() const { Q_D(const QWaylandShellSurface); return d->m_surface; } -QWaylandSurface *QWaylandShellSurface::transientParent() const -{ - Q_D(const QWaylandShellSurface); - return d->m_transientParent; -} - -QPointF QWaylandShellSurface::transientOffset() const -{ - Q_D(const QWaylandShellSurface); - return d->m_transientOffset; -} - -bool QWaylandShellSurface::isTransientInactive() const +QWaylandShellSurface::FocusPolicy QWaylandShellSurface::focusPolicy() const { Q_D(const QWaylandShellSurface); - return d->m_transientInactive; + return d->m_focusPolicy; } QString QWaylandShellSurface::title() const @@ -588,31 +308,4 @@ QString QWaylandShellSurface::className() const return d->m_className; } -void QWaylandShellSurface::mappedChanged() -{ - Q_D(QWaylandShellSurface); - if (!d->m_surface->isMapped()) - return; - - if (d->m_surfaceType == Popup) { - if (d->m_surface->isMapped() && d->m_popupGrabber->grabSerial() == d->m_popupSerial) { - d->m_popupGrabber->addPopup(this); - } else { - d->send_popup_done(); - d->m_popupGrabber->setClient(0); - } - } -} - -void QWaylandShellSurface::adjustOffset(const QPoint &p) -{ - Q_D(QWaylandShellSurface); - if (!d->m_view) - return; - - QPointF offset(p); - QPointF pos = d->m_view->requestedPosition(); - d->m_view->setRequestedPosition(pos + offset); -} - QT_END_NAMESPACE |