mirror of
https://github.com/Trensa-Organization/hy3.git
synced 2025-03-16 03:03:40 +01:00
Animate focused/urgent state in tab bars
This commit is contained in:
parent
3e08002068
commit
4323e901c7
2 changed files with 44 additions and 22 deletions
|
@ -11,6 +11,22 @@
|
||||||
#include <pixman.h>
|
#include <pixman.h>
|
||||||
|
|
||||||
Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) {
|
Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) {
|
||||||
|
this->focused.create(
|
||||||
|
AVARTYPE_FLOAT,
|
||||||
|
0.0f,
|
||||||
|
g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"),
|
||||||
|
nullptr,
|
||||||
|
AVARDAMAGE_NONE
|
||||||
|
);
|
||||||
|
|
||||||
|
this->urgent.create(
|
||||||
|
AVARTYPE_FLOAT,
|
||||||
|
0.0f,
|
||||||
|
g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"),
|
||||||
|
nullptr,
|
||||||
|
AVARDAMAGE_NONE
|
||||||
|
);
|
||||||
|
|
||||||
this->offset.create(
|
this->offset.create(
|
||||||
AVARTYPE_FLOAT,
|
AVARTYPE_FLOAT,
|
||||||
-1.0f,
|
-1.0f,
|
||||||
|
@ -43,6 +59,8 @@ Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_b
|
||||||
AVARDAMAGE_NONE
|
AVARDAMAGE_NONE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this->focused.registerVar();
|
||||||
|
this->urgent.registerVar();
|
||||||
this->offset.registerVar();
|
this->offset.registerVar();
|
||||||
this->width.registerVar();
|
this->width.registerVar();
|
||||||
this->vertical_pos.registerVar();
|
this->vertical_pos.registerVar();
|
||||||
|
@ -50,6 +68,8 @@ Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_b
|
||||||
|
|
||||||
auto update_callback = [this](void*) { this->tab_bar.dirty = true; };
|
auto update_callback = [this](void*) { this->tab_bar.dirty = true; };
|
||||||
|
|
||||||
|
this->focused.setUpdateCallback(update_callback);
|
||||||
|
this->urgent.setUpdateCallback(update_callback);
|
||||||
this->offset.setUpdateCallback(update_callback);
|
this->offset.setUpdateCallback(update_callback);
|
||||||
this->width.setUpdateCallback(update_callback);
|
this->width.setUpdateCallback(update_callback);
|
||||||
this->vertical_pos.setUpdateCallback(update_callback);
|
this->vertical_pos.setUpdateCallback(update_callback);
|
||||||
|
@ -69,16 +89,14 @@ bool Hy3TabBarEntry::operator==(const Hy3TabBarEntry& entry) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hy3TabBarEntry::setFocused(bool focused) {
|
void Hy3TabBarEntry::setFocused(bool focused) {
|
||||||
if (this->focused != focused) {
|
if (this->focused.goalf() != focused) {
|
||||||
this->focused = focused;
|
this->focused = focused;
|
||||||
this->tab_bar.dirty = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hy3TabBarEntry::setUrgent(bool urgent) {
|
void Hy3TabBarEntry::setUrgent(bool urgent) {
|
||||||
if (this->urgent != urgent) {
|
if (this->urgent.goalf() != urgent) {
|
||||||
this->urgent = urgent;
|
this->urgent = urgent;
|
||||||
this->tab_bar.dirty = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +147,8 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|| this->last_render.x != box.x
|
|| this->last_render.x != box.x
|
||||||
|| this->last_render.y != box.y
|
|| this->last_render.y != box.y
|
||||||
|| this->last_render.focused != this->focused
|
|| this->last_render.focused != this->focused.fl()
|
||||||
|| this->last_render.urgent != this->urgent
|
|| this->last_render.urgent != this->urgent.fl()
|
||||||
|| this->last_render.window_title != this->window_title
|
|| this->last_render.window_title != this->window_title
|
||||||
|| this->last_render.rounding != rounding
|
|| this->last_render.rounding != rounding
|
||||||
|| this->last_render.text_font != *text_font
|
|| this->last_render.text_font != *text_font
|
||||||
|
@ -147,8 +165,8 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
|
||||||
{
|
{
|
||||||
this->last_render.x = box.x;
|
this->last_render.x = box.x;
|
||||||
this->last_render.y = box.y;
|
this->last_render.y = box.y;
|
||||||
this->last_render.focused = this->focused;
|
this->last_render.focused = this->focused.fl();
|
||||||
this->last_render.urgent = this->urgent;
|
this->last_render.urgent = this->urgent.fl();
|
||||||
this->last_render.window_title = this->window_title;
|
this->last_render.window_title = this->window_title;
|
||||||
this->last_render.rounding = rounding;
|
this->last_render.rounding = rounding;
|
||||||
this->last_render.text_font = *text_font;
|
this->last_render.text_font = *text_font;
|
||||||
|
@ -172,10 +190,12 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
|
||||||
|
|
||||||
// set brush
|
// set brush
|
||||||
CColor c;
|
CColor c;
|
||||||
if (this->focused) {
|
if (this->focused.fl() > 0.0) {
|
||||||
c = CColor(*col_active);
|
c = (CColor(*col_active) * this->focused.fl())
|
||||||
} else if (this->urgent) {
|
+ (CColor(*col_inactive) * (1.0 - this->focused.fl()));
|
||||||
c = CColor(*col_urgent);
|
} else if (this->urgent.fl() > 0.0) {
|
||||||
|
c = (CColor(*col_urgent) * this->urgent.fl())
|
||||||
|
+ (CColor(*col_inactive) * (1.0 - this->urgent.fl()));
|
||||||
} else {
|
} else {
|
||||||
c = CColor(*col_inactive);
|
c = CColor(*col_inactive);
|
||||||
}
|
}
|
||||||
|
@ -220,10 +240,12 @@ void Hy3TabBarEntry::prepareTexture(float scale, wlr_box& box) {
|
||||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||||
|
|
||||||
CColor c;
|
CColor c;
|
||||||
if (this->focused) {
|
if (this->focused.fl() > 0.0) {
|
||||||
c = CColor(*col_text_active);
|
c = (CColor(*col_text_active) * this->focused.fl())
|
||||||
} else if (this->urgent) {
|
+ (CColor(*col_text_inactive) * (1.0 - this->focused.fl()));
|
||||||
c = CColor(*col_text_urgent);
|
} else if (this->urgent.fl() > 0.0) {
|
||||||
|
c = (CColor(*col_text_urgent) * this->urgent.fl())
|
||||||
|
+ (CColor(*col_text_inactive) * (1.0 - this->urgent.fl()));
|
||||||
} else {
|
} else {
|
||||||
c = CColor(*col_text_inactive);
|
c = CColor(*col_text_inactive);
|
||||||
}
|
}
|
||||||
|
@ -611,12 +633,12 @@ void Hy3TabGroup::renderTabBar() {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& entry: this->bar.entries) {
|
for (auto& entry: this->bar.entries) {
|
||||||
if (entry.focused) continue;
|
if (entry.focused.goalf() == 1.0) continue;
|
||||||
render_entry(entry);
|
render_entry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& entry: this->bar.entries) {
|
for (auto& entry: this->bar.entries) {
|
||||||
if (!entry.focused) continue;
|
if (entry.focused.goalf() == 0.0) continue;
|
||||||
render_entry(entry);
|
render_entry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@ class Hy3TabBar;
|
||||||
|
|
||||||
struct Hy3TabBarEntry {
|
struct Hy3TabBarEntry {
|
||||||
std::string window_title;
|
std::string window_title;
|
||||||
bool focused = false;
|
|
||||||
bool urgent = false;
|
|
||||||
bool destroying = false;
|
bool destroying = false;
|
||||||
CTexture texture;
|
CTexture texture;
|
||||||
|
CAnimatedVariable focused;
|
||||||
|
CAnimatedVariable urgent;
|
||||||
CAnimatedVariable offset; // 0.0-1.0 of total bar
|
CAnimatedVariable offset; // 0.0-1.0 of total bar
|
||||||
CAnimatedVariable width; // 0.0-1.0 of total bar
|
CAnimatedVariable width; // 0.0-1.0 of total bar
|
||||||
CAnimatedVariable vertical_pos; // 0.0-1.0, user specified direction
|
CAnimatedVariable vertical_pos; // 0.0-1.0, user specified direction
|
||||||
|
@ -27,8 +27,8 @@ struct Hy3TabBarEntry {
|
||||||
int x, y;
|
int x, y;
|
||||||
float rounding = 0.0;
|
float rounding = 0.0;
|
||||||
float scale = 0.0;
|
float scale = 0.0;
|
||||||
bool focused = false;
|
float focused = 0.0;
|
||||||
bool urgent = false;
|
float urgent = 0.0;
|
||||||
std::string window_title;
|
std::string window_title;
|
||||||
|
|
||||||
std::string text_font;
|
std::string text_font;
|
||||||
|
|
Loading…
Add table
Reference in a new issue