[PATCH v2 2/3] Fixes cursor rendering for wide glyphs

Peng Wu peng.e.wu at gmail.com
Wed Jul 17 00:50:24 PDT 2013


Show the cursor at the right position, and use wide cursor under wide glyph.
---
 clients/terminal.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/clients/terminal.c b/clients/terminal.c
index 97e315f..d45b740 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -1048,14 +1048,35 @@ redraw_handler(struct widget *widget, void *data)
 
 	if ((terminal->mode & MODE_SHOW_CURSOR) &&
 	    !window_has_focus(terminal->window)) {
+		p_row = terminal_get_row(terminal, terminal->row);
+		extracol = 0;
+
+		for (col = 0; col < terminal->column; col++) {
+			/* check dual width unicode character */
+			unichar = g_utf8_get_char((const char*) p_row[col].byte);
+			iswide = g_unichar_iswide(unichar);
+			if (iswide)
+				extracol++;
+		}
+
+		/* check dual width unicode character */
+		unichar = g_utf8_get_char((const char*)
+					  p_row[terminal->column].byte);
+		iswide = g_unichar_iswide(unichar);
+		if (iswide)
+			unichar_width = 2 * average_width;
+		else
+			unichar_width = average_width;
+
 		d = 0.5;
 
 		cairo_set_line_width(cr, 1);
-		cairo_move_to(cr, terminal->column * average_width + d,
+		cairo_move_to(cr, (terminal->column + extracol) *
+			      average_width + d,
 			      terminal->row * extents.height + d);
-		cairo_rel_line_to(cr, average_width - 2 * d, 0);
+		cairo_rel_line_to(cr, unichar_width - 2 * d, 0);
 		cairo_rel_line_to(cr, 0, extents.height - 2 * d);
-		cairo_rel_line_to(cr, -average_width + 2 * d, 0);
+		cairo_rel_line_to(cr, -unichar_width + 2 * d, 0);
 		cairo_close_path(cr);
 
 		cairo_stroke(cr);
@@ -1068,7 +1089,7 @@ redraw_handler(struct widget *widget, void *data)
 
 	if (terminal->send_cursor_position) {
 		cursor_x = side_margin + allocation.x +
-				terminal->column * average_width;
+			(terminal->column + extracol) * average_width;
 		cursor_y = top_margin + allocation.y +
 				terminal->row * extents.height;
 		window_set_text_cursor_position(terminal->window,
-- 
1.8.3.1



More information about the wayland-devel mailing list