--- rxvt-unicode/src/command.C 2014/05/22 18:54:32 1.550 +++ rxvt-unicode/src/command.C 2016/06/30 16:59:02 1.576 @@ -28,7 +28,7 @@ * - Ctrl/Mod4+Tab works like Meta+Tab (options) * Copyright (c) 2003 Rob McMullen * Copyright (c) 2003-2014 Marc Lehmann - * Copyright (c) 2007 Emanuele Giaquinta + * Copyright (c) 2007,2015 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -212,7 +212,7 @@ if (y >= 0) { - y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; + y = (y >= nrow - len - 5 && x < width + 2) ? 0 : -1; x = 0; } @@ -317,13 +317,8 @@ XK_KP_8, // XK_KP_Up XK_KP_6, // XK_KP_Right XK_KP_2, // XK_KP_Down -# ifndef UNSHIFTED_SCROLLKEYS XK_KP_9, // XK_KP_Prior XK_KP_3, // XK_KP_Next -# else - XK_Prior, - XK_Next, -# endif XK_KP_1, // XK_KP_End XK_KP_5, // XK_KP_Begin }; @@ -378,7 +373,6 @@ case XK_Select: param = 4; break; -#ifndef UNSHIFTED_SCROLLKEYS case XK_Prior: param = 5; break; @@ -391,7 +385,6 @@ case XK_End: param = 8; break; -#endif case XK_Help: param = 28; break; @@ -415,8 +408,7 @@ rxvt_term::key_press (XKeyEvent &ev) { int ctrl, meta, shft, len; - KeySym keysym; - int valid_keysym; + KeySym keysym = NoSymbol; char rkbuf[KBUFSZ + 1]; char *kbuf = rkbuf + 1; @@ -485,19 +477,24 @@ else len = 0; } - - valid_keysym = status_return == XLookupKeySym - || status_return == XLookupBoth; } else #endif { len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose); - valid_keysym = keysym != NoSymbol; } - if (valid_keysym) + if (keysym != NoSymbol) { + KeySym orig_keysym = keysym; + + /* Shift + F1 - F10 generates F11 - F20 */ + if (shft && keysym >= XK_F1 && keysym <= XK_F10) + { + keysym += (XK_F11 - XK_F1); + shft = 0; /* turn off Shift */ + } + if (keysym >= 0xFF00 && keysym <= 0xFFFF) { bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; @@ -681,12 +678,12 @@ for (ch = kbuf; ch < kbuf + len; ch++) *ch |= 0x80; - - meta = 0; } #endif /* nil */ ; } + + keysym = orig_keysym; } /* escape prefix */ @@ -703,7 +700,7 @@ if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) return; - if (valid_keysym) + if (keysym != NoSymbol) { #ifdef KEYSYM_RESOURCE if (keyboard->dispatch (this, keysym, ev.state, kbuf, len)) @@ -772,13 +769,7 @@ if (shft) { - /* Shift + F1 - F10 generates F11 - F20 */ - if (keysym >= XK_F1 && keysym <= XK_F10) - { - keysym += (XK_F11 - XK_F1); - shft = 0; /* turn off Shift */ - } - else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys)) + if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys)) { switch (keysym) { @@ -1045,13 +1036,16 @@ void rxvt_term::cursor_blink_reset () { + if (!focus) + return; + if (hidden_cursor) { hidden_cursor = 0; want_refresh = 1; } - if (option (Opt_cursorBlink)) + if (option (Opt_cursorBlink) || (priv_modes & PrivMode_BlinkingCursor)) cursor_blink_ev.again (); else cursor_blink_ev.stop (); @@ -1250,7 +1244,7 @@ rxvt_term::pointer_unblank () { XDefineCursor (dpy, vt, TermWin_cursor); - recolour_cursor (); + recolor_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; @@ -1620,8 +1614,9 @@ if (hidden_pointer) pointer_unblank (); #endif - if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask)) - || priv_modes & PrivMode_MouseAnyEvent) + if (!bypass_keystate + && ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask)) + || priv_modes & PrivMode_MouseAnyEvent)) mouse_report (ev.xbutton); if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) break; @@ -1643,9 +1638,9 @@ &ev.xbutton.state); #ifdef MOUSE_THRESHOLD /* deal with a `jumpy' mouse */ - if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) - { + if (ev.xmotion.time - MEvent.time > MOUSE_THRESHOLD) #endif + { #if ISO_14755 // 5.4 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) @@ -1704,9 +1699,7 @@ sel_scroll_ev.stop(); } #endif -#ifdef MOUSE_THRESHOLD } -#endif } } else if (scrollBar.state == SB_STATE_MOTION && ev.xany.window == scrollBar.win) @@ -1790,12 +1783,15 @@ if (rs[Rs_fade]) { pix_colors = pix_colors_focused; - scr_recolour (); + scr_recolor (); } #endif #if ENABLE_FRILLS if (option (Opt_urgentOnBell)) set_urgency (0); + + if (priv_modes & PrivMode_FocusEvent) + tt_printf ("\x1b[I"); #endif HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); @@ -1813,6 +1809,9 @@ #if ENABLE_FRILLS if (option (Opt_urgentOnBell)) set_urgency (0); + + if (priv_modes & PrivMode_FocusEvent) + tt_printf ("\x1b[O"); #endif #if ENABLE_FRILLS || ISO_14755 if (iso14755buf) @@ -1837,7 +1836,7 @@ if (rs[Rs_fade]) { pix_colors = pix_colors_unfocused; - scr_recolour (); + scr_recolor (); } #endif @@ -1846,11 +1845,14 @@ } void ecb_cold -rxvt_term::update_fade_color (unsigned int idx) +rxvt_term::update_fade_color (unsigned int idx, bool first_time) { #if OFF_FOCUS_FADING if (rs[Rs_fade]) { + if (!first_time) + pix_colors_focused [idx].free (this); + rgba c; pix_colors [Color_fade].get (c); pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c); @@ -1922,7 +1924,7 @@ } #endif - clickintime = ev.time - MEvent.time < MULTICLICK_TIME; + clickintime = ev.time - MEvent.time < multiClickTime; if (reportmode) { @@ -2182,7 +2184,7 @@ if (MEvent.button != AnyButton && (ev.button != MEvent.button || (ev.time - MEvent.time - > MULTICLICK_TIME / 2))) + > multiClickTime / 2))) { MEvent.clicks = 0; MEvent.button = AnyButton; @@ -2582,13 +2584,13 @@ #ifdef EIGHT_BIT_CONTROLS // 8-bit controls - case 0x90: /* DCS */ + case 0x90: /* DCS */ process_dcs_seq (); break; - case 0x9b: /* CSI */ + case 0x9b: /* CSI */ process_csi_seq (); break; - case 0x9d: /* OSC */ + case 0x9d: /* OSC */ process_osc_seq (); break; #endif @@ -3103,7 +3105,7 @@ priv_modes |= PrivMode_LFNL; break; - case CSI_71: // DESCUSR: set cursor style + case CSI_71: // DECSCUSR: set cursor style if (prev_ch == ' ') set_cursor_style (arg[0]); break; @@ -3334,6 +3336,97 @@ } } +static unsigned int +colorcube_index (unsigned int idx_r, + unsigned int idx_g, + unsigned int idx_b) +{ + assert (idx_r < Red_levels); + assert (idx_g < Green_levels); + assert (idx_b < Blue_levels); + + return idx_r * Blue_levels * Green_levels + + idx_g * Blue_levels + + idx_b; +} + +/* + * Find the nearest color slot in the hidden color cube, + * adapt its value to the 24bit RGB color. + */ +unsigned int +rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b) +{ + r &= 0xff; + g &= 0xff; + b &= 0xff; + + 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] = { + 0, 0, 0, + 0, 0, +1, + 0, 0, -1, + 0, +1, 0, + 0, -1, 0, + +1, 0, 0, + -1, 0, 0, + }; + + 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]; + + 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); + + // minor issue: could update index 0 few more times + if ((rgb24_seqno[index] | rgb24_color[index]) == 0) + { + idx = index; + 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) + idx = index; + } + +update: + rgb24_color[idx] = color; + rgb24_seqno[idx] = ++rgb24_sequence; + + idx += minTermCOLOR24; + pix_colors_focused [idx].free (this); + pix_colors_focused [idx].set (this, rgba (r * 0x0101, g * 0x0101, b * 0x0101)); + update_fade_color (idx, false); + + return idx; +} + void rxvt_term::process_color_seq (int report, int color, const char *str, char resp) { @@ -3344,7 +3437,7 @@ #if XFT if (c.a != rgba::MAX_CC) - tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp); + tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, 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); @@ -3691,6 +3784,7 @@ { 7, PrivMode_Autowrap }, // DECAWM // 8, auto-repeat keys // DECARM { 9, PrivMode_MouseX10 }, + { 12, PrivMode_BlinkingCursor }, // 18 end FF to printer after print screen // 19 Print screen prints full screen/scroll region { 25, PrivMode_VisibleCursor }, // DECTCEM cnorm/cvvis/civis @@ -3712,6 +3806,7 @@ { 1002, PrivMode_MouseBtnEvent }, { 1003, PrivMode_MouseAnyEvent }, #if ENABLE_FRILLS + { 1004, PrivMode_FocusEvent }, { 1005, PrivMode_ExtModeMouse }, #endif { 1010, PrivMode_TtyOutputInh }, // rxvt extension @@ -3809,6 +3904,11 @@ scr_touch (true); break; #endif +#ifdef CURSOR_BLINK + case 12: + cursor_blink_reset (); + break; +#endif case 25: /* visible/invisible cursor */ scr_cursor_visible (state); break; @@ -3923,22 +4023,22 @@ case 21: // disable bold, faint, sometimes doubly underlined (iso 8613) rendset = 0, rendstyle = RS_Bold; break; - case 22: // normal intensity + case 22: // bold off (vt220) rendset = 0, rendstyle = RS_Bold; break; case 23: // disable italic rendset = 0, rendstyle = RS_Italic; break; - case 24: + case 24: // underline off (vt220) rendset = 0, rendstyle = RS_Uline; break; - case 25: + case 25: // blink off (vt220) rendset = 0, rendstyle = RS_Blink; break; case 26: // variable spacing (iso 8613) rendset = 0, rendstyle = RS_Blink; break; - case 27: + case 27: // reverse off (vt220) rendset = 0, rendstyle = RS_RVid; break; //case 28: // visible. NYI @@ -3969,6 +4069,15 @@ 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); @@ -3990,6 +4099,15 @@ 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); @@ -4026,13 +4144,17 @@ void rxvt_term::set_cursor_style (int style) { - if (!IN_RANGE_INC (style, 0, 4)) + if (!IN_RANGE_INC (style, 0, 6)) return; - set_option (Opt_cursorUnderline, style >= 3); + if (style == 0) + style = 1; + + cursor_type = (style - 1) / 2; + set_option (Opt_cursorUnderline, cursor_type == 1); #ifdef CURSOR_BLINK - set_option (Opt_cursorBlink, !style || (style & 1)); + set_option (Opt_cursorBlink, style & 1); cursor_blink_reset (); #endif