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_v6_interface_p.h"
18 #include <wayland-xdg-shell-v6-server-protocol.h>
24 class XdgShellV6Interface::Private :
public XdgShellInterface::Private
27 Private(XdgShellV6Interface *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 reinterpret_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 XdgShellV6Interface *q;
52 static const struct zxdg_shell_v6_interface s_interface;
53 static const quint32 s_version;
57 class XdgPopupV6Interface::Private :
public XdgShellPopupInterface::Private
60 Private(XdgPopupV6Interface *q, XdgShellV6Interface *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)) {
72 while (!configureSerials.isEmpty()) {
73 quint32 i = configureSerials.takeFirst();
74 Q_EMIT q_func()->configureAcknowledged(i);
81 void popupDone()
override;
84 XdgPopupV6Interface *q_func()
86 return reinterpret_cast<XdgPopupV6Interface *
>(q);
90 void setWindowGeometryCallback(
const QRect &rect);
92 static void grabCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial);
94 static const struct zxdg_popup_v6_interface s_interface;
96 struct ShellSurfaceState {
99 bool windowGeometryIsSet =
false;
102 ShellSurfaceState m_currentState;
103 ShellSurfaceState m_pendingState;
105 friend class XdgSurfaceV6Interface;
108 class XdgSurfaceV6Interface::Private :
public KWayland::Server::Resource::Private
111 Private(XdgSurfaceV6Interface *q, XdgShellV6Interface *c, SurfaceInterface *surface, wl_resource *parentResource);
115 XdgSurfaceV6Interface *q_func()
117 return reinterpret_cast<XdgSurfaceV6Interface *
>(q);
120 void createTopLevel(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource);
121 void createPopup(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource, wl_resource *parentWindow, wl_resource *positioner);
122 XdgShellV6Interface *m_shell;
123 SurfaceInterface *m_surface;
131 static void destroyCallback(wl_client *client, wl_resource *resource);
132 static void getTopLevelCallback(wl_client *client, wl_resource *resource, uint32_t
id);
133 static void getPopupCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *parent, wl_resource *positioner);
134 static void ackConfigureCallback(wl_client *client, wl_resource *resource, uint32_t serial);
135 static void setWindowGeometryCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
136 static const struct zxdg_surface_v6_interface s_interface;
139 class XdgTopLevelV6Interface::Private :
public XdgShellSurfaceInterface::Private
142 Private(XdgTopLevelV6Interface *q, XdgShellV6Interface *c, SurfaceInterface *surface, wl_resource *parentResource);
145 QRect windowGeometry()
const override;
146 QSize minimumSize()
const override;
147 QSize maximumSize()
const override;
148 void close()
override;
149 void commit()
override;
151 void ackConfigure(quint32 serial)
153 if (!configureSerials.contains(serial)) {
157 while (!configureSerials.isEmpty()) {
158 quint32 i = configureSerials.takeFirst();
159 Q_EMIT q_func()->configureAcknowledged(i);
171 const quint32 serial = global->display()->nextSerial();
173 wl_array_init(&state);
174 if (states.testFlag(State::Maximized)) {
175 uint32_t *s =
reinterpret_cast<uint32_t *
>(wl_array_add(&state,
sizeof(uint32_t)));
176 *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
178 if (states.testFlag(State::Fullscreen)) {
179 uint32_t *s =
reinterpret_cast<uint32_t *
>(wl_array_add(&state,
sizeof(uint32_t)));
180 *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
182 if (states.testFlag(State::Resizing)) {
183 uint32_t *s =
reinterpret_cast<uint32_t *
>(wl_array_add(&state,
sizeof(uint32_t)));
184 *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
186 if (states.testFlag(State::Activated)) {
187 uint32_t *s =
reinterpret_cast<uint32_t *
>(wl_array_add(&state,
sizeof(uint32_t)));
188 *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
190 configureSerials << serial;
191 zxdg_toplevel_v6_send_configure(resource, size.
width(), size.
height(), &state);
193 zxdg_surface_v6_send_configure(parentResource, serial);
196 wl_array_release(&state);
200 XdgTopLevelV6Interface *q_func()
202 return reinterpret_cast<XdgTopLevelV6Interface *
>(q);
206 void setWindowGeometryCallback(
const QRect &rect);
208 static void destroyCallback(wl_client *client, wl_resource *resource);
209 static void setParentCallback(
struct wl_client *client,
struct wl_resource *resource, wl_resource *parent);
210 static void showWindowMenuCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, int32_t x, int32_t y);
211 static void setMaxSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
212 static void setMinSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
213 static void setMaximizedCallback(wl_client *client, wl_resource *resource);
214 static void unsetMaximizedCallback(wl_client *client, wl_resource *resource);
215 static void setFullscreenCallback(wl_client *client, wl_resource *resource, wl_resource *output);
216 static void unsetFullscreenCallback(wl_client *client, wl_resource *resource);
217 static void setMinimizedCallback(wl_client *client, wl_resource *resource);
219 static const struct zxdg_toplevel_v6_interface s_interface;
221 struct ShellSurfaceState {
222 QRect windowGeometry;
224 QSize maximiumSize =
QSize(INT32_MAX, INT32_MAX);
226 bool windowGeometryIsSet =
false;
227 bool minimumSizeIsSet =
false;
228 bool maximumSizeIsSet =
false;
231 ShellSurfaceState m_currentState;
232 ShellSurfaceState m_pendingState;
234 friend class XdgSurfaceV6Interface;
237 const quint32 XdgShellV6Interface::Private::s_version = 1;
240 const struct zxdg_shell_v6_interface XdgShellV6Interface::Private::s_interface = {destroyCallback,
241 createPositionerCallback,
242 getXdgSurfaceCallback,
246 void XdgShellV6Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
250 wl_resource_destroy(resource);
253 void XdgShellV6Interface::Private::createPositionerCallback(wl_client *client, wl_resource *resource, uint32_t
id)
255 auto s = cast(resource);
256 s->createPositioner(client, wl_resource_get_version(resource),
id, resource);
259 void XdgShellV6Interface::Private::getXdgSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
261 auto s = cast(resource);
262 s->createSurface(client, wl_resource_get_version(resource),
id,
SurfaceInterface::get(surface), resource);
265 void XdgShellV6Interface::Private::createSurface(wl_client *client, uint32_t version, uint32_t
id, SurfaceInterface *surface, wl_resource *parentResource)
267 auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(), [surface](XdgSurfaceV6Interface *s) {
269 return surface == s->surface();
271 if (it != surfaces.constEnd()) {
272 wl_resource_post_error(surface->resource(), ZXDG_SHELL_V6_ERROR_ROLE,
"ShellSurface already created");
275 XdgSurfaceV6Interface *shellSurface =
new XdgSurfaceV6Interface(q, surface, parentResource);
276 surfaces << shellSurface;
277 QObject::connect(shellSurface, &XdgSurfaceV6Interface::destroyed, q, [
this, shellSurface] {
278 surfaces.removeAll(shellSurface);
281 shellSurface->d->create(display->getConnection(client), version,
id);
284 void XdgShellV6Interface::Private::createPositioner(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource)
288 XdgPositionerV6Interface *positioner =
new XdgPositionerV6Interface(q, parentResource);
289 positioners << positioner;
291 positioners.removeAll(positioner);
293 positioner->d->create(display->getConnection(client), version,
id);
296 void XdgShellV6Interface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial)
299 auto s = cast(resource);
300 auto timerIt = s->pingTimers.find(serial);
301 if (timerIt != s->pingTimers.end() && timerIt.value()->isActive()) {
302 delete timerIt.value();
303 s->pingTimers.erase(timerIt);
304 Q_EMIT s->q->pongReceived(serial);
308 XdgShellV6Interface::Private::Private(XdgShellV6Interface *q, Display *d)
314 void XdgShellV6Interface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
316 auto c = display->getConnection(client);
317 auto resource = c->createResource(&zxdg_shell_v6_interface, qMin(version, s_version),
id);
319 wl_client_post_no_memory(client);
322 resources[client] = resource;
323 wl_resource_set_implementation(resource, &s_interface,
this, unbind);
326 void XdgShellV6Interface::Private::unbind(wl_resource *resource)
328 auto s = cast(resource);
329 auto client = wl_resource_get_client(resource);
330 s->resources.remove(client);
333 XdgTopLevelV6Interface *XdgShellV6Interface::getSurface(wl_resource *resource)
340 for (
auto it = d->surfaces.constBegin(); it != d->surfaces.constEnd(); it++) {
341 auto topLevel = (*it)->topLevel();
342 if (topLevel && topLevel->resource() == resource) {
349 XdgSurfaceV6Interface *XdgShellV6Interface::realGetSurface(wl_resource *resource)
356 for (
auto it = d->surfaces.constBegin(); it != d->surfaces.constEnd(); it++) {
357 if ((*it)->resource() == resource) {
364 XdgPositionerV6Interface *XdgShellV6Interface::getPositioner(wl_resource *resource)
370 for (
auto it = d->positioners.constBegin(); it != d->positioners.constEnd(); it++) {
371 if ((*it)->resource() == resource) {
378 quint32 XdgShellV6Interface::Private::ping(XdgShellSurfaceInterface *surface)
380 auto client = surface->client()->client();
383 auto clientXdgShellResource = resources.value(client);
384 if (!clientXdgShellResource) {
388 const quint32 pingSerial = display->nextSerial();
389 zxdg_shell_v6_send_ping(clientXdgShellResource, pingSerial);
391 setupTimer(pingSerial);
395 XdgShellV6Interface::Private *XdgShellV6Interface::d_func()
const
397 return reinterpret_cast<Private *
>(d.data());
403 Qt::Edges edgesToQtEdges(zxdg_toplevel_v6_resize_edge edges)
407 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP:
410 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM:
413 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_LEFT:
416 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP_LEFT:
419 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM_LEFT:
422 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_RIGHT:
425 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP_RIGHT:
428 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM_RIGHT:
431 case ZXDG_TOPLEVEL_V6_RESIZE_EDGE_NONE:
442 const struct zxdg_surface_v6_interface XdgSurfaceV6Interface::Private::s_interface = {destroyCallback,
445 setWindowGeometryCallback,
446 ackConfigureCallback};
449 void XdgSurfaceV6Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
453 wl_resource_destroy(resource);
456 void XdgSurfaceV6Interface::Private::getTopLevelCallback(wl_client *client, wl_resource *resource, uint32_t
id)
458 auto s = cast<XdgSurfaceV6Interface::Private>(resource);
459 s->createTopLevel(client, wl_resource_get_version(resource),
id, resource);
462 void XdgSurfaceV6Interface::Private::createTopLevel(wl_client *client, uint32_t version, uint32_t
id, wl_resource *parentResource)
467 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_ROLE,
"Toplevel already created on this surface");
471 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_ROLE,
"Popup already created on this surface");
474 m_topLevel =
new XdgTopLevelV6Interface(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 XdgSurfaceV6Interface::Private::getPopupCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *parent, wl_resource *positioner)
482 auto s = cast<XdgSurfaceV6Interface::Private>(resource);
483 s->createPopup(client, wl_resource_get_version(resource),
id, resource, parent, positioner);
486 void XdgSurfaceV6Interface::Private::createPopup(wl_client *client,
489 wl_resource *parentResource,
490 wl_resource *parentSurface,
491 wl_resource *positioner)
496 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_ROLE,
"Toplevel already created on this surface");
500 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_ROLE,
"Popup already created on this surface");
504 auto xdgPositioner = m_shell->getPositioner(positioner);
505 if (!xdgPositioner) {
506 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
"Invalid positioner");
509 m_popup =
new XdgPopupV6Interface(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 pd->parent = parentXdgSurface->surface();
518 wl_resource_post_error(parentResource, ZXDG_SHELL_V6_ERROR_INVALID_POPUP_PARENT,
"Invalid popup parent");
522 pd->initialSize = xdgPositioner->initialSize();
523 pd->anchorRect = xdgPositioner->anchorRect();
524 pd->anchorEdge = xdgPositioner->anchorEdge();
525 pd->gravity = xdgPositioner->gravity();
526 pd->constraintAdjustments = xdgPositioner->constraintAdjustments();
527 pd->anchorOffset = xdgPositioner->anchorOffset();
529 Q_EMIT m_shell->xdgPopupCreated(m_popup.data());
532 void XdgSurfaceV6Interface::Private::ackConfigureCallback(wl_client *client, wl_resource *resource, uint32_t serial)
534 auto s = cast<Private>(resource);
535 Q_ASSERT(client == *s->client);
538 s->m_topLevel->d_func()->ackConfigure(serial);
539 }
else if (s->m_popup) {
540 s->m_popup->d_func()->ackConfigure(serial);
544 void XdgSurfaceV6Interface::Private::setWindowGeometryCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
546 auto s = cast<Private>(resource);
547 Q_ASSERT(client == *s->client);
549 if (width < 0 || height < 0) {
550 wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-surface geometry");
555 s->m_topLevel->d_func()->setWindowGeometryCallback(
QRect(x, y, width, height));
556 }
else if (s->m_popup) {
557 s->m_popup->d_func()->setWindowGeometryCallback(
QRect(x, y, width, height));
561 XdgSurfaceV6Interface::Private::Private(XdgSurfaceV6Interface *q, XdgShellV6Interface *c, SurfaceInterface *surface, wl_resource *parentResource)
562 : KWayland::Server::
Resource::Private(q, c, parentResource, &zxdg_surface_v6_interface, &s_interface)
568 XdgSurfaceV6Interface::Private::~Private() =
default;
570 class XdgPositionerV6Interface::Private :
public KWayland::Server::Resource::Private
573 Private(XdgPositionerV6Interface *q, XdgShellV6Interface *c, wl_resource *parentResource);
579 PositionerConstraints constraintAdjustments;
583 static void setSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height);
584 static void setAnchorRectCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
585 static void setAnchorCallback(wl_client *client, wl_resource *resource, uint32_t anchor);
586 static void setGravityCallback(wl_client *client, wl_resource *resource, uint32_t gravity);
587 static void setConstraintAdjustmentCallback(wl_client *client, wl_resource *resource, uint32_t constraint_adjustment);
588 static void setOffsetCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y);
590 static const struct zxdg_positioner_v6_interface s_interface;
593 XdgPositionerV6Interface::Private::Private(XdgPositionerV6Interface *q, XdgShellV6Interface *c, wl_resource *parentResource)
594 : KWayland::Server::
Resource::Private(q, c, parentResource, &zxdg_positioner_v6_interface, &s_interface)
599 const struct zxdg_positioner_v6_interface XdgPositionerV6Interface::Private::s_interface = {resourceDestroyedCallback,
601 setAnchorRectCallback,
604 setConstraintAdjustmentCallback,
608 void XdgPositionerV6Interface::Private::setSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
611 auto s = cast<Private>(resource);
612 s->initialSize =
QSize(width, height);
615 void XdgPositionerV6Interface::Private::setAnchorRectCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
618 auto s = cast<Private>(resource);
619 s->anchorRect =
QRect(x, y, width, height);
622 void XdgPositionerV6Interface::Private::setAnchorCallback(wl_client *client, wl_resource *resource, uint32_t anchor)
626 auto s = cast<Private>(resource);
628 if ((anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) && (anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) {
629 wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"Invalid arguments");
632 if ((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) && (anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) {
633 wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"Invalid arguments");
638 if (anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) {
641 if (anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) {
644 if (anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) {
647 if (anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) {
651 s->anchorEdge = edges;
654 void XdgPositionerV6Interface::Private::setGravityCallback(wl_client *client, wl_resource *resource, uint32_t gravity)
657 auto s = cast<Private>(resource);
658 if ((gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) && (gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) {
659 wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"Invalid arguments");
662 if ((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) && (gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) {
663 wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"Invalid arguments");
668 if (gravity & ZXDG_POSITIONER_V6_ANCHOR_LEFT) {
671 if (gravity & ZXDG_POSITIONER_V6_ANCHOR_TOP) {
674 if (gravity & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) {
677 if (gravity & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) {
684 void XdgPositionerV6Interface::Private::setConstraintAdjustmentCallback(wl_client *client, wl_resource *resource, uint32_t constraint_adjustment)
687 auto s = cast<Private>(resource);
688 PositionerConstraints constraints;
689 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X) {
692 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y) {
695 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X) {
698 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y) {
701 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X) {
704 if (constraint_adjustment & ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y) {
707 s->constraintAdjustments = constraints;
710 void XdgPositionerV6Interface::Private::setOffsetCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
713 auto s = cast<Private>(resource);
714 s->anchorOffset =
QPoint(x, y);
717 QRect XdgTopLevelV6Interface::Private::windowGeometry()
const
719 return m_currentState.windowGeometry;
722 QSize XdgTopLevelV6Interface::Private::minimumSize()
const
724 return m_currentState.minimumSize;
727 QSize XdgTopLevelV6Interface::Private::maximumSize()
const
729 return m_currentState.maximiumSize;
732 void XdgTopLevelV6Interface::Private::close()
734 zxdg_toplevel_v6_send_close(resource);
738 void XdgTopLevelV6Interface::Private::setMaxSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
740 if (width < 0 || height < 0) {
741 wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-toplevel maximum size");
750 auto s = cast<Private>(resource);
751 Q_ASSERT(client == *s->client);
752 s->m_pendingState.maximiumSize =
QSize(width, height);
753 s->m_pendingState.maximumSizeIsSet =
true;
756 void XdgTopLevelV6Interface::Private::setMinSizeCallback(wl_client *client, wl_resource *resource, int32_t width, int32_t height)
758 if (width < 0 || height < 0) {
759 wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE,
"Tried to set invalid xdg-toplevel minimum size");
762 auto s = cast<Private>(resource);
763 Q_ASSERT(client == *s->client);
764 s->m_pendingState.minimumSize =
QSize(width, height);
765 s->m_pendingState.minimumSizeIsSet =
true;
768 void XdgTopLevelV6Interface::Private::setWindowGeometryCallback(
const QRect &rect)
770 m_pendingState.windowGeometry = rect;
771 m_pendingState.windowGeometryIsSet =
true;
774 const struct zxdg_toplevel_v6_interface XdgTopLevelV6Interface::Private::s_interface = {destroyCallback,
778 showWindowMenuCallback,
780 resizeCallback<zxdg_toplevel_v6_resize_edge>,
783 setMaximizedCallback,
784 unsetMaximizedCallback,
785 setFullscreenCallback,
786 unsetFullscreenCallback,
787 setMinimizedCallback};
789 void XdgTopLevelV6Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
792 wl_resource_destroy(resource);
795 void XdgTopLevelV6Interface::Private::setParentCallback(wl_client *client, wl_resource *resource, wl_resource *parent)
797 auto s = cast<Private>(resource);
798 Q_ASSERT(client == *s->client);
802 Q_EMIT s->q_func()->transientForChanged();
804 auto parentSurface =
static_cast<XdgShellV6Interface *
>(s->q->global())->getSurface(parent);
805 if (s->parent.data() != parentSurface) {
807 Q_EMIT s->q_func()->transientForChanged();
812 void XdgTopLevelV6Interface::Private::showWindowMenuCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, int32_t x, int32_t y)
814 auto s = cast<Private>(resource);
815 Q_ASSERT(client == *s->client);
816 Q_EMIT s->q_func()->windowMenuRequested(SeatInterface::get(seat), serial,
QPoint(x, y));
819 XdgTopLevelV6Interface::Private::Private(XdgTopLevelV6Interface *q, XdgShellV6Interface *c, SurfaceInterface *surface, wl_resource *parentResource)
824 void XdgTopLevelV6Interface::Private::commit()
826 const bool windowGeometryChanged = m_pendingState.windowGeometryIsSet;
827 const bool minimumSizeChanged = m_pendingState.minimumSizeIsSet;
828 const bool maximumSizeChanged = m_pendingState.maximumSizeIsSet;
830 if (windowGeometryChanged) {
831 m_currentState.windowGeometry = m_pendingState.windowGeometry;
833 if (minimumSizeChanged) {
834 m_currentState.minimumSize = m_pendingState.minimumSize;
836 if (maximumSizeChanged) {
837 m_currentState.maximiumSize = m_pendingState.maximiumSize;
840 m_pendingState = ShellSurfaceState{};
842 if (windowGeometryChanged) {
843 Q_EMIT q_func()->windowGeometryChanged(m_currentState.windowGeometry);
845 if (minimumSizeChanged) {
846 Q_EMIT q_func()->minSizeChanged(m_currentState.minimumSize);
848 if (maximumSizeChanged) {
849 Q_EMIT q_func()->maxSizeChanged(m_currentState.maximiumSize);
853 void XdgTopLevelV6Interface::Private::setMaximizedCallback(wl_client *client, wl_resource *resource)
855 auto s = cast<Private>(resource);
856 Q_ASSERT(client == *s->client);
857 s->q_func()->maximizedChanged(
true);
860 void XdgTopLevelV6Interface::Private::unsetMaximizedCallback(wl_client *client, wl_resource *resource)
862 auto s = cast<Private>(resource);
863 Q_ASSERT(client == *s->client);
864 s->q_func()->maximizedChanged(
false);
867 void XdgTopLevelV6Interface::Private::setFullscreenCallback(wl_client *client, wl_resource *resource, wl_resource *output)
869 auto s = cast<Private>(resource);
870 Q_ASSERT(client == *s->client);
871 OutputInterface *o =
nullptr;
873 o = OutputInterface::get(output);
875 s->q_func()->fullscreenChanged(
true, o);
878 void XdgTopLevelV6Interface::Private::unsetFullscreenCallback(wl_client *client, wl_resource *resource)
880 auto s = cast<Private>(resource);
881 Q_ASSERT(client == *s->client);
882 s->q_func()->fullscreenChanged(
false,
nullptr);
885 void XdgTopLevelV6Interface::Private::setMinimizedCallback(wl_client *client, wl_resource *resource)
887 auto s = cast<Private>(resource);
888 Q_ASSERT(client == *s->client);
889 s->q_func()->minimizeRequested();
892 XdgTopLevelV6Interface::Private::~Private() =
default;
895 const struct zxdg_popup_v6_interface XdgPopupV6Interface::Private::s_interface = {resourceDestroyedCallback, grabCallback};
898 XdgPopupV6Interface::Private::Private(XdgPopupV6Interface *q, XdgShellV6Interface *c, SurfaceInterface *surface, wl_resource *parentResource)
903 void XdgPopupV6Interface::Private::grabCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial)
906 auto s = cast<Private>(resource);
907 auto seatInterface = SeatInterface::get(seat);
908 s->q_func()->grabRequested(seatInterface, serial);
911 XdgPopupV6Interface::Private::~Private() =
default;
913 QRect XdgPopupV6Interface::Private::windowGeometry()
const
915 return m_currentState.windowGeometry;
918 void XdgPopupV6Interface::Private::commit()
920 const bool windowGeometryChanged = m_pendingState.windowGeometryIsSet;
922 if (windowGeometryChanged) {
923 m_currentState.windowGeometry = m_pendingState.windowGeometry;
926 m_pendingState = ShellSurfaceState{};
928 if (windowGeometryChanged) {
929 Q_EMIT q_func()->windowGeometryChanged(m_currentState.windowGeometry);
933 void XdgPopupV6Interface::Private::setWindowGeometryCallback(
const QRect &rect)
935 m_pendingState.windowGeometry = rect;
936 m_pendingState.windowGeometryIsSet =
true;
939 quint32 XdgPopupV6Interface::Private::configure(
const QRect &rect)
944 const quint32 serial = global->display()->nextSerial();
945 configureSerials << serial;
946 zxdg_popup_v6_send_configure(resource, rect.
x(), rect.
y(), rect.
width(), rect.
height());
947 zxdg_surface_v6_send_configure(parentResource, serial);
953 void XdgPopupV6Interface::Private::popupDone()
959 zxdg_popup_v6_send_popup_done(resource);
963 XdgShellV6Interface::XdgShellV6Interface(Display *display,
QObject *parent)
964 : XdgShellInterface(new Private(this, display), parent)
968 Display *XdgShellV6Interface::display()
const
973 XdgShellV6Interface::~XdgShellV6Interface() =
default;
975 XdgSurfaceV6Interface::XdgSurfaceV6Interface(XdgShellV6Interface *parent, SurfaceInterface *surface, wl_resource *parentResource)
976 : KWayland::Server::
Resource(new Private(this, parent, surface, parentResource))
980 XdgSurfaceV6Interface::~XdgSurfaceV6Interface() =
default;
982 SurfaceInterface *XdgSurfaceV6Interface::surface()
const
988 XdgPositionerV6Interface::XdgPositionerV6Interface(XdgShellV6Interface *parent, wl_resource *parentResource)
989 : KWayland::Server::
Resource(new Private(this, parent, parentResource))
993 QSize XdgPositionerV6Interface::initialSize()
const
996 return d->initialSize;
999 QRect XdgPositionerV6Interface::anchorRect()
const
1002 return d->anchorRect;
1005 Qt::Edges XdgPositionerV6Interface::anchorEdge()
const
1008 return d->anchorEdge;
1011 Qt::Edges XdgPositionerV6Interface::gravity()
const
1017 PositionerConstraints XdgPositionerV6Interface::constraintAdjustments()
const
1020 return d->constraintAdjustments;
1023 QPoint XdgPositionerV6Interface::anchorOffset()
const
1026 return d->anchorOffset;
1029 XdgPositionerV6Interface::Private *XdgPositionerV6Interface::d_func()
const
1031 return reinterpret_cast<Private *
>(d.data());
1034 XdgTopLevelV6Interface *XdgSurfaceV6Interface::topLevel()
const
1037 return d->m_topLevel.data();
1040 XdgPopupV6Interface *XdgSurfaceV6Interface::popup()
const
1043 return d->m_popup.data();
1046 XdgSurfaceV6Interface::Private *XdgSurfaceV6Interface::d_func()
const
1048 return reinterpret_cast<Private *
>(d.data());
1051 XdgTopLevelV6Interface::XdgTopLevelV6Interface(XdgShellV6Interface *parent, SurfaceInterface *surface, wl_resource *parentResource)
1052 : KWayland::Server::XdgShellSurfaceInterface(new Private(this, parent, surface, parentResource))
1056 XdgTopLevelV6Interface::~XdgTopLevelV6Interface() =
default;
1058 XdgTopLevelV6Interface::Private *XdgTopLevelV6Interface::d_func()
const
1060 return reinterpret_cast<Private *
>(d.data());
1063 XdgPopupV6Interface::XdgPopupV6Interface(XdgShellV6Interface *parent, SurfaceInterface *surface, wl_resource *parentResource)
1064 : XdgShellPopupInterface(new Private(this, parent, surface, parentResource))
1068 XdgPopupV6Interface::~XdgPopupV6Interface() =
default;
1070 XdgPopupV6Interface::Private *XdgPopupV6Interface::d_func()
const
1072 return reinterpret_cast<Private *
>(d.data());