--- rxvt-unicode/src/command.C 2021/05/11 18:46:50 1.590 +++ rxvt-unicode/src/command.C 2023/02/19 08:48:42 1.600 @@ -27,7 +27,7 @@ * Copyright (c) 2001 Marius Gedminas * - Ctrl/Mod4+Tab works like Meta+Tab (options) * Copyright (c) 2003 Rob McMullen - * Copyright (c) 2003-2014 Marc Lehmann + * Copyright (c) 2003-2021 Marc Lehmann * Copyright (c) 2007,2015 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify @@ -170,7 +170,7 @@ # if ENABLE_COMBINING if (IS_COMPOSE (ch)) { - len = rxvt_composite.expand (ch, 0); + len = rxvt_composite.expand (ch); alloc = chr = new wchar_t[len]; rxvt_composite.expand (ch, chr); } @@ -1018,7 +1018,7 @@ rxvt_term::refresh_check () { if (want_refresh && !flush_ev.is_active ()) - flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally + flush_ev.start (); display->flush (); } @@ -2354,7 +2354,7 @@ // read the next character wchar_t ecb_hot -rxvt_term::next_char () NOTHROW +rxvt_term::next_char () noexcept { while (cmdbuf_ptr < cmdbuf_endp) { @@ -2390,7 +2390,7 @@ // read the next octet uint32_t ecb_hot -rxvt_term::next_octet () NOTHROW +rxvt_term::next_octet () noexcept { return cmdbuf_ptr < cmdbuf_endp ? (unsigned char)*cmdbuf_ptr++ @@ -2400,7 +2400,7 @@ static class out_of_input out_of_input; wchar_t ecb_hot -rxvt_term::cmd_getc () THROW ((class out_of_input)) +rxvt_term::cmd_getc () { wchar_t c = next_char (); @@ -2411,7 +2411,7 @@ } uint32_t ecb_hot -rxvt_term::cmd_get8 () THROW ((class out_of_input)) +rxvt_term::cmd_get8 () { uint32_t c = next_octet (); @@ -3021,8 +3021,13 @@ tt_printf ("%-.250s\012", rs[Rs_display_name]); break; case 8: /* unofficial extension */ - process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); - break; + { + string_term st; + st.v[0] = CHAR_ST; + st.v[1] = '\0'; + process_xterm_seq (XTerm_title, (char *)RESNAME "-" VERSION, st); // char * cast verified + break; + } } break; @@ -3217,7 +3222,7 @@ * ends_how is terminator used. returned input must be free()'d */ char * -rxvt_term::get_to_st (unicode_t &ends_how) +rxvt_term::get_to_st (string_term &st) { unicode_t ch; bool seen_esc = false; @@ -3256,7 +3261,11 @@ string[n++] = '\0'; - ends_how = (ch == 0x5c ? C0_ESC : ch); + n = 0; + if (ch == 0x5c) + st.v[n++] = C0_ESC; + st.v[n++] = ch; + st.v[n] = '\0'; return rxvt_wcstombs (string); } @@ -3272,8 +3281,8 @@ * Not handled yet */ - unicode_t eh; - char *s = get_to_st (eh); + string_term st; + char *s = get_to_st (st); if (s) free (s); @@ -3295,12 +3304,12 @@ if (ch == ';') { - unicode_t eh; - char *s = get_to_st (eh); + string_term st; + char *s = get_to_st (st); if (s) { - process_xterm_seq (arg, s, eh); + process_xterm_seq (arg, s, st); free (s); } } @@ -3336,15 +3345,22 @@ /* we allow one of the 6 closest neighbouring colours */ /* to replace the current color, if they not used recently */ - static const signed char dxyz[][3] = { + #if 0 + static const unsigned char dxyz[][3] = { 0, 0, 0, 0, 0, 4, - 0, 4, 0, - 4, 0, 0, 0, 4, 4, 4, 4, 0, 4, 0, 4, + 0, 4, 0, + 4, 0, 0, + }; + #else + // silly compressed verlapping triplets version of above + static const unsigned char dxyz[] = { + 0, 0, 0, 4, 4, 0, 4, 0, 0, }; + #endif static const unsigned char color_level[8][32] = { // neighbour index @@ -3361,11 +3377,11 @@ unsigned int idx; - for (int n = 0; n < ecb_array_length (dxyz); ++n) + for (int n = 0; n < ecb_array_length (dxyz) - 2; ++n) { - unsigned int idx_r = color_level[ Red_levels - dxyz[n][0]][r / 8]; - unsigned int idx_g = color_level[Green_levels - dxyz[n][1]][g / 8]; - unsigned int idx_b = color_level[ Blue_levels - dxyz[n][2]][b / 8]; + unsigned int idx_r = color_level[ Red_levels - dxyz[n + 0]][r / 8]; + unsigned int idx_g = color_level[Green_levels - dxyz[n + 1]][g / 8]; + unsigned int idx_b = color_level[ Blue_levels - dxyz[n + 2]][b / 8]; unsigned int index = colorcube_index (idx_r, idx_g, idx_b); if (n == 0) @@ -3385,8 +3401,8 @@ } // like (rgb24_seqno[idx] > rgb24_seqno[index]) - // but also handles wrap around values good enough - if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff) + // but also handles wrap around values well enough + if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x8000) idx = index; } @@ -3403,23 +3419,25 @@ } void -rxvt_term::process_color_seq (int report, int color, const char *str, char resp) +rxvt_term::process_color_seq (int report, int color, const char *str, string_term &st) { if (str[0] == '?' && !str[1]) { - if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) - return; - rgba c; pix_colors_focused[color].get (c); - color -= minCOLOR; + char rgba_str[32]; #if XFT if (c.a != rgba::MAX_CC) - tt_printf ("\033]%d;%d;rgba:%04x/%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, c.a, resp); + snprintf (rgba_str, sizeof (rgba_str), "rgba:%04x/%04x/%04x/%04x", c.r, c.g, c.b, c.a); else #endif - tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, resp); + snprintf (rgba_str, sizeof (rgba_str), "rgb:%04x/%04x/%04x", c.r, c.g, c.b); + + if (IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) + tt_printf ("\033]%d;%d;%s%s", report, color - minCOLOR, rgba_str, st.v); + else + tt_printf ("\033]%d;%s%s", report, rgba_str, st.v); } else set_window_color (color, str); @@ -3429,7 +3447,7 @@ * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) */ void -rxvt_term::process_xterm_seq (int op, char *str, char resp) +rxvt_term::process_xterm_seq (int op, char *str, string_term &st) { int color; char *buf, *name; @@ -3474,7 +3492,7 @@ && actual_format == 8) str = (const char *)(value); - tt_printf ("\033]%d;%s%c", op, option (Opt_insecure) ? str : "", resp); + tt_printf ("\033]%d;%s%s", op, option (Opt_insecure) ? str : "", st.v); XFree (value); } @@ -3508,49 +3526,49 @@ if ((buf = strchr (name, ';')) != NULL) *buf++ = '\0'; - process_color_seq (op, color, name, resp); + process_color_seq (op, color, name, st); } break; case Rxvt_restoreFG: case XTerm_Color00: - process_color_seq (op, Color_fg, str, resp); + process_color_seq (op, Color_fg, str, st); break; case Rxvt_restoreBG: case XTerm_Color01: - process_color_seq (op, Color_bg, str, resp); + process_color_seq (op, Color_bg, str, st); break; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - process_color_seq (op, Color_cursor, str, resp); + process_color_seq (op, Color_cursor, str, st); break; #endif case XTerm_Color_pointer_fg: - process_color_seq (op, Color_pointer_fg, str, resp); + process_color_seq (op, Color_pointer_fg, str, st); break; case XTerm_Color_pointer_bg: - process_color_seq (op, Color_pointer_bg, str, resp); + process_color_seq (op, Color_pointer_bg, str, st); break; #ifdef OPTION_HC case XTerm_Color_HC: - process_color_seq (op, Color_HC, str, resp); + process_color_seq (op, Color_HC, str, st); break; case XTerm_Color_HTC: - process_color_seq (op, Color_HTC, str, resp); + process_color_seq (op, Color_HTC, str, st); break; #endif #ifndef NO_BOLD_UNDERLINE_REVERSE case URxvt_Color_BD: - process_color_seq (op, Color_BD, str, resp); + process_color_seq (op, Color_BD, str, st); break; case URxvt_Color_UL: - process_color_seq (op, Color_UL, str, resp); + process_color_seq (op, Color_UL, str, st); break; case URxvt_Color_IT: - process_color_seq (op, Color_IT, str, resp); + process_color_seq (op, Color_IT, str, st); break; #endif case URxvt_Color_border: - process_color_seq (op, Color_border, str, resp); + process_color_seq (op, Color_border, str, st); break; case XTerm_logfile: @@ -3578,10 +3596,10 @@ case URxvt_boldItalicFont: #endif if (query) - tt_printf ("\33]%d;%-.250s%c", saveop, + tt_printf ("\33]%d;%-.250s%s", saveop, option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc ? fontset[op - URxvt_font]->fontdesc : "", - resp); + st.v); else { const char *&res = rs[Rs_font + (op - URxvt_font)]; @@ -3594,16 +3612,23 @@ case URxvt_version: if (query) - tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", + tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%s", op, rs[Rs_name], VERSION[0], VERSION[2], - resp); + st.v); break; #if !ENABLE_MINIMAL + case URxvt_cellinfo: + if (query) + tt_printf ("\33]%d;%d;%d;%d%s", saveop, + fwidth, fheight, fbase, + st.v); + break; + case URxvt_locale: if (query) - tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp); + tt_printf ("\33]%d;%-.250s%s", op, option (Opt_insecure) ? locale : "", st.v); else { set_locale (str); @@ -3628,7 +3653,7 @@ #if ENABLE_PERL case URxvt_perl: - HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END)); + HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR, st.v, DT_END)); break; #endif } @@ -3733,7 +3758,9 @@ // 1048 save and restore cursor, implemented in code { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ // 1051, 1052, 1060, 1061 keyboard emulation NYI +#if ENABLE_FRILLS { 2004, PrivMode_BracketPaste }, +#endif }; if (nargs == 0)