9#include <QtWaylandCompositor/qwaylandquickshellsurfaceitem.h>
13QPointF QWaylandQtShellChromePrivate::constrainPoint(
const QPointF &point)
const
15 float x0 = maximizedRect.left();
16 float y0 = maximizedRect.top();
17 float x1 = maximizedRect.right();
18 float y1 = maximizedRect.bottom();
19 return QPoint(qBound(x0, point.x(), x1),
20 qBound(y0, point.y(), y1));
24 const QQuickHandlerPoint ¢roid)
26 if (shellSurface ==
nullptr)
29 if (decorationInteraction == quint8(DecorationInteraction::None)) {
30 decorationInteraction = flags;
31 decorationInteractionPosition = centroid.scenePressPosition();
32 decorationInteractionGeometry = shellSurface->windowGeometry();
35 if (decorationInteraction != flags)
38 QPointF position = constrainPoint(centroid.scenePosition());
39 float dx = position.x() - decorationInteractionPosition.x();
40 float dy = position.y() - decorationInteractionPosition.y();
42 float minWidth = qMax(0, shellSurface->minimumSize().width());
43 float minHeight = qMax(0, shellSurface->minimumSize().height());
45 float maxWidth = shellSurface->maximumSize().width();
46 float maxHeight = shellSurface->maximumSize().height();
48 float minX = maxWidth >= 0.0f
49 ? decorationInteractionGeometry.right() - maxWidth
51 float minY = maxHeight >= 0.0f
52 ? decorationInteractionGeometry.bottom() - maxHeight
54 float maxX = maxWidth >= 0
55 ? decorationInteractionGeometry.left() + maxWidth
57 float maxY = maxHeight >= 0.0f
58 ? decorationInteractionGeometry.top() + maxHeight
61 float newLeft = decorationInteractionGeometry.left();
63 newLeft = qBound(minX,
65 float(decorationInteractionGeometry.right() - minWidth));
68 float newTop = decorationInteractionGeometry.top();
72 decorationInteractionGeometry.bottom() + minHeight);
75 float newRight = decorationInteractionGeometry.right();
77 newRight = qBound(decorationInteractionGeometry.left() + minWidth,
82 float newBottom = decorationInteractionGeometry.bottom();
84 newBottom = qBound(decorationInteractionGeometry.top() + minHeight,
89 shellSurface->requestWindowGeometry(shellSurface->windowState(),
90 QRect(
int(newLeft),
int(newTop),
91 int(newRight - newLeft),
int(newBottom - newTop)));
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118QWaylandQtShellChrome::QWaylandQtShellChrome(QQuickItem *parent)
119 : QQuickItem(*
new QWaylandQtShellChromePrivate{}, parent)
124QWaylandQtShellChrome::QWaylandQtShellChrome(QWaylandQtShellChromePrivate &dd,
126 : QQuickItem(dd, parent)
131QWaylandQtShellChrome::~QWaylandQtShellChrome()
133 Q_D(QWaylandQtShellChrome);
134 if (d->shell !=
nullptr)
135 d->shell->unregisterChrome(
this);
138void QWaylandQtShellChrome::init()
140 connect(
this, &QWaylandQtShellChrome::currentWindowStateChanged,
141 this, &QWaylandQtShellChrome::windowMetaInfoChanged);
143 connect(
this, &QWaylandQtShellChrome::currentWindowFlagsChanged,
144 this, &QWaylandQtShellChrome::windowMetaInfoChanged);
146 connect(
this, &QWaylandQtShellChrome::windowMetaInfoChanged,
147 this, &QWaylandQtShellChrome::updateDecorations);
149 connect(
this, &QWaylandQtShellChrome::leftResizeHandleChanged,
150 this, &QWaylandQtShellChrome::updateDecorations);
152 connect(
this, &QWaylandQtShellChrome::rightResizeHandleChanged,
153 this, &QWaylandQtShellChrome::updateDecorations);
155 connect(
this, &QWaylandQtShellChrome::topResizeHandleChanged,
156 this, &QWaylandQtShellChrome::updateDecorations);
158 connect(
this, &QWaylandQtShellChrome::bottomResizeHandleChanged,
159 this, &QWaylandQtShellChrome::updateDecorations);
161 connect(
this, &QWaylandQtShellChrome::topLeftResizeHandleChanged,
162 this, &QWaylandQtShellChrome::updateDecorations);
164 connect(
this, &QWaylandQtShellChrome::bottomLeftResizeHandleChanged,
165 this, &QWaylandQtShellChrome::updateDecorations);
167 connect(
this, &QWaylandQtShellChrome::topRightResizeHandleChanged,
168 this, &QWaylandQtShellChrome::updateDecorations);
170 connect(
this, &QWaylandQtShellChrome::bottomRightResizeHandleChanged,
171 this, &QWaylandQtShellChrome::updateDecorations);
175
176
177
178
179
180void QWaylandQtShellChrome::toggleFullScreen()
182 Q_D(QWaylandQtShellChrome);
183 if (d->shellSurface ==
nullptr)
187 if ((d->shellSurface->windowState() & Qt::WindowFullScreen) == Qt::WindowFullScreen)
188 newState = d->currentState & ~Qt::WindowFullScreen;
190 newState = d->currentState | Qt::WindowFullScreen;
192 if ((newState & (Qt::WindowMinimized | Qt::WindowMaximized)) != 0)
193 newState &= ~(Qt::WindowMinimized | Qt::WindowMaximized);
195 setWindowState(newState);
199
200
201
202
203
204void QWaylandQtShellChrome::toggleMaximized()
206 Q_D(QWaylandQtShellChrome);
207 if (d->shellSurface ==
nullptr)
211 if ((d->shellSurface->windowState() & Qt::WindowMaximized) == Qt::WindowMaximized)
212 newState = d->currentState & ~Qt::WindowMaximized;
214 newState = d->currentState | Qt::WindowMaximized;
216 if ((newState & Qt::WindowMinimized) == Qt::WindowMinimized)
217 newState &= ~Qt::WindowMinimized;
219 setWindowState(newState);
223
224
225
226
227
228void QWaylandQtShellChrome::toggleMinimized()
230 Q_D(QWaylandQtShellChrome);
231 if (d->shellSurface ==
nullptr)
235 if ((d->shellSurface->windowState() & Qt::WindowMinimized) == Qt::WindowMinimized)
236 newState = d->currentState & ~Qt::WindowMinimized;
238 newState = d->currentState | Qt::WindowMinimized;
240 if ((newState & Qt::WindowMaximized) == Qt::WindowMaximized)
241 newState &= ~Qt::WindowMaximized;
243 setWindowState(newState);
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
267
268
269
270
271
272
273
274void QWaylandQtShellChrome::setShellSurfaceItem(QWaylandQuickShellSurfaceItem *shellSurfaceItem)
276 Q_D(QWaylandQtShellChrome);
277 if (d->shellSurfaceItem == shellSurfaceItem)
280 if (d->shellSurfaceItem !=
nullptr)
281 d->shellSurfaceItem->disconnect(
this);
283 d->shellSurfaceItem = shellSurfaceItem;
285 if (d->shellSurfaceItem !=
nullptr) {
286 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::shellSurfaceChanged,
287 this, &QWaylandQtShellChrome::updateShellSurface);
288 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::surfaceDestroyed,
289 this, &QWaylandQtShellChrome::clientDestroyed);
292 updateShellSurface();
293 emit shellSurfaceItemChanged();
296QWaylandQuickShellSurfaceItem *QWaylandQtShellChrome::shellSurfaceItem()
const
298 Q_D(
const QWaylandQtShellChrome);
299 return d->shellSurfaceItem;
302void QWaylandQtShellChrome::stopGrab()
304 Q_D(QWaylandQtShellChrome);
305 d->decorationInteraction = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None);
308void QWaylandQtShellChrome::leftResize()
310 Q_D(QWaylandQtShellChrome);
311 if (!d->leftResizeHandleHandler->active())
314 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound),
315 d->leftResizeHandleHandler->centroid());
318void QWaylandQtShellChrome::rightResize()
320 Q_D(QWaylandQtShellChrome);
321 if (!d->rightResizeHandleHandler->active())
324 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound),
325 d->rightResizeHandleHandler->centroid());
328void QWaylandQtShellChrome::topResize()
330 Q_D(QWaylandQtShellChrome);
331 if (!d->topResizeHandleHandler->active())
334 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
335 d->topResizeHandleHandler->centroid());
338void QWaylandQtShellChrome::bottomResize()
340 Q_D(QWaylandQtShellChrome);
341 if (!d->bottomResizeHandleHandler->active())
344 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
345 d->bottomResizeHandleHandler->centroid());
348void QWaylandQtShellChrome::topLeftResize()
350 Q_D(QWaylandQtShellChrome);
351 if (!d->topLeftResizeHandleHandler->active())
354 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
355 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
356 d->topLeftResizeHandleHandler->centroid());
359void QWaylandQtShellChrome::topRightResize()
361 Q_D(QWaylandQtShellChrome);
362 if (!d->topRightResizeHandleHandler->active())
365 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
366 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
367 d->topRightResizeHandleHandler->centroid());
370void QWaylandQtShellChrome::bottomLeftResize()
372 Q_D(QWaylandQtShellChrome);
373 if (!d->bottomLeftResizeHandleHandler->active())
376 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
377 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
378 d->bottomLeftResizeHandleHandler->centroid());
381void QWaylandQtShellChrome::bottomRightResize()
383 Q_D(QWaylandQtShellChrome);
384 if (!d->bottomRightResizeHandleHandler->active())
387 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
388 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
389 d->bottomRightResizeHandleHandler->centroid());
392void QWaylandQtShellChrome::titleBarMove()
394 Q_D(QWaylandQtShellChrome);
395 if (!d->titleBarHandler->active())
398 quint8 flags = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::TitleBar);
399 QQuickHandlerPoint centroid = d->titleBarHandler->centroid();
400 if (d->decorationInteraction == quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None)) {
401 d->decorationInteraction = flags;
402 d->decorationInteractionPosition = d->shellSurface->windowPosition() - centroid.scenePressPosition();
407 if (d->decorationInteraction != flags)
410 QPointF position = d->constrainPoint(centroid.scenePosition());
411 d->shellSurface->setWindowPosition((position + d->decorationInteractionPosition).toPoint());
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
450
451
452
453
454
455
456
457
458
459QQuickItem *QWaylandQtShellChrome::titleBar()
const
461 Q_D(
const QWaylandQtShellChrome);
465void QWaylandQtShellChrome::setTitleBar(QQuickItem *item)
467 Q_D(QWaylandQtShellChrome);
468 if (d->titleBar == item)
471 if (d->titleBar !=
nullptr) {
472 d->titleBar->disconnect(
this);
474 delete d->titleBarHandler;
475 d->titleBarHandler =
nullptr;
480 if (d->titleBar !=
nullptr) {
481 connect(d->titleBar, &QQuickItem::heightChanged,
482 this, &QWaylandQtShellChrome::updateDecorations);
484 d->titleBarHandler =
new QQuickDragHandler(d->titleBar);
485 d->titleBarHandler->setTarget(
nullptr);
487 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
488 this, &QWaylandQtShellChrome::stopGrab);
489 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
490 this, &QWaylandQtShellChrome::activateOnGrab);
491 connect(d->titleBarHandler, &QQuickMultiPointHandler::centroidChanged,
492 this, &QWaylandQtShellChrome::titleBarMove);
495 emit titleBarChanged();
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
526
527
528
529
530
531
532
533
534
535
536
537
538QQuickItem *QWaylandQtShellChrome::leftResizeHandle()
const
540 Q_D(
const QWaylandQtShellChrome);
541 return d->leftResizeHandle;
544void QWaylandQtShellChrome::setLeftResizeHandle(QQuickItem *item)
546 Q_D(QWaylandQtShellChrome);
547 if (d->leftResizeHandle == item)
550 if (d->leftResizeHandle !=
nullptr) {
551 d->leftResizeHandle->disconnect(
this);
553 delete d->leftResizeHandleHandler;
554 d->leftResizeHandleHandler =
nullptr;
557 d->leftResizeHandle = item;
559 if (d->leftResizeHandle !=
nullptr) {
560 connect(d->leftResizeHandle, &QQuickItem::widthChanged,
561 this, &QWaylandQtShellChrome::updateDecorations);
563 d->leftResizeHandleHandler =
new QQuickDragHandler(d->leftResizeHandle);
564 d->leftResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
565 d->leftResizeHandleHandler->setTarget(
nullptr);
567 connect(d->leftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
568 this, &QWaylandQtShellChrome::stopGrab);
569 connect(d->leftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
570 this, &QWaylandQtShellChrome::leftResize);
573 emit leftResizeHandleChanged();
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
604
605
606
607
608
609
610
611
612
613
614
615
616QQuickItem *QWaylandQtShellChrome::rightResizeHandle()
const
618 Q_D(
const QWaylandQtShellChrome);
619 return d->rightResizeHandle;
622void QWaylandQtShellChrome::setRightResizeHandle(QQuickItem *item)
624 Q_D(QWaylandQtShellChrome);
625 if (d->rightResizeHandle == item)
628 if (d->rightResizeHandle !=
nullptr) {
629 d->rightResizeHandle->disconnect(
this);
631 delete d->rightResizeHandleHandler;
632 d->rightResizeHandleHandler =
nullptr;
635 d->rightResizeHandle = item;
637 if (d->rightResizeHandle !=
nullptr) {
638 connect(d->rightResizeHandle, &QQuickItem::widthChanged,
639 this, &QWaylandQtShellChrome::updateDecorations);
641 d->rightResizeHandleHandler =
new QQuickDragHandler(d->rightResizeHandle);
642 d->rightResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
643 d->rightResizeHandleHandler->setTarget(
nullptr);
645 connect(d->rightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
646 this, &QWaylandQtShellChrome::stopGrab);
647 connect(d->rightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
648 this, &QWaylandQtShellChrome::rightResize);
651 emit rightResizeHandleChanged();
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
682
683
684
685
686
687
688
689
690
691
692
693
694QQuickItem *QWaylandQtShellChrome::topResizeHandle()
const
696 Q_D(
const QWaylandQtShellChrome);
697 return d->topResizeHandle;
700void QWaylandQtShellChrome::setTopResizeHandle(QQuickItem *item)
702 Q_D(QWaylandQtShellChrome);
703 if (d->topResizeHandle == item)
706 if (d->topResizeHandle !=
nullptr) {
707 d->topResizeHandle->disconnect(
this);
709 delete d->topResizeHandleHandler;
710 d->topResizeHandleHandler =
nullptr;
713 d->topResizeHandle = item;
715 if (d->topResizeHandle !=
nullptr) {
716 connect(d->topResizeHandle, &QQuickItem::heightChanged,
717 this, &QWaylandQtShellChrome::updateDecorations);
719 d->topResizeHandleHandler =
new QQuickDragHandler(d->topResizeHandle);
720 d->topResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
721 d->topResizeHandleHandler->setTarget(
nullptr);
723 connect(d->topResizeHandleHandler, &QQuickPointerHandler::grabChanged,
724 this, &QWaylandQtShellChrome::stopGrab);
725 connect(d->topResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
726 this, &QWaylandQtShellChrome::topResize);
729 emit topResizeHandleChanged();
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
760
761
762
763
764
765
766
767
768
769
770
771
772QQuickItem *QWaylandQtShellChrome::bottomResizeHandle()
const
774 Q_D(
const QWaylandQtShellChrome);
775 return d->bottomResizeHandle;
778void QWaylandQtShellChrome::setBottomResizeHandle(QQuickItem *item)
780 Q_D(QWaylandQtShellChrome);
781 if (d->bottomResizeHandle == item)
784 if (d->bottomResizeHandle !=
nullptr) {
785 d->bottomResizeHandle->disconnect(
this);
787 delete d->bottomResizeHandleHandler;
788 d->bottomResizeHandleHandler =
nullptr;
791 d->bottomResizeHandle = item;
793 if (d->bottomResizeHandle !=
nullptr) {
794 connect(d->bottomResizeHandle, &QQuickItem::heightChanged,
795 this, &QWaylandQtShellChrome::updateDecorations);
797 d->bottomResizeHandleHandler =
new QQuickDragHandler(d->bottomResizeHandle);
798 d->bottomResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
799 d->bottomResizeHandleHandler->setTarget(
nullptr);
801 connect(d->bottomResizeHandleHandler, &QQuickPointerHandler::grabChanged,
802 this, &QWaylandQtShellChrome::stopGrab);
803 connect(d->bottomResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
804 this, &QWaylandQtShellChrome::bottomResize);
808 emit bottomResizeHandleChanged();
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
837
838
839
840
841
842
843
844
845
846
847QQuickItem *QWaylandQtShellChrome::topLeftResizeHandle()
const
849 Q_D(
const QWaylandQtShellChrome);
850 return d->topLeftResizeHandle;
853void QWaylandQtShellChrome::setTopLeftResizeHandle(QQuickItem *item)
855 Q_D(QWaylandQtShellChrome);
856 if (d->topLeftResizeHandle == item)
859 if (d->topLeftResizeHandle !=
nullptr) {
860 delete d->topLeftResizeHandleHandler;
861 d->topLeftResizeHandleHandler =
nullptr;
864 d->topLeftResizeHandle = item;
866 if (d->topLeftResizeHandle !=
nullptr) {
867 d->topLeftResizeHandleHandler =
new QQuickDragHandler(d->topLeftResizeHandle);
868 d->topLeftResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
869 d->topLeftResizeHandleHandler->setTarget(
nullptr);
871 connect(d->topLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
872 this, &QWaylandQtShellChrome::stopGrab);
873 connect(d->topLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
874 this, &QWaylandQtShellChrome::topLeftResize);
877 emit topLeftResizeHandleChanged();
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
906
907
908
909
910
911
912
913
914
915
916QQuickItem *QWaylandQtShellChrome::bottomLeftResizeHandle()
const
918 Q_D(
const QWaylandQtShellChrome);
919 return d->bottomLeftResizeHandle;
922void QWaylandQtShellChrome::setBottomLeftResizeHandle(QQuickItem *item)
924 Q_D(QWaylandQtShellChrome);
925 if (d->bottomLeftResizeHandle == item)
928 if (d->bottomLeftResizeHandle !=
nullptr) {
929 delete d->bottomLeftResizeHandleHandler;
930 d->bottomLeftResizeHandleHandler =
nullptr;
933 d->bottomLeftResizeHandle = item;
935 if (d->bottomLeftResizeHandle !=
nullptr) {
936 d->bottomLeftResizeHandleHandler =
new QQuickDragHandler(d->bottomLeftResizeHandle);
937 d->bottomLeftResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
938 d->bottomLeftResizeHandleHandler->setTarget(
nullptr);
940 connect(d->bottomLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
941 this, &QWaylandQtShellChrome::stopGrab);
942 connect(d->bottomLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
943 this, &QWaylandQtShellChrome::bottomLeftResize);
946 emit bottomLeftResizeHandleChanged();
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
975
976
977
978
979
980
981
982
983
984
985QQuickItem *QWaylandQtShellChrome::topRightResizeHandle()
const
987 Q_D(
const QWaylandQtShellChrome);
988 return d->topRightResizeHandle;
991void QWaylandQtShellChrome::setTopRightResizeHandle(QQuickItem *item)
993 Q_D(QWaylandQtShellChrome);
994 if (d->topRightResizeHandle == item)
997 if (d->topRightResizeHandle !=
nullptr) {
998 delete d->topRightResizeHandleHandler;
999 d->topRightResizeHandleHandler =
nullptr;
1002 d->topRightResizeHandle = item;
1004 if (d->topRightResizeHandle !=
nullptr) {
1005 d->topRightResizeHandleHandler =
new QQuickDragHandler(d->topRightResizeHandle);
1006 d->topRightResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
1007 d->topRightResizeHandleHandler->setTarget(
nullptr);
1009 connect(d->topRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
1010 this, &QWaylandQtShellChrome::stopGrab);
1011 connect(d->topRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
1012 this, &QWaylandQtShellChrome::topRightResize);
1015 emit topRightResizeHandleChanged();
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054QQuickItem *QWaylandQtShellChrome::bottomRightResizeHandle()
const
1056 Q_D(
const QWaylandQtShellChrome);
1057 return d->bottomRightResizeHandle;
1060void QWaylandQtShellChrome::setBottomRightResizeHandle(QQuickItem *item)
1062 Q_D(QWaylandQtShellChrome);
1063 if (d->bottomRightResizeHandle == item)
1066 if (d->bottomRightResizeHandle !=
nullptr) {
1067 delete d->bottomRightResizeHandleHandler;
1068 d->bottomRightResizeHandleHandler =
nullptr;
1071 d->bottomRightResizeHandle = item;
1073 if (d->bottomRightResizeHandle !=
nullptr) {
1074 d->bottomRightResizeHandleHandler =
new QQuickDragHandler(d->bottomRightResizeHandle);
1075 d->bottomRightResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
1076 d->bottomRightResizeHandleHandler->setTarget(
nullptr);
1078 connect(d->bottomRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
1079 this, &QWaylandQtShellChrome::stopGrab);
1080 connect(d->bottomRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
1081 this, &QWaylandQtShellChrome::bottomRightResize);
1084 emit bottomRightResizeHandleChanged();
1088
1089
1090
1091
1092
1093
1094
1095
1098
1099
1100
1101
1102
1103
1104
1105
1106void QWaylandQtShellChrome::setMaximizedRect(
const QRect &rect)
1108 Q_D(QWaylandQtShellChrome);
1109 if (d->maximizedRect == rect)
1112 d->maximizedRect = rect;
1113 emit maximizedRectChanged();
1116QRect QWaylandQtShellChrome::maximizedRect()
const
1118 Q_D(
const QWaylandQtShellChrome);
1119 if (d->maximizedRect.isValid())
1120 return d->maximizedRect;
1121 else if (d->shellSurfaceItem !=
nullptr && d->shellSurfaceItem->output() !=
nullptr)
1122 return d->shellSurfaceItem->output()->geometry();
1127void QWaylandQtShellChrome::updateDecorations()
1129 Q_D(QWaylandQtShellChrome);
1130 if (d->shellSurface ==
nullptr)
1133 bool decorations = hasDecorations();
1134 bool titleBarShowing = hasTitleBar();
1137 if (d->automaticFrameMargins) {
1138 if (d->leftResizeHandle !=
nullptr && decorations)
1139 margins.setLeft(d->leftResizeHandle->width());
1140 if (d->rightResizeHandle !=
nullptr && decorations)
1141 margins.setRight(d->rightResizeHandle->width());
1142 if (d->bottomResizeHandle !=
nullptr && decorations)
1143 margins.setBottom(d->bottomResizeHandle->height());
1145 margins.setTop((decorations && d->topResizeHandle !=
nullptr ? d->topResizeHandle->height() : 0)
1146 + (titleBarShowing && d->titleBar !=
nullptr ? d->titleBar->height() : 0));
1148 margins = d->explicitFrameMargins;
1150 d->shellSurface->setFrameMargins(margins);
1152 if (d->titleBar !=
nullptr)
1153 d->titleBar->setVisible(titleBarShowing);
1154 if (d->leftResizeHandle !=
nullptr)
1155 d->leftResizeHandle->setVisible(decorations);
1156 if (d->rightResizeHandle !=
nullptr)
1157 d->rightResizeHandle->setVisible(decorations);
1158 if (d->topResizeHandle !=
nullptr)
1159 d->topResizeHandle->setVisible(decorations);
1160 if (d->bottomResizeHandle !=
nullptr)
1161 d->bottomResizeHandle->setVisible(decorations);
1162 if (d->bottomLeftResizeHandle !=
nullptr)
1163 d->bottomLeftResizeHandle->setVisible(decorations);
1164 if (d->topLeftResizeHandle !=
nullptr)
1165 d->topLeftResizeHandle->setVisible(decorations);
1166 if (d->bottomRightResizeHandle !=
nullptr)
1167 d->bottomRightResizeHandle->setVisible(decorations);
1168 if (d->topRightResizeHandle !=
nullptr)
1169 d->topRightResizeHandle->setVisible(decorations);
1171 bool minimizedOrMaximized = (d->currentState & (Qt::WindowMaximized|Qt::WindowMinimized)) != 0;
1172 if (d->leftResizeHandleHandler !=
nullptr)
1173 d->leftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1174 if (d->rightResizeHandleHandler !=
nullptr)
1175 d->rightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1176 if (d->bottomResizeHandleHandler !=
nullptr)
1177 d->bottomResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1178 if (d->topResizeHandleHandler !=
nullptr)
1179 d->topResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1180 if (d->bottomLeftResizeHandleHandler !=
nullptr)
1181 d->bottomLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1182 if (d->bottomRightResizeHandleHandler !=
nullptr)
1183 d->bottomRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1184 if (d->topLeftResizeHandleHandler !=
nullptr)
1185 d->topLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1186 if (d->topRightResizeHandleHandler !=
nullptr)
1187 d->topRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1188 if (d->titleBarHandler !=
nullptr)
1189 d->titleBarHandler->setEnabled(titleBarShowing && !minimizedOrMaximized);
1192void QWaylandQtShellChrome::updateGeometry()
1194 Q_D(QWaylandQtShellChrome);
1195 if (d->shellSurface ==
nullptr)
1198 QRect windowGeometry = d->shellSurface->windowGeometry();
1200 QPointF position = windowGeometry.topLeft();
1201 position.rx() -= d->shellSurface->frameMarginLeft();
1202 position.ry() -= d->shellSurface->frameMarginTop();
1204 QSizeF size = windowGeometry.size();
1205 size.rwidth() += d->shellSurface->frameMarginLeft() + d->shellSurface->frameMarginRight();
1206 size.rheight() += d->shellSurface->frameMarginTop() + d->shellSurface->frameMarginBottom();
1208 setPosition(position);
1212void QWaylandQtShellChrome::updateSurface()
1214 Q_D(QWaylandQtShellChrome);
1215 QWaylandSurface *surface = d->shellSurface !=
nullptr ? d->shellSurface->surface() :
nullptr;
1216 if (d->surface == surface)
1219 if (d->surface !=
nullptr)
1220 d->surface->disconnect(
this);
1222 d->surface = surface;
1224 if (d->surface !=
nullptr) {
1225 connect(d->surface, &QWaylandSurface::hasContentChanged,
1226 this, &QWaylandQtShellChrome::updateAutomaticPosition);
1230void QWaylandQtShellChrome::updateShellSurface()
1232 Q_D(QWaylandQtShellChrome);
1233 QWaylandQtShellSurface *sf = d->shellSurfaceItem !=
nullptr
1234 ? qobject_cast<QWaylandQtShellSurface *>(d->shellSurfaceItem->shellSurface())
1236 if (d->shellSurface == sf)
1239 if (d->shellSurface !=
nullptr) {
1240 d->shellSurface->disconnect(
this);
1241 if (d->shell !=
nullptr)
1242 d->shell->unregisterChrome(
this);
1246 d->shellSurface = sf;
1247 if (d->shellSurface !=
nullptr) {
1248 d->shell = d->shellSurface->shell();
1249 if (d->shell !=
nullptr)
1250 d->shell->registerChrome(
this);
1252 updateWindowFlags();
1253 connect(d->shellSurface, &QWaylandQtShellSurface::windowFlagsChanged,
1254 this, &QWaylandQtShellChrome::updateWindowFlags);
1255 connect(d->shellSurface, &QWaylandQtShellSurface::windowStateChanged,
1256 this, &QWaylandQtShellChrome::updateWindowState);
1257 connect(d->shellSurface, &QWaylandQtShellSurface::frameMarginChanged,
1258 this, &QWaylandQtShellChrome::updateGeometry);
1259 connect(d->shellSurface, &QWaylandQtShellSurface::windowGeometryChanged,
1260 this, &QWaylandQtShellChrome::updateGeometry);
1261 connect(d->shellSurface, &QWaylandQtShellSurface::raiseRequested,
1262 this, &QWaylandQtShellChrome::raise);
1263 connect(d->shellSurface, &QWaylandQtShellSurface::lowerRequested,
1264 this, &QWaylandQtShellChrome::lower);
1265 connect(d->shellSurface, &QWaylandQtShellSurface::activeChanged,
1266 this, &QWaylandQtShellChrome::updateActiveState);
1267 connect(d->shellSurface, &QWaylandQtShellSurface::surfaceChanged,
1268 this, &QWaylandQtShellChrome::updateSurface);
1271 updateDecorations();
1275void QWaylandQtShellChrome::updateWindowState()
1277 Q_D(QWaylandQtShellChrome);
1278 if (d->shellSurface ==
nullptr)
1281 setWindowState(d->shellSurface->windowState());
1284void QWaylandQtShellChrome::updateWindowFlags()
1286 Q_D(QWaylandQtShellChrome);
1288 uint nextFlags = d->shellSurface ==
nullptr || d->shellSurface->windowFlags() == Qt::Window
1290 : d->shellSurface->windowFlags();
1292 if (d->currentFlags != nextFlags) {
1293 d->currentFlags = nextFlags;
1294 emit currentWindowFlagsChanged();
1299
1300
1301
1302
1303
1304
1305
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317uint QWaylandQtShellChrome::currentWindowFlags()
const
1319 Q_D(
const QWaylandQtShellChrome);
1320 return d->currentFlags;
1324
1325
1326
1327
1328
1329
1330
1333
1334
1335
1336
1337
1338
1339
1340
1341uint QWaylandQtShellChrome::currentWindowState()
const
1343 Q_D(
const QWaylandQtShellChrome);
1344 return d->currentState;
1347bool QWaylandQtShellChrome::hasTitleBar()
const
1349 Q_D(
const QWaylandQtShellChrome);
1351 bool frameless = (d->currentFlags & Qt::FramelessWindowHint) == Qt::FramelessWindowHint
1352 || ((d->currentFlags & Qt::Popup) == Qt::Popup
1353 && (d->currentFlags & Qt::Tool) != Qt::Tool)
1354 || (d->currentState & Qt::WindowFullScreen) == Qt::WindowFullScreen;
1359
1360
1361
1362
1363
1366
1367
1368
1369
1370
1371bool QWaylandQtShellChrome::hasDecorations()
const
1373 Q_D(
const QWaylandQtShellChrome);
1375 return hasTitleBar() && (d->currentFlags & Qt::Window) == Qt::Window;
1378QRect QWaylandQtShellChrome::maxContentRect()
const
1380 Q_D(
const QWaylandQtShellChrome);
1381 if (d->shellSurface ==
nullptr)
1384 int x0 = d->maximizedRect.x() + d->shellSurface->frameMarginLeft();
1385 int x1 = d->maximizedRect.x() + d->maximizedRect.width() - d->shellSurface->frameMarginRight();
1386 int y0 = d->maximizedRect.y() + d->shellSurface->frameMarginTop();
1387 int y1 = d->maximizedRect.y() + d->maximizedRect.height() - d->shellSurface->frameMarginBottom();
1389 return QRect(x0, y0, x1 - x0, y1 - y0);
1394 return (windowSize >= screenSize) ? 0 : rand() % (screenSize - windowSize);
1397void QWaylandQtShellChrome::setWindowState(uint nextState)
1399 Q_D(QWaylandQtShellChrome);
1401 if (d->currentState == nextState)
1404 if (d->shellSurface ==
nullptr || d->shellSurfaceItem ==
nullptr)
1407 QWaylandOutput *output = d->shellSurfaceItem->output();
1408 if (output ==
nullptr)
1411 if ((d->currentState & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) == 0) {
1412 d->restoreGeometry = d->shellSurface->windowGeometry();
1415 d->currentState = nextState;
1416 emit currentWindowStateChanged();
1418 if ((nextState & Qt::WindowMinimized) != 0) {
1419 d->shellSurface->requestWindowGeometry(nextState, QRect(0, 0, 1, 1));
1420 d->shellSurfaceItem->setVisible(
false);
1422 }
else if ((nextState & Qt::WindowFullScreen) != 0) {
1423 d->shellSurfaceItem->setVisible(
true);
1424 d->shellSurface->requestWindowGeometry(nextState, QRect(QPoint(0, 0), output->window()->size()));
1426 }
else if ((nextState & Qt::WindowMaximized) != 0) {
1427 d->shellSurfaceItem->setVisible(
true);
1428 d->shellSurface->requestWindowGeometry(nextState, maxContentRect());
1431 d->shellSurfaceItem->setVisible(
true);
1432 d->shellSurface->requestWindowGeometry(nextState, d->restoreGeometry);
1437void QWaylandQtShellChrome::updateAutomaticPosition()
1439 Q_D(QWaylandQtShellChrome);
1440 if (!d->positionSet && d->shellSurface !=
nullptr) {
1441 bool randomize = d->shellSurface->positionAutomatic();
1442 QRect rect = d->shellSurface->windowGeometry();
1443 QRect space = maxContentRect();
1445 int xpos = randomize ? randomPos(rect.width(), space.width()) + space.x()
1446 : qMax(rect.x(), space.x());
1447 int ypos = randomize ? randomPos(rect.height(), space.height()) + space.y()
1448 : qMax(rect.y(), space.y());
1450 d->shellSurface->setWindowPosition(QPoint(xpos, ypos));
1451 d->positionSet =
true;
1456
1457
1458
1459
1460
1461void QWaylandQtShellChrome::deactivate()
1463 Q_D(QWaylandQtShellChrome);
1464 if (d->shellSurface !=
nullptr)
1465 d->shellSurface->setActive(
false);
1468void QWaylandQtShellChrome::activateOnGrab(QPointingDevice::GrabTransition transition)
1470 Q_D(QWaylandQtShellChrome);
1471 if (d->titleBarHandler !=
nullptr) {
1472 switch (transition) {
1473 case QPointingDevice::GrabPassive:
1474 case QPointingDevice::OverrideGrabPassive:
1475 case QPointingDevice::GrabExclusive:
1485
1486
1487
1488
1489
1490
1491void QWaylandQtShellChrome::activate()
1493 Q_D(QWaylandQtShellChrome);
1494 if (d->shellSurface !=
nullptr)
1495 d->shellSurface->setActive(
true);
1500
1501
1502
1503
1504
1505void QWaylandQtShellChrome::raise()
1507 Q_D(QWaylandQtShellChrome);
1508 if (d->shellSurfaceItem !=
nullptr)
1509 d->shellSurfaceItem->raise();
1513
1514
1515
1516
1517
1518void QWaylandQtShellChrome::lower()
1520 Q_D(QWaylandQtShellChrome);
1521 if (d->shellSurfaceItem !=
nullptr)
1522 d->shellSurfaceItem->lower();
1525void QWaylandQtShellChrome::updateActiveState()
1527 Q_D(QWaylandQtShellChrome);
1528 if (d->shellSurface ==
nullptr)
1531 if (d->shellSurface->active()) {
1540
1541
1542
1543
1544
1545
1546
1547
1548
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560void QWaylandQtShellChrome::setFrameMarginLeft(
int left)
1562 Q_D(QWaylandQtShellChrome);
1563 if (d->explicitFrameMargins.left() == left)
1566 d->explicitFrameMargins.setLeft(left);
1567 d->automaticFrameMargins =
false;
1568 updateDecorations();
1570 emit frameMarginChanged();
1573int QWaylandQtShellChrome::frameMarginLeft()
const
1575 Q_D(
const QWaylandQtShellChrome);
1576 if (d->shellSurface ==
nullptr)
1578 return d->shellSurface->frameMarginLeft();
1582
1583
1584
1585
1586
1587
1588
1589
1590
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602void QWaylandQtShellChrome::setFrameMarginRight(
int right)
1604 Q_D(QWaylandQtShellChrome);
1605 if (d->explicitFrameMargins.right() == right)
1608 d->explicitFrameMargins.setRight(right);
1609 d->automaticFrameMargins =
false;
1610 updateDecorations();
1612 emit frameMarginChanged();
1615int QWaylandQtShellChrome::frameMarginRight()
const
1617 Q_D(
const QWaylandQtShellChrome);
1618 if (d->shellSurface ==
nullptr)
1620 return d->shellSurface->frameMarginRight();
1624
1625
1626
1627
1628
1629
1630
1631
1632
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645void QWaylandQtShellChrome::setFrameMarginTop(
int top)
1647 Q_D(QWaylandQtShellChrome);
1648 if (d->explicitFrameMargins.top() == top)
1650 d->explicitFrameMargins.setTop(top);
1651 d->automaticFrameMargins =
false;
1652 updateDecorations();
1654 emit frameMarginChanged();
1657int QWaylandQtShellChrome::frameMarginTop()
const
1659 Q_D(
const QWaylandQtShellChrome);
1660 if (d->shellSurface ==
nullptr)
1662 return d->shellSurface->frameMarginTop();
1666
1667
1668
1669
1670
1671
1672
1673
1674
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686void QWaylandQtShellChrome::setFrameMarginBottom(
int bottom)
1688 Q_D(QWaylandQtShellChrome);
1689 if (d->explicitFrameMargins.bottom() == bottom)
1691 d->explicitFrameMargins.setBottom(bottom);
1692 d->automaticFrameMargins =
false;
1693 updateDecorations();
1695 emit frameMarginChanged();
1698int QWaylandQtShellChrome::frameMarginBottom()
const
1700 Q_D(
const QWaylandQtShellChrome);
1701 if (d->shellSurface ==
nullptr)
1703 return d->shellSurface->frameMarginBottom();
1708#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)