summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-10-06 15:52:22 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-10-23 13:33:10 +0000
commit36e62983bfe53a6e1f79bf6acaa052bc58a5af63 (patch)
tree734ea930ef035a197b8d8bf792a5fedd04aa9515
parent81627842fe961e3b6a3cef29dac9c98c8f2e30c9 (diff)
Add support for popups to example
Change-Id: If2446073b69c91377f399cfd43506e6a211ac209 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
-rw-r--r--examples/wayland/qwindow-compositor/compositorwindow.cpp5
-rw-r--r--examples/wayland/qwindow-compositor/windowcompositor.cpp48
-rw-r--r--examples/wayland/qwindow-compositor/windowcompositor.h8
3 files changed, 57 insertions, 4 deletions
diff --git a/examples/wayland/qwindow-compositor/compositorwindow.cpp b/examples/wayland/qwindow-compositor/compositorwindow.cpp
index 2ba0dfa96..50fd587a0 100644
--- a/examples/wayland/qwindow-compositor/compositorwindow.cpp
+++ b/examples/wayland/qwindow-compositor/compositorwindow.cpp
@@ -168,9 +168,10 @@ void CompositorWindow::mousePressEvent(QMouseEvent *e)
return;
if (m_mouseView.isNull()) {
m_mouseView = viewAt(e->localPos());
- if (!m_mouseView)
+ if (!m_mouseView) {
+ m_compositor->closePopups();
return;
-
+ }
if (e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::MetaModifier)
m_grabState = MoveGrab; //start move
else
diff --git a/examples/wayland/qwindow-compositor/windowcompositor.cpp b/examples/wayland/qwindow-compositor/windowcompositor.cpp
index 25470f8b8..a359fc6b3 100644
--- a/examples/wayland/qwindow-compositor/windowcompositor.cpp
+++ b/examples/wayland/qwindow-compositor/windowcompositor.cpp
@@ -109,6 +109,13 @@ void WindowCompositor::surfaceMappedChanged()
if (surface->isMapped()) {
if (!surface->isCursorSurface())
defaultInputDevice()->setKeyboardFocus(surface);
+ } else if (popupActive()) {
+ for (int i = 0; i < m_popupViews.count(); i++) {
+ if (m_popupViews.at(i)->surface() == surface) {
+ m_popupViews.removeAt(i);
+ break;
+ }
+ }
}
triggerRender();
}
@@ -144,18 +151,46 @@ void WindowCompositor::onCreateShellSurface(QWaylandSurface *s, QWaylandClient *
QWaylandSurface *surface = s;
QWaylandShellSurface *shellSurface = new QWaylandShellSurface(m_shell, surface, client, id);
- connect(shellSurface, &QWaylandShellSurface::startMove, this, &WindowCompositor::startMove);
+ connect(shellSurface, &QWaylandShellSurface::startMove, this, &WindowCompositor::onStartMove);
connect(shellSurface, &QWaylandShellSurface::startResize, this, &WindowCompositor::onStartResize);
+ connect(shellSurface, &QWaylandShellSurface::setTransient, this, &WindowCompositor::onSetTransient);
+ connect(shellSurface, &QWaylandShellSurface::setPopup, this, &WindowCompositor::onSetPopup);
WindowCompositorView *view = findView(s);
Q_ASSERT(view);
view->m_shellSurface = shellSurface;
}
+void WindowCompositor::onStartMove()
+{
+ closePopups();
+ emit startMove();
+}
+
void WindowCompositor::onStartResize(QWaylandInputDevice *, QWaylandShellSurface::ResizeEdge edges)
{
+ closePopups();
emit startResize(int(edges));
}
+void WindowCompositor::onSetTransient(QWaylandSurface *parentSurface, const QPoint &relativeToParent, QWaylandShellSurface::FocusPolicy focusPolicy)
+{
+ qDebug() << "Transient window support not implemented" << parentSurface << relativeToParent << focusPolicy;
+}
+
+void WindowCompositor::onSetPopup(QWaylandInputDevice *inputDevice, QWaylandSurface *parent, const QPoint &relativeToParent)
+{
+ Q_UNUSED(inputDevice);
+ QWaylandShellSurface *surface = qobject_cast<QWaylandShellSurface*>(sender());
+ WindowCompositorView *view = findView(surface->surface());
+ m_popupViews << view;
+ if (view) {
+ raise(view);
+ WindowCompositorView *parentView = findView(parent);
+ if (parentView)
+ view->setPosition(parentView->position() + relativeToParent);
+ }
+}
+
void WindowCompositor::triggerRender()
{
m_window->requestUpdate();
@@ -193,8 +228,19 @@ void WindowCompositor::adjustCursorSurface(QWaylandSurface *surface, int hotspot
m_cursorHotspotY = hotspotY;
}
+void WindowCompositor::closePopups()
+{
+ Q_FOREACH (WindowCompositorView *view, m_popupViews)
+ view->m_shellSurface->sendPopupDone();
+ m_popupViews.clear();
+}
+
void WindowCompositor::handleMouseEvent(QWaylandView *target, QMouseEvent *me)
{
+ if (target && popupActive() && me->type() == QEvent::MouseButtonPress
+ && target->surface()->client() != m_popupViews.first()->surface()->client()) {
+ closePopups();
+ }
QWaylandInputDevice *input = defaultInputDevice();
switch (me->type()) {
case QEvent::MouseButtonPress:
diff --git a/examples/wayland/qwindow-compositor/windowcompositor.h b/examples/wayland/qwindow-compositor/windowcompositor.h
index 1b5329d89..6f878d3a6 100644
--- a/examples/wayland/qwindow-compositor/windowcompositor.h
+++ b/examples/wayland/qwindow-compositor/windowcompositor.h
@@ -87,6 +87,8 @@ public:
void handleResize(WindowCompositorView *target, const QSize &initialSize, const QPoint &delta, int edge);
void handleDrag(WindowCompositorView *target, QMouseEvent *me);
+ bool popupActive() const { return !m_popupViews.isEmpty(); }
+ void closePopups();
protected:
void adjustCursorSurface(QWaylandSurface *surface, int hotspotX, int hotspotY);
@@ -101,6 +103,7 @@ private slots:
void surfaceDestroyed();
void surfaceCommittedSlot();
void viewSurfaceDestroyed();
+ void onStartMove();
void onStartResize(QWaylandInputDevice *inputDevice, QWaylandShellSurface::ResizeEdge edges);
void startDrag();
@@ -109,13 +112,16 @@ private slots:
void onSurfaceCreated(QWaylandSurface *surface);
void onCreateShellSurface(QWaylandSurface *s, QWaylandClient *client, uint id);
+ void onSetTransient(QWaylandSurface *parentSurface, const QPoint &relativeToParent, QWaylandShellSurface::FocusPolicy focusPolicy);
+ void onSetPopup(QWaylandInputDevice *inputDevice, QWaylandSurface *parent, const QPoint &relativeToParent);
+
void updateCursor();
private:
WindowCompositorView *findView(const QWaylandSurface *s) const;
QWindow *m_window;
QList<WindowCompositorView*> m_views;
+ QList<WindowCompositorView*> m_popupViews;
QWaylandShell *m_shell;
-
QWaylandView m_cursorView;
int m_cursorHotspotX;
int m_cursorHotspotY;