Repository navigation
Expand file tree
/
Copy pathscrollOverview.cpp
More file actions
6121 lines (4900 loc) · 255 KB
/
Copy pathscrollOverview.cpp
File metadata and controls
6121 lines (4900 loc) · 255 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 "scrollOverview.hpp"
#include <algorithm>
#include <any>
#include <array>
#include <chrono>
#include <cstdlib>
#include <dlfcn.h>
#include <functional>
#include <limits>
#include <optional>
#include <unordered_set>
#include <linux/input-event-codes.h>
#include <state/MonitorState.hpp>
#include <state/WorkspaceState.hpp>
#include <hyprland/src/workspace/RegularWorkspace.hpp>
#include <hyprland/src/workspace/query/Query.hpp>
#define private public
#define protected public
#include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/render/SceneResources.hpp>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/managers/fullscreen/FullscreenController.hpp>
#include <hyprland/src/desktop/state/WindowState.hpp>
#include <hyprland/src/desktop/state/ViewState.hpp>
#include <hyprland/src/desktop/state/ViewHitTester.hpp>
#include <hyprland/src/desktop/state/GlobalWindowController.hpp>
#include <hyprland/src/state/MonitorState.hpp>
#include <hyprland/src/state/WorkspaceState.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/config/ConfigManager.hpp>
#include <hyprland/src/config/lua/ConfigManager.hpp>
#include <hyprland/src/config/shared/actions/ConfigActions.hpp>
#include <hyprland/src/config/shared/animation/AnimationTree.hpp>
#include <hyprland/src/config/shared/complex/ComplexDataTypes.hpp>
#include <hyprland/src/event/EventBus.hpp>
#include <hyprland/src/animation/AnimationManager.hpp>
#include <hyprland/src/ipc/s2/S2.hpp>
#include <hyprland/src/managers/input/InputManager.hpp>
#include <hyprland/src/keybinds/Manager.hpp>
#include <hyprland/src/managers/SeatManager.hpp>
#include <hyprland/src/layout/LayoutManager.hpp>
#include <hyprland/src/layout/algorithm/Algorithm.hpp>
#include <hyprland/src/layout/space/Space.hpp>
#include <hyprland/src/layout/target/Target.hpp>
#include <hyprland/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp>
#include <hyprland/src/pointer/cursor/CursorShapeOverrideController.hpp>
#include <hyprland/src/desktop/state/FocusState.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/WLSurface.hpp>
#include <hyprland/src/desktop/view/LayerSurface.hpp>
#include <hyprland/src/desktop/view/Popup.hpp>
#include <hyprland/src/protocols/LayerShell.hpp>
#include <hyprland/src/devices/IKeyboard.hpp>
#include <hyprland/src/helpers/math/Math.hpp>
#include <hyprland/src/helpers/time/Time.hpp>
#include <hyprland/src/plugins/PluginSystem.hpp>
#include <hyprland/src/render/pass/BorderPassElement.hpp>
#include <hyprland/src/render/pass/Pass.hpp>
#include <hyprland/src/render/pass/ClearPassElement.hpp>
#include <hyprland/src/render/pass/PreBlurElement.hpp>
#include <hyprland/src/render/pass/RectPassElement.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/Texture.hpp>
#include <hyprland/src/render/gl/GLTexture.hpp>
// Optional image-file backdrop (plugin:scrolloverview:wallpaper_path): load
// arbitrary image formats via gdk-pixbuf into a cairo ARGB surface.
#include <cairo/cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cstdint>
#include <vector>
#include <hyprland/src/render/decorations/CHyprGroupBarDecoration.hpp>
#include <hyprland/src/render/decorations/DecorationPositioner.hpp>
#include <hyprutils/utils/ScopeGuard.hpp>
#include <hyprutils/string/Numeric.hpp>
#undef protected
#undef private
#include "Config.hpp"
#include "DropIndicator.hpp"
#include "NativeDrag.hpp"
#include "OverviewOpen.hpp"
#include "OverviewPassElement.hpp"
#include "OverviewRender.hpp"
#include "Window.hpp"
static PHLWINDOW getOverviewFullscreenVisibilityWindow(const PHLWORKSPACE& workspace, const PHLWINDOW& fallback = {});
static constexpr const char* OVERVIEW_SUBMAP = "scrolloverview";
static constexpr auto POST_DROP_PSEUDO_FOCUS_DURATION = std::chrono::milliseconds(100);
static CScrollOverview* g_pointerGrabOverview = nullptr;
static bool g_finishingAdoptedNativeDrag = false;
static std::unordered_set<uint32_t> g_topLayerPointerButtons;
static PHLWINDOWREF g_pseudoFocusedWindow;
static Time::steady_tp g_pseudoFocusUntil = {};
static std::optional<uint32_t> g_pendingMouseAxisBindTimeMs;
bool consumeOverviewMouseAxisBind(uint32_t lastInputTimeMs) {
if (!g_pendingMouseAxisBindTimeMs)
return false;
const auto AXISTIMEMS = *g_pendingMouseAxisBindTimeMs;
g_pendingMouseAxisBindTimeMs.reset();
return static_cast<int32_t>(AXISTIMEMS - lastInputTimeMs) >= 0;
}
static bool changeOverviewWorkspace(const PHLMONITOR& monitor, const PHLWORKSPACE& workspace) {
if (!monitor || !workspace || monitor->m_activeWorkspace == workspace)
return false;
const bool FOCUSED = Desktop::focusState()->monitor() == monitor;
monitor->changeWorkspace(workspace, false, true, true);
if (!FOCUSED || monitor->m_activeWorkspace != workspace)
return true;
IPC::Socket2::sock()->postEvent({.event = "workspace", .data = workspace->displayName()});
IPC::Socket2::sock()->postEvent({.event = "workspacev2", .data = std::format("{},{}", Workspace::selector(*workspace), workspace->displayName())});
Event::bus()->m_events.workspace.active.emit(workspace);
return true;
}
static void restoreActiveWorkspaceVisibility() {
for (const auto& monitor : State::monitorState()->monitors()) {
if (!monitor)
continue;
for (const auto& workspace : {monitor->m_activeWorkspace, monitor->m_activeSpecialWorkspace}) {
if (!workspace)
continue;
workspace->setVisible(true);
workspace->m_alpha->setValueAndWarp(1.F);
workspace->m_renderOffset->setValueAndWarp(Vector2D{});
}
g_pHyprRenderer->damageMonitor(monitor);
}
}
static void releaseTopLayerPointerButtons(uint32_t timeMs) {
if (g_topLayerPointerButtons.empty())
return;
for (const auto button : g_topLayerPointerButtons)
g_pSeatManager->sendPointerButton(timeMs, button, WL_POINTER_BUTTON_STATE_RELEASED);
g_topLayerPointerButtons.clear();
g_pSeatManager->sendPointerFrame();
}
void removeOverview(IOverview* overview_) {
auto* overview = dynamic_cast<CScrollOverview*>(overview_);
if (!overview || !overview->closing || !overview->closeRemovalPending)
return;
overview->closeRemovalPending = false;
overview->scale->setCallbackOnEnd({});
if (overview->closeRemovalIdle) {
wl_event_source_remove(overview->closeRemovalIdle);
overview->closeRemovalIdle = nullptr;
}
overview->releaseInputListeners();
const auto PMONITOR = overview->pMonitor.lock();
unregisterScrollOverview(overview);
if (scrollOverviews().empty())
disableScrollOverviewHooks();
if (PMONITOR) {
PMONITOR->recheckSolitary();
g_pHyprRenderer->damageMonitor(PMONITOR);
}
}
static xkb_keysym_t getOverviewKeysym(const IKeyboard::SKeyEvent& event) {
const auto PKEYBOARD = g_pSeatManager->m_keyboard.lock();
if (!PKEYBOARD)
return XKB_KEY_NoSymbol;
xkb_state* const STATE = PKEYBOARD->m_resolveBindsBySym && PKEYBOARD->m_xkbSymState ? PKEYBOARD->m_xkbSymState : PKEYBOARD->m_xkbState;
if (!STATE)
return XKB_KEY_NoSymbol;
return xkb_state_key_get_one_sym(STATE, event.keycode + 8);
}
static bool hasOverviewSubmap() {
return Keybinds::mgr() && Keybinds::mgr()->registry().hasSubmap(OVERVIEW_SUBMAP);
}
static bool isOverviewSubmapActive() {
return Keybinds::mgr() && Keybinds::mgr()->currentSubmap() == OVERVIEW_SUBMAP;
}
static bool hasApplicableScrollKeybind(const IPointer::SAxisEvent& event) {
if (!Keybinds::mgr() || !g_pInputManager || event.source != WL_POINTER_AXIS_SOURCE_WHEEL || event.delta == 0.0)
return false;
std::string key;
if (event.axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
key = event.delta > 0 ? "mouse_down" : "mouse_up";
else if (event.axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL)
key = event.delta < 0 ? "mouse_left" : "mouse_right";
else
return false;
const auto MODS = g_pInputManager->getModsFromAllKBs();
const auto SUBMAP = Keybinds::mgr()->currentSubmap();
return std::ranges::any_of(Keybinds::mgr()->registry().binds(), [&](const auto& keybind) {
return keybind && keybind->enabled() && !Keybinds::mgr()->m_shadowed.contains(keybind) && std::ranges::contains(keybind->keyNames(), key) &&
(keybind->modifierMask() == MODS || keybind->hasFlag(Keybinds::BIND_FLAG_IGNORE_MODS)) &&
(keybind->metadata().submap == SUBMAP || keybind->hasFlag(Keybinds::BIND_FLAG_SUBMAP_UNIVERSAL));
});
}
static bool scrollKeybindIsThrottled() {
if (!Keybinds::mgr())
return false;
return Keybinds::mgr()->m_scrollTimer.getMillis() < ScrollOverview::Config::getValue<int>("binds:scroll_event_delay");
}
static bool isTopLayerFocused(PHLMONITOR monitor) {
const auto FOCUSEDSURFACE = g_pSeatManager->m_state.keyboardFocus.lock();
if (!FOCUSEDSURFACE)
return false;
const auto HLSURFACE = Desktop::View::CWLSurface::fromResource(FOCUSEDSURFACE);
if (!HLSURFACE)
return false;
const auto VIEW = HLSURFACE->view();
if (!VIEW)
return false;
auto layerOwner = Desktop::View::CLayerSurface::fromView(VIEW);
if (!layerOwner) {
const auto POPUP = Desktop::View::CPopup::fromView(VIEW);
if (POPUP) {
const auto T1OWNER = POPUP->getT1Owner();
if (T1OWNER)
layerOwner = Desktop::View::CLayerSurface::fromView(T1OWNER->view());
}
}
return layerOwner && layerOwner->m_monitor == monitor && layerOwner->m_layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP;
}
static constexpr const char* OVERVIEW_INSERT_FADE_BEZIER = "scrolloverviewWorkspaceInsertFade";
static constexpr const char* OVERVIEW_REMOVE_FADE_BEZIER = "scrolloverviewWorkspaceRemoveFade";
// Dedicated open/close zoom on `scale`: a slower open lets the cubic
// ease-in-out breathe; the close is snappier. Both speeds hardcoded (no knob).
static constexpr const char* OVERVIEW_OPEN_BEZIER = "scrolloverviewOpen";
static constexpr float OVERVIEW_OPEN_SPEED = 8.0F;
static constexpr float OVERVIEW_CLOSE_SPEED = 4.0F;
static bool isPointerOnTopLayer(PHLMONITOR monitor) {
if (!monitor)
return false;
const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal();
Vector2D surfaceCoords;
PHLLS layerSurface;
if (Desktop::viewState()->hitTest().layerSurfaceAt(MOUSECOORDS, &monitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &surfaceCoords, &layerSurface))
return true;
return !!Desktop::viewState()->hitTest().layerSurfaceAt(MOUSECOORDS, &monitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &layerSurface);
}
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 bool shouldShowPinnedFloatingOverviewWindow(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 bool surfaceTreeHasFrameCallbacks(SP<CWLSurfaceResource> surface) {
if (!surface)
return false;
bool hasCallbacks = false;
surface->breadthfirst(
[&hasCallbacks](SP<CWLSurfaceResource> child, const Vector2D&, void*) {
if (!child || child->m_current.callbacks.empty())
return;
hasCallbacks = true;
},
nullptr);
return hasCallbacks;
}
static void surfaceTreePresent(SP<CWLSurfaceResource> surface, PHLMONITOR monitor, const Time::steady_tp& now) {
if (!surface)
return;
std::pair<PHLMONITOR, Time::steady_tp> data = {monitor, now};
surface->breadthfirst([](SP<CWLSurfaceResource> child, const Vector2D&, void* data) {
if (!child)
return;
const auto [MONITOR, NOW] = *sc<std::pair<PHLMONITOR, Time::steady_tp>*>(data);
child->presentFeedback(NOW, MONITOR, false);
}, &data);
}
static bool windowHasOverviewAnimation(const PHLWINDOW& window) {
if (!window)
return false;
return window->positionAnimation()->isBeingAnimated() || window->sizeAnimation()->isBeingAnimated() || window->alpha().isBeingAnimated();
}
static bool layerHasOverviewAnimation(const PHLLS& layer) {
if (!Desktop::View::validMapped(layer))
return false;
return layer->positionAnimation()->isBeingAnimated() || layer->sizeAnimation()->isBeingAnimated() || layer->m_alpha.isBeingAnimated();
}
static Vector2D axisOffsetVector(float offset, ScrollOverview::Config::ELayout layout);
static CBox getOverviewBox(CBox box, PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset, ScrollOverview::Config::ELayout layout,
bool round = true) {
const auto MONITORSCALE = monitor->m_scale;
const auto VIEWPORT_CENTER = CBox{{}, monitor->m_size * MONITORSCALE}.middle();
box = {box.pos() * MONITORSCALE, box.size() * MONITORSCALE};
box.translate(-VIEWPORT_CENTER).scale(scale).translate(VIEWPORT_CENTER).translate(-viewOffset * scale * MONITORSCALE).translate(axisOffsetVector(offset, layout));
if (round)
box.round();
return box;
}
static CBox getOverviewGlobalBox(CBox globalBox, PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset, ScrollOverview::Config::ELayout layout,
bool round = true) {
return getOverviewBox({globalBox.pos() - monitor->m_position, globalBox.size()}, monitor, scale, viewOffset, offset, layout, round);
}
static CBox getOverviewWindowBox(const PHLWINDOW& window, PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset, ScrollOverview::Config::ELayout layout,
bool round = true, bool includeDecorations = true) {
if (!window)
return {};
auto box = window->geometricBox(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
if (includeDecorations && g_pDecorationPositioner && window->m_ruleApplicator->decorate().valueOrDefault())
box.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(window, true));
return getOverviewGlobalBox(box, monitor, scale, viewOffset, offset, layout, round);
}
static CBox getOverviewDragWindowBox(const PHLWINDOW& window, PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset, ScrollOverview::Config::ELayout layout,
bool round = true) {
if (!window)
return {};
const auto TARGET = window->layoutTarget();
if (window->grouping().group() && TARGET)
return getOverviewGlobalBox(TARGET->position(), monitor, scale, viewOffset, offset, layout, round);
return getOverviewWindowBox(window, monitor, scale, viewOffset, offset, layout, round, false);
}
static CBox expandOverviewWindowHitbox(CBox box, float scale, float monitorScale) {
const auto GAPS = ScrollOverview::Config::getCssGapData("general:gaps_in");
constexpr float GAP_MULTIPLIER = 2.F;
const float TOTALSCALE = scale * monitorScale;
box.x -= sc<float>(std::max<int64_t>(0, GAPS.m_left)) * TOTALSCALE * GAP_MULTIPLIER;
box.y -= sc<float>(std::max<int64_t>(0, GAPS.m_top)) * TOTALSCALE * GAP_MULTIPLIER;
box.width += sc<float>(std::max<int64_t>(0, GAPS.m_left) + std::max<int64_t>(0, GAPS.m_right)) * TOTALSCALE * GAP_MULTIPLIER;
box.height += sc<float>(std::max<int64_t>(0, GAPS.m_top) + std::max<int64_t>(0, GAPS.m_bottom)) * TOTALSCALE * GAP_MULTIPLIER;
return box;
}
static float overviewPointDistanceSqToBox(const Vector2D& point, const CBox& box) {
const float dx = point.x < box.x ? box.x - point.x : point.x > box.x + box.width ? point.x - (box.x + box.width) : 0.F;
const float dy = point.y < box.y ? box.y - point.y : point.y > box.y + box.height ? point.y - (box.y + box.height) : 0.F;
return dx * dx + dy * dy;
}
static Vector2D getOverviewMousePosLocal(PHLMONITOR monitor) {
if (!monitor)
return {};
return (g_pInputManager->getMouseCoordsInternal() - monitor->m_position) * monitor->m_scale;
}
static bool isOverviewPointerOnMonitor(PHLMONITOR monitor) {
const auto overview = monitor ? scrollOverviewAt(g_pInputManager->getMouseCoordsInternal()) : SP<IOverview>{};
return overview && overview->pMonitor.lock() == monitor;
}
static Vector2D axisOffsetVector(float offset, ScrollOverview::Config::ELayout layout) {
return layout == ScrollOverview::Config::ELayout::HORIZONTAL ? Vector2D{offset, 0.F} : Vector2D{0.F, offset};
}
static float axisValue(const Vector2D& vector, ScrollOverview::Config::ELayout layout) {
return layout == ScrollOverview::Config::ELayout::HORIZONTAL ? vector.x : vector.y;
}
static float axisSize(const Vector2D& size, ScrollOverview::Config::ELayout layout) {
return layout == ScrollOverview::Config::ELayout::HORIZONTAL ? size.x : size.y;
}
static CBox getOverviewWorkspaceBox(PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset, ScrollOverview::Config::ELayout layout) {
return getOverviewBox({{}, monitor->m_size}, monitor, scale, viewOffset, offset, layout);
}
static CBox getWorkspaceGlobalBox(PHLWORKSPACE workspace, PHLMONITOR fallbackMonitor) {
const auto MONITOR = workspace && workspace->m_monitor ? workspace->m_monitor.lock() : fallbackMonitor;
if (!MONITOR)
return {};
return {MONITOR->m_position, MONITOR->m_size};
}
static CBox centerBoxInWorkspace(CBox box, PHLWORKSPACE workspace, PHLMONITOR fallbackMonitor, const SBoxExtents& extents = {}) {
const auto WORKSPACEBOX = getWorkspaceGlobalBox(workspace, fallbackMonitor);
if (WORKSPACEBOX.width <= 0 || WORKSPACEBOX.height <= 0)
return box;
box.addExtents(extents);
box.x = WORKSPACEBOX.x + std::max(0.F, sc<float>(WORKSPACEBOX.width - box.width)) / 2.F;
box.y = WORKSPACEBOX.y + std::max(0.F, sc<float>(WORKSPACEBOX.height - box.height)) / 2.F;
return box.addExtents(extents * -1.0);
}
static CBox clampBoxToWorkspace(CBox box, PHLWORKSPACE workspace, PHLMONITOR fallbackMonitor, float margin = 0.F, const SBoxExtents& extents = {}) {
const auto WORKSPACEBOX = getWorkspaceGlobalBox(workspace, fallbackMonitor);
if (WORKSPACEBOX.width <= 0 || WORKSPACEBOX.height <= 0)
return box;
box.addExtents(extents);
const float CLAMPMARGIN = std::max(0.F, margin);
const float MINX = WORKSPACEBOX.x + CLAMPMARGIN;
const float MINY = WORKSPACEBOX.y + CLAMPMARGIN;
const float MAXX = WORKSPACEBOX.x + std::max(0.F, sc<float>(WORKSPACEBOX.width - box.width - 2.F * CLAMPMARGIN)) + CLAMPMARGIN;
const float MAXY = WORKSPACEBOX.y + std::max(0.F, sc<float>(WORKSPACEBOX.height - box.height - 2.F * CLAMPMARGIN)) + CLAMPMARGIN;
box.x = std::clamp(sc<float>(box.x), MINX, std::max(MINX, MAXX));
box.y = std::clamp(sc<float>(box.y), MINY, std::max(MINY, MAXY));
return box.addExtents(extents * -1.0);
}
static CBox resizedOverviewBoxFromCorner(const CBox& originalBox, const Vector2D& delta, Layout::eRectCorner corner, const Vector2D& minSizePx,
const std::optional<Vector2D>& maxSizePx) {
float left = originalBox.x;
float top = originalBox.y;
float right = originalBox.x + originalBox.width;
float bottom = originalBox.y + originalBox.height;
switch (corner) {
case Layout::CORNER_TOPLEFT:
left += delta.x;
top += delta.y;
break;
case Layout::CORNER_TOPRIGHT:
right += delta.x;
top += delta.y;
break;
case Layout::CORNER_BOTTOMLEFT:
left += delta.x;
bottom += delta.y;
break;
case Layout::CORNER_BOTTOMRIGHT:
default:
right += delta.x;
bottom += delta.y;
break;
}
float width = right - left;
float height = bottom - top;
const float minWidth = sc<float>(std::max(1.0, minSizePx.x));
const float minHeight = sc<float>(std::max(1.0, minSizePx.y));
const float maxWidth = maxSizePx ? sc<float>(std::max(sc<double>(minWidth), maxSizePx->x)) : std::numeric_limits<float>::max();
const float maxHeight = maxSizePx ? sc<float>(std::max(sc<double>(minHeight), maxSizePx->y)) : std::numeric_limits<float>::max();
width = std::clamp(width, minWidth, maxWidth);
height = std::clamp(height, minHeight, maxHeight);
switch (corner) {
case Layout::CORNER_TOPLEFT:
left = right - width;
top = bottom - height;
break;
case Layout::CORNER_TOPRIGHT:
right = left + width;
top = bottom - height;
break;
case Layout::CORNER_BOTTOMLEFT:
left = right - width;
bottom = top + height;
break;
case Layout::CORNER_BOTTOMRIGHT:
default:
right = left + width;
bottom = top + height;
break;
}
return CBox{{left, top}, {right - left, bottom - top}};
}
static CBox clampResizedOverviewBoxToWorkspace(const CBox& box, const CBox& workspaceBox, Layout::eRectCorner corner, float marginPx) {
if (workspaceBox.width <= 0 || workspaceBox.height <= 0)
return box;
const float minX = workspaceBox.x + std::max(0.F, marginPx);
const float minY = workspaceBox.y + std::max(0.F, marginPx);
const float maxX = workspaceBox.x + workspaceBox.width - std::max(0.F, marginPx);
const float maxY = workspaceBox.y + workspaceBox.height - std::max(0.F, marginPx);
float left = box.x;
float top = box.y;
float right = box.x + box.width;
float bottom = box.y + box.height;
switch (corner) {
case Layout::CORNER_TOPLEFT:
left = std::max(left, minX);
top = std::max(top, minY);
break;
case Layout::CORNER_TOPRIGHT:
right = std::min(right, maxX);
top = std::max(top, minY);
break;
case Layout::CORNER_BOTTOMLEFT:
left = std::max(left, minX);
bottom = std::min(bottom, maxY);
break;
case Layout::CORNER_BOTTOMRIGHT:
default:
right = std::min(right, maxX);
bottom = std::min(bottom, maxY);
break;
}
return CBox{{left, top}, {right - left, bottom - top}};
}
static bool overviewBoxIntersectsMonitor(const CBox& box, PHLMONITOR monitor) {
if (!monitor || box.width <= 0 || box.height <= 0)
return false;
const auto RENDERSIZE = monitor->m_size * monitor->m_scale;
return box.x < RENDERSIZE.x && box.x + box.width > 0 && box.y < RENDERSIZE.y && box.y + box.height > 0;
}
static bool overviewBoxFullyVisibleOnMonitor(const CBox& box, PHLMONITOR monitor) {
if (!monitor || box.empty())
return false;
const CBox VIEWPORT = {{}, monitor->m_size * monitor->m_scale};
return box.x >= VIEWPORT.x && box.y >= VIEWPORT.y && box.x + box.width <= VIEWPORT.x + VIEWPORT.width && box.y + box.height <= VIEWPORT.y + VIEWPORT.height;
}
static double overviewBoxIntersectionArea(const CBox& a, const CBox& b) {
const auto INTERSECTION = a.intersection(b);
return std::max(0.0, INTERSECTION.width) * std::max(0.0, INTERSECTION.height);
}
static double overviewBoxArea(const CBox& box) {
return std::max(0.0, box.width) * std::max(0.0, box.height);
}
static double overviewBoxCenterDistanceSquared(const CBox& a, const CBox& b) {
const auto ACENTER = a.middle();
const auto BCENTER = b.middle();
const auto DX = ACENTER.x - BCENTER.x;
const auto DY = ACENTER.y - BCENTER.y;
return DX * DX + DY * DY;
}
static CBox getPinnedFloatingOverviewWindowBox(PHLMONITOR monitor, const PHLWINDOW& window, float targetOverviewScale, float animationProgress, float* renderScale) {
if (!monitor || !window) {
if (renderScale)
*renderScale = 1.F;
return {};
}
const auto MONITORSCALE = monitor->m_scale;
const auto WINDOWSIZE = window->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT) * MONITORSCALE;
if (WINDOWSIZE.x <= 0 || WINDOWSIZE.y <= 0) {
if (renderScale)
*renderScale = 1.F;
return {};
}
const CBox WINDOWBOX = {(window->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT) - monitor->m_position) * MONITORSCALE, WINDOWSIZE};
const auto MONITORW = sc<float>(monitor->m_size.x * MONITORSCALE);
const auto MONITORH = sc<float>(monitor->m_size.y * MONITORSCALE);
const std::array<CBox, 4> QUADRANTS = {
CBox{0.F, 0.F, MONITORW / 2.F, MONITORH / 2.F},
CBox{MONITORW / 2.F, 0.F, MONITORW / 2.F, MONITORH / 2.F},
CBox{0.F, MONITORH / 2.F, MONITORW / 2.F, MONITORH / 2.F},
CBox{MONITORW / 2.F, MONITORH / 2.F, MONITORW / 2.F, MONITORH / 2.F},
};
size_t bestQuadrant = 0;
double bestArea = -1.0;
for (size_t i = 0; i < QUADRANTS.size(); ++i) {
const auto AREA = overviewBoxIntersectionArea(WINDOWBOX, QUADRANTS[i]);
if (AREA <= bestArea)
continue;
bestQuadrant = i;
bestArea = AREA;
}
const bool RIGHT = bestQuadrant == 1 || bestQuadrant == 3;
const bool BOTTOM = bestQuadrant == 2 || bestQuadrant == 3;
const auto FULLBOX = monitor->logicalBox();
const auto WORKBOX = monitor->logicalBoxMinusReserved();
const float RESERVEDLEFT = std::max(0.F, sc<float>(WORKBOX.x - FULLBOX.x)) * MONITORSCALE;
const float RESERVEDTOP = std::max(0.F, sc<float>(WORKBOX.y - FULLBOX.y)) * MONITORSCALE;
const float RESERVEDRIGHT = std::max(0.F, sc<float>((FULLBOX.x + FULLBOX.width) - (WORKBOX.x + WORKBOX.width))) * MONITORSCALE;
const float RESERVEDBOTTOM = std::max(0.F, sc<float>((FULLBOX.y + FULLBOX.height) - (WORKBOX.y + WORKBOX.height))) * MONITORSCALE;
const auto WORKSPACEGAP = sc<float>(ScrollOverview::Config::getWorkspaceGap(monitor)) * MONITORSCALE;
const auto RESERVEDWIDTH = RIGHT ? RESERVEDRIGHT : RESERVEDLEFT;
const auto CALCULATEDWIDTH = std::max(1.F, sc<float>((MONITORW - MONITORW * targetOverviewScale) / 2.F - 2.F * WORKSPACEGAP - RESERVEDWIDTH));
const auto CALCULATEDSCALE = CALCULATEDWIDTH / sc<float>(WINDOWSIZE.x);
const auto WINDOWRENDERSCALE = std::min(1.F, std::max(CALCULATEDSCALE, targetOverviewScale));
const auto PROGRESS = std::clamp(animationProgress, 0.F, 1.F);
const auto CURRENTRENDERSCALE = 1.F + (WINDOWRENDERSCALE - 1.F) * PROGRESS;
const auto TARGETWIDTH = sc<float>(WINDOWSIZE.x) * CURRENTRENDERSCALE;
const auto TARGETHEIGHT = sc<float>(WINDOWSIZE.y) * CURRENTRENDERSCALE;
if (renderScale)
*renderScale = CURRENTRENDERSCALE;
const float X = RIGHT ? MONITORW - TARGETWIDTH - WORKSPACEGAP - RESERVEDRIGHT : WORKSPACEGAP + RESERVEDLEFT;
const float Y = BOTTOM ? MONITORH - TARGETHEIGHT - WORKSPACEGAP - RESERVEDBOTTOM : WORKSPACEGAP + RESERVEDTOP;
CBox box = {{X, Y}, {TARGETWIDTH, TARGETHEIGHT}};
box.x = WINDOWBOX.x + (box.x - WINDOWBOX.x) * PROGRESS;
box.y = WINDOWBOX.y + (box.y - WINDOWBOX.y) * PROGRESS;
box.round();
return box;
}
static std::chrono::milliseconds getOverviewIdleFrameInterval() {
const int fps = std::clamp<int>(ScrollOverview::Config::getValue<int>("misc:render_unfocused_fps"), 1, 240);
return std::chrono::milliseconds(std::max(1, 1000 / fps));
}
static constexpr std::chrono::milliseconds OVERVIEW_WINDOW_FRAME_INTERVAL = std::chrono::milliseconds(33);
struct SOverviewShadowConfig {
bool enabled = false;
int range = 0;
int renderPower = 1;
Config::CGradientValueData color;
};
static SOverviewShadowConfig getOverviewShadowConfig(PHLMONITOR monitor) {
const auto enabled = ScrollOverview::Config::getShadowEnabled(monitor);
const auto range = ScrollOverview::Config::getShadowRange(monitor);
const auto renderPower = ScrollOverview::Config::getShadowRenderPower(monitor);
const auto color = ScrollOverview::Config::getShadowColor(monitor);
const auto globalRange = ScrollOverview::Config::getValue<int>("decoration:shadow:range");
const auto globalRenderPower = ScrollOverview::Config::getValue<int>("decoration:shadow:render_power");
const auto globalColor = ScrollOverview::Config::getValue<::Config::CGradientValueData>("decoration:shadow:color");
Config::CGradientValueData shadowColor;
if (color && !color->m_colors.empty())
shadowColor = *color;
else if (!globalColor.m_colors.empty())
shadowColor = globalColor;
return {
.enabled = !!enabled,
.range = std::max(0, range >= 0 ? range : globalRange),
.renderPower = std::clamp(renderPower >= 0 ? renderPower : globalRenderPower, 1, 4),
.color = shadowColor,
};
}
static void renderOverviewWorkspaceShadow(PHLMONITOR monitor, const CBox& workspaceBox, float overviewScale, bool cutoutCenter, float alpha = 1.F) {
if (!monitor)
return;
// Fade the card's shadow continuously between the desktop and overview,
// including when a gesture reverses before reaching either endpoint.
if (const auto targetScale = ScrollOverview::Config::getScale(monitor); targetScale < 1.F) {
const auto progress = std::clamp((1.F - overviewScale) / (1.F - targetScale), 0.F, 1.F);
alpha *= progress * progress * (3.F - 2.F * progress);
}
const auto SHADOW = getOverviewShadowConfig(monitor);
const bool HASVISIBLECOLOR = std::ranges::any_of(SHADOW.color.m_colors, [](const CHyprColor& color) { return color.a > 0.F; });
if (!SHADOW.enabled || SHADOW.range <= 0 || !HASVISIBLECOLOR || alpha <= 0.F)
return;
const int RANGE = sc<int>(std::round(SHADOW.range * monitor->m_scale * overviewScale));
if (RANGE <= 0)
return;
auto baseBox = workspaceBox.copy().round();
if (baseBox.width < 1 || baseBox.height < 1)
return;
Render::IHyprRenderer::currentPass(g_pHyprRenderer->context()).add(makeUnique<COverviewShadowPassElement>(COverviewShadowPassElement::SData{
.monitor = monitor,
.fullBox = baseBox.copy().expand(RANGE).round(),
.cutoutBox = baseBox,
.rounding = 0,
.roundingPower = 2.F,
.range = RANGE,
.renderPower = SHADOW.renderPower,
.color = SHADOW.color,
.alpha = alpha,
.ignoreWindow = cutoutCenter,
}));
}
static float getWorkspaceRenderedPitch(PHLMONITOR monitor, float scale, ScrollOverview::Config::ELayout layout) {
return (axisSize(monitor->m_size, layout) * scale + sc<float>(ScrollOverview::Config::getWorkspaceGap(monitor))) * monitor->m_scale;
}
static float getWorkspaceLogicalPitch(PHLMONITOR monitor, float scale, ScrollOverview::Config::ELayout layout) {
const auto safeScale = std::max(scale, 0.01F);
return axisSize(monitor->m_size, layout) + sc<float>(ScrollOverview::Config::getWorkspaceGap(monitor)) / safeScale;
}
static float getWindowVerticalOverlap(const PHLWINDOW& a, const PHLWINDOW& b) {
if (!a || !b)
return 0.F;
const auto APOS = a->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto ASIZE = a->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto BPOS = b->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto BSIZE = b->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const double overlap = std::min(APOS.y + ASIZE.y, BPOS.y + BSIZE.y) - std::max(APOS.y, BPOS.y);
return std::max(0.F, sc<float>(overlap));
}
static float getWindowHorizontalOverlap(const PHLWINDOW& a, const PHLWINDOW& b) {
if (!a || !b)
return 0.F;
const auto APOS = a->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto ASIZE = a->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto BPOS = b->position(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const auto BSIZE = b->size(Desktop::View::IGeometric::GEOMETRIC_CURRENT);
const double overlap = std::min(APOS.x + ASIZE.x, BPOS.x + BSIZE.x) - std::max(APOS.x, BPOS.x);
return std::max(0.F, sc<float>(overlap));
}
static bool overviewBoxesEqual(const CBox& a, const CBox& b) {
return std::abs(a.x - b.x) < 0.5 && std::abs(a.y - b.y) < 0.5 && std::abs(a.width - b.width) < 0.5 && std::abs(a.height - b.height) < 0.5;
}
static bool moveOverviewScrollingTargetToWorkspaceEdge(const SP<Layout::ITarget>& target, int side);
static bool moveOverviewScrollingTargetNextToWindow(const SP<Layout::ITarget>& target, const PHLWINDOW& anchor, const std::string& direction);
static double overviewTargetDirectionDelta(const SP<Layout::ITarget>& target, const PHLWINDOW& anchor, const std::string& direction) {
if (!target || !anchor || !anchor->layoutTarget())
return 0.0;
const auto TARGETCENTER = target->position().middle();
const auto ANCHORCENTER = anchor->layoutTarget()->position().middle();
if (direction == "l" || direction == "r")
return TARGETCENTER.x - ANCHORCENTER.x;
return TARGETCENTER.y - ANCHORCENTER.y;
}
static void moveOverviewTargetOneStep(const SP<Layout::ITarget>& target, const std::string& direction) {
if (!target || direction.empty())
return;
g_layoutManager->moveInDirection(target, direction, true);
}
static Layout::Tiled::CScrollingAlgorithm* overviewScrollingAlgorithmForTarget(const SP<Layout::ITarget>& target) {
if (!target || !target->space() || !target->space()->algorithm())
return nullptr;
return dc<Layout::Tiled::CScrollingAlgorithm*>(target->space()->algorithm()->m_tiled.get());
}
static Layout::Tiled::CScrollingAlgorithm* overviewScrollingAlgorithmForWorkspace(const PHLWORKSPACE& workspace) {
if (!workspace || !workspace->space() || !workspace->space()->algorithm())
return nullptr;
return dc<Layout::Tiled::CScrollingAlgorithm*>(workspace->space()->algorithm()->m_tiled.get());
}
static bool isWorkspaceScrolling(const PHLWORKSPACE& workspace) {
return overviewScrollingAlgorithmForWorkspace(workspace) != nullptr;
}
static Vector2D overviewScrollingCameraTranslation(Layout::Tiled::CScrollingAlgorithm* algorithm) {
if (!algorithm || !algorithm->m_scrollingData || !algorithm->m_scrollingData->controller)
return {};
const auto& CONTROLLER = algorithm->m_scrollingData->controller;
const auto TRANSLATION = CONTROLLER->isReversed() ? CONTROLLER->getOffset() : -CONTROLLER->getOffset();
return CONTROLLER->isPrimaryHorizontal() ? Vector2D{TRANSLATION, 0.F} : Vector2D{0.F, TRANSLATION};
}
static CBox getOverviewWorkspaceUsableBox(const PHLWORKSPACE& workspace, PHLMONITOR monitor, float scale, const Vector2D& viewOffset, float offset,
ScrollOverview::Config::ELayout layout) {
if (!workspace || !monitor)
return {};
if (const auto ALGO = overviewScrollingAlgorithmForWorkspace(workspace); ALGO && ALGO->m_scrollingData && ALGO->m_scrollingData->controller) {
const auto USABLE = ALGO->usableArea();
return getOverviewBox(USABLE, monitor, scale, viewOffset, offset, layout);
}
if (!workspace->space())
return getOverviewWorkspaceBox(monitor, scale, viewOffset, offset, layout);
auto USABLE = workspace->space()->workArea();
USABLE.translate(-monitor->m_position);
USABLE.w = std::max(USABLE.w, 1.0);
USABLE.h = std::max(USABLE.h, 1.0);
return getOverviewBox(USABLE, monitor, scale, viewOffset, offset, layout);
}
static double clampOverviewScrollingOffset(Layout::Tiled::CScrollingAlgorithm* algo, double offset) {
if (!algo || !algo->m_scrollingData)
return offset;
const double MAXOFFSET = std::max(0.0, algo->m_scrollingData->maxWidth() - algo->primaryViewportSize());
return std::clamp(offset, 0.0, MAXOFFSET);
}
static bool moveOverviewScrollingTargetToWorkspaceEdge(const SP<Layout::ITarget>& target, int side) {
if (!target || side == 0)
return false;
const auto ALGO = overviewScrollingAlgorithmForTarget(target);
if (!ALGO || !ALGO->m_scrollingData)
return false;
const auto TDATA = ALGO->dataFor(target);
if (!TDATA)
return false;
const auto SRC_COL = TDATA->column.lock();
if (!SRC_COL)
return false;
const auto SRC_COL_WIDTH = SRC_COL->getColumnWidth();
SRC_COL->remove(target);
const int64_t INSERT_AFTER = side < 0 ? -1 : sc<int64_t>(ALGO->m_scrollingData->columns.size()) - 1;
const auto NEW_COL = ALGO->m_scrollingData->add(INSERT_AFTER, SRC_COL_WIDTH);
NEW_COL->add(TDATA);
ALGO->m_scrollingData->centerOrFitCol(NEW_COL);
ALGO->m_scrollingData->recalculate();
ALGO->focusTargetUpdate(target);
return true;
}
static bool moveOverviewScrollingTargetNextToWindow(const SP<Layout::ITarget>& target, const PHLWINDOW& anchor, const std::string& direction) {
if (!target || !anchor || !anchor->layoutTarget() || direction.empty())
return false;
const auto ALGO = overviewScrollingAlgorithmForTarget(target);
if (!ALGO || !ALGO->m_scrollingData)
return false;
const auto TDATA = ALGO->dataFor(target);
const auto ANCHORDATA = ALGO->dataFor(anchor->layoutTarget());
if (!TDATA || !ANCHORDATA)
return false;
const auto SRC_COL = TDATA->column.lock();
const auto ANCHOR_COL = ANCHORDATA->column.lock();
if (!SRC_COL || !ANCHOR_COL)
return false;
const bool PRIMARYHORIZONTAL = ALGO->m_scrollingData->controller && ALGO->m_scrollingData->controller->isPrimaryHorizontal();
const bool MOVINGCOLUMN = PRIMARYHORIZONTAL ? direction == "l" || direction == "r" : direction == "u" || direction == "d";
const bool STACKINGCOLUMN = PRIMARYHORIZONTAL ? direction == "u" || direction == "d" : direction == "l" || direction == "r";
if (MOVINGCOLUMN) {
const auto SRC_COL_WIDTH = SRC_COL->getColumnWidth();
SRC_COL->remove(target);
const auto ANCHOR_COL_IDX = ALGO->m_scrollingData->idx(ANCHOR_COL);
if (ANCHOR_COL_IDX < 0)
return false;
const bool INSERT_BEFORE = direction == "l" || direction == "u";
const int64_t INSERT_AFTER = INSERT_BEFORE ? ANCHOR_COL_IDX - 1 : ANCHOR_COL_IDX;
const auto NEW_COL = ALGO->m_scrollingData->add(INSERT_AFTER, SRC_COL_WIDTH);
NEW_COL->add(TDATA);
ALGO->m_scrollingData->centerOrFitCol(NEW_COL);
ALGO->m_scrollingData->recalculate();
ALGO->focusTargetUpdate(target);
return true;
}
if (!STACKINGCOLUMN)
return false;
SRC_COL->remove(target);
const auto ANCHOR_IDX = ANCHOR_COL->idx(anchor->layoutTarget());
const bool INSERT_BEFORE = direction == "l" || direction == "u";
const int INSERT_AFTER = INSERT_BEFORE ? sc<int>(ANCHOR_IDX) - 1 : sc<int>(ANCHOR_IDX);
ANCHOR_COL->add(TDATA, INSERT_AFTER);
ALGO->m_scrollingData->centerOrFitCol(ANCHOR_COL);
ALGO->m_scrollingData->recalculate();
ALGO->focusTargetUpdate(target);
return true;
}
static void moveOverviewTargetNextToWindow(const SP<Layout::ITarget>& target, const PHLWINDOW& anchor, const std::string& direction) {
if (!target || !anchor || direction.empty())
return;
if (moveOverviewScrollingTargetNextToWindow(target, anchor, direction))
return;
const auto PREVFALLBACK = ScrollOverview::Config::getValue<int>("binds:window_direction_monitor_fallback");
ScrollOverview::Config::setValue("binds:window_direction_monitor_fallback", 0);
auto restoreFallback = Hyprutils::Utils::CScopeGuard([PREVFALLBACK] {
ScrollOverview::Config::setValue("binds:window_direction_monitor_fallback", PREVFALLBACK);
});
const bool WANT_NEGATIVE = direction == "l" || direction == "u";
const auto FORWARD = direction;
const auto BACKWARD = direction == "l" ? "r" : direction == "r" ? "l" : direction == "u" ? "d" : "u";
auto isDesiredSide = [&] {
const auto DELTA = overviewTargetDirectionDelta(target, anchor, direction);
return WANT_NEGATIVE ? DELTA < 0.0 : DELTA > 0.0;
};