summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2025-01-02 17:50:55 +0100
committervaxerski <vaxry@vaxry.net>2025-01-02 17:50:55 +0100
commit81721b8aa87b1df3c3a9c9eadafcc271178c102a (patch)
tree89ea55211a3c88ee7e74e470d412547ea285b647 /src/render
parent365caa49ff4e4f87da687adfa237b8f855aee42b (diff)
groupbar: unify title rendering
moves the text renderer to the unified opengl impl
Diffstat (limited to 'src/render')
-rw-r--r--src/render/OpenGL.cpp4
-rw-r--r--src/render/OpenGL.hpp2
-rw-r--r--src/render/decorations/CHyprGroupBarDecoration.cpp75
-rw-r--r--src/render/decorations/CHyprGroupBarDecoration.hpp3
4 files changed, 11 insertions, 73 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index 93bd129a..68baf48e 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -2555,12 +2555,12 @@ SP<CTexture> CHyprOpenGLImpl::loadAsset(const std::string& filename) {
return tex;
}
-SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col, int pt, bool italic) {
+SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col, int pt, bool italic, const std::string& fontFamily) {
SP<CTexture> tex = makeShared<CTexture>();
static auto FONT = CConfigValue<std::string>("misc:font_family");
- const auto FONTFAMILY = *FONT;
+ const auto FONTFAMILY = fontFamily.empty() ? *FONT : fontFamily;
const auto FONTSIZE = pt;
const auto COLOR = col;
diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp
index 95ac41be..281ee09a 100644
--- a/src/render/OpenGL.hpp
+++ b/src/render/OpenGL.hpp
@@ -218,7 +218,7 @@ class CHyprOpenGLImpl {
void bindBackOnMain();
SP<CTexture> loadAsset(const std::string& file);
- SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false);
+ SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "");
void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {});
diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp
index f870e71b..53d35a64 100644
--- a/src/render/decorations/CHyprGroupBarDecoration.cpp
+++ b/src/render/decorations/CHyprGroupBarDecoration.cpp
@@ -179,10 +179,10 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) {
Vector2D{m_fBarWidth * pMonitor->scale, (*PTITLEFONTSIZE + 2L * BAR_TEXT_PAD) * pMonitor->scale},
pMonitor->scale))
.get();
- rect.y += (rect.height - pTitleTex->textHeight) / 2.0;
- rect.height = pTitleTex->textHeight;
- rect.width = pTitleTex->textWidth;
- rect.x += (m_fBarWidth * pMonitor->scale) / 2.0 - (pTitleTex->textWidth / 2.0);
+ rect.y += std::ceil((rect.height - pTitleTex->texSize.y) / 2.0);
+ rect.height = pTitleTex->texSize.y;
+ rect.width = pTitleTex->texSize.x;
+ rect.x += std::round((m_fBarWidth * pMonitor->scale) / 2.0 - (pTitleTex->texSize.x / 2.0));
rect.round();
CTexPassElement::SRenderData data;
@@ -215,10 +215,6 @@ void CHyprGroupBarDecoration::invalidateTextures() {
}
CTitleTex::CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize, const float monitorScale) : szContent(pWindow->m_szTitle), pWindowOwner(pWindow) {
- tex = makeShared<CTexture>();
- const auto LAYOUTSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
- const auto LAYOUTCAIRO = cairo_create(LAYOUTSURFACE);
-
static auto FALLBACKFONT = CConfigValue<std::string>("misc:font_family");
static auto PTITLEFONTFAMILY = CConfigValue<std::string>("group:groupbar:font_family");
static auto PTITLEFONTSIZE = CConfigValue<Hyprlang::INT>("group:groupbar:font_size");
@@ -227,67 +223,10 @@ CTitleTex::CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize, const float
const CHyprColor COLOR = CHyprColor(*PTEXTCOLOR);
const auto FONTFAMILY = *PTITLEFONTFAMILY != STRVAL_EMPTY ? *PTITLEFONTFAMILY : *FALLBACKFONT;
- cairo_surface_destroy(LAYOUTSURFACE);
-
- // draw title using Pango
- PangoLayout* layout = pango_cairo_create_layout(LAYOUTCAIRO);
- pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
- pango_layout_set_text(layout, szContent.c_str(), -1);
-
- PangoFontDescription* fontDesc = pango_font_description_new();
- pango_font_description_set_family_static(fontDesc, FONTFAMILY.c_str());
- pango_font_description_set_size(fontDesc, *PTITLEFONTSIZE * PANGO_SCALE * monitorScale);
- pango_layout_set_font_description(layout, fontDesc);
- pango_font_description_free(fontDesc);
-
- const int maxWidth = bufferSize.x;
-
- pango_layout_set_width(layout, maxWidth * PANGO_SCALE);
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
-
- int layoutWidth, layoutHeight;
- PangoRectangle inkRect;
- PangoRectangle logicalRect;
- pango_layout_get_pixel_extents(layout, &inkRect, &logicalRect);
- layoutWidth = inkRect.width;
- layoutHeight = inkRect.height;
-
- const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, layoutWidth, layoutHeight);
- const auto CAIRO = cairo_create(CAIROSURFACE);
-
- // clear the pixmap
- cairo_save(CAIRO);
- cairo_set_operator(CAIRO, CAIRO_OPERATOR_CLEAR);
- cairo_paint(CAIRO);
- cairo_restore(CAIRO);
- cairo_move_to(CAIRO, -inkRect.x, -inkRect.y);
- cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a);
- pango_cairo_show_layout(CAIRO, layout);
-
- g_object_unref(layout);
-
- cairo_surface_flush(CAIROSURFACE);
-
- // copy the data to an OpenGL texture we have
- const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
- tex->allocate();
- glBindTexture(GL_TEXTURE_2D, tex->m_iTexID);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
-#ifndef GLES2
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
-#endif
+ tex = g_pHyprOpenGL->renderText(pWindow->m_szTitle, COLOR, *PTITLEFONTSIZE, false, FONTFAMILY);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, layoutWidth, layoutHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA);
-
- // delete cairo
- textWidth = layoutWidth;
- textHeight = layoutHeight;
- cairo_destroy(LAYOUTCAIRO);
- cairo_destroy(CAIRO);
- cairo_surface_destroy(CAIROSURFACE);
+ if (tex)
+ texSize = tex->m_vSize;
}
CTitleTex::~CTitleTex() = default;
diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp
index e813d140..653cd11c 100644
--- a/src/render/decorations/CHyprGroupBarDecoration.hpp
+++ b/src/render/decorations/CHyprGroupBarDecoration.hpp
@@ -14,8 +14,7 @@ class CTitleTex {
SP<CTexture> tex;
std::string szContent;
- int textWidth;
- int textHeight;
+ Vector2D texSize;
PHLWINDOWREF pWindowOwner;
};