--- rxvt-unicode/src/command.C 2016/06/30 16:59:02 1.576 +++ rxvt-unicode/src/command.C 2021/05/08 06:16:21 1.587 @@ -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); } @@ -1484,16 +1486,6 @@ bool want_position_change = SHOULD_INVOKE (HOOK_POSITION_CHANGE); - bool moved = false; -#ifdef HAVE_BG_PIXMAP - if (bg_window_position_sensitive ()) - { - want_position_change = true; - if (bg_img == 0) - moved = true; - } -#endif - if (want_position_change) { int x, y; @@ -1511,7 +1503,6 @@ parent_x = x; parent_y = y; HOOK_INVOKE ((this, HOOK_POSITION_CHANGE, DT_INT, x, DT_INT, y, DT_END)); - moved = true; } } @@ -1520,13 +1511,6 @@ seen_resize = 1; resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); } - else - { -#ifdef HAVE_BG_PIXMAP - if (moved) - update_background (); -#endif - } HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); } @@ -1545,17 +1529,6 @@ break; case MapNotify: -#ifdef HAVE_BG_PIXMAP - // This is needed at startup for the case of no window manager - // or a non-reparenting window manager and also because we - // defer bg image updates if the window is not mapped. The - // short delay is to optimize for multiple ConfigureNotify - // events at startup when the window manager reparents the - // window, so as to perform the computation after we have - // received all of them. - if (bg_img == 0) - update_background_ev.start (0.025); -#endif mapped = 1; #ifdef TEXT_BLINK text_blink_ev.start (); @@ -1860,7 +1833,7 @@ #endif } -#if BG_IMAGE_FROM_ROOT || ENABLE_PERL +#if ENABLE_PERL void ecb_hot rxvt_term::rootwin_cb (XEvent &ev) { @@ -1880,13 +1853,6 @@ if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID] || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) { -#if BG_IMAGE_FROM_ROOT - if (option (Opt_transparent)) - { - rxvt_img::new_from_root (this)->replace (root_img); - update_background (); - } -#endif HOOK_INVOKE ((this, HOOK_ROOTPMAP_CHANGE, DT_END)); } @@ -2187,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; @@ -2392,8 +2358,8 @@ { while (cmdbuf_ptr < cmdbuf_endp) { - // assume 7-bit to be ascii ALWAYS - if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) + // assume 7-bit to be ascii ALWAYS (always true in POSIX) + if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f)) return *cmdbuf_ptr++; wchar_t wc; @@ -2728,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') + 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 */ @@ -2910,7 +2878,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); @@ -2950,7 +2918,7 @@ break; case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */ - case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ + case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ #ifdef ISO6429 arg[0] = -arg[0]; #else /* emulate common DEC VTs */ @@ -3352,24 +3320,23 @@ /* * Find the nearest color slot in the hidden color cube, - * adapt its value to the 24bit RGB color. + * adapt its value to the 32bit RGBA color. */ unsigned int -rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b) +rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b, unsigned int a) { r &= 0xff; g &= 0xff; b &= 0xff; + a &= 0xff; + + uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; - unsigned int color = (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); - if (rgb24_color[idx] == color) - return idx + minTermCOLOR24; - /* we allow one of the 6 directly neighbouring colours */ /* to replace the current color, if they not used recently */ static const signed char dxyz[][3] = { @@ -3385,20 +3352,21 @@ for (int n = 0; n < ecb_array_length (dxyz); ++n) { int r = idx_r + dxyz[n][0]; - int g = idx_r + dxyz[n][1]; - int b = idx_r + dxyz[n][2]; + 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; + 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 index = colorcube_index (r, g, b); + if (rgb24_color[index] == color) + { + rgb24_seqno[index] = ++rgb24_sequence; + return index + minTermCOLOR24; + } + // minor issue: could update index 0 few more times if ((rgb24_seqno[index] | rgb24_color[index]) == 0) { @@ -3406,9 +3374,6 @@ goto update; } - if (rgb24_color[index] == color) - return index + minTermCOLOR24; - // 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) @@ -3421,7 +3386,7 @@ idx += minTermCOLOR24; pix_colors_focused [idx].free (this); - pix_colors_focused [idx].set (this, rgba (r * 0x0101, g * 0x0101, b * 0x0101)); + pix_colors_focused [idx].set (this, rgba (r * 0x0101, g * 0x0101, b * 0x0101, a * 0x0101)); update_fade_color (idx, false); return idx; @@ -3574,74 +3539,6 @@ process_color_seq (op, Color_border, str, resp); break; -#if BG_IMAGE_FROM_ROOT - case URxvt_Color_tint: - process_color_seq (op, Color_tint, str, resp); - { - bool changed = false; - - if (ISSET_PIXCOLOR (Color_tint)) - changed = root_effects.set_tint (pix_colors_focused [Color_tint]); - - if (changed) - update_background (); - } - - break; -#endif - -#if BG_IMAGE_FROM_FILE - case Rxvt_Pixmap: - if (!strcmp (str, "?")) - { - char str[256]; - int h_scale = fimage.h_scale; - int v_scale = fimage.v_scale; - int h_align = fimage.h_align; - int v_align = fimage.v_align; - - sprintf (str, "[%dx%d+%d+%d]", - h_scale, v_scale, - h_align, v_align); - process_xterm_seq (XTerm_title, str, CHAR_ST); - } - else - { - bool changed = false; - - if (*str != ';') - { - try - { - fimage.set_file_geometry (this, str); - changed = true; - } - catch (const class rxvt_failure_exception &e) - { - } - } - else - { - str++; - if (fimage.set_geometry (str, true)) - changed = true; - } - - if (changed) - { - if (bg_window_position_sensitive ()) - { - int x, y; - get_window_origin (x, y); - parent_x = x; - parent_y = y; - } - update_background (); - } - } - break; -#endif - case XTerm_logfile: // TODO, when secure mode? break; @@ -3807,12 +3704,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 @@ -4063,22 +3961,6 @@ case 37: scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); break; - case 38: // set fg color, ISO 8613-6 - if (nargs > i + 2 && arg[i + 1] == 5) - { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); - i += 2; - } - else if (nargs > i + 4 && arg[i + 1] == 2) - { - unsigned int r = arg[i + 2]; - unsigned int g = arg[i + 3]; - unsigned int b = arg[i + 4]; - unsigned int idx = map_rgb24_color (r, g, b); - scr_color (idx, Color_fg); - i += 4; - } - break; case 39: /* default fg */ scr_color (Color_fg, Color_fg); break; @@ -4093,26 +3975,39 @@ case 47: scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); break; - case 48: // set bg color, ISO 8613-6 - if (nargs > i + 2 && arg[i + 1] == 5) - { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); - i += 2; - } - else if (nargs > i + 4 && arg[i + 1] == 2) - { - unsigned int r = arg[i + 2]; - unsigned int g = arg[i + 3]; - unsigned int b = arg[i + 4]; - unsigned int idx = map_rgb24_color (r, g, b); - scr_color (idx, Color_bg); - i += 4; - } - break; case 49: /* default bg */ scr_color (Color_bg, Color_bg); break; + case 38: // set fg color, ISO 8613-6 + case 48: // set bg color, ISO 8613-6 + { + 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]; + i += 2; + + scr_color (idx, fgbg); + } + else if (nargs > i + 4 && arg[i + 1] == 2) + { + unsigned int r = arg[i + 2]; + unsigned int g = arg[i + 3]; + unsigned int b = arg[i + 4]; + unsigned int a = 0xff; + + idx = map_rgb24_color (r, g, b, a); + + i += 4; + + scr_color (idx, fgbg); + } + } + break; + //case 50: // not variable spacing #if !ENABLE_MINIMAL