mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-01-26 04:19:48 +01:00
config: rename scale to progressbar and update configuration
- renamed scale widget to progressbar - updated configuration values for progressbar - modified renderer to use progressbar instead of scale
This commit is contained in:
parent
2f51092152
commit
5f78a5f795
4 changed files with 47 additions and 47 deletions
|
@ -321,21 +321,21 @@ void CConfigManager::init() {
|
||||||
m_config.addSpecialConfigValue("label", "zindex", Hyprlang::INT{0});
|
m_config.addSpecialConfigValue("label", "zindex", Hyprlang::INT{0});
|
||||||
SHADOWABLE("label");
|
SHADOWABLE("label");
|
||||||
|
|
||||||
m_config.addSpecialCategory("scale", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
m_config.addSpecialCategory("progressbar", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||||
m_config.addSpecialConfigValue("scale", "monitor", Hyprlang::STRING{""});
|
m_config.addSpecialConfigValue("progressbar", "monitor", Hyprlang::STRING{""});
|
||||||
m_config.addSpecialConfigValue("scale", "min", Hyprlang::INT{0});
|
m_config.addSpecialConfigValue("progressbar", "min", Hyprlang::INT{0});
|
||||||
m_config.addSpecialConfigValue("scale", "max", Hyprlang::INT{100});
|
m_config.addSpecialConfigValue("progressbar", "max", Hyprlang::INT{100});
|
||||||
m_config.addSpecialConfigValue("scale", "value", Hyprlang::STRING{""});
|
m_config.addSpecialConfigValue("progressbar", "value", Hyprlang::STRING{""});
|
||||||
m_config.addSpecialConfigValue("scale", "border_size", Hyprlang::INT{0});
|
m_config.addSpecialConfigValue("progressbar", "border_size", Hyprlang::INT{0});
|
||||||
m_config.addSpecialConfigValue("scale", "border_color", Hyprlang::INT{0xFF000000});
|
m_config.addSpecialConfigValue("progressbar", "border_color", Hyprlang::INT{0xFF000000});
|
||||||
m_config.addSpecialConfigValue("scale", "rounding", Hyprlang::INT{0});
|
m_config.addSpecialConfigValue("progressbar", "rounding", Hyprlang::INT{0});
|
||||||
m_config.addSpecialConfigValue("scale", "size", LAYOUTCONFIG("100,20"));
|
m_config.addSpecialConfigValue("progressbar", "size", LAYOUTCONFIG("100,20"));
|
||||||
m_config.addSpecialConfigValue("scale", "position", LAYOUTCONFIG("0,0"));
|
m_config.addSpecialConfigValue("progressbar", "position", LAYOUTCONFIG("0,0"));
|
||||||
m_config.addSpecialConfigValue("scale", "halign", Hyprlang::STRING{"center"});
|
m_config.addSpecialConfigValue("progressbar", "halign", Hyprlang::STRING{"center"});
|
||||||
m_config.addSpecialConfigValue("scale", "valign", Hyprlang::STRING{"center"});
|
m_config.addSpecialConfigValue("progressbar", "valign", Hyprlang::STRING{"center"});
|
||||||
m_config.addSpecialConfigValue("scale", "zindex", Hyprlang::INT{0});
|
m_config.addSpecialConfigValue("progressbar", "zindex", Hyprlang::INT{0});
|
||||||
m_config.addSpecialConfigValue("scale", "color", Hyprlang::INT{0xFF00FF00});
|
m_config.addSpecialConfigValue("progressbar", "color", Hyprlang::INT{0xFF00FF00});
|
||||||
m_config.addSpecialConfigValue("scale", "background_color", Hyprlang::INT{0xFF000000});
|
m_config.addSpecialConfigValue("progressbar", "background_color", Hyprlang::INT{0xFF000000});
|
||||||
|
|
||||||
m_config.registerHandler(&::handleSource, "source", {false});
|
m_config.registerHandler(&::handleSource, "source", {false});
|
||||||
m_config.registerHandler(&::handleBezier, "bezier", {false});
|
m_config.registerHandler(&::handleBezier, "bezier", {false});
|
||||||
|
@ -531,26 +531,26 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = m_config.listKeysForSpecialCategory("scale");
|
keys = m_config.listKeysForSpecialCategory("progressbar");
|
||||||
for (auto& k : keys) {
|
for (auto& k : keys) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
result.push_back(CConfigManager::SWidgetConfig{
|
result.push_back(CConfigManager::SWidgetConfig{
|
||||||
"scale",
|
"progressbar",
|
||||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("scale", "monitor", k.c_str())),
|
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("progressbar", "monitor", k.c_str())),
|
||||||
{
|
{
|
||||||
{"min", m_config.getSpecialConfigValue("scale", "min", k.c_str())},
|
{"min", m_config.getSpecialConfigValue("progressbar", "min", k.c_str())},
|
||||||
{"max", m_config.getSpecialConfigValue("scale", "max", k.c_str())},
|
{"max", m_config.getSpecialConfigValue("progressbar", "max", k.c_str())},
|
||||||
{"value", m_config.getSpecialConfigValue("scale", "value", k.c_str())},
|
{"value", m_config.getSpecialConfigValue("progressbar", "value", k.c_str())},
|
||||||
{"border_size", m_config.getSpecialConfigValue("scale", "border_size", k.c_str())},
|
{"border_size", m_config.getSpecialConfigValue("progressbar", "border_size", k.c_str())},
|
||||||
{"border_color", m_config.getSpecialConfigValue("scale", "border_color", k.c_str())},
|
{"border_color", m_config.getSpecialConfigValue("progressbar", "border_color", k.c_str())},
|
||||||
{"rounding", m_config.getSpecialConfigValue("scale", "rounding", k.c_str())},
|
{"rounding", m_config.getSpecialConfigValue("progressbar", "rounding", k.c_str())},
|
||||||
{"size", m_config.getSpecialConfigValue("scale", "size", k.c_str())},
|
{"size", m_config.getSpecialConfigValue("progressbar", "size", k.c_str())},
|
||||||
{"position", m_config.getSpecialConfigValue("scale", "position", k.c_str())},
|
{"position", m_config.getSpecialConfigValue("progressbar", "position", k.c_str())},
|
||||||
{"halign", m_config.getSpecialConfigValue("scale", "halign", k.c_str())},
|
{"halign", m_config.getSpecialConfigValue("progressbar", "halign", k.c_str())},
|
||||||
{"valign", m_config.getSpecialConfigValue("scale", "valign", k.c_str())},
|
{"valign", m_config.getSpecialConfigValue("progressbar", "valign", k.c_str())},
|
||||||
{"zindex", m_config.getSpecialConfigValue("scale", "zindex", k.c_str())},
|
{"zindex", m_config.getSpecialConfigValue("progressbar", "zindex", k.c_str())},
|
||||||
{"color", m_config.getSpecialConfigValue("scale", "color", k.c_str())},
|
{"color", m_config.getSpecialConfigValue("progressbar", "color", k.c_str())},
|
||||||
{"background_color", m_config.getSpecialConfigValue("scale", "background_color", k.c_str())},
|
{"background_color", m_config.getSpecialConfigValue("progressbar", "background_color", k.c_str())},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "widgets/Label.hpp"
|
#include "widgets/Label.hpp"
|
||||||
#include "widgets/Image.hpp"
|
#include "widgets/Image.hpp"
|
||||||
#include "widgets/Shape.hpp"
|
#include "widgets/Shape.hpp"
|
||||||
#include "widgets/Scale.hpp"
|
#include "widgets/ProgressBar.hpp"
|
||||||
|
|
||||||
inline const float fullVerts[] = {
|
inline const float fullVerts[] = {
|
||||||
1, 0, // top right
|
1, 0, // top right
|
||||||
|
@ -449,7 +449,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
|
||||||
|
|
||||||
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values));
|
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values));
|
||||||
} else if (c.type == "scale") {
|
} else if (c.type == "scale") {
|
||||||
widgets[surf].emplace_back(std::make_unique<CScale>(surf->size, c.values, surf->output->stringPort));
|
widgets[surf].emplace_back(std::make_unique<CProgressBar>(surf->size, c.values, surf->output->stringPort));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Scale.hpp"
|
#include "ProgressBar.hpp"
|
||||||
#include "../Renderer.hpp"
|
#include "../Renderer.hpp"
|
||||||
#include "../../core/AnimationManager.hpp"
|
#include "../../core/AnimationManager.hpp"
|
||||||
#include "../../helpers/Log.hpp"
|
#include "../../helpers/Log.hpp"
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#include "../../core/hyprlock.hpp"
|
#include "../../core/hyprlock.hpp"
|
||||||
#include <hyprlang.hpp>
|
#include <hyprlang.hpp>
|
||||||
|
|
||||||
CScale::~CScale() {
|
CProgressBar::~CProgressBar() {
|
||||||
if (valueTimer) {
|
if (valueTimer) {
|
||||||
valueTimer->cancel();
|
valueTimer->cancel();
|
||||||
valueTimer.reset();
|
valueTimer.reset();
|
||||||
|
@ -18,25 +18,25 @@ static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||||
if (data == nullptr)
|
if (data == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto PSCALE = (CScale*)data;
|
const auto PSCALE = (CProgressBar*)data;
|
||||||
|
|
||||||
PSCALE->onTimerUpdate();
|
PSCALE->onTimerUpdate();
|
||||||
PSCALE->plantTimer();
|
PSCALE->plantTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScale::onTimerUpdate() {
|
void CProgressBar::onTimerUpdate() {
|
||||||
updateValue();
|
updateValue();
|
||||||
g_pHyprlock->renderOutput(outputStringPort);
|
g_pHyprlock->renderOutput(outputStringPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScale::plantTimer() {
|
void CProgressBar::plantTimer() {
|
||||||
if (value.updateEveryMs != 0)
|
if (value.updateEveryMs != 0)
|
||||||
valueTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)value.updateEveryMs), onTimer, this, value.allowForceUpdate);
|
valueTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)value.updateEveryMs), onTimer, this, value.allowForceUpdate);
|
||||||
else if (value.updateEveryMs == 0 && value.allowForceUpdate)
|
else if (value.updateEveryMs == 0 && value.allowForceUpdate)
|
||||||
valueTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
valueTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) : viewport(viewport_), outputStringPort(output) {
|
CProgressBar::CProgressBar(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) : viewport(viewport_), outputStringPort(output) {
|
||||||
try {
|
try {
|
||||||
min = std::any_cast<Hyprlang::INT>(props.at("min"));
|
min = std::any_cast<Hyprlang::INT>(props.at("min"));
|
||||||
max = std::any_cast<Hyprlang::INT>(props.at("max"));
|
max = std::any_cast<Hyprlang::INT>(props.at("max"));
|
||||||
|
@ -55,8 +55,8 @@ CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string,
|
||||||
|
|
||||||
backgroundColor = std::any_cast<Hyprlang::INT>(props.at("background_color"));
|
backgroundColor = std::any_cast<Hyprlang::INT>(props.at("background_color"));
|
||||||
|
|
||||||
} catch (const std::bad_any_cast& e) { RASSERT(false, "Failed to construct CScale: {}", e.what()); } catch (const std::out_of_range& e) {
|
} catch (const std::bad_any_cast& e) { RASSERT(false, "Failed to construct CProgressBar: {}", e.what()); } catch (const std::out_of_range& e) {
|
||||||
RASSERT(false, "Missing property for CScale: {}", e.what());
|
RASSERT(false, "Missing property for CProgressBar: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
|
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
|
||||||
|
@ -69,7 +69,7 @@ CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string,
|
||||||
plantTimer();
|
plantTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScale::updateValue() {
|
void CProgressBar::updateValue() {
|
||||||
int value = getValue();
|
int value = getValue();
|
||||||
if (value < min)
|
if (value < min)
|
||||||
value = min;
|
value = min;
|
||||||
|
@ -79,7 +79,7 @@ void CScale::updateValue() {
|
||||||
*animatedValue = static_cast<float>(value - min) / (max - min);
|
*animatedValue = static_cast<float>(value - min) / (max - min);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CScale::draw(const SRenderData& data) {
|
bool CProgressBar::draw(const SRenderData& data) {
|
||||||
CBox box = {pos.x, pos.y, size.x, size.y};
|
CBox box = {pos.x, pos.y, size.x, size.y};
|
||||||
g_pRenderer->renderRect(box, backgroundColor, rounding);
|
g_pRenderer->renderRect(box, backgroundColor, rounding);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ bool CScale::draw(const SRenderData& data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CScale::getValue() {
|
int CProgressBar::getValue() {
|
||||||
if (value.cmd) {
|
if (value.cmd) {
|
||||||
const auto _value = g_pHyprlock->spawnSync(value.formatted);
|
const auto _value = g_pHyprlock->spawnSync(value.formatted);
|
||||||
if (_value.empty())
|
if (_value.empty())
|
|
@ -9,10 +9,10 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
||||||
class CScale : public IWidget {
|
class CProgressBar : public IWidget {
|
||||||
public:
|
public:
|
||||||
CScale(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
CProgressBar(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
||||||
~CScale();
|
~CProgressBar();
|
||||||
|
|
||||||
virtual bool draw(const SRenderData& data);
|
virtual bool draw(const SRenderData& data);
|
||||||
|
|
Loading…
Reference in a new issue