Skip to content

Commit

Permalink
fix: pango text position
Browse files Browse the repository at this point in the history
. pango axis vs cairo axis
. pango size is scaled
  • Loading branch information
rtgiskard committed May 18, 2024
1 parent 2f8dd6b commit e04780e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/debug/HyprDebugOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ int CHyprMonitorDebugOverlay::draw(int offset) {

int textW = 0, textH = 0;
pango_layout_get_size(layoutText, &textW, &textH);
textW /= PANGO_SCALE;
textH /= PANGO_SCALE;
if (textW > maxTextW)
maxTextW = textW;

// move to next line
cairo_rel_move_to(cr, 0, fontSize + 1);
};

const int PADDING = 4;
cairo_move_to(cr, PADDING, PADDING + offset);
const int MARGIN_TOP = 8;
const int MARGIN_LEFT = 4;
cairo_move_to(cr, MARGIN_LEFT, MARGIN_TOP + offset);
cairo_set_source_rgba(g_pDebugOverlay->m_pCairo, 1.f, 1.f, 1.f, 1.f);

std::string text;
Expand Down Expand Up @@ -174,8 +177,8 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
cairo_get_current_point(cr, &pos_x, &pos_y);

g_pHyprRenderer->damageBox(&m_wbLastDrawnBox);
m_wbLastDrawnBox = {(int)g_pCompositor->m_vMonitors.front()->vecPosition.x + PADDING, (int)g_pCompositor->m_vMonitors.front()->vecPosition.y + offset + PADDING - 1,
(int)maxTextW + 2, pos_y - offset - PADDING + 2};
m_wbLastDrawnBox = {(int)g_pCompositor->m_vMonitors.front()->vecPosition.x + MARGIN_LEFT - 1, (int)g_pCompositor->m_vMonitors.front()->vecPosition.y + offset + MARGIN_TOP - 1,
(int)maxTextW + 2, pos_y - offset - MARGIN_TOP + 2};
g_pHyprRenderer->damageBox(&m_wbLastDrawnBox);

return pos_y - offset;
Expand Down
4 changes: 2 additions & 2 deletions src/debug/HyprNotificationOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) {

// draw icon
cairo_set_source_rgb(m_pCairo, 1.f, 1.f, 1.f);
cairo_move_to(m_pCairo, MONSIZE.x - NOTIFSIZE.x * SECONDRECTPERC + NOTIF_LEFTBAR_SIZE + ICONPADFORNOTIF - 1, offsetY + std::round((NOTIFSIZE.y - iconH - 4) / 2.0));
cairo_move_to(m_pCairo, MONSIZE.x - NOTIFSIZE.x * SECONDRECTPERC + NOTIF_LEFTBAR_SIZE + ICONPADFORNOTIF - 1, offsetY - 2 + std::round((NOTIFSIZE.y - iconH) / 2.0));
pango_cairo_show_layout(m_pCairo, layoutIcon);
}

// draw text
cairo_set_source_rgb(m_pCairo, 1.f, 1.f, 1.f);
cairo_move_to(m_pCairo, MONSIZE.x - NOTIFSIZE.x * SECONDRECTPERC + NOTIF_LEFTBAR_SIZE + iconW + 2 * ICONPADFORNOTIF, offsetY + FONTSIZE + (FONTSIZE / 10.0));
cairo_move_to(m_pCairo, MONSIZE.x - NOTIFSIZE.x * SECONDRECTPERC + NOTIF_LEFTBAR_SIZE + iconW + 2 * ICONPADFORNOTIF, offsetY - 2 + std::round((NOTIFSIZE.y - textH) / 2.0));
pango_cairo_show_layout(m_pCairo, layoutText);

// adjust offset and move on
Expand Down
2 changes: 1 addition & 1 deletion src/hyprerror/HyprError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void CHyprError::createQueued() {
pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL);
pango_layout_set_font_description(layoutText, pangoFD);

float yoffset = TOPBAR ? FONTSIZE : Y - PAD + FONTSIZE;
float yoffset = TOPBAR ? 0 : Y - PAD;
int renderedcnt = 0;
while (!m_szQueued.empty() && renderedcnt < VISLINECOUNT) {
std::string current = m_szQueued.substr(0, m_szQueued.find('\n'));
Expand Down
4 changes: 3 additions & 1 deletion src/render/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2117,8 +2117,10 @@ void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const
int textW = 0, textH = 0;
pango_layout_set_text(layoutText, g_pCompositor->m_szCurrentSplash.c_str(), -1);
pango_layout_get_size(layoutText, &textW, &textH);
textW /= PANGO_SCALE;
textH /= PANGO_SCALE;

cairo_move_to(CAIRO, (size.x - textW) / 2.0, size.y - textH + offsetY);
cairo_move_to(CAIRO, (size.x - textW) / 2.0, size.y - textH * 2 + offsetY);
pango_cairo_show_layout(CAIRO, layoutText);

pango_font_description_free(pangoFD);
Expand Down

0 comments on commit e04780e

Please sign in to comment.