8 #include "generic_shell_surface_p.h"
11 #include "output_interface.h"
12 #include "resource_p.h"
13 #include "seat_interface.h"
14 #include "surface_interface.h"
15 #include "xdgshell_interface_p.h"
16 #include "xdgshell_stable_interface_p.h"
18 #include <wayland-xdg-shell-server-protocol.h>
24 class XdgShellStableInterface::Private :
public XdgShellInterface::Private
27 Private(XdgShellStableInterface *q, Display *d);
33 void createSurface(wl_client *client, uint32_t version, uint32_t
id, SurfaceInterface *surface, wl_resource *parentResource);
34 void createPositioner(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource);
36 void bind(wl_client *client, uint32_t version, uint32_t
id)
override;
38 quint32 ping(XdgShellSurfaceInterface *surface)
override;
40 static void unbind(wl_resource *resource);
41 static Private *cast(wl_resource *r)
43 return static_cast<Private *
>(wl_resource_get_user_data(r));
46 static void destroyCallback(wl_client *client, wl_resource *resource);
47 static void createPositionerCallback(wl_client *client, wl_resource *resource, uint32_t
id);
48 static void getXdgSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface);
49 static void pongCallback(wl_client *client, wl_resource *resource, uint32_t serial);
51 XdgShellStableInterface *q;
52 static const struct xdg_wm_base_interface s_interface;
53 static const quint32 s_version;
57 class XdgPopupStableInterface::Private :
public XdgShellPopupInterface::Private
60 Private(XdgPopupStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
63 QRect windowGeometry()
const override;
64 void commit()
override;
66 void ackConfigure(quint32 serial)
68 if (!configureSerials.contains(serial)) {
71 while (!configureSerials.isEmpty()) {
72 quint32 i = configureSerials.takeFirst();
73 Q_EMIT q_func()->configureAcknowledged(i);
80 void popupDone()
override;
83 XdgPopupStableInterface *q_func()
85 return static_cast<XdgPopupStableInterface *
>(q);
89 void setWindowGeometryCallback(
const QRect &rect);
91 static void grabCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial);
93 static const struct xdg_popup_interface s_interface;
95 struct ShellSurfaceState {
98 bool windowGeometryIsSet =
false;
101 ShellSurfaceState m_currentState;
102 ShellSurfaceState m_pendingState;
104 friend class XdgSurfaceStableInterface;
107 class XdgSurfaceStableInterface::Private :
public KWayland::Server::Resource::Private
110 Private(XdgSurfaceStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
114 XdgSurfaceStableInterface *q_func()
116 return static_cast<XdgSurfaceStableInterface *
>(q);
119 void createTopLevel(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource);
120 void createPopup(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource, wl_resource *parentWindow, wl_resource *positioner);
121 XdgShellStableInterface *m_shell;
122 SurfaceInterface *m_surface;
130 static void destroyCallback(wl_client *client, wl_resource *resource);
131 static void getTopLevelCallback(wl_client *client, wl_resource *resource, uint32_t
id);
132 static void getPopupCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *parent, wl_resource *positioner);
133 static void ackConfigureCallback(wl_client *client, wl_resource *resource, uint32_t serial);
134 static void setWindowGeometryCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
135 static const struct xdg_surface_interface s_interface;
138 class XdgTopLevelStableInterface::Private :
public XdgShellSurfaceInterface::Private
141 Private(XdgTopLevelStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource);
144 QRect windowGeometry()
const override;
145 QSize minimumSize()
const override;
146 QSize maximumSize()
const override;
147 void close()
override;
148 void commit()
override;
150 void ackConfigure(quint32 serial)
152 if (!configureSerials.contains(serial)) {
155 while (!configureSerials.isEmpty()) {
156 quint32 i = configureSerials.takeFirst();
157 Q_EMIT q_func()->configureAcknowledged(i);
169 const quint32 serial = global->display()->nextSerial();
170 wl_array configureStates;
171 wl_array_init(&configureStates);
172 if (states.testFlag(State::Maximized)) {
173 uint32_t *s =
static_cast<uint32_t *
>(wl_array_add(&configureStates,
sizeof(uint32_t)));
174 *s = XDG_TOPLEVEL_STATE_MAXIMIZED;
176 if (states.testFlag(State::Fullscreen)) {
177 uint32_t *s =
static_cast<uint32_t *
>(wl_array_add(&configureStates,
sizeof(uint32_t)));
178 *s = XDG_TOPLEVEL_STATE_FULLSCREEN;
180 if (states.testFlag(State::Resizing)) {
181 uint32_t *s =
static_cast<uint32_t *
>(wl_array_add(&configureStates,
sizeof(uint32_t)));
182 *s = XDG_TOPLEVEL_STATE_RESIZING;
184 if (states.testFlag(State::Activated)) {
185 uint32_t *s =
static_cast<uint32_t *
>(wl_array_add(&configureStates,
sizeof(uint32_t)));
186 *s = XDG_TOPLEVEL_STATE_ACTIVATED;
188 configureSerials << serial;
189 xdg_toplevel_send_configure(resource, size.
width(), size.
height(), &configureStates);
191 xdg_surface_send_configure(parentResource, serial);
194 wl_array_release(&configureStates);
198 XdgTopLevelStableInterface *q_func()
200 return static_cast<XdgTopLevelStableInterface *
>(q);
204 void setWindowGeometryCallback(
const QRect &rect);
206 static void destroyCallback(wl_client *client, wl_resource *resource);
207 static void setParentCallback(
struct wl_client *client,
struct wl_resource *resource, wl_resource *parent);
208 static void showWindowMenuCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, int32_t x, int32_t y);
209 static void setMaxSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
210 static void setMinSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
211 static void setMaximizedCallback(wl_client *client, wl_resource *resource);
212 static void unsetMaximizedCallback(wl_client *client, wl_resource *resource);
213 static void setFullscreenCallback(wl_client *client, wl_resource *resource, wl_resource *output);
214 static void unsetFullscreenCallback(wl_client *client, wl_resource *resource);
215 static void setMinimizedCallback(wl_client *client, wl_resource *resource);
217 static const struct xdg_toplevel_interface s_interface;
219 struct ShellSurfaceState {
220 QRect windowGeometry;
222 QSize maximiumSize =
QSize(INT32_MAX, INT32_MAX);
224 bool windowGeometryIsSet =
false;
225 bool minimumSizeIsSet =
false;
226 bool maximumSizeIsSet =
false;
229 ShellSurfaceState m_currentState;
230 ShellSurfaceState m_pendingState;
232 friend class XdgSurfaceStableInterface;
235 const quint32 XdgShellStableInterface::Private::s_version = 1;
238 const struct xdg_wm_base_interface XdgShellStableInterface::Private::s_interface = {destroyCallback,
239 createPositionerCallback,
240 getXdgSurfaceCallback,
244 void XdgShellStableInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
247 auto s = cast(resource);
248 if (!s->surfaces.isEmpty()) {
249 wl_resource_post_error(resource, XDG_WM_BASE_ERROR_DEFUNCT_SURFACES,
"WMBase destroyed before surfaces");
252 wl_resource_destroy(resource);
255 void XdgShellStableInterface::Private::createPositionerCallback(wl_client *client, wl_resource *resource, uint32_t
id)
257 auto s = cast(resource);
258 s->createPositioner(client, wl_resource_get_version(resource),
id, resource);
261 void XdgShellStableInterface::Private::getXdgSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
263 auto s = cast(resource);
264 s->createSurface(client, wl_resource_get_version(resource),
id,
SurfaceInterface::get(surface), resource);
267 void XdgShellStableInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t
id, SurfaceInterface *surface, wl_resource *parentResource)
269 auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(), [surface](XdgSurfaceStableInterface *s) {
270 return surface == s->surface();
272 if (it != surfaces.constEnd()) {
273 wl_resource_post_error(surface->resource(), XDG_WM_BASE_ERROR_ROLE,
"XDG Surface already created");
276 XdgSurfaceStableInterface *shellSurface =
new XdgSurfaceStableInterface(q, surface, parentResource);
277 surfaces << shellSurface;
278 QObject::connect(shellSurface, &XdgSurfaceStableInterface::destroyed, q, [
this, shellSurface] {
279 surfaces.removeAll(shellSurface);
282 shellSurface->d->create(display->getConnection(client), version,
id);
285 void XdgShellStableInterface::Private::createPositioner(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource)
289 XdgPositionerStableInterface *positioner =
new XdgPositionerStableInterface(q, parentResource);
290 positioners << positioner;
292 positioners.removeAll(positioner);
294 positioner->d->create(display->getConnection(client), version,
id);
297 void XdgShellStableInterface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial)
300 auto s = cast(resource);
301 auto timerIt = s->pingTimers.find(serial);
302 if (timerIt != s->pingTimers.end() && timerIt.value()->isActive()) {
303 delete timerIt.value();
304 s->pingTimers.erase(timerIt);
305 Q_EMIT s->q->pongReceived(serial);
309 XdgShellStableInterface::Private::Private(XdgShellStableInterface *q, Display *d)
315 void XdgShellStableInterface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
317 auto c = display->getConnection(client);
318 auto resource = c->createResource(&xdg_wm_base_interface, qMin(version, s_version),
id);
320 wl_client_post_no_memory(client);
323 resources[client] = resource;
324 wl_resource_set_implementation(resource, &s_interface,
this, unbind);
327 void XdgShellStableInterface::Private::unbind(wl_resource *resource)
329 auto s = cast(resource);
330 auto client = wl_resource_get_client(resource);
331 s->resources.remove(client);
334 XdgTopLevelStableInterface *XdgShellStableInterface::getSurface(wl_resource *resource)
341 for (
auto it = d->surfaces.constBegin(); it != d->surfaces.constEnd(); it++) {
342 auto topLevel = (*it)->topLevel();
343 if (topLevel && topLevel->resource() == resource) {
350 XdgSurfaceStableInterface *XdgShellStableInterface::realGetSurface(wl_resource *resource)
357 for (
auto it = d->surfaces.constBegin(); it != d->surfaces.constEnd(); it++) {
358 if ((*it)->resource() == resource) {
365 XdgPositionerStableInterface *XdgShellStableInterface::getPositioner(wl_resource *resource)
371 for (
auto it = d->positioners.constBegin(); it != d->positioners.constEnd(); it++) {
372 if ((*it)->resource() == resource) {
379 quint32 XdgShellStableInterface::Private::ping(XdgShellSurfaceInterface *surface)
381 auto client = surface->client()->client();
384 auto clientXdgShellResource = resources.value(client);
385 if (!clientXdgShellResource) {
389 const quint32 pingSerial = display->nextSerial();
390 xdg_wm_base_send_ping(clientXdgShellResource, pingSerial);
392 setupTimer(pingSerial);
396 XdgShellStableInterface::Private *XdgShellStableInterface::d_func()
const
398 return static_cast<Private *
>(d.data());
404 Qt::Edges edgesToQtEdges(xdg_toplevel_resize_edge edges)
408 case XDG_TOPLEVEL_RESIZE_EDGE_TOP:
411 case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM:
414 case XDG_TOPLEVEL_RESIZE_EDGE_LEFT:
417 case XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT:
420 case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT:
423 case XDG_TOPLEVEL_RESIZE_EDGE_RIGHT:
426 case XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT:
429 case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT:
432 case XDG_TOPLEVEL_RESIZE_EDGE_NONE:
443 const struct xdg_surface_interface XdgSurfaceStableInterface::Private::s_interface = {destroyCallback,
446 setWindowGeometryCallback,
447 ackConfigureCallback};
450 void XdgSurfaceStableInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
453 wl_resource_destroy(resource);
456 void XdgSurfaceStableInterface::Private::getTopLevelCallback(wl_client *client, wl_resource *resource, uint32_t
id)
458 auto s = cast<XdgSurfaceStableInterface::Private>(resource);
459 s->createTopLevel(client, wl_resource_get_version(resource),
id, resource);
462 void XdgSurfaceStableInterface::Private::createTopLevel(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource)
467 wl_resource_post_error(parentResource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"Toplevel already created on this surface");
471 wl_resource_post_error(parentResource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"Popup already created on this surface");
474 m_topLevel =
new XdgTopLevelStableInterface(m_shell, m_surface, parentResource);
475 m_topLevel->d->create(m_shell->display()->getConnection(client), version,
id);
477 Q_EMIT m_shell->surfaceCreated(m_topLevel);
480 void XdgSurfaceStableInterface::Private::getPopupCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *parent, wl_resource *positioner)
482 auto s = cast<XdgSurfaceStableInterface::Private>(resource);
483 s->createPopup(client, wl_resource_get_version(resource),
id, resource, parent, positioner);
486 void XdgSurfaceStableInterface::Private::createPopup(wl_client *client,
489 wl_resource *parentResource,
490 wl_resource *parentSurface,
491 wl_resource *positioner)
496 wl_resource_post_error(parentResource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"Toplevel already created on this surface");
500 wl_resource_post_error(parentResource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"Popup already created on this surface");
504 auto xdgPositioner = m_shell->getPositioner(positioner);
505 if (!xdgPositioner) {
506 wl_resource_post_error(parentResource, XDG_WM_BASE_ERROR_INVALID_POSITIONER,
"Invalid positioner");
509 m_popup =
new XdgPopupStableInterface(m_shell, m_surface, parentResource);
510 auto pd = m_popup->d_func();
512 pd->create(m_shell->display()->getConnection(client), version,
id);
514 auto parentXdgSurface = m_shell->realGetSurface(parentSurface);
515 if (!parentXdgSurface) {
516 wl_resource_post_error(parentResource, XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT,
"Invalid popup parent");
519 pd->parent = parentXdgSurface->surface();
520 pd->initialSize = xdgPositioner->initialSize();
521 pd->anchorRect = xdgPositioner->anchorRect();
522 pd->anchorEdge = xdgPositioner->anchorEdge();
523 pd->gravity = xdgPositioner->gravity();
524 pd->constraintAdjustments = xdgPositioner->constraintAdjustments();
525 pd->anchorOffset = xdgPositioner->anchorOffset();
527 Q_EMIT m_shell->xdgPopupCreated(m_popup.data());
530 void XdgSurfaceStableInterface::Private::ackConfigureCallback(wl_client *client, wl_resource *resource, uint32_t serial)
532 auto s = cast<Private>(resource);
533 Q_ASSERT(client == *s->client);
536 s->m_topLevel->d_func()->ackConfigure(serial);
537 }
else if (s->m_popup) {
538 s->m_popup->d_func()->ackConfigure(serial);
542 void XdgSurfaceStableInterface::Private::setWindowGeometryCallback(wl_client *client,
543 wl_resource *resource,
549 auto s = cast<Private>(resource);
550 Q_ASSERT(client == *s->client);
552 if (width < 0 || height < 0) {
553 wl_resource_post_error(resource, XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-surface geometry");
558 s->m_topLevel->d_func()->setWindowGeometryCallback(
QRect(x, y, width, height));
559 }
else if (s->m_popup) {
560 s->m_popup->d_func()->setWindowGeometryCallback(
QRect(x, y, width, height));
564 XdgSurfaceStableInterface::Private::Private(XdgSurfaceStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource)
565 : KWayland::Server::
Resource::Private(q, c, parentResource, &xdg_surface_interface, &s_interface)
571 XdgSurfaceStableInterface::Private::~Private() =
default;
573 class XdgPositionerStableInterface::Private :
public KWayland::Server::Resource::Private
576 Private(XdgPositionerStableInterface *q, XdgShellStableInterface *c, wl_resource *parentResource);
582 PositionerConstraints constraintAdjustments;
586 static void setSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
587 static void setAnchorRectCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
588 static void setAnchorCallback(wl_client *client, wl_resource *resource, uint32_t anchor);
589 static void setGravityCallback(wl_client *client, wl_resource *resource, uint32_t gravity);
590 static void setConstraintAdjustmentCallback(wl_client *client, wl_resource *resource, uint32_t constraint_adjustment);
591 static void setOffsetCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y);
593 static const struct xdg_positioner_interface s_interface;
596 XdgPositionerStableInterface::Private::Private(XdgPositionerStableInterface *q, XdgShellStableInterface *c, wl_resource *parentResource)
597 : KWayland::Server::
Resource::Private(q, c, parentResource, &xdg_positioner_interface, &s_interface)
602 const struct xdg_positioner_interface XdgPositionerStableInterface::Private::s_interface = {resourceDestroyedCallback,
604 setAnchorRectCallback,
607 setConstraintAdjustmentCallback,
611 void XdgPositionerStableInterface::Private::setSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
614 auto s = cast<Private>(resource);
615 s->initialSize =
QSize(width, height);
618 void XdgPositionerStableInterface::Private::setAnchorRectCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
621 auto s = cast<Private>(resource);
622 s->anchorRect =
QRect(x, y, width, height);
625 void XdgPositionerStableInterface::Private::setAnchorCallback(wl_client *client, wl_resource *resource, uint32_t anchor)
629 auto s = cast<Private>(resource);
633 case XDG_POSITIONER_ANCHOR_TOP:
636 case XDG_POSITIONER_ANCHOR_BOTTOM:
639 case XDG_POSITIONER_ANCHOR_LEFT:
642 case XDG_POSITIONER_ANCHOR_TOP_LEFT:
645 case XDG_POSITIONER_ANCHOR_BOTTOM_LEFT:
648 case XDG_POSITIONER_ANCHOR_RIGHT:
651 case XDG_POSITIONER_ANCHOR_TOP_RIGHT:
654 case XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT:
657 case XDG_POSITIONER_ANCHOR_NONE:
664 s->anchorEdge = qtEdges;
667 void XdgPositionerStableInterface::Private::setGravityCallback(wl_client *client, wl_resource *resource, uint32_t gravity)
670 auto s = cast<Private>(resource);
674 case XDG_POSITIONER_GRAVITY_TOP:
677 case XDG_POSITIONER_GRAVITY_BOTTOM:
680 case XDG_POSITIONER_GRAVITY_LEFT:
683 case XDG_POSITIONER_GRAVITY_TOP_LEFT:
686 case XDG_POSITIONER_GRAVITY_BOTTOM_LEFT:
689 case XDG_POSITIONER_GRAVITY_RIGHT:
692 case XDG_POSITIONER_GRAVITY_TOP_RIGHT:
695 case XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT:
698 case XDG_POSITIONER_GRAVITY_NONE:
705 s->gravity = qtEdges;
708 void XdgPositionerStableInterface::Private::setConstraintAdjustmentCallback(wl_client *client, wl_resource *resource, uint32_t constraint_adjustment)
711 auto s = cast<Private>(resource);
712 PositionerConstraints constraints;
713 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X) {
716 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y) {
719 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X) {
722 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y) {
725 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X) {
728 if (constraint_adjustment & XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y) {
731 s->constraintAdjustments = constraints;
734 void XdgPositionerStableInterface::Private::setOffsetCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
737 auto s = cast<Private>(resource);
738 s->anchorOffset =
QPoint(x, y);
741 QRect XdgTopLevelStableInterface::Private::windowGeometry()
const
743 return m_currentState.windowGeometry;
746 QSize XdgTopLevelStableInterface::Private::minimumSize()
const
748 return m_currentState.minimumSize;
751 QSize XdgTopLevelStableInterface::Private::maximumSize()
const
753 return m_currentState.maximiumSize;
756 void XdgTopLevelStableInterface::Private::close()
758 xdg_toplevel_send_close(resource);
762 void XdgTopLevelStableInterface::Private::commit()
764 const bool windowGeometryChanged = m_pendingState.windowGeometryIsSet;
765 const bool minimumSizeChanged = m_pendingState.minimumSizeIsSet;
766 const bool maximumSizeChanged = m_pendingState.maximumSizeIsSet;
768 if (windowGeometryChanged) {
769 m_currentState.windowGeometry = m_pendingState.windowGeometry;
771 if (minimumSizeChanged) {
772 m_currentState.minimumSize = m_pendingState.minimumSize;
774 if (maximumSizeChanged) {
775 m_currentState.maximiumSize = m_pendingState.maximiumSize;
778 m_pendingState = ShellSurfaceState{};
780 if (windowGeometryChanged) {
781 Q_EMIT q_func()->windowGeometryChanged(m_currentState.windowGeometry);
783 if (minimumSizeChanged) {
784 Q_EMIT q_func()->minSizeChanged(m_currentState.minimumSize);
786 if (maximumSizeChanged) {
787 Q_EMIT q_func()->maxSizeChanged(m_currentState.maximiumSize);
791 void XdgTopLevelStableInterface::Private::setMaxSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
793 if (width < 0 || height < 0) {
794 wl_resource_post_error(resource, XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-toplevel maximum size");
803 auto s = cast<Private>(resource);
804 Q_ASSERT(client == *s->client);
805 s->m_pendingState.maximiumSize =
QSize(width, height);
806 s->m_pendingState.maximumSizeIsSet =
true;
809 void XdgTopLevelStableInterface::Private::setMinSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
811 if (width < 0 || height < 0) {
812 wl_resource_post_error(resource, XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-toplevel minimum size");
815 auto s = cast<Private>(resource);
816 Q_ASSERT(client == *s->client);
817 s->m_pendingState.minimumSize =
QSize(width, height);
818 s->m_pendingState.minimumSizeIsSet =
true;
821 void XdgTopLevelStableInterface::Private::setWindowGeometryCallback(
const QRect &rect)
823 m_pendingState.windowGeometry = rect;
824 m_pendingState.windowGeometryIsSet =
true;
827 const struct xdg_toplevel_interface XdgTopLevelStableInterface::Private::s_interface = {destroyCallback,
831 showWindowMenuCallback,
833 resizeCallback<xdg_toplevel_resize_edge>,
836 setMaximizedCallback,
837 unsetMaximizedCallback,
838 setFullscreenCallback,
839 unsetFullscreenCallback,
840 setMinimizedCallback};
842 void XdgTopLevelStableInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
845 wl_resource_destroy(resource);
848 void XdgTopLevelStableInterface::Private::setParentCallback(wl_client *client, wl_resource *resource, wl_resource *parent)
850 auto s = cast<Private>(resource);
851 Q_ASSERT(client == *s->client);
855 Q_EMIT s->q_func()->transientForChanged();
857 auto parentSurface =
static_cast<XdgShellStableInterface *
>(s->q->global())->getSurface(parent);
858 if (s->parent.data() != parentSurface) {
860 Q_EMIT s->q_func()->transientForChanged();
865 void XdgTopLevelStableInterface::Private::showWindowMenuCallback(wl_client *client,
866 wl_resource *resource,
872 auto s = cast<Private>(resource);
873 Q_ASSERT(client == *s->client);
874 Q_EMIT s->q_func()->windowMenuRequested(SeatInterface::get(seat), serial,
QPoint(x, y));
877 XdgTopLevelStableInterface::Private::Private(XdgTopLevelStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource)
882 void XdgTopLevelStableInterface::Private::setMaximizedCallback(wl_client *client, wl_resource *resource)
884 auto s = cast<Private>(resource);
885 Q_ASSERT(client == *s->client);
886 s->q_func()->maximizedChanged(
true);
889 void XdgTopLevelStableInterface::Private::unsetMaximizedCallback(wl_client *client, wl_resource *resource)
891 auto s = cast<Private>(resource);
892 Q_ASSERT(client == *s->client);
893 s->q_func()->maximizedChanged(
false);
896 void XdgTopLevelStableInterface::Private::setFullscreenCallback(wl_client *client, wl_resource *resource, wl_resource *output)
898 auto s = cast<Private>(resource);
899 Q_ASSERT(client == *s->client);
900 OutputInterface *o =
nullptr;
902 o = OutputInterface::get(output);
904 s->q_func()->fullscreenChanged(
true, o);
907 void XdgTopLevelStableInterface::Private::unsetFullscreenCallback(wl_client *client, wl_resource *resource)
909 auto s = cast<Private>(resource);
910 Q_ASSERT(client == *s->client);
911 s->q_func()->fullscreenChanged(
false,
nullptr);
914 void XdgTopLevelStableInterface::Private::setMinimizedCallback(wl_client *client, wl_resource *resource)
916 auto s = cast<Private>(resource);
917 Q_ASSERT(client == *s->client);
918 s->q_func()->minimizeRequested();
921 XdgTopLevelStableInterface::Private::~Private() =
default;
924 const struct xdg_popup_interface XdgPopupStableInterface::Private::s_interface = {resourceDestroyedCallback, grabCallback};
927 XdgPopupStableInterface::Private::Private(XdgPopupStableInterface *q, XdgShellStableInterface *c, SurfaceInterface *surface, wl_resource *parentResource)
932 QRect XdgPopupStableInterface::Private::windowGeometry()
const
934 return m_currentState.windowGeometry;
937 void XdgPopupStableInterface::Private::commit()
939 const bool windowGeometryChanged = m_pendingState.windowGeometryIsSet;
941 if (windowGeometryChanged) {
942 m_currentState.windowGeometry = m_pendingState.windowGeometry;
945 m_pendingState = ShellSurfaceState{};
947 if (windowGeometryChanged) {
948 Q_EMIT q_func()->windowGeometryChanged(m_currentState.windowGeometry);
952 void XdgPopupStableInterface::Private::setWindowGeometryCallback(
const QRect &rect)
954 m_pendingState.windowGeometry = rect;
955 m_pendingState.windowGeometryIsSet =
true;
958 void XdgPopupStableInterface::Private::grabCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial)
961 auto s = cast<Private>(resource);
962 auto seatInterface = SeatInterface::get(seat);
963 s->q_func()->grabRequested(seatInterface, serial);
966 XdgPopupStableInterface::Private::~Private() =
default;
968 quint32 XdgPopupStableInterface::Private::configure(
const QRect &rect)
973 const quint32 serial = global->display()->nextSerial();
974 configureSerials << serial;
975 xdg_popup_send_configure(resource, rect.
x(), rect.
y(), rect.
width(), rect.
height());
976 xdg_surface_send_configure(parentResource, serial);
982 void XdgPopupStableInterface::Private::popupDone()
988 xdg_popup_send_popup_done(resource);
992 XdgShellStableInterface::XdgShellStableInterface(Display *display,
QObject *parent)
993 : XdgShellInterface(new Private(this, display), parent)
997 Display *XdgShellStableInterface::display()
const
1002 XdgShellStableInterface::~XdgShellStableInterface() =
default;
1004 XdgSurfaceStableInterface::XdgSurfaceStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource)
1005 : KWayland::Server::
Resource(new Private(this, parent, surface, parentResource))
1009 XdgSurfaceStableInterface::~XdgSurfaceStableInterface() =
default;
1011 SurfaceInterface *XdgSurfaceStableInterface::surface()
const
1014 return d->m_surface;
1017 XdgPositionerStableInterface::XdgPositionerStableInterface(XdgShellStableInterface *parent, wl_resource *parentResource)
1018 : KWayland::Server::
Resource(new Private(this, parent, parentResource))
1022 QSize XdgPositionerStableInterface::initialSize()
const
1025 return d->initialSize;
1028 QRect XdgPositionerStableInterface::anchorRect()
const
1031 return d->anchorRect;
1034 Qt::Edges XdgPositionerStableInterface::anchorEdge()
const
1037 return d->anchorEdge;
1040 Qt::Edges XdgPositionerStableInterface::gravity()
const
1046 PositionerConstraints XdgPositionerStableInterface::constraintAdjustments()
const
1049 return d->constraintAdjustments;
1052 QPoint XdgPositionerStableInterface::anchorOffset()
const
1055 return d->anchorOffset;
1058 XdgPositionerStableInterface::Private *XdgPositionerStableInterface::d_func()
const
1060 return static_cast<Private *
>(d.data());
1063 XdgTopLevelStableInterface *XdgSurfaceStableInterface::topLevel()
const
1066 return d->m_topLevel.data();
1069 XdgPopupStableInterface *XdgSurfaceStableInterface::popup()
const
1072 return d->m_popup.data();
1075 XdgSurfaceStableInterface::Private *XdgSurfaceStableInterface::d_func()
const
1077 return static_cast<Private *
>(d.data());
1080 XdgTopLevelStableInterface::XdgTopLevelStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource)
1081 : KWayland::Server::XdgShellSurfaceInterface(new Private(this, parent, surface, parentResource))
1085 XdgTopLevelStableInterface::~XdgTopLevelStableInterface() =
default;
1087 XdgTopLevelStableInterface::Private *XdgTopLevelStableInterface::d_func()
const
1089 return static_cast<Private *
>(d.data());
1092 XdgPopupStableInterface::XdgPopupStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource)
1093 : XdgShellPopupInterface(new Private(this, parent, surface, parentResource))
1097 XdgPopupStableInterface::~XdgPopupStableInterface() =
default;
1099 XdgPopupStableInterface::Private *XdgPopupStableInterface::d_func()
const
1101 return static_cast<Private *
>(d.data());