-
Notifications
You must be signed in to change notification settings - Fork 6
/
abstract_client.cpp
3866 lines (3429 loc) · 130 KB
/
abstract_client.cpp
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
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "abstract_client.h"
#include "appmenu.h"
#include "decorations/decoratedclient.h"
#include "decorations/decorationpalette.h"
#include "decorations/decorationbridge.h"
#include "effects.h"
#include "focuschain.h"
#include "outline.h"
#include "screens.h"
#ifdef KWIN_BUILD_TABBOX
#include "tabbox.h"
#endif
#include "screenedge.h"
#include "useractions.h"
#include "workspace.h"
#include "wayland_server.h"
#include <KWaylandServer/plasmawindowmanagement_interface.h>
#include <KDecoration2/DecoratedClient>
#include <KDecoration2/Decoration>
#include <KDesktopFile>
#include <KWaylandServer/surface_interface.h>
#include <KWaylandServer/clientconnection.h>
#include <QDir>
#include <QMouseEvent>
#include <QStyleHints>
namespace KWin
{
static inline int sign(int v)
{
return (v > 0) - (v < 0);
}
QHash<QString, std::weak_ptr<Decoration::DecorationPalette>> AbstractClient::s_palettes;
std::shared_ptr<Decoration::DecorationPalette> AbstractClient::s_defaultPalette;
AbstractClient::AbstractClient()
: Toplevel()
#ifdef KWIN_BUILD_TABBOX
, m_tabBoxClient(QSharedPointer<TabBox::TabBoxClientImpl>(new TabBox::TabBoxClientImpl(this)))
#endif
, m_colorScheme(QStringLiteral("kdeglobals"))
{
connect(this, &AbstractClient::clientStartUserMovedResized, this, &AbstractClient::moveResizedChanged);
connect(this, &AbstractClient::clientFinishUserMovedResized, this, &AbstractClient::moveResizedChanged);
connect(this, &AbstractClient::clientStartUserMovedResized, this, &AbstractClient::removeCheckScreenConnection);
connect(this, &AbstractClient::clientFinishUserMovedResized, this, &AbstractClient::setupCheckScreenConnection);
connect(this, &AbstractClient::paletteChanged, this, &AbstractClient::triggerDecorationRepaint);
connect(Decoration::DecorationBridge::self(), &QObject::destroyed, this, &AbstractClient::destroyDecoration);
// If the user manually moved the window, don't restore it after the keyboard closes
connect(this, &AbstractClient::clientFinishUserMovedResized, this, [this] () {
m_keyboardGeometryRestore = QRect();
});
connect(this, qOverload<AbstractClient *, bool, bool>(&AbstractClient::clientMaximizedStateChanged), this, [this] () {
m_keyboardGeometryRestore = QRect();
});
connect(this, &AbstractClient::fullScreenChanged, this, [this] () {
m_keyboardGeometryRestore = QRect();
});
// replace on-screen-display on size changes
connect(this, &AbstractClient::frameGeometryChanged, this,
[this] (Toplevel *c, const QRect &old) {
Q_UNUSED(c)
if (isOnScreenDisplay() && !frameGeometry().isEmpty() && old.size() != frameGeometry().size() && isPlaceable()) {
GeometryUpdatesBlocker blocker(this);
// jing_kwin for jingos app under panel
const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->current(), desktop());
Placement::self()->place(this, area);
setGeometryRestore(frameGeometry());
}
}
);
connect(this, &AbstractClient::paddingChanged, this, [this]() {
m_visibleRectBeforeGeometryUpdate = visibleRect();
});
connect(ApplicationMenu::self(), &ApplicationMenu::applicationMenuEnabledChanged, this, [this] {
emit hasApplicationMenuChanged(hasApplicationMenu());
});
connect(this, &AbstractClient::surfaceChanged, this, &AbstractClient::updateIsSystemUI);
connect(this, &AbstractClient::windowClassChanged, this, &AbstractClient::updateIsSystemUI);
}
void AbstractClient::updateJingLayer()
{
if (m_jingWindowType == JingWindowType::TYPE_KEYGUARD && !isLockScreen()) {
m_jingLayer = JingLayer::LAYER_APPLICATION;
} else if (isFullScreen() && m_active && isApplication()) {
m_jingLayer = JingLayer::LAYER_FULL_SCREEN;
} else {
switch(m_jingWindowType) {
case JingWindowType::TYPE_WALLPAPER :
m_jingLayer = JingLayer::LAYER_WALLPAPER;
break;
case JingWindowType::TYPE_DESKTOP :
m_jingLayer = JingLayer::LAYER_DESKTOP;
break;
case JingWindowType::TYPE_DIALOG :
m_jingLayer = JingLayer::LAYER_DIALOG;
break;
case JingWindowType::TYPE_SYS_SPLASH :
m_jingLayer = JingLayer::LAYER_SYS_SPLASH;
break;
case JingWindowType::TYPE_SEARCH_BAR :
m_jingLayer = JingLayer::LAYER_SEARCH_BAR;
break;
case JingWindowType::TYPE_NOTIFICATION :
m_jingLayer = JingLayer::LAYER_NOTIFICATION;
break;
case JingWindowType::TYPE_CRITICAL_NOTIFICATION :
m_jingLayer = JingLayer::LAYER_CRITICAL_NOTIFICATION;
break;
case JingWindowType::TYPE_INPUT_METHOD :
m_jingLayer = JingLayer::LAYER_INPUT_METHOD;
break;
case JingWindowType::TYPE_INPUT_METHOD_DIALOG :
m_jingLayer = JingLayer::LAYER_INPUT_METHOD_DIALOG;
break;
case JingWindowType::TYPE_DND :
m_jingLayer = JingLayer::LAYER_DND;
break;
case JingWindowType::TYPE_DOCK :
m_jingLayer = JingLayer::LAYER_DOCK;
break;
case JingWindowType:: TYPE_APPLICATION_OVERLAY :
m_jingLayer = JingLayer::LAYER_APPLICATION_OVERLAY;
break;
case JingWindowType::TYPE_STATUS_BAR :
m_jingLayer = JingLayer::LAYER_STATUS_BAR;
break;
case JingWindowType::TYPE_STATUS_BAR_PANEL :
m_jingLayer = JingLayer::LAYER_STATUS_BAR_PANEL;
break;
case JingWindowType::TYPE_TOAST :
m_jingLayer = JingLayer::LAYER_TOAST;
break;
case JingWindowType::TYPE_KEYGUARD :
m_jingLayer = JingLayer::LAYER_KEYGUARD;
break;
case JingWindowType::TYPE_PHONE :
m_jingLayer = JingLayer::LAYER_PHONE;
break;
case JingWindowType::TYPE_SYSTEM_DIALOG :
m_jingLayer = JingLayer::LAYER_SYSTEM_DIALOG;
break;
case JingWindowType::TYPE_SYSTEM_OVERLAY:
m_jingLayer = JingLayer::LAYER_SYSTEM_OVERLAY;
break;
case JingWindowType::TYPE_SYSTEM_ERROR :
m_jingLayer = JingLayer::LAYER_SYSTEM_ERROR;
break;
case JingWindowType::TYPE_VOICE_INTERACTION :
m_jingLayer = JingLayer::LAYER_SYSTEM_INTERACTION;
break;
case JingWindowType:: TYPE_SCREENSHOT :
m_jingLayer = JingLayer::LAYER_SCREENSHOT;
break;
case JingWindowType::TYPE_BOOT_PROGRESS :
m_jingLayer = JingLayer::LAYER_BOOT_PROGRESS;
break;
case JingWindowType::TYPE_POINTER :
m_jingLayer = JingLayer::LAYER_POINTER;
break;
case JingWindowType::TYPE_LAST_SYS_LAYER :
m_jingLayer = JingLayer::LAYER_LAST_LAYER;
break;
case JingWindowType::TYPE_BASE_APPLICATION :
m_jingLayer = JingLayer::LAYER_APPLICATION;
break;
case JingWindowType::TYPE_APPLICATION :
m_jingLayer = JingLayer::LAYER_APPLICATION;
break;
case JingWindowType::TYPE_APPLICATION_STARTING:
m_jingLayer = JingLayer::LAYER_APPLICATION;
break;
case JingWindowType::TYPE_LAST_APPLICATION_WINDOW:
m_jingLayer = JingLayer::LAYER_APPLICATION;
break;
case JingWindowType::TYPE_UNKNOW:
m_jingLayer = JingLayer::LAYER_APPLICATION;
break;
default:
m_jingLayer = JingLayer::LAYER_APPLICATION;
}
}
postUpdateWidnwoType();
}
AbstractClient::~AbstractClient()
{
Q_ASSERT(m_blockGeometryUpdates == 0);
Q_ASSERT(m_decoration.decoration == nullptr);
}
void AbstractClient::updateMouseGrab()
{
}
bool AbstractClient::belongToSameApplication(const AbstractClient *c1, const AbstractClient *c2, SameApplicationChecks checks)
{
return c1->belongsToSameApplication(c2, checks);
}
bool AbstractClient::isTransient() const
{
return false;
}
bool AbstractClient::hasParent() const
{
return isTransient();
}
void AbstractClient::setClientShown(bool shown)
{
Q_UNUSED(shown)
}
xcb_timestamp_t AbstractClient::userTime() const
{
return XCB_TIME_CURRENT_TIME;
}
void AbstractClient::setSkipSwitcher(bool set)
{
set = rules()->checkSkipSwitcher(set);
if (set == skipSwitcher())
return;
m_skipSwitcher = set;
doSetSkipSwitcher();
updateWindowRules(Rules::SkipSwitcher);
emit skipSwitcherChanged();
}
void AbstractClient::setRequestVisible(bool visible)
{
if (m_requestVisible != visible) {
m_requestVisible = visible;
effects->addRepaint(visibleRect());
emit requestVisibileChanged();
}
}
void AbstractClient::setJingWindowType(JingWindowType windowType)
{
if (m_jingWindowType != windowType) {
m_jingWindowType = windowType;
emit jingWindowTypeChanged();
updateJingLayer();
if (m_jingWindowType == JingWindowType::TYPE_DESKTOP) {
workspace()->setDesktop(this);
}
}
}
JingWindowType AbstractClient::jingWindowType() const
{
if (isLockScreen()) {
return JingWindowType::TYPE_KEYGUARD;
}
return m_jingWindowType;
}
void AbstractClient::setSkipPager(bool b)
{
b = rules()->checkSkipPager(b);
if (b == skipPager())
return;
m_skipPager = b;
doSetSkipPager();
updateWindowRules(Rules::SkipPager);
emit skipPagerChanged();
}
void AbstractClient::doSetSkipPager()
{
}
void AbstractClient::setSkipTaskbar(bool b)
{
int was_wants_tab_focus = wantsTabFocus();
if (b == skipTaskbar())
return;
m_skipTaskbar = b;
doSetSkipTaskbar();
updateWindowRules(Rules::SkipTaskbar);
if (was_wants_tab_focus != wantsTabFocus()) {
FocusChain::self()->update(this, isActive() ? FocusChain::MakeFirst : FocusChain::Update);
}
emit skipTaskbarChanged();
}
void AbstractClient::setOriginalSkipTaskbar(bool b)
{
m_originalSkipTaskbar = rules()->checkSkipTaskbar(b);
setSkipTaskbar(m_originalSkipTaskbar);
}
void AbstractClient::doSetSkipTaskbar()
{
}
void AbstractClient::doSetSkipSwitcher()
{
}
void AbstractClient::setIcon(const QIcon &icon)
{
if (!icon.isNull()) {
m_icon = icon;
emit iconChanged();
}
}
void AbstractClient::setTitle(const QString &title)
{
m_title = title;
}
void AbstractClient::setActive(bool act)
{
if (act) {
setIsBackApp(false);
}
if (isZombie()) {
return;
}
if (m_active == act) {
return;
}
m_active = act;
const int ruledOpacity = m_active
? rules()->checkOpacityActive(qRound(opacity() * 100.0))
: rules()->checkOpacityInactive(qRound(opacity() * 100.0));
setOpacity(ruledOpacity / 100.0);
updateJingLayer();
if (!m_active) {
cancelAutoRaise();
setVirtualKeyboardGeometry({});
}
workspace()->setActiveClient(act ? this : nullptr);
if (!m_active && shadeMode() == ShadeActivated)
setShade(ShadeNormal);
StackingUpdatesBlocker blocker(workspace());
workspace()->updateClientLayer(this); // active windows may get different layer
auto mainclients = mainClients();
for (auto it = mainclients.constBegin();
it != mainclients.constEnd();
++it)
if ((*it)->isFullScreen()) // fullscreens go high even if their transient is active
workspace()->updateClientLayer(*it);
doSetActive();
emit activeChanged();
updateMouseGrab();
}
void AbstractClient::doSetActive()
{
}
bool AbstractClient::isZombie() const
{
return m_zombie;
}
void AbstractClient::markAsZombie()
{
Q_ASSERT(!m_zombie);
m_zombie = true;
addWorkspaceRepaint(visibleRect());
}
JingLayer AbstractClient::jingLayer() const
{
if (isLockScreen()) {
return JingLayer::LAYER_KEYGUARD;
}
return m_jingLayer;
}
void AbstractClient::placeIn(const QRect &area)
{
// TODO: Get rid of this method eventually. We need to call setGeometryRestore() because
// checkWorkspacePosition() operates on geometryRestore() and because of quick tiling.
Placement::self()->place(this, area);
setGeometryRestore(frameGeometry());
}
bool AbstractClient::belongsToDesktop() const
{
return false;
}
void AbstractClient::setKeepAbove(bool b)
{
b = rules()->checkKeepAbove(b);
if (b && !rules()->checkKeepBelow(false))
setKeepBelow(false);
if (b == keepAbove()) {
return;
}
m_keepAbove = b;
doSetKeepAbove();
workspace()->updateClientLayer(this);
updateWindowRules(Rules::Above);
emit keepAboveChanged(m_keepAbove);
}
void AbstractClient::doSetKeepAbove()
{
}
void AbstractClient::setKeepBelow(bool b)
{
b = rules()->checkKeepBelow(b);
if (b && !rules()->checkKeepAbove(false))
setKeepAbove(false);
if (b == keepBelow()) {
return;
}
m_keepBelow = b;
doSetKeepBelow();
workspace()->updateClientLayer(this);
updateWindowRules(Rules::Below);
emit keepBelowChanged(m_keepBelow);
}
void AbstractClient::doSetKeepBelow()
{
}
void AbstractClient::startAutoRaise()
{
delete m_autoRaiseTimer;
m_autoRaiseTimer = new QTimer(this);
connect(m_autoRaiseTimer, &QTimer::timeout, this, &AbstractClient::autoRaise);
m_autoRaiseTimer->setSingleShot(true);
m_autoRaiseTimer->start(options->autoRaiseInterval());
}
void AbstractClient::cancelAutoRaise()
{
delete m_autoRaiseTimer;
m_autoRaiseTimer = nullptr;
}
void AbstractClient::autoRaise()
{
workspace()->raiseClient(this);
cancelAutoRaise();
}
bool AbstractClient::isMostRecentlyRaised() const
{
// The last toplevel in the unconstrained stacking order is the most recently raised one.
return workspace()->topClientOnDesktop(VirtualDesktopManager::self()->current(), -1, true, false) == this;
}
bool AbstractClient::wantsTabFocus() const
{
return (isNormalWindow() || isDialog()) && wantsInput();
}
bool AbstractClient::isSpecialWindow() const
{
// TODO
return isDesktop() || isStatusBar() || isSplash() || isToolbar() || isNotification() || isOnScreenDisplay() || isCriticalNotification() || (!isApplication() && !isLockScreen());
}
void AbstractClient::demandAttention(bool set)
{
if (isActive())
set = false;
if (m_demandsAttention == set)
return;
m_demandsAttention = set;
doSetDemandsAttention();
workspace()->clientAttentionChanged(this, set);
emit demandsAttentionChanged();
}
void AbstractClient::doSetDemandsAttention()
{
}
void AbstractClient::setDesktop(int desktop)
{
const int numberOfDesktops = VirtualDesktopManager::self()->count();
if (desktop != NET::OnAllDesktops) // Do range check
desktop = qMax(1, qMin(numberOfDesktops, desktop));
desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop));
QVector<VirtualDesktop *> desktops;
if (desktop != NET::OnAllDesktops) {
desktops << VirtualDesktopManager::self()->desktopForX11Id(desktop);
}
setDesktops(desktops);
}
void AbstractClient::setDesktops(QVector<VirtualDesktop*> desktops)
{
//on x11 we can have only one desktop at a time
if (kwinApp()->operationMode() == Application::OperationModeX11 && desktops.size() > 1) {
desktops = QVector<VirtualDesktop*>({desktops.last()});
}
if (desktops == m_desktops) {
return;
}
int was_desk = AbstractClient::desktop();
const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0;
m_desktops = desktops;
if (windowManagementInterface()) {
if (m_desktops.isEmpty()) {
windowManagementInterface()->setOnAllDesktops(true);
} else {
windowManagementInterface()->setOnAllDesktops(false);
auto currentDesktops = windowManagementInterface()->plasmaVirtualDesktops();
for (auto desktop: m_desktops) {
if (!currentDesktops.contains(desktop->id())) {
windowManagementInterface()->addPlasmaVirtualDesktop(desktop->id());
} else {
currentDesktops.removeOne(desktop->id());
}
}
for (auto desktopId: currentDesktops) {
windowManagementInterface()->removePlasmaVirtualDesktop(desktopId);
}
}
}
if (info) {
info->setDesktop(desktop());
}
if ((was_desk == NET::OnAllDesktops) != (desktop() == NET::OnAllDesktops)) {
// onAllDesktops changed
workspace()->updateOnAllDesktopsOfTransients(this);
}
auto transients_stacking_order = workspace()->ensureStackingOrder(transients());
for (auto it = transients_stacking_order.constBegin();
it != transients_stacking_order.constEnd();
++it)
(*it)->setDesktops(desktops);
if (isModal()) // if a modal dialog is moved, move the mainwindow with it as otherwise
// the (just moved) modal dialog will confusingly return to the mainwindow with
// the next desktop change
{
foreach (AbstractClient * c2, mainClients())
c2->setDesktops(desktops);
}
doSetDesktop();
FocusChain::self()->update(this, FocusChain::MakeFirst);
updateWindowRules(Rules::Desktop);
emit desktopChanged();
if (wasOnCurrentDesktop != isOnCurrentDesktop())
emit desktopPresenceChanged(this, was_desk);
emit x11DesktopIdsChanged();
}
void AbstractClient::doSetDesktop()
{
}
void AbstractClient::enterDesktop(VirtualDesktop *virtualDesktop)
{
if (m_desktops.contains(virtualDesktop)) {
return;
}
auto desktops = m_desktops;
desktops.append(virtualDesktop);
setDesktops(desktops);
}
void AbstractClient::leaveDesktop(VirtualDesktop *virtualDesktop)
{
QVector<VirtualDesktop*> currentDesktops;
if (m_desktops.isEmpty()) {
currentDesktops = VirtualDesktopManager::self()->desktops();
} else {
currentDesktops = m_desktops;
}
if (!currentDesktops.contains(virtualDesktop)) {
return;
}
auto desktops = currentDesktops;
desktops.removeOne(virtualDesktop);
setDesktops(desktops);
}
void AbstractClient::setOnAllDesktops(bool b)
{
if ((b && isOnAllDesktops()) ||
(!b && !isOnAllDesktops()))
return;
if (b)
setDesktop(NET::OnAllDesktops);
else
setDesktop(VirtualDesktopManager::self()->current());
}
QVector<uint> AbstractClient::x11DesktopIds() const
{
const auto desks = desktops();
QVector<uint> x11Ids;
x11Ids.reserve(desks.count());
std::transform(desks.constBegin(), desks.constEnd(),
std::back_inserter(x11Ids),
[] (const VirtualDesktop *vd) {
return vd->x11DesktopNumber();
}
);
return x11Ids;
}
ShadeMode AbstractClient::shadeMode() const
{
return m_shadeMode;
}
bool AbstractClient::isShadeable() const
{
return false;
}
void AbstractClient::setShade(bool set)
{
set ? setShade(ShadeNormal) : setShade(ShadeNone);
}
void AbstractClient::setShade(ShadeMode mode)
{
if (!isShadeable())
return;
if (mode == ShadeHover && isMove())
return; // causes geometry breaks and is probably nasty
if (isSpecialWindow() || noBorder())
mode = ShadeNone;
mode = rules()->checkShade(mode);
if (m_shadeMode == mode)
return;
const bool wasShade = isShade();
const ShadeMode previousShadeMode = shadeMode();
m_shadeMode = mode;
if (wasShade == isShade()) {
// Decoration may want to update after e.g. hover-shade changes
emit shadeChanged();
return; // No real change in shaded state
}
Q_ASSERT(isDecorated());
GeometryUpdatesBlocker blocker(this);
doSetShade(previousShadeMode);
discardWindowPixmap();
updateWindowRules(Rules::Shade);
emit shadeChanged();
}
void AbstractClient::doSetShade(ShadeMode previousShadeMode)
{
Q_UNUSED(previousShadeMode)
}
void AbstractClient::shadeHover()
{
setShade(ShadeHover);
cancelShadeHoverTimer();
}
void AbstractClient::shadeUnhover()
{
setShade(ShadeNormal);
cancelShadeHoverTimer();
}
void AbstractClient::updateIsSystemUI()
{
m_isSystemUI = workspace()->isSystemUI(this);
}
void AbstractClient::startShadeHoverTimer()
{
if (!isShade())
return;
m_shadeHoverTimer = new QTimer(this);
connect(m_shadeHoverTimer, &QTimer::timeout, this, &AbstractClient::shadeHover);
m_shadeHoverTimer->setSingleShot(true);
m_shadeHoverTimer->start(options->shadeHoverInterval());
}
void AbstractClient::startShadeUnhoverTimer()
{
if (m_shadeMode == ShadeHover && !isMoveResize() && !isMoveResizePointerButtonDown()) {
m_shadeHoverTimer = new QTimer(this);
connect(m_shadeHoverTimer, &QTimer::timeout, this, &AbstractClient::shadeUnhover);
m_shadeHoverTimer->setSingleShot(true);
m_shadeHoverTimer->start(options->shadeHoverInterval());
}
}
void AbstractClient::cancelShadeHoverTimer()
{
delete m_shadeHoverTimer;
m_shadeHoverTimer = nullptr;
}
void AbstractClient::toggleShade()
{
// If the mode is ShadeHover or ShadeActive, cancel shade too.
setShade(shadeMode() == ShadeNone ? ShadeNormal : ShadeNone);
}
AbstractClient::Position AbstractClient::titlebarPosition() const
{
// TODO: still needed, remove?
return PositionTop;
}
bool AbstractClient::titlebarPositionUnderMouse() const
{
if (!isDecorated()) {
return false;
}
const auto sectionUnderMouse = decoration()->sectionUnderMouse();
if (sectionUnderMouse == Qt::TitleBarArea) {
return true;
}
// check other sections based on titlebarPosition
switch (titlebarPosition()) {
case AbstractClient::PositionTop:
return (sectionUnderMouse == Qt::TopLeftSection || sectionUnderMouse == Qt::TopSection || sectionUnderMouse == Qt::TopRightSection);
case AbstractClient::PositionLeft:
return (sectionUnderMouse == Qt::TopLeftSection || sectionUnderMouse == Qt::LeftSection || sectionUnderMouse == Qt::BottomLeftSection);
case AbstractClient::PositionRight:
return (sectionUnderMouse == Qt::BottomRightSection || sectionUnderMouse == Qt::RightSection || sectionUnderMouse == Qt::TopRightSection);
case AbstractClient::PositionBottom:
return (sectionUnderMouse == Qt::BottomLeftSection || sectionUnderMouse == Qt::BottomSection || sectionUnderMouse == Qt::BottomRightSection);
default:
// nothing
return false;
}
}
void AbstractClient::setMinimized(bool set)
{
set ? minimize() : unminimize();
}
void AbstractClient::minimize(bool avoid_animation)
{
if (!isMinimizable() || isMinimized() || isLockScreen())
return;
m_minimized = true;
doMinimize();
updateWindowRules(Rules::Minimize);
if (options->moveMinimizedWindowsToEndOfTabBoxFocusChain()) {
FocusChain::self()->update(this, FocusChain::MakeFirstMinimized);
}
// TODO: merge signal with s_minimized
addWorkspaceRepaint(visibleRect());
emit clientMinimized(this, !avoid_animation);
emit minimizedChanged();
}
void AbstractClient::unminimize(bool avoid_animation)
{
if (!isMinimized())
return;
if (rules()->checkMinimize(false)) {
return;
}
m_minimized = false;
doMinimize();
updateWindowRules(Rules::Minimize);
emit clientUnminimized(this, !avoid_animation);
emit minimizedChanged();
}
void AbstractClient::doMinimize()
{
}
QPalette AbstractClient::palette() const
{
if (!m_palette) {
return QPalette();
}
return m_palette->palette();
}
const Decoration::DecorationPalette *AbstractClient::decorationPalette() const
{
return m_palette.get();
}
QString AbstractClient::preferredColorScheme() const
{
return rules()->checkDecoColor(QString());
}
QString AbstractClient::colorScheme() const
{
return m_colorScheme;
}
void AbstractClient::setColorScheme(const QString &colorScheme)
{
QString requestedColorScheme = colorScheme;
if (requestedColorScheme.isEmpty()) {
requestedColorScheme = QStringLiteral("kdeglobals");
}
if (!m_palette || m_colorScheme != requestedColorScheme) {
m_colorScheme = requestedColorScheme;
if (m_palette) {
disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange);
}
auto it = s_palettes.find(m_colorScheme);
if (it == s_palettes.end() || it->expired()) {
m_palette = std::make_shared<Decoration::DecorationPalette>(m_colorScheme);
if (m_palette->isValid()) {
s_palettes[m_colorScheme] = m_palette;
} else {
if (!s_defaultPalette) {
s_defaultPalette = std::make_shared<Decoration::DecorationPalette>(QStringLiteral("kdeglobals"));
s_palettes[QStringLiteral("kdeglobals")] = s_defaultPalette;
}
m_palette = s_defaultPalette;
}
if (m_colorScheme == QStringLiteral("kdeglobals")) {
s_defaultPalette = m_palette;
}
} else {
m_palette = it->lock();
}
connect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange);
emit paletteChanged(palette());
emit colorSchemeChanged();
}
}
void AbstractClient::updateColorScheme()
{
setColorScheme(preferredColorScheme());
}
void AbstractClient::handlePaletteChange()
{
emit paletteChanged(palette());
}
void AbstractClient::keepInArea(QRect area, bool partial)
{
if (partial) {
// increase the area so that can have only 100 pixels in the area
area.setLeft(qMin(area.left() - width() + 100, area.left()));
area.setTop(qMin(area.top() - height() + 100, area.top()));
area.setRight(qMax(area.right() + width() - 100, area.right()));
area.setBottom(qMax(area.bottom() + height() - 100, area.bottom()));
}
if (!partial) {
// resize to fit into area
if (area.width() < width() || area.height() < height())
resizeWithChecks(size().boundedTo(area.size()));
}
int tx = x(), ty = y();
if (frameGeometry().right() > area.right() && width() <= area.width())
tx = area.right() - width() + 1;
if (frameGeometry().bottom() > area.bottom() && height() <= area.height())
ty = area.bottom() - height() + 1;
if (!area.contains(frameGeometry().topLeft())) {
if (tx < area.x())
tx = area.x();
if (ty < area.y())
ty = area.y();
}
if (tx != x() || ty != y())
move(tx, ty);
}
/**
* Returns the maximum client size, not the maximum frame size.
*/
QSize AbstractClient::maxSize() const
{
return rules()->checkMaxSize(QSize(INT_MAX, INT_MAX));
}
/**
* Returns the minimum client size, not the minimum frame size.
*/
QSize AbstractClient::minSize() const
{
return rules()->checkMinSize(QSize(0, 0));
}
void AbstractClient::blockGeometryUpdates(bool block)
{
if (block) {
if (m_blockGeometryUpdates == 0)
m_pendingGeometryUpdate = PendingGeometryNone;
++m_blockGeometryUpdates;
} else {
if (--m_blockGeometryUpdates == 0) {
if (m_pendingGeometryUpdate != PendingGeometryNone) {
if (isShade())
setFrameGeometry(QRect(pos(), adjustedSize()), NormalGeometrySet);
else
setFrameGeometry(frameGeometry(), NormalGeometrySet);
m_pendingGeometryUpdate = PendingGeometryNone;
}
}
}
}
void AbstractClient::maximize(MaximizeMode m)
{
setMaximize(m & MaximizeVertical, m & MaximizeHorizontal);
}
void AbstractClient::setMaximize(bool vertically, bool horizontally)
{
// jing_kwin max window
if ((!vertically || !horizontally) && isDefaultMaxApp()) {
return;
}
// changeMaximize() flips the state, so change from set->flip
const MaximizeMode oldMode = requestedMaximizeMode();
changeMaximize(
oldMode & MaximizeHorizontal ? !horizontally : horizontally,
oldMode & MaximizeVertical ? !vertically : vertically,
false);
const MaximizeMode newMode = maximizeMode();
if (oldMode != newMode) {
emit clientMaximizedStateChanged(this, newMode);