45a97217029823f684753beedf44386d24c10d72

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

Replace tab entry logic and tab bar renderer (WIP)

Diff

This diff is truncated to protect this page.

  1diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp
  2index d40f63ac93406cfd095acc55282f97460dde909e..979444a39e9001b8633c70538fabb983350fa560 100644
  3--- a/src/TabGroup.cpp
  4+++ b/src/TabGroup.cpp
  5@@ -5,86 +5,151 @@
  6 #include <hyprland/src/Compositor.hpp>
  7 #include <cairo/cairo.h>
  8 
  9-void Hy3TabBar::updateWithGroupEntries(Hy3Node& group_node) {
 10-	if (group_node.data.type != Hy3NodeData::Group) return;
 11-	auto& group = group_node.data.as_group;
 12+Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) {
 13+	this->offset.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
 14+	this->width.create(AVARTYPE_FLOAT, -1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
 15 
 16-	auto entries_iter = this->entries.begin();
 17-	auto group_iter = group.children.begin();
 18+	this->offset.registerVar();
 19+	this->width.registerVar();
 20 
 21-	auto* root_node = &group_node;
 22-	while (root_node->parent != nullptr) root_node = root_node->parent;
 23-	Hy3Node* focused_node = root_node->getFocusedNode();
 24+	this->window_title = node.getTitle();
 25+	this->urgent = node.isUrgent();
 26+}
 27 
 28-	while (entries_iter != this->entries.end()) {
 29-		if (group_iter == group.children.end()) {
 30-			needs_redraw = true;
 31+bool Hy3TabBarEntry::operator==(const Hy3Node& node) const {
 32+	return this->node == node;
 33+}
 34 
 35-			while (entries_iter != this->entries.end()) {
 36-				entries_iter = this->entries.erase(entries_iter);
 37-			}
 38+Hy3TabBar::Hy3TabBar() {
 39+	this->vertical_pos.create(AVARTYPE_FLOAT, 20.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
 40+	this->fade_opacity.create(AVARTYPE_FLOAT, 0.0f, g_pConfigManager->getAnimationPropertyConfig("windowsMove"), nullptr, AVARDAMAGE_NONE);
 41+	this->focus_start.create(AVARTYPE_FLOAT, 0.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
 42+	this->focus_end.create(AVARTYPE_FLOAT, 1.0f, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), nullptr, AVARDAMAGE_NONE);
 43+	this->vertical_pos.registerVar();
 44+	this->fade_opacity.registerVar();
 45+	this->focus_start.registerVar();
 46+	this->focus_end.registerVar();
 47+
 48+	this->vertical_pos = 0.0;
 49+	this->fade_opacity = 1.0;
 50+}
 51 
 52-			return;
 53-		};
 54+void Hy3TabBar::focusNode(Hy3Node* node) {
 55+	this->focused_node = node;
 56 
 57-		auto& entry = *entries_iter;
 58-		auto& node = **group_iter;
 59+	if (this->focused_node == nullptr) {
 60+		this->focus_start = 0.0;
 61+		this->focus_end = 1.0;
 62+	} else {
 63+		auto entry = std::find(this->entries.begin(), this->entries.end(), *node);
 64+
 65+		if (entry != this->entries.end()) {
 66+			this->focus_start = entry->offset.goalf();
 67+			this->focus_end = entry->offset.goalf() + entry->width.goalf();
 68+		}
 69+	}
 70+}
 71 
 72-		std::string title = node.getTitle();
 73-		bool urgent = node.isUrgent();
 74-		bool focused = focused_node == &group_node
 75-		|| focused_node == &node
 76-			|| (node.data.type == Hy3NodeData::Group && node.data.as_group.hasChild(focused_node));
 77+void Hy3TabBar::updateNodeList(std::list<Hy3Node*>& nodes) {
 78+	std::list<Hy3TabBarEntry> removed_entries;
 79 
 80-		if (entry.urgent != urgent
 81-				|| entry.focused != focused
 82-				|| entry.window_title != title)
 83-			this->needs_redraw = true;
 84+	auto entry = this->entries.begin();
 85+	auto node = nodes.begin();
 86 
 87-		entry.window_title = std::move(title);
 88-		entry.urgent = urgent;
 89-		entry.focused = focused;
 90+	// move any out of order entries to removed_entries
 91+	while (node != nodes.end()) {
 92+		while (true) {
 93+			if (entry == this->entries.end()) goto exitloop;
 94+			if (*entry == **node) break;
 95+			removed_entries.splice(removed_entries.end(), this->entries, entry++);
 96+		}
 97 
 98-		entries_iter = std::next(entries_iter);
 99-		group_iter = std::next(group_iter);
100+		node = std::next(node);
101+		entry = std::next(entry);
102 	}
103 
104-	while (group_iter != group.children.end()) {
105diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp
106index 08d0de67542dceb7056895882fb1dbcabdaacd5a..eb373c4f6d6d0bca500a7828a021b8e79e3e1cd0 100644
107--- a/src/TabGroup.hpp
108+++ b/src/TabGroup.hpp
109@@ -2,9 +2,10 @@
110 
111 #include <hyprland/src/helpers/AnimatedVariable.hpp>
112 #include <hyprland/src/helpers/Vector2D.hpp>
113-#include <vector>
114+#include <list>
115 
116 class Hy3TabGroup;
117+class Hy3TabBar;
118 
119 #include "Hy3Layout.hpp"
120 #include <hyprland/src/render/Texture.hpp>
121@@ -12,25 +13,41 @@ class Hy3TabGroup;
122 struct Hy3TabBarEntry {
123 	std::string window_title;
124 	bool urgent = false;
125-	bool focused = false;
126+	CAnimatedVariable offset; // offset 0, 0.0-1.0 of total bar
127+	CAnimatedVariable width; // 0.0-1.0 of total bar
128+	Hy3TabBar& tab_bar;
129+	Hy3Node& node; // only used for comparioson. do not deref.
130+
131+	Hy3TabBarEntry(Hy3TabBar&, Hy3Node&);
132+	bool operator==(const Hy3Node& node) const;
133 };
134 
135 class Hy3TabBar {
136 public:
137-	CTexture texture;
138+	CTexture mask_texture;
139+	CAnimatedVariable vertical_pos;
140+	CAnimatedVariable fade_opacity;
141+
142+	Hy3TabBar();
143 
144-	void updateWithGroupEntries(Hy3Node&);
145-	void setPos(Vector2D);
146+	void focusNode(Hy3Node*);
147+	void updateNodeList(std::list<Hy3Node*>& nodes);
148+	void updateAnimations(bool warp = false);
149 	void setSize(Vector2D);
150 
151-	// Redraw the texture if necessary, and bind it to GL_TEXTURE_2D
152-	void prepareTexture();
153+	// Redraw the mask texture if necessary, and bind it to GL_TEXTURE_2D
154+	void prepareMask();
155+
156 private:
157-	bool needs_redraw = true;
158+	bool need_mask_redraw = false;
159+	int last_mask_rounding = 0;
160+
161+	Hy3Node* focused_node = nullptr;
162+	CAnimatedVariable focus_opacity;
163+	CAnimatedVariable focus_start;
164+	CAnimatedVariable focus_end;
165 
166-	std::vector<Hy3TabBarEntry> entries;
167-	// scaled pos/size
168-	Vector2D pos;
169+	std::list<Hy3TabBarEntry> entries;
170 	Vector2D size;
171 };
172