From 1fda6b42ae54531830e9dff9eda55138952bed01 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 19 May 2012 06:34:34 +0300 Subject: [PATCH] fixed bug with mouse reporting (mouse coords was double-encoded) --- src/sterm.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/sterm.c b/src/sterm.c index cbdfd95..78b8167 100644 --- a/src/sterm.c +++ b/src/sterm.c @@ -580,6 +580,7 @@ static const char *findCommandCompletion (const char *str, int slen, const char static void ttyresize (void); static void tputc (const char *c); // `c` is utf-8 static void ttywrite (const char *s, size_t n); +static void ttywritenoenc (const char *s, size_t n); static void tsetdirt (int top, int bot); static void tfulldirt (void); @@ -596,6 +597,7 @@ static void tcmdput (const char *s, int len); static inline void ttywritestr (const char *s) { if (s != NULL && s[0]) ttywrite(s, strlen(s)); } +static inline void ttywritestrnoenc (const char *s) { if (s != NULL && s[0]) ttywritenoenc(s, strlen(s)); } static inline uint32 getColor (int idx) { @@ -1566,6 +1568,7 @@ static void mousereport (XEvent *e) { if (term == NULL) return; if (x < 0 || x >= term->col || y < 0 || y >= term->row) return; // + //fprintf(stderr, "mr(%d): x=%d; y=%d\n", term->mousemode, x, y); #if 0 case 1000: /* X11 xterm mouse reporting */ case 1005: /* utf-8 mouse encoding */ @@ -1637,7 +1640,7 @@ static void mousereport (XEvent *e) { fputs(">\n", stderr); } */ - ttywritestr(buf); + ttywritestrnoenc(buf); } @@ -1855,7 +1858,7 @@ static void selnotify (XEvent *e) { } else { if (nitems*format/8 > 0 && !wasbrk && IS_SET(MODE_BRACPASTE)) { wasbrk = 1; - ttywritestr("\x1b[200~"); + ttywritestrnoenc("\x1b[200~"); } ttywrite(str, blen); } @@ -1864,7 +1867,7 @@ static void selnotify (XEvent *e) { ofs += nitems*format/32; } while (rem > 0); // - if (wasbrk) ttywritestr("\x1b[201~"); + if (wasbrk) ttywritestrnoenc("\x1b[201~"); if (ucbuf != NULL) free(ucbuf); } @@ -2364,16 +2367,20 @@ static void ttyflushwrbuf (void) { // convert char to locale and write it -static void ttywriterawchar (const char *s, int len) { +static void ttywriterawchar (const char *s, int len, int noenc) { char loc[16]; int clen; // if (s == NULL || len < 1) return; - if (term->needConv) { - if ((clen = utf2loc(loc, s, len)) < 1) return; + if (!noenc) { + if (term->needConv) { + if ((clen = utf2loc(loc, s, len)) < 1) return; + } else { + if ((clen = utf8size(s)) < 1) return; + memmove(loc, s, clen); + } } else { - if ((clen = utf8size(s)) < 1) return; - memmove(loc, s, clen); + memmove(loc, s, (clen = len)); } #ifdef DUMP_IO_WRITE { @@ -2402,6 +2409,15 @@ static void ttywriterawchar (const char *s, int len) { } +static void ttywritenoenc (const char *s, size_t n) { + if (n > 0) { + term->ubufpos = 0; // discard possible utf-8 char + while (n-- > 0) ttywriterawchar(s++, 1, 1); + } + ttyflushwrbuf(); +} + + static void ttywrite (const char *s, size_t n) { if (term == NULL || term->dead || term->cmdfd < 0) return; #ifdef DUMP_PROG_INPUT @@ -2420,7 +2436,7 @@ static void ttywrite (const char *s, size_t n) { // if (term->ubufpos > 0 && isfullutf8(term->ubuf, term->ubufpos)) { // have complete char - ttywriterawchar(term->ubuf, term->ubufpos); + ttywriterawchar(term->ubuf, term->ubufpos, 0); term->ubufpos = 0; continue; } @@ -2428,7 +2444,7 @@ static void ttywrite (const char *s, size_t n) { if (term->ubufpos == 0) { // new char if (c < 128) { - ttywriterawchar(s, 1); + ttywriterawchar(s, 1, 0); } else if ((c&0xc0) == 0xc0) { // new utf-8 char term->ubuf[term->ubufpos++] = *s; @@ -2451,7 +2467,7 @@ static void ttywrite (const char *s, size_t n) { --n; if (isfullutf8(term->ubuf, term->ubufpos)) { // have complete char - ttywriterawchar(term->ubuf, term->ubufpos); + ttywriterawchar(term->ubuf, term->ubufpos, 0); term->ubufpos = 0; } } -- 2.11.4.GIT