summaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-15 01:21:04 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-15 01:21:04 +0200
commit01b4d568b99fc48fdab0ec628a550dfbeaa7b021 (patch)
tree6629463cfe74fc9be48a9c631e419ca7b51308c2 /src/input.c
parent5a6fe0574c77342f29370219fb9010b72d6d3a00 (diff)
downloadratpoison-01b4d568b99fc48fdab0ec628a550dfbeaa7b021.zip
Support UTF-8 in the input bar
* introduce RP_IS_UTF8_{CHAR,CONT,START} macros. Those yield non-zero only if the locale is UTF-8. * use those macros in editor.c to properly handle UTF-8 multibyte characters. * use them also in input.c:update_input_window, to draw the cursor Reviewing and comments are welcome. Patches for generic support of multibyte encodings are welcome too. UTF-8 was chosen because of its processing simplicity and its wide use, not because of any political opinion or religious belief. ;)
Diffstat (limited to 'src/input.c')
-rw-r--r--src/input.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/input.c b/src/input.c
index 86866f7..5757bf7 100644
--- a/src/input.c
+++ b/src/input.c
@@ -428,16 +428,23 @@ read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
static void
update_input_window (rp_screen *s, rp_input_line *line)
{
- int prompt_width = rp_text_width (s, line->prompt, -1);
- int input_width = rp_text_width (s, line->buffer, line->length);
- int total_width;
+ int prompt_width, input_width, total_width;
+ int char_len = 0, height;
GC lgc;
XGCValues gcv;
- int height;
+ prompt_width = rp_text_width (s, line->prompt, -1);
+ input_width = rp_text_width (s, line->buffer, line->length);
total_width = defaults.bar_x_padding * 2 + prompt_width + input_width + MAX_FONT_WIDTH (defaults.font);
height = (FONT_HEIGHT (s) + defaults.bar_y_padding * 2);
+ if (RP_IS_UTF8_START (line->buffer[line->position]))
+ do
+ char_len++;
+ while (RP_IS_UTF8_CONT (line->buffer[line->position + char_len]));
+ else
+ char_len = 1;
+
if (total_width < defaults.input_window_size + prompt_width)
{
total_width = defaults.input_window_size + prompt_width;
@@ -466,12 +473,12 @@ update_input_window (rp_screen *s, rp_input_line *line)
gcv.foreground = s->fg_color ^ s->bg_color;
lgc = XCreateGC (dpy, s->input_window, GCFunction | GCForeground, &gcv);
- /* Draw a cheap-o cursor - MkII */
+ /* Draw a cheap-o cursor - MkIII */
XFillRectangle (dpy, s->input_window, lgc,
defaults.bar_x_padding + prompt_width +
rp_text_width (s, line->buffer, line->position),
defaults.bar_y_padding,
- rp_text_width (s, &line->buffer[line->position], 1),
+ rp_text_width (s, &line->buffer[line->position], char_len),
FONT_HEIGHT (s));
XFlush (dpy);