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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qwaylandxdgshellv5.h"
#include "qwaylandxdgshellv5_p.h"
#if QT_CONFIG(wayland_compositor_quick)
#include "qwaylandxdgshellv5integration_p.h"
#endif
#include <QtWaylandCompositor/private/qwaylandutils_p.h>
#include <QtWaylandCompositor/QWaylandCompositor>
#include <QtWaylandCompositor/QWaylandSurface>
#include <QtWaylandCompositor/QWaylandSurfaceRole>
#include <QtWaylandCompositor/QWaylandResource>
#include <QtWaylandCompositor/QWaylandSeat>
#include <QtCore/QObject>
#include <algorithm>
QT_BEGIN_NAMESPACE
#if QT_DEPRECATED_SINCE(5, 15)
QWaylandSurfaceRole QWaylandXdgSurfaceV5Private::s_role("xdg_surface");
QWaylandSurfaceRole QWaylandXdgPopupV5Private::s_role("xdg_popup");
QWaylandXdgShellV5Private::QWaylandXdgShellV5Private()
{
}
void QWaylandXdgShellV5Private::ping(Resource *resource, uint32_t serial)
{
m_pings.insert(serial);
send_ping(resource->handle, serial);
}
void QWaylandXdgShellV5Private::registerSurface(QWaylandXdgSurfaceV5 *xdgSurface)
{
m_xdgSurfaces.insert(xdgSurface->surface()->client()->client(), xdgSurface);
}
void QWaylandXdgShellV5Private::unregisterXdgSurface(QWaylandXdgSurfaceV5 *xdgSurface)
{
auto xdgSurfacePrivate = QWaylandXdgSurfaceV5Private::get(xdgSurface);
if (!m_xdgSurfaces.remove(xdgSurfacePrivate->resource()->client(), xdgSurface))
qWarning("%s Unexpected state. Can't find registered xdg surface\n", Q_FUNC_INFO);
}
void QWaylandXdgShellV5Private::registerXdgPopup(QWaylandXdgPopupV5 *xdgPopup)
{
m_xdgPopups.insert(xdgPopup->surface()->client()->client(), xdgPopup);
}
void QWaylandXdgShellV5Private::unregisterXdgPopup(QWaylandXdgPopupV5 *xdgPopup)
{
auto xdgPopupPrivate = QWaylandXdgPopupV5Private::get(xdgPopup);
if (!m_xdgPopups.remove(xdgPopupPrivate->resource()->client(), xdgPopup))
qWarning("%s Unexpected state. Can't find registered xdg popup\n", Q_FUNC_INFO);
}
bool QWaylandXdgShellV5Private::isValidPopupParent(QWaylandSurface *parentSurface) const
{
QWaylandXdgPopupV5 *topmostPopup = topmostPopupForClient(parentSurface->client()->client());
if (topmostPopup && topmostPopup->surface() != parentSurface) {
return false;
}
QWaylandSurfaceRole *parentRole = parentSurface->role();
if (parentRole != QWaylandXdgSurfaceV5::role() && parentRole != QWaylandXdgPopupV5::role()) {
return false;
}
return true;
}
QWaylandXdgPopupV5 *QWaylandXdgShellV5Private::topmostPopupForClient(wl_client *client) const
{
QList<QWaylandXdgPopupV5 *> clientPopups = m_xdgPopups.values(client);
return clientPopups.empty() ? nullptr : clientPopups.last();
}
QWaylandXdgSurfaceV5 *QWaylandXdgShellV5Private::xdgSurfaceFromSurface(QWaylandSurface *surface) const
{
for (QWaylandXdgSurfaceV5 *xdgSurface : m_xdgSurfaces) {
if (surface == xdgSurface->surface())
return xdgSurface;
}
return nullptr;
}
void QWaylandXdgShellV5Private::xdg_shell_destroy(Resource *resource)
{
if (!m_xdgSurfaces.values(resource->client()).empty())
wl_resource_post_error(resource->handle, XDG_SHELL_ERROR_DEFUNCT_SURFACES,
"xdg_shell was destroyed before children");
wl_resource_destroy(resource->handle);
}
void QWaylandXdgShellV5Private::xdg_shell_get_xdg_surface(Resource *resource, uint32_t id,
wl_resource *surface_res)
{
Q_Q(QWaylandXdgShellV5);
QWaylandSurface *surface = QWaylandSurface::fromResource(surface_res);
if (xdgSurfaceFromSurface(surface)) {
wl_resource_post_error(resource->handle, XDG_SHELL_ERROR_ROLE,
"An active xdg_surface already exists for wl_surface@%d",
wl_resource_get_id(surface->resource()));
return;
}
if (!surface->setRole(QWaylandXdgSurfaceV5::role(), resource->handle, XDG_SHELL_ERROR_ROLE))
return;
QWaylandResource xdgSurfaceResource(wl_resource_create(resource->client(), &xdg_surface_v5_interface,
wl_resource_get_version(resource->handle), id));
emit q->xdgSurfaceRequested(surface, xdgSurfaceResource);
QWaylandXdgSurfaceV5 *xdgSurface = QWaylandXdgSurfaceV5::fromResource(xdgSurfaceResource.resource());
if (!xdgSurface) {
// A QWaylandXdgSurfaceV5 was not created in response to the xdgSurfaceRequested signal, so we
// create one as fallback here instead.
xdgSurface = new QWaylandXdgSurfaceV5(q, surface, xdgSurfaceResource);
}
registerSurface(xdgSurface);
emit q->xdgSurfaceCreated(xdgSurface);
}
void QWaylandXdgShellV5Private::xdg_shell_use_unstable_version(Resource *resource, int32_t version)
{
if (xdg_shell_v5::version_current != version) {
wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
"incompatible version, server is %d, but client wants %d",
xdg_shell_v5::version_current, version);
}
}
void QWaylandXdgShellV5Private::xdg_shell_get_xdg_popup(Resource *resource, uint32_t id,
wl_resource *surface_res, wl_resource *parent,
wl_resource *seatResource, uint32_t serial,
int32_t x, int32_t y)
{
Q_UNUSED(serial);
Q_Q(QWaylandXdgShellV5);
QWaylandSurface *surface = QWaylandSurface::fromResource(surface_res);
QWaylandSurface *parentSurface = QWaylandSurface::fromResource(parent);
if (!isValidPopupParent(parentSurface)) {
wl_resource_post_error(resource->handle, XDG_SHELL_ERROR_INVALID_POPUP_PARENT,
"the client specified an invalid popup parent surface");
return;
}
if (!surface->setRole(QWaylandXdgPopupV5::role(), resource->handle, XDG_SHELL_ERROR_ROLE)) {
return;
}
QWaylandResource xdgPopupResource (wl_resource_create(resource->client(), &xdg_popup_v5_interface,
wl_resource_get_version(resource->handle), id));
QWaylandSeat *seat = QWaylandSeat::fromSeatResource(seatResource);
QPoint position(x, y);
emit q->xdgPopupRequested(surface, parentSurface, seat, position, xdgPopupResource);
QWaylandXdgPopupV5 *xdgPopup = QWaylandXdgPopupV5::fromResource(xdgPopupResource.resource());
if (!xdgPopup) {
// A QWaylandXdgPopupV5 was not created in response to the xdgPopupRequested signal, so we
// create one as fallback here instead.
xdgPopup = new QWaylandXdgPopupV5(q, surface, parentSurface, position, xdgPopupResource);
}
registerXdgPopup(xdgPopup);
emit q->xdgPopupCreated(xdgPopup);
}
void QWaylandXdgShellV5Private::xdg_shell_pong(Resource *resource, uint32_t serial)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgShellV5);
if (m_pings.remove(serial))
emit q->pong(serial);
else
qWarning("Received an unexpected pong!");
}
QWaylandXdgSurfaceV5Private::QWaylandXdgSurfaceV5Private()
: m_lastAckedConfigure({{}, QSize(0, 0), 0})
{
}
void QWaylandXdgSurfaceV5Private::handleFocusLost()
{
Q_Q(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent current = lastSentConfigure();
current.states.removeOne(QWaylandXdgSurfaceV5::State::ActivatedState);
q->sendConfigure(current.size, current.states);
}
void QWaylandXdgSurfaceV5Private::handleFocusReceived()
{
Q_Q(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent current = lastSentConfigure();
if (!current.states.contains(QWaylandXdgSurfaceV5::State::ActivatedState)) {
current.states.push_back(QWaylandXdgSurfaceV5::State::ActivatedState);
}
q->sendConfigure(current.size, current.states);
}
QRect QWaylandXdgSurfaceV5Private::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 QWaylandXdgSurfaceV5Private::updateFallbackWindowGeometry()
{
Q_Q(QWaylandXdgSurfaceV5);
if (!m_unsetWindowGeometry)
return;
const QRect unsetGeometry = calculateFallbackWindowGeometry();
if (unsetGeometry == m_windowGeometry)
return;
m_windowGeometry = unsetGeometry;
emit q->windowGeometryChanged();
}
void QWaylandXdgSurfaceV5Private::setWindowType(Qt::WindowType windowType)
{
if (m_windowType == windowType)
return;
m_windowType = windowType;
Q_Q(QWaylandXdgSurfaceV5);
emit q->windowTypeChanged();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_destroy_resource(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
QWaylandXdgShellV5Private::get(m_xdgShell)->unregisterXdgSurface(q);
delete q;
}
void QWaylandXdgSurfaceV5Private::xdg_surface_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void QWaylandXdgSurfaceV5Private::xdg_surface_move(Resource *resource, wl_resource *seat, uint32_t serial)
{
Q_UNUSED(resource);
Q_UNUSED(serial);
Q_Q(QWaylandXdgSurfaceV5);
QWaylandSeat *input_device = QWaylandSeat::fromSeatResource(seat);
emit q->startMove(input_device);
}
void QWaylandXdgSurfaceV5Private::xdg_surface_resize(Resource *resource, wl_resource *seat,
uint32_t serial, uint32_t edges)
{
Q_UNUSED(resource);
Q_UNUSED(serial);
Q_Q(QWaylandXdgSurfaceV5);
QWaylandSeat *input_device = QWaylandSeat::fromSeatResource(seat);
emit q->startResize(input_device, QWaylandXdgSurfaceV5::ResizeEdge(edges));
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_maximized(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
emit q->setMaximized();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_unset_maximized(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
emit q->unsetMaximized();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_fullscreen(Resource *resource, wl_resource *output_res)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
QWaylandOutput *output = output_res ? QWaylandOutput::fromResource(output_res) : nullptr;
emit q->setFullscreen(output);
}
void QWaylandXdgSurfaceV5Private::xdg_surface_unset_fullscreen(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
emit q->unsetFullscreen();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_minimized(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
emit q->setMinimized();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_parent(Resource *resource, wl_resource *parent)
{
Q_UNUSED(resource);
QWaylandXdgSurfaceV5 *parentSurface = nullptr;
if (parent) {
parentSurface = static_cast<QWaylandXdgSurfaceV5Private *>(
QWaylandXdgSurfaceV5Private::Resource::fromResource(parent)->xdg_surface_object)->q_func();
}
Q_Q(QWaylandXdgSurfaceV5);
if (m_parentSurface != parentSurface) {
m_parentSurface = parentSurface;
emit q->parentSurfaceChanged();
}
if (m_parentSurface && m_windowType != Qt::WindowType::SubWindow) {
// There's a parent now, which means the surface is transient
setWindowType(Qt::WindowType::SubWindow);
emit q->setTransient();
} else if (!m_parentSurface && m_windowType != Qt::WindowType::Window) {
// When the surface has no parent it is toplevel
setWindowType(Qt::WindowType::Window);
emit q->setTopLevel();
}
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_app_id(Resource *resource, const QString &app_id)
{
Q_UNUSED(resource);
if (app_id == m_appId)
return;
Q_Q(QWaylandXdgSurfaceV5);
m_appId = app_id;
emit q->appIdChanged();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_show_window_menu(Resource *resource, wl_resource *seatResource,
uint32_t serial, int32_t x, int32_t y)
{
Q_UNUSED(resource);
Q_UNUSED(serial);
QPoint position(x, y);
auto seat = QWaylandSeat::fromSeatResource(seatResource);
Q_Q(QWaylandXdgSurfaceV5);
emit q->showWindowMenu(seat, position);
}
void QWaylandXdgSurfaceV5Private::xdg_surface_ack_configure(Resource *resource, uint32_t serial)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgSurfaceV5);
ConfigureEvent config;
Q_FOREVER {
if (m_pendingConfigures.empty()) {
qWarning("Received an unexpected ack_configure!");
return;
}
config = m_pendingConfigures.takeFirst();
if (config.serial == serial)
break;
}
std::vector<uint> changedStates;
std::set_symmetric_difference(
m_lastAckedConfigure.states.begin(), m_lastAckedConfigure.states.end(),
config.states.begin(), config.states.end(),
std::back_inserter(changedStates));
m_lastAckedConfigure = config;
if (!changedStates.empty()) {
for (uint state : changedStates) {
switch (state) {
case QWaylandXdgSurfaceV5::State::MaximizedState:
emit q->maximizedChanged();
break;
case QWaylandXdgSurfaceV5::State::FullscreenState:
emit q->fullscreenChanged();
break;
case QWaylandXdgSurfaceV5::State::ResizingState:
emit q->resizingChanged();
break;
case QWaylandXdgSurfaceV5::State::ActivatedState:
emit q->activatedChanged();
break;
}
}
emit q->statesChanged();
}
emit q->ackConfigure(serial);
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_title(Resource *resource, const QString &title)
{
Q_UNUSED(resource);
if (title == m_title)
return;
Q_Q(QWaylandXdgSurfaceV5);
m_title = title;
emit q->titleChanged();
}
void QWaylandXdgSurfaceV5Private::xdg_surface_set_window_geometry(Resource *resource,
int32_t x, int32_t y,
int32_t width, int32_t height)
{
Q_UNUSED(resource);
if (width <= 0 || height <= 0) {
qWarning() << "Invalid (non-positive) dimensions received in set_window_geometry";
return;
}
m_unsetWindowGeometry = false;
QRect geometry(x, y, width, height);
Q_Q(QWaylandXdgSurfaceV5);
if ((q->maximized() || q->fullscreen()) && m_lastAckedConfigure.size != geometry.size())
qWarning() << "Client window geometry did not obey last acked configure";
if (geometry == m_windowGeometry)
return;
m_windowGeometry = geometry;
emit q->windowGeometryChanged();
}
QWaylandXdgPopupV5Private::QWaylandXdgPopupV5Private()
{
}
void QWaylandXdgPopupV5Private::xdg_popup_destroy_resource(Resource *resource)
{
Q_UNUSED(resource);
Q_Q(QWaylandXdgPopupV5);
QWaylandXdgShellV5Private::get(m_xdgShell)->unregisterXdgPopup(q);
delete q;
}
void QWaylandXdgPopupV5Private::xdg_popup_destroy(Resource *resource)
{
//TODO: post error if not topmost popup
wl_resource_destroy(resource->handle);
}
/*!
* \qmltype XdgShellV5
* \inqmlmodule QtWayland.Compositor
* \since 5.8
* \obsolete
* \brief Provides an extension for desktop-style user interfaces.
*
* The XdgShellV5 extension provides a way to associate an XdgSurfaceV5
* with a regular Wayland surface. Using the xdg_surface interface, the client
* can request that the surface is resized, moved, and so on.
*
* XdgShellV5 corresponds to the Wayland interface \c xdg_shell.
*
* To provide the functionality of the shell extension in a compositor, create
* an instance of the XdgShellV5 component and add it as a child of the
* compositor:
*
* \qml \QtMinorVersion
* import QtWayland.Compositor 1.\1
*
* WaylandCompositor {
* XdgShellV5 {
* // ...
* }
* }
* \endqml
*
* \deprecated
*/
/*!
* \class QWaylandXdgShellV5
* \inmodule QtWaylandCompositor
* \since 5.8
* \obsolete
* \brief The QWaylandXdgShellV5 class is an extension for desktop-style user interfaces.
*
* The QWaylandXdgShellV5 extension provides a way to associate a QWaylandXdgSurfaceV5 with
* a regular Wayland surface. Using the xdg_surface interface, the client
* can request that the surface is resized, moved, and so on.
*
* QWaylandXdgShellV5 corresponds to the Wayland interface \c xdg_shell.
*
* \deprecated
*/
/*!
* Constructs a QWaylandXdgShellV5 object.
*/
QWaylandXdgShellV5::QWaylandXdgShellV5()
: QWaylandShellTemplate<QWaylandXdgShellV5>(*new QWaylandXdgShellV5Private())
{ }
/*!
* Constructs a QWaylandXdgShellV5 object for the provided \a compositor.
*/
QWaylandXdgShellV5::QWaylandXdgShellV5(QWaylandCompositor *compositor)
: QWaylandShellTemplate<QWaylandXdgShellV5>(compositor, *new QWaylandXdgShellV5Private())
{ }
/*!
* Initializes the shell extension.
*/
void QWaylandXdgShellV5::initialize()
{
Q_D(QWaylandXdgShellV5);
QWaylandShellTemplate::initialize();
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
if (!compositor) {
qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandXdgShellV5";
return;
}
d->init(compositor->display(), 1);
handleSeatChanged(compositor->defaultSeat(), nullptr);
connect(compositor, &QWaylandCompositor::defaultSeatChanged,
this, &QWaylandXdgShellV5::handleSeatChanged);
}
QWaylandClient *QWaylandXdgShellV5::popupClient() const
{
Q_D(const QWaylandXdgShellV5);
for (QWaylandXdgPopupV5 *popup : d->m_xdgPopups) {
if (popup->surface()->hasContent())
return popup->surface()->client();
}
return nullptr;
}
/*!
* Returns the Wayland interface for the QWaylandXdgShellV5.
*/
const struct wl_interface *QWaylandXdgShellV5::interface()
{
return QWaylandXdgShellV5Private::interface();
}
QByteArray QWaylandXdgShellV5::interfaceName()
{
return QWaylandXdgShellV5Private::interfaceName();
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgShellV5::ping(WaylandClient client)
*
* Sends a ping event to the \a client. If the client replies to the event, the
* pong signal will be emitted.
*/
/*!
* Sends a ping event to the \a client. If the client replies to the event, the
* pong signal will be emitted.
*/
uint QWaylandXdgShellV5::ping(QWaylandClient *client)
{
Q_D(QWaylandXdgShellV5);
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
Q_ASSERT(compositor);
uint32_t serial = compositor->nextSerial();
QWaylandXdgShellV5Private::Resource *clientResource = d->resourceMap().value(client->client(), nullptr);
Q_ASSERT(clientResource);
d->ping(clientResource, serial);
return serial;
}
// ### remove once QMap has rbegin()/rend()
template <typename Iterator>
std::reverse_iterator<Iterator> make_reverse(Iterator it)
{
return std::reverse_iterator<Iterator>(std::move(it));
}
void QWaylandXdgShellV5::closeAllPopups()
{
Q_D(QWaylandXdgShellV5);
// Close pop-ups from top-most to bottom-most, lest we get protocol errors:
for (auto rit = make_reverse(d->m_xdgPopups.end()), rend = make_reverse(d->m_xdgPopups.begin()); rit != rend; ++rit) {
(*rit)->sendPopupDone();
}
}
/*!
* \qmlsignal void QtWaylandCompositor::XdgShellV5::xdgSurfaceRequested(WaylandSurface surface, WaylandResource resource)
*
* This signal is emitted when the client has requested an \c xdg_surface to be associated
* with \a surface. The handler for this signal may create the shell surface for \a resource
* and initialize it within the scope of the signal emission. Otherwise an XdgSurfaceV5 will
* be created automatically.
*/
/*!
* \fn void QWaylandXdgShellV5::xdgSurfaceRequested(QWaylandSurface *surface, const QWaylandResource &resource)
*
* This signal is emitted when the client has requested an \c xdg_surface to be associated
* with \a surface. The handler for this signal may create the shell surface for \a resource
* and initialize it within the scope of the signal emission. Otherwise a QWaylandXdgSurfaceV5
* will be created automatically.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgShellV5::xdgSurfaceCreated(XdgSurfaceV5 xdgSurface)
*
* This signal is emitted when the client has created an \c xdg_surface.
* A common use case is to let the handler of this signal instantiate a ShellSurfaceItem or
* WaylandQuickItem for displaying \a xdgSurface in a QtQuick scene.
*/
/*!
* \fn void QWaylandXdgShellV5::xdgSurfaceCreated(QWaylandXdgSurfaceV5 *xdgSurface)
*
* This signal is emitted when the client has created an \c xdg_surface.
* A common use case is to let the handler of this signal instantiate a QWaylandShellSurfaceItem or
* QWaylandQuickItem for displaying \a xdgSurface in a QtQuick scene.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgShellV5::xdgPopupRequested(WaylandSurface surface, WaylandSurface parent, WaylandSeat seat, point position, WaylandResource resource)
*
* This signal is emitted when the client has requested an \c xdg_popup to be associated
* with \a surface. The handler for this signal may create the xdg popup for \a resource and
* initialize it within the scope of the signal emission. Otherwise an XdgPopupV5 will be
* created automatically.
*
* The \a seat is the \c wl_seat that caused the popup to be opened.
*
* \a position is the desired position of the popup, relative to the \a parent.
*/
/*!
* \fn void QWaylandXdgShellV5::xdgPopupRequested(QWaylandSurface *surface, QWaylandSurface *parent, QWaylandSeat *seat, const QPoint &position, const QWaylandResource &resource)
*
* This signal is emitted when the client has requested an \c xdg_surface to be associated
* with \a surface. The handler for this signal may create the xdg poup for \a resource and
* initialize it within the scope of the signal emission. Otherwise a QWaylandXdgPopupV5 will be
* created automatically.
*
* The \a seat is the \c wl_seat that caused the popup to be opened.
*
* \a position is the desired position of the popup, relative to the \a parent.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgShellV5::xdgPopupCreated(XdgPopupV5 xdgPopup)
*
* This signal is emitted when the client has created an \c xdg_popup.
* A common use case is to let the handler of this signal instantiate a ShellSurfaceItem or
* WaylandQuickItem for displaying \a xdgPopup in a QtQuick scene.
*/
/*!
* \fn void QWaylandXdgShellV5::xdgPopupCreated(QWaylandXdgPopupV5 *xdgPopup)
*
* This signal is emitted when the client has created an \c xdg_popup.
* A common use case is to let the handler of this signal instantiate a QWaylandShellSurfaceItem or
* QWaylandQuickItem for displaying \a xdgPopup in a QtQuick scene.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgShellV5::pong(int serial)
*
* This signal is emitted when the client has responded to a ping event with serial \a serial.
*
* \sa QtWaylandCompositor::XdgShellV5::ping()
*/
/*!
* \fn void QWaylandXdgShellV5::pong(uint serial)
*
* This signal is emitted when the client has responded to a ping event with serial \a serial.
*
* \sa QWaylandXdgShellV5::ping()
*/
void QWaylandXdgShellV5::handleSeatChanged(QWaylandSeat *newSeat, QWaylandSeat *oldSeat)
{
if (oldSeat != nullptr) {
disconnect(oldSeat, &QWaylandSeat::keyboardFocusChanged,
this, &QWaylandXdgShellV5::handleFocusChanged);
}
if (newSeat != nullptr) {
connect(newSeat, &QWaylandSeat::keyboardFocusChanged,
this, &QWaylandXdgShellV5::handleFocusChanged);
}
}
void QWaylandXdgShellV5::handleFocusChanged(QWaylandSurface *newSurface, QWaylandSurface *oldSurface)
{
Q_D(QWaylandXdgShellV5);
QWaylandXdgSurfaceV5 *newXdgSurface = d->xdgSurfaceFromSurface(newSurface);
QWaylandXdgSurfaceV5 *oldXdgSurface = d->xdgSurfaceFromSurface(oldSurface);
if (newXdgSurface)
QWaylandXdgSurfaceV5Private::get(newXdgSurface)->handleFocusReceived();
if (oldXdgSurface)
QWaylandXdgSurfaceV5Private::get(oldXdgSurface)->handleFocusLost();
}
/*!
* \qmltype XdgSurfaceV5
* \inqmlmodule QtWayland.Compositor
* \since 5.8
* \obsolete
* \brief Provides a \c xdg_surface that offers desktop-style compositor-specific features to a surface.
*
* This type is part of the \l{XdgShellV5} extension and provides a way to extend
* the functionality of an existing WaylandSurface with features specific to desktop-style
* compositors, such as resizing and moving the surface.
*
* It corresponds to the Wayland interface \c xdg_surface for the unstable xdg-shell protocol v5.
*
* \deprecated
*/
/*!
* \class QWaylandXdgSurfaceV5
* \inmodule QtWaylandCompositor
* \since 5.8
* \obsolete
* \brief The QWaylandXdgSurfaceV5 class provides desktop-style compositor-specific features to an xdg surface.
*
* This class is part of the QWaylandXdgShellV5 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 xdg_surface.
*
* \deprecated
*/
/*!
\enum QWaylandXdgSurfaceV5::ResizeEdge
\value NoneEdge
No edge defined.
\value TopEdge
Top egde.
\value BottomEdge
Bottom edge.
\value LeftEdge
Left edge.
\value TopLeftEdge
Top-left edge.
\value BottomLeftEdge
Bottom-left edge.
\value RightEdge
Right edge.
\value TopRightEdge
Top-right edge.
\value BottomRightEdge
Bottom-right edge.
*/
/*!
* \fn QWaylandXdgSurfaceV5::setTopLevel()
*
* This signal is emitted when the parent surface is unset, effectively
* making the window top level.
*/
/*!
* \qmlsignal QtWaylandCompositor::XdgSurfaceV5::setTopLevel()
*
* This signal is emitted when the parent surface is unset, effectively
* making the window top level.
*/
/*!
* \fn QWaylandXdgSurfaceV5::setTransient()
*
* This signal is emitted when the parent surface is set, effectively
* making the window transient.
*/
/*!
* \qmlsignal QtWaylandCompositor::XdgSurfaceV5::setTransient()
*
* This signal is emitted when the parent surface is set, effectively
* making the window transient.
*/
/*!
* Constructs a QWaylandXdgSurfaceV5.
*/
QWaylandXdgSurfaceV5::QWaylandXdgSurfaceV5()
: QWaylandShellSurfaceTemplate<QWaylandXdgSurfaceV5>(*new QWaylandXdgSurfaceV5Private)
{
}
/*!
* Constructs a QWaylandXdgSurfaceV5 for \a surface and initializes it with the
* given \a xdgShell, \a surface, and resource \a res.
*/
QWaylandXdgSurfaceV5::QWaylandXdgSurfaceV5(QWaylandXdgShellV5 *xdgShell, QWaylandSurface *surface, const QWaylandResource &res)
: QWaylandShellSurfaceTemplate<QWaylandXdgSurfaceV5>(*new QWaylandXdgSurfaceV5Private)
{
initialize(xdgShell, surface, res);
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgSurfaceV5::initialize(XdgShellV5 xdgShell, WaylandSurface surface, WaylandResource resource)
*
* Initializes the XdgSurfaceV5, associating it with the given \a xdgShell, \a surface,
* and \a resource.
*/
/*!
* Initializes the QWaylandXdgSurfaceV5, associating it with the given \a xdgShell, \a surface
* and \a resource.
*/
void QWaylandXdgSurfaceV5::initialize(QWaylandXdgShellV5 *xdgShell, QWaylandSurface *surface, const QWaylandResource &resource)
{
Q_D(QWaylandXdgSurfaceV5);
d->m_xdgShell = xdgShell;
d->m_surface = surface;
d->init(resource.resource());
setExtensionContainer(surface);
d->m_windowGeometry = d->calculateFallbackWindowGeometry();
connect(surface, &QWaylandSurface::destinationSizeChanged, this, &QWaylandXdgSurfaceV5::handleSurfaceSizeChanged);
connect(surface, &QWaylandSurface::bufferScaleChanged, this, &QWaylandXdgSurfaceV5::handleBufferScaleChanged);
emit shellChanged();
emit surfaceChanged();
emit windowGeometryChanged();
QWaylandCompositorExtension::initialize();
}
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::showWindowMenu(WaylandSeat seat, point localSurfacePosition)
*
* This signal is emitted when the client wants to show a context menu at \a localSurfacePosition,
* using the Wayland seat \a seat. It's typically emitted in response to the user right-clicking
* the window decorations.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::showWindowMenu(QWaylandSeat *seat, const QPoint &localSurfacePosition)
*
* This signal is emitted when the client wants to show a context menu at \a localSurfacePosition,
* using the Wayland seat \a seat. It's typically emitted in response to the user right-clicking
* the window decorations.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::startMove(WaylandSeat seat)
*
* This signal is emitted when the client wants to start an interactive move of the XdgSurfaceV5,
* typically in response to the window decorations being dragged by \a seat.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::startMove(QWaylandSeat *seat)
*
* This signal is emitted when the client wants to start an interactive move of the
* QWaylandXdgSurfaceV5, typically in response to the window decorations being dragged by \a seat.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::startResize(WaylandSeat seat, enumeration edges)
*
* This signal is emitted when the client wants to start an interactive resize of the XdgSurfaceV5,
* typically in response to the window decorations being dragged by \a seat on the window borders
* given by \a edges.
*
* \sa QWaylandXdgSurfaceV5::ResizeEdge
*/
/*!
* \fn void QWaylandXdgSurfaceV5::startResize(QWaylandSeat *seat, ResizeEdge edges)
*
* This signal is emitted when the client wants to start an interactive resize of the
* QWaylandXdgSurfaceV5, typically in response to the window decorations being dragged by
* \a seat on the window borders given by \a edges.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::setMaximized()
*
* This signal is emitted when the client wants the \c xdg_surface to be maximized.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::setMaximized()
*
* This signal is emitted when the client wants the \c xdg_surface to be maximized.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::unsetMaximized()
*
* This signal is emitted when the client doesn't want the \c xdg_surface to be maximized anymore.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::unsetMaximized()
*
* This signal is emitted when the client doesn't want the \c xdg_surface to be maximized anymore.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::setFullscreen(WaylandOutput output)
*
* This signal is emitted when the client wants the \c xdg_surface to be in full screen mode.
* The client may specify an \a output it wishes the \c xdg_surface to be shown on.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::setFullscreen(QWaylandOutput *output)
*
* This signal is emitted when the client wants the \c xdg_surface to be in full screen mode.
* The client may specify an \a output it wishes the \c xdg_surface to be shown on.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::unsetFullscreen()
*
* This signal is emitted when the client doesn't want the \c xdg_surface to be in full screen mode
* anymore.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::unsetFullscreen()
*
* This signal is emitted when the client doesn't want the \c xdg_surface to be in full screen mode
* anymore.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::setMinimized()
*
* This signal is emitted when the client wants the \c xdg_surface to be minimized.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::setMinimized()
*
* This signal is emitted when the client wants the \c xdg_surface to be minimized.
*/
/*!
* \qmlsignal void QtWaylandCompositor::XdgSurfaceV5::ackConfigure(int serial)
*
* This signal is emitted when the client has received configure events up to and including the
* configure event with serial \a serial and will draw its surface accordingly in the next committed
* buffer.
*/
/*!
* \fn void QWaylandXdgSurfaceV5::ackConfigure(uint serial)
*
* This signal is emitted when the client has received configure events up to and including the
* configure event with serial \a serial and will draw its surface accordingly in the next committed
* buffer.
*/
/*!
* \internal
*/
void QWaylandXdgSurfaceV5::initialize()
{
QWaylandCompositorExtension::initialize();
}
QList<int> QWaylandXdgSurfaceV5::statesAsInts() const
{
QList<int> list;
const auto s = states();
list.reserve(s.size());
for (auto state : s) {
list << static_cast<int>(state);
}
return list;
}
void QWaylandXdgSurfaceV5::handleSurfaceSizeChanged()
{
Q_D(QWaylandXdgSurfaceV5);
d->updateFallbackWindowGeometry();
}
void QWaylandXdgSurfaceV5::handleBufferScaleChanged()
{
Q_D(QWaylandXdgSurfaceV5);
d->updateFallbackWindowGeometry();
}
/*!
* \qmlproperty XdgShellV5 QtWaylandCompositor::XdgSurfaceV5::shell
*
* This property holds the shell associated with this XdgSurfaceV5.
*/
/*!
* \property QWaylandXdgSurfaceV5::shell
*
* This property holds the shell associated with this QWaylandXdgSurfaceV5.
*/
QWaylandXdgShellV5 *QWaylandXdgSurfaceV5::shell() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_xdgShell;
}
/*!
* \qmlproperty WaylandSurface QtWaylandCompositor::XdgSurfaceV5::surface
*
* This property holds the surface associated with this XdgSurfaceV5.
*/
/*!
* \property QWaylandXdgSurfaceV5::surface
*
* This property holds the surface associated with this QWaylandXdgSurfaceV5.
*/
QWaylandSurface *QWaylandXdgSurfaceV5::surface() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_surface;
}
/*!
* \qmlproperty enumeration QtWaylandCompositor::XdgSurfaceV5::windowType
*
* This property holds the window type of the XdgSurfaceV5.
*/
Qt::WindowType QWaylandXdgSurfaceV5::windowType() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_windowType;
}
/*!
* \qmlproperty XdgSurfaceV5 QtWaylandCompositor::XdgSurfaceV5::parentSurface
*
* This property holds the XdgSurfaceV5 parent of this XdgSurfaceV5.
* When a parent surface is set, the parentSurfaceChanged() signal
* is guaranteed to be emitted before setTopLevel() and setTransient().
*
* \sa QtWaylandCompositor::XdgSurfaceV5::setTopLevel()
* \sa QtWaylandCompositor::XdgSurfaceV5::setTransient()
*/
/*!
* \property QWaylandXdgSurfaceV5::parentSurface
*
* This property holds the XdgSurfaceV5 parent of this XdgSurfaceV5.
* When a parent surface is set, the parentSurfaceChanged() signal
* is guaranteed to be emitted before setTopLevel() and setTransient().
*
* \sa QWaylandXdgSurfaceV5::setTopLevel()
* \sa QWaylandXdgSurfaceV5::setTransient()
*/
QWaylandXdgSurfaceV5 *QWaylandXdgSurfaceV5::parentSurface() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_parentSurface;
}
/*!
* \qmlproperty string QtWaylandCompositor::XdgSurfaceV5::title
*
* This property holds the title of the XdgSurfaceV5.
*/
/*!
* \property QWaylandXdgSurfaceV5::title
*
* This property holds the title of the QWaylandXdgSurfaceV5.
*/
QString QWaylandXdgSurfaceV5::title() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_title;
}
/*!
* \property QWaylandXdgSurfaceV5::appId
*
* This property holds the app id of the QWaylandXdgSurfaceV5.
*/
QString QWaylandXdgSurfaceV5::appId() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_appId;
}
/*!
* \property QWaylandXdgSurfaceV5::windowGeometry
*
* This property holds the window geometry of the QWaylandXdgSurfaceV5. 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 QWaylandXdgSurfaceV5::windowGeometry() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_windowGeometry;
}
/*!
* \property QWaylandXdgSurfaceV5::states
*
* This property holds the last states the client acknowledged for this QWaylandXdgSurfaceV5.
*/
QVector<uint> QWaylandXdgSurfaceV5::states() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_lastAckedConfigure.states;
}
bool QWaylandXdgSurfaceV5::maximized() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgSurfaceV5::State::MaximizedState);
}
bool QWaylandXdgSurfaceV5::fullscreen() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgSurfaceV5::State::FullscreenState);
}
bool QWaylandXdgSurfaceV5::resizing() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgSurfaceV5::State::ResizingState);
}
bool QWaylandXdgSurfaceV5::activated() const
{
Q_D(const QWaylandXdgSurfaceV5);
return d->m_lastAckedConfigure.states.contains(QWaylandXdgSurfaceV5::State::ActivatedState);
}
/*!
* Returns the Wayland interface for the QWaylandXdgSurfaceV5.
*/
const wl_interface *QWaylandXdgSurfaceV5::interface()
{
return QWaylandXdgSurfaceV5Private::interface();
}
QByteArray QWaylandXdgSurfaceV5::interfaceName()
{
return QWaylandXdgSurfaceV5Private::interfaceName();
}
/*!
* Returns the surface role for the QWaylandXdgSurfaceV5.
*/
QWaylandSurfaceRole *QWaylandXdgSurfaceV5::role()
{
return &QWaylandXdgSurfaceV5Private::s_role;
}
/*!
* Returns the QWaylandXdgSurfaceV5 corresponding to the \a resource.
*/
QWaylandXdgSurfaceV5 *QWaylandXdgSurfaceV5::fromResource(wl_resource *resource)
{
if (auto p = QtWayland::fromResource<QWaylandXdgSurfaceV5Private *>(resource))
return p->q_func();
return nullptr;
}
QSize QWaylandXdgSurfaceV5::sizeForResize(const QSizeF &size, const QPointF &delta,
QWaylandXdgSurfaceV5::ResizeEdge edge)
{
qreal width = size.width();
qreal height = size.height();
if (edge & LeftEdge)
width -= delta.x();
else if (edge & RightEdge)
width += delta.x();
if (edge & TopEdge)
height -= delta.y();
else if (edge & BottomEdge)
height += delta.y();
QSizeF newSize(qMax(width, 1.0), qMax(height, 1.0));
return newSize.toSize();
}
/*!
* \qmlmethod int QtWaylandCompositor::XdgSurfaceV5::sendConfigure(size size, list<uint> states)
*
* Sends a configure event to the client. \a size contains the pixel size of the surface.
* Known \a states are enumerated in XdgSurfaceV5::State.
*/
/*!
* Sends a configure event to the client. Parameter \a size contains the pixel size
* of the surface. Known \a states are enumerated in QWaylandXdgSurfaceV5::State.
*/
uint QWaylandXdgSurfaceV5::sendConfigure(const QSize &size, const QVector<uint> &states)
{
if (!size.isValid()) {
qWarning() << "Can't configure xdg surface (v5) with an invalid size" << size;
return 0;
}
Q_D(QWaylandXdgSurfaceV5);
auto statesBytes = QByteArray::fromRawData((char *)states.data(), states.size() * sizeof(State));
QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(extensionContainer());
Q_ASSERT(surface);
QWaylandCompositor *compositor = surface->compositor();
Q_ASSERT(compositor);
uint32_t serial = compositor->nextSerial();
d->m_pendingConfigures.append(QWaylandXdgSurfaceV5Private::ConfigureEvent{states, size, serial});
d->send_configure(size.width(), size.height(), statesBytes, serial);
return serial;
}
uint QWaylandXdgSurfaceV5::sendConfigure(const QSize &size, const QVector<QWaylandXdgSurfaceV5::State> &states)
{
QVector<uint> asUints;
asUints.reserve(states.size());
for (QWaylandXdgSurfaceV5::State state : states) {
asUints << state;
}
return sendConfigure(size, asUints);
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgSurfaceV5::sendClose()
*
* Sends a close event to the client.
*/
/*!
* Sends a close event to the client.
*/
void QWaylandXdgSurfaceV5::sendClose()
{
Q_D(QWaylandXdgSurfaceV5);
d->send_close();
}
uint QWaylandXdgSurfaceV5::sendMaximized(const QSize &size)
{
Q_D(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent conf = d->lastSentConfigure();
if (!conf.states.contains(QWaylandXdgSurfaceV5::State::MaximizedState))
conf.states.append(QWaylandXdgSurfaceV5::State::MaximizedState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::FullscreenState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::ResizingState);
return sendConfigure(size, conf.states);
}
uint QWaylandXdgSurfaceV5::sendUnmaximized(const QSize &size)
{
Q_D(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent conf = d->lastSentConfigure();
conf.states.removeOne(QWaylandXdgSurfaceV5::State::MaximizedState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::FullscreenState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::ResizingState);
return sendConfigure(size, conf.states);
}
uint QWaylandXdgSurfaceV5::sendFullscreen(const QSize &size)
{
Q_D(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent conf = d->lastSentConfigure();
if (!conf.states.contains(QWaylandXdgSurfaceV5::State::FullscreenState))
conf.states.append(QWaylandXdgSurfaceV5::State::FullscreenState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::MaximizedState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::ResizingState);
return sendConfigure(size, conf.states);
}
uint QWaylandXdgSurfaceV5::sendResizing(const QSize &maxSize)
{
Q_D(QWaylandXdgSurfaceV5);
QWaylandXdgSurfaceV5Private::ConfigureEvent conf = d->lastSentConfigure();
if (!conf.states.contains(QWaylandXdgSurfaceV5::State::ResizingState))
conf.states.append(QWaylandXdgSurfaceV5::State::ResizingState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::MaximizedState);
conf.states.removeOne(QWaylandXdgSurfaceV5::State::FullscreenState);
return sendConfigure(maxSize, conf.states);
}
#if QT_CONFIG(wayland_compositor_quick)
QWaylandQuickShellIntegration *QWaylandXdgSurfaceV5::createIntegration(QWaylandQuickShellSurfaceItem *item)
{
return new QtWayland::XdgShellV5Integration(item);
}
#endif
/*!
* \qmltype XdgPopupV5
* \inqmlmodule QtWayland.Compositor
* \since 5.8
* \obsolete
* \brief Provides a \c xdg_popup interface that implements popup features for the xdg-shell protocol.
*
* This type is part of the \l{XdgShellV5} extension and provides a way to extend
* the functionality of an existing WaylandSurface for handling popup surfaces created by clients
* using xdg-shell.
*
* It corresponds to the Wayland interface \c xdg_popup for the unstable xdg-shell protocol v5.
*
* \deprecated
*/
/*!
* \class QWaylandXdgPopupV5
* \inmodule QtWaylandCompositor
* \since 5.8
* \obsolete
* \brief The QWaylandXdgPopupV5 class provides menus for an xdg surface.
*
* This class is part of the QWaylandXdgShellV5 extension and provides a way to
* extend the functionality of an existing QWaylandSurface with features
* specific to desktop-style menus for an xdg surface.
*
* It corresponds to the Wayland interface xdg_popup.
*
* \deprecated
*/
/*!
* Constructs a QWaylandXdgPopupV5.
*/
QWaylandXdgPopupV5::QWaylandXdgPopupV5()
: QWaylandShellSurfaceTemplate<QWaylandXdgPopupV5>(*new QWaylandXdgPopupV5Private)
{
}
/*!
* Constructs a QWaylandXdgPopupV5, associating it with \a xdgShell at the specified \a position
* for \a surface, and initializes it with the given \a parentSurface and \a resource.
*/
QWaylandXdgPopupV5::QWaylandXdgPopupV5(QWaylandXdgShellV5 *xdgShell, QWaylandSurface *surface,
QWaylandSurface *parentSurface, const QPoint &position, const QWaylandResource &resource)
: QWaylandShellSurfaceTemplate<QWaylandXdgPopupV5>(*new QWaylandXdgPopupV5Private)
{
initialize(xdgShell, surface, parentSurface, position, resource);
}
/*!
* \qmlmethod void QtWaylandCompositor::XdgPopupV5::initialize(XdgShellV5 shell, WaylandSurface surface, WaylandSurface parentSurface, point position, WaylandResource resource)
*
* Initializes the xdg popup, associating it with the given \a shell, \a surface,
* \a parentSurface, \a position and \a resource.
*/
/*!
* Initializes the QWaylandXdgPopupV5, associating it with the given \a shell, \a surface,
* \a parentSurface, \a position, and \a resource.
*/
void QWaylandXdgPopupV5::initialize(QWaylandXdgShellV5 *shell, QWaylandSurface *surface, QWaylandSurface *parentSurface,
const QPoint& position, const QWaylandResource &resource)
{
Q_D(QWaylandXdgPopupV5);
d->m_surface = surface;
d->m_parentSurface = parentSurface;
d->m_xdgShell = shell;
d->m_position = position;
d->init(resource.resource());
setExtensionContainer(surface);
emit shellChanged();
emit surfaceChanged();
emit parentSurfaceChanged();
emit positionChanged();
QWaylandCompositorExtension::initialize();
}
/*!
* \qmlproperty XdgShellV5 QtWaylandCompositor::XdgPopupV5::shell
*
* This property holds the shell associated with this XdgPopupV5.
*/
/*!
* \property QWaylandXdgPopupV5::shell
*
* This property holds the shell associated with this QWaylandXdgPopupV5.
*/
QWaylandXdgShellV5 *QWaylandXdgPopupV5::shell() const
{
Q_D(const QWaylandXdgPopupV5);
return d->m_xdgShell;
}
/*!
* \qmlproperty WaylandSurface QtWaylandCompositor::XdgPopupV5::surface
*
* This property holds the surface associated with this XdgPopupV5.
*/
/*!
* \property QWaylandXdgPopupV5::surface
*
* This property holds the surface associated with this QWaylandXdgPopupV5.
*/
QWaylandSurface *QWaylandXdgPopupV5::surface() const
{
Q_D(const QWaylandXdgPopupV5);
return d->m_surface;
}
/*!
* \qmlproperty WaylandSurface QtWaylandCompositor::XdgPopupV5::parentSurface
*
* This property holds the surface associated with the parent of this XdgPopupV5.
*/
/*!
* \property QWaylandXdgPopupV5::parentSurface
*
* This property holds the surface associated with the parent of this
* QWaylandXdgPopupV5.
*/
QWaylandSurface *QWaylandXdgPopupV5::parentSurface() const
{
Q_D(const QWaylandXdgPopupV5);
return d->m_parentSurface;
}
/*!
* \qmlproperty point QtWaylandCompositor::XdgPopupV5::position
*
* This property holds the location of the upper left corner of the surface
* relative to the upper left corner of the parent surface, in surface local
* coordinates.
*/
/*!
* \property QWaylandXdgPopupV5::position
*
* This property holds the location of the upper left corner of the surface
* relative to the upper left corner of the parent surface, in surface local
* coordinates.
*/
QPoint QWaylandXdgPopupV5::position() const
{
Q_D(const QWaylandXdgPopupV5);
return d->m_position;
}
/*!
* \internal
*/
void QWaylandXdgPopupV5::initialize()
{
QWaylandCompositorExtension::initialize();
}
/*!
* Returns the Wayland interface for the QWaylandXdgPopupV5.
*/
const wl_interface *QWaylandXdgPopupV5::interface()
{
return QWaylandXdgPopupV5Private::interface();
}
QByteArray QWaylandXdgPopupV5::interfaceName()
{
return QWaylandXdgPopupV5Private::interfaceName();
}
/*!
* Returns the surface role for the QWaylandXdgPopupV5.
*/
QWaylandSurfaceRole *QWaylandXdgPopupV5::role()
{
return &QWaylandXdgPopupV5Private::s_role;
}
QWaylandXdgPopupV5 *QWaylandXdgPopupV5::fromResource(wl_resource *resource)
{
if (auto p = QtWayland::fromResource<QWaylandXdgPopupV5Private *>(resource))
return p->q_func();
return nullptr;
}
void QWaylandXdgPopupV5::sendPopupDone()
{
Q_D(QWaylandXdgPopupV5);
d->send_popup_done();
}
#if QT_CONFIG(wayland_compositor_quick)
QWaylandQuickShellIntegration *QWaylandXdgPopupV5::createIntegration(QWaylandQuickShellSurfaceItem *item)
{
return new QtWayland::XdgPopupV5Integration(item);
}
#endif
#endif // QT_DEPRECATED_SINCE(5, 15)
QT_END_NAMESPACE
|