Further much needed changes (renaming col.text, allowing users to change the icon colour of buttons)

This commit is contained in:
caffeine01 2024-12-10 19:50:18 +00:00
parent 0bedd0abe5
commit b10a63f0ef
4 changed files with 108 additions and 31 deletions

View file

@ -20,11 +20,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1731496216, "lastModified": 1731959031,
"narHash": "sha256-nlQrNN+tmJ+iP6Ck/czwZI0Hxz3oNvUyGkVruxJwgwA=", "narHash": "sha256-TGcvIjftziC1CjuiHCzrYDwmOoSFYIhdiKmLetzB5L0=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "aquamarine", "repo": "aquamarine",
"rev": "3b00e96f90cb0040de6d88ad99bf5f4d443f0c59", "rev": "4468981c1c50999f315baa1508f0e53c4ee70c52",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -100,11 +100,42 @@
"type": "github" "type": "github"
} }
}, },
"hyprgraphics": {
"inputs": {
"hyprutils": [
"hyprland",
"hyprutils"
],
"nixpkgs": [
"hyprland",
"nixpkgs"
],
"systems": [
"hyprland",
"systems"
]
},
"locked": {
"lastModified": 1733248371,
"narHash": "sha256-FFLJzFTyNhS7tBEEECx0B8Ye/bpmxhFVEKlECgMLc6c=",
"owner": "hyprwm",
"repo": "hyprgraphics",
"rev": "cc95e5babc6065bc3ab4cd195429a9900836ef13",
"type": "github"
},
"original": {
"owner": "hyprwm",
"repo": "hyprgraphics",
"type": "github"
}
},
"hyprland": { "hyprland": {
"inputs": { "inputs": {
"aquamarine": "aquamarine", "aquamarine": "aquamarine",
"hyprcursor": "hyprcursor", "hyprcursor": "hyprcursor",
"hyprgraphics": "hyprgraphics",
"hyprland-protocols": "hyprland-protocols", "hyprland-protocols": "hyprland-protocols",
"hyprland-qtutils": "hyprland-qtutils",
"hyprlang": "hyprlang", "hyprlang": "hyprlang",
"hyprutils": "hyprutils", "hyprutils": "hyprutils",
"hyprwayland-scanner": "hyprwayland-scanner", "hyprwayland-scanner": "hyprwayland-scanner",
@ -114,11 +145,11 @@
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1731526492, "lastModified": 1733683959,
"narHash": "sha256-tzWLCOcIxvJvxB25kC0Q371pc5wBBzbzwSlSNc4L8gw=", "narHash": "sha256-+tHGw4fimhZ9LtGUTpXV8V1EH5AWY6FC/3u5OmZ4I5A=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "Hyprland", "repo": "Hyprland",
"rev": "3fb47372b79265ebdabeeefdad10359d5b18377a", "rev": "0a27af8cd190315c1f13363ebd11e83d30455d48",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -152,6 +183,35 @@
"type": "github" "type": "github"
} }
}, },
"hyprland-qtutils": {
"inputs": {
"hyprutils": [
"hyprland",
"hyprutils"
],
"nixpkgs": [
"hyprland",
"nixpkgs"
],
"systems": [
"hyprland",
"systems"
]
},
"locked": {
"lastModified": 1733472316,
"narHash": "sha256-PvXiFLIExJEJj+goLbIuXLTN5CSDSAUsAfiYSdbbWg0=",
"owner": "hyprwm",
"repo": "hyprland-qtutils",
"rev": "969427419276c7ee170301ef1ebe0f68eb6eb2e2",
"type": "github"
},
"original": {
"owner": "hyprwm",
"repo": "hyprland-qtutils",
"type": "github"
}
},
"hyprlang": { "hyprlang": {
"inputs": { "inputs": {
"hyprutils": [ "hyprutils": [
@ -193,11 +253,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1731518387, "lastModified": 1732288281,
"narHash": "sha256-aZZw1ZvTMLkcA6udlvkA3hrCkuipoWLy8s/JNnIclxY=", "narHash": "sha256-XTU9B53IjGeJiJ7LstOhuxcRjCOFkQFl01H78sT9Lg4=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "hyprutils", "repo": "hyprutils",
"rev": "315fba5d21d87ddb756d4bebdb49f99d86b0ffe8", "rev": "b26f33cc1c8a7fd5076e19e2cce3f062dca6351c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -233,11 +293,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1731139594, "lastModified": 1733392399,
"narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", "narHash": "sha256-kEsTJTUQfQFIJOcLYFt/RvNxIK653ZkTBIs4DG+cBns=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", "rev": "d0797a04b81caeae77bcff10a9dde78bc17f5661",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -274,11 +334,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1731363552, "lastModified": 1733318908,
"narHash": "sha256-vFta1uHnD29VUY4HJOO/D6p6rxyObnf+InnSMT4jlMU=", "narHash": "sha256-SVQVsbafSM1dJ4fpgyBqLZ+Lft+jcQuMtEL3lQWx2Sk=",
"owner": "cachix", "owner": "cachix",
"repo": "git-hooks.nix", "repo": "git-hooks.nix",
"rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0", "rev": "6f4e2a2112050951a314d2733a994fbab94864c6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -343,11 +403,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1730743262, "lastModified": 1733157064,
"narHash": "sha256-iTLqj3lU8kFehPm5tXpctzkD274t/k1nwSSq3qCWXeg=", "narHash": "sha256-NetqJHAN4bbZDQADvpep+wXk2AbMZ2bN6tINz8Kpz6M=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "xdg-desktop-portal-hyprland", "repo": "xdg-desktop-portal-hyprland",
"rev": "09b23cef06fe248e61cec8862c04b9bcb62f4b6d", "rev": "fd85ef39369f95eed67fdf3f025e86916edeea2f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -350,7 +350,7 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
const int Y = currentPos.y; const int Y = currentPos.y;
const int RADIUS = static_cast<int>(std::ceil(scaledButtonSize / 2.0)); const int RADIUS = static_cast<int>(std::ceil(scaledButtonSize / 2.0));
cairo_set_source_rgba(CAIRO, button.col.r, button.col.g, button.col.b, button.col.a); cairo_set_source_rgba(CAIRO, button.bgcol.r, button.bgcol.g, button.bgcol.b, button.bgcol.a);
cairo_arc(CAIRO, X, Y + RADIUS, RADIUS, 0, 2 * M_PI); cairo_arc(CAIRO, X, Y + RADIUS, RADIUS, 0, 2 * M_PI);
cairo_fill(CAIRO); cairo_fill(CAIRO);
@ -399,9 +399,14 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float
// render icon // render icon
const Vector2D BUFSIZE = {scaledButtonSize, scaledButtonSize}; const Vector2D BUFSIZE = {scaledButtonSize, scaledButtonSize};
const bool LIGHT = button.col.r + button.col.g + button.col.b < 1; auto fgcolor = button.fgcol;
renderText(button.iconTex, button.icon, LIGHT ? CHyprColor(0xFFFFFFFF) : CHyprColor(0xFF000000), BUFSIZE, scale, button.size * 0.62); if (fgcolor == CHyprColor(0, 0, 0, 0)) {
const bool LIGHT = button.bgcol.r + button.bgcol.g + button.bgcol.b < 1;
fgcolor = LIGHT ? CHyprColor(0xFFFFFFFF) : CHyprColor(0xFF000000);
}
renderText(button.iconTex, button.icon, fgcolor, BUFSIZE, scale, button.size * 0.62);
} }
if (button.iconTex->m_iTexID == 0) if (button.iconTex->m_iTexID == 0)

View file

@ -7,7 +7,8 @@ inline HANDLE PHANDLE = nullptr;
struct SHyprButton { struct SHyprButton {
std::string cmd = ""; std::string cmd = "";
CHyprColor col = CHyprColor(0, 0, 0, 0); CHyprColor fgcol = CHyprColor(0, 0, 0, 0);
CHyprColor bgcol = CHyprColor(0, 0, 0, 0);
float size = 10; float size = 10;
std::string icon = ""; std::string icon = "";
SP<CTexture> iconTex = makeShared<CTexture>(); SP<CTexture> iconTex = makeShared<CTexture>();

View file

@ -59,10 +59,10 @@ Hyprlang::CParseResult onNewButton(const char* K, const char* V) {
Hyprlang::CParseResult result; Hyprlang::CParseResult result;
// hyprbars-button = color, size, icon, action // hyprbars-button = bgcolor, size, icon, action, fgcolor
if (vars[0].empty() || vars[1].empty()) { if (vars[0].empty() || vars[1].empty()) {
result.setError("var 1 and 2 cannot be empty"); result.setError("bgcolor and size cannot be empty");
return result; return result;
} }
@ -70,16 +70,27 @@ Hyprlang::CParseResult onNewButton(const char* K, const char* V) {
try { try {
size = std::stof(vars[1]); size = std::stof(vars[1]);
} catch (std::exception& e) { } catch (std::exception& e) {
result.setError("failed parsing var 2 as int"); result.setError("failed to parse size");
return result; return result;
} }
auto X = configStringToInt(vars[0]); auto bgcolor = configStringToInt(vars[1]);
if (!X) { auto fgcolor = configStringToInt("");
result.setError("var2 is not a valid number");
if (!bgcolor) {
result.setError("invalid bgcolor");
return result; return result;
} }
g_pGlobalState->buttons.push_back(SHyprButton{vars[3], *X, size, vars[2]});
if (vars.size() == 5) {
fgcolor = configStringToInt(vars[4]);
if (!fgcolor) {
result.setError("invalid fgcolor");
return result;
}
}
g_pGlobalState->buttons.push_back(SHyprButton{vars[3], *fgcolor, *bgcolor, size, vars[2]});
for (auto& b : g_pGlobalState->bars) { for (auto& b : g_pGlobalState->bars) {
b->m_bButtonsDirty = true; b->m_bButtonsDirty = true;
@ -108,7 +119,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_color", Hyprlang::INT{*configStringToInt("rgba(33333388)")}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_color", Hyprlang::INT{*configStringToInt("rgba(33333388)")});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_height", Hyprlang::INT{15}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_height", Hyprlang::INT{15});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:col.text", Hyprlang::INT{*configStringToInt("rgba(ffffffff)")}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_color", Hyprlang::INT{*configStringToInt("rgba(ffffffff)")});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size", Hyprlang::INT{10}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size", Hyprlang::INT{10});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled", Hyprlang::INT{1}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font", Hyprlang::STRING{"Sans"}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font", Hyprlang::STRING{"Sans"});
@ -132,7 +143,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::reloadConfig(); HyprlandAPI::reloadConfig();
HyprlandAPI::addNotification(PHANDLE, "[hyprbars] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000); /* HyprlandAPI::addNotification(PHANDLE, "[hyprbars] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000); annoying and dumb as fuck.*/
return {"hyprbars", "A plugin to add title bars to windows.", "Vaxry", "1.0"}; return {"hyprbars", "A plugin to add title bars to windows.", "Vaxry", "1.0"};
} }