forked from linuxdeepin/treeland
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsurfacewrapper.cpp
More file actions
2481 lines (2126 loc) · 72.3 KB
/
Copy pathsurfacewrapper.cpp
File metadata and controls
2481 lines (2126 loc) · 72.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "surface/surfacewrapper.h"
#include "common/treelandlogging.h"
#include "core/qmlengine.h"
#include "output/output.h"
#include "seat/helper.h"
#include "treelanduserconfig.hpp"
#include "workspace/workspace.h"
#include "wtoplevelsurface.h"
#include <winputpopupsurfaceitem.h>
#include <wlayersurface.h>
#include <wlayersurfaceitem.h>
#include <woutput.h>
#include <woutputitem.h>
#include <woutputrenderwindow.h>
#include <wsocket.h>
#include <wxdgpopupsurfaceitem.h>
#include <wxdgtoplevelsurfaceitem.h>
#include <wxwaylandsurface.h>
#include <wxwaylandsurfaceitem.h>
#include <qwbuffer.h>
#include <qwlayershellv1.h>
#include <QColor>
#include <QVariant>
#define OPEN_ANIMATION 1
#define CLOSE_ANIMATION 2
#define ALWAYSONTOPLAYER 1
SurfaceWrapper::SurfaceWrapper(QmlEngine *qmlEngine,
WToplevelSurface *shellSurface,
Type type,
const QString &appId,
QQuickItem *parent)
: QQuickItem(parent)
, m_engine(qmlEngine)
, m_shellSurface(shellSurface)
, m_type(type)
, m_positionAutomatic(true)
, m_visibleDecoration(true)
, m_clipInOutput(false)
, m_noDecoration(true)
, m_noTitleBar(true)
, m_noCornerRadius(false)
, m_alwaysOnTop(false)
, m_skipSwitcher(false)
, m_skipDockPreView(true)
, m_skipMutiTaskView(false)
, m_isDdeShellSurface(false)
, m_xwaylandPositionFromSurface(true)
, m_wrapperAboutToRemove(false)
, m_isProxy(false)
, m_hideByWorkspace(false)
, m_hideByshowDesk(true)
, m_hideByLockScreen(false)
, m_confirmHideByLockScreen(false)
, m_blur(false)
, m_isActivated(false)
, m_attention(false)
, m_isIMCandidatePanel(false)
, m_resizable(false)
, m_maximizable(false)
, m_modal(false)
, m_appId(appId)
{
QQmlEngine::setContextForObject(this, qmlEngine->rootContext());
setup();
}
SurfaceWrapper::SurfaceWrapper(SurfaceWrapper *original, QQuickItem *parent)
: QQuickItem(parent)
, m_engine(original->m_engine)
, m_shellSurface(original->m_shellSurface)
, m_type(original->m_type)
, m_positionAutomatic(true)
, m_visibleDecoration(true)
, m_clipInOutput(false)
, m_noDecoration(true)
, m_noTitleBar(true)
, m_noCornerRadius(false)
, m_alwaysOnTop(false)
, m_skipSwitcher(false)
, m_skipDockPreView(true)
, m_skipMutiTaskView(false)
, m_isDdeShellSurface(false)
, m_xwaylandPositionFromSurface(true)
, m_wrapperAboutToRemove(false)
, m_isProxy(true)
, m_hideByWorkspace(false)
, m_hideByshowDesk(true)
, m_hideByLockScreen(false)
, m_confirmHideByLockScreen(false)
, m_blur(false)
, m_isActivated(false)
, m_attention(false)
, m_isIMCandidatePanel(false)
, m_resizable(false)
, m_maximizable(false)
, m_modal(false)
, m_appId(original->m_appId)
{
QQmlEngine::setContextForObject(this, m_engine->rootContext());
if (original->m_shellSurface) {
setup();
} else {
setImplicitSize(original->implicitWidth(), original->implicitHeight());
auto iconVar = original->prelaunchSplash()
? original->prelaunchSplash()->property("iconBuffer")
: QVariant();
QColor bgColor = original->prelaunchSplash()
? original->prelaunchSplash()->property("backgroundColor").value<QColor>()
: QColor("#ffffff");
m_prelaunchSplash =
m_engine->createPrelaunchSplash(this,
original->radius(),
iconVar.value<QW_NAMESPACE::qw_buffer *>(),
bgColor);
setNoDecoration(false);
connect(original, &SurfaceWrapper::surfaceItemCreated, this, [this, original]() {
m_shellSurface = original->m_shellSurface;
m_type = original->m_type;
if (m_prelaunchSplash) {
m_prelaunchSplash->deleteLater();
m_prelaunchSplash = nullptr;
}
setup();
});
}
}
// Constructor used for the prelaunch splash
SurfaceWrapper::SurfaceWrapper(QmlEngine *qmlEngine,
QQuickItem *parent,
const QSize &initialSize,
const QString &appId,
QW_NAMESPACE::qw_buffer *iconBuffer,
const QColor &backgroundColor)
: QQuickItem(parent)
, m_engine(qmlEngine)
, m_shellSurface(nullptr)
, m_type(Type::SplashScreen)
, m_positionAutomatic(true)
, m_visibleDecoration(true)
, m_clipInOutput(false)
, m_noDecoration(true)
, m_noTitleBar(true)
, m_noCornerRadius(false)
, m_alwaysOnTop(false)
, m_skipSwitcher(false)
, m_skipDockPreView(false)
, m_skipMutiTaskView(false)
, m_isDdeShellSurface(false)
, m_xwaylandPositionFromSurface(true)
, m_wrapperAboutToRemove(false)
, m_isProxy(false)
, m_hideByWorkspace(false)
, m_hideByshowDesk(true)
, m_hideByLockScreen(false)
, m_confirmHideByLockScreen(false)
, m_blur(false)
, m_isActivated(false)
, m_attention(false)
, m_isIMCandidatePanel(false)
, m_resizable(false)
, m_maximizable(false)
, m_modal(false)
, m_appId(appId)
{
QQmlEngine::setContextForObject(this, qmlEngine->rootContext());
if (initialSize.isValid() && initialSize.width() > 0 && initialSize.height() > 0) {
// Also set implicit size to keep QML layout consistent
setImplicitSize(initialSize.width(), initialSize.height());
qCDebug(lcTlSurface) << "Prelaunch Splash: set initial size to" << initialSize;
} else {
setImplicitSize(800, 600);
}
m_prelaunchSplash =
m_engine->createPrelaunchSplash(this, radius(), iconBuffer, backgroundColor);
setNoDecoration(false);
updateHasActiveCapability(ActiveControlState::HasActivateCapability, true);
updateHasActiveCapability(ActiveControlState::MappedOrSplash, true); // Splash is true
}
void SurfaceWrapper::invalidate()
{
Q_ASSERT_X(!m_wrapperAboutToRemove, Q_FUNC_INFO, "Can't call `invalidate` twice!");
m_wrapperAboutToRemove = true;
Q_EMIT aboutToBeInvalidated();
if (!m_skipDockPreView)
setSkipDockPreView(true);
if (m_container) {
m_container->removeSurface(this);
m_container = nullptr;
}
if (m_ownsOutput) {
m_ownsOutput->removeSurface(this);
m_ownsOutput = nullptr;
}
if (m_parentSurface) {
m_parentSurface->removeSubSurface(this);
m_parentSurface = nullptr;
}
for (auto subS : std::as_const(m_subSurfaces)) {
subS->m_parentSurface = nullptr;
}
updateHasActiveCapability(ActiveControlState::MappedOrSplash, false);
updateFocusControlState(FocusControlState::Mapped, false);
m_subSurfaces.clear();
m_shellSurface = nullptr;
if (m_surfaceItem)
m_surfaceItem->disconnect(this);
}
SurfaceWrapper::~SurfaceWrapper()
{
if (!m_wrapperAboutToRemove) {
if (isWindowAnimationRunning()) {
qCWarning(lcTlSurface)
<< "SurfaceWrapper is being destroyed without destroy(); expected external"
" destroy() rather than QObject parent-child destruction";
}
invalidate();
}
if (m_titleBar) {
delete m_titleBar;
m_titleBar = nullptr;
}
if (m_decoration) {
delete m_decoration;
m_decoration = nullptr;
}
if (m_geometryAnimation) {
delete m_geometryAnimation;
m_geometryAnimation = nullptr;
}
if (m_windowAnimation) {
delete m_windowAnimation;
m_windowAnimation = nullptr;
}
if (m_coverContent) {
delete m_coverContent;
m_coverContent = nullptr;
}
// Ensure we do not hold stale connections to shellSurface; QPointer may already be null.
if (m_shellSurface) {
QObject::disconnect(m_shellSurface, nullptr, this, nullptr);
m_shellSurface.clear();
}
}
void SurfaceWrapper::setup()
{
Q_ASSERT(m_shellSurface);
Q_ASSERT(m_type != Type::SplashScreen);
updateActivateCapability();
updateFocusCapability();
switch (m_type) {
case Type::XdgToplevel:
m_surfaceItem = new WXdgToplevelSurfaceItem(this);
break;
case Type::XdgPopup:
m_surfaceItem = new WXdgPopupSurfaceItem(this);
break;
case Type::Layer:
m_surfaceItem = new WLayerSurfaceItem(this);
break;
case Type::XWayland: {
m_surfaceItem = new WXWaylandSurfaceItem(this);
connect(m_surfaceItem,
&WSurfaceItem::bufferScaleChanged,
this,
&SurfaceWrapper::updateSurfaceSizeRatio);
updateSurfaceSizeRatio();
break;
}
case Type::InputPopup:
m_surfaceItem = new WInputPopupSurfaceItem(this);
break;
#ifdef EXT_SESSION_LOCK_V1
case Type::LockScreen:
m_surfaceItem = new WSurfaceItem(this);
break;
#endif
default:
Q_UNREACHABLE();
}
QQmlEngine::setContextForObject(m_surfaceItem, m_engine->rootContext());
m_surfaceItem->setDelegate(m_engine->surfaceContentComponent());
m_surfaceItem->setResizeMode(WSurfaceItem::ManualResize);
m_surfaceItem->setShellSurface(m_shellSurface);
// Initialize focus policy even if focus capability state never toggles later.
m_surfaceItem->setFocusPolicy(hasFocusCapability() ? Qt::StrongFocus : Qt::NoFocus);
if (!m_isProxy) {
m_shellSurface->safeConnect(&WToplevelSurface::requestMinimize, this, [this]() {
minimize();
});
m_shellSurface->safeConnect(&WToplevelSurface::requestCancelMinimize, this, [this]() {
restoreFromMinimized();
});
m_shellSurface->safeConnect(&WToplevelSurface::requestMaximize,
this,
&SurfaceWrapper::maximize);
m_shellSurface->safeConnect(&WToplevelSurface::requestCancelMaximize,
this,
&SurfaceWrapper::unmaximize);
m_shellSurface->safeConnect(&WToplevelSurface::requestMove, this, [this]() {
Q_EMIT moveRequested();
});
m_shellSurface->safeConnect(&WToplevelSurface::requestResize,
this,
[this](WSeat *, Qt::Edges edge, quint32) {
Q_EMIT resizeRequested(edge);
});
m_shellSurface->safeConnect(&WToplevelSurface::requestFullscreen,
this,
&SurfaceWrapper::enterFullscreen);
m_shellSurface->safeConnect(&WToplevelSurface::requestCancelFullscreen,
this,
&SurfaceWrapper::leaveFullscreen);
if (m_type == Type::XdgToplevel) {
m_shellSurface->safeConnect(&WToplevelSurface::requestShowWindowMenu,
this,
[this](WSeat *, QPoint pos, quint32) {
Q_EMIT windowMenuRequested(
m_surfaceItem->mapFromSurface(pos).toPoint());
});
}
}
m_shellSurface->surface()->safeConnect(&WSurface::mappedChanged,
this,
&SurfaceWrapper::onMappedChanged);
Q_EMIT surfaceItemCreated();
// Forward WToplevelSurface appId changes when using fallback mode
if (m_appId.isEmpty()) {
m_shellSurface->safeConnect(&WToplevelSurface::appIdChanged, this, [this]() {
Q_EMIT appIdChanged();
});
}
if (m_type == Type::XdgToplevel || m_type == Type::XWayland) {
m_shellSurface->safeConnect(&WToplevelSurface::minimumSizeChanged,
this,
&SurfaceWrapper::updateSizeCapabilities);
m_shellSurface->safeConnect(&WToplevelSurface::maximumSizeChanged,
this,
&SurfaceWrapper::updateSizeCapabilities);
}
updateSizeCapabilities();
if (!m_prelaunchSplash) {
setImplicitSize(m_surfaceItem->implicitWidth(), m_surfaceItem->implicitHeight());
connect(m_surfaceItem, &WSurfaceItem::implicitWidthChanged, this, [this] {
setImplicitWidth(m_surfaceItem->implicitWidth());
});
connect(m_surfaceItem, &WSurfaceItem::implicitHeightChanged, this, [this] {
setImplicitHeight(m_surfaceItem->implicitHeight());
});
connect(m_surfaceItem,
&WSurfaceItem::boundingRectChanged,
this,
&SurfaceWrapper::updateBoundingRect);
}
if (auto client = m_shellSurface->waylandClient()) {
connect(client->socket(),
&WSocket::enabledChanged,
this,
&SurfaceWrapper::onSocketEnabledChanged);
onSocketEnabledChanged();
}
updateActivateCapability();
updateFocusCapability();
if (m_type == Type::XdgToplevel && !m_isProxy) // x11 will set later
setSkipDockPreView(false);
if (m_type == Type::Layer) {
if (auto *layerSurface = qobject_cast<WLayerSurface *>(m_shellSurface.data())) {
connect(layerSurface,
&WLayerSurface::keyboardInteractivityChanged,
this,
&SurfaceWrapper::updateFocusCapability);
}
}
if (m_type == Type::XWayland && !m_isProxy) {
auto xwaylandSurface = qobject_cast<WXWaylandSurface *>(m_shellSurface);
auto xwaylandSurfaceItem = qobject_cast<WXWaylandSurfaceItem *>(m_surfaceItem);
connect(xwaylandSurfaceItem,
&WXWaylandSurfaceItem::implicitPositionChanged,
this,
[this, xwaylandSurfaceItem]() {
if (m_xwaylandPositionFromSurface)
moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());
});
connect(this, &QQuickItem::xChanged, xwaylandSurface, [this, xwaylandSurfaceItem]() {
xwaylandSurfaceItem->moveTo(position(), !m_xwaylandPositionFromSurface);
});
connect(this, &QQuickItem::yChanged, xwaylandSurface, [this, xwaylandSurfaceItem]() {
xwaylandSurfaceItem->moveTo(position(), !m_xwaylandPositionFromSurface);
});
auto requestPos = xwaylandSurface->requestConfigureGeometry().topLeft();
if (!requestPos.isNull()) {
// NOTE: need a better check whether set positionAutomatic, WindowTypes?
m_positionAutomatic = false;
moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());
}
auto updateX11shouldSkipDock = [this]() {
// TODO: support missing type in waylib
// https://github.com/linuxdeepin/dde-shell/blob/b94a3cec4e01cba64f56e040e74419248985d03d/panels/dock/taskmanager/x11window.cpp#L81-L107
auto xwaylandSurface = qobject_cast<WXWaylandSurface *>(this->shellSurface());
if (!xwaylandSurface)
return;
auto atoms = xwaylandSurface->windowTypes();
bool skipDock = false;
skipDock |= xwaylandSurface->isBypassManager();
// skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::_NET_WM_WINDOW_TYPE_DIALOG)
// && !isActionMinimizeAllowed();
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_UTILITY);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_COMBO);
// skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_DESKTOP);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_DND);
// skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_DOCK);
skipDock |=
atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_DROPDOWN_MENU);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_MENU);
skipDock |=
atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_NOTIFICATION);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_POPUP_MENU);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_SPLASH);
// skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_TOOLBAR);
skipDock |= atoms.testFlag(WXWaylandSurface::WindowType::NET_WM_WINDOW_TYPE_TOOLTIP);
setSkipDockPreView(skipDock);
};
connect(xwaylandSurface,
&WXWaylandSurface::bypassManagerChanged,
this,
[this, updateX11shouldSkipDock]() {
updateX11shouldSkipDock();
updateSizeCapabilities();
updateActivateCapability();
updateFocusCapability();
});
connect(xwaylandSurface,
&WXWaylandSurface::windowTypesChanged,
this,
[this, updateX11shouldSkipDock]() {
updateX11shouldSkipDock();
updateSizeCapabilities();
});
updateX11shouldSkipDock();
}
// Connect DConfig windowRadius change so QML bindings re-evaluate radius()
if (m_type == Type::XdgToplevel || m_type == Type::XWayland) {
if (auto *helper = Helper::instance()) {
if (auto *config = helper->config()) {
connect(config,
&TreelandUserConfig::windowRadiusChanged,
this,
&SurfaceWrapper::radiusChanged);
}
}
}
}
void SurfaceWrapper::convertToNormalSurface(WToplevelSurface *shellSurface, Type type)
{
// Conversion only allowed from prelaunch (SplashScreen) state
if (m_type != Type::SplashScreen || m_shellSurface != nullptr) {
qCCritical(lcTlSurface)
<< "convertToNormalSurface can only be called on prelaunch surfaces";
return;
}
// Assign new shell surface (QPointer auto-detects destruction)
m_shellSurface = shellSurface;
m_type = type;
Q_EMIT typeChanged();
// Call setup() to initialize surfaceItem related features
setup();
m_surfaceItem->setVisible(false);
// Check if surface is still valid before accessing
WSurface *surf = surface();
if (surf && surf->mapped()) {
updateFocusControlState(FocusControlState::Mapped, true);
// ActiveControlState::MappedOrSplash is already true
syncPrelaunchMappedState();
startPrelaunchSplashHideSequence();
}
}
void SurfaceWrapper::setParent(QQuickItem *item)
{
QObject::setParent(item);
setParentItem(item);
}
void SurfaceWrapper::setActivate(bool activate)
{
if (m_wrapperAboutToRemove)
return;
if (m_isActivated == activate)
return;
Q_ASSERT(!activate || hasActiveCapability());
m_isActivated = activate;
if (m_attention && m_isActivated)
setAttention(false);
// No shellSurface in prelaunch mode -> early return
if (m_shellSurface)
updateActiveState();
Q_EMIT isActivatedChanged();
}
void SurfaceWrapper::updateActiveState()
{
if (!m_shellSurface) {
qCCritical(lcTlSurface) << "updateActiveState called without a valid shellSurface";
return;
}
if (!m_shellSurface->isInitialized()) {
qCWarning(lcTlSurface)
<< "updateActiveState called with shellSurface not yet initialized";
return;
}
m_shellSurface->setActivate(m_isActivated);
}
void SurfaceWrapper::setFocus(bool focus, Qt::FocusReason reason)
{
// No surfaceItem in prelaunch mode -> early return
if (!m_surfaceItem) {
qCDebug(lcTlSurface) << "setFocus called but m_surfaceItem is null, appId:" << m_appId;
return;
}
if (focus)
m_surfaceItem->forceActiveFocus(reason);
else
m_surfaceItem->setFocus(false, reason);
}
void SurfaceWrapper::syncPrelaunchMappedState()
{
if (!m_prelaunchOutputs.isEmpty()) {
setOutputs(m_prelaunchOutputs);
m_prelaunchOutputs.clear();
}
updateActiveState();
}
void SurfaceWrapper::startPrelaunchSplashHideSequence()
{
Q_ASSERT(m_surfaceItem != nullptr);
if (m_windowAnimation) {
qCDebug(lcTlSurface) << "prelaunch splash transition is starting while window "
"animation is still running,"
"this may cause visual glitches, will delay the transition "
"until window animation finishes";
return;
}
if (m_geometryAnimation) {
qCDebug(lcTlSurface) << "prelaunch splash transition already prepared or running, skip";
return;
}
// Wait until surfaceItem has computed a valid scene-space implicit size.
// For XWayland, this happens in updateSurfaceState() after the first surface commit;
// for other types it may be deferred until componentComplete + first polish.
if (!m_surfaceItem->isReady()) {
connect(m_surfaceItem,
&WSurfaceItem::readyChanged,
this,
&SurfaceWrapper::startPrelaunchSplashHideSequence,
Qt::SingleShotConnection);
return;
}
// Use surfaceItem's scene-space implicit size: for XWayland, surf->size() is
// buffer-space and differs from scene-space after DPR scaling via surfaceSizeRatio.
const QSizeF targetImplicitSize(m_surfaceItem->implicitWidth(),
m_surfaceItem->implicitHeight());
const bool hasValidTargetImplicitSize =
targetImplicitSize.width() > 0 && targetImplicitSize.height() > 0;
if (!hasValidTargetImplicitSize) {
qCCritical(lcTlSurface) << "Invalid target implicit size, skip transition animation"
<< "targetImplicit=" << targetImplicitSize;
}
const bool needImplicitSizeTransition = hasValidTargetImplicitSize && (container() != nullptr)
&& (!qFuzzyCompare(implicitWidth() + 1.0, targetImplicitSize.width() + 1.0)
|| !qFuzzyCompare(implicitHeight() + 1.0, targetImplicitSize.height() + 1.0));
if (needImplicitSizeTransition) {
const QRectF fromGeometry(position(), size());
// XWayland clients manage their own position; respect it and don't shift.
// For all other types, keep the center fixed so the window expands from center.
const QPointF toTopLeft = (m_type == Type::XWayland) ? fromGeometry.topLeft()
: fromGeometry.center()
- QPointF(targetImplicitSize.width() / 2.0, targetImplicitSize.height() / 2.0);
const QRectF toGeometry(toTopLeft, targetImplicitSize);
m_geometryAnimation =
m_engine->createGeometryAnimation(this, fromGeometry, toGeometry, container());
bool ok = connect(m_geometryAnimation,
SIGNAL(ready()),
this,
SLOT(onPrelaunchGeometryAnimationReady()));
Q_ASSERT(ok);
ok = connect(m_geometryAnimation,
SIGNAL(finished()),
this,
SLOT(onPrelaunchGeometryAnimationFinished()));
Q_ASSERT(ok);
ok = QMetaObject::invokeMethod(m_geometryAnimation, "start");
Q_ASSERT(ok);
} else {
completeSplashTransition(targetImplicitSize);
}
}
void SurfaceWrapper::onPrelaunchGeometryAnimationReady()
{
Q_ASSERT(m_geometryAnimation);
const QRectF toGeo = m_geometryAnimation->property("toGeometry").toRectF();
// Move the wrapper to the animation's final position before revealing the real surface,
// so the window appears exactly where the animation ended (no position jump).
setPosition(toGeo.topLeft());
// Keep normalGeometry in sync so subsequent state transitions use the correct position.
setNormalGeometry(toGeo);
completeSplashTransition(toGeo.size(), true);
}
void SurfaceWrapper::onPrelaunchGeometryAnimationFinished()
{
Q_ASSERT(m_geometryAnimation);
m_geometryAnimation->disconnect(this);
m_geometryAnimation->deleteLater();
m_geometryAnimation = nullptr;
if (m_decoration)
m_decoration->setVisible(true);
}
void SurfaceWrapper::completeSplashTransition(const QSizeF &targetImplicitSize, bool hideDecoration)
{
setImplicitSize(targetImplicitSize.width(), targetImplicitSize.height());
connect(m_surfaceItem, &WSurfaceItem::implicitWidthChanged, this, [this] {
setImplicitWidth(m_surfaceItem->implicitWidth());
});
connect(m_surfaceItem, &WSurfaceItem::implicitHeightChanged, this, [this] {
setImplicitHeight(m_surfaceItem->implicitHeight());
});
connect(m_surfaceItem,
&WSurfaceItem::boundingRectChanged,
this,
&SurfaceWrapper::updateBoundingRect);
// setNoDecoration not called updateTitleBar when type is SplashScreen
updateTitleBar();
if (m_decoration) {
if (hideDecoration)
m_decoration->setVisible(false);
m_decoration->stackBefore(m_surfaceItem);
}
m_surfaceItem->setVisible(true);
Q_ASSERT(m_prelaunchSplash);
m_prelaunchSplash->setVisible(false);
m_prelaunchSplash->deleteLater();
m_prelaunchSplash = nullptr;
Q_EMIT prelaunchSplashChanged();
// Now that the splash is hidden and deleted, the surface can be considered active if it's
// mapped
updateHasActiveCapability(ActiveControlState::MappedOrSplash, surface() && surface()->mapped());
}
WSurface *SurfaceWrapper::surface() const
{
if (!m_shellSurface)
return nullptr;
auto *surf = m_shellSurface->surface();
return surf;
}
WToplevelSurface *SurfaceWrapper::shellSurface() const
{
return m_shellSurface;
}
WSurfaceItem *SurfaceWrapper::surfaceItem() const
{
return m_surfaceItem;
}
QQuickItem *SurfaceWrapper::prelaunchSplash() const
{
return m_prelaunchSplash;
}
QString SurfaceWrapper::appId() const
{
// TODO: Need to consider `engineName` to ensure the uniqueness of appid.
if (!m_appId.isEmpty())
return m_appId;
// TODO: consider to use "xdg-shell/" + m_shellSurface->appId(), need dde-shell adaptation
if (m_shellSurface)
return m_shellSurface->appId();
return QString();
}
bool SurfaceWrapper::resize(const QSizeF &size, bool tryExec)
{
// No surfaceItem in prelaunch mode -> return false
if (!m_surfaceItem)
return false;
return m_surfaceItem->resizeSurface(size, tryExec);
}
void SurfaceWrapper::close()
{
if (m_type == Type::SplashScreen) {
// For splash screens, emit a signal to request closure
Q_EMIT splashCloseRequested();
} else if (m_shellSurface) {
// For normal surfaces, call the shell surface's close method
m_shellSurface->close();
}
}
QRectF SurfaceWrapper::titlebarGeometry() const
{
return m_titleBar ? QRectF({ 0, 0 }, m_titleBar->size()) : QRectF();
}
QRectF SurfaceWrapper::boundingRect() const
{
return m_boundedRect;
}
QRectF SurfaceWrapper::normalGeometry() const
{
return m_normalGeometry;
}
void SurfaceWrapper::moveNormalGeometryInOutput(const QPointF &position)
{
QPointF alignedPosition = alignToPixelGrid(position);
setNormalGeometry(QRectF(alignedPosition, m_normalGeometry.size()));
if (isNormal()) {
setPosition(alignedPosition);
} else if (m_pendingState == State::Normal && m_geometryAnimation) {
m_geometryAnimation->setProperty("toGeometry", m_normalGeometry);
}
}
void SurfaceWrapper::setNormalGeometry(const QRectF &newNormalGeometry)
{
if (m_normalGeometry == newNormalGeometry)
return;
m_normalGeometry = newNormalGeometry;
Q_EMIT normalGeometryChanged();
}
QRectF SurfaceWrapper::maximizedGeometry() const
{
return m_maximizedGeometry;
}
void SurfaceWrapper::setMaximizedGeometry(const QRectF &newMaximizedGeometry)
{
if (m_wrapperAboutToRemove)
return;
if (m_maximizedGeometry == newMaximizedGeometry)
return;
m_maximizedGeometry = newMaximizedGeometry;
// This geometry change might be caused by a change in the output size due to screen scaling.
// Ensure that the surfaceSizeRatio is updated before modifying the window size
// to avoid incorrect sizing of Xwayland windows.
updateSurfaceSizeRatio();
if (m_surfaceState == State::Maximized) {
setPosition(newMaximizedGeometry.topLeft());
resize(newMaximizedGeometry.size());
} else if (m_pendingState == State::Maximized && m_geometryAnimation) {
m_geometryAnimation->setProperty("targetGeometry", newMaximizedGeometry);
}
Q_EMIT maximizedGeometryChanged();
}
QRectF SurfaceWrapper::fullscreenGeometry() const
{
return m_fullscreenGeometry;
}
void SurfaceWrapper::setFullscreenGeometry(const QRectF &newFullscreenGeometry)
{
if (m_wrapperAboutToRemove)
return;
if (m_fullscreenGeometry == newFullscreenGeometry)
return;
m_fullscreenGeometry = newFullscreenGeometry;
// This geometry change might be caused by a change in the output size due to screen scaling.
// Ensure that the surfaceSizeRatio is updated before modifying the window size
// to avoid incorrect sizing of Xwayland windows.
updateSurfaceSizeRatio();
if (m_surfaceState == State::Fullscreen) {
setPosition(newFullscreenGeometry.topLeft());
resize(newFullscreenGeometry.size());
} else if (m_pendingState == State::Fullscreen && m_geometryAnimation) {
m_geometryAnimation->setProperty("targetGeometry", newFullscreenGeometry);
}
Q_EMIT fullscreenGeometryChanged();
updateClipRect();
}
QRectF SurfaceWrapper::tilingGeometry() const
{
return m_tilingGeometry;
}
void SurfaceWrapper::setTilingGeometry(const QRectF &newTilingGeometry)
{
if (m_wrapperAboutToRemove)
return;
if (m_tilingGeometry == newTilingGeometry)
return;
m_tilingGeometry = newTilingGeometry;
// This geometry change might be caused by a change in the output size due to screen scaling.
// Ensure that the surfaceSizeRatio is updated before modifying the window size
// to avoid incorrect sizing of Xwayland windows.
updateSurfaceSizeRatio();
if (m_surfaceState == State::Tiling) {
setPosition(newTilingGeometry.topLeft());
resize(newTilingGeometry.size());
}
Q_EMIT tilingGeometryChanged();
}
bool SurfaceWrapper::positionAutomatic() const
{
return m_positionAutomatic;
}
void SurfaceWrapper::setPositionAutomatic(bool newPositionAutomatic)
{
if (m_positionAutomatic == newPositionAutomatic)
return;
m_positionAutomatic = newPositionAutomatic;
Q_EMIT positionAutomaticChanged();
}
void SurfaceWrapper::resetWidth()
{
if (m_surfaceItem)
m_surfaceItem->resetWidth();
QQuickItem::resetWidth();
}
void SurfaceWrapper::resetHeight()
{
if (m_surfaceItem)
m_surfaceItem->resetHeight();
QQuickItem::resetHeight();
}
SurfaceWrapper::Type SurfaceWrapper::type() const
{
return m_type;
}
SurfaceWrapper *SurfaceWrapper::parentSurface() const
{
return m_parentSurface;
}
Output *SurfaceWrapper::ownsOutput() const
{
return m_ownsOutput;
}
void SurfaceWrapper::setOwnsOutput(Output *newOwnsOutput)
{
if (m_wrapperAboutToRemove)
return;
if (m_ownsOutput == newOwnsOutput)
return;
if (m_ownsOutput) {
m_ownsOutput->removeSurface(this);
}
m_ownsOutput = newOwnsOutput;
if (m_ownsOutput) {
m_ownsOutput->addSurface(this);
}
Q_EMIT ownsOutputChanged();
}
void SurfaceWrapper::setOutputs(const QList<WOutput *> &outputs)
{
if (m_wrapperAboutToRemove)
return;
if (m_type == Type::SplashScreen) {
m_prelaunchOutputs = outputs;
return;
}
if (!surface()) {
qCDebug(lcTlSurface) << "SurfaceWrapper::setOutputs called but surface() is null!";
return;
}
const auto oldOutputs = surface()->outputs();
for (auto output : std::as_const(oldOutputs)) {
if (outputs.contains(output)) {
continue;
}
surface()->leaveOutput(output);
}
for (auto output : outputs) {
if (oldOutputs.contains(output))
continue;
surface()->enterOutput(output);
}
}
const QList<WOutput *> &SurfaceWrapper::outputs() const
{
if (m_type == Type::SplashScreen) {
return m_prelaunchOutputs;
}
if (!surface()) {
static const QList<WOutput *> empty;
return empty;
}
return surface()->outputs();
}
QRectF SurfaceWrapper::geometry() const
{
return QRectF(position(), size());
}
SurfaceWrapper::State SurfaceWrapper::previousSurfaceState() const
{
return m_previousSurfaceState;
}
SurfaceWrapper::State SurfaceWrapper::surfaceState() const
{
return m_surfaceState;
}