mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-12-22 13:29:48 +01:00
renderer: add text trim with option to disable (#310)
* renderer: add text trim with option to disable * refactor: format CAsyncResourceGatherer::renderText * config: change disable_text_trim to text_trim
This commit is contained in:
parent
21226c1206
commit
c87af3aa1f
2 changed files with 15 additions and 7 deletions
|
@ -44,6 +44,7 @@ void CConfigManager::init() {
|
||||||
m_config.addSpecialConfigValue(name, "shadow_boost", Hyprlang::FLOAT{1.2});
|
m_config.addSpecialConfigValue(name, "shadow_boost", Hyprlang::FLOAT{1.2});
|
||||||
|
|
||||||
m_config.addConfigValue("general:disable_loading_bar", Hyprlang::INT{0});
|
m_config.addConfigValue("general:disable_loading_bar", Hyprlang::INT{0});
|
||||||
|
m_config.addConfigValue("general:text_trim", Hyprlang::INT{1});
|
||||||
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
|
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
|
||||||
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
|
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
|
||||||
m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0});
|
m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0});
|
||||||
|
|
|
@ -277,14 +277,21 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
||||||
target.type = TARGET_IMAGE; /* text is just an image lol */
|
target.type = TARGET_IMAGE; /* text is just an image lol */
|
||||||
target.id = rq.id;
|
target.id = rq.id;
|
||||||
|
|
||||||
const int FONTSIZE = rq.props.contains("font_size") ? std::any_cast<int>(rq.props.at("font_size")) : 16;
|
const int FONTSIZE = rq.props.contains("font_size") ? std::any_cast<int>(rq.props.at("font_size")) : 16;
|
||||||
const CColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CColor>(rq.props.at("color")) : CColor(1.0, 1.0, 1.0, 1.0);
|
const CColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CColor>(rq.props.at("color")) : CColor(1.0, 1.0, 1.0, 1.0);
|
||||||
const std::string FONTFAMILY = rq.props.contains("font_family") ? std::any_cast<std::string>(rq.props.at("font_family")) : "Sans";
|
const std::string FONTFAMILY = rq.props.contains("font_family") ? std::any_cast<std::string>(rq.props.at("font_family")) : "Sans";
|
||||||
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
|
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
|
||||||
const std::string TEXT = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
|
|
||||||
|
|
||||||
auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1920, 1080 /* dummy value */);
|
static auto* const TRIM = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:text_trim");
|
||||||
auto CAIRO = cairo_create(CAIROSURFACE);
|
std::string TEXT = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
|
||||||
|
|
||||||
|
if (**TRIM) {
|
||||||
|
TEXT.erase(0, TEXT.find_first_not_of(" \n\r\t"));
|
||||||
|
TEXT.erase(TEXT.find_last_not_of(" \n\r\t") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1920, 1080 /* dummy value */);
|
||||||
|
auto CAIRO = cairo_create(CAIROSURFACE);
|
||||||
|
|
||||||
// draw title using Pango
|
// draw title using Pango
|
||||||
PangoLayout* layout = pango_cairo_create_layout(CAIRO);
|
PangoLayout* layout = pango_cairo_create_layout(CAIRO);
|
||||||
|
|
Loading…
Reference in a new issue