-
Notifications
You must be signed in to change notification settings - Fork 83
/
qwaylandxdgshell.cpp
2108 lines (1813 loc) · 65.5 KB
/
qwaylandxdgshell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qwaylandxdgshell.h"
#include "qwaylandxdgshell_p.h"
#if QT_CONFIG(wayland_compositor_quick)
#include "qwaylandxdgshellintegration_p.h"
#endif
#include <QtWaylandCompositor/private/qwaylandutils_p.h>
#include <QtWaylandCompositor/QWaylandCompositor>
#include <QtWaylandCompositor/QWaylandSeat>
#include <QtWaylandCompositor/QWaylandSurface>
#include <QtWaylandCompositor/QWaylandSurfaceRole>
#include <QtWaylandCompositor/QWaylandResource>
#include <QtCore/QObject>
#include <algorithm>
QT_BEGIN_NAMESPACE
QWaylandXdgShellPrivate::QWaylandXdgShellPrivate()
{
}
void QWaylandXdgShellPrivate::ping(QtWaylandServer::xdg_wm_base::Resource *resource, uint32_t serial)
{
m_pings.insert(serial);
send_ping(resource->handle, serial);
}
void QWaylandXdgShellPrivate::registerXdgSurface(QWaylandXdgSurface *xdgSurface)
{
m_xdgSurfaces.insert(xdgSurface->surface()->client()->client(), xdgSurface);
}
void QWaylandXdgShellPrivate::unregisterXdgSurface(QWaylandXdgSurface *xdgSurface)
{
auto xdgSurfacePrivate = QWaylandXdgSurfacePrivate::get(xdgSurface);
if (!m_xdgSurfaces.remove(xdgSurfacePrivate->resource()->client(), xdgSurface))
qWarning("%s Unexpected state. Can't find registered xdg surface\n", Q_FUNC_INFO);
}
QWaylandXdgSurface *QWaylandXdgShellPrivate::xdgSurfaceFromSurface(QWaylandSurface *surface)
{
for (QWaylandXdgSurface *xdgSurface : qAsConst(m_xdgSurfaces)) {
if (surface == xdgSurface->surface())
return xdgSurface;
}
return nullptr;
}
void QWaylandXdgShellPrivate::xdg_wm_base_destroy(Resource *resource)
{
if (!m_xdgSurfaces.values(resource->client()).empty())
wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_DEFUNCT_SURFACES,
"xdg_shell was destroyed before children");
wl_resource_destroy(resource->handle);
}
void QWaylandXdgShellPrivate::xdg_wm_base_create_positioner(QtWaylandServer::xdg_wm_base::Resource *resource, uint32_t id)
{
QWaylandResource positionerResource(wl_resource_create(resource->client(), &xdg_positioner_interface,
wl_resource_get_version(resource->handle), id));
new QWaylandXdgPositioner(positionerResource);
}
void QWaylandXdgShellPrivate::xdg_wm_base_get_xdg_surface(Resource *resource, uint32_t id, wl_resource *surfaceResource)
{
Q_Q(QWaylandXdgShell);
QWaylandSurface *surface = QWaylandSurface::fromResource(surfaceResource);
if (surface->role() != nullptr) {
wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_ROLE,
"wl_surface@%d, already has role %s\n",
wl_resource_get_id(surface->resource()),
surface->role()->name().constData());
return;
}
if (surface->hasContent()) {
//TODO: According to the spec, this is a client error, but there's no appropriate error code
qWarning() << "get_xdg_surface requested on a xdg_surface with content";
}
QWaylandResource xdgSurfaceResource(wl_resource_create(resource->client(), &xdg_surface_interface,
wl_resource_get_version(resource->handle), id));
QWaylandXdgSurface *xdgSurface = new QWaylandXdgSurface(q, surface, xdgSurfaceResource);
registerXdgSurface(xdgSurface);
emit q->xdgSurfaceCreated(xdgSurface);
}
void QWaylandXdgShellPrivate::xdg_wm_base_pong(Resource *resource, uint32_t serial)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgShell);
if (m_pings.remove(serial))
emit q->pong(serial);
else
qWarning("Received an unexpected pong!");
}
/*!
* \qmltype XdgShell
* \instantiates QWaylandXdgShell
* \inqmlmodule QtWayland.Compositor.XdgShell
* \since 5.12
* \brief Provides an extension for desktop-style user interfaces.
*
* The XdgShell extension provides a way to associate a XdgToplevel or XdgPopup
* with a regular Wayland surface. Using the XdgToplevel interface, the client
* can request that the surface is resized, moved, and so on.
*
* XdgShell corresponds to the Wayland interface, \c xdg_shell.
*
* To provide the functionality of the shell extension in a compositor, create
* an instance of the XdgShell component and add it to the list of extensions
* supported by the compositor:
*
* \qml
* import QtWayland.Compositor.XdgShell
*
* WaylandCompositor {
* XdgShell {
* // ...
* }
* }
* \endqml
*/
/*!
* \class QWaylandXdgShell
* \inmodule QtWaylandCompositor
* \since 5.12
* \brief The QWaylandXdgShell class is an extension for desktop-style user interfaces.
*
* The QWaylandXdgShell extension provides a way to associate a QWaylandXdgToplevel or
* QWaylandXdgPopup with a regular Wayland surface. Using the QWaylandXdgToplevel interface,
* the client can request that the surface is resized, moved, and so on.
*
* QWaylandXdgShell corresponds to the Wayland interface, \c xdg_shell.
*/
/*!
* Constructs a QWaylandXdgShell object.
*/
QWaylandXdgShell::QWaylandXdgShell()
: QWaylandShellTemplate<QWaylandXdgShell>(*new QWaylandXdgShellPrivate())
{
}
/*!
* Constructs a QWaylandXdgShell object for the provided \a compositor.
*/
QWaylandXdgShell::QWaylandXdgShell(QWaylandCompositor *compositor)
: QWaylandShellTemplate<QWaylandXdgShell>(compositor, *new QWaylandXdgShellPrivate())
{
}
/*!
* Initializes the shell extension.
*/
void QWaylandXdgShell::initialize()
{
Q_D(QWaylandXdgShell);
QWaylandShellTemplate::initialize();
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
if (!compositor) {
qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandXdgShell";
return;
}
d->init(compositor->display(), 1);
handleSeatChanged(compositor->defaultSeat(), nullptr);
connect(compositor, &QWaylandCompositor::defaultSeatChanged,
this, &QWaylandXdgShell::handleSeatChanged);
}
/*!
* Returns the Wayland interface for the QWaylandXdgShell.
*/
const struct wl_interface *QWaylandXdgShell::interface()
{
return QWaylandXdgShellPrivate::interface();
}
QByteArray QWaylandXdgShell::interfaceName()
{
return QWaylandXdgShellPrivate::interfaceName();
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgShell::ping(WaylandClient client)
*
* Sends a ping event to \a client. If the client replies to the event the
* \l pong signal will be emitted.
*/
/*!
* Sends a ping event to \a client. If the client replies to the event the
* \l pong signal will be emitted.
*/
uint QWaylandXdgShell::ping(QWaylandClient *client)
{
Q_D(QWaylandXdgShell);
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
Q_ASSERT(compositor);
uint32_t serial = compositor->nextSerial();
QWaylandXdgShellPrivate::Resource *clientResource = d->resourceMap().value(client->client(), nullptr);
Q_ASSERT(clientResource);
d->ping(clientResource, serial);
return serial;
}
void QWaylandXdgShell::handleSeatChanged(QWaylandSeat *newSeat, QWaylandSeat *oldSeat)
{
if (oldSeat != nullptr) {
disconnect(oldSeat, &QWaylandSeat::keyboardFocusChanged,
this, &QWaylandXdgShell::handleFocusChanged);
}
if (newSeat != nullptr) {
connect(newSeat, &QWaylandSeat::keyboardFocusChanged,
this, &QWaylandXdgShell::handleFocusChanged);
}
}
void QWaylandXdgShell::handleFocusChanged(QWaylandSurface *newSurface, QWaylandSurface *oldSurface)
{
Q_D(QWaylandXdgShell);
QWaylandXdgSurface *newXdgSurface = d->xdgSurfaceFromSurface(newSurface);
QWaylandXdgSurface *oldXdgSurface = d->xdgSurfaceFromSurface(oldSurface);
if (newXdgSurface)
QWaylandXdgSurfacePrivate::get(newXdgSurface)->handleFocusReceived();
if (oldXdgSurface)
QWaylandXdgSurfacePrivate::get(oldXdgSurface)->handleFocusLost();
}
QWaylandXdgSurfacePrivate::QWaylandXdgSurfacePrivate()
{
}
void QWaylandXdgSurfacePrivate::setWindowType(Qt::WindowType windowType)
{
if (m_windowType == windowType)
return;
m_windowType = windowType;
Q_Q(QWaylandXdgSurface);
emit q->windowTypeChanged();
}
void QWaylandXdgSurfacePrivate::handleFocusLost()
{
if (m_toplevel)
QWaylandXdgToplevelPrivate::get(m_toplevel)->handleFocusLost();
}
void QWaylandXdgSurfacePrivate::handleFocusReceived()
{
if (m_toplevel)
QWaylandXdgToplevelPrivate::get(m_toplevel)->handleFocusReceived();
}
QRect QWaylandXdgSurfacePrivate::calculateFallbackWindowGeometry() const
{
// TODO: The unset window geometry should include subsurfaces as well, so this solution
// won't work too well on those kinds of clients.
return QRect(QPoint(), m_surface->destinationSize());
}
void QWaylandXdgSurfacePrivate::updateFallbackWindowGeometry()
{
Q_Q(QWaylandXdgSurface);
if (!m_unsetWindowGeometry)
return;
const QRect unsetGeometry = calculateFallbackWindowGeometry();
if (unsetGeometry == m_windowGeometry)
return;
m_windowGeometry = unsetGeometry;
emit q->windowGeometryChanged();
}
void QWaylandXdgSurfacePrivate::xdg_surface_destroy_resource(QtWaylandServer::xdg_surface::Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurface);
QWaylandXdgShellPrivate::get(m_xdgShell)->unregisterXdgSurface(q);
delete q;
}
void QWaylandXdgSurfacePrivate::xdg_surface_destroy(QtWaylandServer::xdg_surface::Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void QWaylandXdgSurfacePrivate::xdg_surface_get_toplevel(QtWaylandServer::xdg_surface::Resource *resource, uint32_t id)
{
Q_Q(QWaylandXdgSurface);
if (m_toplevel || m_popup) {
wl_resource_post_error(resource->handle, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"xdg_surface already has a role object");
return;
}
if (!m_surface->setRole(QWaylandXdgToplevel::role(), resource->handle, XDG_WM_BASE_ERROR_ROLE))
return;
QWaylandResource topLevelResource(wl_resource_create(resource->client(), &xdg_toplevel_interface,
wl_resource_get_version(resource->handle), id));
m_toplevel = new QWaylandXdgToplevel(q, topLevelResource);
emit q->toplevelCreated();
emit m_xdgShell->toplevelCreated(m_toplevel, q);
}
void QWaylandXdgSurfacePrivate::xdg_surface_get_popup(QtWaylandServer::xdg_surface::Resource *resource, uint32_t id, wl_resource *parentResource, wl_resource *positionerResource)
{
Q_Q(QWaylandXdgSurface);
if (m_toplevel || m_popup) {
wl_resource_post_error(resource->handle, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED,
"xdg_surface already has a role object");
return;
}
QWaylandXdgSurface *parent = QWaylandXdgSurface::fromResource(parentResource);
if (!parent) {
wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT,
"xdg_surface.get_popup with invalid popup parent");
return;
}
QWaylandXdgPositioner *positioner = QWaylandXdgPositioner::fromResource(positionerResource);
if (!positioner) {
wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_INVALID_POSITIONER,
"xdg_surface.get_popup without positioner");
return;
}
if (!positioner->m_data.isComplete()) {
QWaylandXdgPositionerData p = positioner->m_data;
wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_INVALID_POSITIONER,
"xdg_surface.get_popup with invalid positioner (size: %dx%d, anchorRect: %dx%d)",
p.size.width(), p.size.height(), p.anchorRect.width(), p.anchorRect.height());
return;
}
QRect anchorBounds(QPoint(0, 0), parent->windowGeometry().size());
if (!anchorBounds.contains(positioner->m_data.anchorRect)) {
// TODO: this is a protocol error and should ideally be handled like this:
//wl_resource_post_error(resource->handle, XDG_WM_BASE_ERROR_INVALID_POSITIONER,
// "xdg_positioner anchor rect extends beyound its parent's window geometry");
//return;
// However, our own clients currently do this, so we'll settle for a gentle warning instead.
qCWarning(qLcWaylandCompositor) << "Ignoring client protocol error: xdg_positioner anchor"
<< "rect extends beyond its parent's window geometry";
}
if (!m_surface->setRole(QWaylandXdgPopup::role(), resource->handle, XDG_WM_BASE_ERROR_ROLE))
return;
QWaylandResource popupResource(wl_resource_create(resource->client(), &xdg_popup_interface,
wl_resource_get_version(resource->handle), id));
m_popup = new QWaylandXdgPopup(q, parent, positioner, popupResource);
emit q->popupCreated();
emit m_xdgShell->popupCreated(m_popup, q);
}
void QWaylandXdgSurfacePrivate::xdg_surface_ack_configure(QtWaylandServer::xdg_surface::Resource *resource, uint32_t serial)
{
if (m_toplevel) {
QWaylandXdgToplevelPrivate::get(m_toplevel)->handleAckConfigure(serial);
} else if (m_popup) {
QWaylandXdgPopupPrivate::get(m_popup)->handleAckConfigure(serial);
} else {
wl_resource_post_error(resource->handle, XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
"ack_configure requested on an unconstructed xdg_surface");
}
}
void QWaylandXdgSurfacePrivate::xdg_surface_set_window_geometry(QtWaylandServer::xdg_surface::Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
{
Q_Q(QWaylandXdgSurface);
if (!q->surface()->role()) {
wl_resource_post_error(resource->handle, XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
"set_window_geometry requested on an unconstructed xdg_surface");
return;
}
if (width <= 0 || height <= 0) {
// The protocol spec says "setting an invalid size will raise an error". But doesn't tell
// which error to raise, and there's no fitting error in the xdg_surface_error enum.
// So until this is fixed, just output a warning and return.
qWarning() << "Invalid (non-positive) dimensions received in set_window_geometry";
return;
}
m_unsetWindowGeometry = false;
QRect geometry(x, y, width, height);
if (m_windowGeometry == geometry)
return;
m_windowGeometry = geometry;
emit q->windowGeometryChanged();
}
/*!
* \qmltype XdgSurface
* \instantiates QWaylandXdgSurface
* \inqmlmodule QtWayland.Compositor.XdgShell
* \since 5.12
* \brief XdgSurface provides desktop-style compositor-specific features to an xdg surface.
*
* This type is part of the \l{XdgShell} extension and provides a way to
* extend the functionality of an existing \l{WaylandSurface} with features
* specific to desktop-style compositors, such as resizing and moving the
* surface.
*
* It corresponds to the Wayland interface \c xdg_surface.
*/
/*!
* \class QWaylandXdgSurface
* \inmodule QtWaylandCompositor
* \since 5.12
* \brief The QWaylandXdgSurface class provides desktop-style compositor-specific features to an xdg surface.
*
* This class is part of the QWaylandXdgShell extension and provides a way to
* extend the functionality of an existing QWaylandSurface with features
* specific to desktop-style compositors, such as resizing and moving the
* surface.
*
* It corresponds to the Wayland interface \c xdg_surface.
*/
/*!
* Constructs a QWaylandXdgSurface.
*/
QWaylandXdgSurface::QWaylandXdgSurface()
: QWaylandShellSurfaceTemplate<QWaylandXdgSurface>(*new QWaylandXdgSurfacePrivate)
{
}
/*!
* Constructs a QWaylandXdgSurface for \a surface and initializes it with the
* given \a xdgShell, \a surface, and resource \a res.
*/
QWaylandXdgSurface::QWaylandXdgSurface(QWaylandXdgShell *xdgShell, QWaylandSurface *surface, const QWaylandResource &res)
: QWaylandShellSurfaceTemplate<QWaylandXdgSurface>(*new QWaylandXdgSurfacePrivate)
{
initialize(xdgShell, surface, res);
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgSurface::initialize(object xdgShell, object surface, object client, int id)
*
* Initializes the XdgSurface, associating it with the given \a xdgShell, \a surface,
* \a client, and \a id.
*/
/*!
* Initializes the QWaylandXdgSurface, associating it with the given \a xdgShell, \a surface
* and \a resource.
*/
void QWaylandXdgSurface::initialize(QWaylandXdgShell *xdgShell, QWaylandSurface *surface, const QWaylandResource &resource)
{
Q_D(QWaylandXdgSurface);
d->m_xdgShell = xdgShell;
d->m_surface = surface;
d->init(resource.resource());
setExtensionContainer(surface);
d->m_windowGeometry = d->calculateFallbackWindowGeometry();
connect(surface, &QWaylandSurface::destinationSizeChanged, this, &QWaylandXdgSurface::handleSurfaceSizeChanged);
connect(surface, &QWaylandSurface::bufferScaleChanged, this, &QWaylandXdgSurface::handleBufferScaleChanged);
emit shellChanged();
emit surfaceChanged();
QWaylandCompositorExtension::initialize();
}
/*!
* \qmlproperty enum QtWaylandCompositor::XdgSurface::windowType
*
* This property holds the window type of the XdgSurface.
*/
Qt::WindowType QWaylandXdgSurface::windowType() const
{
Q_D(const QWaylandXdgSurface);
return d->m_windowType;
}
/*!
* \qmlproperty rect QtWaylandCompositor::XdgSurface::windowGeometry
*
* This property holds the window geometry of the QWaylandXdgSurface. The window
* geometry describes the window's visible bounds from the user's perspective.
* The geometry includes title bars and borders if drawn by the client, but
* excludes drop shadows. It is meant to be used for aligning and tiling
* windows.
*/
/*!
* \property QWaylandXdgSurface::windowGeometry
*
* This property holds the window geometry of the QWaylandXdgSurface. The window
* geometry describes the window's visible bounds from the user's perspective.
* The geometry includes title bars and borders if drawn by the client, but
* excludes drop shadows. It is meant to be used for aligning and tiling
* windows.
*/
QRect QWaylandXdgSurface::windowGeometry() const
{
Q_D(const QWaylandXdgSurface);
return d->m_windowGeometry;
}
/*!
* \internal
*/
void QWaylandXdgSurface::initialize()
{
QWaylandCompositorExtension::initialize();
}
void QWaylandXdgSurface::handleSurfaceSizeChanged()
{
Q_D(QWaylandXdgSurface);
d->updateFallbackWindowGeometry();
}
void QWaylandXdgSurface::handleBufferScaleChanged()
{
Q_D(QWaylandXdgSurface);
d->updateFallbackWindowGeometry();
}
/*!
* \qmlproperty XdgShell QtWaylandCompositor::XdgSurface::shell
*
* This property holds the shell associated with this XdgSurface.
*/
/*!
* \property QWaylandXdgSurface::shell
*
* This property holds the shell associated with this QWaylandXdgSurface.
*/
QWaylandXdgShell *QWaylandXdgSurface::shell() const
{
Q_D(const QWaylandXdgSurface);
return d->m_xdgShell;
}
/*!
* \qmlproperty WaylandSurface QtWaylandCompositor::XdgSurface::surface
*
* This property holds the surface associated with this XdgSurface.
*/
/*!
* \property QWaylandXdgSurface::surface
*
* This property holds the surface associated with this QWaylandXdgSurface.
*/
QWaylandSurface *QWaylandXdgSurface::surface() const
{
Q_D(const QWaylandXdgSurface);
return d->m_surface;
}
/*!
* \qmlproperty XdgToplevel QtWaylandCompositor::XdgSurface::toplevel
*
* This property holds the properties and methods that are specific to the
* toplevel XdgSurface.
*
* \sa popup, XdgShell::toplevelCreated
*/
/*!
* \property QWaylandXdgSurface::toplevel
*
* This property holds the properties and methods that are specific to the
* toplevel QWaylandXdgSurface.
*
* \sa QWaylandXdgSurface::popup, QWaylandXdgShell::toplevelCreated
*/
QWaylandXdgToplevel *QWaylandXdgSurface::toplevel() const
{
Q_D(const QWaylandXdgSurface);
return d->m_toplevel;
}
/*!
* \qmlproperty XdgPopup QtWaylandCompositor::XdgSurface::popup
*
* This property holds the properties and methods that are specific to the
* popup XdgSurface.
*
* \sa toplevel, XdgShell::popupCreated
*/
/*!
* \property QWaylandXdgSurface::popup
*
* This property holds the properties and methods that are specific to the
* popup QWaylandXdgSurface.
*
* \sa QWaylandXdgSurface::toplevel, QWaylandXdgShell::popupCreated
*/
QWaylandXdgPopup *QWaylandXdgSurface::popup() const
{
Q_D(const QWaylandXdgSurface);
return d->m_popup;
}
/*!
* Returns the Wayland interface for the QWaylandXdgSurface.
*/
const wl_interface *QWaylandXdgSurface::interface()
{
return QWaylandXdgSurfacePrivate::interface();
}
/*!
* \internal
*/
QByteArray QWaylandXdgSurface::interfaceName()
{
return QWaylandXdgSurfacePrivate::interfaceName();
}
/*!
* Returns the QWaylandXdgSurface corresponding to the \a resource.
*/
QWaylandXdgSurface *QWaylandXdgSurface::fromResource(wl_resource *resource)
{
if (auto p = QtWayland::fromResource<QWaylandXdgSurfacePrivate *>(resource))
return p->q_func();
return nullptr;
}
#if QT_CONFIG(wayland_compositor_quick)
QWaylandQuickShellIntegration *QWaylandXdgSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
{
Q_D(const QWaylandXdgSurface);
if (d->m_toplevel)
return new QtWayland::XdgToplevelIntegration(item);
if (d->m_popup)
return new QtWayland::XdgPopupIntegration(item);
return nullptr;
}
#endif
/*!
* \qmltype XdgToplevel
* \instantiates QWaylandXdgToplevel
* \inqmlmodule QtWayland.Compositor.XdgShell
* \since 5.12
* \brief XdgToplevel represents the toplevel window specific parts of an xdg surface.
*
* This type is part of the \l{XdgShell} extension and provides a way to
* extend the functionality of an XdgSurface with features
* specific to desktop-style windows.
*
* It corresponds to the Wayland interface \c xdg_toplevel.
*/
/*!
* \class QWaylandXdgToplevel
* \inmodule QtWaylandCompositor
* \since 5.12
* \brief The QWaylandXdgToplevel class represents the toplevel window specific parts of an xdg surface.
*
* This class is part of the QWaylandXdgShell extension and provides a way to
* extend the functionality of an QWaylandXdgSurface with features
* specific to desktop-style windows.
*
* It corresponds to the Wayland interface \c xdg_toplevel.
*/
/*!
* Constructs a QWaylandXdgToplevel for the given \a xdgSurface and \a resource.
*/
QWaylandXdgToplevel::QWaylandXdgToplevel(QWaylandXdgSurface *xdgSurface, QWaylandResource &resource)
: QObject(*new QWaylandXdgToplevelPrivate(xdgSurface, resource))
{
QList<QWaylandXdgToplevel::State> states;
sendConfigure({0, 0}, states);
}
QWaylandXdgToplevel::~QWaylandXdgToplevel()
{
Q_D(QWaylandXdgToplevel);
// Usually, the decoration is destroyed by the client (according to the protocol),
// but if the client misbehaves, or is shut down, we need to clean up here.
if (Q_UNLIKELY(d->m_decoration))
wl_resource_destroy(d->m_decoration->resource()->handle);
Q_ASSERT(!d->m_decoration);
}
/*!
* \qmlproperty XdgSurface QtWaylandCompositor::XdgToplevel::xdgSurface
*
* This property holds the XdgSurface for this XdgToplevel.
*/
/*!
* \property QWaylandXdgToplevel::xdgSurface
*
* This property holds the QWaylandXdgSurface for this QWaylandXdgToplevel.
*/
QWaylandXdgSurface *QWaylandXdgToplevel::xdgSurface() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_xdgSurface;
}
/*!
* \qmlproperty XdgToplevel QtWaylandCompositor::XdgToplevel::parentToplevel
*
* This property holds the XdgToplevel parent of this XdgToplevel.
*/
/*!
* \property QWaylandXdgToplevel::parentToplevel
*
* This property holds the XdgToplevel parent of this XdgToplevel.
*
*/
QWaylandXdgToplevel *QWaylandXdgToplevel::parentToplevel() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_parentToplevel;
}
/*!
* \qmlproperty string QtWaylandCompositor::XdgToplevel::title
*
* This property holds the title of the XdgToplevel.
*/
/*!
* \property QWaylandXdgToplevel::title
*
* This property holds the title of the QWaylandXdgToplevel.
*/
QString QWaylandXdgToplevel::title() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_title;
}
/*!
* \qmlproperty string QtWaylandCompositor::XdgToplevel::appId
*
* This property holds the app id of the XdgToplevel.
*/
/*!
* \property QWaylandXdgToplevel::appId
*
* This property holds the app id of the QWaylandXdgToplevel.
*/
QString QWaylandXdgToplevel::appId() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_appId;
}
/*!
* \qmlproperty size QtWaylandCompositor::XdgToplevel::maxSize
*
* This property holds the maximum size of the XdgToplevel as requested by the client.
*
* The compositor is free to ignore this value and request a larger size.
*/
/*!
* \property QWaylandXdgToplevel::maxSize
*
* This property holds the maximum size of the QWaylandXdgToplevel.
*
* The compositor is free to ignore this value and request a larger size.
*/
QSize QWaylandXdgToplevel::maxSize() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_maxSize;
}
/*!
* \qmlproperty size QtWaylandCompositor::XdgToplevel::minSize
*
* This property holds the minimum size of the XdgToplevel as requested by the client.
*
* The compositor is free to ignore this value and request a smaller size.
*/
/*!
* \property QWaylandXdgToplevel::minSize
*
* This property holds the minimum size of the QWaylandXdgToplevel.
*
* The compositor is free to ignore this value and request a smaller size.
*/
QSize QWaylandXdgToplevel::minSize() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_minSize;
}
/*!
* \property QWaylandXdgToplevel::states
*
* This property holds the last states the client acknowledged for this QWaylandToplevel.
*/
QList<QWaylandXdgToplevel::State> QWaylandXdgToplevel::states() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_lastAckedConfigure.states;
}
/*!
* \qmlproperty bool QtWaylandCompositor::XdgToplevel::maximized
*
* This property holds whether the client has acknowledged that it should be maximized.
*/
/*!
* \property QWaylandXdgToplevel::maximized
*
* This property holds whether the client has acknowledged that it should be maximized.
*/
bool QWaylandXdgToplevel::maximized() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgToplevel::State::MaximizedState);
}
/*!
* \qmlproperty bool QtWaylandCompositor::XdgToplevel::fullscreen
*
* This property holds whether the client has acknowledged that it should be fullscreen.
*/
/*!
* \property QWaylandXdgToplevel::fullscreen
*
* This property holds whether the client has acknowledged that it should be fullscreen.
*/
bool QWaylandXdgToplevel::fullscreen() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgToplevel::State::FullscreenState);
}
/*!
* \qmlproperty bool QtWaylandCompositor::XdgToplevel::resizing
*
* This property holds whether the client has acknowledged that it is being resized.
*/
/*!
* \property QWaylandXdgToplevel::resizing
*
* This property holds whether the client has acknowledged that it is being resized.
*/
bool QWaylandXdgToplevel::resizing() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgToplevel::State::ResizingState);
}
/*!
* \qmlproperty bool QtWaylandCompositor::XdgToplevel::activated
*
* This property holds whether toplevel is drawing itself as having input focus.
*/
/*!
* \property QWaylandXdgToplevel::activated
*
* This property holds whether toplevel is drawing itself as having input focus.
*/
bool QWaylandXdgToplevel::activated() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgToplevel::State::ActivatedState);
}
/*!
* \enum QWaylandXdgToplevel::DecorationMode
*
* This enum type is used to specify the window decoration mode for toplevel windows.
*
* \value ServerSideDecoration The compositor should draw window decorations.
* \value ClientSideDecoration The client should draw window decorations.
*/
/*!
* \qmlproperty enumeration QtWaylandCompositor::XdgToplevel::decorationMode
*
* This property holds the current window decoration mode for this toplevel.
*
* The possible values are:
* \value XdgToplevel.ServerSideDecoration The compositor should draw window decorations.
* \value XdgToplevel.ClientSideDecoration The client should draw window decorations.
*
* \sa XdgDecorationManagerV1
*/
/*!
* \property QWaylandXdgToplevel::decorationMode
*
* This property holds the current window decoration mode for this toplevel.
*
* \sa QWaylandXdgDecorationManagerV1
*/
QWaylandXdgToplevel::DecorationMode QWaylandXdgToplevel::decorationMode() const
{
Q_D(const QWaylandXdgToplevel);
return d->m_decoration ? d->m_decoration->configuredMode() : DecorationMode::ClientSideDecoration;
}
/*!
* \qmlmethod size QtWaylandCompositor::XdgToplevel::sizeForResize(size size, point delta, uint edges)
*
* Convenience for computing the new size given the current \a size, a \a delta, and
* the \a edges active in the drag.
*/
/*!
* Convenience for computing the new size given the current \a size, a \a delta, and
* the \a edges active in the drag.
*/
QSize QWaylandXdgToplevel::sizeForResize(const QSizeF &size, const QPointF &delta, Qt::Edges edges) const
{
qreal width = size.width();
qreal height = size.height();
if (edges & Qt::LeftEdge)
width -= delta.x();
else if (edges & Qt::RightEdge)
width += delta.x();
if (edges & Qt::TopEdge)
height -= delta.y();
else if (edges & Qt::BottomEdge)
height += delta.y();
QSize newSize = QSize(width, height)
.expandedTo(minSize())
.expandedTo({1, 1}); // We don't want to send a size of (0,0) as that means that the client decides
if (maxSize().isValid())
newSize = newSize.boundedTo(maxSize());
return newSize;
}
/*!
* Sends a configure event to the client. Parameter \a size contains the pixel size
* of the surface. A size of zero means the client is free to decide the size.
* Known \a states are enumerated in QWaylandXdgToplevel::State.
*/
uint QWaylandXdgToplevel::sendConfigure(const QSize &size, const QList<QWaylandXdgToplevel::State> &states)
{
if (!size.isValid()) {
qWarning() << "Can't configure xdg_toplevel with an invalid size" << size;
return 0;
}
Q_D(QWaylandXdgToplevel);
auto statesBytes = QByteArray::fromRawData(reinterpret_cast<const char *>(states.data()),
states.size() * static_cast<int>(sizeof(State)));
uint32_t serial = d->m_xdgSurface->surface()->compositor()->nextSerial();