4323e901c727e58eaa385d6f8b5c8ff42719dc55

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

Message

Animate focused/urgent state in tab bars

Diff

This diff is truncated to protect this page.

  1diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp
  2index 0c48d48e0d9ab0d9762f7c17395652de283460bd..e2bb44949bce4e8b1839a3b62504cf0a56765af6 100644
  3--- a/src/TabGroup.cpp
  4+++ b/src/TabGroup.cpp
  5@@ -11,6 +11,22 @@
  6 #include <pixman.h>
  7 
  8 Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) {
  9+	this->focused.create(
 10+	    AVARTYPE_FLOAT,
 11+	    0.0f,
 12+	    g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"),
 13+	    nullptr,
 14+	    AVARDAMAGE_NONE
 15+	);
 16+
 17+	this->urgent.create(
 18+	    AVARTYPE_FLOAT,
 19+	    0.0f,
 20+	    g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"),
 21+	    nullptr,
 22+	    AVARDAMAGE_NONE
 23+	);
 24+
 25 	this->offset.create(
 26 	    AVARTYPE_FLOAT,
 27 	    -1.0f,
 28@@ -43,6 +59,8 @@ Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_b
 29 	    AVARDAMAGE_NONE
 30 	);
 31 
 32+	this->focused.registerVar();
 33+	this->urgent.registerVar();
 34 	this->offset.registerVar();
 35 	this->width.registerVar();
 36 	this->vertical_pos.registerVar();
 37@@ -50,6 +68,8 @@ Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_b
 38 
 39 	auto update_callback = [this](void*) { this->tab_bar.dirty = true; };
 40 
 41+	this->focused.setUpdateCallback(update_callback);
 42+	this->urgent.setUpdateCallback(update_callback);
 43 	this->offset.setUpdateCallback(update_callback);
 44 	this->width.setUpdateCallback(update_callback);
 45 	this->vertical_pos.setUpdateCallback(update_callback);
 46@@ -69,16 +89,14 @@ bool Hy3TabBarEntry::operator==(const Hy3TabBarEntry& entry) const {
 47 }
 48 
 49 void Hy3TabBarEntry::setFocused(bool focused) {
 50-	if (this->focused != focused) {
 51+	if (this->focused.goalf() != focused) {
 52 		this->focused = focused;
 53-		this->tab_bar.dirty = true;
 54 	}
 55 }
 56 
 57 void Hy3TabBarEntry::setUrgent(bool urgent) {
 58-	if (this->urgent != urgent) {
 59+	if (this->urgent.goalf() != urgent) {
 60 		this->urgent = urgent;
 61-		this->tab_bar.dirty = true;
 62 	}
 63 }
 64 
 65@@ -129,8 +147,8 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
 66 	    // clang-format off
 67 			|| this->last_render.x != box.x
 68 			|| this->last_render.y != box.y
 69-	    || this->last_render.focused != this->focused
 70-			|| this->last_render.urgent != this->urgent
 71+	    || this->last_render.focused != this->focused.fl()
 72+			|| this->last_render.urgent != this->urgent.fl()
 73 	    || this->last_render.window_title != this->window_title
 74 	    || this->last_render.rounding != rounding
 75 			|| this->last_render.text_font != *text_font
 76@@ -147,8 +165,8 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
 77 	{
 78 		this->last_render.x = box.x;
 79 		this->last_render.y = box.y;
 80-		this->last_render.focused = this->focused;
 81-		this->last_render.urgent = this->urgent;
 82+		this->last_render.focused = this->focused.fl();
 83+		this->last_render.urgent = this->urgent.fl();
 84 		this->last_render.window_title = this->window_title;
 85 		this->last_render.rounding = rounding;
 86 		this->last_render.text_font = *text_font;
 87@@ -172,10 +190,12 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
 88 
 89 		// set brush
 90 		CColor c;
 91-		if (this->focused) {
 92-			c = CColor(*col_active);
 93-		} else if (this->urgent) {
 94-			c = CColor(*col_urgent);
 95+		if (this->focused.fl() > 0.0) {
 96+			c = (CColor(*col_active) * this->focused.fl())
 97+			  + (CColor(*col_inactive) * (1.0 - this->focused.fl()));
 98+		} else if (this->urgent.fl() > 0.0) {
 99+			c = (CColor(*col_urgent) * this->urgent.fl())
100+			  + (CColor(*col_inactive) * (1.0 - this->urgent.fl()));
101 		} else {
102 			c = CColor(*col_inactive);
103 		}
104@@ -220,10 +240,12 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
105diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp
106index 5204ce54edab9b9ba3d6354d4240014ec9645a8b..90af61b751224e2fecd0a671c7675279c14c794c 100644
107--- a/src/TabGroup.hpp
108+++ b/src/TabGroup.hpp
109@@ -12,10 +12,10 @@ class Hy3TabBar;
110 
111 struct Hy3TabBarEntry {
112 	std::string window_title;
113-	bool focused = false;
114-	bool urgent = false;
115 	bool destroying = false;
116 	CTexture texture;
117+	CAnimatedVariable focused;
118+	CAnimatedVariable urgent;
119 	CAnimatedVariable offset;       // 0.0-1.0 of total bar
120 	CAnimatedVariable width;        // 0.0-1.0 of total bar
121 	CAnimatedVariable vertical_pos; // 0.0-1.0, user specified direction
122@@ -27,8 +27,8 @@ struct Hy3TabBarEntry {
123 		int x, y;
124 		float rounding = 0.0;
125 		float scale = 0.0;
126-		bool focused = false;
127-		bool urgent = false;
128+		float focused = 0.0;
129+		float urgent = 0.0;
130 		std::string window_title;
131 
132 		std::string text_font;