--- dmenu.c.orig	2015-11-09 06:42:21.000000000 +0800
+++ dmenu.c	2016-05-10 01:46:51.139220000 +0800
@@ -117,7 +117,6 @@
 static void
 drawmenu(void)
 {
-	int curpos;
 	struct item *item;
 	int x = 0, y = 0, h = bh, w;
 
@@ -132,12 +131,7 @@
 	/* draw input field */
 	w = (lines > 0 || !matches) ? mw - x : inputw;
 	drw_setscheme(drw, &scheme[SchemeNorm]);
-	drw_text(drw, x, 0, w, bh, text, 0);
-
-	if ((curpos = TEXTNW(text, cursor) + bh / 2 - 2) < w) {
-		drw_setscheme(drw, &scheme[SchemeNorm]);
-		drw_rect(drw, x + curpos + 2, 2, 1, bh - 4, 1, 1, 0);
-	}
+	drw_text_cursor(drw, x, 0, w, bh, text, 0, cursor);
 
 	if (lines > 0) {
 		/* draw vertical list */
--- drw.c.orig	2016-05-10 01:17:03.412047000 +0800
+++ drw.c	2016-05-10 01:40:45.695271000 +0800
@@ -219,7 +219,7 @@
 }
 
 int
-drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert)
+drw_text_cursor(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert, int cursor)
 {
 	char buf[1024];
 	int tx, ty, th;
@@ -251,6 +251,8 @@
 	}
 
 	curfont = drw->fonts[0];
+	if (cursor == 0)
+		drw_rect(drw, h / 2 , 2, 1, h - 4, 1, 1, 0);
 	while (1) {
 		utf8strlen = 0;
 		utf8str = text;
@@ -293,10 +295,13 @@
 					ty = y + (h / 2) - (th / 2) + curfont->ascent;
 					tx = x + (h / 2);
 					XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len);
+					if (0 < cursor && cursor <= utf8strlen)
+						drw_rect(drw, x + (h / 2) + drw_font_getexts_width(curfont, utf8str, cursor), 2, 1, h - 4, 1, 1, 0);
 				}
 				x += tex.w;
 				w -= tex.w;
 			}
+			cursor -= utf8strlen;
 		}
 
 		if (!*text) {
@@ -350,6 +355,12 @@
 	return x;
 }
 
+int
+drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert)
+{
+	return drw_text_cursor(drw, x, y, w, h, text, invert, -1);
+}
+
 void
 drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
 {
--- drw.h.orig	2016-05-10 01:49:12.501324000 +0800
+++ drw.h	2016-05-10 01:20:07.264071000 +0800
@@ -69,6 +69,7 @@
 /* Drawing functions */
 void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int);
 int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int);
+int drw_text_cursor(Drw *, int, int, unsigned int, unsigned int, const char *, int, int);
 
 /* Map functions */
 void drw_map(Drw *, Window, int, int, unsigned int, unsigned int);
