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
264void QWaylandQtShellChrome::setShellSurfaceItem(QWaylandQuickShellSurfaceItem *shellSurfaceItem)
266 Q_D(QWaylandQtShellChrome);
267 if (d->shellSurfaceItem == shellSurfaceItem)
270 if (d->shellSurfaceItem !=
nullptr)
271 d->shellSurfaceItem->disconnect(
this);
273 d->shellSurfaceItem = shellSurfaceItem;
275 if (d->shellSurfaceItem !=
nullptr) {
276 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::shellSurfaceChanged,
277 this, &QWaylandQtShellChrome::updateShellSurface);
278 connect(d->shellSurfaceItem, &QWaylandQuickShellSurfaceItem::surfaceDestroyed,
279 this, &QWaylandQtShellChrome::clientDestroyed);
282 updateShellSurface();
283 emit shellSurfaceItemChanged();
286QWaylandQuickShellSurfaceItem *QWaylandQtShellChrome::shellSurfaceItem()
const
288 Q_D(
const QWaylandQtShellChrome);
289 return d->shellSurfaceItem;
292void QWaylandQtShellChrome::stopGrab()
294 Q_D(QWaylandQtShellChrome);
295 d->decorationInteraction = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None);
298void QWaylandQtShellChrome::leftResize()
300 Q_D(QWaylandQtShellChrome);
301 if (!d->leftResizeHandleHandler->active())
304 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound),
305 d->leftResizeHandleHandler->centroid());
308void QWaylandQtShellChrome::rightResize()
310 Q_D(QWaylandQtShellChrome);
311 if (!d->rightResizeHandleHandler->active())
314 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound),
315 d->rightResizeHandleHandler->centroid());
318void QWaylandQtShellChrome::topResize()
320 Q_D(QWaylandQtShellChrome);
321 if (!d->topResizeHandleHandler->active())
324 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
325 d->topResizeHandleHandler->centroid());
328void QWaylandQtShellChrome::bottomResize()
330 Q_D(QWaylandQtShellChrome);
331 if (!d->bottomResizeHandleHandler->active())
334 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
335 d->bottomResizeHandleHandler->centroid());
338void QWaylandQtShellChrome::topLeftResize()
340 Q_D(QWaylandQtShellChrome);
341 if (!d->topLeftResizeHandleHandler->active())
344 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
345 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
346 d->topLeftResizeHandleHandler->centroid());
349void QWaylandQtShellChrome::topRightResize()
351 Q_D(QWaylandQtShellChrome);
352 if (!d->topRightResizeHandleHandler->active())
355 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
356 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::NorthBound),
357 d->topRightResizeHandleHandler->centroid());
360void QWaylandQtShellChrome::bottomLeftResize()
362 Q_D(QWaylandQtShellChrome);
363 if (!d->bottomLeftResizeHandleHandler->active())
366 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::WestBound)
367 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
368 d->bottomLeftResizeHandleHandler->centroid());
371void QWaylandQtShellChrome::bottomRightResize()
373 Q_D(QWaylandQtShellChrome);
374 if (!d->bottomRightResizeHandleHandler->active())
377 d->updateDecorationInteraction(quint8(QWaylandQtShellChromePrivate::DecorationInteraction::EastBound)
378 | quint8(QWaylandQtShellChromePrivate::DecorationInteraction::SouthBound),
379 d->bottomRightResizeHandleHandler->centroid());
382void QWaylandQtShellChrome::titleBarMove()
384 Q_D(QWaylandQtShellChrome);
385 if (!d->titleBarHandler->active())
388 quint8 flags = quint8(QWaylandQtShellChromePrivate::DecorationInteraction::TitleBar);
389 QQuickHandlerPoint centroid = d->titleBarHandler->centroid();
390 if (d->decorationInteraction == quint8(QWaylandQtShellChromePrivate::DecorationInteraction::None)) {
391 d->decorationInteraction = flags;
392 d->decorationInteractionPosition = d->shellSurface->windowPosition() - centroid.scenePressPosition();
397 if (d->decorationInteraction != flags)
400 QPointF position = d->constrainPoint(centroid.scenePosition());
401 d->shellSurface->setWindowPosition((position + d->decorationInteractionPosition).toPoint());
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
438QQuickItem *QWaylandQtShellChrome::titleBar()
const
440 Q_D(
const QWaylandQtShellChrome);
444void QWaylandQtShellChrome::setTitleBar(QQuickItem *item)
446 Q_D(QWaylandQtShellChrome);
447 if (d->titleBar == item)
450 if (d->titleBar !=
nullptr) {
451 d->titleBar->disconnect(
this);
453 delete d->titleBarHandler;
454 d->titleBarHandler =
nullptr;
459 if (d->titleBar !=
nullptr) {
460 connect(d->titleBar, &QQuickItem::heightChanged,
461 this, &QWaylandQtShellChrome::updateDecorations);
463 d->titleBarHandler =
new QQuickDragHandler(d->titleBar);
464 d->titleBarHandler->setTarget(
nullptr);
466 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
467 this, &QWaylandQtShellChrome::stopGrab);
468 connect(d->titleBarHandler, &QQuickPointerHandler::grabChanged,
469 this, &QWaylandQtShellChrome::activateOnGrab);
470 connect(d->titleBarHandler, &QQuickMultiPointHandler::centroidChanged,
471 this, &QWaylandQtShellChrome::titleBarMove);
474 emit titleBarChanged();
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
503QQuickItem *QWaylandQtShellChrome::leftResizeHandle()
const
505 Q_D(
const QWaylandQtShellChrome);
506 return d->leftResizeHandle;
509void QWaylandQtShellChrome::setLeftResizeHandle(QQuickItem *item)
511 Q_D(QWaylandQtShellChrome);
512 if (d->leftResizeHandle == item)
515 if (d->leftResizeHandle !=
nullptr) {
516 d->leftResizeHandle->disconnect(
this);
518 delete d->leftResizeHandleHandler;
519 d->leftResizeHandleHandler =
nullptr;
522 d->leftResizeHandle = item;
524 if (d->leftResizeHandle !=
nullptr) {
525 connect(d->leftResizeHandle, &QQuickItem::widthChanged,
526 this, &QWaylandQtShellChrome::updateDecorations);
528 d->leftResizeHandleHandler =
new QQuickDragHandler(d->leftResizeHandle);
529 d->leftResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
530 d->leftResizeHandleHandler->setTarget(
nullptr);
532 connect(d->leftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
533 this, &QWaylandQtShellChrome::stopGrab);
534 connect(d->leftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
535 this, &QWaylandQtShellChrome::leftResize);
538 emit leftResizeHandleChanged();
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
567QQuickItem *QWaylandQtShellChrome::rightResizeHandle()
const
569 Q_D(
const QWaylandQtShellChrome);
570 return d->rightResizeHandle;
573void QWaylandQtShellChrome::setRightResizeHandle(QQuickItem *item)
575 Q_D(QWaylandQtShellChrome);
576 if (d->rightResizeHandle == item)
579 if (d->rightResizeHandle !=
nullptr) {
580 d->rightResizeHandle->disconnect(
this);
582 delete d->rightResizeHandleHandler;
583 d->rightResizeHandleHandler =
nullptr;
586 d->rightResizeHandle = item;
588 if (d->rightResizeHandle !=
nullptr) {
589 connect(d->rightResizeHandle, &QQuickItem::widthChanged,
590 this, &QWaylandQtShellChrome::updateDecorations);
592 d->rightResizeHandleHandler =
new QQuickDragHandler(d->rightResizeHandle);
593 d->rightResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
594 d->rightResizeHandleHandler->setTarget(
nullptr);
596 connect(d->rightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
597 this, &QWaylandQtShellChrome::stopGrab);
598 connect(d->rightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
599 this, &QWaylandQtShellChrome::rightResize);
602 emit rightResizeHandleChanged();
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
631QQuickItem *QWaylandQtShellChrome::topResizeHandle()
const
633 Q_D(
const QWaylandQtShellChrome);
634 return d->topResizeHandle;
637void QWaylandQtShellChrome::setTopResizeHandle(QQuickItem *item)
639 Q_D(QWaylandQtShellChrome);
640 if (d->topResizeHandle == item)
643 if (d->topResizeHandle !=
nullptr) {
644 d->topResizeHandle->disconnect(
this);
646 delete d->topResizeHandleHandler;
647 d->topResizeHandleHandler =
nullptr;
650 d->topResizeHandle = item;
652 if (d->topResizeHandle !=
nullptr) {
653 connect(d->topResizeHandle, &QQuickItem::heightChanged,
654 this, &QWaylandQtShellChrome::updateDecorations);
656 d->topResizeHandleHandler =
new QQuickDragHandler(d->topResizeHandle);
657 d->topResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
658 d->topResizeHandleHandler->setTarget(
nullptr);
660 connect(d->topResizeHandleHandler, &QQuickPointerHandler::grabChanged,
661 this, &QWaylandQtShellChrome::stopGrab);
662 connect(d->topResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
663 this, &QWaylandQtShellChrome::topResize);
666 emit topResizeHandleChanged();
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
695QQuickItem *QWaylandQtShellChrome::bottomResizeHandle()
const
697 Q_D(
const QWaylandQtShellChrome);
698 return d->bottomResizeHandle;
701void QWaylandQtShellChrome::setBottomResizeHandle(QQuickItem *item)
703 Q_D(QWaylandQtShellChrome);
704 if (d->bottomResizeHandle == item)
707 if (d->bottomResizeHandle !=
nullptr) {
708 d->bottomResizeHandle->disconnect(
this);
710 delete d->bottomResizeHandleHandler;
711 d->bottomResizeHandleHandler =
nullptr;
714 d->bottomResizeHandle = item;
716 if (d->bottomResizeHandle !=
nullptr) {
717 connect(d->bottomResizeHandle, &QQuickItem::heightChanged,
718 this, &QWaylandQtShellChrome::updateDecorations);
720 d->bottomResizeHandleHandler =
new QQuickDragHandler(d->bottomResizeHandle);
721 d->bottomResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
722 d->bottomResizeHandleHandler->setTarget(
nullptr);
724 connect(d->bottomResizeHandleHandler, &QQuickPointerHandler::grabChanged,
725 this, &QWaylandQtShellChrome::stopGrab);
726 connect(d->bottomResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
727 this, &QWaylandQtShellChrome::bottomResize);
731 emit bottomResizeHandleChanged();
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758QQuickItem *QWaylandQtShellChrome::topLeftResizeHandle()
const
760 Q_D(
const QWaylandQtShellChrome);
761 return d->topLeftResizeHandle;
764void QWaylandQtShellChrome::setTopLeftResizeHandle(QQuickItem *item)
766 Q_D(QWaylandQtShellChrome);
767 if (d->topLeftResizeHandle == item)
770 if (d->topLeftResizeHandle !=
nullptr) {
771 delete d->topLeftResizeHandleHandler;
772 d->topLeftResizeHandleHandler =
nullptr;
775 d->topLeftResizeHandle = item;
777 if (d->topLeftResizeHandle !=
nullptr) {
778 d->topLeftResizeHandleHandler =
new QQuickDragHandler(d->topLeftResizeHandle);
779 d->topLeftResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
780 d->topLeftResizeHandleHandler->setTarget(
nullptr);
782 connect(d->topLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
783 this, &QWaylandQtShellChrome::stopGrab);
784 connect(d->topLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
785 this, &QWaylandQtShellChrome::topLeftResize);
788 emit topLeftResizeHandleChanged();
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815QQuickItem *QWaylandQtShellChrome::bottomLeftResizeHandle()
const
817 Q_D(
const QWaylandQtShellChrome);
818 return d->bottomLeftResizeHandle;
821void QWaylandQtShellChrome::setBottomLeftResizeHandle(QQuickItem *item)
823 Q_D(QWaylandQtShellChrome);
824 if (d->bottomLeftResizeHandle == item)
827 if (d->bottomLeftResizeHandle !=
nullptr) {
828 delete d->bottomLeftResizeHandleHandler;
829 d->bottomLeftResizeHandleHandler =
nullptr;
832 d->bottomLeftResizeHandle = item;
834 if (d->bottomLeftResizeHandle !=
nullptr) {
835 d->bottomLeftResizeHandleHandler =
new QQuickDragHandler(d->bottomLeftResizeHandle);
836 d->bottomLeftResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
837 d->bottomLeftResizeHandleHandler->setTarget(
nullptr);
839 connect(d->bottomLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
840 this, &QWaylandQtShellChrome::stopGrab);
841 connect(d->bottomLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
842 this, &QWaylandQtShellChrome::bottomLeftResize);
845 emit bottomLeftResizeHandleChanged();
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872QQuickItem *QWaylandQtShellChrome::topRightResizeHandle()
const
874 Q_D(
const QWaylandQtShellChrome);
875 return d->topRightResizeHandle;
878void QWaylandQtShellChrome::setTopRightResizeHandle(QQuickItem *item)
880 Q_D(QWaylandQtShellChrome);
881 if (d->topRightResizeHandle == item)
884 if (d->topRightResizeHandle !=
nullptr) {
885 delete d->topRightResizeHandleHandler;
886 d->topRightResizeHandleHandler =
nullptr;
889 d->topRightResizeHandle = item;
891 if (d->topRightResizeHandle !=
nullptr) {
892 d->topRightResizeHandleHandler =
new QQuickDragHandler(d->topRightResizeHandle);
893 d->topRightResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
894 d->topRightResizeHandleHandler->setTarget(
nullptr);
896 connect(d->topRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
897 this, &QWaylandQtShellChrome::stopGrab);
898 connect(d->topRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
899 this, &QWaylandQtShellChrome::topRightResize);
902 emit topRightResizeHandleChanged();
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929QQuickItem *QWaylandQtShellChrome::bottomRightResizeHandle()
const
931 Q_D(
const QWaylandQtShellChrome);
932 return d->bottomRightResizeHandle;
935void QWaylandQtShellChrome::setBottomRightResizeHandle(QQuickItem *item)
937 Q_D(QWaylandQtShellChrome);
938 if (d->bottomRightResizeHandle == item)
941 if (d->bottomRightResizeHandle !=
nullptr) {
942 delete d->bottomRightResizeHandleHandler;
943 d->bottomRightResizeHandleHandler =
nullptr;
946 d->bottomRightResizeHandle = item;
948 if (d->bottomRightResizeHandle !=
nullptr) {
949 d->bottomRightResizeHandleHandler =
new QQuickDragHandler(d->bottomRightResizeHandle);
950 d->bottomRightResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
951 d->bottomRightResizeHandleHandler->setTarget(
nullptr);
953 connect(d->bottomRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
954 this, &QWaylandQtShellChrome::stopGrab);
955 connect(d->bottomRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
956 this, &QWaylandQtShellChrome::bottomRightResize);
959 emit bottomRightResizeHandleChanged();
963
964
965
966
967
968
969
970
971void QWaylandQtShellChrome::setMaximizedRect(
const QRect &rect)
973 Q_D(QWaylandQtShellChrome);
974 if (d->maximizedRect == rect)
977 d->maximizedRect = rect;
978 emit maximizedRectChanged();
981QRect QWaylandQtShellChrome::maximizedRect()
const
983 Q_D(
const QWaylandQtShellChrome);
984 if (d->maximizedRect.isValid())
985 return d->maximizedRect;
986 else if (d->shellSurfaceItem !=
nullptr && d->shellSurfaceItem->output() !=
nullptr)
987 return d->shellSurfaceItem->output()->geometry();
992void QWaylandQtShellChrome::updateDecorations()
994 Q_D(QWaylandQtShellChrome);
995 if (d->shellSurface ==
nullptr)
998 bool decorations = hasDecorations();
999 bool titleBarShowing = hasTitleBar();
1002 if (d->automaticFrameMargins) {
1003 if (d->leftResizeHandle !=
nullptr && decorations)
1004 margins.setLeft(d->leftResizeHandle->width());
1005 if (d->rightResizeHandle !=
nullptr && decorations)
1006 margins.setRight(d->rightResizeHandle->width());
1007 if (d->bottomResizeHandle !=
nullptr && decorations)
1008 margins.setBottom(d->bottomResizeHandle->height());
1010 margins.setTop((decorations && d->topResizeHandle !=
nullptr ? d->topResizeHandle->height() : 0)
1011 + (titleBarShowing && d->titleBar !=
nullptr ? d->titleBar->height() : 0));
1013 margins = d->explicitFrameMargins;
1015 d->shellSurface->setFrameMargins(margins);
1017 if (d->titleBar !=
nullptr)
1018 d->titleBar->setVisible(titleBarShowing);
1019 if (d->leftResizeHandle !=
nullptr)
1020 d->leftResizeHandle->setVisible(decorations);
1021 if (d->rightResizeHandle !=
nullptr)
1022 d->rightResizeHandle->setVisible(decorations);
1023 if (d->topResizeHandle !=
nullptr)
1024 d->topResizeHandle->setVisible(decorations);
1025 if (d->bottomResizeHandle !=
nullptr)
1026 d->bottomResizeHandle->setVisible(decorations);
1027 if (d->bottomLeftResizeHandle !=
nullptr)
1028 d->bottomLeftResizeHandle->setVisible(decorations);
1029 if (d->topLeftResizeHandle !=
nullptr)
1030 d->topLeftResizeHandle->setVisible(decorations);
1031 if (d->bottomRightResizeHandle !=
nullptr)
1032 d->bottomRightResizeHandle->setVisible(decorations);
1033 if (d->topRightResizeHandle !=
nullptr)
1034 d->topRightResizeHandle->setVisible(decorations);
1036 bool minimizedOrMaximized = (d->currentState & (Qt::WindowMaximized|Qt::WindowMinimized)) != 0;
1037 if (d->leftResizeHandleHandler !=
nullptr)
1038 d->leftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1039 if (d->rightResizeHandleHandler !=
nullptr)
1040 d->rightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1041 if (d->bottomResizeHandleHandler !=
nullptr)
1042 d->bottomResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1043 if (d->topResizeHandleHandler !=
nullptr)
1044 d->topResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1045 if (d->bottomLeftResizeHandleHandler !=
nullptr)
1046 d->bottomLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1047 if (d->bottomRightResizeHandleHandler !=
nullptr)
1048 d->bottomRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1049 if (d->topLeftResizeHandleHandler !=
nullptr)
1050 d->topLeftResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1051 if (d->topRightResizeHandleHandler !=
nullptr)
1052 d->topRightResizeHandleHandler->setEnabled(decorations && !minimizedOrMaximized);
1053 if (d->titleBarHandler !=
nullptr)
1054 d->titleBarHandler->setEnabled(titleBarShowing && !minimizedOrMaximized);
1057void QWaylandQtShellChrome::updateGeometry()
1059 Q_D(QWaylandQtShellChrome);
1060 if (d->shellSurface ==
nullptr)
1063 QRect windowGeometry = d->shellSurface->windowGeometry();
1065 QPointF position = windowGeometry.topLeft();
1066 position.rx() -= d->shellSurface->frameMarginLeft();
1067 position.ry() -= d->shellSurface->frameMarginTop();
1069 QSizeF size = windowGeometry.size();
1070 size.rwidth() += d->shellSurface->frameMarginLeft() + d->shellSurface->frameMarginRight();
1071 size.rheight() += d->shellSurface->frameMarginTop() + d->shellSurface->frameMarginBottom();
1073 setPosition(position);
1077void QWaylandQtShellChrome::updateSurface()
1079 Q_D(QWaylandQtShellChrome);
1080 QWaylandSurface *surface = d->shellSurface !=
nullptr ? d->shellSurface->surface() :
nullptr;
1081 if (d->surface == surface)
1084 if (d->surface !=
nullptr)
1085 d->surface->disconnect(
this);
1087 d->surface = surface;
1089 if (d->surface !=
nullptr) {
1090 connect(d->surface, &QWaylandSurface::hasContentChanged,
1091 this, &QWaylandQtShellChrome::updateAutomaticPosition);
1095void QWaylandQtShellChrome::updateShellSurface()
1097 Q_D(QWaylandQtShellChrome);
1098 QWaylandQtShellSurface *sf = d->shellSurfaceItem !=
nullptr
1099 ? qobject_cast<QWaylandQtShellSurface *>(d->shellSurfaceItem->shellSurface())
1101 if (d->shellSurface == sf)
1104 if (d->shellSurface !=
nullptr) {
1105 d->shellSurface->disconnect(
this);
1106 if (d->shell !=
nullptr)
1107 d->shell->unregisterChrome(
this);
1111 d->shellSurface = sf;
1112 if (d->shellSurface !=
nullptr) {
1113 d->shell = d->shellSurface->shell();
1114 if (d->shell !=
nullptr)
1115 d->shell->registerChrome(
this);
1117 updateWindowFlags();
1118 connect(d->shellSurface, &QWaylandQtShellSurface::windowFlagsChanged,
1119 this, &QWaylandQtShellChrome::updateWindowFlags);
1120 connect(d->shellSurface, &QWaylandQtShellSurface::windowStateChanged,
1121 this, &QWaylandQtShellChrome::updateWindowState);
1122 connect(d->shellSurface, &QWaylandQtShellSurface::frameMarginChanged,
1123 this, &QWaylandQtShellChrome::updateGeometry);
1124 connect(d->shellSurface, &QWaylandQtShellSurface::windowGeometryChanged,
1125 this, &QWaylandQtShellChrome::updateGeometry);
1126 connect(d->shellSurface, &QWaylandQtShellSurface::raiseRequested,
1127 this, &QWaylandQtShellChrome::raise);
1128 connect(d->shellSurface, &QWaylandQtShellSurface::lowerRequested,
1129 this, &QWaylandQtShellChrome::lower);
1130 connect(d->shellSurface, &QWaylandQtShellSurface::activeChanged,
1131 this, &QWaylandQtShellChrome::updateActiveState);
1132 connect(d->shellSurface, &QWaylandQtShellSurface::surfaceChanged,
1133 this, &QWaylandQtShellChrome::updateSurface);
1136 updateDecorations();
1140void QWaylandQtShellChrome::updateWindowState()
1142 Q_D(QWaylandQtShellChrome);
1143 if (d->shellSurface ==
nullptr)
1146 setWindowState(d->shellSurface->windowState());
1149void QWaylandQtShellChrome::updateWindowFlags()
1151 Q_D(QWaylandQtShellChrome);
1153 uint nextFlags = d->shellSurface ==
nullptr || d->shellSurface->windowFlags() == Qt::Window
1155 : d->shellSurface->windowFlags();
1157 if (d->currentFlags != nextFlags) {
1158 d->currentFlags = nextFlags;
1159 emit currentWindowFlagsChanged();
1164
1165
1166
1167
1168
1169
1170
1171uint QWaylandQtShellChrome::currentWindowFlags()
const
1173 Q_D(
const QWaylandQtShellChrome);
1174 return d->currentFlags;
1178
1179
1180
1181
1182
1183
1184
1185uint QWaylandQtShellChrome::currentWindowState()
const
1187 Q_D(
const QWaylandQtShellChrome);
1188 return d->currentState;
1191bool QWaylandQtShellChrome::hasTitleBar()
const
1193 Q_D(
const QWaylandQtShellChrome);
1195 bool frameless = (d->currentFlags & Qt::FramelessWindowHint) == Qt::FramelessWindowHint
1196 || ((d->currentFlags & Qt::Popup) == Qt::Popup
1197 && (d->currentFlags & Qt::Tool) != Qt::Tool)
1198 || (d->currentState & Qt::WindowFullScreen) == Qt::WindowFullScreen;
1203
1204
1205
1206
1207
1208bool QWaylandQtShellChrome::hasDecorations()
const
1210 Q_D(
const QWaylandQtShellChrome);
1212 return hasTitleBar() && (d->currentFlags & Qt::Window) == Qt::Window;
1215QRect QWaylandQtShellChrome::maxContentRect()
const
1217 Q_D(
const QWaylandQtShellChrome);
1218 if (d->shellSurface ==
nullptr)
1221 int x0 = d->maximizedRect.x() + d->shellSurface->frameMarginLeft();
1222 int x1 = d->maximizedRect.x() + d->maximizedRect.width() - d->shellSurface->frameMarginRight();
1223 int y0 = d->maximizedRect.y() + d->shellSurface->frameMarginTop();
1224 int y1 = d->maximizedRect.y() + d->maximizedRect.height() - d->shellSurface->frameMarginBottom();
1226 return QRect(x0, y0, x1 - x0, y1 - y0);
1231 return (windowSize >= screenSize) ? 0 : rand() % (screenSize - windowSize);
1234void QWaylandQtShellChrome::setWindowState(uint nextState)
1236 Q_D(QWaylandQtShellChrome);
1238 if (d->currentState == nextState)
1241 if (d->shellSurface ==
nullptr || d->shellSurfaceItem ==
nullptr)
1244 QWaylandOutput *output = d->shellSurfaceItem->output();
1245 if (output ==
nullptr)
1248 if ((d->currentState & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) == 0) {
1249 d->restoreGeometry = d->shellSurface->windowGeometry();
1252 d->currentState = nextState;
1253 emit currentWindowStateChanged();
1255 if ((nextState & Qt::WindowMinimized) != 0) {
1256 d->shellSurface->requestWindowGeometry(nextState, QRect(0, 0, 1, 1));
1257 d->shellSurfaceItem->setVisible(
false);
1259 }
else if ((nextState & Qt::WindowFullScreen) != 0) {
1260 d->shellSurfaceItem->setVisible(
true);
1261 d->shellSurface->requestWindowGeometry(nextState, QRect(QPoint(0, 0), output->window()->size()));
1263 }
else if ((nextState & Qt::WindowMaximized) != 0) {
1264 d->shellSurfaceItem->setVisible(
true);
1265 d->shellSurface->requestWindowGeometry(nextState, maxContentRect());
1268 d->shellSurfaceItem->setVisible(
true);
1269 d->shellSurface->requestWindowGeometry(nextState, d->restoreGeometry);
1274void QWaylandQtShellChrome::updateAutomaticPosition()
1276 Q_D(QWaylandQtShellChrome);
1277 if (!d->positionSet && d->shellSurface !=
nullptr) {
1278 bool randomize = d->shellSurface->positionAutomatic();
1279 QRect rect = d->shellSurface->windowGeometry();
1280 QRect space = maxContentRect();
1282 int xpos = randomize ? randomPos(rect.width(), space.width()) + space.x()
1283 : qMax(rect.x(), space.x());
1284 int ypos = randomize ? randomPos(rect.height(), space.height()) + space.y()
1285 : qMax(rect.y(), space.y());
1287 d->shellSurface->setWindowPosition(QPoint(xpos, ypos));
1288 d->positionSet =
true;
1293
1294
1295
1296
1297
1298void QWaylandQtShellChrome::deactivate()
1300 Q_D(QWaylandQtShellChrome);
1301 if (d->shellSurface !=
nullptr)
1302 d->shellSurface->setActive(
false);
1305void QWaylandQtShellChrome::activateOnGrab(QPointingDevice::GrabTransition transition)
1307 Q_D(QWaylandQtShellChrome);
1308 if (d->titleBarHandler !=
nullptr) {
1309 switch (transition) {
1310 case QPointingDevice::GrabPassive:
1311 case QPointingDevice::OverrideGrabPassive:
1312 case QPointingDevice::GrabExclusive:
1322
1323
1324
1325
1326
1327
1328void QWaylandQtShellChrome::activate()
1330 Q_D(QWaylandQtShellChrome);
1331 if (d->shellSurface !=
nullptr)
1332 d->shellSurface->setActive(
true);
1337
1338
1339
1340
1341
1342void QWaylandQtShellChrome::raise()
1344 Q_D(QWaylandQtShellChrome);
1345 if (d->shellSurfaceItem !=
nullptr)
1346 d->shellSurfaceItem->raise();
1350
1351
1352
1353
1354
1355void QWaylandQtShellChrome::lower()
1357 Q_D(QWaylandQtShellChrome);
1358 if (d->shellSurfaceItem !=
nullptr)
1359 d->shellSurfaceItem->lower();
1362void QWaylandQtShellChrome::updateActiveState()
1364 Q_D(QWaylandQtShellChrome);
1365 if (d->shellSurface ==
nullptr)
1368 if (d->shellSurface->active()) {
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386void QWaylandQtShellChrome::setFrameMarginLeft(
int left)
1388 Q_D(QWaylandQtShellChrome);
1389 if (d->explicitFrameMargins.left() == left)
1392 d->explicitFrameMargins.setLeft(left);
1393 d->automaticFrameMargins =
false;
1394 updateDecorations();
1396 emit frameMarginChanged();
1399int QWaylandQtShellChrome::frameMarginLeft()
const
1401 Q_D(
const QWaylandQtShellChrome);
1402 if (d->shellSurface ==
nullptr)
1404 return d->shellSurface->frameMarginLeft();
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417void QWaylandQtShellChrome::setFrameMarginRight(
int right)
1419 Q_D(QWaylandQtShellChrome);
1420 if (d->explicitFrameMargins.right() == right)
1423 d->explicitFrameMargins.setRight(right);
1424 d->automaticFrameMargins =
false;
1425 updateDecorations();
1427 emit frameMarginChanged();
1430int QWaylandQtShellChrome::frameMarginRight()
const
1432 Q_D(
const QWaylandQtShellChrome);
1433 if (d->shellSurface ==
nullptr)
1435 return d->shellSurface->frameMarginRight();
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448void QWaylandQtShellChrome::setFrameMarginTop(
int top)
1450 Q_D(QWaylandQtShellChrome);
1451 if (d->explicitFrameMargins.top() == top)
1453 d->explicitFrameMargins.setTop(top);
1454 d->automaticFrameMargins =
false;
1455 updateDecorations();
1457 emit frameMarginChanged();
1460int QWaylandQtShellChrome::frameMarginTop()
const
1462 Q_D(
const QWaylandQtShellChrome);
1463 if (d->shellSurface ==
nullptr)
1465 return d->shellSurface->frameMarginTop();
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478void QWaylandQtShellChrome::setFrameMarginBottom(
int bottom)
1480 Q_D(QWaylandQtShellChrome);
1481 if (d->explicitFrameMargins.bottom() == bottom)
1483 d->explicitFrameMargins.setBottom(bottom);
1484 d->automaticFrameMargins =
false;
1485 updateDecorations();
1487 emit frameMarginChanged();
1490int QWaylandQtShellChrome::frameMarginBottom()
const
1492 Q_D(
const QWaylandQtShellChrome);
1493 if (d->shellSurface ==
nullptr)
1495 return d->shellSurface->frameMarginBottom();
1500#include "moc_qwaylandqtshellchrome.cpp"
void updateDecorationInteraction(quint8 flags, const QQuickHandlerPoint ¢roid)
static int randomPos(int windowSize, int screenSize)