--- rxvt-unicode/src/command.C 2008/02/16 13:36:10 1.408 +++ rxvt-unicode/src/command.C 2008/10/10 13:23:56 1.419 @@ -336,6 +336,65 @@ return keysym; } +static inline int +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; +#ifndef UNSHIFTED_SCROLLKEYS + case XK_Prior: + param = 5; + break; + case XK_Next: + param = 6; + break; + case XK_Home: + param = 7; + break; + case XK_End: + param = 8; + break; +#endif + case XK_Help: + param = 28; + break; + case XK_Menu: + param = 29; + break; + } + return param; +} + void rxvt_term::key_press (XKeyEvent &ev) { @@ -362,7 +421,7 @@ if (numlock_state || (ev.state & ModNumLockMask)) { numlock_state = (ev.state & ModNumLockMask); - PrivMode ((!numlock_state), PrivMode_aplKP); + set_privmode (PrivMode_aplKP, !numlock_state); } kbuf[0] = 0; @@ -584,218 +643,137 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { - bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; - unsigned int newlen = 1; + bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; + unsigned int newlen = 1; - switch (translate_keypad (keysym, kp)) - { + switch (translate_keypad (keysym, kp)) + { #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; + 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; + case XK_Delete: + strcpy (kbuf, rs[Rs_delete_key]); + break; #endif - case XK_Tab: - if (shft) - strcpy (kbuf, "\033[Z"); - else - { + case XK_Tab: + if (shft) + strcpy (kbuf, "\033[Z"); + else + { #ifdef CTRL_TAB_MAKES_META - if (ctrl) - meta = 1; + if (ctrl) + meta = 1; #endif #ifdef MOD4_TAB_MAKES_META - if (ev.state & Mod4Mask) - meta = 1; + 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 */ + newlen = 0; + } + break; - 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_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_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); + case XK_KP_Enter: + /* allow shift to override */ + if (kp) + { + strcpy (kbuf, "\033OM"); 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; + /* FALLTHROUGH */ - case XK_Find: - strcpy (kbuf, "\033[1~"); - break; + 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_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; + 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; -#define FKEY(n, fkey) \ - sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey))) + 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_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: + default: + { + int param = map_function_key (keysym); + if (param > 0) + sprintf (kbuf,"\033[%d~", param); + else newlen = 0; - break; } + break; + } - if (newlen) - len = strlen (kbuf); + if (newlen) + len = strlen (kbuf); /* * Pass meta for all function keys, if 'meta' option set @@ -1039,7 +1017,7 @@ } scr_refresh (); - scrollbar_show (1); + scrollBar.show (1); #ifdef USE_XIM IMSendSpot (); #endif @@ -1560,7 +1538,7 @@ if (scrollBar.state && ev.xany.window == scrollBar.win) { scrollBar.state = STATE_IDLE; - scrollbar_show (0); + scrollBar.show (0); } } break; @@ -1669,9 +1647,9 @@ &ev.xbutton.x, &ev.xbutton.y, &unused_mask); scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, - scrollbar_size ()); + scrollBar.size ()); want_refresh = 1; - scrollbar_show (1); + scrollBar.show (1); } break; } @@ -2034,7 +2012,7 @@ 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 ()); + scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ()); scrollBar.state = STATE_MOTION; break; @@ -2067,7 +2045,7 @@ scr_page ((ev.button == Button1 ? DN : UP), (nrow * scrollbar_position (ev.y) - / scrollbar_size ())); + / scrollBar.size ())); } break; @@ -2090,7 +2068,7 @@ if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN) { scrollBar.state = STATE_IDLE; - scrollbar_show (0); + scrollBar.show (0); } #ifdef SELECTION_SCROLLING @@ -2183,7 +2161,7 @@ # endif { scr_page (v, i); - scrollbar_show (1); + scrollBar.show (1); } } break; @@ -2203,7 +2181,7 @@ for (;;) { - if (ch == NOCHAR) + if (expect_false (ch == NOCHAR)) { seq_begin = cmdbuf_ptr; ch = next_char (); @@ -2212,9 +2190,9 @@ break; } - if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) + if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)) { - if (!seen_input) + if (expect_false (!seen_input)) { seen_input = 1; // many badly-written programs (e.g. jed) contain a race condition: @@ -2237,12 +2215,12 @@ for (;;) { - if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) + if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))) break; *str++ = ch; - if (ch == C0_LF || str >= eol) + if (expect_false (ch == C0_LF || str >= eol)) { if (ch == C0_LF) nlines++; @@ -2334,7 +2312,7 @@ while (cmdbuf_ptr < cmdbuf_endp) { // assume 7-bit to be ascii ALWAYS - if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) + if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) return *cmdbuf_ptr++; wchar_t wc; @@ -2348,7 +2326,10 @@ } if (len == (size_t)-1) - return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + { + mbrtowc (0, 0, 0, mbstate); // reset now undefined conversion state + return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + } // assume wchar == unicode cmdbuf_ptr += len; @@ -2402,7 +2383,7 @@ FILE * 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"); @@ -2423,17 +2404,16 @@ void 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; @@ -2588,7 +2568,7 @@ tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ break; case '<': /* turn off VT52 mode */ - PrivMode (0, PrivMode_vt52); + set_privmode (PrivMode_vt52, 0); break; case 'F': /* use special graphics character set */ case 'G': /* use regular character set */ @@ -2652,7 +2632,7 @@ #endif case '=': case '>': - PrivMode ((ch == '='), PrivMode_aplKP); + set_privmode (PrivMode_aplKP, ch == '='); break; case C1_40: @@ -2715,7 +2695,7 @@ case 'c': mbstate.reset (); scr_poweron (); - scrollbar_show (1); + scrollBar.show (1); break; /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ @@ -3531,8 +3511,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 } @@ -3565,7 +3544,7 @@ state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ else state = (mode == 't') ? ! (priv_modes & bit) : mode; - PrivMode (state, bit); + set_privmode (bit, state); } return state; @@ -3673,7 +3652,7 @@ * parameter. Return from VT52 mode with an ESC < from * within VT52 mode */ - PrivMode (1, PrivMode_vt52); + set_privmode (PrivMode_vt52, 1); break; case 3: /* 80/132 */ if (priv_modes & PrivMode_132OK) @@ -3701,7 +3680,7 @@ break; #ifdef scrollBar_esc case scrollBar_esc: - if (scrollbar_mapping (state)) + if (scrollBar.map (state)) { resize_all_windows (0, 0, 0); scr_touch (true);