-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoverview.cpp
More file actions
1412 lines (1168 loc) · 60 KB
/
overview.cpp
File metadata and controls
1412 lines (1168 loc) · 60 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 "overview.hpp"
#include <any>
#include <hyprland/src/event/EventBus.hpp>
#define private public
#include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/config/ConfigManager.hpp>
#include <hyprland/src/managers/animation/AnimationManager.hpp>
#include <hyprland/src/managers/animation/DesktopAnimationManager.hpp>
#include <hyprland/src/managers/input/InputManager.hpp>
#include <hyprland/src/managers/PointerManager.hpp>
#include <hyprland/src/helpers/time/Time.hpp>
#undef private
#include "OverviewPassElement.hpp"
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/config/ConfigDataValues.hpp>
#include <pango/pangocairo.h>
#include <cmath>
static bool isTransformRotated(wl_output_transform t) {
return t == WL_OUTPUT_TRANSFORM_90 || t == WL_OUTPUT_TRANSFORM_270 ||
t == WL_OUTPUT_TRANSFORM_FLIPPED_90 || t == WL_OUTPUT_TRANSFORM_FLIPPED_270;
}
struct SHyprGradientSpec {
CHyprColor c1;
CHyprColor c2;
float angleDeg = 0.f;
bool valid = false;
};
static bool parseHexRGBA8(const std::string& s, CHyprColor& out) {
// expects 8 hex digits RRGGBBAA
if (s.size() != 8)
return false;
auto hexTo = [](char c) -> int {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
return -1;
};
auto byteAt = [&](int i) -> int {
int a = hexTo(s[i]);
int b = hexTo(s[i+1]);
if (a < 0 || b < 0) return -1;
return (a << 4) | b;
};
int r = byteAt(0);
int g = byteAt(2);
int b = byteAt(4);
int a = byteAt(6);
if (r < 0 || g < 0 || b < 0 || a < 0) return false;
out = CHyprColor{r / 255.f, g / 255.f, b / 255.f, a / 255.f};
return true;
}
static SHyprGradientSpec parseGradientSpec(const std::string& inRaw) {
// Accept forms like: "rgba(33ccffee) rgba(00ff99ee) 45deg"
// Extract 8 hex digits from two rgba(...) groups and an integer angle
SHyprGradientSpec spec;
std::string s = inRaw;
// remove commas
s.erase(std::remove(s.begin(), s.end(), ','), s.end());
// find 1st rgba(XXXXXXXX)
auto p1 = s.find("rgba(");
auto p2 = s.find("rgba(", p1 == std::string::npos ? 0 : p1 + 1);
if (p1 == std::string::npos || p2 == std::string::npos)
return spec;
auto e1 = s.find(')', p1);
auto e2 = s.find(')', p2);
if (e1 == std::string::npos || e2 == std::string::npos)
return spec;
const std::string hex1 = s.substr(p1 + 5, e1 - (p1 + 5));
const std::string hex2 = s.substr(p2 + 5, e2 - (p2 + 5));
CHyprColor c1, c2;
if (!parseHexRGBA8(hex1, c1) || !parseHexRGBA8(hex2, c2))
return spec;
// find angle
float angle = 0.f;
auto pd = s.find("deg", e2);
if (pd != std::string::npos) {
// collect digits before 'deg'
size_t beg = s.rfind(' ', pd);
if (beg == std::string::npos)
beg = e2 + 1;
try {
angle = std::stof(s.substr(beg, pd - beg));
} catch (...) { angle = 0.f; }
}
spec.c1 = c1;
spec.c2 = c2;
spec.angleDeg = angle;
spec.valid = true;
return spec;
}
// Helper to detect if a border config string is a gradient or solid color
static bool isGradientBorderSpec(const std::string& borderSpec) {
if (borderSpec.empty())
return false;
// Check if it contains gradient pattern: rgba(...) rgba(...) deg
return borderSpec.find("rgba(") != std::string::npos &&
borderSpec.rfind("rgba(") != borderSpec.find("rgba(");
}
static void renderGradientBorder(const CBox& box, int borderSize, const SHyprGradientSpec& grad, int round = 0) {
if (!grad.valid || borderSize <= 0)
return;
// gradient direction
const float rad = grad.angleDeg * (float)M_PI / 180.f;
const Vector2D g{std::cos(rad), std::sin(rad)};
// compute min/max dot among corners
const Vector2D corners[4] = {{box.x, box.y}, {box.x + box.w, box.y}, {box.x, box.y + box.h}, {box.x + box.w, box.y + box.h}};
float minD = 1e9f, maxD = -1e9f;
for (auto& c : corners) {
float d = c.x * g.x + c.y * g.y;
minD = std::min(minD, d);
maxD = std::max(maxD, d);
}
const float range = std::max(1e-3f, maxD - minD);
auto mixCol = [](const CHyprColor& a, const CHyprColor& b, float t) {
t = std::clamp(t, 0.f, 1.f);
auto m = CHyprColor{a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t, a.a + (b.a - a.a) * t};
return m;
};
// choose segment counts
const int segW = std::clamp((int)std::round(box.w / 20.0), 8, 64);
const int segH = std::clamp((int)std::round(box.h / 20.0), 8, 64);
auto drawSeg = [&](const CBox& r) {
const float cx = r.x + r.w / 2.0;
const float cy = r.y + r.h / 2.0;
const float d = cx * g.x + cy * g.y;
const float t = (d - minD) / range;
g_pHyprOpenGL->renderRect(r, mixCol(grad.c1, grad.c2, t), {});
};
const double cr = std::clamp((double)round, 0.0, std::min(box.w, box.h) / 2.0);
// top and bottom bars (shrink horizontally by cr)
if (box.w > 2 * cr) {
for (int i = 0; i < segW; ++i) {
const double sx = box.x + cr + (double)i * ((box.w - 2 * cr) / segW);
const double sw = (i == segW - 1) ? (box.x + box.w - cr - sx) : ((box.w - 2 * cr) / segW);
drawSeg(CBox{sx, box.y, sw, (double)borderSize});
drawSeg(CBox{sx, box.y + box.h - borderSize, sw, (double)borderSize});
}
}
// left and right bars (shrink vertically by cr)
if (box.h > 2 * cr) {
for (int i = 0; i < segH; ++i) {
const double sy = box.y + cr + (double)i * ((box.h - 2 * cr) / segH);
const double sh = (i == segH - 1) ? (box.y + box.h - cr - sy) : ((box.h - 2 * cr) / segH);
drawSeg(CBox{box.x, sy, (double)borderSize, sh});
drawSeg(CBox{box.x + box.w - borderSize, sy, (double)borderSize, sh});
}
}
}
static void renderNumberTexture(SP<CTexture> out, const std::string& text, const CHyprColor& color, const Vector2D& bufferSize, const float scale, const int fontSize) {
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
const auto CAIRO = cairo_create(CAIROSURFACE);
cairo_save(CAIRO);
cairo_set_operator(CAIRO, CAIRO_OPERATOR_CLEAR);
cairo_paint(CAIRO);
cairo_restore(CAIRO);
PangoLayout* layout = pango_cairo_create_layout(CAIRO);
pango_layout_set_text(layout, text.c_str(), -1);
// font options from config
static auto* const PFONTFAM = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_font_family")->getDataStaticPtr();
static auto* const PFONTB = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_font_bold")->getDataStaticPtr();
static auto* const PFONTI = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_font_italic")->getDataStaticPtr();
static auto* const PTUNDER = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_text_underline")->getDataStaticPtr();
static auto* const PTSTRIKE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_text_strikethrough")->getDataStaticPtr();
PangoFontDescription* fontDesc = pango_font_description_from_string(*PFONTFAM);
pango_font_description_set_size(fontDesc, fontSize * scale * PANGO_SCALE);
pango_font_description_set_weight(fontDesc, **PFONTB ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
pango_font_description_set_style(fontDesc, **PFONTI ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
pango_layout_set_font_description(layout, fontDesc);
pango_font_description_free(fontDesc);
if (**PTUNDER || **PTSTRIKE) {
PangoAttrList* attrs = pango_attr_list_new();
if (**PTUNDER) {
pango_attr_list_insert(attrs, pango_attr_underline_new(PANGO_UNDERLINE_SINGLE));
}
if (**PTSTRIKE) {
pango_attr_list_insert(attrs, pango_attr_strikethrough_new(TRUE));
}
pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs);
}
pango_layout_set_width(layout, bufferSize.x * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
cairo_set_source_rgba(CAIRO, color.r, color.g, color.b, color.a);
PangoRectangle ink_rect, logical_rect;
pango_layout_get_extents(layout, &ink_rect, &logical_rect);
// center inside the provided buffer using ink rect (accounts for glyph bearings)
const int inkW = std::max(0, ink_rect.width / PANGO_SCALE);
const int inkH = std::max(0, ink_rect.height / PANGO_SCALE);
const int inkX = ink_rect.x / PANGO_SCALE; // can be negative
const int inkY = ink_rect.y / PANGO_SCALE; // can be negative
static auto* const* PCENTERADJX = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_center_adjust_x")->getDataStaticPtr();
static auto* const* PCENTERADJY = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:label_center_adjust_y")->getDataStaticPtr();
const double xOffset = (bufferSize.x - inkW) / 2.0 - inkX + **PCENTERADJX;
const double yOffset = (bufferSize.y - inkH) / 2.0 - inkY + **PCENTERADJY;
cairo_move_to(CAIRO, xOffset, yOffset);
pango_cairo_show_layout(CAIRO, layout);
g_object_unref(layout);
cairo_surface_flush(CAIROSURFACE);
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
out->allocate();
glBindTexture(GL_TEXTURE_2D, out->m_texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#ifndef GLES2
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferSize.x, bufferSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA);
cairo_destroy(CAIRO);
cairo_surface_destroy(CAIROSURFACE);
}
static void damageMonitor(WP<Hyprutils::Animation::CBaseAnimatedVariable> thisptr) {
g_pOverview->damage();
}
static void removeOverview(WP<Hyprutils::Animation::CBaseAnimatedVariable> thisptr) {
g_pOverview.reset();
}
// Get workspace method configuration for a specific monitor
// Returns pair of {isCenter, startWorkspaceID}
static std::pair<bool, int> getWorkspaceMethodForMonitor(PHLMONITOR monitor) {
static auto const* PMETHOD = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:workspace_method")->getDataStaticPtr();
const std::string monitorName = monitor->m_name;
const std::string configStr = std::string{*PMETHOD};
// Priority order:
// 1. hyprexpo_workspace_method keyword (backwards compatibility)
// 2. plugin:hyprexpo:workspace_method with delimiter format
std::string methodStr;
bool foundMonitorConfig = false;
// First check hyprexpo_workspace_method keyword for this monitor (backwards compatibility)
auto it = g_monitorWorkspaceMethods.find(monitorName);
if (it != g_monitorWorkspaceMethods.end()) {
methodStr = it->second;
foundMonitorConfig = true;
} else {
// Parse plugin config value with delimiter support
// Supports:
// 1. Global: "center current" or "first 1"
// 2. Per-monitor: "DP-1 first 1, HDMI-1 center current"
// 3. The parser looks for 3-token groups (monitor method workspace) vs 2-token (method workspace)
// Split by commas to get individual entries
std::vector<std::string> entries;
size_t start = 0;
while (start < configStr.size()) {
size_t commaPos = configStr.find(',', start);
if (commaPos == std::string::npos)
commaPos = configStr.size();
std::string entry = configStr.substr(start, commaPos - start);
// Trim whitespace
size_t firstNonSpace = entry.find_first_not_of(" \t");
size_t lastNonSpace = entry.find_last_not_of(" \t");
if (firstNonSpace != std::string::npos)
entry = entry.substr(firstNonSpace, lastNonSpace - firstNonSpace + 1);
if (!entry.empty())
entries.push_back(entry);
start = commaPos + 1;
}
// Try to find a monitor-specific config
std::string globalFallback;
for (const auto& entry : entries) {
CVarList tokens{entry, 0, 's', true};
if (tokens.size() == 3) {
// Format: "MONITOR method workspace"
std::string entryMonitor = std::string{tokens[0]};
if (entryMonitor == monitorName) {
// Found config for this monitor
methodStr = std::string{tokens[1]} + " " + std::string{tokens[2]};
foundMonitorConfig = true;
break;
}
} else if (tokens.size() == 2 && globalFallback.empty()) {
// Format: "method workspace" - save as global fallback
globalFallback = entry;
}
}
// If no monitor-specific config found, use global fallback or original string
if (!foundMonitorConfig) {
if (!globalFallback.empty())
methodStr = globalFallback;
else
methodStr = configStr;
}
}
// Parse the method string (format: "method workspace")
bool methodCenter = true;
int methodStartID = monitor->activeWorkspaceID();
CVarList method{methodStr, 0, 's', true};
if (method.size() >= 2) {
methodCenter = method[0] == "center";
methodStartID = getWorkspaceIDNameFromString(method[1]).id;
if (methodStartID == WORKSPACE_INVALID)
methodStartID = monitor->activeWorkspaceID();
} else if (method.size() > 0) {
Log::logger->log(Log::ERR, "[hyprexpo] invalid workspace_method for monitor {}: {}", monitorName, methodStr);
}
return {methodCenter, methodStartID};
}
COverview::~COverview() {
g_pHyprRenderer->makeEGLCurrent();
images.clear(); // otherwise we get a vram leak
g_pPointerManager->resetCursorImage();
g_pInputManager->simulateMouseMovement();
g_pHyprOpenGL->markBlurDirtyForMonitor(pMonitor.lock());
resetSubmapIfNeeded();
}
COverview::COverview(PHLWORKSPACE startedOn_, bool swipe_) : startedOn(startedOn_), swipe(swipe_) {
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
pMonitor = PMONITOR;
static auto* const* PCOLUMNS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:columns")->getDataStaticPtr();
static auto* const* PGAPS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gaps_in")->getDataStaticPtr();
static auto* const* PCOL = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:bg_col")->getDataStaticPtr();
static auto* const* PSKIP = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:skip_empty")->getDataStaticPtr();
SIDE_LENGTH = **PCOLUMNS;
GAP_WIDTH = **PGAPS;
BG_COLOR = **PCOL;
// Get workspace method for this specific monitor
auto [methodCenter, methodStartID] = getWorkspaceMethodForMonitor(pMonitor.lock());
images.resize(SIDE_LENGTH * SIDE_LENGTH);
// r includes empty workspaces; m skips over them
std::string selector = **PSKIP ? "m" : "r";
if (methodCenter) {
int currentID = methodStartID;
int firstID = currentID;
int backtracked = 0;
// Initialize tiles to WORKSPACE_INVALID; cliking one of these results
// in changing to "emptynm" (next empty workspace). Tiles with this id
// will only remain if skip_empty is on.
for (size_t i = 0; i < images.size(); i++) {
images[i].workspaceID = WORKSPACE_INVALID;
}
// Scan through workspaces lower than methodStartID until we wrap; count how many
for (size_t i = 1; i < images.size() / 2; ++i) {
currentID = getWorkspaceIDNameFromString(selector + "-" + std::to_string(i)).id;
if (currentID >= firstID)
break;
backtracked++;
firstID = currentID;
}
// Scan through workspaces higher than methodStartID. If using "m"
// (skip_empty), stop when we wrap, leaving the rest of the workspace
// ID's set to WORKSPACE_INVALID
for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
auto& image = images[i];
if ((int64_t)i - backtracked < 0) {
currentID = getWorkspaceIDNameFromString(selector + std::to_string((int64_t)i - backtracked)).id;
} else {
currentID = getWorkspaceIDNameFromString(selector + "+" + std::to_string((int64_t)i - backtracked)).id;
if (i > 0 && currentID <= firstID)
break;
}
image.workspaceID = currentID;
}
} else {
int currentID = methodStartID;
images[0].workspaceID = currentID;
auto PWORKSPACESTART = g_pCompositor->getWorkspaceByID(currentID);
if (!PWORKSPACESTART)
PWORKSPACESTART = CWorkspace::create(currentID, pMonitor.lock(), std::to_string(currentID));
pMonitor->m_activeWorkspace = PWORKSPACESTART;
// Scan through workspaces higher than methodStartID. If using "m"
// (skip_empty), stop when we wrap, leaving the rest of the workspace
// ID's set to WORKSPACE_INVALID
for (size_t i = 1; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
auto& image = images[i];
currentID = getWorkspaceIDNameFromString(selector + "+" + std::to_string(i)).id;
if (currentID <= methodStartID)
break;
image.workspaceID = currentID;
}
pMonitor->m_activeWorkspace = startedOn;
}
g_pHyprRenderer->makeEGLCurrent();
Vector2D tileSize = pMonitor->m_size / SIDE_LENGTH;
Vector2D tileRenderSize = (pMonitor->m_size - Vector2D{GAP_WIDTH * pMonitor->m_scale, GAP_WIDTH * pMonitor->m_scale} * (SIDE_LENGTH - 1)) / SIDE_LENGTH;
CBox monbox{0, 0, tileSize.x * 2, tileSize.y * 2};
if (!ENABLE_LOWRES)
monbox = {{0, 0}, pMonitor->m_pixelSize};
int currentid = 0;
// Temporarily disable monitor rotation during framebuffer capture so
// workspace content renders in the logical (portrait) orientation
// rather than the physical panel orientation.
const auto savedTransform = pMonitor->m_transform;
const auto savedTransformedSize = pMonitor->m_transformedSize;
const auto savedPixelSize = pMonitor->m_pixelSize;
// Fix for rotated monitors: m_pixelSize contains physical panel dimensions
// (landscape), but we need logical portrait dimensions for the framebuffer
if (isTransformRotated(savedTransform)) {
// Swap monbox dimensions to match logical orientation
monbox = {{0, 0}, {monbox.h, monbox.w}};
// Override monitor state: disable rotation and set all size fields to
// portrait dimensions so beginRender sets up the viewport correctly
pMonitor->m_transform = WL_OUTPUT_TRANSFORM_NORMAL;
pMonitor->m_pixelSize = {monbox.w, monbox.h};
pMonitor->m_transformedSize = {monbox.w, monbox.h};
}
PHLWORKSPACE openSpecial = PMONITOR->m_activeSpecialWorkspace;
if (openSpecial)
PMONITOR->m_activeSpecialWorkspace.reset();
g_pHyprRenderer->m_bBlockSurfaceFeedback = true;
startedOn->m_visible = false;
for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
COverview::SWorkspaceImage& image = images[i];
image.fb.alloc(monbox.w, monbox.h, PMONITOR->m_output->state->state().drmFormat);
CRegion fakeDamage{0, 0, INT16_MAX, INT16_MAX};
g_pHyprRenderer->beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &image.fb, true);
g_pHyprOpenGL->clear(CHyprColor{0, 0, 0, 1.0});
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(image.workspaceID);
if (PWORKSPACE == startedOn)
currentid = i;
if (PWORKSPACE) {
image.pWorkspace = PWORKSPACE;
PMONITOR->m_activeWorkspace = PWORKSPACE;
g_pDesktopAnimationManager->startAnimation(PWORKSPACE, CDesktopAnimationManager::ANIMATION_TYPE_IN, true, true);
PWORKSPACE->m_visible = true;
if (PWORKSPACE == startedOn)
PMONITOR->m_activeSpecialWorkspace = openSpecial;
g_pHyprRenderer->renderWorkspace(PMONITOR, PWORKSPACE, Time::steadyNow(), monbox);
PWORKSPACE->m_visible = false;
g_pDesktopAnimationManager->startAnimation(PWORKSPACE, CDesktopAnimationManager::ANIMATION_TYPE_OUT, false, true);
if (PWORKSPACE == startedOn)
PMONITOR->m_activeSpecialWorkspace.reset();
} else
g_pHyprRenderer->renderWorkspace(PMONITOR, PWORKSPACE, Time::steadyNow(), monbox);
image.box = {(i % SIDE_LENGTH) * tileRenderSize.x + (i % SIDE_LENGTH) * GAP_WIDTH, (i / SIDE_LENGTH) * tileRenderSize.y + (i / SIDE_LENGTH) * GAP_WIDTH, tileRenderSize.x,
tileRenderSize.y};
g_pHyprOpenGL->m_renderData.blockScreenShader = true;
g_pHyprRenderer->endRender();
}
g_pHyprRenderer->m_bBlockSurfaceFeedback = false;
// Restore the original monitor state after capture
pMonitor->m_transform = savedTransform;
pMonitor->m_pixelSize = savedPixelSize;
pMonitor->m_transformedSize = savedTransformedSize;
PMONITOR->m_activeSpecialWorkspace = openSpecial;
PMONITOR->m_activeWorkspace = startedOn;
startedOn->m_visible = true;
g_pDesktopAnimationManager->startAnimation(startedOn, CDesktopAnimationManager::ANIMATION_TYPE_IN, true, true);
// zoom on the current workspace.
// const auto& TILE = images[std::clamp(currentid, 0, SIDE_LENGTH * SIDE_LENGTH)];
g_pAnimationManager->createAnimation(pMonitor->m_size * pMonitor->m_size / tileSize, size, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), AVARDAMAGE_NONE);
g_pAnimationManager->createAnimation((-((pMonitor->m_size / (double)SIDE_LENGTH) * Vector2D{currentid % SIDE_LENGTH, currentid / SIDE_LENGTH}) * pMonitor->m_scale) *
(pMonitor->m_size / tileSize),
pos, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), AVARDAMAGE_NONE);
size->setUpdateCallback(damageMonitor);
pos->setUpdateCallback(damageMonitor);
if (!swipe) {
*size = pMonitor->m_size;
*pos = {0, 0};
size->setCallbackOnEnd([this](auto) { redrawAll(true); });
}
openedID = currentid;
g_pPointerManager->resetCursorImage();
lastMousePosLocal = g_pInputManager->getMouseCoordsInternal() - pMonitor->m_position;
// Initialize hoveredID based on current mouse position
int hx = std::clamp((int)(lastMousePosLocal.x / pMonitor->m_size.x * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
int hy = std::clamp((int)(lastMousePosLocal.y / pMonitor->m_size.y * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
hoveredID = hx + hy * SIDE_LENGTH;
mouseMoveHook = Event::bus()->m_events.input.mouse.move.listen([this](const Vector2D& coords, Event::SCallbackInfo& info) {
if (closing)
return;
info.cancelled = true;
lastMousePosLocal = g_pInputManager->getMouseCoordsInternal() - pMonitor->m_position;
// Update hovered tile
int hx = std::clamp((int)(lastMousePosLocal.x / pMonitor->m_size.x * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
int hy = std::clamp((int)(lastMousePosLocal.y / pMonitor->m_size.y * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
int newHoveredID = hx + hy * SIDE_LENGTH;
if (newHoveredID != hoveredID) {
hoveredID = newHoveredID;
damage();
}
});
touchMoveHook = Event::bus()->m_events.input.touch.motion.listen([this](const ITouch::SMotionEvent& e, Event::SCallbackInfo& info) {
if (closing)
return;
info.cancelled = true;
lastMousePosLocal = g_pInputManager->getMouseCoordsInternal() - pMonitor->m_position;
int hx = std::clamp((int)(lastMousePosLocal.x / pMonitor->m_size.x * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
int hy = std::clamp((int)(lastMousePosLocal.y / pMonitor->m_size.y * SIDE_LENGTH), 0, SIDE_LENGTH - 1);
int newHoveredID = hx + hy * SIDE_LENGTH;
if (newHoveredID != hoveredID) {
hoveredID = newHoveredID;
damage();
}
});
mouseButtonHook = Event::bus()->m_events.input.mouse.button.listen([this](const IPointer::SButtonEvent& e, Event::SCallbackInfo& info) {
if (closing)
return;
info.cancelled = true;
selectHoveredWorkspace();
close();
});
touchDownHook = Event::bus()->m_events.input.touch.down.listen([this](const ITouch::SDownEvent& e, Event::SCallbackInfo& info) {
if (closing)
return;
info.cancelled = true;
selectHoveredWorkspace();
close();
});
enterSubmapIfEnabled();
}
void COverview::selectHoveredWorkspace() {
if (closing)
return;
// get tile x,y
int x = lastMousePosLocal.x / pMonitor->m_size.x * SIDE_LENGTH;
int y = lastMousePosLocal.y / pMonitor->m_size.y * SIDE_LENGTH;
closeOnID = x + y * SIDE_LENGTH;
}
void COverview::ensureKbFocusInitialized() {
if (kbFocusID != -1)
return;
// try to set to current openedID
if (openedID != -1) {
kbFocusID = openedID;
return;
}
// fallback: first valid tile
for (size_t i = 0; i < images.size(); ++i) {
if (isTileValid(i)) {
kbFocusID = i;
return;
}
}
}
bool COverview::isTileValid(int id) const {
if (id < 0 || id >= SIDE_LENGTH * SIDE_LENGTH)
return false;
return images[id].workspaceID != WORKSPACE_INVALID;
}
int COverview::tileForWorkspaceID(int wsid) const {
for (size_t i = 0; i < images.size(); ++i) {
if (images[i].workspaceID == wsid)
return (int)i;
}
return -1;
}
int COverview::tileForVisibleIndex(int vIdx) const {
if (vIdx < 0)
return -1;
int seen = 0;
for (size_t i = 0; i < images.size(); ++i) {
if (images[i].workspaceID == WORKSPACE_INVALID)
continue;
if (seen == vIdx)
return (int)i;
++seen;
}
return -1;
}
void COverview::moveFocus(int dx, int dy) {
ensureKbFocusInitialized();
if (kbFocusID == -1)
return;
int x = kbFocusID % SIDE_LENGTH;
int y = kbFocusID / SIDE_LENGTH;
static auto* const* PWRAPH = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:keynav_wrap_h")->getDataStaticPtr();
static auto* const* PWRAPV = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:keynav_wrap_v")->getDataStaticPtr();
if (dx != 0) {
static auto* const* PREADING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:keynav_reading_order")->getDataStaticPtr();
int step = dx > 0 ? 1 : -1;
if (**PREADING) {
// reading-order scan: proceed linearly across the grid (row-major)
const int total = SIDE_LENGTH * SIDE_LENGTH;
int idx = kbFocusID;
for (int tries = 0; tries < total; ++tries) {
idx += step;
if (idx < 0 || idx >= total) {
// wrap only if both wraps are enabled (edge of grid)
if (**PWRAPH && **PWRAPV)
idx = (idx + total) % total;
else
break;
}
if (isTileValid(idx)) {
kbFocusID = idx;
return;
}
}
} else {
// in-row scan with optional horizontal wrap
int nx = x;
for (int tries = 0; tries < SIDE_LENGTH; ++tries) {
nx += step;
if (nx < 0 || nx >= SIDE_LENGTH) {
if (**PWRAPH)
nx = (nx + SIDE_LENGTH) % SIDE_LENGTH;
else
break;
}
const int nid = nx + y * SIDE_LENGTH;
if (isTileValid(nid)) {
kbFocusID = nid;
return;
}
}
}
}
if (dy != 0) {
int step = dy > 0 ? 1 : -1;
int ny = y;
for (int tries = 0; tries < SIDE_LENGTH; ++tries) {
ny += step;
if (ny < 0 || ny >= SIDE_LENGTH) {
if (**PWRAPV)
ny = (ny + SIDE_LENGTH) % SIDE_LENGTH;
else
break;
}
const int nid = x + ny * SIDE_LENGTH;
if (isTileValid(nid)) {
kbFocusID = nid;
return;
}
}
}
}
void COverview::onKbMoveFocus(const std::string& dir) {
if (closing)
return;
if (dir == "left")
moveFocus(-1, 0);
else if (dir == "right")
moveFocus(1, 0);
else if (dir == "up")
moveFocus(0, -1);
else if (dir == "down")
moveFocus(0, 1);
damage();
}
void COverview::onKbConfirm() {
if (closing)
return;
ensureKbFocusInitialized();
if (kbFocusID != -1)
closeOnID = kbFocusID;
close();
}
void COverview::onKbSelectNumber(int num) {
if (closing)
return;
if (num == 0)
num = 10;
const int tid = tileForWorkspaceID(num);
if (tid != -1) {
closeOnID = tid;
close();
}
}
void COverview::onKbSelectToken(int visibleIdx) {
if (closing)
return;
if (visibleIdx < 0)
return;
const int tid = tileForVisibleIndex(visibleIdx);
if (tid != -1) {
closeOnID = tid;
close();
}
}
void COverview::redrawID(int id, bool forcelowres) {
if (pMonitor->m_activeWorkspace != startedOn && !closing) {
// likely user changed.
onWorkspaceChange();
}
blockOverviewRendering = true;
g_pHyprRenderer->makeEGLCurrent();
id = std::clamp(id, 0, SIDE_LENGTH * SIDE_LENGTH);
Vector2D tileSize = pMonitor->m_size / SIDE_LENGTH;
Vector2D tileRenderSize = (pMonitor->m_size - Vector2D{GAP_WIDTH, GAP_WIDTH} * (SIDE_LENGTH - 1)) / SIDE_LENGTH;
CBox monbox{0, 0, tileSize.x * 2, tileSize.y * 2};
if (!forcelowres && (size->value() != pMonitor->m_size || closing))
monbox = {{0, 0}, pMonitor->m_pixelSize};
if (!ENABLE_LOWRES)
monbox = {{0, 0}, pMonitor->m_pixelSize};
const auto savedTransform = pMonitor->m_transform;
const auto savedTransformedSize = pMonitor->m_transformedSize;
const auto savedPixelSize = pMonitor->m_pixelSize;
// Fix for rotated monitors: swap dimensions to match logical orientation
if (isTransformRotated(savedTransform)) {
monbox = {{0, 0}, {monbox.h, monbox.w}};
// Override monitor state to disable rotation
pMonitor->m_transform = WL_OUTPUT_TRANSFORM_NORMAL;
pMonitor->m_pixelSize = {monbox.w, monbox.h};
pMonitor->m_transformedSize = {monbox.w, monbox.h};
}
auto& image = images[id];
if (image.fb.m_size != monbox.size()) {
image.fb.release();
image.fb.alloc(monbox.w, monbox.h, pMonitor->m_output->state->state().drmFormat);
}
CRegion fakeDamage{0, 0, INT16_MAX, INT16_MAX};
g_pHyprRenderer->beginRender(pMonitor.lock(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &image.fb, true);
g_pHyprOpenGL->clear(CHyprColor{0, 0, 0, 1.0});
const auto PWORKSPACE = image.pWorkspace;
PHLWORKSPACE openSpecial = pMonitor->m_activeSpecialWorkspace;
if (openSpecial)
pMonitor->m_activeSpecialWorkspace.reset();
startedOn->m_visible = false;
if (PWORKSPACE) {
pMonitor->m_activeWorkspace = PWORKSPACE;
g_pDesktopAnimationManager->startAnimation(PWORKSPACE, CDesktopAnimationManager::ANIMATION_TYPE_IN, true, true);
PWORKSPACE->m_visible = true;
if (PWORKSPACE == startedOn)
pMonitor->m_activeSpecialWorkspace = openSpecial;
g_pHyprRenderer->renderWorkspace(pMonitor.lock(), PWORKSPACE, Time::steadyNow(), monbox);
PWORKSPACE->m_visible = false;
g_pDesktopAnimationManager->startAnimation(PWORKSPACE, CDesktopAnimationManager::ANIMATION_TYPE_OUT, false, true);
if (PWORKSPACE == startedOn)
pMonitor->m_activeSpecialWorkspace.reset();
} else
g_pHyprRenderer->renderWorkspace(pMonitor.lock(), PWORKSPACE, Time::steadyNow(), monbox);
g_pHyprOpenGL->m_renderData.blockScreenShader = true;
g_pHyprRenderer->endRender();
// Restore the original monitor state after capture
pMonitor->m_transform = savedTransform;
pMonitor->m_pixelSize = savedPixelSize;
pMonitor->m_transformedSize = savedTransformedSize;
pMonitor->m_activeSpecialWorkspace = openSpecial;
pMonitor->m_activeWorkspace = startedOn;
startedOn->m_visible = true;
g_pDesktopAnimationManager->startAnimation(startedOn, CDesktopAnimationManager::ANIMATION_TYPE_IN, true, true);
blockOverviewRendering = false;
}
void COverview::redrawAll(bool forcelowres) {
for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
redrawID(i, forcelowres);
}
}
void COverview::damage() {
blockDamageReporting = true;
g_pHyprRenderer->damageMonitor(pMonitor.lock());
blockDamageReporting = false;
}
void COverview::onDamageReported() {
damageDirty = true;
Vector2D SIZE = size->value();
Vector2D tileSize = (SIZE / SIDE_LENGTH);
const auto GAPSIZE = (closing ? (1.0 - size->getPercent()) : size->getPercent()) * GAP_WIDTH;
static auto* const* PGAPSO = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gaps_out")->getDataStaticPtr();
const float OUTER = **PGAPSO * (closing ? (1.0 - size->getPercent()) : size->getPercent());
Vector2D tileRenderSize = (SIZE - Vector2D{GAPSIZE, GAPSIZE} * (SIDE_LENGTH - 1) - Vector2D{OUTER * 2, OUTER * 2}) / SIDE_LENGTH;
// const auto& TILE = images[std::clamp(openedID, 0, SIDE_LENGTH * SIDE_LENGTH)];
CBox texbox = CBox{OUTER + (openedID % SIDE_LENGTH) * tileRenderSize.x + (openedID % SIDE_LENGTH) * GAPSIZE,
OUTER + (openedID / SIDE_LENGTH) * tileRenderSize.y + (openedID / SIDE_LENGTH) * GAPSIZE, tileRenderSize.x, tileRenderSize.y}
.translate(pMonitor->m_position);
damage();
blockDamageReporting = true;
g_pHyprRenderer->damageBox(texbox);
blockDamageReporting = false;
g_pCompositor->scheduleFrameForMonitor(pMonitor.lock());
}
void COverview::close() {
if (closing)
return;
resetSubmapIfNeeded();
const int ID = closeOnID == -1 ? openedID : closeOnID;
const auto& TILE = images[std::clamp(ID, 0, SIDE_LENGTH * SIDE_LENGTH)];
Vector2D tileSize = (pMonitor->m_size / SIDE_LENGTH);
*size = pMonitor->m_size * pMonitor->m_size / tileSize;
*pos = (-((pMonitor->m_size / (double)SIDE_LENGTH) * Vector2D{ID % SIDE_LENGTH, ID / SIDE_LENGTH}) * pMonitor->m_scale) * (pMonitor->m_size / tileSize);
size->setCallbackOnEnd(removeOverview);
closing = true;
redrawAll();
if (TILE.workspaceID != pMonitor->activeWorkspaceID()) {
pMonitor->setSpecialWorkspace(0);
// If this tile's workspace was WORKSPACE_INVALID, move to the next
// empty workspace. This should only happen if skip_empty is on, in
// which case some tiles will be left with this ID intentionally.
const int NEWID = TILE.workspaceID == WORKSPACE_INVALID ? getWorkspaceIDNameFromString("emptynm").id : TILE.workspaceID;
const auto NEWIDWS = g_pCompositor->getWorkspaceByID(NEWID);
const auto OLDWS = pMonitor->m_activeWorkspace;
if (!NEWIDWS)
g_pKeybindManager->changeworkspace(std::to_string(NEWID));
else
g_pKeybindManager->changeworkspace(NEWIDWS->getConfigName());
g_pDesktopAnimationManager->startAnimation(pMonitor->m_activeWorkspace, CDesktopAnimationManager::ANIMATION_TYPE_IN, true, true);
g_pDesktopAnimationManager->startAnimation(OLDWS, CDesktopAnimationManager::ANIMATION_TYPE_OUT, false, true);
startedOn = pMonitor->m_activeWorkspace;
}
}
void COverview::onPreRender() {
if (damageDirty) {
damageDirty = false;
redrawID(closing ? (closeOnID == -1 ? openedID : closeOnID) : openedID);
}
}
void COverview::onWorkspaceChange() {
if (valid(startedOn))
g_pDesktopAnimationManager->startAnimation(startedOn, CDesktopAnimationManager::ANIMATION_TYPE_OUT, false, true);
else
startedOn = pMonitor->m_activeWorkspace;
for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
if (images[i].workspaceID != pMonitor->activeWorkspaceID())
continue;
openedID = i;
break;
}
closeOnID = openedID;
close();
}
void COverview::render() {
g_pHyprRenderer->m_renderPass.add(makeUnique<COverviewPassElement>());
}
void COverview::fullRender() {
const auto GAPSIZE = (closing ? (1.0 - size->getPercent()) : size->getPercent()) * GAP_WIDTH;
if (pMonitor->m_activeWorkspace != startedOn && !closing) {
// likely user changed.