e717c00603c05cb86734404a706ff43df5faa27d
- Author
- outfoxxed <outfoxxed@outfoxxed.me>
- Committer
- outfoxxed <outfoxxed@outfoxxed.me>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp
2index 7ad8334aeb95499b0cd7d95b8eba8dd1267aff1c..f6165d4e7c476786a1756127e10387eb68bde0fa 100644
3--- a/src/TabGroup.cpp
4+++ b/src/TabGroup.cpp
5@@ -6,8 +6,8 @@
6 #include <cairo/cairo.h>
7
8 Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) {
9- this->offset.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
10- this->width.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
11+ this->offset.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
12+ this->width.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
13
14 this->offset.registerVar();
15 this->width.registerVar();
16@@ -20,6 +20,77 @@ bool Hy3TabBarEntry::operator==(const Hy3Node& node) const {
17 return this->node == node;
18 }
19
20+void Hy3TabBarEntry::prepareTexture(float scale, Vector2D size) {
21+ static const auto* rounding_setting = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:rounding")->intValue;
22+ auto rounding = *rounding_setting;
23+
24+ auto width = size.x * scale;
25+ auto height = size.y * scale;
26+
27+ if (this->needs_redraw
28+ || this->texture.m_iTexID == 0
29+ || this->last_render_rounding == rounding
30+ || this->last_render_scale == scale
31+ || this->last_render_size == size
32+ || true // todo
33+ ) {
34+ this->needs_redraw = false;
35+ this->last_render_rounding = rounding;
36+ this->last_render_scale = scale;
37+ this->last_render_size = size;
38+
39+ auto cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
40+ auto cairo = cairo_create(cairo_surface);
41+
42+ // clear pixmap
43+ cairo_save(cairo);
44+ cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
45+ cairo_paint(cairo);
46+ cairo_restore(cairo);
47+
48+ // set brush
49+ if (this->focused) {
50+ cairo_set_source_rgba(cairo, 0.2, 0.7, 1.0, 1.0);
51+ } else {
52+ cairo_set_source_rgba(cairo, 0.5, 0.5, 0.5, 1.0);
53+ }
54+
55+ // outline bar shape
56+ cairo_move_to(cairo, 0, rounding);
57+ cairo_arc(cairo, rounding, rounding, rounding, -180.0 * (M_PI / 180.0), -90.0 * (M_PI / 180.0));
58+ cairo_line_to(cairo, width - rounding, 0);
59+ cairo_arc(cairo, width - rounding, rounding, rounding, -90.0 * (M_PI / 180.0), 0.0);
60+ cairo_line_to(cairo, width, height - rounding);
61+ cairo_arc(cairo, width - rounding, height - rounding, rounding, 0.0, 90.0 * (M_PI / 180.0));
62+ cairo_line_to(cairo, rounding, height);
63+ cairo_arc(cairo, rounding, height - rounding, rounding, -270.0 * (M_PI / 180.0), -180.0 * (M_PI / 180.0));
64+ cairo_close_path(cairo);
65+
66+ // draw
67+ cairo_fill(cairo);
68+
69+ auto data = cairo_image_surface_get_data(cairo_surface);
70+ this->texture.allocate();
71+
72+ glBindTexture(GL_TEXTURE_2D, this->texture.m_iTexID);
73+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
74+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
75+
76+ #ifdef GLES32
77+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
78+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
79+ #endif
80+
81+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
82+
83+ cairo_destroy(cairo);
84+ cairo_surface_destroy(cairo_surface);
85+ } else {
86+ glBindTexture(GL_TEXTURE_2D, this->texture.m_iTexID);
87+ }
88+}
89+
90+
91 Hy3TabBar::Hy3TabBar() {
92 this->vertical_pos.create(AVARTYPE_FLOAT, 1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
93 this->fade_opacity.create(AVARTYPE_FLOAT, 1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
94@@ -88,6 +159,13 @@ void Hy3TabBar::updateNodeList(std::list<Hy3Node*>& nodes) {
95 }
96 }
97
98+ // set stats from node data
99+ auto* root = *node;
100+ while (root->parent != nullptr) root = root->parent;
101+ auto* focused = root->getFocusedNode();
102+ entry->focused = focused == *node;
103+ entry->urgent = (*node)->isUrgent();
104+
105diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp
106index 399e2156e21364806a8444db75cd34bd27642735..29309993b7185764ac584baad2d146c1c7c63a03 100644
107--- a/src/TabGroup.hpp
108+++ b/src/TabGroup.hpp
109@@ -13,19 +13,26 @@ class Hy3TabBar;
110
111 struct Hy3TabBarEntry {
112 std::string window_title;
113+ bool focused = false;
114 bool urgent = false;
115+ bool needs_redraw = false;
116+ CTexture texture;
117 CAnimatedVariable offset; // offset 0, 0.0-1.0 of total bar
118 CAnimatedVariable width; // 0.0-1.0 of total bar
119 Hy3TabBar& tab_bar;
120 Hy3Node& node; // only used for comparioson. do not deref.
121+ Vector2D last_render_size;
122+ float last_render_scale = 0.0;
123+ float last_render_rounding = 0.0;
124
125 Hy3TabBarEntry(Hy3TabBar&, Hy3Node&);
126 bool operator==(const Hy3Node& node) const;
127+
128+ void prepareTexture(float scale, Vector2D size);
129 };
130
131 class Hy3TabBar {
132 public:
133- CTexture mask_texture;
134 CAnimatedVariable vertical_pos;
135 CAnimatedVariable fade_opacity;
136
137@@ -36,19 +43,13 @@ public:
138 void updateAnimations(bool warp = false);
139 void setSize(Vector2D);
140
141- // Redraw the mask texture if necessary, and bind it to GL_TEXTURE_2D
142- void prepareMask();
143-
144+ std::list<Hy3TabBarEntry> entries;
145 private:
146- bool need_mask_redraw = false;
147- int last_mask_rounding = 0;
148-
149 Hy3Node* focused_node = nullptr;
150 CAnimatedVariable focus_opacity;
151 CAnimatedVariable focus_start;
152 CAnimatedVariable focus_end;
153
154- std::list<Hy3TabBarEntry> entries;
155 Vector2D size;
156 };
157