forked from ukui/ukui-kwin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_client.cpp
3146 lines (2805 loc) · 111 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.
Copyright (C) 2015 Martin Gräßlin <[email protected]>
Copyright (C) 2019 Vlad Zahorodnii <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "abstract_client.h"
#include "appmenu.h"
#include "decorations/decoratedclient.h"
#include "decorations/decorationpalette.h"
#include "decorations/decorationbridge.h"
#include "cursor.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 <KWayland/Server/plasmawindowmanagement_interface.h>
#include <KDecoration2/Decoration>
#include <KDesktopFile>
#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::geometryShapeChanged, this, &AbstractClient::geometryChanged);
auto signalMaximizeChanged = static_cast<void (AbstractClient::*)(KWin::AbstractClient*, MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged);
connect(this, signalMaximizeChanged, this, &AbstractClient::geometryChanged);
connect(this, &AbstractClient::clientStepUserMovedResized, this, &AbstractClient::geometryChanged);
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::geometryShapeChanged, this,
[this] (Toplevel *c, const QRect &old) {
Q_UNUSED(c)
if (isOnScreenDisplay() && !frameGeometry().isEmpty() && old.size() != frameGeometry().size() && !isInitialPositionSet()) {
GeometryUpdatesBlocker blocker(this);
const QRect area = workspace()->clientArea(PlacementArea, 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());
});
}
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;
}
void AbstractClient::setClientShown(bool shown)
{
Q_UNUSED(shown)
}
MaximizeMode AbstractClient::requestedMaximizeMode() const
{
return maximizeMode();
}
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::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)
{
m_icon = icon;
emit iconChanged();
}
void AbstractClient::setActive(bool act)
{
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);
workspace()->setActiveClient(act ? this : nullptr);
if (!m_active)
cancelAutoRaise();
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()
{
}
Layer AbstractClient::layer() const
{
if (m_layer == UnknownLayer)
const_cast< AbstractClient* >(this)->m_layer = belongsToLayer();
return m_layer;
}
void AbstractClient::updateLayer()
{
if (layer() == belongsToLayer())
return;
StackingUpdatesBlocker blocker(workspace());
invalidateLayer(); // invalidate, will be updated when doing restacking
for (auto it = transients().constBegin(), end = transients().constEnd(); it != end; ++it)
(*it)->updateLayer();
}
void AbstractClient::invalidateLayer()
{
m_layer = UnknownLayer;
}
Layer AbstractClient::belongsToLayer() const
{
// NOTICE while showingDesktop, desktops move to the AboveLayer
// (interchangeable w/ eg. yakuake etc. which will at first remain visible)
// and the docks move into the NotificationLayer (which is between Above- and
// ActiveLayer, so that active fullscreen windows will still cover everything)
// Since the desktop is also activated, nothing should be in the ActiveLayer, though
if (isInternal())
return UnmanagedLayer;
if (isDesktop())
return workspace()->showingDesktop() ? AboveLayer : DesktopLayer;
if (isSplash()) // no damn annoying splashscreens
return NormalLayer; // getting in the way of everything else
if (isDock()) {
if (workspace()->showingDesktop())
return NotificationLayer;
return layerForDock();
}
if (isOnScreenDisplay())
return OnScreenDisplayLayer;
if (isNotification())
return NotificationLayer;
if (isCriticalNotification())
return CriticalNotificationLayer;
if (workspace()->showingDesktop() && belongsToDesktop()) {
return AboveLayer;
}
if (keepBelow())
return BelowLayer;
if (isActiveFullScreen())
return ActiveLayer;
if (keepAbove())
return AboveLayer;
return NormalLayer;
}
bool AbstractClient::belongsToDesktop() const
{
return false;
}
Layer AbstractClient::layerForDock() const
{
// slight hack for the 'allow window to cover panel' Kicker setting
// don't move keepbelow docks below normal window, but only to the same
// layer, so that both may be raised to cover the other
if (keepBelow())
return NormalLayer;
if (keepAbove()) // slight hack for the autohiding panels
return AboveLayer;
return DockLayer;
}
void AbstractClient::setKeepAbove(bool b)
{
b = rules()->checkKeepAbove(b);
if (b && !rules()->checkKeepBelow(false))
setKeepBelow(false);
if (b == keepAbove()) {
// force hint change if different
if (info && bool(info->state() & NET::KeepAbove) != keepAbove())
info->setState(keepAbove() ? NET::KeepAbove : NET::States(), NET::KeepAbove);
return;
}
m_keepAbove = b;
if (info) {
info->setState(keepAbove() ? NET::KeepAbove : NET::States(), NET::KeepAbove);
}
workspace()->updateClientLayer(this);
updateWindowRules(Rules::Above);
doSetKeepAbove();
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()) {
// force hint change if different
if (info && bool(info->state() & NET::KeepBelow) != keepBelow())
info->setState(keepBelow() ? NET::KeepBelow : NET::States(), NET::KeepBelow);
return;
}
m_keepBelow = b;
if (info) {
info->setState(keepBelow() ? NET::KeepBelow : NET::States(), NET::KeepBelow);
}
workspace()->updateClientLayer(this);
updateWindowRules(Rules::Below);
doSetKeepBelow();
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::wantsTabFocus() const
{
return (isNormalWindow() || isDialog()) && wantsInput();
}
bool AbstractClient::isSpecialWindow() const
{
// TODO
return isDesktop() || isDock() || isSplash() || isToolbar() || isNotification() || isOnScreenDisplay() || isCriticalNotification();
}
void AbstractClient::demandAttention(bool set)
{
if (isActive())
set = false;
if (m_demandsAttention == set)
return;
m_demandsAttention = set;
if (info) {
info->setState(set ? NET::DemandsAttention : NET::States(), NET::DemandsAttention);
}
workspace()->clientAttentionChanged(this, set);
emit demandsAttentionChanged();
}
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(desktop(), was_desk);
FocusChain::self()->update(this, FocusChain::MakeFirst);
updateWindowRules(Rules::Desktop);
emit desktopChanged();
if (wasOnCurrentDesktop != isOnCurrentDesktop())
emit desktopPresenceChanged(this, was_desk);
emit x11DesktopIdsChanged();
}
void AbstractClient::doSetDesktop(int desktop, int was_desk)
{
Q_UNUSED(desktop)
Q_UNUSED(was_desk)
}
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;
}
bool AbstractClient::isShadeable() const
{
return false;
}
void AbstractClient::setShade(bool set)
{
set ? setShade(ShadeNormal) : setShade(ShadeNone);
}
void AbstractClient::setShade(ShadeMode mode)
{
Q_UNUSED(mode)
}
ShadeMode AbstractClient::shadeMode() const
{
return 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())
return;
if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded
info->setState(NET::States(), NET::Shaded);
m_minimized = true;
doMinimize();
updateWindowRules(Rules::Minimize);
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;
}
if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded
info->setState(NET::Shaded, NET::Shaded);
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();
}
void AbstractClient::updateColorScheme(QString path)
{
if (path.isEmpty()) {
path = QStringLiteral("kdeglobals");
}
if (!m_palette || m_colorScheme != path) {
m_colorScheme = path;
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::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(qMin(area.width(), width()), qMin(area.height(), height()));
}
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);
}
QSize AbstractClient::maxSize() const
{
return rules()->checkMaxSize(QSize(INT_MAX, INT_MAX));
}
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)
{
// changeMaximize() flips the state, so change from set->flip
const MaximizeMode oldMode = maximizeMode();
changeMaximize(
oldMode & MaximizeHorizontal ? !horizontally : horizontally,
oldMode & MaximizeVertical ? !vertically : vertically,
false);
const MaximizeMode newMode = maximizeMode();
if (oldMode != newMode) {
emit clientMaximizedStateChanged(this, newMode);
emit clientMaximizedStateChanged(this, vertically, horizontally);
}
}
void AbstractClient::move(int x, int y, ForceGeometry_t force)
{
// resuming geometry updates is handled only in setGeometry()
Q_ASSERT(pendingGeometryUpdate() == PendingGeometryNone || areGeometryUpdatesBlocked());
QPoint p(x, y);
if (!areGeometryUpdatesBlocked() && p != rules()->checkPosition(p)) {
qCDebug(KWIN_CORE) << "forced position fail:" << p << ":" << rules()->checkPosition(p);
}
if (force == NormalGeometrySet && m_frameGeometry.topLeft() == p)
return;
m_frameGeometry.moveTopLeft(p);
if (areGeometryUpdatesBlocked()) {
if (pendingGeometryUpdate() == PendingGeometryForced)
{} // maximum, nothing needed
else if (force == ForceGeometrySet)
setPendingGeometryUpdate(PendingGeometryForced);
else
setPendingGeometryUpdate(PendingGeometryNormal);
return;
}
doMove(x, y);
updateWindowRules(Rules::Position);
screens()->setCurrent(this);
workspace()->updateStackingOrder();
// client itself is not damaged
addRepaintDuringGeometryUpdates();
updateGeometryBeforeUpdateBlocking();
emit geometryChanged();
}
bool AbstractClient::startMoveResize()
{
Q_ASSERT(!isMoveResize());
Q_ASSERT(QWidget::keyboardGrabber() == nullptr);
Q_ASSERT(QWidget::mouseGrabber() == nullptr);
stopDelayedMoveResize();
if (QApplication::activePopupWidget() != nullptr)
return false; // popups have grab
if (isFullScreen() && (screens()->count() < 2 || !isMovableAcrossScreens()))
return false;
if (!doStartMoveResize()) {
return false;
}
invalidateDecorationDoubleClickTimer();
setMoveResize(true);
workspace()->setMoveResizeClient(this);
const Position mode = moveResizePointerMode();
if (mode != PositionCenter) { // means "isResize()" but moveResizeMode = true is set below
if (maximizeMode() == MaximizeFull) { // partial is cond. reset in finishMoveResize
setGeometryRestore(frameGeometry()); // "restore" to current geometry
setMaximize(false, false);
}
}
if (quickTileMode() != QuickTileMode(QuickTileFlag::None) && mode != PositionCenter) { // Cannot use isResize() yet
// Exit quick tile mode when the user attempts to resize a tiled window
updateQuickTileMode(QuickTileFlag::None); // Do so without restoring original geometry
setGeometryRestore(frameGeometry());
emit quickTileModeChanged();
}
updateHaveResizeEffect();
updateInitialMoveResizeGeometry();
checkUnrestrictedMoveResize();
emit clientStartUserMovedResized(this);
if (ScreenEdges::self()->isDesktopSwitchingMovingClients())
ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal);
return true;
}
void AbstractClient::finishMoveResize(bool cancel)
{
GeometryUpdatesBlocker blocker(this);
const bool wasResize = isResize(); // store across leaveMoveResize
leaveMoveResize();
if (cancel)
setFrameGeometry(initialMoveResizeGeometry());
else {
const QRect &moveResizeGeom = moveResizeGeometry();
if (wasResize) {
const bool restoreH = maximizeMode() == MaximizeHorizontal &&
moveResizeGeom.width() != initialMoveResizeGeometry().width();
const bool restoreV = maximizeMode() == MaximizeVertical &&
moveResizeGeom.height() != initialMoveResizeGeometry().height();
if (restoreH || restoreV) {
changeMaximize(restoreH, restoreV, false);
}
}
setFrameGeometry(moveResizeGeom);
}
checkScreen(); // needs to be done because clientFinishUserMovedResized has not yet re-activated online alignment
if (screen() != moveResizeStartScreen()) {
workspace()->sendClientToScreen(this, screen()); // checks rule validity
if (maximizeMode() != MaximizeRestore)
checkWorkspacePosition();
}
if (isElectricBorderMaximizing()) {
setQuickTileMode(electricBorderMode());
setElectricBorderMaximizing(false);
} else if (!cancel) {
QRect geom_restore = geometryRestore();
if (!(maximizeMode() & MaximizeHorizontal)) {
geom_restore.setX(frameGeometry().x());
geom_restore.setWidth(frameGeometry().width());
}
if (!(maximizeMode() & MaximizeVertical)) {
geom_restore.setY(frameGeometry().y());
geom_restore.setHeight(frameGeometry().height());
}
setGeometryRestore(geom_restore);
}
// FRAME update();
emit clientFinishUserMovedResized(this);
}
// This function checks if it actually makes sense to perform a restricted move/resize.
// If e.g. the titlebar is already outside of the workarea, there's no point in performing
// a restricted move resize, because then e.g. resize would also move the window (#74555).
// NOTE: Most of it is duplicated from handleMoveResize().
void AbstractClient::checkUnrestrictedMoveResize()
{
if (isUnrestrictedMoveResize())
return;
const QRect &moveResizeGeom = moveResizeGeometry();
QRect desktopArea = workspace()->clientArea(WorkArea, moveResizeGeom.center(), desktop());
int left_marge, right_marge, top_marge, bottom_marge, titlebar_marge;
// restricted move/resize - keep at least part of the titlebar always visible
// how much must remain visible when moved away in that direction
left_marge = qMin(100 + borderRight(), moveResizeGeom.width());
right_marge = qMin(100 + borderLeft(), moveResizeGeom.width());
// width/height change with opaque resizing, use the initial ones
titlebar_marge = initialMoveResizeGeometry().height();
top_marge = borderBottom();
bottom_marge = borderTop();
if (isResize()) {
if (moveResizeGeom.bottom() < desktopArea.top() + top_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
setUnrestrictedMoveResize(true);
if (!isUnrestrictedMoveResize() && moveResizeGeom.top() < desktopArea.top()) // titlebar mustn't go out
setUnrestrictedMoveResize(true);
}
if (isMove()) {
if (moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1)
setUnrestrictedMoveResize(true);
// no need to check top_marge, titlebar_marge already handles it
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge + 1) // titlebar mustn't go out
setUnrestrictedMoveResize(true);
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
setUnrestrictedMoveResize(true);
}
}
// When the user pressed mouse on the titlebar, don't activate move immediatelly,
// since it may be just a click. Activate instead after a delay. Move used to be
// activated only after moving by several pixels, but that looks bad.
void AbstractClient::startDelayedMoveResize()
{
Q_ASSERT(!m_moveResize.delayedTimer);
m_moveResize.delayedTimer = new QTimer(this);
m_moveResize.delayedTimer->setSingleShot(true);
connect(m_moveResize.delayedTimer, &QTimer::timeout, this,
[this]() {
Q_ASSERT(isMoveResizePointerButtonDown());
if (!startMoveResize()) {
setMoveResizePointerButtonDown(false);
}
updateCursor();
stopDelayedMoveResize();
}
);
m_moveResize.delayedTimer->start(QApplication::startDragTime());
}
void AbstractClient::stopDelayedMoveResize()
{
delete m_moveResize.delayedTimer;
m_moveResize.delayedTimer = nullptr;
}
void AbstractClient::updateMoveResize(const QPointF ¤tGlobalCursor)
{
handleMoveResize(pos(), currentGlobalCursor.toPoint());
}
void AbstractClient::handleMoveResize(const QPoint &local, const QPoint &global)
{
const QRect oldGeo = frameGeometry();
handleMoveResize(local.x(), local.y(), global.x(), global.y());
if (!isFullScreen() && isMove()) {