GithubHelp home page GithubHelp logo

Comments (3)

01micko avatar 01micko commented on September 21, 2024

This is a weird bug. I put a hack in osd.c and workspaces.c printing x to file (the cairo x coordinate for text position) and here's the result:

68 [en - wkspces]
68
68
68
68
68
68
68
258 [en - osd]
258
66 [ar - wkspces]
66
66
66
66
66
66
256 [ar - osd]
256
256

The font extents were like so 84 [en] and 87 [ar] in both osd.c and workspaces.c so there is no error in the math. I didn't expect so but I did suspect maybe something weird was happening in font_width().

I think somehow in workspaces.c the logic maybe out?

from labwc.

Consolatis avatar Consolatis commented on September 21, 2024

Hm.. yeah, I think there is a bug in the calculation of the available width; we do set the width available to pango to the whole available space rather than just the space required for the text, clamped by the whole available width.

That should usually not be an issue but in this case of a RTL setting it means that pango will in fact use all the available width as it starts the text on the right rather than our pre-calculated center offset.

This might fix it:

diff --git a/src/workspaces.c b/src/workspaces.c
index e7707c5f..c8b1ac2c 100644
--- a/src/workspaces.c
+++ b/src/workspaces.c
@@ -118,18 +118,21 @@ _osd_update(struct server *server)
 		/* Text */
 		set_cairo_color(cairo, server->theme->osd_label_text_color);
 		PangoLayout *layout = pango_cairo_create_layout(cairo);
-		pango_layout_set_width(layout, (width - 2 * margin) * PANGO_SCALE);
 		pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
 
-		PangoFontDescription *desc = font_to_pango_desc(&rc.font_osd);
-		pango_layout_set_font_description(layout, desc);
 
 		/* Center workspace indicator on the x axis */
-		x = font_width(&rc.font_osd, server->workspace_current->name);
-		x = (width - x) / 2;
+		int req_width = font_width(&rc.font_osd, server->workspace_current->name);
+		if (req_width > width - 2 * margin) {
+			req_width = width - 2 * margin;
+		}
+		x = (width - req_width) / 2;
 		cairo_move_to(cairo, x, margin * 2 + rect_height);
+
+		PangoFontDescription *desc = font_to_pango_desc(&rc.font_osd);
 		//pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
 		pango_layout_set_font_description(layout, desc);
+		pango_layout_set_width(layout, req_width * PANGO_SCALE);
 		pango_font_description_free(desc);
 		pango_layout_set_text(layout, server->workspace_current->name, -1);
 		pango_cairo_show_layout(cairo, layout);

from labwc.

01micko avatar 01micko commented on September 21, 2024

Nice!

ar-fixed

from labwc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.