--- rxvt-unicode/src/command.C 2021/05/08 06:16:21 1.587 +++ rxvt-unicode/src/command.C 2021/05/13 19:40:19 1.591 @@ -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 (); @@ -2869,6 +2869,8 @@ case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') process_terminal_mode (ch, priv, nargs, arg); + if (prev_ch == '$' && ch == 'p') + process_terminal_mode (ch, priv, nargs, arg); break; case '!': @@ -3332,34 +3334,42 @@ uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; - unsigned int idx_r = r * (Red_levels - 1) / 0xff; - unsigned int idx_g = g * (Green_levels - 1) / 0xff; - unsigned int idx_b = b * (Blue_levels - 1) / 0xff; - unsigned int idx = colorcube_index (idx_r, idx_g, idx_b); - - /* we allow one of the 6 directly neighbouring colours */ + /* 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] = { - 0, 0, 0, - 0, 0, +1, - 0, 0, -1, - 0, +1, 0, - 0, -1, 0, - +1, 0, 0, - -1, 0, 0, + 0, 0, 0, + 0, 0, 4, + 0, 4, 0, + 4, 0, 0, + 0, 4, 4, + 4, 4, 0, + 4, 0, 4, + }; + + static const unsigned char color_level[8][32] = { + // neighbour index + {0, 0, 1, 0, 0, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}, + {0, 1, 0, 1, 1, 2, 1, 1, 2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4}, + {0, 0, 1, 2, 1, 1, 2, 3, 3, 2, 2, 3, 3, 4, 4, 3, 3, 3, 4, 4, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 5}, + {0, 0, 2, 1, 2, 3, 2, 2, 3, 4, 4, 3, 3, 4, 4, 5, 5, 4, 4, 5, 5, 5, 6, 6, 5, 5, 5, 6, 6, 6, 6, 6}, + // Red_levels/Green_levels/Blue_levels index + {0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}, + {0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, + {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6}, }; + unsigned int idx; + for (int n = 0; n < ecb_array_length (dxyz); ++n) { - int r = idx_r + dxyz[n][0]; - int g = idx_g + dxyz[n][1]; - int b = idx_b + dxyz[n][2]; - - if (!IN_RANGE_EXC (r, 0, Red_levels )) continue; - if (!IN_RANGE_EXC (g, 0, Green_levels)) continue; - if (!IN_RANGE_EXC (b, 0, Blue_levels )) continue; + 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); - unsigned int index = colorcube_index (r, g, b); + if (n == 0) + idx = index; if (rgb24_color[index] == color) { @@ -3397,15 +3407,19 @@ { if (str[0] == '?' && !str[1]) { + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) + return; + rgba c; pix_colors_focused[color].get (c); + color -= minCOLOR; #if XFT if (c.a != rgba::MAX_CC) - tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.r, c.g, c.b, c.a, resp); + tt_printf ("\033]%d;%d;rgba:%04x/%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, c.a, resp); else #endif - tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp); + tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, resp); } else set_window_color (color, str); @@ -3725,6 +3739,24 @@ if (nargs == 0) return; + // DECRQM + if (mode == 'p') + { + int status = 0; + if (nargs != 1) + return; + + for (j = 0; j < ecb_array_length (argtopriv); j++) + if (argtopriv[j].argval == arg[0]) + { + status = (priv_modes & argtopriv[j].bit) ? 1 : 2; + break; + } + + tt_printf ("\33[?%d;%d$y", arg[0], status); + return; + } + /* make lo/hi boolean */ if (mode == 'l') mode = 0; /* reset */