8#include <QtWaylandCompositor/qwaylandquickshellsurfaceitem.h>
12QPointF QWaylandQtShellChromePrivate::constrainPoint(
const QPointF &point)
const
14 float x0 = maximizedRect.left();
15 float y0 = maximizedRect.top();
16 float x1 = maximizedRect.right();
17 float y1 = maximizedRect.bottom();
18 return QPoint(qBound(x0, point.x(), x1),
19 qBound(y0, point.y(), y1));
23 const QQuickHandlerPoint ¢roid)
25 if (shellSurface ==
nullptr)
28 if (decorationInteraction == quint8(DecorationInteraction::None)) {
29 decorationInteraction = flags;
30 decorationInteractionPosition = centroid.scenePressPosition();
31 decorationInteractionGeometry = shellSurface->windowGeometry();
34 if (decorationInteraction != flags)
37 QPointF position = constrainPoint(centroid.scenePosition());
38 float dx = position.x() - decorationInteractionPosition.x();
39 float dy = position.y() - decorationInteractionPosition.y();
41 float minWidth = qMax(0, shellSurface->minimumSize().width());
42 float minHeight = qMax(0, shellSurface->minimumSize().height());
44 float maxWidth = shellSurface->maximumSize().width();
45 float maxHeight = shellSurface->maximumSize().height();
47 float minX = maxWidth >= 0.0f
48 ? decorationInteractionGeometry.right() - maxWidth
50 float minY = maxHeight >= 0.0f
51 ? decorationInteractionGeometry.bottom() - maxHeight
53 float maxX = maxWidth >= 0
54 ? decorationInteractionGeometry.left() + maxWidth
56 float maxY = maxHeight >= 0.0f
57 ? decorationInteractionGeometry.top() + maxHeight
60 float newLeft = decorationInteractionGeometry.left();
62 newLeft = qBound(minX,
64 float(decorationInteractionGeometry.right() - minWidth));
67 float newTop = decorationInteractionGeometry.top();
71 decorationInteractionGeometry.bottom() + minHeight);
74 float newRight = decorationInteractionGeometry.right();
76 newRight = qBound(decorationInteractionGeometry.left() + minWidth,
81 float newBottom = decorationInteractionGeometry.bottom();
83 newBottom = qBound(decorationInteractionGeometry.top() + minHeight,
88 shellSurface->requestWindowGeometry(shellSurface->windowState(),
89 QRect(
int(newLeft),
int(newTop),
90 int(newRight - newLeft),
int(newBottom - newTop)));
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117QWaylandQtShellChrome::QWaylandQtShellChrome(QQuickItem *parent)
118 : QQuickItem(*
new QWaylandQtShellChromePrivate{}, parent)
123QWaylandQtShellChrome::QWaylandQtShellChrome(QWaylandQtShellChromePrivate &dd,
125 : QQuickItem(dd, parent)
130QWaylandQtShellChrome::~QWaylandQtShellChrome()
132 Q_D(QWaylandQtShellChrome);
133 if (d->shell !=
nullptr)
134 d->shell->unregisterChrome(
this);
137void QWaylandQtShellChrome::init()
139 connect(
this, &QWaylandQtShellChrome::currentWindowStateChanged,
140 this, &QWaylandQtShellChrome::windowMetaInfoChanged);
142 connect(
this, &QWaylandQtShellChrome::currentWindowFlagsChanged,
143 this, &QWaylandQtShellChrome::windowMetaInfoChanged);
145 connect(
this, &QWaylandQtShellChrome::windowMetaInfoChanged,
146 this, &QWaylandQtShellChrome::updateDecorations);
148 connect(
this, &QWaylandQtShellChrome::leftResizeHandleChanged,
149 this, &QWaylandQtShellChrome::updateDecorations);
151 connect(
this, &QWaylandQtShellChrome::rightResizeHandleChanged,
152 this, &QWaylandQtShellChrome::updateDecorations);
154 connect(
this, &QWaylandQtShellChrome::topResizeHandleChanged,
155 this, &QWaylandQtShellChrome::updateDecorations);
157 connect(
this, &QWaylandQtShellChrome::bottomResizeHandleChanged,
158 this, &QWaylandQtShellChrome::updateDecorations);
160 connect(
this, &QWaylandQtShellChrome::topLeftResizeHandleChanged,
161 this, &QWaylandQtShellChrome::updateDecorations);
163 connect(
this, &QWaylandQtShellChrome::bottomLeftResizeHandleChanged,
164 this, &QWaylandQtShellChrome::updateDecorations);
166 connect(
this, &QWaylandQtShellChrome::topRightResizeHandleChanged,
167 this, &QWaylandQtShellChrome::updateDecorations);
169 connect(
this, &QWaylandQtShellChrome::bottomRightResizeHandleChanged,
170 this, &QWaylandQtShellChrome::updateDecorations);
174
175
176
177
178
179void QWaylandQtShellChrome::toggleFullScreen()
181 Q_D(QWaylandQtShellChrome);
182 if (d->shellSurface ==
nullptr)
186 if ((d->shellSurface->windowState() & Qt::WindowFullScreen) == Qt::WindowFullScreen)
187 newState = d->currentState & ~Qt::WindowFullScreen;
189 newState = d->currentState | Qt::WindowFullScreen;
191 if ((newState & (Qt::WindowMinimized | Qt::WindowMaximized)) != 0)
192 newState &= ~(Qt::WindowMinimized | Qt::WindowMaximized);
194 setWindowState(newState);
198
199
200
201
202
203void QWaylandQtShellChrome::toggleMaximized()
205 Q_D(QWaylandQtShellChrome);
206 if (d->shellSurface ==
nullptr)
210 if ((d->shellSurface->windowState() & Qt::WindowMaximized) == Qt::WindowMaximized)
211 newState = d->currentState & ~Qt::WindowMaximized;
213 newState = d->currentState | Qt::WindowMaximized;
215 if ((newState & Qt::WindowMinimized) == Qt::WindowMinimized)
216 newState &= ~Qt::WindowMinimized;
218 setWindowState(newState);
222
223
224
225
226
227void QWaylandQtShellChrome::toggleMinimized()
229 Q_D(QWaylandQtShellChrome);
230 if (d->shellSurface ==
nullptr)
234 if ((d->shellSurface->windowState() & Qt::WindowMinimized) == Qt::WindowMinimized)
235 newState = d->currentState & ~Qt::WindowMinimized;
237 newState = d->currentState | Qt::WindowMinimized;
239 if ((newState & Qt::WindowMaximized) == Qt::WindowMaximized)
240 newState &= ~Qt::WindowMaximized;
242 setWindowState(newState);
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
266
267
268
269
270
271
272
273void QWaylandQtShellChrome::setShellSurfaceItem(QWaylandQuickShellSurfaceItem *shellSurfaceItem)
275 Q_D(QWaylandQtShellChrome);
276 if (d->shellSurfaceItem == shellSurfaceItem)
279 if (d->shellSurfaceItem !=
nullptr)
280 d->shellSurfaceItem->disconnect(
this);
282 d->shellSurfaceItem = shellSurfaceItem;
284 if (d->shellSurfaceItem !=
nullptr) {
285 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::shellSurfaceChanged,
286 this, &QWaylandQtShellChrome::updateShellSurface);
287 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::surfaceDestroyed,
288 this, &QWaylandQtShellChrome::clientDestroyed);
291 updateShellSurface();
292 emit shellSurfaceItemChanged();
295QWaylandQuickShellSurfaceItem *QWaylandQtShellChrome::shellSurfaceItem()
const
297 Q_D(
const QWaylandQtShellChrome);
298 return d->shellSurfaceItem;
301void QWaylandQtShellChrome::stopGrab()
303 Q_D(QWaylandQtShellChrome);
304 d->decorationInteraction = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None);
307void QWaylandQtShellChrome::leftResize()
309 Q_D(QWaylandQtShellChrome);
310 if (!d->leftResizeHandleHandler->active())
313 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound),
314 d->leftResizeHandleHandler->centroid());
317void QWaylandQtShellChrome::rightResize()
319 Q_D(QWaylandQtShellChrome);
320 if (!d->rightResizeHandleHandler->active())
323 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound),
324 d->rightResizeHandleHandler->centroid());
327void QWaylandQtShellChrome::topResize()
329 Q_D(QWaylandQtShellChrome);
330 if (!d->topResizeHandleHandler->active())
333 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
334 d->topResizeHandleHandler->centroid());
337void QWaylandQtShellChrome::bottomResize()
339 Q_D(QWaylandQtShellChrome);
340 if (!d->bottomResizeHandleHandler->active())
343 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
344 d->bottomResizeHandleHandler->centroid());
347void QWaylandQtShellChrome::topLeftResize()
349 Q_D(QWaylandQtShellChrome);
350 if (!d->topLeftResizeHandleHandler->active())
353 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
354 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
355 d->topLeftResizeHandleHandler->centroid());
358void QWaylandQtShellChrome::topRightResize()
360 Q_D(QWaylandQtShellChrome);
361 if (!d->topRightResizeHandleHandler->active())
364 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
365 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
366 d->topRightResizeHandleHandler->centroid());
369void QWaylandQtShellChrome::bottomLeftResize()
371 Q_D(QWaylandQtShellChrome);
372 if (!d->bottomLeftResizeHandleHandler->active())
375 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
376 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
377 d->bottomLeftResizeHandleHandler->centroid());
380void QWaylandQtShellChrome::bottomRightResize()
382 Q_D(QWaylandQtShellChrome);
383 if (!d->bottomRightResizeHandleHandler->active())
386 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
387 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
388 d->bottomRightResizeHandleHandler->centroid());
391void QWaylandQtShellChrome::titleBarMove()
393 Q_D(QWaylandQtShellChrome);
394 if (!d->titleBarHandler->active())
397 quint8 flags = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::TitleBar);
398 QQuickHandlerPoint centroid = d->titleBarHandler->centroid();
399 if (d->decorationInteraction == quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None)) {
400 d->decorationInteraction = flags;
401 d->decorationInteractionPosition = d->shellSurface->windowPosition() - centroid.scenePressPosition();
406 if (d->decorationInteraction != flags)
409 QPointF position = d->constrainPoint(centroid.scenePosition());
410 d->shellSurface->setWindowPosition((position + d->decorationInteractionPosition).toPoint());
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
449
450
451
452
453
454
455
456
457
458QQuickItem *QWaylandQtShellChrome::titleBar()
const
460 Q_D(
const QWaylandQtShellChrome);
464void QWaylandQtShellChrome::setTitleBar(QQuickItem *item)
466 Q_D(QWaylandQtShellChrome);
467 if (d->titleBar == item)
470 if (d->titleBar !=
nullptr) {
471 d->titleBar->disconnect(
this);
473 delete d->titleBarHandler;
474 d->titleBarHandler =
nullptr;
479 if (d->titleBar !=
nullptr) {
480 connect(d->titleBar, &QQuickItem::heightChanged,
481 this, &QWaylandQtShellChrome::updateDecorations);
483 d->titleBarHandler =
new QQuickDragHandler(d->titleBar);
484 d->titleBarHandler->setTarget(
nullptr);
486 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
487 this, &QWaylandQtShellChrome::stopGrab);
488 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
489 this, &QWaylandQtShellChrome::activateOnGrab);
490 connect(d->titleBarHandler, &QQuickMultiPointHandler::centroidChanged,
491 this, &QWaylandQtShellChrome::titleBarMove);
494 emit titleBarChanged();
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
525
526
527
528
529
530
531
532
533
534
535
536
537QQuickItem *QWaylandQtShellChrome::leftResizeHandle()
const
539 Q_D(
const QWaylandQtShellChrome);
540 return d->leftResizeHandle;
543void QWaylandQtShellChrome::setLeftResizeHandle(QQuickItem *item)
545 Q_D(QWaylandQtShellChrome);
546 if (d->leftResizeHandle == item)
549 if (d->leftResizeHandle !=
nullptr) {
550 d->leftResizeHandle->disconnect(
this);
552 delete d->leftResizeHandleHandler;
553 d->leftResizeHandleHandler =
nullptr;
556 d->leftResizeHandle = item;
558 if (d->leftResizeHandle !=
nullptr) {
559 connect(d->leftResizeHandle, &QQuickItem::widthChanged,
560 this, &QWaylandQtShellChrome::updateDecorations);
562 d->leftResizeHandleHandler =
new QQuickDragHandler(d->leftResizeHandle);
563 d->leftResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
564 d->leftResizeHandleHandler->setTarget(
nullptr);
566 connect(d->leftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
567 this, &QWaylandQtShellChrome::stopGrab);
568 connect(d->leftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
569 this, &QWaylandQtShellChrome::leftResize);
572 emit leftResizeHandleChanged();
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
603
604
605
606
607
608
609
610
611
612
613
614
615QQuickItem *QWaylandQtShellChrome::rightResizeHandle()
const
617 Q_D(
const QWaylandQtShellChrome);
618 return d->rightResizeHandle;
621void QWaylandQtShellChrome::setRightResizeHandle(QQuickItem *item)
623 Q_D(QWaylandQtShellChrome);
624 if (d->rightResizeHandle == item)
627 if (d->rightResizeHandle !=
nullptr) {
628 d->rightResizeHandle->disconnect(
this);
630 delete d->rightResizeHandleHandler;
631 d->rightResizeHandleHandler =
nullptr;
634 d->rightResizeHandle = item;
636 if (d->rightResizeHandle !=
nullptr) {
637 connect(d->rightResizeHandle, &QQuickItem::widthChanged,
638 this, &QWaylandQtShellChrome::updateDecorations);
640 d->rightResizeHandleHandler =
new QQuickDragHandler(d->rightResizeHandle);
641 d->rightResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
642 d->rightResizeHandleHandler->setTarget(
nullptr);
644 connect(d->rightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
645 this, &QWaylandQtShellChrome::stopGrab);
646 connect(d->rightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
647 this, &QWaylandQtShellChrome::rightResize);
650 emit rightResizeHandleChanged();
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
681
682
683
684
685
686
687
688
689
690
691
692
693QQuickItem *QWaylandQtShellChrome::topResizeHandle()
const
695 Q_D(
const QWaylandQtShellChrome);
696 return d->topResizeHandle;
699void QWaylandQtShellChrome::setTopResizeHandle(QQuickItem *item)
701 Q_D(QWaylandQtShellChrome);
702 if (d->topResizeHandle == item)
705 if (d->topResizeHandle !=
nullptr) {
706 d->topResizeHandle->disconnect(
this);
708 delete d->topResizeHandleHandler;
709 d->topResizeHandleHandler =
nullptr;
712 d->topResizeHandle = item;
714 if (d->topResizeHandle !=
nullptr) {
715 connect(d->topResizeHandle, &QQuickItem::heightChanged,
716 this, &QWaylandQtShellChrome::updateDecorations);
718 d->topResizeHandleHandler =
new QQuickDragHandler(d->topResizeHandle);
719 d->topResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
720 d->topResizeHandleHandler->setTarget(
nullptr);
722 connect(d->topResizeHandleHandler, &QQuickPointerHandler::grabChanged,
723 this, &QWaylandQtShellChrome::stopGrab);
724 connect(d->topResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
725 this, &QWaylandQtShellChrome::topResize);
728 emit topResizeHandleChanged();
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
759
760
761
762
763
764
765
766
767
768
769
770
771QQuickItem *QWaylandQtShellChrome::bottomResizeHandle()
const
773 Q_D(
const QWaylandQtShellChrome);
774 return d->bottomResizeHandle;
777void QWaylandQtShellChrome::setBottomResizeHandle(QQuickItem *item)
779 Q_D(QWaylandQtShellChrome);
780 if (d->bottomResizeHandle == item)
783 if (d->bottomResizeHandle !=
nullptr) {
784 d->bottomResizeHandle->disconnect(
this);
786 delete d->bottomResizeHandleHandler;
787 d->bottomResizeHandleHandler =
nullptr;
790 d->bottomResizeHandle = item;
792 if (d->bottomResizeHandle !=
nullptr) {
793 connect(d->bottomResizeHandle, &QQuickItem::heightChanged,
794 this, &QWaylandQtShellChrome::updateDecorations);
796 d->bottomResizeHandleHandler =
new QQuickDragHandler(d->bottomResizeHandle);
797 d->bottomResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
798 d->bottomResizeHandleHandler->setTarget(
nullptr);
800 connect(d->bottomResizeHandleHandler, &QQuickPointerHandler::grabChanged,
801 this, &QWaylandQtShellChrome::stopGrab);
802 connect(d->bottomResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
803 this, &QWaylandQtShellChrome::bottomResize);
807 emit bottomResizeHandleChanged();
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
836
837
838
839
840
841
842
843
844
845
846QQuickItem *QWaylandQtShellChrome::topLeftResizeHandle()
const
848 Q_D(
const QWaylandQtShellChrome);
849 return d->topLeftResizeHandle;
852void QWaylandQtShellChrome::setTopLeftResizeHandle(QQuickItem *item)
854 Q_D(QWaylandQtShellChrome);
855 if (d->topLeftResizeHandle == item)
858 if (d->topLeftResizeHandle !=
nullptr) {
859 delete d->topLeftResizeHandleHandler;
860 d->topLeftResizeHandleHandler =
nullptr;
863 d->topLeftResizeHandle = item;
865 if (d->topLeftResizeHandle !=
nullptr) {
866 d->topLeftResizeHandleHandler =
new QQuickDragHandler(d->topLeftResizeHandle);
867 d->topLeftResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
868 d->topLeftResizeHandleHandler->setTarget(
nullptr);
870 connect(d->topLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
871 this, &QWaylandQtShellChrome::stopGrab);
872 connect(d->topLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
873 this, &QWaylandQtShellChrome::topLeftResize);
876 emit topLeftResizeHandleChanged();
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
905
906
907
908
909
910
911
912
913
914
915QQuickItem *QWaylandQtShellChrome::bottomLeftResizeHandle()
const
917 Q_D(
const QWaylandQtShellChrome);
918 return d->bottomLeftResizeHandle;
921void QWaylandQtShellChrome::setBottomLeftResizeHandle(QQuickItem *item)
923 Q_D(QWaylandQtShellChrome);
924 if (d->bottomLeftResizeHandle == item)
927 if (d->bottomLeftResizeHandle !=
nullptr) {
928 delete d->bottomLeftResizeHandleHandler;
929 d->bottomLeftResizeHandleHandler =
nullptr;
932 d->bottomLeftResizeHandle = item;
934 if (d->bottomLeftResizeHandle !=
nullptr) {
935 d->bottomLeftResizeHandleHandler =
new QQuickDragHandler(d->bottomLeftResizeHandle);
936 d->bottomLeftResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
937 d->bottomLeftResizeHandleHandler->setTarget(
nullptr);
939 connect(d->bottomLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
940 this, &QWaylandQtShellChrome::stopGrab);
941 connect(d->bottomLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
942 this, &QWaylandQtShellChrome::bottomLeftResize);
945 emit bottomLeftResizeHandleChanged();
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
974
975
976
977
978
979
980
981
982
983
984QQuickItem *QWaylandQtShellChrome::topRightResizeHandle()
const
986 Q_D(
const QWaylandQtShellChrome);
987 return d->topRightResizeHandle;
990void QWaylandQtShellChrome::setTopRightResizeHandle(QQuickItem *item)
992 Q_D(QWaylandQtShellChrome);
993 if (d->topRightResizeHandle == item)
996 if (d->topRightResizeHandle !=
nullptr) {
997 delete d->topRightResizeHandleHandler;
998 d->topRightResizeHandleHandler =
nullptr;
1001 d->topRightResizeHandle = item;
1003 if (d->topRightResizeHandle !=
nullptr) {
1004 d->topRightResizeHandleHandler =
new QQuickDragHandler(d->topRightResizeHandle);
1005 d->topRightResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
1006 d->topRightResizeHandleHandler->setTarget(
nullptr);
1008 connect(d->topRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
1009 this, &QWaylandQtShellChrome::stopGrab);
1010 connect(d->topRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
1011 this, &QWaylandQtShellChrome::topRightResize);
1014 emit topRightResizeHandleChanged();
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053QQuickItem *QWaylandQtShellChrome::bottomRightResizeHandle()
const
1055 Q_D(
const QWaylandQtShellChrome);
1056 return d->bottomRightResizeHandle;
1059void QWaylandQtShellChrome::setBottomRightResizeHandle(QQuickItem *item)
1061 Q_D(QWaylandQtShellChrome);
1062 if (d->bottomRightResizeHandle == item)
1065 if (d->bottomRightResizeHandle !=
nullptr) {
1066 delete d->bottomRightResizeHandleHandler;
1067 d->bottomRightResizeHandleHandler =
nullptr;
1070 d->bottomRightResizeHandle = item;
1072 if (d->bottomRightResizeHandle !=
nullptr) {
1073 d->bottomRightResizeHandleHandler =
new QQuickDragHandler(d->bottomRightResizeHandle);
1074 d->bottomRightResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
1075 d->bottomRightResizeHandleHandler->setTarget(
nullptr);
1077 connect(d->bottomRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
1078 this, &QWaylandQtShellChrome::stopGrab);
1079 connect(d->bottomRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
1080 this, &QWaylandQtShellChrome::bottomRightResize);
1083 emit bottomRightResizeHandleChanged();
1087
1088
1089
1090
1091
1092
1093
1094
1097
1098
1099
1100
1101
1102
1103
1104
1105void QWaylandQtShellChrome::setMaximizedRect(
const QRect &rect)
1107 Q_D(QWaylandQtShellChrome);
1108 if (d->maximizedRect == rect)
1111 d->maximizedRect = rect;
1112 emit maximizedRectChanged();
1115QRect QWaylandQtShellChrome::maximizedRect()
const
1117 Q_D(
const QWaylandQtShellChrome);
1118 if (d->maximizedRect.isValid())
1119 return d->maximizedRect;
1120 else if (d->shellSurfaceItem !=
nullptr && d->shellSurfaceItem->output() !=
nullptr)
1121 return d->shellSurfaceItem->output()->geometry();
1126void QWaylandQtShellChrome::updateDecorations()
1128 Q_D(QWaylandQtShellChrome);
1129 if (d->shellSurface ==
nullptr)
1132 bool decorations = hasDecorations();
1133 bool titleBarShowing = hasTitleBar();
1136 if (d->automaticFrameMargins) {
1137 if (d->leftResizeHandle !=
nullptr && decorations)
1138 margins.setLeft(d->leftResizeHandle->width());
1139 if (d->rightResizeHandle !=
nullptr && decorations)
1140 margins.setRight(d->rightResizeHandle->width());
1141 if (d->bottomResizeHandle !=
nullptr && decorations)
1142 margins.setBottom(d->bottomResizeHandle->height());
1144 margins.setTop((decorations && d->topResizeHandle !=
nullptr ? d->topResizeHandle->height() : 0)
1145 + (titleBarShowing && d->titleBar !=
nullptr ? d->titleBar->height() : 0));
1147 margins = d->explicitFrameMargins;
1149 d->shellSurface->setFrameMargins(margins);
1151 if (d->titleBar !=
nullptr)
1152 d->titleBar->setVisible(titleBarShowing);
1153 if (d->leftResizeHandle !=
nullptr)
1154 d->leftResizeHandle->setVisible(decorations);
1155 if (d->rightResizeHandle !=
nullptr)
1156 d->rightResizeHandle->setVisible(decorations);
1157 if (d->topResizeHandle !=
nullptr)
1158 d->topResizeHandle->setVisible(decorations);
1159 if (d->bottomResizeHandle !=
nullptr)
1160 d->bottomResizeHandle->setVisible(decorations);
1161 if (d->bottomLeftResizeHandle !=
nullptr)
1162 d->bottomLeftResizeHandle->setVisible(decorations);
1163 if (d->topLeftResizeHandle !=
nullptr)
1164 d->topLeftResizeHandle->setVisible(decorations);
1165 if (d->bottomRightResizeHandle !=
nullptr)
1166 d->bottomRightResizeHandle->setVisible(decorations);
1167 if (d->topRightResizeHandle !=
nullptr)
1168 d->topRightResizeHandle->setVisible(decorations);
1170 bool minimizedOrMaximized = (d->currentState & (Qt::WindowMaximized|Qt::WindowMinimized)) != 0;
1171 if (d->leftResizeHandleHandler !=
nullptr)
1172 d->leftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1173 if (d->rightResizeHandleHandler !=
nullptr)
1174 d->rightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1175 if (d->bottomResizeHandleHandler !=
nullptr)
1176 d->bottomResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1177 if (d->topResizeHandleHandler !=
nullptr)
1178 d->topResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1179 if (d->bottomLeftResizeHandleHandler !=
nullptr)
1180 d->bottomLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1181 if (d->bottomRightResizeHandleHandler !=
nullptr)
1182 d->bottomRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1183 if (d->topLeftResizeHandleHandler !=
nullptr)
1184 d->topLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1185 if (d->topRightResizeHandleHandler !=
nullptr)
1186 d->topRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1187 if (d->titleBarHandler !=
nullptr)
1188 d->titleBarHandler->setEnabled(titleBarShowing && !minimizedOrMaximized);
1191void QWaylandQtShellChrome::updateGeometry()
1193 Q_D(QWaylandQtShellChrome);
1194 if (d->shellSurface ==
nullptr)
1197 QRect windowGeometry = d->shellSurface->windowGeometry();
1199 QPointF position = windowGeometry.topLeft();
1200 position.rx() -= d->shellSurface->frameMarginLeft();
1201 position.ry() -= d->shellSurface->frameMarginTop();
1203 QSizeF size = windowGeometry.size();
1204 size.rwidth() += d->shellSurface->frameMarginLeft() + d->shellSurface->frameMarginRight();
1205 size.rheight() += d->shellSurface->frameMarginTop() + d->shellSurface->frameMarginBottom();
1207 setPosition(position);
1211void QWaylandQtShellChrome::updateSurface()
1213 Q_D(QWaylandQtShellChrome);
1214 QWaylandSurface *surface = d->shellSurface !=
nullptr ? d->shellSurface->surface() :
nullptr;
1215 if (d->surface == surface)
1218 if (d->surface !=
nullptr)
1219 d->surface->disconnect(
this);
1221 d->surface = surface;
1223 if (d->surface !=
nullptr) {
1224 connect(d->surface, &QWaylandSurface::hasContentChanged,
1225 this, &QWaylandQtShellChrome::updateAutomaticPosition);
1229void QWaylandQtShellChrome::updateShellSurface()
1231 Q_D(QWaylandQtShellChrome);
1232 QWaylandQtShellSurface *sf = d->shellSurfaceItem !=
nullptr
1233 ? qobject_cast<QWaylandQtShellSurface *>(d->shellSurfaceItem->shellSurface())
1235 if (d->shellSurface == sf)
1238 if (d->shellSurface !=
nullptr) {
1239 d->shellSurface->disconnect(
this);
1240 if (d->shell !=
nullptr)
1241 d->shell->unregisterChrome(
this);
1245 d->shellSurface = sf;
1246 if (d->shellSurface !=
nullptr) {
1247 d->shell = d->shellSurface->shell();
1248 if (d->shell !=
nullptr)
1249 d->shell->registerChrome(
this);
1251 updateWindowFlags();
1252 connect(d->shellSurface, &QWaylandQtShellSurface::windowFlagsChanged,
1253 this, &QWaylandQtShellChrome::updateWindowFlags);
1254 connect(d->shellSurface, &QWaylandQtShellSurface::windowStateChanged,
1255 this, &QWaylandQtShellChrome::updateWindowState);
1256 connect(d->shellSurface, &QWaylandQtShellSurface::frameMarginChanged,
1257 this, &QWaylandQtShellChrome::updateGeometry);
1258 connect(d->shellSurface, &QWaylandQtShellSurface::windowGeometryChanged,
1259 this, &QWaylandQtShellChrome::updateGeometry);
1260 connect(d->shellSurface, &QWaylandQtShellSurface::raiseRequested,
1261 this, &QWaylandQtShellChrome::raise);
1262 connect(d->shellSurface, &QWaylandQtShellSurface::lowerRequested,
1263 this, &QWaylandQtShellChrome::lower);
1264 connect(d->shellSurface, &QWaylandQtShellSurface::activeChanged,
1265 this, &QWaylandQtShellChrome::updateActiveState);
1266 connect(d->shellSurface, &QWaylandQtShellSurface::surfaceChanged,
1267 this, &QWaylandQtShellChrome::updateSurface);
1270 updateDecorations();
1274void QWaylandQtShellChrome::updateWindowState()
1276 Q_D(QWaylandQtShellChrome);
1277 if (d->shellSurface ==
nullptr)
1280 setWindowState(d->shellSurface->windowState());
1283void QWaylandQtShellChrome::updateWindowFlags()
1285 Q_D(QWaylandQtShellChrome);
1287 uint nextFlags = d->shellSurface ==
nullptr || d->shellSurface->windowFlags() == Qt::Window
1289 : d->shellSurface->windowFlags();
1291 if (d->currentFlags != nextFlags) {
1292 d->currentFlags = nextFlags;
1293 emit currentWindowFlagsChanged();
1298
1299
1300
1301
1302
1303
1304
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316uint QWaylandQtShellChrome::currentWindowFlags()
const
1318 Q_D(
const QWaylandQtShellChrome);
1319 return d->currentFlags;
1323
1324
1325
1326
1327
1328
1329
1332
1333
1334
1335
1336
1337
1338
1339
1340uint QWaylandQtShellChrome::currentWindowState()
const
1342 Q_D(
const QWaylandQtShellChrome);
1343 return d->currentState;
1346bool QWaylandQtShellChrome::hasTitleBar()
const
1348 Q_D(
const QWaylandQtShellChrome);
1350 bool frameless = (d->currentFlags & Qt::FramelessWindowHint) == Qt::FramelessWindowHint
1351 || ((d->currentFlags & Qt::Popup) == Qt::Popup
1352 && (d->currentFlags & Qt::Tool) != Qt::Tool)
1353 || (d->currentState & Qt::WindowFullScreen) == Qt::WindowFullScreen;
1358
1359
1360
1361
1362
1365
1366
1367
1368
1369
1370bool QWaylandQtShellChrome::hasDecorations()
const
1372 Q_D(
const QWaylandQtShellChrome);
1374 return hasTitleBar() && (d->currentFlags & Qt::Window) == Qt::Window;
1377QRect QWaylandQtShellChrome::maxContentRect()
const
1379 Q_D(
const QWaylandQtShellChrome);
1380 if (d->shellSurface ==
nullptr)
1383 int x0 = d->maximizedRect.x() + d->shellSurface->frameMarginLeft();
1384 int x1 = d->maximizedRect.x() + d->maximizedRect.width() - d->shellSurface->frameMarginRight();
1385 int y0 = d->maximizedRect.y() + d->shellSurface->frameMarginTop();
1386 int y1 = d->maximizedRect.y() + d->maximizedRect.height() - d->shellSurface->frameMarginBottom();
1388 return QRect(x0, y0, x1 - x0, y1 - y0);
1393 return (windowSize >= screenSize) ? 0 : rand() % (screenSize - windowSize);
1396void QWaylandQtShellChrome::setWindowState(uint nextState)
1398 Q_D(QWaylandQtShellChrome);
1400 if (d->currentState == nextState)
1403 if (d->shellSurface ==
nullptr || d->shellSurfaceItem ==
nullptr)
1406 QWaylandOutput *output = d->shellSurfaceItem->output();
1407 if (output ==
nullptr)
1410 if ((d->currentState & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) == 0) {
1411 d->restoreGeometry = d->shellSurface->windowGeometry();
1414 d->currentState = nextState;
1415 emit currentWindowStateChanged();
1417 if ((nextState & Qt::WindowMinimized) != 0) {
1418 d->shellSurface->requestWindowGeometry(nextState, QRect(0, 0, 1, 1));
1419 d->shellSurfaceItem->setVisible(
false);
1421 }
else if ((nextState & Qt::WindowFullScreen) != 0) {
1422 d->shellSurfaceItem->setVisible(
true);
1423 d->shellSurface->requestWindowGeometry(nextState, QRect(QPoint(0, 0), output->window()->size()));
1425 }
else if ((nextState & Qt::WindowMaximized) != 0) {
1426 d->shellSurfaceItem->setVisible(
true);
1427 d->shellSurface->requestWindowGeometry(nextState, maxContentRect());
1430 d->shellSurfaceItem->setVisible(
true);
1431 d->shellSurface->requestWindowGeometry(nextState, d->restoreGeometry);
1436void QWaylandQtShellChrome::updateAutomaticPosition()
1438 Q_D(QWaylandQtShellChrome);
1439 if (!d->positionSet && d->shellSurface !=
nullptr) {
1440 bool randomize = d->shellSurface->positionAutomatic();
1441 QRect rect = d->shellSurface->windowGeometry();
1442 QRect space = maxContentRect();
1444 int xpos = randomize ? randomPos(rect.width(), space.width()) + space.x()
1445 : qMax(rect.x(), space.x());
1446 int ypos = randomize ? randomPos(rect.height(), space.height()) + space.y()
1447 : qMax(rect.y(), space.y());
1449 d->shellSurface->setWindowPosition(QPoint(xpos, ypos));
1450 d->positionSet =
true;
1455
1456
1457
1458
1459
1460void QWaylandQtShellChrome::deactivate()
1462 Q_D(QWaylandQtShellChrome);
1463 if (d->shellSurface !=
nullptr)
1464 d->shellSurface->setActive(
false);
1467void QWaylandQtShellChrome::activateOnGrab(QPointingDevice::GrabTransition transition)
1469 Q_D(QWaylandQtShellChrome);
1470 if (d->titleBarHandler !=
nullptr) {
1471 switch (transition) {
1472 case QPointingDevice::GrabPassive:
1473 case QPointingDevice::OverrideGrabPassive:
1474 case QPointingDevice::GrabExclusive:
1484
1485
1486
1487
1488
1489
1490void QWaylandQtShellChrome::activate()
1492 Q_D(QWaylandQtShellChrome);
1493 if (d->shellSurface !=
nullptr)
1494 d->shellSurface->setActive(
true);
1499
1500
1501
1502
1503
1504void QWaylandQtShellChrome::raise()
1506 Q_D(QWaylandQtShellChrome);
1507 if (d->shellSurfaceItem !=
nullptr)
1508 d->shellSurfaceItem->raise();
1512
1513
1514
1515
1516
1517void QWaylandQtShellChrome::lower()
1519 Q_D(QWaylandQtShellChrome);
1520 if (d->shellSurfaceItem !=
nullptr)
1521 d->shellSurfaceItem->lower();
1524void QWaylandQtShellChrome::updateActiveState()
1526 Q_D(QWaylandQtShellChrome);
1527 if (d->shellSurface ==
nullptr)
1530 if (d->shellSurface->active()) {
1539
1540
1541
1542
1543
1544
1545
1546
1547
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559void QWaylandQtShellChrome::setFrameMarginLeft(
int left)
1561 Q_D(QWaylandQtShellChrome);
1562 if (d->explicitFrameMargins.left() == left)
1565 d->explicitFrameMargins.setLeft(left);
1566 d->automaticFrameMargins =
false;
1567 updateDecorations();
1569 emit frameMarginChanged();
1572int QWaylandQtShellChrome::frameMarginLeft()
const
1574 Q_D(
const QWaylandQtShellChrome);
1575 if (d->shellSurface ==
nullptr)
1577 return d->shellSurface->frameMarginLeft();
1581
1582
1583
1584
1585
1586
1587
1588
1589
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601void QWaylandQtShellChrome::setFrameMarginRight(
int right)
1603 Q_D(QWaylandQtShellChrome);
1604 if (d->explicitFrameMargins.right() == right)
1607 d->explicitFrameMargins.setRight(right);
1608 d->automaticFrameMargins =
false;
1609 updateDecorations();
1611 emit frameMarginChanged();
1614int QWaylandQtShellChrome::frameMarginRight()
const
1616 Q_D(
const QWaylandQtShellChrome);
1617 if (d->shellSurface ==
nullptr)
1619 return d->shellSurface->frameMarginRight();
1623
1624
1625
1626
1627
1628
1629
1630
1631
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644void QWaylandQtShellChrome::setFrameMarginTop(
int top)
1646 Q_D(QWaylandQtShellChrome);
1647 if (d->explicitFrameMargins.top() == top)
1649 d->explicitFrameMargins.setTop(top);
1650 d->automaticFrameMargins =
false;
1651 updateDecorations();
1653 emit frameMarginChanged();
1656int QWaylandQtShellChrome::frameMarginTop()
const
1658 Q_D(
const QWaylandQtShellChrome);
1659 if (d->shellSurface ==
nullptr)
1661 return d->shellSurface->frameMarginTop();
1665
1666
1667
1668
1669
1670
1671
1672
1673
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685void QWaylandQtShellChrome::setFrameMarginBottom(
int bottom)
1687 Q_D(QWaylandQtShellChrome);
1688 if (d->explicitFrameMargins.bottom() == bottom)
1690 d->explicitFrameMargins.setBottom(bottom);
1691 d->automaticFrameMargins =
false;
1692 updateDecorations();
1694 emit frameMarginChanged();
1697int QWaylandQtShellChrome::frameMarginBottom()
const
1699 Q_D(
const QWaylandQtShellChrome);
1700 if (d->shellSurface ==
nullptr)
1702 return d->shellSurface->frameMarginBottom();
1707#include "moc_qwaylandqtshellchrome.cpp"
void updateDecorationInteraction(quint8 flags, const QQuickHandlerPoint ¢roid)
Combined button and popup list for selecting options.
static int randomPos(int windowSize, int screenSize)