--- rxvt-unicode/src/command.C 2019/07/07 08:02:15 1.584 +++ rxvt-unicode/src/command.C 2021/05/09 15:48:26 1.589 @@ -1279,9 +1279,9 @@ void rxvt_term::mouse_report (XButtonEvent &ev) { - int button_number, key_state = 0; + int button_number, state = 0; int x, y; - int code = 32; + bool release = ev.type == ButtonRelease; x = Pixel2Col (ev.x) + 1; y = Pixel2Row (ev.y) + 1; @@ -1293,18 +1293,13 @@ mouse_row = x; mouse_col = y; - code += 32; + state += 32; } - if (MEvent.button == AnyButton) - button_number = 3; - else - { - button_number = MEvent.button - Button1; - /* add 0x3D for wheel events, like xterm does */ - if (button_number >= 3) - button_number += 64 - 3; - } + button_number = MEvent.button - Button1; + /* add 0x3D for wheel events, like xterm does */ + if (button_number >= 3) + button_number += 64 - 3; if (priv_modes & PrivMode_MouseX10) { @@ -1312,8 +1307,7 @@ * do not report ButtonRelease * no state info allowed */ - key_state = 0; - if (button_number == 3) + if (release) return; } else @@ -1325,23 +1319,25 @@ * plus will add in our own Double-Click reporting * 32 = Double Click */ - key_state = ((MEvent.state & ShiftMask) ? 4 : 0) - + ((MEvent.state & ModMetaMask) ? 8 : 0) - + ((MEvent.state & ControlMask) ? 16 : 0); + state += ((MEvent.state & ShiftMask) ? 4 : 0) + + ((MEvent.state & ModMetaMask) ? 8 : 0) + + ((MEvent.state & ControlMask) ? 16 : 0); #ifdef MOUSE_REPORT_DOUBLECLICK - key_state += ((MEvent.clicks > 1) ? 32 : 0); + state += ((MEvent.clicks > 1) ? 32 : 0); #endif } + int code = 32 + (release ? 3 : button_number) + state; + #if DEBUG_MOUSEREPORT fprintf (stderr, "Mouse ["); - if (key_state & 16) + if (state & 16) fputc ('C', stderr); - if (key_state & 4) + if (state & 4) fputc ('S', stderr); - if (key_state & 8) + if (state & 8) fputc ('A', stderr); - if (key_state & 32) + if (state & 32) fputc ('2', stderr); fprintf (stderr, "]: <%d>, %d/%d\n", button_number, @@ -1350,20 +1346,26 @@ #endif #if ENABLE_FRILLS - if (priv_modes & PrivMode_ExtMouseRight) + if (priv_modes & PrivMode_ExtMouseSGR) + tt_printf ("\033[<%d;%d;%d%c", + button_number + state, + x, + y, + release ? 'm' : 'M'); + else if (priv_modes & PrivMode_ExtMouseUrxvt) tt_printf ("\033[%d;%d;%dM", - code + button_number + key_state, + code, x, y); - else if (priv_modes & PrivMode_ExtModeMouse) + else if (priv_modes & PrivMode_ExtMouseUTF8) tt_printf ("\033[M%c%lc%lc", - code + button_number + key_state, + code, wint_t (32 + x), wint_t (32 + y)); else #endif tt_printf ("\033[M%c%c%c", - code + button_number + key_state, + code, 32 + x, 32 + y); } @@ -2151,11 +2153,11 @@ > multiClickTime / 2))) { MEvent.clicks = 0; - MEvent.button = AnyButton; + MEvent.button = ev.button; mouse_report (ev); } #else /* MOUSE_REPORT_DOUBLECLICK */ - MEvent.button = AnyButton; + MEvent.button = ev.button; mouse_report (ev); #endif /* MOUSE_REPORT_DOUBLECLICK */ return; @@ -2692,12 +2694,14 @@ } break; +#if 0 // disabled because embedded newlines can make exploits easier /* kidnapped escape sequence: Should be 8.3.48 */ case C1_ESA: /* ESC G */ // used by original rxvt for rob nations own graphics mode if (cmd_getc () == 'Q' && option (Opt_insecure)) tt_printf ("\033G0\012"); /* query graphics - no graphics */ break; +#endif /* 8.3.63: CHARACTER TABULATION SET */ case C1_HTS: /* ESC H */ @@ -2865,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 '!': @@ -2874,7 +2880,7 @@ scr_soft_reset (); static const int pm_h[] = { 7, 25 }; - static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1015, 1049 }; + static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1006, 1015, 1049 }; process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h); process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l); @@ -3393,15 +3399,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); @@ -3700,12 +3710,13 @@ { 1003, PrivMode_MouseAnyEvent }, #if ENABLE_FRILLS { 1004, PrivMode_FocusEvent }, - { 1005, PrivMode_ExtModeMouse }, + { 1005, PrivMode_ExtMouseUTF8 }, + { 1006, PrivMode_ExtMouseSGR }, #endif { 1010, PrivMode_TtyOutputInh }, // rxvt extension { 1011, PrivMode_Keypress }, // rxvt extension #if ENABLE_FRILLS - { 1015, PrivMode_ExtMouseRight }, // urxvt extension of 1005 + { 1015, PrivMode_ExtMouseUrxvt }, // urxvt extension of 1005 #endif // 1035 enable modifiers for alt, numlock NYI // 1036 send ESC for meta keys NYI @@ -3720,6 +3731,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 */ @@ -3979,7 +4008,7 @@ { unsigned int fgbg = arg[i] == 38 ? Color_fg : Color_bg; unsigned int idx; - + if (nargs > i + 2 && arg[i + 1] == 5) { idx = minCOLOR + arg[i + 2];