Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspaces: when cycling through desktops RTL languages shift right too much. #1633

Closed
01micko opened this issue Mar 17, 2024 · 3 comments
Closed
Milestone

Comments

@01micko
Copy link
Contributor
01micko commented Mar 17, 2024

So, when a feature is added then a bug is found! Re 5a20014

I found that when cycling trough desktops with an RTL locale (which I didn't test :( ) that the text is apparently on the wrong side of the desktop number. EDIT: no, the whole thing is pushed right, text is correct in relation to the number.

ar-bug

Works fine in the main window switcher osd so is probably a fairly simple fix. Maybe a pango option missing or something.

@01micko 01micko changed the title osd: when cycling through desktops RTL languages shift right too much. workspaces: when cycling through desktops RTL languages shift right too much. Mar 17, 2024
@Consolatis Consolatis added this to the 0.7.2 milestone Mar 17, 2024
@01micko
Copy link
Contributor Author
01micko commented Mar 18, 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?

@Consolatis
Copy link
Member

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);

@01micko
Copy link
Contributor Author
01micko commented Mar 18, 2024

Nice!

ar-fixed

01micko pushed a commit to 01micko/labwc that referenced this issue Mar 18, 2024
Thanks to Consolatis for the patch.
01micko pushed a commit to 01micko/labwc that referenced this issue Mar 18, 2024
01micko pushed a commit to 01micko/labwc that referenced this issue Mar 18, 2024
grisha128 pushed a commit to grisha128/labwc that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants