Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandqtshellchrome.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
6#include "qwaylandqtshell.h"
7
8#include <QtWaylandCompositor/qwaylandquickshellsurfaceitem.h>
9
11
13{
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));
20}
21
23 const QQuickHandlerPoint &centroid)
24{
25 if (shellSurface == nullptr)
26 return;
27
32 }
33
35 return;
36
38 float dx = position.x() - decorationInteractionPosition.x();
39 float dy = position.y() - decorationInteractionPosition.y();
40
41 float minWidth = qMax(0, shellSurface->minimumSize().width());
42 float minHeight = qMax(0, shellSurface->minimumSize().height());
43
44 float maxWidth = shellSurface->maximumSize().width();
45 float maxHeight = shellSurface->maximumSize().height();
46
47 float minX = maxWidth >= 0.0f
49 : -FLT_MAX;
50 float minY = maxHeight >= 0.0f
52 : -FLT_MAX;
53 float maxX = maxWidth >= 0
55 : FLT_MAX;
56 float maxY = maxHeight >= 0.0f
58 : FLT_MAX;
59
60 float newLeft = decorationInteractionGeometry.left();
62 newLeft = qBound(minX,
63 newLeft + dx,
64 float(decorationInteractionGeometry.right() - minWidth));
65 }
66
67 float newTop = decorationInteractionGeometry.top();
69 newTop = qBound(minY,
70 newTop + dy,
72 }
73
74 float newRight = decorationInteractionGeometry.right();
76 newRight = qBound(decorationInteractionGeometry.left() + minWidth,
77 newRight + dx,
78 maxX);
79 }
80
81 float newBottom = decorationInteractionGeometry.bottom();
83 newBottom = qBound(decorationInteractionGeometry.top() + minHeight,
84 newBottom + dy,
85 maxY);
86 }
87
89 QRect(int(newLeft), int(newTop),
90 int(newRight - newLeft), int(newBottom - newTop)));
91}
92
122
129
131{
133 if (d->shell != nullptr)
134 d->shell->unregisterChrome(this);
135}
136
137void QWaylandQtShellChrome::init()
138{
141
144
146 this, &QWaylandQtShellChrome::updateDecorations);
147
149 this, &QWaylandQtShellChrome::updateDecorations);
150
152 this, &QWaylandQtShellChrome::updateDecorations);
153
155 this, &QWaylandQtShellChrome::updateDecorations);
156
158 this, &QWaylandQtShellChrome::updateDecorations);
159
161 this, &QWaylandQtShellChrome::updateDecorations);
162
164 this, &QWaylandQtShellChrome::updateDecorations);
165
167 this, &QWaylandQtShellChrome::updateDecorations);
168
170 this, &QWaylandQtShellChrome::updateDecorations);
171}
172
180{
182 if (d->shellSurface == nullptr)
183 return;
184
186 if ((d->shellSurface->windowState() & Qt::WindowFullScreen) == Qt::WindowFullScreen)
187 newState = d->currentState & ~Qt::WindowFullScreen;
188 else
189 newState = d->currentState | Qt::WindowFullScreen;
190
193
194 setWindowState(newState);
195}
196
204{
206 if (d->shellSurface == nullptr)
207 return;
208
210 if ((d->shellSurface->windowState() & Qt::WindowMaximized) == Qt::WindowMaximized)
211 newState = d->currentState & ~Qt::WindowMaximized;
212 else
213 newState = d->currentState | Qt::WindowMaximized;
214
216 newState &= ~Qt::WindowMinimized;
217
218 setWindowState(newState);
219}
220
228{
230 if (d->shellSurface == nullptr)
231 return;
232
234 if ((d->shellSurface->windowState() & Qt::WindowMinimized) == Qt::WindowMinimized)
235 newState = d->currentState & ~Qt::WindowMinimized;
236 else
237 newState = d->currentState | Qt::WindowMinimized;
238
240 newState &= ~Qt::WindowMaximized;
241
242 setWindowState(newState);
243}
244
265{
267 if (d->shellSurfaceItem == shellSurfaceItem)
268 return;
269
270 if (d->shellSurfaceItem != nullptr)
271 d->shellSurfaceItem->disconnect(this);
272
273 d->shellSurfaceItem = shellSurfaceItem;
274
275 if (d->shellSurfaceItem != nullptr) {
277 this, &QWaylandQtShellChrome::updateShellSurface);
280 }
281
282 updateShellSurface();
284}
285
287{
288 Q_D(const QWaylandQtShellChrome);
289 return d->shellSurfaceItem;
290}
291
292void QWaylandQtShellChrome::stopGrab()
293{
296}
297
298void QWaylandQtShellChrome::leftResize()
299{
301 if (!d->leftResizeHandleHandler->active())
302 return;
303
305 d->leftResizeHandleHandler->centroid());
306}
307
308void QWaylandQtShellChrome::rightResize()
309{
311 if (!d->rightResizeHandleHandler->active())
312 return;
313
315 d->rightResizeHandleHandler->centroid());
316}
317
318void QWaylandQtShellChrome::topResize()
319{
321 if (!d->topResizeHandleHandler->active())
322 return;
323
325 d->topResizeHandleHandler->centroid());
326}
327
328void QWaylandQtShellChrome::bottomResize()
329{
331 if (!d->bottomResizeHandleHandler->active())
332 return;
333
335 d->bottomResizeHandleHandler->centroid());
336}
337
338void QWaylandQtShellChrome::topLeftResize()
339{
341 if (!d->topLeftResizeHandleHandler->active())
342 return;
343
346 d->topLeftResizeHandleHandler->centroid());
347}
348
349void QWaylandQtShellChrome::topRightResize()
350{
352 if (!d->topRightResizeHandleHandler->active())
353 return;
354
357 d->topRightResizeHandleHandler->centroid());
358}
359
360void QWaylandQtShellChrome::bottomLeftResize()
361{
363 if (!d->bottomLeftResizeHandleHandler->active())
364 return;
365
368 d->bottomLeftResizeHandleHandler->centroid());
369}
370
371void QWaylandQtShellChrome::bottomRightResize()
372{
374 if (!d->bottomRightResizeHandleHandler->active())
375 return;
376
379 d->bottomRightResizeHandleHandler->centroid());
380}
381
382void QWaylandQtShellChrome::titleBarMove()
383{
385 if (!d->titleBarHandler->active())
386 return;
387
389 QQuickHandlerPoint centroid = d->titleBarHandler->centroid();
391 d->decorationInteraction = flags;
392 d->decorationInteractionPosition = d->shellSurface->windowPosition() - centroid.scenePressPosition();
393
394 activate();
395 }
396
397 if (d->decorationInteraction != flags)
398 return;
399
400 QPointF position = d->constrainPoint(centroid.scenePosition());
401 d->shellSurface->setWindowPosition((position + d->decorationInteractionPosition).toPoint());
402}
403
439{
440 Q_D(const QWaylandQtShellChrome);
441 return d->titleBar;
442}
443
445{
447 if (d->titleBar == item)
448 return;
449
450 if (d->titleBar != nullptr) {
451 d->titleBar->disconnect(this);
452
453 delete d->titleBarHandler;
454 d->titleBarHandler = nullptr;
455 }
456
457 d->titleBar = item;
458
459 if (d->titleBar != nullptr) {
461 this, &QWaylandQtShellChrome::updateDecorations);
462
463 d->titleBarHandler = new QQuickDragHandler(d->titleBar);
464 d->titleBarHandler->setTarget(nullptr);
465
467 this, &QWaylandQtShellChrome::stopGrab);
469 this, &QWaylandQtShellChrome::activateOnGrab);
471 this, &QWaylandQtShellChrome::titleBarMove);
472 }
473
475}
476
504{
505 Q_D(const QWaylandQtShellChrome);
506 return d->leftResizeHandle;
507}
508
510{
512 if (d->leftResizeHandle == item)
513 return;
514
515 if (d->leftResizeHandle != nullptr) {
516 d->leftResizeHandle->disconnect(this);
517
518 delete d->leftResizeHandleHandler;
519 d->leftResizeHandleHandler = nullptr;
520 }
521
522 d->leftResizeHandle = item;
523
524 if (d->leftResizeHandle != nullptr) {
525 connect(d->leftResizeHandle, &QQuickItem::widthChanged,
526 this, &QWaylandQtShellChrome::updateDecorations);
527
528 d->leftResizeHandleHandler = new QQuickDragHandler(d->leftResizeHandle);
529 d->leftResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
530 d->leftResizeHandleHandler->setTarget(nullptr);
531
532 connect(d->leftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
533 this, &QWaylandQtShellChrome::stopGrab);
534 connect(d->leftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
535 this, &QWaylandQtShellChrome::leftResize);
536 }
537
539}
540
568{
569 Q_D(const QWaylandQtShellChrome);
570 return d->rightResizeHandle;
571}
572
574{
576 if (d->rightResizeHandle == item)
577 return;
578
579 if (d->rightResizeHandle != nullptr) {
580 d->rightResizeHandle->disconnect(this);
581
582 delete d->rightResizeHandleHandler;
583 d->rightResizeHandleHandler = nullptr;
584 }
585
586 d->rightResizeHandle = item;
587
588 if (d->rightResizeHandle != nullptr) {
589 connect(d->rightResizeHandle, &QQuickItem::widthChanged,
590 this, &QWaylandQtShellChrome::updateDecorations);
591
592 d->rightResizeHandleHandler = new QQuickDragHandler(d->rightResizeHandle);
593 d->rightResizeHandleHandler->setCursorShape(Qt::SizeHorCursor);
594 d->rightResizeHandleHandler->setTarget(nullptr);
595
596 connect(d->rightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
597 this, &QWaylandQtShellChrome::stopGrab);
598 connect(d->rightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
599 this, &QWaylandQtShellChrome::rightResize);
600 }
601
603}
604
632{
633 Q_D(const QWaylandQtShellChrome);
634 return d->topResizeHandle;
635}
636
638{
640 if (d->topResizeHandle == item)
641 return;
642
643 if (d->topResizeHandle != nullptr) {
644 d->topResizeHandle->disconnect(this);
645
646 delete d->topResizeHandleHandler;
647 d->topResizeHandleHandler = nullptr;
648 }
649
650 d->topResizeHandle = item;
651
652 if (d->topResizeHandle != nullptr) {
653 connect(d->topResizeHandle, &QQuickItem::heightChanged,
654 this, &QWaylandQtShellChrome::updateDecorations);
655
656 d->topResizeHandleHandler = new QQuickDragHandler(d->topResizeHandle);
657 d->topResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
658 d->topResizeHandleHandler->setTarget(nullptr);
659
660 connect(d->topResizeHandleHandler, &QQuickPointerHandler::grabChanged,
661 this, &QWaylandQtShellChrome::stopGrab);
662 connect(d->topResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
663 this, &QWaylandQtShellChrome::topResize);
664 }
665
667}
668
696{
697 Q_D(const QWaylandQtShellChrome);
698 return d->bottomResizeHandle;
699}
700
702{
704 if (d->bottomResizeHandle == item)
705 return;
706
707 if (d->bottomResizeHandle != nullptr) {
708 d->bottomResizeHandle->disconnect(this);
709
710 delete d->bottomResizeHandleHandler;
711 d->bottomResizeHandleHandler = nullptr;
712 }
713
714 d->bottomResizeHandle = item;
715
716 if (d->bottomResizeHandle != nullptr) {
717 connect(d->bottomResizeHandle, &QQuickItem::heightChanged,
718 this, &QWaylandQtShellChrome::updateDecorations);
719
720 d->bottomResizeHandleHandler = new QQuickDragHandler(d->bottomResizeHandle);
721 d->bottomResizeHandleHandler->setCursorShape(Qt::SizeVerCursor);
722 d->bottomResizeHandleHandler->setTarget(nullptr);
723
724 connect(d->bottomResizeHandleHandler, &QQuickPointerHandler::grabChanged,
725 this, &QWaylandQtShellChrome::stopGrab);
726 connect(d->bottomResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
727 this, &QWaylandQtShellChrome::bottomResize);
728
729 }
730
732}
733
759{
760 Q_D(const QWaylandQtShellChrome);
761 return d->topLeftResizeHandle;
762}
763
765{
767 if (d->topLeftResizeHandle == item)
768 return;
769
770 if (d->topLeftResizeHandle != nullptr) {
771 delete d->topLeftResizeHandleHandler;
772 d->topLeftResizeHandleHandler = nullptr;
773 }
774
775 d->topLeftResizeHandle = item;
776
777 if (d->topLeftResizeHandle != nullptr) {
778 d->topLeftResizeHandleHandler = new QQuickDragHandler(d->topLeftResizeHandle);
779 d->topLeftResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
780 d->topLeftResizeHandleHandler->setTarget(nullptr);
781
782 connect(d->topLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
783 this, &QWaylandQtShellChrome::stopGrab);
784 connect(d->topLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
785 this, &QWaylandQtShellChrome::topLeftResize);
786 }
787
789}
790
816{
817 Q_D(const QWaylandQtShellChrome);
818 return d->bottomLeftResizeHandle;
819}
820
822{
824 if (d->bottomLeftResizeHandle == item)
825 return;
826
827 if (d->bottomLeftResizeHandle != nullptr) {
828 delete d->bottomLeftResizeHandleHandler;
829 d->bottomLeftResizeHandleHandler = nullptr;
830 }
831
832 d->bottomLeftResizeHandle = item;
833
834 if (d->bottomLeftResizeHandle != nullptr) {
835 d->bottomLeftResizeHandleHandler = new QQuickDragHandler(d->bottomLeftResizeHandle);
836 d->bottomLeftResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
837 d->bottomLeftResizeHandleHandler->setTarget(nullptr);
838
839 connect(d->bottomLeftResizeHandleHandler, &QQuickPointerHandler::grabChanged,
840 this, &QWaylandQtShellChrome::stopGrab);
841 connect(d->bottomLeftResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
842 this, &QWaylandQtShellChrome::bottomLeftResize);
843 }
844
846}
847
873{
874 Q_D(const QWaylandQtShellChrome);
875 return d->topRightResizeHandle;
876}
877
879{
881 if (d->topRightResizeHandle == item)
882 return;
883
884 if (d->topRightResizeHandle != nullptr) {
885 delete d->topRightResizeHandleHandler;
886 d->topRightResizeHandleHandler = nullptr;
887 }
888
889 d->topRightResizeHandle = item;
890
891 if (d->topRightResizeHandle != nullptr) {
892 d->topRightResizeHandleHandler = new QQuickDragHandler(d->topRightResizeHandle);
893 d->topRightResizeHandleHandler->setCursorShape(Qt::SizeBDiagCursor);
894 d->topRightResizeHandleHandler->setTarget(nullptr);
895
896 connect(d->topRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
897 this, &QWaylandQtShellChrome::stopGrab);
898 connect(d->topRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
899 this, &QWaylandQtShellChrome::topRightResize);
900 }
901
903}
904
930{
931 Q_D(const QWaylandQtShellChrome);
932 return d->bottomRightResizeHandle;
933}
934
936{
938 if (d->bottomRightResizeHandle == item)
939 return;
940
941 if (d->bottomRightResizeHandle != nullptr) {
942 delete d->bottomRightResizeHandleHandler;
943 d->bottomRightResizeHandleHandler = nullptr;
944 }
945
946 d->bottomRightResizeHandle = item;
947
948 if (d->bottomRightResizeHandle != nullptr) {
949 d->bottomRightResizeHandleHandler = new QQuickDragHandler(d->bottomRightResizeHandle);
950 d->bottomRightResizeHandleHandler->setCursorShape(Qt::SizeFDiagCursor);
951 d->bottomRightResizeHandleHandler->setTarget(nullptr);
952
953 connect(d->bottomRightResizeHandleHandler, &QQuickPointerHandler::grabChanged,
954 this, &QWaylandQtShellChrome::stopGrab);
955 connect(d->bottomRightResizeHandleHandler, &QQuickMultiPointHandler::centroidChanged,
956 this, &QWaylandQtShellChrome::bottomRightResize);
957 }
958
960}
961
972{
974 if (d->maximizedRect == rect)
975 return;
976
977 d->maximizedRect = rect;
979}
980
982{
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();
988
989 return QRect{};
990}
991
992void QWaylandQtShellChrome::updateDecorations()
993{
995 if (d->shellSurface == nullptr)
996 return;
997
998 bool decorations = hasDecorations();
999 bool titleBarShowing = hasTitleBar();
1000
1001 QMargins margins;
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());
1009
1010 margins.setTop((decorations && d->topResizeHandle != nullptr ? d->topResizeHandle->height() : 0)
1011 + (titleBarShowing && d->titleBar != nullptr ? d->titleBar->height() : 0));
1012 } else {
1013 margins = d->explicitFrameMargins;
1014 }
1015 d->shellSurface->setFrameMargins(margins);
1016
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);
1035
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);
1055}
1056
1057void QWaylandQtShellChrome::updateGeometry()
1058{
1060 if (d->shellSurface == nullptr)
1061 return;
1062
1063 QRect windowGeometry = d->shellSurface->windowGeometry();
1064
1065 QPointF position = windowGeometry.topLeft();
1066 position.rx() -= d->shellSurface->frameMarginLeft();
1067 position.ry() -= d->shellSurface->frameMarginTop();
1068
1069 QSizeF size = windowGeometry.size();
1070 size.rwidth() += d->shellSurface->frameMarginLeft() + d->shellSurface->frameMarginRight();
1071 size.rheight() += d->shellSurface->frameMarginTop() + d->shellSurface->frameMarginBottom();
1072
1074 setSize(size);
1075}
1076
1077void QWaylandQtShellChrome::updateSurface()
1078{
1080 QWaylandSurface *surface = d->shellSurface != nullptr ? d->shellSurface->surface() : nullptr;
1081 if (d->surface == surface)
1082 return;
1083
1084 if (d->surface != nullptr)
1085 d->surface->disconnect(this);
1086
1087 d->surface = surface;
1088
1089 if (d->surface != nullptr) {
1091 this, &QWaylandQtShellChrome::updateAutomaticPosition);
1092 }
1093}
1094
1095void QWaylandQtShellChrome::updateShellSurface()
1096{
1098 QWaylandQtShellSurface *sf = d->shellSurfaceItem != nullptr
1099 ? qobject_cast<QWaylandQtShellSurface *>(d->shellSurfaceItem->shellSurface())
1100 : nullptr;
1101 if (d->shellSurface == sf)
1102 return;
1103
1104 if (d->shellSurface != nullptr) {
1105 d->shellSurface->disconnect(this);
1106 if (d->shell != nullptr)
1107 d->shell->unregisterChrome(this);
1108 d->shell = nullptr;
1109 }
1110
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);
1116
1117 updateWindowFlags();
1119 this, &QWaylandQtShellChrome::updateWindowFlags);
1121 this, &QWaylandQtShellChrome::updateWindowState);
1123 this, &QWaylandQtShellChrome::updateGeometry);
1125 this, &QWaylandQtShellChrome::updateGeometry);
1131 this, &QWaylandQtShellChrome::updateActiveState);
1133 this, &QWaylandQtShellChrome::updateSurface);
1134 }
1135
1136 updateDecorations();
1137 updateSurface();
1138}
1139
1140void QWaylandQtShellChrome::updateWindowState()
1141{
1143 if (d->shellSurface == nullptr)
1144 return;
1145
1146 setWindowState(d->shellSurface->windowState());
1147}
1148
1149void QWaylandQtShellChrome::updateWindowFlags()
1150{
1152
1153 uint nextFlags = d->shellSurface == nullptr || d->shellSurface->windowFlags() == Qt::Window
1154 ? d->defaultFlags
1155 : d->shellSurface->windowFlags();
1156
1157 if (d->currentFlags != nextFlags) {
1158 d->currentFlags = nextFlags;
1160 }
1161}
1162
1172{
1173 Q_D(const QWaylandQtShellChrome);
1174 return d->currentFlags;
1175}
1176
1186{
1187 Q_D(const QWaylandQtShellChrome);
1188 return d->currentState;
1189}
1190
1192{
1193 Q_D(const QWaylandQtShellChrome);
1194
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;
1199 return !frameless;
1200}
1201
1209{
1210 Q_D(const QWaylandQtShellChrome);
1211
1212 return hasTitleBar() && (d->currentFlags & Qt::Window) == Qt::Window;
1213}
1214
1215QRect QWaylandQtShellChrome::maxContentRect() const
1216{
1217 Q_D(const QWaylandQtShellChrome);
1218 if (d->shellSurface == nullptr)
1219 return QRect{};
1220
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();
1225
1226 return QRect(x0, y0, x1 - x0, y1 - y0);
1227}
1228
1229static int randomPos(int windowSize, int screenSize)
1230{
1231 return (windowSize >= screenSize) ? 0 : rand() % (screenSize - windowSize);
1232}
1233
1234void QWaylandQtShellChrome::setWindowState(uint nextState)
1235{
1237
1238 if (d->currentState == nextState)
1239 return;
1240
1241 if (d->shellSurface == nullptr || d->shellSurfaceItem == nullptr)
1242 return;
1243
1244 QWaylandOutput *output = d->shellSurfaceItem->output();
1245 if (output == nullptr)
1246 return;
1247
1248 if ((d->currentState & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) == 0) {
1249 d->restoreGeometry = d->shellSurface->windowGeometry();
1250 }
1251
1252 d->currentState = nextState;
1254
1255 if ((nextState & Qt::WindowMinimized) != 0) {
1256 d->shellSurface->requestWindowGeometry(nextState, QRect(0, 0, 1, 1));
1257 d->shellSurfaceItem->setVisible(false);
1258 deactivate();
1259 } else if ((nextState & Qt::WindowFullScreen) != 0) {
1260 d->shellSurfaceItem->setVisible(true);
1261 d->shellSurface->requestWindowGeometry(nextState, QRect(QPoint(0, 0), output->window()->size()));
1262 activate();
1263 } else if ((nextState & Qt::WindowMaximized) != 0) {
1264 d->shellSurfaceItem->setVisible(true);
1265 d->shellSurface->requestWindowGeometry(nextState, maxContentRect());
1266 activate();
1267 } else {
1268 d->shellSurfaceItem->setVisible(true);
1269 d->shellSurface->requestWindowGeometry(nextState, d->restoreGeometry);
1270 activate();
1271 }
1272}
1273
1274void QWaylandQtShellChrome::updateAutomaticPosition()
1275{
1277 if (!d->positionSet && d->shellSurface != nullptr) {
1278 bool randomize = d->shellSurface->positionAutomatic();
1279 QRect rect = d->shellSurface->windowGeometry();
1280 QRect space = maxContentRect();
1281
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());
1286
1287 d->shellSurface->setWindowPosition(QPoint(xpos, ypos));
1288 d->positionSet = true;
1289 }
1290}
1291
1299{
1301 if (d->shellSurface != nullptr)
1302 d->shellSurface->setActive(false);
1303}
1304
1305void QWaylandQtShellChrome::activateOnGrab(QPointingDevice::GrabTransition transition)
1306{
1308 if (d->titleBarHandler != nullptr) {
1309 switch (transition) {
1313 activate();
1314 break;
1315 default:
1316 break;
1317 }
1318 }
1319}
1320
1329{
1331 if (d->shellSurface != nullptr)
1332 d->shellSurface->setActive(true);
1333 raise();
1334}
1335
1343{
1345 if (d->shellSurfaceItem != nullptr)
1346 d->shellSurfaceItem->raise();
1347}
1348
1356{
1358 if (d->shellSurfaceItem != nullptr)
1359 d->shellSurfaceItem->lower();
1360}
1361
1362void QWaylandQtShellChrome::updateActiveState()
1363{
1365 if (d->shellSurface == nullptr)
1366 return;
1367
1368 if (d->shellSurface->active()) {
1369 raise();
1370 emit activated();
1371 } else {
1372 emit deactivated();
1373 }
1374}
1375
1387{
1389 if (d->explicitFrameMargins.left() == left)
1390 return;
1391
1392 d->explicitFrameMargins.setLeft(left);
1393 d->automaticFrameMargins = false;
1394 updateDecorations();
1395
1397}
1398
1400{
1401 Q_D(const QWaylandQtShellChrome);
1402 if (d->shellSurface == nullptr)
1403 return 0;
1404 return d->shellSurface->frameMarginLeft();
1405}
1406
1418{
1420 if (d->explicitFrameMargins.right() == right)
1421 return;
1422
1423 d->explicitFrameMargins.setRight(right);
1424 d->automaticFrameMargins = false;
1425 updateDecorations();
1426
1428}
1429
1431{
1432 Q_D(const QWaylandQtShellChrome);
1433 if (d->shellSurface == nullptr)
1434 return 0;
1435 return d->shellSurface->frameMarginRight();
1436}
1437
1449{
1451 if (d->explicitFrameMargins.top() == top)
1452 return;
1453 d->explicitFrameMargins.setTop(top);
1454 d->automaticFrameMargins = false;
1455 updateDecorations();
1456
1458}
1459
1461{
1462 Q_D(const QWaylandQtShellChrome);
1463 if (d->shellSurface == nullptr)
1464 return 0;
1465 return d->shellSurface->frameMarginTop();
1466}
1467
1479{
1481 if (d->explicitFrameMargins.bottom() == bottom)
1482 return;
1483 d->explicitFrameMargins.setBottom(bottom);
1484 d->automaticFrameMargins = false;
1485 updateDecorations();
1486
1488}
1489
1491{
1492 Q_D(const QWaylandQtShellChrome);
1493 if (d->shellSurface == nullptr)
1494 return 0;
1495 return d->shellSurface->frameMarginBottom();
1496}
1497
1499
1500#include "moc_qwaylandqtshellchrome.cpp"
\inmodule QtCore
Definition qmargins.h:24
constexpr void setTop(int top) noexcept
Sets the Top margin to Top.
Definition qmargins.h:122
constexpr void setBottom(int bottom) noexcept
Sets the bottom margin to bottom.
Definition qmargins.h:128
constexpr void setLeft(int left) noexcept
Sets the left margin to left.
Definition qmargins.h:119
constexpr void setRight(int right) noexcept
Sets the right margin to right.
Definition qmargins.h:125
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal & ry() noexcept
Returns a reference to the y coordinate of this point.
Definition qpoint.h:368
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
Definition qpoint.h:363
\inmodule QtCore\reentrant
Definition qpoint.h:25
GrabTransition
This enum represents a transition of exclusive or passive grab from one object (possibly nullptr) to ...
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void heightChanged()
Flags flags() const
Returns the item flags for this item.
void setSize(const QSizeF &size)
void widthChanged()
QPointF position() const
void grabChanged(QPointingDevice::GrabTransition transition, QEventPoint point)
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
\inmodule QtCore
Definition qsize.h:208
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\qmltype WaylandOutput \instantiates QWaylandOutput \inqmlmodule QtWayland.Compositor
void updateDecorationInteraction(quint8 flags, const QQuickHandlerPoint &centroid)
QPointF constrainPoint(const QPointF &point) const
QPointer< QWaylandQtShellSurface > shellSurface
void currentWindowFlagsChanged()
void bottomResizeHandleChanged()
void setFrameMarginBottom(int bottom)
\qmlproperty int QtShellChrome::frameMarginBottom
void setMaximizedRect(const QRect &rect)
\qmlproperty rect QtShellChrome::maximizedRect
void bottomLeftResizeHandleChanged()
void bottomRightResizeHandleChanged()
uint currentWindowFlags() const
\qmlproperty int QtShellChrome::windowFlags
void currentWindowStateChanged()
void lower()
\qmlmethod void QtShellChrome::lower()
void toggleMinimized()
\qmlmethod void QtShellChrome::toggleMinimized()
void raise()
\qmlmethod void QtShellChrome::raise()
void setFrameMarginRight(int right)
\qmlproperty int QtShellChrome::frameMarginRight
void setTopRightResizeHandle(QQuickItem *item)
void setBottomLeftResizeHandle(QQuickItem *item)
void setFrameMarginLeft(int left)
\qmlproperty int QtShellChrome::frameMarginLeft
void toggleFullScreen()
\qmlmethod void QtShellChrome::toggleFullScreen()
void setFrameMarginTop(int top)
\qmlproperty int QtShellChrome::frameMarginTop
void setBottomRightResizeHandle(QQuickItem *item)
void deactivate()
\qmlmethod void QtShellChrome::deactivate()
QWaylandQtShellChrome(QQuickItem *parent=nullptr)
\qmltype QtShellChrome \instantiates QWaylandQtShellChrome \inqmlmodule QtWayland....
QWaylandQuickShellSurfaceItem * shellSurfaceItem
void topRightResizeHandleChanged()
void setTopLeftResizeHandle(QQuickItem *item)
void toggleMaximized()
\qmlmethod void QtShellChrome::toggleMaximized()
void setShellSurfaceItem(QWaylandQuickShellSurfaceItem *shellSurfaceItem)
\qmlproperty ShellSurfaceItem QtShellChrome::shellSurfaceItem
void setTitleBar(QQuickItem *item)
void setTopResizeHandle(QQuickItem *item)
uint currentWindowState() const
\qmlproperty int QtShellChrome::windowState
void topLeftResizeHandleChanged()
void setLeftResizeHandle(QQuickItem *item)
void setRightResizeHandle(QQuickItem *item)
void setBottomResizeHandle(QQuickItem *item)
void activate()
\qmlmethod void QtShellChrome::activate()
Q_INVOKABLE void requestWindowGeometry(uint windowState, const QRect &windowGeometry)
\qmlmethod void QtShellSurface::requestWindowGeometry(int windowState, rect windowGeometry)
void surfaceDestroyed()
\qmlsignal void QtWayland.Compositor::WaylandQuickItem::surfaceDestroyed()
\qmltype ShellSurfaceItem \instantiates QWaylandQuickShellSurfaceItem \inherits WaylandQuickItem \inq...
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
void hasContentChanged()
rect
[4]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ SizeHorCursor
@ SizeVerCursor
@ SizeFDiagCursor
@ SizeBDiagCursor
@ FramelessWindowHint
Definition qnamespace.h:225
@ Popup
Definition qnamespace.h:211
@ Window
Definition qnamespace.h:207
@ Tool
Definition qnamespace.h:212
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
n void setPosition(void) \n\
GLint GLsizei GLsizei height
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLfloat GLfloat GLfloat x1
GLdouble GLdouble GLdouble GLdouble top
GLfloat minY
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLuint GLfloat x0
GLbitfield flags
GLuint GLfloat GLfloat y0
GLfloat GLfloat GLfloat GLfloat maxX
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define emit
unsigned int uint
Definition qtypes.h:34
unsigned char quint8
Definition qtypes.h:46
QT_BEGIN_NAMESPACE typedef uchar * output
static int randomPos(int windowSize, int screenSize)
QObject::connect nullptr
QGraphicsItem * item