Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandwlshell.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#include "qwaylandwlshell.h"
6#include "qwaylandwlshell_p.h"
7
8#if QT_CONFIG(wayland_compositor_quick)
10#endif
11#include <QtWaylandCompositor/private/qwaylandutils_p.h>
12
13#include <QtWaylandCompositor/QWaylandCompositor>
14#include <QtWaylandCompositor/QWaylandView>
15#include <QtWaylandCompositor/QWaylandOutput>
16#include <QtWaylandCompositor/QWaylandClient>
17
18#include <QtCore/QObject>
19#include <QtCore/QDebug>
20
22
23QWaylandSurfaceRole QWaylandWlShellSurfacePrivate::s_role("wl_shell_surface");
24
28
29void QWaylandWlShellPrivate::shell_get_shell_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface_res)
30{
31 Q_Q(QWaylandWlShell);
32 QWaylandSurface *surface = QWaylandSurface::fromResource(surface_res);
33
34 QWaylandResource shellSurfaceResource(wl_resource_create(resource->client(), &wl_shell_surface_interface,
35 wl_resource_get_version(resource->handle), id));
36
37 // XXX FIXME
38 // The role concept was formalized in wayland 1.7, so that release adds one error
39 // code for each interface that implements a role, and we are supposed to pass here
40 // the newly constructed resource and the correct error code so that if setting the
41 // role fails, a proper error can be sent to the client.
42 // However we're still using wayland 1.4, which doesn't have interface specific role
43 // errors, so the best we can do is to use wl_display's object_id error.
44 wl_resource *displayRes = wl_client_get_object(resource->client(), 1);
45 if (!surface->setRole(QWaylandWlShellSurface::role(), displayRes, WL_DISPLAY_ERROR_INVALID_OBJECT))
46 return;
47
48 emit q->wlShellSurfaceRequested(surface, shellSurfaceResource);
49
50 QWaylandWlShellSurface *shellSurface = QWaylandWlShellSurface::fromResource(shellSurfaceResource.resource());
51 if (!shellSurface) {
52 // A QWaylandWlShellSurface was not created in response to the wlShellSurfaceRequested
53 // signal, so we create one as fallback here instead.
54 shellSurface = new QWaylandWlShellSurface(q, surface, shellSurfaceResource);
55 }
56
57 m_shellSurfaces.append(shellSurface);
58 emit q->wlShellSurfaceCreated(shellSurface);
59}
60
62{
63 if (!m_shellSurfaces.removeOne(shellSurface))
64 qWarning("Unexpected state. Can't find registered shell surface.");
65}
66
70
74
76{
77 m_pings.insert(serial);
78 send_ping(serial);
79}
80
82{
83 if (m_windowType == windowType)
84 return;
85 m_windowType = windowType;
86
88 emit q->windowTypeChanged();
89}
90
97
99 struct wl_resource *input_device_super,
100 uint32_t serial)
101{
102 Q_UNUSED(resource);
103 Q_UNUSED(serial);
104
106 QWaylandSeat *input_device = QWaylandSeat::fromSeatResource(input_device_super);
107 emit q->startMove(input_device);
108}
109
111 struct wl_resource *input_device_super,
112 uint32_t serial,
113 uint32_t edges)
114{
115 Q_UNUSED(resource);
116 Q_UNUSED(serial);
118
119 QWaylandSeat *input_device = QWaylandSeat::fromSeatResource(input_device_super);
120 emit q->startResize(input_device, QWaylandWlShellSurface::ResizeEdge(edges));
121}
122
124{
125 Q_UNUSED(resource);
128 emit q->setDefaultToplevel();
129}
130
132 struct wl_resource *parent_surface_resource,
133 int x,
134 int y,
135 uint32_t flags)
136{
137
138 Q_UNUSED(resource);
140 QWaylandSurface *parent_surface = QWaylandSurface::fromResource(parent_surface_resource);
142 emit q->setTransient(parent_surface, QPoint(x,y), flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE);
143}
144
146 uint32_t method,
147 uint32_t framerate,
148 struct wl_resource *output_resource)
149{
150 Q_UNUSED(resource);
152 Q_UNUSED(framerate);
154 QWaylandOutput *output = output_resource
155 ? QWaylandOutput::fromResource(output_resource)
156 : nullptr;
158 emit q->setFullScreen(QWaylandWlShellSurface::FullScreenMethod(method), framerate, output);
159}
160
161void QWaylandWlShellSurfacePrivate::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)
162{
163 Q_UNUSED(resource);
164 Q_UNUSED(serial);
170 emit q->setPopup(input, parentSurface, QPoint(x,y));
171
172}
173
175 struct wl_resource *output_resource)
176{
177 Q_UNUSED(resource);
179 QWaylandOutput *output = output_resource
180 ? QWaylandOutput::fromResource(output_resource)
181 : nullptr;
183 emit q->setMaximized(output);
184}
185
187 uint32_t serial)
188{
189 Q_UNUSED(resource);
191 if (m_pings.remove(serial))
192 emit q->pong();
193 else
194 qWarning("Received an unexpected pong!");
195}
196
198 const QString &title)
199{
200 Q_UNUSED(resource);
201 if (title == m_title)
202 return;
204 m_title = title;
205 emit q->titleChanged();
206}
207
209 const QString &className)
210{
211 Q_UNUSED(resource);
212 if (className == m_className)
213 return;
215 m_className = className;
216 emit q->classNameChanged();
217}
218
266
273
274
279{
280 Q_D(QWaylandWlShell);
282 QWaylandCompositor *compositor = qobject_cast<QWaylandCompositor *>(extensionContainer());
283 if (!compositor) {
284 qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandWlShell";
285 return;
286 }
287 d->init(compositor->display(), 1);
288}
289
290QList<QWaylandWlShellSurface *> QWaylandWlShell::shellSurfaces() const
291{
292 Q_D(const QWaylandWlShell);
293 return d->m_shellSurfaces;
294}
295
296QList<QWaylandWlShellSurface *> QWaylandWlShell::shellSurfacesForClient(QWaylandClient *client) const
297{
298 Q_D(const QWaylandWlShell);
299 QList<QWaylandWlShellSurface *> surfsForClient;
300 for (QWaylandWlShellSurface *shellSurface : d->m_shellSurfaces) {
301 if (shellSurface->surface() && shellSurface->surface()->client() == client)
302 surfsForClient.append(shellSurface);
303 }
304 return surfsForClient;
305}
306
307QList<QWaylandWlShellSurface *> QWaylandWlShell::mappedPopups() const
308{
309 Q_D(const QWaylandWlShell);
310 QList<QWaylandWlShellSurface *> popupSurfaces;
311 for (QWaylandWlShellSurface *shellSurface : d->m_shellSurfaces) {
312 if (shellSurface->windowType() == Qt::WindowType::Popup
313 && shellSurface->surface() && shellSurface->surface()->hasContent()) {
314 popupSurfaces.append(shellSurface);
315 }
316 }
317 return popupSurfaces;
318}
319
321{
322 Q_D(const QWaylandWlShell);
323 for (QWaylandWlShellSurface *shellSurface : d->m_shellSurfaces) {
324 if (shellSurface->windowType() == Qt::WindowType::Popup
325 && shellSurface->surface() && shellSurface->surface()->hasContent()) {
326 return shellSurface->surface()->client();
327 }
328 }
329 return nullptr;
330}
331
333{
334 const auto mapped = mappedPopups();
335 for (QWaylandWlShellSurface *shellSurface : mapped)
336 shellSurface->sendPopupDone();
337}
338
342const struct wl_interface *QWaylandWlShell::interface()
343{
344 return QWaylandWlShellPrivate::interface();
345}
346
385{
386 return QWaylandWlShellPrivate::interfaceName();
387}
388
423
432
434{
436 if (d->m_shell)
437 QWaylandWlShellPrivate::get(d->m_shell)->unregisterShellSurface(this);
438}
439
450{
452 d->m_shell = shell;
453 d->m_surface = surface;
454 d->init(resource.resource());
459}
460
468
469const struct wl_interface *QWaylandWlShellSurface::interface()
470{
471 return QWaylandWlShellSurfacePrivate::interface();
472}
473
478{
479 return QWaylandWlShellSurfacePrivate::interfaceName();
480}
481
483{
484 qreal width = size.width();
485 qreal height = size.height();
486 if (edge & LeftEdge)
487 width -= delta.x();
488 else if (edge & RightEdge)
489 width += delta.x();
490
491 if (edge & TopEdge)
492 height -= delta.y();
493 else if (edge & BottomEdge)
494 height += delta.y();
495
496 QSizeF newSize(qMax(width, 1.0), qMax(height, 1.0));
497 return newSize.toSize();
498}
499
531{
533 if (!size.isValid()) {
534 qWarning() << "Can't configure wl_shell_surface with an invalid size" << size;
535 return;
536 }
537 d->send_configure(edges, size.width(), size.height());
538}
539
552{
554 d->send_popup_done();
555}
556
557#if QT_CONFIG(wayland_compositor_quick)
558QWaylandQuickShellIntegration *QWaylandWlShellSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
559{
561}
562#endif
563
576{
577 Q_D(const QWaylandWlShellSurface);
578 return d->m_surface;
579}
580
593{
594 Q_D(const QWaylandWlShellSurface);
595 return d->m_shell;
596}
597
605{
606 Q_D(const QWaylandWlShellSurface);
607 return d->m_windowType;
608}
609
622{
623 Q_D(const QWaylandWlShellSurface);
624 return d->m_title;
625}
626
639{
640 Q_D(const QWaylandWlShellSurface);
641 return d->m_className;
642}
643
645{
646 return &QWaylandWlShellSurfacePrivate::s_role;
647}
648
661{
663 uint32_t serial = d->m_surface->compositor()->nextSerial();
664 d->ping(serial);
665}
666
671{
672 if (auto p = QtWayland::fromResource<QWaylandWlShellSurfacePrivate *>(resource))
673 return p->q_func();
674 return nullptr;
675}
676
678
679#include "moc_qwaylandwlshell.cpp"
\inmodule QtCore
Definition qbytearray.h:57
bool removeOne(const AT &t)
Definition qlist.h:598
void append(parameter_type t)
Definition qlist.h:458
QObject * parent
Definition qobject.h:73
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qpoint.h:25
bool remove(const T &value)
Definition qset.h:63
iterator insert(const T &value)
Definition qset.h:155
\inmodule QtCore
Definition qsize.h:208
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:401
\inmodule QtCore
Definition qsize.h:25
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\qmltype WaylandClient \instantiates QWaylandClient \inqmlmodule QtWayland.Compositor
void setExtensionContainer(QWaylandObject *container)
Sets the extension container for this QWaylandCompositorExtension to container.
virtual void initialize()
Initializes the QWaylandCompositorExtension.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
\qmltype WaylandOutput \instantiates QWaylandOutput \inqmlmodule QtWayland.Compositor
static QWaylandOutput * fromResource(wl_resource *resource)
Returns the QWaylandOutput corresponding to resource.
\qmltype ShellSurfaceItem \instantiates QWaylandQuickShellSurfaceItem \inherits WaylandQuickItem \inq...
\inmodule QtWaylandCompositor
wl_resource * resource() const
\qmltype WaylandSeat \instantiates QWaylandSeat \inqmlmodule QtWayland.Compositor
static QWaylandSeat * fromSeatResource(struct ::wl_resource *resource)
Returns the QWaylandSeat corresponding to the resource.
\inmodule QtWaylandCompositor
\inmodule QtWaylandCompositor
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
static QWaylandSurface * fromResource(::wl_resource *resource)
Returns the QWaylandSurface corresponding to the Wayland resource resource.
bool setRole(QWaylandSurfaceRole *role, wl_resource *errorResource, uint32_t errorCode)
Sets a role on the surface.
QList< QWaylandWlShellSurface * > m_shellSurfaces
static QWaylandWlShellPrivate * get(QWaylandWlShell *shell)
void unregisterShellSurface(QWaylandWlShellSurface *shellSurface)
void shell_get_shell_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface) override
void shell_surface_set_maximized(Resource *resource, struct wl_resource *output_resource) override
void shell_surface_destroy_resource(Resource *resource) override
void shell_surface_set_toplevel(Resource *resource) override
void shell_surface_move(Resource *resource, struct wl_resource *input_device_super, uint32_t time) override
void shell_surface_pong(Resource *resource, uint32_t serial) override
void shell_surface_set_fullscreen(Resource *resource, uint32_t method, uint32_t framerate, struct wl_resource *output_resource) override
void shell_surface_set_transient(Resource *resource, struct wl_resource *parent_surface_resource, int x, int y, uint32_t flags) override
void shell_surface_set_class(Resource *resource, const QString &class_) override
void shell_surface_set_title(Resource *resource, const QString &title) override
void shell_surface_resize(Resource *resource, struct wl_resource *input_device, uint32_t time, uint32_t edges) override
void shell_surface_set_popup(Resource *resource, struct wl_resource *input_device, uint32_t time, struct wl_resource *parent, int32_t x, int32_t y, uint32_t flags) override
void setWindowType(Qt::WindowType windowType)
\qmltype WlShellSurface \instantiates QWaylandWlShellSurface \inqmlmodule QtWayland....
static QWaylandWlShellSurface * fromResource(wl_resource *res)
Returns the QWaylandWlShellSurface object associated with the given resource, or null if no such obje...
static QByteArray interfaceName()
QWaylandWlShell * shell
\qmlproperty WlShell WlShellSurface::shell
static const struct wl_interface * interface()
Q_INVOKABLE void sendPopupDone()
\qmlmethod void WlShellSurface::sendPopupDone()
QString title
\qmlproperty string WlShellSurface::title
QString className
\qmlproperty string WlShellSurface::className
Q_INVOKABLE void sendConfigure(const QSize &size, ResizeEdge edges)
\qmlmethod void WlShellSurface::sendConfigure(size s, enum edges)
static QWaylandSurfaceRole * role()
ResizeEdge
This enum type provides a way to specify an edge or corner of the surface.
Qt::WindowType windowType() const override
\qmlproperty enum WlShellSurface::windowType
QWaylandSurface * surface
\qmlproperty WaylandSurface WlShellSurface::surface
void ping()
\qmlmethod void WlShellSurface::ping()
Q_INVOKABLE QSize sizeForResize(const QSizeF &size, const QPointF &delta, ResizeEdge edges)
QWaylandWlShellSurface()
Constructs a QWaylandWlShellSurface.
\qmltype WlShell \instantiates QWaylandWlShell \inqmlmodule QtWayland.Compositor.WlShell
QWaylandWlShell()
Constructs a QWaylandWlShell object.
QList< QWaylandWlShellSurface * > shellSurfacesForClient(QWaylandClient *client) const
QWaylandClient * popupClient() const
static QByteArray interfaceName()
void initialize() override
Initializes the WlShell extension.
QList< QWaylandWlShellSurface * > shellSurfaces() const
QList< QWaylandWlShellSurface * > mappedPopups() const
static const struct wl_interface * interface()
Returns the Wayland interface for the QWaylandWlShell.
Combined button and popup list for selecting options.
WindowType
Definition qnamespace.h:205
@ Popup
Definition qnamespace.h:211
@ Window
Definition qnamespace.h:207
@ SubWindow
Definition qnamespace.h:216
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
#define qWarning
Definition qlogging.h:166
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static QOpenGLCompositor * compositor
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLbitfield flags
GLint y
GLuint res
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLenum GLenum GLenum input
#define emit
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
QT_BEGIN_NAMESPACE typedef uchar * output
const char className[16]
[1]
Definition qwizard.cpp:100
QString title
[35]
QGraphicsItem * item