8#include <QtWaylandCompositor/QWaylandCompositor>
9#include <QtWaylandCompositor/QWaylandSurface>
11#include <QtWaylandCompositor/QWaylandResource>
13#if QT_CONFIG(wayland_compositor_quick)
14# include "qwaylandqtshellintegration_p.h"
17#include <QtWaylandCompositor/QWaylandResource>
19#include "compositor_api/qwaylandseat.h"
21#include <QtWaylandCompositor/private/qwaylandutils_p.h>
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53QWaylandQtShell::QWaylandQtShell()
54 : QWaylandCompositorExtensionTemplate<QWaylandQtShell>(*
new QWaylandQtShellPrivate())
58QWaylandQtShell::QWaylandQtShell(QWaylandCompositor *compositor)
59 : QWaylandCompositorExtensionTemplate<QWaylandQtShell>(compositor, *
new QWaylandQtShellPrivate())
63bool QWaylandQtShell::moveChromeToFront(QWaylandQtShellChrome *chrome)
66 for (
int i = 0; i < d->m_chromes.size(); ++i) {
67 if (d->m_chromes.at(i) == chrome) {
69 QWaylandQtShellChrome *currentActive = d->m_chromes.first();
70 d->m_chromes.move(i, 0);
72 currentActive->deactivate();
81void QWaylandQtShell::registerChrome(QWaylandQtShellChrome *chrome)
84 if (moveChromeToFront(chrome))
87 QWaylandQtShellChrome *currentActive = d->m_chromes.isEmpty() ?
nullptr : d->m_chromes.first();
89 d->m_chromes.prepend(chrome);
92 if (currentActive !=
nullptr)
93 currentActive->deactivate();
95 connect(chrome, &QWaylandQtShellChrome::activated,
this, &QWaylandQtShell::chromeActivated);
96 connect(chrome, &QWaylandQtShellChrome::deactivated,
this, &QWaylandQtShell::chromeDeactivated);
99void QWaylandQtShell::unregisterChrome(QWaylandQtShellChrome *chrome)
101 Q_D(QWaylandQtShell);
103 chrome->disconnect(
this);
104 int index = d->m_chromes.indexOf(chrome);
106 d->m_chromes.removeAt(index);
107 if (index == 0 && d->m_chromes.size() > 0)
108 d->m_chromes.at(0)->activate();
112void QWaylandQtShell::chromeActivated()
114 QWaylandQtShellChrome *c = qobject_cast<QWaylandQtShellChrome *>(sender());
116 moveChromeToFront(c);
120void QWaylandQtShell::chromeDeactivated()
122 Q_D(QWaylandQtShell);
123 QWaylandQtShellChrome *c = qobject_cast<QWaylandQtShellChrome *>(sender());
124 if (d->m_chromes.size() > 1 && d->m_chromes.at(0) == c) {
125 d->m_chromes.move(0, 1);
126 d->m_chromes.at(0)->activate();
127 }
else if (d->m_chromes.size() == 1) {
128 d->m_chromes.at(0)->activate();
132void QWaylandQtShell::initialize()
134 Q_D(QWaylandQtShell);
135 QWaylandCompositorExtensionTemplate::initialize();
137 QWaylandCompositor *compositor =
static_cast<QWaylandCompositor *>(extensionContainer());
139 qWarning() <<
"Failed to find QWaylandCompositor when initializing QWaylandQtShell";
143 d->init(compositor->display(), 1);
146const struct wl_interface *QWaylandQtShell::interface()
148 return QWaylandQtShellPrivate::interface();
152
153
154QByteArray QWaylandQtShell::interfaceName()
156 return QWaylandQtShellPrivate::interfaceName();
160
161
162
163
164
165
166
169
170
171
172
173
175QWaylandQtShellPrivate::QWaylandQtShellPrivate()
179void QWaylandQtShellPrivate::unregisterQtShellSurface(QWaylandQtShellSurface *qtShellSurface)
181 Q_UNUSED(qtShellSurface)
184void QWaylandQtShellPrivate::zqt_shell_v1_surface_create(QtWaylandServer::zqt_shell_v1::Resource *resource, wl_resource *surfaceResource, uint32_t id)
186 Q_Q(QWaylandQtShell);
187 QWaylandSurface *surface = QWaylandSurface::fromResource(surfaceResource);
189 if (!surface->setRole(QWaylandQtShellSurface::role(), resource->handle, ZQT_SHELL_V1_ERROR_ROLE))
192 QWaylandResource qtShellSurfaceResource(wl_resource_create(resource->client(), &zqt_shell_surface_v1_interface,
193 wl_resource_get_version(resource->handle), id));
195 emit q->qtShellSurfaceRequested(surface, qtShellSurfaceResource);
197 QWaylandQtShellSurface *qtShellSurface = QWaylandQtShellSurface::fromResource(qtShellSurfaceResource.resource());
200 qtShellSurface =
new QWaylandQtShellSurface(q, surface, qtShellSurfaceResource);
202 emit q->qtShellSurfaceCreated(qtShellSurface);
205QWaylandSurfaceRole QWaylandQtShellSurfacePrivate::s_role(
"qt_shell_surface");
208
209
210
211
212
213
214
215
216
217
218
219
220
221
224
225
226
227
228
229
230
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
250QWaylandQtShellSurface::QWaylandQtShellSurface()
251 : QWaylandShellSurfaceTemplate<QWaylandQtShellSurface>(*
new QWaylandQtShellSurfacePrivate())
255QWaylandQtShellSurface::QWaylandQtShellSurface(QWaylandQtShell *application, QWaylandSurface *surface,
const QWaylandResource &resource)
256 : QWaylandShellSurfaceTemplate<QWaylandQtShellSurface>(*
new QWaylandQtShellSurfacePrivate())
258 initialize(application, surface, resource);
262
263
264
265
266
267void QWaylandQtShellSurface::initialize(QWaylandQtShell *qtShell, QWaylandSurface *surface,
const QWaylandResource &resource)
269 Q_D(QWaylandQtShellSurface);
271 d->m_qtShell = qtShell;
272 d->m_surface = surface;
274 connect(d->m_surface, &QWaylandSurface::damaged,
this, &QWaylandQtShellSurface::surfaceCommitted);
276 d->init(resource.resource());
277 setExtensionContainer(surface);
279 emit surfaceChanged();
281 QWaylandCompositorExtension::initialize();
285
286
287
288
289QWaylandSurface *QWaylandQtShellSurface::surface()
const
291 Q_D(
const QWaylandQtShellSurface);
295QWaylandQtShell *QWaylandQtShellSurface::shell()
const
297 Q_D(
const QWaylandQtShellSurface);
302
303
304
305
306QPoint QWaylandQtShellSurface::windowPosition()
const
308 Q_D(
const QWaylandQtShellSurface);
309 return d->m_windowGeometry.topLeft();
312void QWaylandQtShellSurface::setWindowPosition(
const QPoint &position)
314 Q_D(QWaylandQtShellSurface);
317 d->send_set_position(UINT32_MAX, position.x(), position.y());
318 d->send_configure(UINT32_MAX);
320 d->m_windowGeometry.moveTopLeft(position);
321 d->m_positionSet =
true;
322 emit positionAutomaticChanged();
323 emit windowGeometryChanged();
327
328
329
330
331QRect QWaylandQtShellSurface::windowGeometry()
const
333 Q_D(
const QWaylandQtShellSurface);
334 return d->m_windowGeometry;
338
339
340
341
342QSize QWaylandQtShellSurface::minimumSize()
const
344 Q_D(
const QWaylandQtShellSurface);
345 return d->m_minimumSize;
349
350
351
352
353QSize QWaylandQtShellSurface::maximumSize()
const
355 Q_D(
const QWaylandQtShellSurface);
356 return d->m_maximumSize;
360
361
362
363
364
365
366void QWaylandQtShellSurface::requestWindowGeometry(uint windowState,
const QRect &windowGeometry)
368 Q_D(QWaylandQtShellSurface);
369 if (!windowGeometry.isValid())
372 d->configure(windowState, windowGeometry);
375void QWaylandQtShellSurfacePrivate::configure(uint windowState,
const QRect &newGeometry)
377 QWaylandCompositor *compositor = m_surface !=
nullptr ? m_surface->compositor() :
nullptr;
379 qWarning() <<
"Failed to find QWaylandCompositor when configuring QWaylandQtShell";
383 uint32_t serial = compositor->nextSerial();
384 m_pendingConfigures[serial] = qMakePair(windowState, newGeometry);
386 send_set_position(serial, newGeometry.x(), newGeometry.y());
387 send_resize(serial, newGeometry.width(), newGeometry.height());
388 send_set_window_state(serial, windowState & ~Qt::WindowActive);
389 send_configure(serial);
392void QWaylandQtShellSurface::setFrameMargins(
const QMargins &margins)
394 Q_D(QWaylandQtShellSurface);
395 if (d->m_frameMargins == margins)
398 d->m_frameMargins = margins;
399 d->updateFrameMargins();
401 emit frameMarginChanged();
405
406
407
408
409void QWaylandQtShellSurface::setFrameMarginLeft(
int left)
411 Q_D(QWaylandQtShellSurface);
412 if (d->m_frameMargins.left() == left)
415 d->m_frameMargins.setLeft(left);
416 d->updateFrameMargins();
418 emit frameMarginChanged();
421int QWaylandQtShellSurface::frameMarginLeft()
const
423 Q_D(
const QWaylandQtShellSurface);
424 return d->m_frameMargins.left();
428
429
430
431
432void QWaylandQtShellSurface::setFrameMarginRight(
int right)
434 Q_D(QWaylandQtShellSurface);
435 if (d->m_frameMargins.right() == right)
438 d->m_frameMargins.setRight(right);
439 d->updateFrameMargins();
441 emit frameMarginChanged();
444int QWaylandQtShellSurface::frameMarginRight()
const
446 Q_D(
const QWaylandQtShellSurface);
447 return d->m_frameMargins.right();
451
452
453
454
456void QWaylandQtShellSurface::setFrameMarginTop(
int top)
458 Q_D(QWaylandQtShellSurface);
459 if (d->m_frameMargins.top() == top)
461 d->m_frameMargins.setTop(top);
462 d->updateFrameMargins();
464 emit frameMarginChanged();
467int QWaylandQtShellSurface::frameMarginTop()
const
469 Q_D(
const QWaylandQtShellSurface);
470 return d->m_frameMargins.top();
474
475
476
477
478void QWaylandQtShellSurface::setFrameMarginBottom(
int bottom)
480 Q_D(QWaylandQtShellSurface);
481 if (d->m_frameMargins.bottom() == bottom)
483 d->m_frameMargins.setBottom(bottom);
484 d->updateFrameMargins();
486 emit frameMarginChanged();
489bool QWaylandQtShellSurface::positionAutomatic()
const
491 Q_D(
const QWaylandQtShellSurface);
492 return !d->m_positionSet;
495int QWaylandQtShellSurface::frameMarginBottom()
const
497 Q_D(
const QWaylandQtShellSurface);
498 return d->m_frameMargins.bottom();
502
503
504
505
506uint QWaylandQtShellSurface::windowFlags()
const
508 Q_D(
const QWaylandQtShellSurface);
509 return d->m_windowFlags;
513
514
515
516
517void QWaylandQtShellSurface::sendClose()
519 Q_D(QWaylandQtShellSurface);
524
525
526
527
528QString QWaylandQtShellSurface::windowTitle()
const
530 Q_D(
const QWaylandQtShellSurface);
531 return d->m_windowTitle;
535
536
537
538
539
540
541
542
543void QWaylandQtShellSurface::setActive(
bool active)
545 Q_D(QWaylandQtShellSurface);
546 if (d->m_active == active)
549 d->m_active = active;
550 QWaylandCompositor *compositor = d->m_surface ? d->m_surface->compositor() :
nullptr;
551 QWaylandSeat *seat = compositor ? compositor->defaultSeat() :
nullptr;
553 seat->setKeyboardFocus(surface());
554 emit activeChanged();
557bool QWaylandQtShellSurface::active()
const
559 Q_D(
const QWaylandQtShellSurface);
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578void QWaylandQtShellSurface::setCapabilities(CapabilityFlags capabilities)
580 Q_D(QWaylandQtShellSurface);
581 if (d->m_capabilities == capabilities)
584 d->m_capabilities = capabilities;
585 d->send_set_capabilities(capabilities);
587 emit capabilitiesChanged();
590QWaylandQtShellSurface::CapabilityFlags QWaylandQtShellSurface::capabilities()
const
592 Q_D(
const QWaylandQtShellSurface);
593 return d->m_capabilities;
597
598
599
600
601
602
603
604uint QWaylandQtShellSurface::windowState()
const
606 Q_D(
const QWaylandQtShellSurface);
607 return d->m_windowState;
610void QWaylandQtShellSurface::surfaceCommitted()
612 Q_D(QWaylandQtShellSurface);
613 if (d->m_lastAckedConfigure < UINT32_MAX) {
614 QRect targetRect = d->m_windowGeometry;
615 uint windowState = d->m_windowState;
616 for (
auto it = d->m_pendingConfigures.begin(); it != d->m_pendingConfigures.end(); ) {
617 if (it.key() == d->m_lastAckedConfigure) {
618 targetRect = it.value().second;
619 windowState = it.value().first;
622 if (it.key() <= d->m_lastAckedConfigure)
623 it = d->m_pendingConfigures.erase(it);
628 if (d->m_windowState != windowState) {
629 d->m_windowState = windowState;
630 emit windowStateChanged();
633 if (d->m_windowGeometry != targetRect) {
634 d->m_windowGeometry = targetRect;
635 d->m_positionSet =
true;
636 emit positionAutomaticChanged();
637 emit windowGeometryChanged();
640 d->m_lastAckedConfigure = UINT32_MAX;
641 d->m_pendingPosition = QPoint{};
642 d->m_pendingPositionValid =
false;
643 d->m_pendingSize = QSize{};
645 QRect oldRect = d->m_windowGeometry;
646 if (d->m_pendingPositionValid) {
647 d->m_windowGeometry.moveTopLeft(d->m_pendingPosition);
648 d->m_pendingPosition = QPoint{};
649 d->m_pendingPositionValid =
false;
650 d->m_positionSet =
true;
651 emit positionAutomaticChanged();
654 if (d->m_pendingSize.isValid()) {
655 d->m_windowGeometry.setSize(d->m_pendingSize);
656 d->m_pendingSize = QSize{};
659 if (d->m_windowGeometry != oldRect)
660 emit windowGeometryChanged();
665
666
667
668const wl_interface *QWaylandQtShellSurface::interface()
670 return QWaylandQtShellSurfacePrivate::interface();
673QByteArray QWaylandQtShellSurface::interfaceName()
675 return QWaylandQtShellSurfacePrivate::interfaceName();
679
680
681
682QWaylandSurfaceRole *QWaylandQtShellSurface::role()
684 return &QWaylandQtShellSurfacePrivate::s_role;
688
689
690
691QWaylandQtShellSurface *QWaylandQtShellSurface::fromResource(wl_resource *resource)
693 if (
auto p = QtWayland::fromResource<QWaylandQtShellSurfacePrivate *>(resource))
698#if QT_CONFIG(wayland_compositor_quick)
699QWaylandQuickShellIntegration *QWaylandQtShellSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
701 return new QtWayland::QtShellIntegration(item);
706
707
708void QWaylandQtShellSurface::initialize()
710 QWaylandShellSurfaceTemplate::initialize();
713QWaylandQtShellSurfacePrivate::QWaylandQtShellSurfacePrivate()
717void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_ack_configure(Resource *resource, uint32_t serial)
720 Q_Q(QWaylandQtShellSurface);
721 if (serial < UINT32_MAX)
722 m_lastAckedConfigure = serial;
725 if (m_windowState & Qt::WindowMinimized)
726 q->surfaceCommitted();
729void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_reposition(Resource *resource, int32_t x, int32_t y)
733 m_pendingPosition = QPoint(x, y);
734 m_pendingPositionValid =
true;
735 m_lastAckedConfigure = UINT32_MAX;
738void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_set_size(Resource *resource, int32_t width, int32_t height)
742 m_pendingSize = QSize(width, height);
743 m_lastAckedConfigure = UINT32_MAX;
746void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_set_minimum_size(Resource *resource, int32_t width, int32_t height)
749 Q_Q(QWaylandQtShellSurface);
750 m_minimumSize = QSize{width, height};
751 emit q->minimumSizeChanged();
754void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_set_maximum_size(Resource *resource, int32_t width, int32_t height)
757 Q_Q(QWaylandQtShellSurface);
758 m_maximumSize = QSize{width, height};
759 emit q->maximumSizeChanged();
762void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_destroy_resource(QtWaylandServer::zqt_shell_surface_v1::Resource *resource)
765 Q_Q(QWaylandQtShellSurface);
766 QWaylandQtShellPrivate::get(m_qtShell)->unregisterQtShellSurface(q);
770void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_destroy(QtWaylandServer::zqt_shell_surface_v1::Resource *resource)
772 wl_resource_destroy(resource->handle);
775void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_set_window_flags(Resource *resource, uint32_t flags)
778 Q_Q(QWaylandQtShellSurface);
779 m_windowFlags = flags;
780 emit q->windowFlagsChanged();
783void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_change_window_state(Resource *resource, uint32_t state)
786 Q_Q(QWaylandQtShellSurface);
787 uint oldWindowState = m_windowState;
788 m_windowState = state & ~Qt::WindowActive;
790 if (oldWindowState != m_windowState)
791 emit q->windowStateChanged();
794void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_start_system_resize(Resource *resource, uint32_t serial, uint32_t edge)
798 Q_Q(QWaylandQtShellSurface);
799 emit q->startResize(Qt::Edges(edge));
802void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_start_system_move(Resource *resource, uint32_t serial)
806 Q_Q(QWaylandQtShellSurface);
810void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_set_window_title(Resource *resource,
811 const QString &title)
814 Q_Q(QWaylandQtShellSurface);
815 m_windowTitle = title;
816 emit q->windowTitleChanged();
819void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_request_activate(Resource *resource)
823 Q_Q(QWaylandQtShellSurface);
827 auto view = m_surface->primaryView();
828 auto item = view ? qobject_cast<QWaylandQuickItem *>(view->renderObject()) :
nullptr;
830 item->forceActiveFocus();
834void QWaylandQtShellSurfacePrivate::updateFrameMargins()
836 send_set_frame_margins(m_frameMargins.left(), m_frameMargins.right(),
837 m_frameMargins.top(), m_frameMargins.bottom());
841void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_raise(Resource *resource)
844 Q_Q(QWaylandQtShellSurface);
845 emit q->raiseRequested();
848void QWaylandQtShellSurfacePrivate::zqt_shell_surface_v1_lower(Resource *resource)
851 Q_Q(QWaylandQtShellSurface);
852 emit q->lowerRequested();
857#include "moc_qwaylandqtshell_p.cpp"