Repository navigation
Expand file tree
/
Copy pathWindow.cpp
More file actions
1175 lines (977 loc) · 61.1 KB
/
Copy pathWindow.cpp
File metadata and controls
1175 lines (977 loc) · 61.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Window.hpp"
#include <algorithm>
#include <cmath>
#include <dlfcn.h>
#include <functional>
#include <list>
#include <memory>
#define private public
#define protected public
#include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/managers/fullscreen/FullscreenController.hpp>
#include <hyprland/src/workspace/HLWorkspace.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/managers/SeatManager.hpp>
#include <hyprland/src/desktop/state/FocusState.hpp>
#include <hyprland/src/desktop/state/WindowState.hpp>
#include <hyprland/src/desktop/view/Group.hpp>
#include <hyprland/src/desktop/view/window/Window.hpp>
#include <hyprland/src/desktop/view/window/WindowGroupMembership.hpp>
#include <hyprland/src/desktop/view/window/WindowPresentation.hpp>
#include <hyprland/src/desktop/view/Popup.hpp>
#include <hyprland/src/desktop/view/WLSurface.hpp>
#include <hyprland/src/plugins/PluginSystem.hpp>
#include <hyprland/src/render/pass/Pass.hpp>
#include <hyprland/src/render/pass/RectPassElement.hpp>
#include <hyprland/src/render/pass/BorderPassElement.hpp>
#include <hyprland/src/render/pass/RendererHintsPassElement.hpp>
#include <hyprland/src/render/pass/SurfacePassElement.hpp>
#include <hyprland/src/render/pass/TexPassElement.hpp>
#include <hyprland/src/render/types.hpp>
#include <hyprland/src/render/decorations/CHyprGroupBarDecoration.hpp>
#include <hyprland/src/render/decorations/CHyprInnerGlowDecoration.hpp>
#include <hyprland/src/render/decorations/CHyprDropShadowDecoration.hpp>
#include <hyprland/src/render/decorations/DecorationPositioner.hpp>
#include <hyprland/src/config/shared/complex/ComplexDataTypes.hpp>
#include <hyprland/src/protocols/XDGShell.hpp>
#include <hyprland/src/managers/fullscreen/FullscreenController.hpp>
#include <hyprland/src/render/decorations/CHyprBorderDecoration.hpp>
#include <hyprutils/utils/ScopeGuard.hpp>
#undef protected
#undef private
#include "Config.hpp"
#include "OverviewPassElement.hpp"
#include "OverviewRender.hpp"
namespace OverviewWindow {
namespace {
struct SOverviewCustomDecorationRenderState {
bool queuedAny = false;
std::vector<std::function<void()>> restoreFns;
};
struct SHyprbarButtonMirror {
std::string cmd = "";
bool userfg = false;
CHyprColor fgcol = CHyprColor(0, 0, 0, 0);
CHyprColor bgcol = CHyprColor(0, 0, 0, 0);
float size = 10.F;
std::string icon = "";
SP<Render::ITexture> iconTex;
};
struct SHyprbarGlobalStateMirror {
std::vector<SHyprbarButtonMirror> buttons;
};
struct SOverviewButtonKey {
std::string icon;
std::string font;
CHyprColor color;
int pointSize = 0;
int maxWidth = 0;
bool operator==(const SOverviewButtonKey&) const = default;
};
struct SOverviewButtonIcon {
SOverviewButtonKey key;
SP<Render::ITexture> texture;
};
// Key the actual raster size, not the continuously animated overview scale.
// Keep several sizes so pinned windows and differently scaled monitors reuse
// their own textures instead of replacing the regular workspace icons.
static std::list<SOverviewButtonIcon> s_overviewButtonIcons;
static SP<Render::ITexture> getOverviewButtonIcon(const SHyprbarButtonMirror& button, float pixelScale, const std::string& font) {
const float pixelSize = button.size * pixelScale;
if (button.icon.empty() || pixelSize <= 0.F)
return nullptr;
const SOverviewButtonKey key{
.icon = button.icon,
.font = font,
.color = button.userfg ? button.fgcol :
(button.bgcol.r + button.bgcol.g + button.bgcol.b < 1.F) ? CHyprColor(0xFFFFFFFF) : CHyprColor(0xFF000000),
.pointSize = std::max(1, sc<int>(std::round(pixelSize * 0.62F))),
.maxWidth = std::max(1, sc<int>(std::round(pixelSize))),
};
for (auto it = s_overviewButtonIcons.begin(); it != s_overviewButtonIcons.end(); ++it) {
if (it->key != key)
continue;
if (it->texture && it->texture->ok()) {
s_overviewButtonIcons.splice(s_overviewButtonIcons.begin(), s_overviewButtonIcons, it);
return s_overviewButtonIcons.front().texture;
}
s_overviewButtonIcons.erase(it);
break;
}
auto texture = g_pHyprRenderer->renderText(key.icon, key.color, key.pointSize, false, key.font, key.maxWidth);
if (!texture || !texture->ok())
return nullptr;
constexpr size_t MAX_CACHED_ICONS = 128;
s_overviewButtonIcons.push_front({key, texture});
if (s_overviewButtonIcons.size() > MAX_CACHED_ICONS)
s_overviewButtonIcons.pop_back();
return texture;
}
struct SOverviewButtonState {
float size = 0.F;
SP<Render::ITexture> originalIcon;
SP<Render::ITexture> overviewIcon;
};
struct SOverviewWindowMetrics {
float renderScale = 1.F;
float pxScale = 1.F;
float targetOpacity = 1.F;
float borderSize = 0.F;
int borderPx = 0;
float borderPxScaled = 0.F;
float roundingBase = 0.F;
float roundingPower = 2.F;
float correctionOffset = 0.F;
float outerRound = 0.F;
int roundingPx = 0;
int outerRoundPx = 0;
float hyprbarLogicalHeight = 0.F;
int hyprbarHeightPx = 0;
float hyprbarHeightPxScaled = 0.F;
float hyprbarTopOffsetLogical = 0.F;
bool shadowIncludesHyprbar = false;
bool borderIncludesHyprbar = false;
};
// SurfacePassElement only scales subsurface textures while the window size is
// marked as animated. Overview temporarily changes the current window size
// without starting a real animation, so expose that single bit for the duration
// of the synchronous overview render and restore it immediately afterwards.
struct COverviewAnimatedVariableAccess : Hyprutils::Animation::CBaseAnimatedVariable {
static void setBeingAnimated(Hyprutils::Animation::CBaseAnimatedVariable* variable, bool animated) {
if (!variable)
return;
rc<COverviewAnimatedVariableAccess*>(variable)->m_bIsBeingAnimated = animated;
}
};
static PHLWINDOW getOverviewWindowToShow(const PHLWINDOW& window) {
if (!window)
return nullptr;
if (window->grouping().group())
return window->grouping().group()->current();
return window;
}
static bool shouldShowOverviewWindow(const PHLWINDOW& window) {
const auto WINDOW = getOverviewWindowToShow(window);
if (!validMapped(WINDOW))
return false;
if ((WINDOW->m_state & Desktop::View::WINDOW_STATE_PINNED) && WINDOW->isFloating())
return false;
return true;
}
static float getOverviewWindowTargetOpacity(const PHLWINDOW& window) {
if (!window)
return 1.F;
const bool fullscreen = Fullscreen::controller()->isFullscreen(window);
const bool active = Desktop::focusState()->window() == window;
float targetOpacity = fullscreen ? ScrollOverview::Config::getValue<float>("decoration:fullscreen_opacity") :
active ? ScrollOverview::Config::getValue<float>("decoration:active_opacity") : ScrollOverview::Config::getValue<float>("decoration:inactive_opacity");
const auto& ruleOpacityVar = fullscreen ? window->m_ruleApplicator->alphaFullscreen() : active ? window->m_ruleApplicator->alpha() : window->m_ruleApplicator->alphaInactive();
targetOpacity = ruleOpacityVar.valueOr(Desktop::Types::SAlphaValue{}).applyAlpha(targetOpacity);
return std::clamp(targetOpacity, 0.F, 1.F);
}
struct SOverviewPseudoFocusState {
PHLWINDOW window;
SP<Desktop::CFocusState> focusState;
PHLWINDOWREF previousFocusWindow;
WP<CWLSurfaceResource> previousFocusSurface;
CHyprBorderDecoration* borderDecoration = nullptr;
CHyprDropShadowDecoration* shadowDecoration = nullptr;
CHyprInnerGlowDecoration* glowDecoration = nullptr;
Config::CGradientValueData previousBorderColor;
Config::CGradientValueData previousBorderColorPrevious;
Config::CGradientValueData previousShadowColor;
Config::CGradientValueData previousShadowColorPrevious;
Config::CGradientValueData previousGlowColor;
Config::CGradientValueData previousGlowColorPrevious;
float previousOpacity = 1.F;
float previousDim = 0.F;
bool active = false;
static void setGradientState(CAnimatedDecorationGradient& gradient, const Config::CGradientValueData& value) {
gradient.m_current = value;
gradient.m_previous = value;
}
SOverviewPseudoFocusState(const PHLWINDOW& window_, const PHLWINDOW& pseudoFocusWindow) : window(window_) {
if (!window || !pseudoFocusWindow)
return;
active = true;
focusState = Desktop::focusState();
previousFocusWindow = focusState->m_focusWindow;
previousFocusSurface = focusState->m_focusSurface;
previousOpacity = window->presentation().alpha(Desktop::View::WINDOW_ALPHA_ACTIVE)->value();
previousDim = window->presentation().dimPercent();
borderDecoration = dc<CHyprBorderDecoration*>(window->presentation().decoration(DECORATION_BORDER).get());
shadowDecoration = dc<CHyprDropShadowDecoration*>(window->presentation().decoration(DECORATION_SHADOW).get());
glowDecoration = dc<CHyprInnerGlowDecoration*>(window->presentation().decoration(DECORATION_INNER_GLOW).get());
if (borderDecoration) {
previousBorderColor = borderDecoration->m_gradient.m_current;
previousBorderColorPrevious = borderDecoration->m_gradient.m_previous;
}
if (shadowDecoration) {
previousShadowColor = shadowDecoration->m_gradient.m_current;
previousShadowColorPrevious = shadowDecoration->m_gradient.m_previous;
}
if (glowDecoration) {
previousGlowColor = glowDecoration->m_gradient.m_current;
previousGlowColorPrevious = glowDecoration->m_gradient.m_previous;
}
focusState->m_focusWindow = pseudoFocusWindow;
if (pseudoFocusWindow->wlSurface() && pseudoFocusWindow->wlSurface()->resource())
focusState->m_focusSurface = pseudoFocusWindow->wlSurface()->resource();
const bool ISACTIVE = window == pseudoFocusWindow;
const bool GROUPLOCKED = (window->grouping().group() && window->grouping().group()->locked()) || Desktop::windowState()->groupsLocked();
const bool NOGROUP = window->grouping().rules() & Desktop::View::GROUP_DENY;
const auto BORDERKEY = window->grouping().group() ?
(ISACTIVE ? (GROUPLOCKED ? "group:col.border_locked_active" : "group:col.border_active") :
(GROUPLOCKED ? "group:col.border_locked_inactive" : "group:col.border_inactive")) :
(ISACTIVE ? (NOGROUP ? "general:col.nogroup_border_active" : "general:col.active_border") :
(NOGROUP ? "general:col.nogroup_border" : "general:col.inactive_border"));
const auto BORDERCOLOR = ScrollOverview::Config::getValue<Config::CGradientValueData>(BORDERKEY);
const auto BORDER = ISACTIVE ? window->m_ruleApplicator->activeBorderColor().valueOr(BORDERCOLOR) :
window->m_ruleApplicator->inactiveBorderColor().valueOr(BORDERCOLOR);
const auto SHADOWACTIVE = ScrollOverview::Config::getValue<Config::CGradientValueData>("decoration:shadow:color");
const auto shadowInactiveReply = Config::mgr()->getConfigValue("decoration:shadow:color_inactive");
const auto SHADOWINACTIVE = (shadowInactiveReply.setByUser && *shadowInactiveReply.setByUser) ?
ScrollOverview::Config::getValue<Config::CGradientValueData>("decoration:shadow:color_inactive") : SHADOWACTIVE;
const auto GLOWACTIVE = ScrollOverview::Config::getValue<Config::CGradientValueData>("decoration:glow:color");
const auto glowInactiveReply = Config::mgr()->getConfigValue("decoration:glow:color_inactive");
const auto GLOWINACTIVE = (glowInactiveReply.setByUser && *glowInactiveReply.setByUser) ?
ScrollOverview::Config::getValue<Config::CGradientValueData>("decoration:glow:color_inactive") : GLOWACTIVE;
const Config::CGradientValueData TRANSPARENT{CHyprColor{0, 0, 0, 0}};
if (borderDecoration)
setGradientState(borderDecoration->m_gradient, BORDER);
if (shadowDecoration)
setGradientState(shadowDecoration->m_gradient, window->backend().traits().overrideRedirect || window->backend().traits().suggestsNoBorder ? TRANSPARENT : (ISACTIVE ? SHADOWACTIVE : SHADOWINACTIVE));
if (glowDecoration)
setGradientState(glowDecoration->m_gradient, window->backend().traits().overrideRedirect || window->backend().traits().suggestsNoBorder ? TRANSPARENT : (ISACTIVE ? GLOWACTIVE : GLOWINACTIVE));
window->presentation().alpha(Desktop::View::WINDOW_ALPHA_ACTIVE)->value() = getOverviewWindowTargetOpacity(window);
const bool ISMODALSHADOWED = window->backend().traits().hasModalChild;
float dim = ISACTIVE || window->m_ruleApplicator->noDim().valueOrDefault() || !ScrollOverview::Config::getValue<bool>("decoration:dim_inactive") ?
0.F :
ScrollOverview::Config::getValue<float>("decoration:dim_strength");
if (ISMODALSHADOWED && ScrollOverview::Config::getValue<bool>("decoration:dim_modal"))
dim += (1.F - dim) / 2.F;
window->presentation().m_dimPercent->value() = dim;
}
~SOverviewPseudoFocusState() {
if (!active)
return;
if (borderDecoration) {
borderDecoration->m_gradient.m_current = previousBorderColor;
borderDecoration->m_gradient.m_previous = previousBorderColorPrevious;
}
if (shadowDecoration) {
shadowDecoration->m_gradient.m_current = previousShadowColor;
shadowDecoration->m_gradient.m_previous = previousShadowColorPrevious;
}
if (glowDecoration) {
glowDecoration->m_gradient.m_current = previousGlowColor;
glowDecoration->m_gradient.m_previous = previousGlowColorPrevious;
}
window->presentation().alpha(Desktop::View::WINDOW_ALPHA_ACTIVE)->value() = previousOpacity;
window->presentation().m_dimPercent->value() = previousDim;
focusState->m_focusWindow = previousFocusWindow;
focusState->m_focusSurface = previousFocusSurface;
}
};
static void roundStandaloneWindowPassElements(const PHLWINDOW& window, PHLMONITOR monitor, float renderScale, size_t firstElement) {
if (!window || !monitor)
return;
if (Fullscreen::controller()->isFullscreen(window))
return;
const int rounding = sc<int>(std::round(window->presentation().rounding() * monitor->m_scale * renderScale));
const float roundingPower = window->presentation().roundingPower();
if (rounding <= 0)
return;
auto& passElements = Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).m_passElements;
for (size_t i = firstElement; i < passElements.size(); ++i) {
const auto& passElement = passElements[i];
if (!passElement.element)
continue;
auto* surfacePassElement = dc<CSurfacePassElement*>(passElement.element.get());
if (!surfacePassElement || surfacePassElement->m_data.pWindow != window || surfacePassElement->m_data.popup)
continue;
surfacePassElement->m_data.dontRound = false;
surfacePassElement->m_data.rounding = rounding;
surfacePassElement->m_data.roundingPower = roundingPower;
}
}
static bool isOverviewHyprbarDecoration(IHyprWindowDecoration* decoration) {
return decoration && decoration->getDecorationType() == DECORATION_CUSTOM && decoration->getDisplayName() == "Hyprbar";
}
static SHyprbarGlobalStateMirror* getOverviewHyprbarGlobalState() {
if (!g_pPluginSystem)
return nullptr;
HANDLE hyprbarsHandle = nullptr;
for (const auto* plugin : g_pPluginSystem->getAllPlugins()) {
if (!plugin)
continue;
if (plugin->m_name == "hyprbars" || plugin->m_path.contains("hyprbars")) {
hyprbarsHandle = plugin->m_handle;
break;
}
}
if (!hyprbarsHandle)
return nullptr;
void* const symbol = dlsym(hyprbarsHandle, "g_pGlobalState");
if (!symbol)
return nullptr;
const auto STATEPTR = sc<UP<SHyprbarGlobalStateMirror>*>(symbol);
if (!STATEPTR || !STATEPTR->get())
return nullptr;
// The mirror is only safe while hyprbars lays its buttons out the same way;
// a button struct that has grown makes every read and write here land in the
// wrong place, and the miscounted list aborts the compositor. A hyprbars
// that publishes its button size is taken at its word. For one that does
// not, the list has to span a whole number of mirrored buttons, and a sane
// count of them, before anything touches it.
if (const auto* const BUTTONSIZE = sc<const size_t*>(dlsym(hyprbarsHandle, "g_hyprbarsButtonSize"))) {
if (*BUTTONSIZE != sizeof(SHyprbarButtonMirror))
return nullptr;
} else {
const auto& BUTTONS = STATEPTR->get()->buttons;
const ptrdiff_t BYTES = reinterpret_cast<const char*>(std::to_address(BUTTONS.end())) - reinterpret_cast<const char*>(BUTTONS.data());
if (BYTES < 0 || sc<size_t>(BYTES) % sizeof(SHyprbarButtonMirror) != 0 || sc<size_t>(BYTES) / sizeof(SHyprbarButtonMirror) > 32)
return nullptr;
}
return STATEPTR->get();
}
static void restoreOverviewHyprbarButtons(const std::vector<SOverviewButtonState>& previousButtons) {
auto* const state = getOverviewHyprbarGlobalState();
if (!state)
return;
for (size_t i = 0; i < previousButtons.size() && i < state->buttons.size(); ++i) {
auto& button = state->buttons[i];
const auto& previous = previousButtons[i];
button.size = previous.size;
// Hyprbars updates its scale metadata when it regenerates a texture.
// If that happened during this draw, the old desktop texture no longer
// matches that metadata. Invalidate it so Hyprbars rebuilds both on its
// next draw, without relying on another plugin's private state layout.
button.iconTex = button.iconTex == previous.overviewIcon ? previous.originalIcon : nullptr;
}
}
static float getOverviewHyprbarLogicalHeight(const PHLWINDOW& window) {
if (!window || !window->m_ruleApplicator->decorate().valueOrDefault())
return 0.F;
for (const auto& deco : window->presentation().decorations()) {
if (!isOverviewHyprbarDecoration(deco.get()))
continue;
const auto INFO = deco->getPositioningInfo();
if (INFO.policy != DECORATION_POSITION_STICKY || INFO.edges != DECORATION_EDGE_TOP)
continue;
return std::max(0.F, sc<float>(INFO.desiredExtents.topLeft.y));
}
return 0.F;
}
static bool shouldOverviewBorderIncludeHyprbar(const PHLWINDOW& window) {
const float hyprbarHeight = getOverviewHyprbarLogicalHeight(window);
if (hyprbarHeight <= 0.F)
return false;
return ScrollOverview::Config::getValue<bool>("plugin:hyprbars:bar_precedence_over_border");
}
static bool shouldOverviewShadowIncludeHyprbar(const PHLWINDOW& window, bool borderIncludesHyprbar) {
const float hyprbarHeight = getOverviewHyprbarLogicalHeight(window);
if (hyprbarHeight <= 0.F)
return false;
if (borderIncludesHyprbar)
return true;
return ScrollOverview::Config::getValue<bool>("plugin:hyprbars:bar_part_of_window");
}
static void blockOverviewWindowBlurOptimization(const PHLWINDOW& window, size_t firstElement) {
if (!window)
return;
auto& passElements = Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).m_passElements;
for (size_t i = firstElement; i < passElements.size(); ++i) {
const auto& passElement = passElements[i];
if (!passElement.element)
continue;
auto* surfacePassElement = dc<CSurfacePassElement*>(passElement.element.get());
if (!surfacePassElement || surfacePassElement->m_data.pWindow != window)
continue;
surfacePassElement->m_data.blockBlurOptimization = true;
}
}
static void scaleOverviewChildSurfaceGeometry(const PHLWINDOW& window, const Vector2D& targetPosition, const Vector2D& targetSize,
size_t firstElement) {
if (!window)
return;
const auto REPORTEDSIZE = window->backend().reportedSize();
if (REPORTEDSIZE.x <= 0 || REPORTEDSIZE.y <= 0)
return;
const Vector2D SURFACESCALE = targetSize / REPORTEDSIZE;
auto& passElements = Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).m_passElements;
for (size_t i = firstElement; i < passElements.size(); ++i) {
const auto& passElement = passElements[i];
if (!passElement.element)
continue;
auto* surfacePassElement = dc<CSurfacePassElement*>(passElement.element.get());
if (!surfacePassElement || surfacePassElement->m_data.pWindow != window || surfacePassElement->m_data.mainSurface)
continue;
if (surfacePassElement->m_data.popup) {
// Popup positions are relative to the unscaled top-level window,
// while `pos` already contains the overview window position.
// Scale that relative part, including the popup's own subsurface
// offset, around the overview window origin.
surfacePassElement->m_data.pos = targetPosition + (surfacePassElement->m_data.pos - targetPosition) * SURFACESCALE;
surfacePassElement->m_data.localPos *= SURFACESCALE;
// Hyprland deliberately disables squishing for popups, which also
// disables its resize scaling. Re-enable it for this pass element,
// but expand the clamp dimensions to the complete scaled surface
// so the popup remains allowed to extend beyond the main window.
const auto SURFACESIZE =
surfacePassElement->m_data.surface->m_current.size.clamp({2.F, 2.F}, {INFINITY, INFINITY}) * SURFACESCALE;
surfacePassElement->m_data.w = std::max(1.0, surfacePassElement->m_data.localPos.x + SURFACESIZE.x + 1.0);
surfacePassElement->m_data.h = std::max(1.0, surfacePassElement->m_data.localPos.y + SURFACESIZE.y + 1.0);
surfacePassElement->m_data.squishOversized = true;
continue;
}
// Hyprland scales a regular subsurface texture during a resize, but
// its cumulative position remains in the client's reported coordinate
// space. Apply the same scale to the position so embedded dmabuf
// surfaces (OBS preview, OrcaSlicer viewport, etc.) stay attached.
surfacePassElement->m_data.localPos *= SURFACESCALE;
}
}
static void raiseWindowPopups(const PHLWINDOW& window, size_t firstElement) {
if (!window)
return;
auto& passElements = Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).m_passElements;
if (firstElement >= passElements.size())
return;
// renderWindow queues popups after the main surface, but overview adds its
// own decorations and border afterwards. Keep every non-popup element in
// its original order and move only this window's popup surfaces on top.
std::stable_partition(passElements.begin() + firstElement, passElements.end(), [&window](const auto& passElement) {
if (!passElement.element)
return true;
const auto* surfacePassElement = dc<const CSurfacePassElement*>(passElement.element.get());
return !surfacePassElement || surfacePassElement->m_data.pWindow != window || !surfacePassElement->m_data.popup;
});
}
static SOverviewWindowMetrics getOverviewWindowMetrics(PHLMONITOR monitor, const PHLWINDOW& window, float renderScale) {
SOverviewWindowMetrics metrics;
metrics.renderScale = renderScale;
metrics.targetOpacity = getOverviewWindowTargetOpacity(window);
if (!monitor || !window)
return metrics;
metrics.pxScale = monitor->m_scale * renderScale;
metrics.borderSize = window->presentation().borderSize();
metrics.borderPx = sc<int>(std::round(metrics.borderSize * monitor->m_scale));
metrics.borderPxScaled = metrics.borderSize * metrics.pxScale;
metrics.roundingBase = window->presentation().rounding();
metrics.roundingPower = window->presentation().roundingPower();
metrics.correctionOffset = metrics.borderSize * (M_SQRT2 - 1) * std::max(2.0 - metrics.roundingPower, 0.0);
metrics.outerRound = metrics.roundingBase > 0 ? (metrics.roundingBase + metrics.borderSize) - metrics.correctionOffset : 0.F;
metrics.roundingPx = sc<int>(std::round(metrics.roundingBase * metrics.pxScale));
metrics.outerRoundPx = sc<int>(std::round(metrics.outerRound * metrics.pxScale));
metrics.hyprbarLogicalHeight = getOverviewHyprbarLogicalHeight(window);
metrics.borderIncludesHyprbar = shouldOverviewBorderIncludeHyprbar(window);
metrics.shadowIncludesHyprbar = shouldOverviewShadowIncludeHyprbar(window, metrics.borderIncludesHyprbar);
metrics.hyprbarHeightPx = sc<int>(std::round(metrics.hyprbarLogicalHeight * metrics.pxScale));
metrics.hyprbarHeightPxScaled = metrics.hyprbarLogicalHeight * metrics.pxScale;
metrics.hyprbarTopOffsetLogical = metrics.hyprbarLogicalHeight > 0.F ? metrics.hyprbarLogicalHeight + metrics.borderSize : 0.F;
return metrics;
}
static std::optional<SDecorationPositioningReply> getOverviewTopStickyDecorationReply(IHyprWindowDecoration* decoration, const PHLWINDOW& window, float heightScale = 1.F) {
if (!decoration || !window)
return std::nullopt;
const auto INFO = decoration->getPositioningInfo();
if (INFO.policy != DECORATION_POSITION_STICKY || INFO.edges != DECORATION_EDGE_TOP)
return std::nullopt;
const float HEIGHT = std::max(0.F, sc<float>(INFO.desiredExtents.topLeft.y) * heightScale);
const float BORDER = sc<float>(window->presentation().borderSize());
const bool PRECEDE = shouldOverviewBorderIncludeHyprbar(window);
const float WIDTH = PRECEDE ? window->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT).x : window->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT).x + BORDER * 2.F;
const float YOFFSET = PRECEDE ? 0.F : BORDER;
return SDecorationPositioningReply{
.assignedGeometry = CBox{{-WIDTH / 2.F, -HEIGHT - YOFFSET}, {WIDTH, HEIGHT}},
};
}
static CBox getOverviewOuterBorderBox(const CBox& windowBox, const SOverviewWindowMetrics& metrics) {
CBox box = windowBox.copy().expand(metrics.borderPx);
if (metrics.shadowIncludesHyprbar && metrics.hyprbarHeightPx > 0) {
box.y -= metrics.hyprbarHeightPx;
box.height += metrics.hyprbarHeightPx;
}
return box;
}
static CBox getOverviewBorderBox(const CBox& windowBox, const SOverviewWindowMetrics& metrics) {
CBox box = windowBox;
if (metrics.borderIncludesHyprbar && metrics.hyprbarHeightPx > 0) {
box.y -= metrics.hyprbarHeightPx;
box.height += metrics.hyprbarHeightPx;
}
return box;
}
static void renderOverviewHyprbarDecoration(SOverviewCustomDecorationRenderState& state, PHLMONITOR monitor, const PHLWINDOW& window, IHyprWindowDecoration* decoration,
const CBox& windowBox, const SOverviewWindowMetrics& metrics) {
if (!monitor || !window || !decoration)
return;
auto* const HYPRBARGLOBALSTATE = getOverviewHyprbarGlobalState();
const bool PARTOFWINDOW = decoration->getDecorationFlags() & DECORATION_PART_OF_MAIN_WINDOW;
const int previousBarTextSize = ScrollOverview::Config::getValue<int>("plugin:hyprbars:bar_text_size");
const int previousButtonPadding = ScrollOverview::Config::getValue<int>("plugin:hyprbars:bar_button_padding");
const int previousBarPadding = ScrollOverview::Config::getValue<int>("plugin:hyprbars:bar_padding");
std::string barFont = ScrollOverview::Config::getValue<std::string>("plugin:hyprbars:bar_text_font");
if (barFont.empty() || barFont == STRVAL_EMPTY)
barFont = "Sans";
const float monitorScale = monitor->m_scale;
const float renderScale = metrics.renderScale;
std::vector<SOverviewButtonState> previousButtons;
if (HYPRBARGLOBALSTATE) {
previousButtons.reserve(HYPRBARGLOBALSTATE->buttons.size());
for (auto& button : HYPRBARGLOBALSTATE->buttons) {
auto icon = getOverviewButtonIcon(button, renderScale * monitorScale, barFont);
previousButtons.push_back({button.size, button.iconTex, icon});
button.size *= renderScale;
button.iconTex = std::move(icon);
}
}
ScrollOverview::Config::setValue("plugin:hyprbars:bar_text_size", std::max(1, sc<int>(std::round(previousBarTextSize * metrics.renderScale))));
ScrollOverview::Config::setValue("plugin:hyprbars:bar_button_padding", std::max(0, sc<int>(std::round(previousButtonPadding * metrics.renderScale))));
ScrollOverview::Config::setValue("plugin:hyprbars:bar_padding", std::max(0, sc<int>(std::round(previousBarPadding * metrics.renderScale))));
const Vector2D previousWindowPos = window->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const Vector2D previousWindowSize = window->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto WORKSPACE = window->m_workspace;
const bool OVERRIDEWORKSPACEOFFSET = WORKSPACE && !(window->m_state & Desktop::View::WINDOW_STATE_PINNED);
const Vector2D previousWorkspaceOffset = OVERRIDEWORKSPACEOFFSET ? WORKSPACE->m_renderOffset->value() : Vector2D{};
const auto previousReplyData = g_pDecorationPositioner->getDataFor(decoration, window);
const auto previousReply = previousReplyData ? previousReplyData->lastReply : SDecorationPositioningReply{};
const auto previousRounding = window->m_ruleApplicator->rounding();
const auto previousBorderSize = window->m_ruleApplicator->borderSize();
auto* const BORDERDECO = dc<CHyprBorderDecoration*>(window->presentation().decoration(DECORATION_BORDER).get());
const bool previousBorderCacheDirty = BORDERDECO && BORDERDECO->m_borderSizeCacheDirty;
const int previousCachedBorderSize = BORDERDECO ? BORDERDECO->m_cachedBorderSize : -1;
const auto scaledRounding = std::max<Config::INTEGER>(0, sc<Config::INTEGER>(std::round(window->m_ruleApplicator->rounding().valueOrDefault() * metrics.renderScale)));
const auto scaledBorderSize = std::max<Config::INTEGER>(0, sc<Config::INTEGER>(std::round(window->presentation().borderSize() * metrics.renderScale)));
window->m_ruleApplicator->rounding().set(scaledRounding, Desktop::Types::PRIORITY_SET_PROP);
window->m_ruleApplicator->borderSize().set(scaledBorderSize, Desktop::Types::PRIORITY_SET_PROP);
if (BORDERDECO)
BORDERDECO->m_borderSizeCacheDirty = true;
window->positionAnimation()->value() = monitor->m_position + windowBox.pos() / monitor->m_scale - window->presentation().floatingOffset();
window->sizeAnimation()->value() = windowBox.size() / monitor->m_scale;
const auto REPLY = getOverviewTopStickyDecorationReply(decoration, window, metrics.renderScale);
if (!REPLY) {
window->positionAnimation()->value() = previousWindowPos;
window->sizeAnimation()->value() = previousWindowSize;
ScrollOverview::Config::setValue("plugin:hyprbars:bar_text_size", previousBarTextSize);
ScrollOverview::Config::setValue("plugin:hyprbars:bar_button_padding", previousButtonPadding);
ScrollOverview::Config::setValue("plugin:hyprbars:bar_padding", previousBarPadding);
window->m_ruleApplicator->roundingOverride(previousRounding);
window->m_ruleApplicator->borderSizeOverride(previousBorderSize);
if (auto* const BORDER = dc<CHyprBorderDecoration*>(window->presentation().decoration(DECORATION_BORDER).get())) {
BORDER->m_borderSizeCacheDirty = previousBorderCacheDirty;
BORDER->m_cachedBorderSize = previousCachedBorderSize;
}
restoreOverviewHyprbarButtons(previousButtons);
return;
}
if (OVERRIDEWORKSPACEOFFSET)
WORKSPACE->m_renderOffset->value() = {};
if (previousReplyData)
previousReplyData->lastReply = *REPLY;
decoration->onPositioningReply(*REPLY);
decoration->draw(g_pHyprRenderer->context(), monitor, PARTOFWINDOW ? 1.F : metrics.targetOpacity, window->presentation().renderPresentation(dynamicPointerCast<Workspace::CWorkspacePresentable>(window->m_workspace)));
state.queuedAny = true;
state.restoreFns.emplace_back([window, decoration, WORKSPACE, OVERRIDEWORKSPACEOFFSET, previousWindowPos, previousWindowSize, previousWorkspaceOffset, previousReply,
previousReplyData, previousBarTextSize, previousButtonPadding, previousBarPadding, previousButtons,
previousRounding, previousBorderSize, previousBorderCacheDirty, previousCachedBorderSize] {
if (!window || !decoration)
return;
window->positionAnimation()->value() = previousWindowPos;
window->sizeAnimation()->value() = previousWindowSize;
if (OVERRIDEWORKSPACEOFFSET && WORKSPACE)
WORKSPACE->m_renderOffset->value() = previousWorkspaceOffset;
if (previousReplyData)
previousReplyData->lastReply = previousReply;
decoration->onPositioningReply(previousReply);
ScrollOverview::Config::setValue("plugin:hyprbars:bar_text_size", previousBarTextSize);
ScrollOverview::Config::setValue("plugin:hyprbars:bar_button_padding", previousButtonPadding);
ScrollOverview::Config::setValue("plugin:hyprbars:bar_padding", previousBarPadding);
window->m_ruleApplicator->roundingOverride(previousRounding);
window->m_ruleApplicator->borderSizeOverride(previousBorderSize);
if (auto* const BORDER = dc<CHyprBorderDecoration*>(window->presentation().decoration(DECORATION_BORDER).get())) {
BORDER->m_borderSizeCacheDirty = previousBorderCacheDirty;
BORDER->m_cachedBorderSize = previousCachedBorderSize;
}
restoreOverviewHyprbarButtons(previousButtons);
});
}
static void renderOverviewWindowShadow(PHLMONITOR monitor, const PHLWINDOW& window, const CBox& windowBox, const SOverviewWindowMetrics& metrics, bool selected) {
if (!monitor || !window || (!window->mapped() && !window->alpha().isBeingAnimated()))
return;
const auto PSHADOWS = ScrollOverview::Config::getValue<int>("decoration:shadow:enabled");
const auto PSHADOWSIZE = ScrollOverview::Config::getValue<int>("decoration:shadow:range");
const auto PSHADOWSCALE = ScrollOverview::Config::getValue<float>("decoration:shadow:scale");
const auto PSHADOWOFFSET = ScrollOverview::Config::getValue<Hyprlang::VEC2>("decoration:shadow:offset");
if (PSHADOWS != 1 || PSHADOWSIZE <= 0)
return;
if (window->backend().traits().overrideRedirect || window->backend().traits().suggestsNoBorder || !window->m_ruleApplicator->decorate().valueOrDefault() ||
window->m_ruleApplicator->noShadow().valueOrDefault())
return;
const int rangePx = sc<int>(std::round(PSHADOWSIZE * monitor->m_scale * metrics.renderScale));
const float shadowScale = std::clamp(PSHADOWSCALE, 0.F, 1.F);
const auto shadowOffset = Vector2D{PSHADOWOFFSET.x, PSHADOWOFFSET.y} * monitor->m_scale * metrics.renderScale;
if (rangePx <= 0)
return;
CBox shadowBaseBox = getOverviewOuterBorderBox(windowBox, metrics);
CBox cutoutBox = windowBox;
CBox shadowBox = shadowBaseBox.copy().expand(rangePx).scaleFromCenter(shadowScale).translate(shadowOffset);
shadowBox.round();
if (shadowBox.width < 1 || shadowBox.height < 1)
return;
auto* const SHADOWDECO = dc<CHyprDropShadowDecoration*>(window->presentation().decoration(DECORATION_SHADOW).get());
if (!SHADOWDECO)
return;
const auto shadowState = SHADOWDECO->m_gradient.renderState();
const auto& shadowColor = shadowState.current;
if (std::ranges::none_of(shadowColor.m_colors, [](const CHyprColor& color) { return color.a > 0.F; }))
return;
Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).add(makeUnique<COverviewShadowPassElement>(COverviewShadowPassElement::SData{
.monitor = monitor,
.fullBox = shadowBox,
.cutoutBox = cutoutBox.round(),
.rounding = metrics.outerRoundPx,
.roundingPower = metrics.roundingPower,
.range = rangePx,
.renderPower = ScrollOverview::Config::getValue<int>("decoration:shadow:render_power"),
.color = shadowColor,
.alpha = metrics.targetOpacity,
.ignoreWindow = true,
}));
}
static void renderOverviewWindowBorder(PHLMONITOR monitor, const PHLWINDOW& window, const CBox& windowBox, const SOverviewWindowMetrics& metrics, bool selected) {
if (!monitor || !window || (!window->mapped() && !window->alpha().isBeingAnimated()))
return;
if (metrics.borderSize <= 0.F)
return;
auto* const BORDERDECO = dc<CHyprBorderDecoration*>(window->presentation().decoration(DECORATION_BORDER).get());
if (!BORDERDECO)
return;
const auto GRADIENT = BORDERDECO->m_gradient.renderState();
auto grad = GRADIENT.current;
const CBox borderBox = getOverviewBorderBox(windowBox, metrics);
CBorderPassElement::SBorderData data;
data.box = borderBox;
data.grad1 = grad;
data.round = metrics.roundingPx;
data.outerRound = metrics.outerRoundPx;
data.roundingPower = metrics.roundingPower;
data.a = metrics.targetOpacity;
data.borderSize = metrics.borderSize;
if (GRADIENT.transitioning) {
data.hasGrad2 = true;
data.grad1 = GRADIENT.previous;
data.grad2 = grad;
data.lerp = GRADIENT.progress;
} else
data.grad1 = grad;
Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).add(makeUnique<CBorderPassElement>(data));
}
static void renderOverviewGroupTabIndicators(PHLMONITOR monitor, const PHLWINDOW& window, const CBox& windowBox, const SOverviewWindowMetrics& metrics, float alpha) {
if (!monitor || !window || !window->grouping().group() || window->grouping().group()->size() < 1)
return;
const auto PINDICATORHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_height");
const auto PINDICATORGAP = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_gap");
const auto PHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:height");
const auto PGRADIENTS = ScrollOverview::Config::getValue<bool>("group:groupbar:gradients");
const auto PRENDERTITLES = ScrollOverview::Config::getValue<bool>("group:groupbar:render_titles");
const auto PSTACKED = ScrollOverview::Config::getValue<bool>("group:groupbar:stacked");
const auto PROUNDING = ScrollOverview::Config::getValue<int>("group:groupbar:rounding");
const auto PROUNDINGPOWER = ScrollOverview::Config::getValue<float>("group:groupbar:rounding_power");
const auto POUTERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:gaps_out");
const auto PINNERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:gaps_in");
if (PINDICATORHEIGHT <= 0)
return;
const bool groupLocked = window->grouping().group()->locked() || Desktop::windowState()->groupsLocked();
const auto groupWindows = window->grouping().group()->windows();
const auto focusedWindow = Desktop::focusState()->window();
const float indicatorH = sc<float>(PINDICATORHEIGHT) * metrics.pxScale;
const float outerGap = sc<float>(POUTERGAP) * metrics.pxScale;
const float innerGap = sc<float>(PINNERGAP) * metrics.pxScale;
const float oneBarHeight = sc<float>(POUTERGAP + PINDICATORHEIGHT + PINDICATORGAP + ((PGRADIENTS || PRENDERTITLES) ? PHEIGHT : 0)) * metrics.pxScale;
const int rounding = sc<int>(std::round(PROUNDING * metrics.pxScale));
CBox indicatorArea = windowBox.copy().expand(metrics.borderPxScaled);
indicatorArea.y -= metrics.hyprbarHeightPxScaled;
auto* const GROUPCOLACTIVE = sc<Config::CGradientValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:col.active").ptr());
auto* const GROUPCOLINACTIVE = sc<Config::CGradientValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:col.inactive").ptr());
auto* const GROUPCOLACTIVELOCKED = sc<Config::CGradientValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:col.locked_active").ptr());
auto* const GROUPCOLINACTIVELOCKED = sc<Config::CGradientValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:col.locked_inactive").ptr());
const auto* const COLACTIVE = groupLocked ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE;
const auto* const COLINACTIVE = groupLocked ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE;
float xoff = 0.F;
float yoff = 0.F;
for (size_t i = 0; i < groupWindows.size(); ++i) {
const size_t windowIdx = PSTACKED ? groupWindows.size() - i - 1 : i;
const auto member = groupWindows[windowIdx].lock();
if (!member)
continue;
CHyprColor color = member == focusedWindow ? COLACTIVE->m_colors[0] : COLINACTIVE->m_colors[0];
color.a *= alpha;
if (color.a <= 0.F)
continue;
CBox box;
if (PSTACKED) {
box = {indicatorArea.x, indicatorArea.y - yoff - outerGap - indicatorH, indicatorArea.width, indicatorH};
yoff += oneBarHeight;
} else {
const float barWidth = (indicatorArea.width - innerGap * (groupWindows.size() - 1)) / groupWindows.size();
box = {indicatorArea.x + xoff, indicatorArea.y - outerGap - indicatorH, barWidth, indicatorH};
xoff += innerGap + barWidth;
}
box.round();
if (box.empty())
continue;
CRectPassElement::SRectData data;
data.box = box;
data.color = color;
data.round = rounding;
data.roundingPower = PROUNDINGPOWER;
Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).add(makeUnique<CRectPassElement>(data));
}
}
static void renderOverviewGroupTabTitles(PHLMONITOR monitor, const PHLWINDOW& window, const CBox& windowBox, const SOverviewWindowMetrics& metrics, float alpha) {
if (!monitor || !window || !window->grouping().group() || window->grouping().group()->size() < 1 || alpha <= 0.F)
return;
const auto PRENDERTITLES = ScrollOverview::Config::getValue<bool>("group:groupbar:render_titles");
const auto PTITLEFONTSIZE = ScrollOverview::Config::getValue<int>("group:groupbar:font_size");
const auto PHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:height");
const auto PINDICATORGAP = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_gap");
const auto PINDICATORHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_height");
const auto PSTACKED = ScrollOverview::Config::getValue<bool>("group:groupbar:stacked");
const auto POUTERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:gaps_out");
const auto PINNERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:gaps_in");
const auto PTEXTOFFSET = ScrollOverview::Config::getValue<int>("group:groupbar:text_offset");
const auto PTEXTPADDING = ScrollOverview::Config::getValue<int>("group:groupbar:text_padding");
const auto PTEXTCOLORACTIVE = ScrollOverview::Config::getValue<int>("group:groupbar:text_color");
const auto PTEXTCOLORINACTIVE = ScrollOverview::Config::getValue<int>("group:groupbar:text_color_inactive");
const auto PTEXTCOLORLOCKEDACTIVE = ScrollOverview::Config::getValue<int>("group:groupbar:text_color_locked_active");
const auto PTEXTCOLORLOCKEDINACTIVE = ScrollOverview::Config::getValue<int>("group:groupbar:text_color_locked_inactive");
if (!PRENDERTITLES || PHEIGHT <= 0)
return;
const bool groupLocked = window->grouping().group()->locked() || Desktop::windowState()->groupsLocked();
const auto groupWindows = window->grouping().group()->windows();
const auto focusedWindow = Desktop::focusState()->window();
const float outerGap = sc<float>(POUTERGAP) * metrics.pxScale;
const float innerGap = sc<float>(PINNERGAP) * metrics.pxScale;
const float oneBarHeight = sc<float>(POUTERGAP + PINDICATORHEIGHT + PINDICATORGAP + PHEIGHT) * metrics.pxScale;
const float titleHeight = sc<float>(PHEIGHT) * metrics.pxScale;
const float textPadding = sc<float>(PTEXTPADDING) * metrics.pxScale;
const float textOffset = sc<float>(PTEXTOFFSET) * metrics.pxScale;
const int fontSizePx = std::max(1, sc<int>(std::round(PTITLEFONTSIZE * metrics.pxScale)));
CBox titleArea = windowBox.copy().expand(metrics.borderPxScaled);
titleArea.y -= metrics.hyprbarHeightPxScaled;
const CHyprColor COLORACTIVE = CHyprColor(PTEXTCOLORACTIVE);
const CHyprColor COLORINACTIVE = PTEXTCOLORINACTIVE == -1 ? COLORACTIVE : CHyprColor(PTEXTCOLORINACTIVE);
const CHyprColor COLORLOCKEDACTIVE = PTEXTCOLORLOCKEDACTIVE == -1 ? COLORACTIVE : CHyprColor(PTEXTCOLORLOCKEDACTIVE);
const CHyprColor COLORLOCKEDINACTIVE = PTEXTCOLORLOCKEDINACTIVE == -1 ? COLORINACTIVE : CHyprColor(PTEXTCOLORLOCKEDINACTIVE);
const auto FONTWEIGHTACTIVE = sc<Config::CFontWeightConfigValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:font_weight_active").ptr());
const auto FONTWEIGHTINACTIVE = sc<Config::CFontWeightConfigValueData*>(ScrollOverview::Config::valueRef<Config::IComplexConfigValue>("group:groupbar:font_weight_inactive").ptr());
const auto TITLEFONTFAMILY = ScrollOverview::Config::getValue<std::string>("group:groupbar:font_family");
const auto FONTFAMILY = TITLEFONTFAMILY != STRVAL_EMPTY ? TITLEFONTFAMILY : ScrollOverview::Config::getValue<std::string>("misc:font_family");
float xoff = 0.F;
float yoff = 0.F;
for (size_t i = 0; i < groupWindows.size(); ++i) {
const size_t windowIdx = PSTACKED ? groupWindows.size() - i - 1 : i;
const auto member = groupWindows[windowIdx].lock();
if (!member)
continue;
const float barWidth = PSTACKED ? titleArea.width : (titleArea.width - innerGap * (groupWindows.size() - 1)) / groupWindows.size();
CBox box;
if (PSTACKED) {
box = {titleArea.x, titleArea.y - yoff - outerGap - titleHeight - sc<float>(PINDICATORHEIGHT) * metrics.pxScale - sc<float>(PINDICATORGAP) * metrics.pxScale,
titleArea.width, titleHeight};
yoff += oneBarHeight;
} else {
box = {titleArea.x + xoff, titleArea.y - outerGap - titleHeight - sc<float>(PINDICATORHEIGHT) * metrics.pxScale - sc<float>(PINDICATORGAP) * metrics.pxScale,
barWidth, titleHeight};
xoff += innerGap + barWidth;
}
box.round();
if (box.empty())
continue;
CHyprColor textColor;
const bool isCurrent = member == focusedWindow;
if (groupLocked)
textColor = isCurrent ? COLORLOCKEDACTIVE : COLORLOCKEDINACTIVE;
else
textColor = isCurrent ? COLORACTIVE : COLORINACTIVE;
textColor.a *= alpha;
if (textColor.a <= 0.F)
continue;
const int maxWidth = std::max(1, sc<int>(std::round(box.width - textPadding * 2.F)));
auto titleTex =
g_pHyprRenderer->renderText(member->metadata().title(), textColor, fontSizePx, false, FONTFAMILY, maxWidth, isCurrent ? FONTWEIGHTACTIVE->m_value : FONTWEIGHTINACTIVE->m_value);
if (!titleTex || !titleTex->ok())
continue;
CBox textBox = box;
textBox.y += std::ceil((box.height - titleTex->m_size.y) / 2.0 - textOffset);
textBox.height = titleTex->m_size.y;
textBox.width = titleTex->m_size.x;
textBox.x += std::round((box.width + textPadding) / 2.0 - (titleTex->m_size.x + textPadding) / 2.0);
textBox.round();
CTexPassElement::SRenderData data;
data.tex = titleTex;
data.box = textBox;
data.a = 1.F;
Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).add(makeUnique<CTexPassElement>(data));
}
}
static void renderOverviewGroupTabs(PHLMONITOR monitor, const PHLWINDOW& window, const CBox& windowBox, const CBox& workspaceBox,
const SOverviewWindowMetrics& metrics) {
if (!monitor || !window || !window->grouping().group() || window->grouping().group()->size() < 1)
return;
auto* const GROUPBAR = dc<CHyprGroupBarDecoration*>(window->presentation().decoration(DECORATION_GROUPBAR).get());
if (!GROUPBAR)
return;
const auto PHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:height");
const auto PINDICATORGAP = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_gap");
const auto PINDICATORHEIGHT = ScrollOverview::Config::getValue<int>("group:groupbar:indicator_height");
const auto PRENDERTITLES = ScrollOverview::Config::getValue<bool>("group:groupbar:render_titles");
const auto PGRADIENTS = ScrollOverview::Config::getValue<bool>("group:groupbar:gradients");
const auto PSTACKED = ScrollOverview::Config::getValue<bool>("group:groupbar:stacked");
const auto POUTERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:gaps_out");
const auto PKEEPUPPERGAP = ScrollOverview::Config::getValue<int>("group:groupbar:keep_upper_gap");
const auto ONEBARHEIGHT = POUTERGAP + PINDICATORHEIGHT + PINDICATORGAP + (PGRADIENTS || PRENDERTITLES ? PHEIGHT : 0);
const double DESIREDHEIGHT = sc<double>(PSTACKED ? (ONEBARHEIGHT * window->grouping().group()->size()) + POUTERGAP * PKEEPUPPERGAP : POUTERGAP * (1 + PKEEPUPPERGAP) + ONEBARHEIGHT);
const auto EDGEPOINT = g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, window);
CBox assignedBox = {window->positionAnimation()->value() - Vector2D(0.0, DESIREDHEIGHT + metrics.hyprbarTopOffsetLogical),
Vector2D(window->sizeAnimation()->value().x, DESIREDHEIGHT)};