Repository navigation
Expand file tree
/
Copy pathview_rules.cpp
More file actions
809 lines (767 loc) · 34.5 KB
/
Copy pathview_rules.cpp
File metadata and controls
809 lines (767 loc) · 34.5 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
#include "config/config.h"
#include "config/resolve.h"
#include "config/store.h"
#include "core/log.h"
#include "input/cursor.h"
#include "input/seat.h"
#include "layer/layer_surface.h"
#include "layout/scrolling.h"
#include "output/output.h"
#include "overview/overview.h"
#include "scene/effect_registry.h"
#include "scene/surface_blur.h"
#include "server/server.h"
#include "view/size_hints.h"
#include "view/view.h"
#include "view/view_internal.h"
// clang-format off
#include "wlr.h"
// clang-format on
#include "workspace/scratchpad.h"
#include "workspace/workspace.h"
#include "xwayland/xwayland.h"
namespace umbriel {
namespace {
constexpr Logger kLog("view");
template <typename T>
bool unseenInitialRuleValue(
const std::optional<T>& current, const std::vector<ResolvedWindowRule>& history,
const std::optional<T> ResolvedWindowRule::* member
) {
return current.has_value() && std::ranges::none_of(history, [&](const ResolvedWindowRule& previous) {
return previous.*member == current;
});
}
bool unseenInitialExtentValue(
const std::optional<int>& currentPixels, const std::optional<double>& currentFraction,
const std::vector<ResolvedWindowRule>& history, const std::optional<int> ResolvedWindowRule::* pixelsMember,
const std::optional<double> ResolvedWindowRule::* fractionMember
) {
if (currentPixels) {
return std::ranges::none_of(history, [&](const ResolvedWindowRule& previous) {
return previous.*pixelsMember == currentPixels;
});
}
return currentFraction.has_value() && std::ranges::none_of(history, [&](const ResolvedWindowRule& previous) {
return !(previous.*pixelsMember).has_value() && previous.*fractionMember == currentFraction;
});
}
} // namespace
using view_detail::windowRuleWorkspace;
using view_detail::windowRuleWorkspaceGroup;
// True when this window is in the workspace's only tiled column.
bool View::isAloneInLayout() const { return m_tiled && m_workspace != nullptr && m_workspace->isAloneInLayout(this); }
// True when nothing else occupies the workspace, a float counting as much as a tile.
bool View::isOnlyWindowOnWorkspace() const { return m_workspace != nullptr && m_workspace->isOnlyVisibleView(this); }
// Reads the rules with the alone state forced either way, so the alone effect knows what it should change, and so
// the opening configure can read the alone rules while the view is not in the layout yet.
ResolvedWindowRule View::resolveRulesWithAlone(bool alone) const {
WindowRuleState state = ruleState();
state.alone = alone;
return resolveWindowRules(
config(), ruleText(appId()), ruleText(title()), m_xdgTag, m_contentType, state, m_server->uptimeMs()
);
}
// The difference between the alone and not-alone rules. Only the five size-related fields are kept: the others
// are handled by the normal dynamic rules.
ResolvedWindowRule View::aloneRuleDiff(const ResolvedWindowRule& alone, const ResolvedWindowRule& other) const {
ResolvedWindowRule diff;
if (alone.defaultFullscreen != other.defaultFullscreen) {
diff.defaultFullscreen = alone.defaultFullscreen;
}
if (alone.defaultMaximizeToEdges != other.defaultMaximizeToEdges) {
diff.defaultMaximizeToEdges = alone.defaultMaximizeToEdges;
}
if (alone.defaultMaximize != other.defaultMaximize) {
diff.defaultMaximize = alone.defaultMaximize;
}
if (alone.defaultScrollingExtentPx != other.defaultScrollingExtentPx) {
diff.defaultScrollingExtentPx = alone.defaultScrollingExtentPx;
}
if (alone.defaultScrollingExtent != other.defaultScrollingExtent) {
diff.defaultScrollingExtent = alone.defaultScrollingExtent;
}
return diff;
}
// Applies one effect at a time, in the same order as at map time. Returns whether the effect was applied: if the
// window is already there, or the layout cannot do it, nothing is claimed and leaving alone will not undo anything.
// The exception is a state the opening configure seeded from these same rules, which this pass takes over.
bool View::applyAloneRuleEffects(const ResolvedWindowRule& delta) {
if (delta.defaultFullscreen && *delta.defaultFullscreen) {
if (scheduledFullscreen() && m_aloneOpeningSeed != AloneSeed::Fullscreen) {
return false;
}
setFullscreen(true);
m_aloneAction = AloneAction::Fullscreen;
return true;
}
if (delta.defaultMaximizeToEdges && *delta.defaultMaximizeToEdges) {
if ((m_maximizedToEdges && m_aloneOpeningSeed != AloneSeed::MaximizeToEdges) || scheduledFullscreen()) {
return false;
}
setMaximizedToEdges(true);
m_aloneAction = AloneAction::MaximizeToEdges;
return true;
}
if (!openingParented() && delta.defaultMaximize && *delta.defaultMaximize) {
if (scheduledMaximized() && m_aloneOpeningSeed != AloneSeed::Maximize) {
return false;
}
setMaximized(true);
m_aloneAction = AloneAction::Maximize;
return true;
}
if ((delta.defaultScrollingExtentPx || delta.defaultScrollingExtent)
&& m_workspace != nullptr
&& !scheduledFullscreen()
&& !m_maximizedToEdges
&& !scheduledMaximized()) {
ScrollingLayout* scrolling = m_workspace->scrollingLayout();
if (scrolling != nullptr) {
const int column = scrolling->columnOf(this);
if (column >= 0) {
// Pixel rules take precedence over fraction rules
if (delta.defaultScrollingExtentPx) {
const int target = *delta.defaultScrollingExtentPx;
const double current = scrolling->widthFraction(column);
if (target != current) {
m_aloneSavedWidthFrac = current;
scrolling->setWidthFromPixels(column, m_workspace->scrollViewportExtent(), target);
m_workspace->markArrange();
m_aloneAction = AloneAction::Width;
return true;
}
} else if (delta.defaultScrollingExtent) {
const double target = *delta.defaultScrollingExtent;
const double current = scrolling->widthFraction(column);
if (target != current) {
m_aloneSavedWidthFrac = current;
scrolling->setWidthFraction(column, target);
m_workspace->markArrange();
m_aloneAction = AloneAction::Width;
return true;
}
}
m_aloneSavedWidthFrac = scrolling->widthFraction(-1);
m_aloneAction = AloneAction::Width;
return true;
}
}
}
return false;
}
// Undoes the effect that was applied. For the width, the value saved before is restored, it is cleared even when
// the window no longer has a column (the layout changed).
void View::revertAloneRuleEffects() {
switch (m_aloneAction) {
case AloneAction::Fullscreen:
if (scheduledFullscreen()) {
setFullscreen(false);
}
break;
case AloneAction::MaximizeToEdges:
if (m_maximizedToEdges) {
setMaximizedToEdges(false);
}
break;
case AloneAction::Maximize:
if (scheduledMaximized() && !m_maximizedToEdges) {
setMaximized(false);
}
break;
case AloneAction::Width:
if (m_workspace != nullptr) {
ScrollingLayout* scrolling = m_workspace->scrollingLayout();
if (scrolling != nullptr) {
const int column = scrolling->columnOf(this);
if (column >= 0) {
const std::optional<double> notAloneWidth = resolveRulesWithAlone(false).defaultScrollingExtent;
const double restore = notAloneWidth.value_or(m_aloneSavedWidthFrac.value_or(scrolling->widthFraction(-1)));
scrolling->setWidthFraction(column, restore);
m_workspace->markArrange();
}
}
m_aloneSavedWidthFrac.reset();
}
break;
case AloneAction::None:
break;
}
m_aloneAction = AloneAction::None;
}
void View::releaseColumnWideAloneEffect() {
if (!m_aloneEffectsActive || m_workspace == nullptr) {
return;
}
if (m_aloneAction != AloneAction::Maximize && m_aloneAction != AloneAction::Width) {
return;
}
const int column = m_workspace->layout().columnOf(this);
if (column < 0) {
return;
}
const auto& views = m_workspace->layout().columns()[static_cast<size_t>(column)].views;
if (views.size() <= 1) {
return;
}
// toggleFloating unmaximizes, then re-maximizes the float; keep it owned for the alone pass.
const bool maximizeAlreadyUndone =
m_aloneAction == AloneAction::Maximize && (!scheduledMaximized() || m_maximizedToEdges);
if (!maximizeAlreadyUndone) {
revertAloneRuleEffects();
m_aloneEffectsActive = false;
m_lastAloneDelta = {};
}
// The column survives, so its peers can reapply their own effects.
for (View* other : views) {
if (other != this) {
other->m_lastAloneDelta = {};
}
}
}
// Called by the workspace whenever the tiled columns change, or on a config reload. The dynamic rules come first, so
// `match.is_only_window` lands with them. If the window leaves the only column, the applied effect is undone. While
// alone, the settings are only re-applied when the effective ones changed; gaining or losing a peer in the column
// changes them too, because fullscreen and maximize-to-edges stop being applicable.
bool View::notifyAloneStateChanged() {
if (!m_mapped || m_workspace == nullptr) {
return false;
}
refreshStateRuleEffects();
const bool alone = isAloneInLayout();
const bool soleTiled = m_workspace->isOnlyTiledView(this);
if (!alone) {
if (!m_aloneEffectsActive) {
// The window may become alone again with the same rules, so the old answer must not suppress that pass.
m_lastAloneDelta = ResolvedWindowRule{};
return false;
}
revertAloneRuleEffects();
m_lastAloneDelta = ResolvedWindowRule{};
m_aloneEffectsActive = false;
m_workspace->ensureFocusedVisible();
return true;
}
ResolvedWindowRule delta = aloneRuleDiff(resolvedRules(), resolveRulesWithAlone(false));
// A column can hold several windows. Fullscreen and maximize-to-edges cover the output, so they still need the
// window to be the only tile; maximize and the scrolling extent belong to the whole column and stay applicable.
if (!soleTiled) {
delta.defaultFullscreen.reset();
delta.defaultMaximizeToEdges.reset();
}
if (delta == m_lastAloneDelta) {
return false;
}
bool changed = false;
if (m_aloneEffectsActive) {
revertAloneRuleEffects();
changed = true;
}
const bool applied = applyAloneRuleEffects(delta);
m_lastAloneDelta = std::move(delta);
m_aloneEffectsActive = applied;
return changed || applied;
}
// The alone rules can name the column the window opens in, and the attach must know that name before it looks for
// the column, so a peer opening through the same name finds this window.
void View::registerOpeningAloneColumn() {
if (m_workspace == nullptr || !m_tiled || m_workspace->layoutMode() == LayoutMode::Stacking) {
return;
}
const ResolvedWindowRule alone = resolveRulesWithAlone(true);
if (m_workspace->wouldBeAloneInLayout(
this, alone.defaultScrollingColumn.value_or(""), alone.defaultScrollingColumnOrder
)) {
m_namedScrollingColumnName = alone.defaultScrollingColumn;
m_namedScrollingColumnOrder = alone.defaultScrollingColumnOrder;
}
}
// The opening configure states a window that will be in the only tiled column from its alone rules, before the view
// is in the layout. Now that it is, notifyAloneStateChanged hands that state to the alone effect, so leaving alone
// undoes it again. The seed is single-use: a later pass must not take over a state the user or the client chose.
void View::settleOpeningAloneState() {
// Restored maximize only steals alone ownership when the compositor honors it. Otherwise the alone rule owns the
// state like any other window, and the client's session flag is ignored.
const bool maximizedSeed =
m_aloneOpeningSeed == AloneSeed::MaximizeToEdges || m_aloneOpeningSeed == AloneSeed::Maximize;
const bool clientRequested = m_aloneOpeningSeed == AloneSeed::Fullscreen
? requestedFullscreen()
: maximizedSeed && requestedMaximized() && config().general.honorRestoredMaximize;
const bool soleTiled = m_workspace != nullptr && m_workspace->isOnlyTiledView(this);
if (clientRequested) {
// The client has asked for the state itself since the opening configure, so it owns it.
m_aloneOpeningSeed = AloneSeed::None;
} else if (!isAloneInLayout()) {
// Another column reached the workspace first, so nothing owns the seeded state: neither the client nor the
// window's not-alone rules. The arrange the attach marked carries the tiled size.
if (m_aloneOpeningSeed == AloneSeed::Fullscreen) {
setFullscreen(false, FullscreenExitLayout::DeferToCaller);
} else if (m_aloneOpeningSeed == AloneSeed::MaximizeToEdges) {
setMaximizedToEdges(false);
} else if (m_aloneOpeningSeed == AloneSeed::Maximize) {
setMaximized(false);
}
} else if (!soleTiled) {
// Another window joined the column. The output-covering states no longer apply, while a maximized column and
// its extent do.
if (m_aloneOpeningSeed == AloneSeed::Fullscreen) {
setFullscreen(false, FullscreenExitLayout::DeferToCaller);
} else if (m_aloneOpeningSeed == AloneSeed::MaximizeToEdges) {
setMaximizedToEdges(false);
}
}
notifyAloneStateChanged();
m_aloneOpeningSeed = AloneSeed::None;
}
bool View::confinePointer() { return resolvedRules().confinePointer.value_or(false); }
double View::touchpadScrollFactor() { return resolvedRules().touchpadScrollFactor.value_or(1.0); }
bool View::allowsShortcutsInhibit() { return resolvedRules().allowShortcutsInhibit.value_or(true); }
std::optional<bool> View::tearingRuleOverride() { return resolvedRules().allowTearing; }
void View::applyWindowRules() {
if (!m_mapped) {
return;
}
// Late app ID or title settlement may select opening rules, but identity hints changed after map must not select
// new one-shot behavior. is_alone never selects opening settings: alone effects are applied and undone on every
// change to the workspace's tiled set.
const ResolvedWindowRule rule = resolveWindowRules(
config(), m_initialRulesAppId, m_initialRulesTitle, m_initialRulesXdgTag, m_initialRulesContentType,
m_initialRuleState, m_server->uptimeMs()
);
// An attached dialog's placement is its parent's, so the placement rules have nothing to act on.
if (attached()) {
m_initialRules = rule;
m_initialRuleHistory.push_back(rule);
applyDynamicRules();
return;
}
ScratchpadManager* scratchpadManager = m_server->scratchpadManager();
const bool wasInScratchpad = scratchpadManager != nullptr && scratchpadManager->contains(this);
const bool scratchpadChanged =
unseenInitialRuleValue(rule.defaultScratchpad, m_initialRuleHistory, &ResolvedWindowRule::defaultScratchpad);
const bool defaultFloatingChanged =
unseenInitialRuleValue(rule.defaultFloating, m_initialRuleHistory, &ResolvedWindowRule::defaultFloating);
const bool floatingWidthChanged = unseenInitialExtentValue(
rule.defaultFloatingWidthPx, rule.defaultFloatingWidth, m_initialRuleHistory,
&ResolvedWindowRule::defaultFloatingWidthPx, &ResolvedWindowRule::defaultFloatingWidth
);
const bool floatingHeightChanged = unseenInitialExtentValue(
rule.defaultFloatingHeightPx, rule.defaultFloatingHeight, m_initialRuleHistory,
&ResolvedWindowRule::defaultFloatingHeightPx, &ResolvedWindowRule::defaultFloatingHeight
);
const bool floatingPositionChanged =
unseenInitialRuleValue(rule.defaultPosition, m_initialRuleHistory, &ResolvedWindowRule::defaultPosition);
bool floatingGeometryAppliedOnTransition = false;
const bool enteringFloatingByRule = !wasInScratchpad && defaultFloatingChanged && *rule.defaultFloating && m_tiled;
const bool placementChanged =
(rule.defaultOutput.has_value() || rule.defaultWorkspace.has_value())
&& std::ranges::none_of(m_initialRuleHistory, [&](const ResolvedWindowRule& previous) {
return previous.defaultOutput == rule.defaultOutput && previous.defaultWorkspace == rule.defaultWorkspace;
});
const bool namedScrollingColumnTupleUnseen =
rule.defaultScrollingColumn.has_value()
&& std::ranges::none_of(m_initialRuleHistory, [&](const ResolvedWindowRule& previous) {
return previous.defaultScrollingColumn == rule.defaultScrollingColumn
&& previous.defaultScrollingColumnOrder == rule.defaultScrollingColumnOrder;
});
const bool namedScrollingColumnNameChanged =
namedScrollingColumnTupleUnseen && rule.defaultScrollingColumn != m_namedScrollingColumnName;
const bool namedScrollingColumnOrderChanged =
namedScrollingColumnTupleUnseen && rule.defaultScrollingColumn == m_namedScrollingColumnName;
std::optional<Workspace::NamedScrollingColumnChange> namedScrollingColumnChange;
if (namedScrollingColumnNameChanged) {
namedScrollingColumnChange = Workspace::NamedScrollingColumnChange::Name;
} else if (namedScrollingColumnOrderChanged) {
namedScrollingColumnChange = Workspace::NamedScrollingColumnChange::Order;
}
if (namedScrollingColumnChange) {
m_namedScrollingColumnName = rule.defaultScrollingColumn;
m_namedScrollingColumnOrder = rule.defaultScrollingColumnOrder;
}
if (!wasInScratchpad && placementChanged && m_workspace != nullptr) {
const bool wasActivated = m_activated;
WorkspaceGroup* targetGroup = windowRuleWorkspaceGroup(*m_server, rule, m_workspace->group());
Workspace* target = windowRuleWorkspace(targetGroup, rule);
if (target != nullptr && target != m_workspace) {
setWorkspace(target, false);
if (m_workspace == target) {
if (!enteringFloatingByRule) {
target->layoutAttach(
this, rule.defaultScrollingExtent, rule.defaultScrollingExtentPx, LayoutAttachOrigin::OpeningView
);
if (m_tiled && scheduledMaximized() && !m_maximizedToEdges) {
setMaximized(true);
}
}
if (wasActivated) {
m_server->focusView(this);
}
}
}
}
// Identity can arrive after map. Apply a newly selected one-shot value, but never replay a value already applied at
// map over the user's later state.
// Move first so a simultaneous floating-size rule resolves against the destination output.
if (!wasInScratchpad && defaultFloatingChanged) {
const bool wantFloat = *rule.defaultFloating;
if (wantFloat && m_floatedByStackingLayout) {
m_floatedByStackingLayout = false;
}
if (wantFloat != !m_tiled) {
if (wantFloat) {
if (floatingWidthChanged) {
m_pendingFloatingWidthPx = rule.defaultFloatingWidthPx;
m_pendingFloatingWidth = rule.defaultFloatingWidth;
}
if (floatingHeightChanged) {
m_pendingFloatingHeightPx = rule.defaultFloatingHeightPx;
m_pendingFloatingHeight = rule.defaultFloatingHeight;
}
if (floatingPositionChanged) {
m_pendingFloatingPosition = rule.defaultPosition;
}
}
setFloating(wantFloat);
floatingGeometryAppliedOnTransition = wantFloat && !m_tiled;
}
}
if (namedScrollingColumnChange && m_workspace != nullptr) {
m_workspace->applyNamedScrollingColumnRule(
this, rule.defaultScrollingExtent, rule.defaultScrollingExtentPx, *namedScrollingColumnChange
);
}
std::optional<std::string_view> scratchpadTarget;
if ((!wasInScratchpad || scratchpadChanged)
&& rule.defaultScratchpad
&& scratchpadManager != nullptr
&& scratchpadManager->hasScratchpad(*rule.defaultScratchpad)) {
scratchpadTarget = *rule.defaultScratchpad;
} else if (wasInScratchpad) {
scratchpadTarget = scratchpadManager->nameFor(this);
}
const bool updateScratchpad =
scratchpadTarget && (scratchpadChanged || (wasInScratchpad && (placementChanged || defaultFloatingChanged)));
bool assignedScratchpad = false;
if (updateScratchpad) {
Output* savedOutput = wasInScratchpad ? scratchpadManager->restoreOutputFor(this) : nullptr;
Workspace* targetWorkspace = !wasInScratchpad ? m_workspace : nullptr;
Output* targetOutput = targetWorkspace != nullptr && targetWorkspace->group() != nullptr
? targetWorkspace->group()->output()
: savedOutput;
if (placementChanged) {
WorkspaceGroup* fallbackGroup = targetOutput != nullptr ? targetOutput->workspaceGroup() : nullptr;
WorkspaceGroup* targetGroup = windowRuleWorkspaceGroup(*m_server, rule, fallbackGroup);
targetWorkspace = windowRuleWorkspace(targetGroup, rule);
targetOutput = targetGroup != nullptr ? targetGroup->output() : targetOutput;
}
if (targetOutput == nullptr) {
targetOutput = currentOutput();
}
std::optional<bool> restoreTiled;
if (!wasInScratchpad) {
restoreTiled = m_pinned ? m_restoreTiledAfterUnpin : m_tiled;
}
if (defaultFloatingChanged) {
restoreTiled = !*rule.defaultFloating;
}
if (targetOutput != nullptr) {
const bool wasActivated = m_activated;
assignedScratchpad = scratchpadManager->assignAutomatic(
this, *scratchpadTarget, targetOutput,
ScratchpadManager::AutomaticAdmission{
.restoreOutput = targetOutput,
.restoreWorkspace = targetWorkspace,
.focusOrigin = currentOutput(),
.restoreTiled = restoreTiled,
.updateRestoreLocation = !wasInScratchpad || placementChanged,
}
);
if (assignedScratchpad
&& scratchpadChanged
&& rule.defaultFocused.value_or(false)
&& scratchpadManager->summon(*scratchpadTarget, targetOutput, this)
&& wasActivated) {
m_server->focusView(this);
}
}
}
const bool inScratchpad = wasInScratchpad || assignedScratchpad;
if (!inScratchpad
&& unseenInitialRuleValue(rule.defaultPinned, m_initialRuleHistory, &ResolvedWindowRule::defaultPinned)) {
setPinned(*rule.defaultPinned, false);
}
ScrollingLayout* scrolling = m_workspace != nullptr ? m_workspace->scrollingLayout() : nullptr;
const bool defaultExtentChanged = unseenInitialExtentValue(
rule.defaultScrollingExtentPx, rule.defaultScrollingExtent, m_initialRuleHistory,
&ResolvedWindowRule::defaultScrollingExtentPx, &ResolvedWindowRule::defaultScrollingExtent
);
const bool ownsNamedScrollingColumnExtent =
m_displacedHome ? m_displacedHome->ownsNamedScrollingColumnExtent : m_ownsNamedScrollingColumnExtent;
if (defaultExtentChanged
&& m_tiled
&& m_namedScrollingColumnName
&& m_displacedHome
&& ownsNamedScrollingColumnExtent) {
m_displacedHome->pendingNamedScrollingColumnExtentPx = rule.defaultScrollingExtentPx;
m_displacedHome->pendingNamedScrollingColumnExtent = rule.defaultScrollingExtent;
}
const bool canResizeCurrentNamedScrollingColumn =
ownsNamedScrollingColumnExtent && (!m_displacedHome || m_ownsNamedScrollingColumnExtent);
if (defaultExtentChanged
&& m_tiled
&& scrolling != nullptr
&& (!m_namedScrollingColumnName || canResizeCurrentNamedScrollingColumn)) {
const int column = scrolling->columnOf(this);
if (column >= 0) {
if (rule.defaultScrollingExtentPx) {
scrolling->setWidthFromPixels(column, m_workspace->scrollViewportExtent(), *rule.defaultScrollingExtentPx);
} else if (rule.defaultScrollingExtent) {
scrolling->setWidthFraction(column, *rule.defaultScrollingExtent);
}
m_workspace->markArrange();
}
}
if (defaultExtentChanged && !m_tiled) {
m_savedScrollingExtentPx = rule.defaultScrollingExtentPx;
m_savedScrollingExtent = rule.defaultScrollingExtent;
}
if (!inScratchpad && !floatingGeometryAppliedOnTransition && (floatingWidthChanged || floatingHeightChanged)) {
if (!m_tiled) {
const wlr_box usable = floatingUsableArea();
const SizeHints hints = sizeHints();
auto [width, height] = floatingSize();
if (floatingWidthChanged) {
if (rule.defaultFloatingWidthPx) {
width = clampWidth(*rule.defaultFloatingWidthPx, hints);
} else if (rule.defaultFloatingWidth && usable.width > 0) {
width = clampWidth(floatingFractionSize(*rule.defaultFloatingWidth, usable.width), hints);
}
}
if (floatingHeightChanged) {
if (rule.defaultFloatingHeightPx) {
height = clampHeight(*rule.defaultFloatingHeightPx, hints);
} else if (rule.defaultFloatingHeight && usable.height > 0) {
height = clampHeight(floatingFractionSize(*rule.defaultFloatingHeight, usable.height), hints);
}
}
if (width > 0 && height > 0) {
requestFloatingSize(width, height);
placeInUsableArea();
}
} else {
if (floatingWidthChanged) {
m_pendingFloatingWidthPx = rule.defaultFloatingWidthPx;
m_pendingFloatingWidth = rule.defaultFloatingWidth;
}
if (floatingHeightChanged) {
m_pendingFloatingHeightPx = rule.defaultFloatingHeightPx;
m_pendingFloatingHeight = rule.defaultFloatingHeight;
}
}
}
if (!inScratchpad && !floatingGeometryAppliedOnTransition && floatingPositionChanged) {
if (!m_tiled) {
placeInUsableArea(rule.defaultPosition);
} else {
m_pendingFloatingPosition = rule.defaultPosition;
}
}
if (!inScratchpad
&& unseenInitialRuleValue(rule.defaultFullscreen, m_initialRuleHistory, &ResolvedWindowRule::defaultFullscreen)
&& *rule.defaultFullscreen
&& !scheduledFullscreen()) {
setFullscreen(true);
}
if (!inScratchpad
&& unseenInitialRuleValue(
rule.defaultMaximizeToEdges, m_initialRuleHistory, &ResolvedWindowRule::defaultMaximizeToEdges
)
&& *rule.defaultMaximizeToEdges
&& !m_maximizedToEdges) {
setMaximizedToEdges(true);
}
if (!inScratchpad
&& !openingParented()
&& unseenInitialRuleValue(rule.defaultMaximize, m_initialRuleHistory, &ResolvedWindowRule::defaultMaximize)
&& *rule.defaultMaximize
&& !scheduledMaximized()) {
setMaximized(true);
}
// A later initial identity signal compares against every resolution already considered, so it cannot replay an
// earlier one-shot value over intervening user state. Keep the latest resolution for later parent changes.
m_initialRules = rule;
m_initialRuleHistory.push_back(rule);
// Dynamic effects use the current identity hints, including ones changed after map.
applyDynamicRules();
}
void View::refreshStartupRuleEffects() {
m_rulesGeneration = 0;
if (m_mapped) {
applyDynamicRules();
}
}
void View::refreshStateRuleEffects() {
syncMinimizeEligibility();
if (m_mapped && m_appliedRuleState != ruleState()) {
applyDynamicRules();
}
}
WindowRuleState View::ruleState() const {
return {
.focused = m_borderFocusedState,
.floating = !m_tiled,
.maximizedToEdges = m_maximizedToEdges,
.pinned = m_pinned,
.scratchpad = m_inScratchpad,
.alone = isAloneInLayout(),
.onlyWindow = isOnlyWindowOnWorkspace(),
.dialog = shellParent() != nullptr,
.castTarget = m_server->viewCaptured(*this),
.layout = m_workspace != nullptr ? std::optional{m_workspace->layoutMode()} : std::nullopt,
};
}
const ResolvedWindowRule& View::resolvedRules() {
const std::optional<std::string_view> ruleAppId = ruleText(appId());
const std::optional<std::string_view> ruleTitle = ruleText(title());
const uint64_t generation = configStore().generation();
const WindowRuleState state = ruleState();
// An unset identity string is a distinct key from an empty one: only the latter matches a pattern accepting the
// empty string, so a client that replaces a missing title with an empty one must re-resolve.
if (m_rulesGeneration == generation
&& m_rulesState == state
&& m_rulesAppId == ruleAppId
&& m_rulesTitle == ruleTitle
&& m_rulesXdgTag == m_xdgTag
&& m_rulesContentType == m_contentType) {
return m_rules;
}
m_rules = resolveWindowRules(config(), ruleAppId, ruleTitle, m_xdgTag, m_contentType, state, m_server->uptimeMs());
m_rulesGeneration = generation;
m_rulesState = state;
m_rulesAppId = ruleAppId;
m_rulesTitle = ruleTitle;
m_rulesXdgTag = m_xdgTag;
m_rulesContentType = m_contentType;
return m_rules;
}
void View::refreshEffectSelection() {
applyDynamicRules();
scheduleFrame();
m_server->scheduleIpcWindowsEvent();
}
void View::onEffectSelectionIdle(void* data) {
auto* view = static_cast<View*>(data);
view->m_effectSelectionIdle = nullptr;
if (view->m_mapped) {
view->refreshEffectSelection();
}
}
void View::applyDynamicRules(const ResolvedWindowRule* resolved) {
const bool frame = m_server->handlingOutputFrame();
if (!frame && m_effectSelectionIdle != nullptr) {
wl_event_source_remove(m_effectSelectionIdle);
m_effectSelectionIdle = nullptr;
}
const ResolvedWindowRule& rule = resolved != nullptr ? *resolved : resolvedRules();
const bool focusChanged = m_appliedRuleState.focused != ruleState().focused;
m_appliedRuleState = ruleState();
if (const bool allowed = rule.allowShortcutsInhibit.value_or(true); allowed != m_allowShortcutsInhibit) {
m_allowShortcutsInhibit = allowed;
m_server->refreshKeyboardShortcutsInhibitors();
}
const std::optional<TitleBarMode> titleBarMode = rule.titleBar;
if (m_titleBarMode != titleBarMode) {
m_titleBarMode = titleBarMode;
refreshTitleBar();
}
if (m_titleBarButtons != rule.titleBarButtons) {
m_titleBarButtons = rule.titleBarButtons;
syncTitleBarButtons();
}
// Tile spacing stays on the global border width, so a decoration change redraws this window without an arrange.
const bool ringChanged = m_decoration.applyRule(rule);
const auto resolve = [&](EffectKind kind, const std::string& fallback, const std::optional<std::string>& selected) {
EffectSlot& slot = m_effects.slot(kind);
const std::string& selector = selected ? *selected : fallback;
const auto source = selected ? EffectSelectorSource::Rule : EffectSelectorSource::Default;
if (frame) {
if (slot.configuredSelector == selector && slot.configuredSource == source) {
return;
}
if ((!selector.empty() && selector != kEffectOff) || !slot.name.empty() || !slot.pool.empty()) {
if (m_effectSelectionIdle == nullptr) {
m_effectSelectionIdle =
wl_event_loop_add_idle(wl_display_get_event_loop(m_server->display()), onEffectSelectionIdle, this);
if (m_effectSelectionIdle == nullptr) {
kLog.error("failed to defer effect selection after a frame-time rule change");
}
}
return;
}
// Empty/off selectors need no allocation policy or idle source.
}
const auto before = std::tuple(slot.name, slot.pool, slot.source(), slot.suppressed);
slot.configuredSelector = selector;
slot.configuredSource = source;
if (!frame) {
m_server->resolveEffectSlot(slot, kind, m_mapped);
}
if (m_mapped && before != std::tuple(slot.name, slot.pool, slot.source(), slot.suppressed)) {
scheduleFrame();
m_server->scheduleIpcWindowsEvent();
}
};
resolve(EffectKind::Border, config().effects.border, rule.borderEffect);
resolve(EffectKind::Window, config().effects.window, rule.windowEffect);
m_effects.syncNames(config().effects);
const bool paddingChanged = m_decoration.setBorderPadding(m_effects.borderPadding());
if (ringChanged || paddingChanged) {
updateBorderGeometry();
applyCornerRadius();
updateShadow();
}
if (paddingChanged) {
// Overview cards lay their rings out from the padding too.
if (Overview* overview = m_server->overview(); overview != nullptr && overview->active()) {
overview->onViewPresentationChanged(this);
scheduleFrame();
}
}
const auto& opacityAnimation = config().animation.windowsOpacity;
const bool animateFocus = m_mapped && config().animation.enabled && opacityAnimation.enabled;
const auto now = static_cast<double>(m_server->animationClockMsec());
const auto update = [&](AnimatedValue& value, double target) {
if (animateFocus && focusChanged && value.target() != target) {
value.tick(now);
value.retarget(target, opacityAnimation.durationMs, opacityAnimation.curve);
value.tick(now);
scheduleFrame();
} else if (!animateFocus || value.target() != target) {
value.snap(target);
}
};
update(m_ruleOpacity, rule.opacity.value_or(1.0));
update(m_ruleBlur, rule.blur.value_or(false) ? 1.0 : 0.0);
updateBorderColor(focusChanged);
setFadeAlpha(m_fadeAlpha);
m_ruleCaptureBlocked = rule.blockCapture.value_or(false);
refreshCaptureProtection();
if (const bool backgroundRender = rule.backgroundRender.value_or(false); backgroundRender != m_backgroundRender) {
m_backgroundRender = backgroundRender;
m_server->scheduleSuspensionSync();
}
m_presentation.setFullscreenOpaque(fullscreenOpaque());
updateDimBehind();
updateBlur();
// updateBlur creates the full node box. Re-apply the owning output's clip immediately, because focus, title, and
// app-id rule refreshes do not necessarily produce a later surface commit or layout pass.
if (m_workspace != nullptr) {
m_workspace->syncViewPresentation(this);
}
if (m_mapped) {
// Static effects and frozen clocks may never trigger another animation tick.
syncAnimationEffects();
m_server->refreshOutputPolicies();
}
}
} // namespace umbriel