--- rxvt-unicode/src/command.C 2007/11/30 10:57:04 1.370 +++ rxvt-unicode/src/command.C 2016/06/21 12:03:56 1.570 @@ -6,7 +6,7 @@ * Copyright (c) 1992 John Bovey, University of Kent at Canterbury * - original version * Copyright (c) 1994 Robert Nation - * - extensive modifications + * - extensive modifications * Copyright (c) 1995 Garrett D'Amore * - vt100 printing * Copyright (c) 1995 Steven Hirsch @@ -22,16 +22,17 @@ * and Linux 1.2.x * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing - * - extensive modifications + * - extensive modifications * Copyright (c) 1998 Alfredo K. Kojima * Copyright (c) 2001 Marius Gedminas * - Ctrl/Mod4+Tab works like Meta+Tab (options) * Copyright (c) 2003 Rob McMullen - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2014 Marc Lehmann + * 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 - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -55,10 +56,10 @@ # include "keyboard.h" #endif -#include +#include #if LINUX_YIELD_HACK -# include +# include #endif /*----------------------------------------------------------------------*/ @@ -132,7 +133,7 @@ 0, }; -void +void ecb_cold rxvt_term::iso14755_54 (int x, int y) { x = Pixel2Col (x); @@ -150,7 +151,7 @@ if (t != NOCHAR || !x) { - iso14755_51 (l.t[x], l.r[x], x, y); + iso14755_51 (l.t[x], l.r[x], x, y, view_start); iso14755buf = ISO_14755_54; break; } @@ -159,16 +160,13 @@ } } -void -rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) +void ecb_cold +rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y, int y2) { rxvt_fontset *fs = FONTSET (r); - rxvt_font *f = (*fs)[fs->find_font (ch)]; - wchar_t *chr, *alloc, ch2, *fname; + wchar_t *chr, *alloc, ch2, **fname; int len; - fname = rxvt_utf8towcs (f->name); - # if ENABLE_COMBINING if (IS_COMPOSE (ch)) { @@ -186,6 +184,9 @@ len = 1; } + char rowcol[40]; + snprintf (rowcol, sizeof rowcol, "col %d row %d @%d", x, y, y2); + char attr[80]; // plenty sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", @@ -198,18 +199,26 @@ r & RS_Uline ? " uline" : "", r & RS_Careful ? " careful" : ""); - int width = wcswidth (fname, wcslen (fname)); + int width = 0; + fname = rxvt_temp_buf (len); + for (int i = 0; i < len; i++) + { + rxvt_font *f = (*fs)[fs->find_font_idx (chr[i])]; + fname[i] = rxvt_utf8towcs (f->name); + max_it (width, wcswidth (fname[i], wcslen (fname[i]))); + } - max_it (width, 8+5); // for char + hey max_it (width, strlen (attr)); 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; } - scr_overlay_new (x, y, width, len + 2); + scr_overlay_new (x, y, width, len * 2 + 2); + + scr_overlay_set (0, 0, rowcol); r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); @@ -220,16 +229,16 @@ ch = *chr++; sprintf (buf, "%8x", ch); - scr_overlay_set (0, y, buf); - scr_overlay_set (9, y, '='); -# if !UNICODE3 + scr_overlay_set (0, y + 1, buf); + scr_overlay_set (9, y + 1, '='); +# if !UNICODE_3 if (ch >= 0x10000) ch = 0xfffd; # endif - scr_overlay_set (11, y, ch, r); + scr_overlay_set (11, y + 1, ch, r); if (WCWIDTH (ch) >= 2) - scr_overlay_set (12, y, NOCHAR, r); + scr_overlay_set (12, y + 1, NOCHAR, r); } // { @@ -237,10 +246,12 @@ // snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y); // scr_overlay_set (0, 0, buf); // } - scr_overlay_set (0, len , attr); - scr_overlay_set (0, len + 1, fname); - - free (fname); + scr_overlay_set (0, len + 1, attr); + for (int i = 0; i < len; i++) + { + scr_overlay_set (0, len + 2 + i, fname[i]); + free (fname[i]); + } # if ENABLE_COMBINING if (alloc) @@ -249,25 +260,22 @@ } #endif -void +void ecb_cold rxvt_term::commit_iso14755 () { - wchar_t ch[2]; - - ch[0] = iso14755buf & ISO_14755_MASK; - ch[1] = 0; + wchar_t ch = iso14755buf & ISO_14755_MASK; if (iso14755buf & ISO_14755_51) { - char mb[16]; + char mb[MB_LEN_MAX]; int len; // allow verbatim 0-bytes and control-bytes to be entered - if (ch[0] >= 0x20) - len = wcstombs (mb, ch, 16); + if (ch >= 0x20) + len = wctomb (mb, ch); else { - mb[0] = ch[0]; + mb[0] = ch; len = 1; } @@ -280,10 +288,10 @@ iso14755buf = 0; } -int -rxvt_term::hex_keyval (XKeyEvent &ev) +static int ecb_cold +hex_keyval (XKeyEvent &ev) { - // check wether this event corresponds to a hex digit + // check whether this event corresponds to a hex digit // if the modifiers had not been pressed. for (int index = 0; index < 8; index++) { @@ -299,14 +307,110 @@ } #endif -void +static inline KeySym ecb_cold +translate_keypad (KeySym keysym, bool kp) +{ +#ifdef XK_KP_Home + static const KeySym keypadtrans[] = { + XK_KP_7, // XK_KP_Home + XK_KP_4, // XK_KP_Left + XK_KP_8, // XK_KP_Up + XK_KP_6, // XK_KP_Right + XK_KP_2, // XK_KP_Down + XK_KP_9, // XK_KP_Prior + XK_KP_3, // XK_KP_Next + XK_KP_1, // XK_KP_End + XK_KP_5, // XK_KP_Begin + }; + + if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin)) + { + unsigned int index = keysym - XK_KP_Home; + keysym = kp ? keypadtrans[index] : XK_Home + index; + } + else if (keysym == XK_KP_Insert) + keysym = kp ? XK_KP_0 : XK_Insert; +# ifndef NO_DELETE_KEY + else if (keysym == XK_KP_Delete) + keysym = kp ? XK_KP_Decimal : XK_Delete; +# endif +#endif + return keysym; +} + +static inline int ecb_cold +map_function_key (KeySym keysym) +{ + int param = 0; + + if (IN_RANGE_INC (keysym, XK_F1, XK_F35)) + { + param = 11 + keysym - XK_F1; + if (keysym >= XK_F17) + param += 4; + else if (keysym >= XK_F15) + param += 3; + else if (keysym >= XK_F11) + param += 2; + else if (keysym >= XK_F6) + param += 1; + } + else + switch (keysym) + { + case XK_Find: + param = 1; + break; + case XK_Insert: + param = 2; + break; +#ifdef DXK_Remove + case DXK_Remove: +#endif + case XK_Execute: + param = 3; + break; + case XK_Select: + param = 4; + break; + case XK_Prior: + param = 5; + break; + case XK_Next: + param = 6; + break; + case XK_Home: + param = 7; + break; + case XK_End: + param = 8; + break; + case XK_Help: + param = 28; + break; + case XK_Menu: + param = 29; + break; + } + return param; +} + +static inline wchar_t * +rxvt_wcsdup (const wchar_t *str, int len) +{ + wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t)); + memcpy (r, str, len * sizeof (wchar_t)); + r[len] = 0; + return r; +} + +void ecb_cold rxvt_term::key_press (XKeyEvent &ev) { int ctrl, meta, shft, len; - unsigned int newlen; - KeySym keysym; - int valid_keysym; - char kbuf[KBUFSZ]; + KeySym keysym = NoSymbol; + char rkbuf[KBUFSZ + 1]; + char *kbuf = rkbuf + 1; #if ISO_14755 if (iso14755buf & ISO_14755_52) @@ -323,15 +427,9 @@ ctrl = ev.state & ControlMask; meta = ev.state & ModMetaMask; - if (numlock_state || (ev.state & ModNumLockMask)) - { - numlock_state = (ev.state & ModNumLockMask); - PrivMode ((!numlock_state), PrivMode_aplKP); - } - kbuf[0] = 0; -#ifdef USE_XIM +#if USE_XIM if (Input_Context) { Status status_return; @@ -379,21 +477,233 @@ 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; + unsigned int newlen = 1; + + if (ev.state & ModNumLockMask) + kp = false; + + keysym = translate_keypad (keysym, kp); + + switch (keysym) + { +#ifndef NO_BACKSPACE_KEY + case XK_BackSpace: + if (priv_modes & PrivMode_HaveBackSpace) + { + kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) + ^ !!ctrl) ? '\b' : '\177'; + kbuf[1] = '\0'; + } + else + strcpy (kbuf, rs[Rs_backspace_key]); + break; +#endif +#ifndef NO_DELETE_KEY + case XK_Delete: + strcpy (kbuf, rs[Rs_delete_key]); + break; +#endif + case XK_Tab: + if (shft) + strcpy (kbuf, "\033[Z"); + else + { +#ifdef CTRL_TAB_MAKES_META + if (ctrl) + meta = 1; +#endif +#ifdef MOD4_TAB_MAKES_META + if (ev.state & Mod4Mask) + meta = 1; +#endif + newlen = 0; + } + break; + + case XK_Up: /* "\033[A" */ + case XK_Down: /* "\033[B" */ + case XK_Right: /* "\033[C" */ + case XK_Left: /* "\033[D" */ + strcpy (kbuf, "\033[Z"); + kbuf[2] = "DACB"[keysym - XK_Left]; + /* do Shift first */ + if (shft) + kbuf[2] = "dacb"[keysym - XK_Left]; + else if (ctrl) + { + kbuf[1] = 'O'; + kbuf[2] = "dacb"[keysym - XK_Left]; + } + else if (priv_modes & PrivMode_aplCUR) + kbuf[1] = 'O'; + break; + + case XK_KP_Enter: + /* allow shift to override */ + if (kp) + { + strcpy (kbuf, "\033OM"); + break; + } + + /* FALLTHROUGH */ + + case XK_Return: + if (priv_modes & PrivMode_LFNL) + { + kbuf[0] = '\015'; + kbuf[1] = '\012'; + kbuf[2] = '\0'; + } + else + { + kbuf[0] = '\015'; + kbuf[1] = '\0'; + } + break; + + case XK_KP_F1: /* "\033OP" */ + case XK_KP_F2: /* "\033OQ" */ + case XK_KP_F3: /* "\033OR" */ + case XK_KP_F4: /* "\033OS" */ + strcpy (kbuf, "\033OP"); + kbuf[2] += (keysym - XK_KP_F1); + break; + + case XK_KP_Multiply: /* "\033Oj" : "*" */ + case XK_KP_Add: /* "\033Ok" : "+" */ + case XK_KP_Separator: /* "\033Ol" : "," */ + case XK_KP_Subtract: /* "\033Om" : "-" */ + case XK_KP_Decimal: /* "\033On" : "." */ + case XK_KP_Divide: /* "\033Oo" : "/" */ + case XK_KP_0: /* "\033Op" : "0" */ + case XK_KP_1: /* "\033Oq" : "1" */ + case XK_KP_2: /* "\033Or" : "2" */ + case XK_KP_3: /* "\033Os" : "3" */ + case XK_KP_4: /* "\033Ot" : "4" */ + case XK_KP_5: /* "\033Ou" : "5" */ + case XK_KP_6: /* "\033Ov" : "6" */ + case XK_KP_7: /* "\033Ow" : "7" */ + case XK_KP_8: /* "\033Ox" : "8" */ + case XK_KP_9: /* "\033Oy" : "9" */ + /* allow shift to override */ + if (kp) + { + strcpy (kbuf, "\033Oj"); + kbuf[2] += (keysym - XK_KP_Multiply); + } + else + { + kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); + kbuf[1] = '\0'; + } + break; + + default: + { + int param = map_function_key (keysym); + if (param > 0) + sprintf (kbuf,"\033[%d~", param); + else + newlen = 0; + } + break; + } + + if (newlen) + len = strlen (kbuf); + + if (len > 0) + { + /* + * pass Shift/Control indicators for function keys ending with `~' + * + * eg, + * Prior = "ESC[5~" + * Shift+Prior = "ESC[5$" + * Ctrl+Prior = "ESC[5^" + * Ctrl+Shift+Prior = "ESC[5@" + */ + if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') + kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); + + /* + * Pass meta for all function keys, if 'meta' option set + */ +#ifdef META8_OPTION + if (meta && (meta_char == 0x80)) + kbuf[len - 1] |= 0x80; +#endif + } + + } + else if (ctrl && keysym == XK_minus) + { + len = 1; + kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ + } + else if (keysym == XK_ISO_Left_Tab) + { + strcpy (kbuf, "\033[Z"); + len = 3; + } + else + { +#ifdef META8_OPTION + /* set 8-bit on */ + if (meta && (meta_char == 0x80)) + { + char *ch; + + for (ch = kbuf; ch < kbuf + len; ch++) + *ch |= 0x80; + } +#endif + /* nil */ ; + } + + keysym = orig_keysym; + } + + /* escape prefix */ + if (len && meta +#ifdef META8_OPTION + && meta_char == C0_ESC +#endif + ) + { + *--kbuf = C0_ESC; + len++; + } + + if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) + return; + + if (keysym != NoSymbol) { #ifdef KEYSYM_RESOURCE - if (keyboard->dispatch (this, keysym, ev.state)) + if (keyboard->dispatch (this, keysym, ev.state, kbuf, len)) return; #endif @@ -412,14 +722,16 @@ #else lnsppg = nrow * 4 / 5; #endif + max_it (lnsppg, 1); + if (keysym == XK_Prior) { - scr_page (UP, lnsppg); + scr_page (lnsppg); return; } else if (keysym == XK_Next) { - scr_page (DN, lnsppg); + scr_page (-lnsppg); return; } } @@ -428,12 +740,12 @@ { if (keysym == XK_Up) { - scr_page (UP, 1); + scr_page (1); return; } else if (keysym == XK_Down) { - scr_page (DN, 1); + scr_page (-1); return; } } @@ -443,12 +755,12 @@ { if (keysym == XK_Home) { - scr_move_to (0, 1); + scr_changeview (top_row); return; } else if (keysym == XK_End) { - scr_move_to (1, 1); + scr_changeview (0); return; } } @@ -457,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) { @@ -474,19 +780,32 @@ #if TODO /* rxvt extras */ case XK_KP_Add: /* Shift+KP_Add = bigger font */ - change_font (FONT_UP); return; case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ - change_font (FONT_DN); return; #endif } } } + if (ctrl && meta && (keysym == XK_c || keysym == XK_v)) + { + if (keysym == XK_v) + selection_request (ev.time, Sel_Clipboard); + else if (selection.len > 0) + { + free (selection.clip_text); + selection.clip_text = rxvt_wcsdup (selection.text, selection.len); + selection.clip_len = selection.len; + selection_grab (CurrentTime, true); + } + + return; + } + #if ENABLE_FRILLS || ISO_14755 // ISO 14755 support - if (shft && ctrl) + if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51)) { int hv; @@ -526,8 +845,9 @@ iso14755buf = 0; } } - else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) - || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) + else if (option (Opt_iso14755) && + ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) + || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))) if (!(iso14755buf & ISO_14755_STARTED)) { iso14755buf |= ISO_14755_STARTED; @@ -545,332 +865,15 @@ return; } #endif - - if (keysym >= 0xFF00 && keysym <= 0xFFFF) - { - { - bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; - newlen = 1; -#ifdef XK_KP_Home - static const KeySym keypadtrans[] = { - XK_KP_7, // XK_KP_Home - XK_KP_4, // XK_KP_Left - 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 - }; - - if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin)) - { - unsigned int index = keysym - XK_KP_Home; - keysym = kp ? keypadtrans[index] : XK_Home + index; - } - else if (keysym == XK_KP_Insert) - keysym = kp ? XK_KP_0 : XK_Insert; -#ifndef NO_DELETE_KEY - else if (keysym == XK_KP_Delete) - keysym = kp ? XK_KP_Decimal : XK_Delete; -#endif -#endif - switch (keysym) - { -#ifndef NO_BACKSPACE_KEY - case XK_BackSpace: - if (priv_modes & PrivMode_HaveBackSpace) - { - kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) - ^ !!ctrl) ? '\b' : '\177'; - kbuf[1] = '\0'; - } - else - strcpy (kbuf, rs[Rs_backspace_key]); - break; -#endif -#ifndef NO_DELETE_KEY - case XK_Delete: - strcpy (kbuf, rs[Rs_delete_key]); - break; -#endif - case XK_Tab: - if (shft) - strcpy (kbuf, "\033[Z"); - else - { -#ifdef CTRL_TAB_MAKES_META - if (ctrl) - meta = 1; -#endif -#ifdef MOD4_TAB_MAKES_META - if (ev.state & Mod4Mask) - meta = 1; -#endif - newlen = 0; - } - break; - - case XK_Up: /* "\033[A" */ - case XK_Down: /* "\033[B" */ - case XK_Right: /* "\033[C" */ - case XK_Left: /* "\033[D" */ - strcpy (kbuf, "\033[Z"); - kbuf[2] = "DACB"[keysym - XK_Left]; - /* do Shift first */ - if (shft) - kbuf[2] = "dacb"[keysym - XK_Left]; - else if (ctrl) - { - kbuf[1] = 'O'; - kbuf[2] = "dacb"[keysym - XK_Left]; - } - else if (priv_modes & PrivMode_aplCUR) - kbuf[1] = 'O'; - break; - -#ifndef UNSHIFTED_SCROLLKEYS - case XK_Prior: - strcpy (kbuf, "\033[5~"); - break; - case XK_Next: - strcpy (kbuf, "\033[6~"); - break; -#endif - case XK_KP_Enter: - /* allow shift to override */ - if (kp) - { - strcpy (kbuf, "\033OM"); - break; - } - - /* FALLTHROUGH */ - - case XK_Return: - if (priv_modes & PrivMode_LFNL) - { - kbuf[0] = '\015'; - kbuf[1] = '\012'; - kbuf[2] = '\0'; - } - else - { - kbuf[0] = '\015'; - kbuf[1] = '\0'; - } - break; - - case XK_KP_F1: /* "\033OP" */ - case XK_KP_F2: /* "\033OQ" */ - case XK_KP_F3: /* "\033OR" */ - case XK_KP_F4: /* "\033OS" */ - strcpy (kbuf, "\033OP"); - kbuf[2] += (keysym - XK_KP_F1); - break; - - case XK_KP_Multiply: /* "\033Oj" : "*" */ - case XK_KP_Add: /* "\033Ok" : "+" */ - case XK_KP_Separator: /* "\033Ol" : "," */ - case XK_KP_Subtract: /* "\033Om" : "-" */ - case XK_KP_Decimal: /* "\033On" : "." */ - case XK_KP_Divide: /* "\033Oo" : "/" */ - case XK_KP_0: /* "\033Op" : "0" */ - case XK_KP_1: /* "\033Oq" : "1" */ - case XK_KP_2: /* "\033Or" : "2" */ - case XK_KP_3: /* "\033Os" : "3" */ - case XK_KP_4: /* "\033Ot" : "4" */ - case XK_KP_5: /* "\033Ou" : "5" */ - case XK_KP_6: /* "\033Ov" : "6" */ - case XK_KP_7: /* "\033Ow" : "7" */ - case XK_KP_8: /* "\033Ox" : "8" */ - case XK_KP_9: /* "\033Oy" : "9" */ - /* allow shift to override */ - if (kp) - { - strcpy (kbuf, "\033Oj"); - kbuf[2] += (keysym - XK_KP_Multiply); - } - else - { - kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); - kbuf[1] = '\0'; - } - break; - - case XK_Find: - strcpy (kbuf, "\033[1~"); - break; - - case XK_Insert: - strcpy (kbuf, "\033[2~"); - break; -#ifdef DXK_Remove /* support for DEC remove like key */ - case DXK_Remove: - /* FALLTHROUGH */ -#endif - case XK_Execute: - strcpy (kbuf, "\033[3~"); - break; - case XK_Select: - strcpy (kbuf, "\033[4~"); - break; - case XK_End: - strcpy (kbuf, KS_END); - break; - case XK_Home: - strcpy (kbuf, KS_HOME); - break; - -#define FKEY(n, fkey) \ - sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey))) - - case XK_F1: /* "\033[11~" */ - case XK_F2: /* "\033[12~" */ - case XK_F3: /* "\033[13~" */ - case XK_F4: /* "\033[14~" */ - case XK_F5: /* "\033[15~" */ - FKEY (11, XK_F1); - break; - case XK_F6: /* "\033[17~" */ - case XK_F7: /* "\033[18~" */ - case XK_F8: /* "\033[19~" */ - case XK_F9: /* "\033[20~" */ - case XK_F10: /* "\033[21~" */ - FKEY (17, XK_F6); - break; - case XK_F11: /* "\033[23~" */ - case XK_F12: /* "\033[24~" */ - case XK_F13: /* "\033[25~" */ - case XK_F14: /* "\033[26~" */ - FKEY (23, XK_F11); - break; - case XK_F15: /* "\033[28~" */ - case XK_F16: /* "\033[29~" */ - FKEY (28, XK_F15); - break; - case XK_Help: /* "\033[28~" */ - FKEY (28, XK_Help); - break; - case XK_Menu: /* "\033[29~" */ - FKEY (29, XK_Menu); - break; - case XK_F17: /* "\033[31~" */ - case XK_F18: /* "\033[32~" */ - case XK_F19: /* "\033[33~" */ - case XK_F20: /* "\033[34~" */ - case XK_F21: /* "\033[35~" */ - case XK_F22: /* "\033[36~" */ - case XK_F23: /* "\033[37~" */ - case XK_F24: /* "\033[38~" */ - case XK_F25: /* "\033[39~" */ - case XK_F26: /* "\033[40~" */ - case XK_F27: /* "\033[41~" */ - case XK_F28: /* "\033[42~" */ - case XK_F29: /* "\033[43~" */ - case XK_F30: /* "\033[44~" */ - case XK_F31: /* "\033[45~" */ - case XK_F32: /* "\033[46~" */ - case XK_F33: /* "\033[47~" */ - case XK_F34: /* "\033[48~" */ - case XK_F35: /* "\033[49~" */ - FKEY (31, XK_F17); - break; -#undef FKEY - default: - newlen = 0; - break; - } - - if (newlen) - len = strlen (kbuf); - } - - /* - * Pass meta for all function keys, if 'meta' option set - */ -#ifdef META8_OPTION - if (meta && (meta_char == 0x80) && len > 0) - kbuf[len - 1] |= 0x80; -#endif - - } - else if (ctrl && keysym == XK_minus) - { - len = 1; - kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ - } - else if (keysym == XK_ISO_Left_Tab) - { - strcpy (kbuf, "\033[Z"); - len = 3; - } - else - { -#ifdef META8_OPTION - /* set 8-bit on */ - if (meta && (meta_char == 0x80)) - { - char *ch; - - for (ch = kbuf; ch < kbuf + len; ch++) - *ch |= 0x80; - - meta = 0; - } -#endif - /* nil */ ; - } } - if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) - return; - if (len <= 0) return; /* not mapped */ - if (option (Opt_scrollTtyKeypress)) - if (view_start) - { - view_start = 0; - want_refresh = 1; - } - - /* - * these modifications only affect the static keybuffer - * pass Shift/Control indicators for function keys ending with `~' - * - * eg, - * Prior = "ESC[5~" - * Shift+Prior = "ESC[5$" - * Ctrl+Prior = "ESC[5^" - * Ctrl+Shift+Prior = "ESC[5@" - * Meta adds an Escape prefix (with META8_OPTION, if meta == ). - */ - if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') - kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); - - /* escape prefix */ - if (meta -#ifdef META8_OPTION - && meta_char == C0_ESC -#endif - ) - { - const char ch = C0_ESC; - tt_write (&ch, 1); - } - - tt_write (kbuf, (unsigned int)len); + tt_write_user_input (kbuf, (unsigned int)len); } -void +void ecb_cold rxvt_term::key_release (XKeyEvent &ev) { #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL @@ -900,7 +903,7 @@ return; } - for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) + for (unsigned short *i = iso14755_symtab; i[0]; i += 2) if (i[0] == keysym) { iso14755buf = ISO_14755_51 | i[1]; @@ -947,48 +950,15 @@ #endif } -#if defined (KEYSYM_RESOURCE) -unsigned int -rxvt_term::cmd_write (const char *str, unsigned int count) -{ - unsigned int n, s; - - n = cmdbuf_ptr - cmdbuf_base; - s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; - - if (n > 0 && s < count) - { - memmove (cmdbuf_base, cmdbuf_ptr, - (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp -= n; - s += n; - } - - if (count > s) - { - rxvt_warn ("data loss: cmd_write too large, continuing.\n"); - count = s; - } - - for (; count--;) - *cmdbuf_endp++ = *str++; - - cmd_parse (); - - return 0; -} -#endif - void rxvt_term::flush () { flush_ev.stop (); -#ifdef HAVE_BG_PIXMAP - if (bgPixmap.check_clearChanged ()) +#ifdef HAVE_IMG + if (bg_flags & BG_NEEDS_REFRESH) { -// scr_clear (true); This needs to be researched further! + bg_flags &= ~BG_NEEDS_REFRESH; scr_touch (false); } #endif @@ -1034,24 +1004,23 @@ } scr_refresh (); - scrollbar_show (1); -#ifdef USE_XIM - IMSendSpot (); + scrollBar.show (1); +#if USE_XIM + im_send_spot (); #endif } display->flush (); } +/* checks whether a refresh is requested and starts the refresh timer */ void -rxvt_term::prepare_cb (ev::prepare &w, int revents) +rxvt_term::refresh_check () { - make_current (); + if (want_refresh && !flush_ev.is_active ()) + flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally display->flush (); - - if (want_refresh && !flush_ev.active) - flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally } void @@ -1065,10 +1034,29 @@ #ifdef CURSOR_BLINK void +rxvt_term::cursor_blink_reset () +{ + if (!focus) + return; + + if (hidden_cursor) + { + hidden_cursor = 0; + want_refresh = 1; + } + + if (option (Opt_cursorBlink) || (priv_modes & PrivMode_BlinkingCursor)) + cursor_blink_ev.again (); + else + cursor_blink_ev.stop (); +} + +void rxvt_term::cursor_blink_cb (ev::timer &w, int revents) { hidden_cursor = !hidden_cursor; want_refresh = 1; + refresh_check (); } #endif @@ -1080,7 +1068,10 @@ { hidden_text = !hidden_text; want_refresh = 1; + refresh_check (); } + else + w.stop (); } #endif @@ -1088,9 +1079,12 @@ void rxvt_term::cont_scroll_cb (ev::timer &w, int revents) { - if ((scrollbar_isUp() || scrollbar_isDn()) && - scr_page (scrollbar_isUp() ? UP : DN, 1)) - want_refresh = 1; + if ((scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN) + && scr_page (scrollBar.state == SB_STATE_UP ? UP : DN, 1)) + { + want_refresh = 1; + refresh_check (); + } else w.stop (); } @@ -1100,10 +1094,11 @@ void rxvt_term::sel_scroll_cb (ev::timer &w, int revents) { - if (scr_page (scroll_selection_dir, scroll_selection_lines)) + if (scr_page (scroll_selection_lines)) { selection_extend (selection_save_x, selection_save_y, selection_save_state); want_refresh = 1; + refresh_check (); } else w.stop (); @@ -1114,17 +1109,17 @@ void rxvt_term::slip_wheel_cb (ev::timer &w, int revents) { - if (mouse_slip_wheel_speed == 0 - || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) - : scr_page (UP, mouse_slip_wheel_speed)) + if (scr_page (mouse_slip_wheel_speed)) { - if (view_start == top_row || view_start == 0) - mouse_slip_wheel_speed = 0; - want_refresh = 1; + refresh_check (); + } + + if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0) + { + mouse_slip_wheel_speed = 0; + w.stop (); } - else - w.stop (); } #endif @@ -1139,8 +1134,11 @@ // that giving a process calling sched_yield () less cpu time than // ones with high nice levels is a useful thing to do. It surely is is // allowed by the sus... as is returning ENOSYS. + // since the linux guys additionally thought that breaking the only + // known workaround against their unusable sched_yield hack is cool, + // we just nanosleep a bit and hope for the best. - struct timespec ts = { 0, 0 }; + struct timespec ts = { 0, 1000 }; nanosleep (&ts, 0); w.stop (); @@ -1153,22 +1151,55 @@ } event_handler; #endif +/* make sure all the cmd data is at beginning of cmdbuf */ +void +rxvt_term::cmdbuf_reify () +{ + if (cmdbuf_ptr == cmdbuf_base) + return; + + ssize_t used = cmdbuf_endp - cmdbuf_ptr; + + memmove (cmdbuf_base, cmdbuf_ptr, used); + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr + used; + +} + +#if defined (KEYSYM_RESOURCE) +void +rxvt_term::cmdbuf_append (const char *str, size_t count) +{ + cmdbuf_reify (); + + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; + + if (count > avail) + return; + + memcpy (cmdbuf_endp, str, count); + cmdbuf_endp += count; + + cmd_parse (); +} +#endif + bool rxvt_term::pty_fill () { - ssize_t n = cmdbuf_endp - cmdbuf_ptr; + cmdbuf_reify (); + + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; - if (CBUFSIZ == n) + if (!avail) { - rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n"); - n = 0; + // normally this indicates a "too long" command sequence - just drop the data we have + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr; + avail = CBUFSIZ; } - memmove (cmdbuf_base, cmdbuf_ptr, n); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp = cmdbuf_ptr + n; - - ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n); + ssize_t r = read (pty->pty, cmdbuf_endp, avail); if (r > 0) { @@ -1200,19 +1231,20 @@ if (revents & ev::READ) // loop, but don't allow a single term to monopolize us - while (pty_fill ()) - if (cmd_parse ()) - break; + for (int i = CBUFCNT; i-- && pty_fill (); ) + cmd_parse (); if (revents & ev::WRITE) pty_write (); + + refresh_check (); } -void +void ecb_cold rxvt_term::pointer_unblank () { XDefineCursor (dpy, vt, TermWin_cursor); - recolour_cursor (); + recolor_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; @@ -1223,7 +1255,7 @@ } #ifdef POINTER_BLANK -void +void ecb_cold rxvt_term::pointer_blank () { if (!option (Opt_pointerBlank)) @@ -1235,7 +1267,7 @@ hidden_pointer = 1; } -void +void ecb_cold rxvt_term::pointer_cb (ev::timer &w, int revents) { make_current (); @@ -1251,12 +1283,14 @@ int x, y; int code = 32; - x = Pixel2Col (ev.x); - y = Pixel2Row (ev.y); + x = Pixel2Col (ev.x) + 1; + y = Pixel2Row (ev.y) + 1; + if (ev.type == MotionNotify) { if (x == mouse_row && y == mouse_col) return; + mouse_row = x; mouse_col = y; code += 32; @@ -1269,7 +1303,7 @@ button_number = MEvent.button - Button1; /* add 0x3D for wheel events, like xterm does */ if (button_number >= 3) - button_number += (64 - 3); + button_number += 64 - 3; } if (priv_modes & PrivMode_MouseX10) @@ -1311,18 +1345,31 @@ fputc ('2', stderr); fprintf (stderr, "]: <%d>, %d/%d\n", button_number, - x + 1, - y + 1); + x, + y); #endif - tt_printf ("\033[M%c%c%c", - (code + button_number + key_state), - (32 + x + 1), - (32 + y + 1)); +#if ENABLE_FRILLS + if (priv_modes & PrivMode_ExtMouseRight) + tt_printf ("\033[%d;%d;%dM", + code + button_number + key_state, + x, + y); + else if (priv_modes & PrivMode_ExtModeMouse) + tt_printf ("\033[M%c%lc%lc", + code + button_number + key_state, + wint_t (32 + x), + wint_t (32 + y)); + else +#endif + tt_printf ("\033[M%c%c%c", + code + button_number + key_state, + 32 + x, + 32 + y); } /*{{{ process an X event */ -void +void ecb_hot rxvt_term::x_cb (XEvent &ev) { make_current (); @@ -1430,14 +1477,44 @@ break; case ConfigureNotify: - /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n", - ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y, - szHint.width, szHint.height); */ - if (ev.xconfigure.window == parent[0]) + if (ev.xconfigure.window == parent) { while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) ; + 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; + + if (ev.xconfigure.send_event) + { + x = ev.xconfigure.x; + y = ev.xconfigure.y; + } + else + get_window_origin (x, y); + + if (x != parent_x || y != parent_y) + { + parent_x = x; + parent_y = y; + HOOK_INVOKE ((this, HOOK_POSITION_CHANGE, DT_INT, x, DT_INT, y, DT_END)); + moved = true; + } + } + if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) { seen_resize = 1; @@ -1446,29 +1523,21 @@ else { #ifdef HAVE_BG_PIXMAP - if (bgPixmap.window_position_sensitive ()) + if (moved) update_background (); #endif } + HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); } break; case PropertyNotify: - if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) - if (ev.xproperty.atom == xa[XA_VT_SELECTION] - && ev.xproperty.state == PropertyNewValue) - selection_property (ev.xproperty.window, ev.xproperty.atom); - + HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)); break; case SelectionClear: - selection_clear (); - break; - - case SelectionNotify: - if (selection_wait == Sel_normal) - selection_paste (ev.xselection.requestor, ev.xselection.property, true); + selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]); break; case SelectionRequest: @@ -1476,9 +1545,20 @@ 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 (TEXT_BLINK_INTERVAL); + text_blink_ev.start (); #endif HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; @@ -1498,7 +1578,7 @@ do { scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + ev.xexpose.width, ev.xexpose.height, false); } while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)); @@ -1507,8 +1587,9 @@ while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) { scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + ev.xexpose.width, ev.xexpose.height, false); } + want_refresh = 1; } else @@ -1520,10 +1601,10 @@ while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) ; - if (isScrollbarWindow (ev.xany.window)) + if (scrollBar.state && ev.xany.window == scrollBar.win) { - scrollBar.setIdle (); - scrollbar_show (0); + scrollBar.state = SB_STATE_IDLE; + scrollBar.show (0); } } break; @@ -1533,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; @@ -1556,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)) @@ -1574,12 +1656,13 @@ if (ev.xbutton.y < int_bwidth || Pixel2Row (ev.xbutton.y) > (nrow-1)) { + page_dirn scroll_selection_dir; int dist; /* don't clobber the current delay if we are * already in the middle of scrolling. */ - if (!sel_scroll_ev.active) + if (!sel_scroll_ev.is_active ()) sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); /* save the event params so we can highlight @@ -1598,7 +1681,7 @@ else { scroll_selection_dir = DN; - dist = ev.xbutton.y - (int_bwidth + height); + dist = ev.xbutton.y - (int_bwidth + vt_height); } scroll_selection_lines = Pixel2Height (dist) @@ -1606,22 +1689,20 @@ + 1; min_it (scroll_selection_lines, SELECTION_SCROLL_MAX_LINES); + scroll_selection_lines *= scroll_selection_dir; } else { /* we are within the text window, so we * shouldn't be scrolling */ - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); } #endif -#ifdef MOUSE_THRESHOLD } -#endif } } - else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) + else if (scrollBar.state == SB_STATE_MOTION && ev.xany.window == scrollBar.win) { while (XCheckTypedWindowEvent (dpy, scrollBar.win, MotionNotify, &ev)) @@ -1632,25 +1713,17 @@ &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, &unused_mask); - scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, - scrollbar_size ()); + scr_move_to (scrollBar.position (ev.xbutton.y) - csrO, + scrollBar.size ()); want_refresh = 1; - scrollbar_show (1); + scrollBar.show (1); } break; } #if defined(CURSOR_BLINK) - if (option (Opt_cursorBlink) && ev.type == KeyPress) - { - if (hidden_cursor) - { - hidden_cursor = 0; - want_refresh = 1; - } - - cursor_blink_ev.again (); - } + if (ev.type == KeyPress) + cursor_blink_reset (); #endif #if defined(POINTER_BLANK) @@ -1666,9 +1739,28 @@ pointer_blank (); } #endif + + refresh_check (); } -void +#if ENABLE_FRILLS +void ecb_cold +rxvt_term::set_urgency (bool enable) +{ + if (enable == urgency_hint) + return; + + if (XWMHints *h = XGetWMHints (dpy, parent)) + { + h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0); + XSetWMHints (dpy, parent, h); + urgency_hint = enable; + XFree (h); + } +} +#endif + +void ecb_cold rxvt_term::focus_in () { if (!focus) @@ -1676,40 +1768,37 @@ focus = 1; want_refresh = 1; - HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); - #if USE_XIM if (Input_Context != NULL) { - IMSetPosition (); + im_set_position (); XSetICFocus (Input_Context); } #endif #if CURSOR_BLINK if (option (Opt_cursorBlink)) - cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL); + cursor_blink_ev.again (); #endif #if OFF_FOCUS_FADING if (rs[Rs_fade]) { pix_colors = pix_colors_focused; - scr_recolour (); + scr_recolor (); } #endif #if ENABLE_FRILLS if (option (Opt_urgentOnBell)) - { - if (XWMHints *h = XGetWMHints(dpy, parent[0])) - { - h->flags &= ~XUrgencyHint; - XSetWMHints (dpy, parent[0], h); - } - } + set_urgency (0); + + if (priv_modes & PrivMode_FocusEvent) + tt_printf ("\x1b[I"); #endif + + HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); } } -void +void ecb_cold rxvt_term::focus_out () { if (focus) @@ -1717,8 +1806,13 @@ focus = 0; want_refresh = 1; - HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); +#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) { @@ -1742,18 +1836,23 @@ if (rs[Rs_fade]) { pix_colors = pix_colors_unfocused; - scr_recolour (); + scr_recolor (); } #endif + + HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); } } -void -rxvt_term::update_fade_color (unsigned int idx) +void ecb_cold +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); @@ -1761,8 +1860,8 @@ #endif } -#if ENABLE_TRANSPARENCY || ENABLE_PERL -void +#if BG_IMAGE_FROM_ROOT || ENABLE_PERL +void ecb_hot rxvt_term::rootwin_cb (XEvent &ev) { make_current (); @@ -1771,7 +1870,6 @@ && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END))) return; -# if ENABLE_TRANSPARENCY switch (ev.type) { case PropertyNotify: @@ -1782,12 +1880,20 @@ if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID] || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) { - bgPixmap.set_root_pixmap (); - update_background (); +#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)); } + break; } -# endif + + refresh_check (); } #endif @@ -1818,7 +1924,7 @@ } #endif - clickintime = ev.time - MEvent.time < MULTICLICK_TIME; + clickintime = ev.time - MEvent.time < multiClickTime; if (reportmode) { @@ -1828,7 +1934,7 @@ #ifdef MOUSE_REPORT_DOUBLECLICK if (ev.button == MEvent.button && clickintime) { - /* same button, within alloted time */ + /* same button, within allowed time */ MEvent.clicks++; if (MEvent.clicks > 1) @@ -1910,9 +2016,16 @@ /* * Scrollbar window processing of button press */ - if (isScrollbarWindow (ev.window)) + if (scrollBar.state && ev.window == scrollBar.win) { - scrollBar.setIdle (); + page_dirn direction = NO_DIR; + + if (scrollBar.upButton (ev.y)) + direction = UP; /* up */ + else if (scrollBar.dnButton (ev.y)) + direction = DN; /* down */ + + scrollBar.state = SB_STATE_IDLE; /* * Rxvt-style scrollbar: * move up if mouse is above slider @@ -1931,15 +2044,9 @@ * arrow buttons - send up/down * click on scrollbar - send pageup/down */ - if ((scrollBar.style == R_SB_NEXT - && scrollbarnext_upButton (ev.y)) - || (scrollBar.style == R_SB_RXVT - && scrollbarrxvt_upButton (ev.y))) + if (direction == UP) tt_printf ("\033[A"); - else if ((scrollBar.style == R_SB_NEXT - && scrollbarnext_dnButton (ev.y)) - || (scrollBar.style == R_SB_RXVT - && scrollbarrxvt_dnButton (ev.y))) + else if (direction == DN) tt_printf ("\033[B"); else switch (ev.button) @@ -1957,91 +2064,75 @@ } else #endif /* NO_SCROLLBAR_REPORT */ - { - char upordown = 0; - - if (scrollBar.style == R_SB_NEXT) - { - if (scrollbarnext_upButton (ev.y)) - upordown = -1; /* up */ - else if (scrollbarnext_dnButton (ev.y)) - upordown = 1; /* down */ - } - else if (scrollBar.style == R_SB_RXVT) - { - if (scrollbarrxvt_upButton (ev.y)) - upordown = -1; /* up */ - else if (scrollbarrxvt_dnButton (ev.y)) - upordown = 1; /* down */ - } - if (upordown) + if (direction != NO_DIR) { #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); + if (!cont_scroll_ev.is_active ()) + cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); #endif - if (scr_page (upordown < 0 ? UP : DN, 1)) + if (scr_page (direction, 1)) { - if (upordown < 0) - scrollBar.setUp (); + if (direction == UP) + scrollBar.state = SB_STATE_UP; else - scrollBar.setDn (); + scrollBar.state = SB_STATE_DOWN; } } else switch (ev.button) { case Button2: - switch (scrollbar_align) + switch (scrollBar.align) { - case R_SB_ALIGN_TOP: + case SB_ALIGN_TOP: csrO = 0; break; - case R_SB_ALIGN_CENTRE: + case SB_ALIGN_CENTRE: csrO = (scrollBar.bot - scrollBar.top) / 2; break; - case R_SB_ALIGN_BOTTOM: + case SB_ALIGN_BOTTOM: csrO = scrollBar.bot - scrollBar.top; break; } - if (scrollBar.style == R_SB_XTERM - || scrollbar_above_slider (ev.y) - || scrollbar_below_slider (ev.y)) - scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); + if (scrollBar.style == SB_STYLE_XTERM + || scrollBar.above_slider (ev.y) + || scrollBar.below_slider (ev.y)) + scr_move_to (scrollBar.position (ev.y) - csrO, scrollBar.size ()); - scrollBar.setMotion (); + scrollBar.state = SB_STATE_MOTION; break; case Button1: - if (scrollbar_align == R_SB_ALIGN_CENTRE) + if (scrollBar.align == SB_ALIGN_CENTRE) csrO = ev.y - scrollBar.top; /* FALLTHROUGH */ case Button3: - if (scrollBar.style != R_SB_XTERM) + if (scrollBar.style != SB_STYLE_XTERM) { - if (scrollbar_above_slider (ev.y)) + if (scrollBar.above_slider (ev.y)) # ifdef RXVT_SCROLL_FULL scr_page (UP, nrow - 1); # else scr_page (UP, nrow / 4); # endif - else if (scrollbar_below_slider (ev.y)) + else if (scrollBar.below_slider (ev.y)) # ifdef RXVT_SCROLL_FULL scr_page (DN, nrow - 1); # else scr_page (DN, nrow / 4); # endif else - scrollBar.setMotion (); + scrollBar.state = SB_STATE_MOTION; } else { scr_page ((ev.button == Button1 ? DN : UP), (nrow - * scrollbar_position (ev.y) - / scrollbar_size ())); + * scrollBar.position (ev.y) + / scrollBar.size ())); } break; @@ -2061,15 +2152,14 @@ if (!bypass_keystate) reportmode = !! (priv_modes & PrivMode_mouse_report); - if (scrollbar_isUpDn ()) + if (scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN) { - scrollBar.setIdle (); - scrollbar_show (0); + scrollBar.state = SB_STATE_IDLE; + scrollBar.show (0); } #ifdef SELECTION_SCROLLING - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); #endif if (ev.window == vt) @@ -2094,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; @@ -2124,43 +2214,41 @@ break; case Button2: - if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? - selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); + if (IN_RANGE_EXC (ev.x, 0, vt_width) && IN_RANGE_EXC (ev.y, 0, vt_height)) // inside window? + selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); break; #ifdef MOUSE_WHEEL case Button4: case Button5: { - int i; - page_dirn v; + int lines; + page_dirn dirn; - v = ev.button == Button4 ? UP : DN; + dirn = ev.button == Button4 ? UP : DN; if (ev.state & ShiftMask) - i = 1; + lines = 1; else if (option (Opt_mouseWheelScrollPage)) - i = nrow - 1; + lines = nrow - 1; else - i = 5; + lines = 5; # ifdef MOUSE_SLIP_WHEELING if (ev.state & ControlMask) { - mouse_slip_wheel_speed += v ? -1 : 1; - if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; - if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; + mouse_slip_wheel_speed += dirn; + clamp_it (mouse_slip_wheel_speed, -nrow, nrow); - slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); + if (!slip_wheel_ev.is_active ()) + slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); } else - { # endif - scr_page (v, i); - scrollbar_show (1); -# ifdef MOUSE_SLIP_WHEELING + { + scr_page (dirn, lines); + scrollBar.show (1); } -# endif } break; #endif @@ -2170,16 +2258,15 @@ /*}}} */ -bool +void ecb_hot rxvt_term::cmd_parse () { - bool flag = false; wchar_t ch = NOCHAR; char *seq_begin; // remember start of esc-sequence here for (;;) { - if (ch == NOCHAR) + if (ecb_unlikely (ch == NOCHAR)) { seq_begin = cmdbuf_ptr; ch = next_char (); @@ -2188,9 +2275,9 @@ break; } - if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) + if (ecb_likely (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)) { - if (!seen_input) + if (ecb_unlikely (!seen_input)) { seen_input = 1; // many badly-written programs (e.g. jed) contain a race condition: @@ -2213,12 +2300,12 @@ for (;;) { - if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) + if (ecb_unlikely (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))) break; *str++ = ch; - if (ch == C0_LF || str >= eol) + if (ecb_unlikely (ch == C0_LF || str >= eol)) { if (ch == C0_LF) nlines++; @@ -2277,11 +2364,9 @@ */ if (refreshnow) { - flag = true; scr_refresh (); want_refresh = 1; } - } else { @@ -2299,18 +2384,16 @@ ch = NOCHAR; } } - - return flag; } // read the next character -wchar_t +wchar_t ecb_hot rxvt_term::next_char () NOTHROW { while (cmdbuf_ptr < cmdbuf_endp) { // assume 7-bit to be ascii ALWAYS - if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) + if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) return *cmdbuf_ptr++; wchar_t wc; @@ -2324,7 +2407,12 @@ } if (len == (size_t)-1) - return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + { + mbstate.reset (); // reset now undefined conversion state + // a -1 might indicate that a previous incomplete char is invalid (previous return -2) + // in which case we "erroneously" return the next byte which might be valid. + return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + } // assume wchar == unicode cmdbuf_ptr += len; @@ -2335,7 +2423,7 @@ } // read the next octet -uint32_t +uint32_t ecb_hot rxvt_term::next_octet () NOTHROW { return cmdbuf_ptr < cmdbuf_endp @@ -2345,12 +2433,7 @@ static class out_of_input out_of_input; -/* rxvt_cmd_getc () - Return next input character */ -/* - * Return the next input character after first passing any keyboard input - * to the command. - */ -wchar_t +wchar_t ecb_hot rxvt_term::cmd_getc () THROW ((class out_of_input)) { wchar_t c = next_char (); @@ -2361,7 +2444,7 @@ return c; } -uint32_t +uint32_t ecb_hot rxvt_term::cmd_get8 () THROW ((class out_of_input)) { uint32_t c = next_octet (); @@ -2375,10 +2458,10 @@ /*{{{ print pipe */ /*----------------------------------------------------------------------*/ #ifdef PRINTPIPE -FILE * +FILE * ecb_cold rxvt_term::popen_printer () { - FILE *stream = popen (rs[Rs_print_pipe], "w"); + FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w"); if (stream == NULL) rxvt_warn ("can't open printer pipe, not printing.\n"); @@ -2386,7 +2469,7 @@ return stream; } -int +int ecb_cold rxvt_term::pclose_printer (FILE *stream) { fflush (stream); @@ -2396,20 +2479,19 @@ /* * simulate attached vt100 printer */ -void +void ecb_cold rxvt_term::process_print_pipe () { - int done; - FILE *fd; + FILE *fd = popen_printer (); - if ((fd = popen_printer ()) == NULL) + if (!fd) return; /* * Send all input to the printer until either ESC[4i or ESC[?4i * is received. */ - for (done = 0; !done;) + for (int done = 0; !done; ) { unsigned char buf[8]; unicode_t ch; @@ -2453,7 +2535,6 @@ #endif /* PRINTPIPE */ /*}}} */ -/* *INDENT-OFF* */ enum { C1_40 = 0x40, C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, @@ -2461,10 +2542,9 @@ C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, }; -/* *INDENT-ON* */ /*{{{ process non-printing single characters */ -void +void ecb_hot rxvt_term::process_nonprinting (unicode_t ch) { switch (ch) @@ -2504,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 @@ -2520,7 +2600,7 @@ /*{{{ process VT52 escape sequences */ -void +void ecb_cold rxvt_term::process_escape_vt52 (unicode_t ch) { int row, col; @@ -2564,7 +2644,7 @@ tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ break; case '<': /* turn off VT52 mode */ - PrivMode (0, PrivMode_vt52); + priv_modes &= ~PrivMode_vt52; break; case 'F': /* use special graphics character set */ case 'G': /* use regular character set */ @@ -2580,7 +2660,7 @@ /*{{{ process escape sequences */ -void +void ecb_hot rxvt_term::process_escape_seq () { unicode_t ch = cmd_getc (); @@ -2593,7 +2673,6 @@ switch (ch) { - /* case 1: do_tek_mode (); break; */ case '#': if (cmd_getc () == '8') scr_E (); @@ -2626,9 +2705,12 @@ scr_forwardindex (); break; #endif + // DECPAM/DECPNM case '=': + priv_modes |= PrivMode_aplKP; + break; case '>': - PrivMode ((ch == '='), PrivMode_aplKP); + priv_modes &= ~PrivMode_aplKP; break; case C1_40: @@ -2642,13 +2724,15 @@ case C1_NEL: /* ESC E */ { wchar_t nlcr[] = { C0_LF, C0_CR }; - scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1); + scr_add_lines (nlcr, ecb_array_length (nlcr), 1); } break; /* kidnapped escape sequence: Should be 8.3.48 */ case C1_ESA: /* ESC G */ - process_graphics (); + // used by original rxvt for rob nations own graphics mode + if (cmd_getc () == 'Q') + tt_printf ("\033G0\012"); /* query graphics - no graphics */ break; /* 8.3.63: CHARACTER TABULATION SET */ @@ -2662,10 +2746,10 @@ break; /* 8.3.142: SINGLE-SHIFT TWO */ - /*case C1_SS2: scr_single_shift (2); break; */ + /* case C1_SS2: break; */ /* 8.3.143: SINGLE-SHIFT THREE */ - /*case C1_SS3: scr_single_shift (3); break; */ + /* case C1_SS3: break; */ /* 8.3.27: DEVICE CONTROL STRING */ case C1_DCS: /* ESC P */ @@ -2677,21 +2761,21 @@ tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); break; /* steal obsolete ESC [ c */ - /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ + /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */ case C1_CSI: /* ESC [ */ process_csi_seq (); break; - /* 8.3.90: OPERATING SYSTEM COMMAND */ + /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */ case C1_OSC: /* ESC ] */ process_osc_seq (); break; - /* 8.3.106: RESET TO INITIAL STATE */ + /* 8.3.106: RESET TO INITIAL STATE (RIS) */ case 'c': mbstate.reset (); scr_poweron (); - scrollbar_show (1); + scrollBar.show (1); break; /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ @@ -2708,7 +2792,6 @@ /*}}} */ /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ -/* *INDENT-OFF* */ enum { CSI_ICH = 0x40, CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, @@ -2721,13 +2804,13 @@ CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F }; -#define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \ +#define make_byte(b0,b1,b2,b3,b4,b5,b6,b7) \ (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \ | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0)) #define get_byte_array_bit(array, bit) \ - (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7)))) + (!! ((array)[(bit) >> 3] & (1 << ((bit) & 7)))) -const unsigned char csi_defaults[] = +static const unsigned char csi_defaults[] = { make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */ make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */ @@ -2738,12 +2821,11 @@ make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ }; -/* *INDENT-ON* */ -void +void ecb_hot rxvt_term::process_csi_seq () { - unicode_t ch, priv, i; + unicode_t ch, priv, prev_ch, i; unsigned int nargs, p; int n, ndef; int arg[ESC_ARGS] = { }; @@ -2752,13 +2834,14 @@ priv = 0; ch = cmd_getc (); - if (ch >= '<' && ch <= '?') + if ((ch >= '<' && ch <= '?') || ch == '!') { - /* '<' '=' '>' '?' */ + /* '<' '=' '>' '?' '!' */ priv = ch; ch = cmd_getc (); } + prev_ch = 0; /* read any numerical arguments */ for (n = -1; ch < CSI_ICH; ) { @@ -2778,6 +2861,7 @@ else if (IS_CONTROL (ch)) process_nonprinting (ch); + prev_ch = ch; ch = cmd_getc (); } @@ -2813,11 +2897,27 @@ tt_printf ("\033[>%d;95;0c", 'U'); } break; + case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') process_terminal_mode (ch, priv, nargs, arg); break; + + case '!': + if (ch == CSI_70) + { + /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */ + 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 }; + + process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h); + process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l); + } + break; } + return; } @@ -2841,11 +2941,11 @@ #endif case CSI_CUU: /* 8.3.22: (1) CURSOR UP */ - case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ + case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ arg[0] = -arg[0]; /* FALLTHROUGH */ case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */ - case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ + case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ scr_gotorc (arg[0], 0, RELATIVE); break; @@ -3005,6 +3105,11 @@ priv_modes |= PrivMode_LFNL; break; + case CSI_71: // DECSCUSR: set cursor style + if (prev_ch == ' ') + set_cursor_style (arg[0]); + break; + /* * PRIVATE USE beyond this point. All CSI_7? sequences here */ @@ -3042,7 +3147,6 @@ /*}}} */ #if !ENABLE_MINIMAL -/* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) { @@ -3061,22 +3165,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (dpy, parent[0]); + XMapWindow (dpy, parent); break; case 2: /* iconify window */ - XIconifyWindow (dpy, parent[0], display->screen); + XIconifyWindow (dpy, parent, display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (dpy, parent[0], args[1], args[2]); + XMoveWindow (dpy, parent, args[1], args[2]); break; case 4: /* set size (pixels) */ set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); break; case 5: /* raise window */ - XRaiseWindow (dpy, parent[0]); + XRaiseWindow (dpy, parent); break; case 6: /* lower window */ - XLowerWindow (dpy, parent[0]); + XLowerWindow (dpy, parent); break; case 7: /* refresh window */ scr_touch (true); @@ -3089,7 +3193,7 @@ //case 9: NYI, TODO, restore maximized window or maximize window default: if (args[0] >= 24) /* set height (chars) */ - set_widthheight ((unsigned int)width, + set_widthheight ((unsigned int)vt_width, (unsigned int) (args[1] * fheight)); break; @@ -3097,18 +3201,18 @@ * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (dpy, parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (dpy, parent[0], &wattr); - XTranslateCoordinates (dpy, parent[0], wattr.root, + XGetWindowAttributes (dpy, parent, &wattr); + XTranslateCoordinates (dpy, parent, wattr.root, -wattr.border_width, -wattr.border_width, &x, &y, &wdummy); tt_printf ("\033[3;%d;%dt", x, y); break; case 14: /* report window size (pixels) */ - XGetWindowAttributes (dpy, parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ @@ -3120,7 +3224,7 @@ case 20: /* report icon label */ { char *s; - XGetIconName (dpy, parent[0], &s); + XGetIconName (dpy, parent, &s); tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3128,7 +3232,7 @@ case 21: /* report window title */ { char *s; - XFetchName (dpy, parent[0], &s); + XFetchName (dpy, parent, &s); tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3148,7 +3252,7 @@ unicode_t ch; bool seen_esc = false; unsigned int n = 0; - wchar_t string[STRING_MAX]; + wchar_t string[CBUFSIZ]; while ((ch = cmd_getc ()) != NOCHAR) { @@ -3173,7 +3277,7 @@ seen_esc = false; - if (n >= STRING_MAX - 1) + if (n >= sizeof (string) - 1) // stop at some sane length return NULL; @@ -3194,13 +3298,12 @@ void rxvt_term::process_dcs_seq () { - char *s; - unicode_t eh; - /* * Not handled yet */ - s = get_to_st (eh); + + unicode_t eh; + char *s = get_to_st (eh); if (s) free (s); @@ -3214,15 +3317,15 @@ void rxvt_term::process_osc_seq () { - unicode_t ch, eh; int arg; - ch = cmd_getc (); + unicode_t ch = cmd_getc (); for (arg = 0; isdigit (ch); ch = cmd_getc ()) arg = arg * 10 + (ch - '0'); if (ch == ';') { + unicode_t eh; char *s = get_to_st (eh); if (s) @@ -3233,6 +3336,31 @@ } } +/* + * 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) +{ + unsigned int idx_r = (r & 0xff) / (0xff / (Red_levels - 1)); + unsigned int idx_g = (g & 0xff) / (0xff / (Green_levels - 1)); + unsigned int idx_b = (b & 0xff) / (0xff / (Blue_levels - 1)); + unsigned int idx; + + idx = minTermCOLOR24 + idx_r * Blue_levels * Green_levels + + idx_g * Blue_levels + + idx_b; + + 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) { @@ -3243,7 +3371,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); @@ -3256,7 +3384,7 @@ * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) */ void -rxvt_term::process_xterm_seq (int op, const char *str, char resp) +rxvt_term::process_xterm_seq (int op, char *str, char resp) { int color; char *buf, *name; @@ -3293,7 +3421,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (dpy, parent[0], + && XGetWindowProperty (dpy, parent, prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3301,13 +3429,13 @@ && actual_format == 8) str = (const char *)(value); - tt_printf ("\033]%d;%s%c", op, str, resp); + tt_printf ("\033]%d;%s%c", op, option (Opt_insecure) ? str : "", resp); XFree (value); } else { - char *eq = strchr (str, '='); // constness lost, but verified to be ok + char *eq = strchr (str, '='); if (eq) { @@ -3315,7 +3443,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (dpy, parent[0], + XDeleteProperty (dpy, parent, display->atom (str)); } break; @@ -3338,9 +3466,11 @@ process_color_seq (op, color, name, resp); } break; + case Rxvt_restoreFG: case XTerm_Color00: process_color_seq (op, Color_fg, str, resp); break; + case Rxvt_restoreBG: case XTerm_Color01: process_color_seq (op, Color_bg, str, resp); break; @@ -3355,15 +3485,18 @@ case XTerm_Color_pointer_bg: process_color_seq (op, Color_pointer_bg, str, resp); break; -#ifndef NO_BOLD_UNDERLINE_REVERSE - case XTerm_Color_RV: - process_color_seq (op, Color_RV, str, resp); +#ifdef OPTION_HC + case XTerm_Color_HC: + process_color_seq (op, Color_HC, str, resp); + break; + case XTerm_Color_HTC: + process_color_seq (op, Color_HTC, str, resp); break; - case Rxvt_Color_BD: +#endif +#ifndef NO_BOLD_UNDERLINE_REVERSE case URxvt_Color_BD: process_color_seq (op, Color_BD, str, resp); break; - case Rxvt_Color_UL: case URxvt_Color_UL: process_color_seq (op, Color_UL, str, resp); break; @@ -3371,15 +3504,19 @@ process_color_seq (op, Color_IT, str, resp); break; #endif -#if ENABLE_TRANSPARENCY + case URxvt_Color_border: + 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 = bgPixmap.set_tint (pix_colors_focused [Color_tint]); - else - changed = bgPixmap.unset_tint (); + changed = root_effects.set_tint (pix_colors_focused [Color_tint]); + if (changed) update_background (); } @@ -3392,46 +3529,53 @@ if (!strcmp (str, "?")) { char str[256]; - - sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ - min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767), - min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767)); + 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 { - int changed = 0; + bool changed = false; if (*str != ';') { - /* reset to default scaling :*/ - bgPixmap.unset_geometry (); - if (bgPixmap.set_file (str)) /* change pixmap */ - changed++; - str = strchr (str, ';'); - if (str == NULL) - bgPixmap.set_defaultGeometry (); + try + { + fimage.set_file_geometry (this, str); + changed = true; + } + catch (const class rxvt_failure_exception &e) + { + } } - while (str) + else { str++; - if (bgPixmap.set_geometry (str)) - changed++; - str = strchr (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 Rxvt_restoreFG: - set_window_color (Color_fg, str); - break; - case Rxvt_restoreBG: - set_window_color (Color_bg, str); - break; - case XTerm_logfile: // TODO, when secure mode? break; @@ -3507,8 +3651,7 @@ #if ENABLE_PERL case URxvt_perl: - if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) - ; // no responses yet + HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END)); break; #endif } @@ -3525,14 +3668,17 @@ * 't' = toggle * so no need for fancy checking */ -int +int ecb_cold rxvt_term::privcases (int mode, unsigned long bit) { int state; if (mode == 's') { - SavedModes |= (priv_modes & bit); + if (priv_modes & bit) + SavedModes |= bit; + else + SavedModes &= ~bit; return -1; } else @@ -3541,7 +3687,11 @@ state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ else state = (mode == 't') ? ! (priv_modes & bit) : mode; - PrivMode (state, bit); + + if (state) + priv_modes |= bit; + else + priv_modes &= ~bit; } return state; @@ -3549,7 +3699,7 @@ /* we're not using priv _yet_ */ void -rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg) +rxvt_term::process_terminal_mode (int mode, int priv ecb_unused, unsigned int nargs, const int *arg) { unsigned int i, j; int state; @@ -3559,42 +3709,53 @@ const int argval; const unsigned long bit; } argtopriv[] = { - { 1, PrivMode_aplCUR }, - { 2, PrivMode_vt52 }, - { 3, PrivMode_132 }, - { 4, PrivMode_smoothScroll }, - { 5, PrivMode_rVideo }, - { 6, PrivMode_relOrigin }, - { 7, PrivMode_Autowrap }, - // 8, bi-directional support mode + { 1, PrivMode_aplCUR }, // DECCKM + { 2, PrivMode_vt52 }, // DECANM + { 3, PrivMode_132 }, // DECCOLM + { 4, PrivMode_smoothScroll }, // DECSCLM + { 5, PrivMode_rVideo }, // DECSCNM + { 6, PrivMode_relOrigin }, // DECOM + { 7, PrivMode_Autowrap }, // DECAWM + // 8, auto-repeat keys // DECARM { 9, PrivMode_MouseX10 }, - // 18, 19 printing-related - { 25, PrivMode_VisibleCursor }, + { 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 #ifdef scrollBar_esc { scrollBar_esc, PrivMode_scrollBar }, #endif - { 35, PrivMode_ShiftKeys }, // rxvt extension + { 35, PrivMode_ShiftKeys }, // rxvt extension + // 38, tektronix mode // DECTEK { 40, PrivMode_132OK }, // 41 xterm more fixes NYI // 45 margin bell NYI // 46 start logging { 47, PrivMode_Screen }, - { 66, PrivMode_aplKP }, + { 66, PrivMode_aplKP }, // DECNKM #ifndef NO_BACKSPACE_KEY - { 67, PrivMode_BackSpace }, + { 67, PrivMode_BackSpace }, // DECBKM #endif { 1000, PrivMode_MouseX11 }, { 1002, PrivMode_MouseBtnEvent }, { 1003, PrivMode_MouseAnyEvent }, +#if ENABLE_FRILLS + { 1004, PrivMode_FocusEvent }, + { 1005, PrivMode_ExtModeMouse }, +#endif { 1010, PrivMode_TtyOutputInh }, // rxvt extension { 1011, PrivMode_Keypress }, // rxvt extension +#if ENABLE_FRILLS + { 1015, PrivMode_ExtMouseRight }, // urxvt extension of 1005 +#endif // 1035 enable modifiers for alt, numlock NYI // 1036 send ESC for meta keys NYI // 1037 send DEL for keypad delete NYI { 1047, PrivMode_Screen }, - // 1048 save and restore cursor + // 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 + { 2004, PrivMode_BracketPaste }, }; if (nargs == 0) @@ -3611,7 +3772,7 @@ state = -1; /* basic handling */ - for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++) + for (j = 0; j < ecb_array_length (argtopriv); j++) if (argtopriv[j].argval == arg[i]) { state = privcases (mode, argtopriv[j].bit); @@ -3629,7 +3790,6 @@ break; #endif case 1048: /* alternative cursor save */ - case 1049: if (option (Opt_secondaryScreen)) if (mode == 0) scr_cursor (RESTORE); @@ -3648,11 +3808,11 @@ * parameter. Return from VT52 mode with an ESC < from * within VT52 mode */ - PrivMode (1, PrivMode_vt52); + priv_modes |= PrivMode_vt52; break; case 3: /* 80/132 */ if (priv_modes & PrivMode_132OK) - set_widthheight (((state ? 132 : 80) * fwidth), height); + set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight); break; case 4: /* smooth scrolling */ set_option (Opt_jumpScroll, !state); @@ -3673,11 +3833,14 @@ break; #ifdef scrollBar_esc case scrollBar_esc: - if (scrollbar_mapping (state)) - { - resize_all_windows (0, 0, 0); - scr_touch (true); - } + scrollBar.map (state); + resize_all_windows (0, 0, 0); + scr_touch (true); + break; +#endif +#ifdef CURSOR_BLINK + case 12: + cursor_blink_reset (); break; #endif case 25: /* visible/invisible cursor */ @@ -3700,10 +3863,12 @@ { priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11); priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent; + mouse_row = mouse_col = 0; vt_emask_mouse = PointerMotionMask; } else vt_emask_mouse = NoEventMask; + vt_select_input (); break; case 1010: /* scroll to bottom on TTY output inhibit */ @@ -3714,15 +3879,23 @@ break; case 1047: /* secondary screen w/ clearing last */ if (option (Opt_secondaryScreen)) - if (current_screen != PRIMARY) + if (!state) scr_erase_screen (2); + scr_change_screen (state); break; case 1049: /* secondary screen w/ clearing first */ + if (option (Opt_secondaryScreen)) + if (state) + scr_cursor (SAVE); + scr_change_screen (state); + if (option (Opt_secondaryScreen)) - if (current_screen != PRIMARY) + if (state) scr_erase_screen (2); + else + scr_cursor (RESTORE); break; default: break; @@ -3732,7 +3905,7 @@ /*}}} */ /*{{{ process sgr sequences */ -void +void ecb_hot rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) { unsigned int i; @@ -3784,22 +3957,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 @@ -3830,6 +4003,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); @@ -3851,6 +4033,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); @@ -3883,28 +4074,32 @@ } } } -/*}}} */ -/*{{{ (do not) process Rob Nation's own graphics mode sequences */ void -rxvt_term::process_graphics () +rxvt_term::set_cursor_style (int style) { - unicode_t ch, cmd = cmd_getc (); + if (!IN_RANGE_INC (style, 0, 6)) + return; - if (cmd == 'Q') - { - /* query graphics */ - tt_printf ("\033G0\012"); /* no graphics */ - return; - } - /* swallow other graphics sequences until terminating ':' */ - do - ch = cmd_getc (); - while (ch != ':'); + 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 & 1); + cursor_blink_reset (); +#endif + + want_refresh = 1; } /*}}} */ -/* ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- */ +/* Write data to the pty as typed by the user, pasted with the mouse, + * or generated by us in response to a query ESC sequence. + */ /* * Send printf () formatted output to the command. @@ -3922,11 +4117,22 @@ tt_write (buf, strlen (buf)); } -/* ---------------------------------------------------------------------- */ -/* Write data to the pty as typed by the user, pasted with the mouse, - * or generated by us in response to a query ESC sequence. - */ -const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT +/* Write data to the pty as typed by the user. */ +void +rxvt_term::tt_write_user_input (const char *data, unsigned int len) +{ + if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) + return; + + if (option (Opt_scrollTtyKeypress)) + if (view_start) + { + view_start = 0; + want_refresh = 1; + } + + tt_write_ (data, len); +} void rxvt_term::tt_write (const char *data, unsigned int len) @@ -3934,6 +4140,14 @@ if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) return; + tt_write_ (data, len); +} + +static const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT + +void +rxvt_term::tt_write_ (const char *data, unsigned int len) +{ if (pty->pty < 0) return; @@ -3941,14 +4155,16 @@ { ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE)); - if ((unsigned int)written == len) + max_it (written, 0); + + if (written == len) return; data += written; len -= written; } - v_buffer = (char *)realloc (v_buffer, v_buflen + len); + v_buffer = (char *)rxvt_realloc (v_buffer, v_buflen + len); memcpy (v_buffer + v_buflen, data, len); v_buflen += len;