--- rxvt-unicode/src/command.C 2004/02/22 08:28:36 1.51 +++ rxvt-unicode/src/command.C 2012/06/05 11:00:40 1.515 @@ -1,5 +1,5 @@ -/*--------------------------------*-C-*---------------------------------* - * File: command.c +/*----------------------------------------------------------------------* + * File: command.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. @@ -27,7 +27,8 @@ * Copyright (c) 2001 Marius Gedminas * - Ctrl/Mod4+Tab works like Meta+Tab (options) * Copyright (c) 2003 Rob McMullen - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2011 Marc Lehmann + * Copyright (c) 2007 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 @@ -45,27 +46,370 @@ *----------------------------------------------------------------------*/ /*{{{ includes: */ -#include "../config.h" /* NECESSARY */ -#include "rxvt.h" /* NECESSARY */ +#include "../config.h" +#include "rxvt.h" +#include "rxvtperl.h" #include "version.h" #include "command.h" -#include +#ifdef KEYSYM_RESOURCE +# include "keyboard.h" +#endif + +#include + +#if LINUX_YIELD_HACK +# include +#endif /*----------------------------------------------------------------------*/ -/*{{{ Convert the keypress event into a string */ -void -rxvt_term::lookup_key (XKeyEvent &ev) +#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) + +#if ENABLE_FRILLS || ISO_14755 + +#define ISO_14755_STARTED 0x80000000UL +#define ISO_14755_51 0x40000000UL // basic (section 5.1) +#define ISO_14755_52 0x20000000UL // keycap (section 5.2) +#define ISO_14755_54 0x10000000UL // code feedback (section 5.4) +#define ISO_14755_MASK 0x0fffffffUL + +#if ISO_14755 +static unsigned short iso14755_symtab[] = { + // keysym, unicode + XK_Left, 0x2190, + XK_KP_Left, 0x2190, + XK_Up, 0x2191, + XK_KP_Up, 0x2191, + XK_Right, 0x2192, + XK_KP_Right, 0x2192, + XK_Down, 0x2193, + XK_KP_Down, 0x2193, + XK_Linefeed, 0x21b4, + XK_Return, 0x21b5, + XK_KP_Enter, 0x21b5, + + XK_Prior, 0x21de, + XK_Next, 0x21df, + XK_Tab, 0x21e5, + XK_ISO_Left_Tab, 0x21e6, + XK_Shift_L, 0x21e7, + XK_Shift_R, 0x21e7, + + XK_Shift_Lock, 0x21eb, + XK_ISO_Lock, 0x21eb, + XK_Caps_Lock, 0x21ec, + XK_Num_Lock, 0x21ed, + XK_ISO_Level3_Shift, 0x21ee, + XK_ISO_Level3_Lock, 0x21ef, + XK_ISO_Group_Lock, 0x21f0, + XK_Home, 0x21f1, + XK_End, 0x21f2, + + XK_Execute, 0x2318, + XK_Begin, 0x2320, + XK_Delete, 0x2326, + XK_Clear, 0x2327, + XK_BackSpace, 0x232b, + XK_Insert, 0x2380, + XK_Control_L, 0x2388, + XK_Control_R, 0x2388, + XK_Pause, 0x2389, + XK_Break, 0x238a, + XK_Escape, 0x238b, + XK_Undo, 0x238c, + XK_Print, 0x2399, + + XK_space, 0x2423, + +#ifdef XK_KP_Begin + XK_KP_Prior, 0x21de, + XK_KP_Next, 0x21df, + XK_KP_Begin, 0x2320, + XK_KP_Insert, 0x2380, + XK_KP_Delete, 0x2326, + XK_KP_Space, 0x2422, +#endif + 0, +}; + +void ecb_cold +rxvt_term::iso14755_54 (int x, int y) +{ + x = Pixel2Col (x); + y = Pixel2Row (y); + + if (!IN_RANGE_EXC (x, 0, ncol) + || !IN_RANGE_EXC (y, 0, nrow)) + return; + + for (;;) + { + const line_t &l = ROW(y + view_start); + + text_t t = l.t[x]; + + if (t != NOCHAR || !x) + { + iso14755_51 (l.t[x], l.r[x], x, y); + iso14755buf = ISO_14755_54; + break; + } + + x--; + } +} + +void ecb_cold +rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) +{ + rxvt_fontset *fs = FONTSET (r); + wchar_t *chr, *alloc, ch2, **fname; + int len; + +# if ENABLE_COMBINING + if (IS_COMPOSE (ch)) + { + len = rxvt_composite.expand (ch, 0); + alloc = chr = new wchar_t[len]; + rxvt_composite.expand (ch, chr); + } + else +# endif + { + ch2 = ch; + + alloc = 0; + chr = &ch2; + len = 1; + } + + char attr[80]; // plenty + + sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", + (int)r, + fgcolor_of (r), bgcolor_of (r), + r & RS_Bold ? " bold" : "", + r & RS_Italic ? " italic" : "", + r & RS_Blink ? " blink" : "", + r & RS_RVid ? " rvid" : "", + r & RS_Uline ? " uline" : "", + r & RS_Careful ? " careful" : ""); + + 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 + hex + max_it (width, strlen (attr)); + + if (y >= 0) + { + y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; + x = 0; + } + + scr_overlay_new (x, y, width, len * 2 + 1); + + r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); + + for (int y = 0; y < len; y++) + { + char buf[9]; + + ch = *chr++; + + sprintf (buf, "%8x", ch); + scr_overlay_set (0, y, buf); + scr_overlay_set (9, y, '='); +# if !UNICODE_3 + if (ch >= 0x10000) + ch = 0xfffd; +# endif + scr_overlay_set (11, y, ch, r); + + if (WCWIDTH (ch) >= 2) + scr_overlay_set (12, y, NOCHAR, r); + } + +// { +// char buf[4+4+3+1]; +// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y); +// scr_overlay_set (0, 0, buf); +// } + scr_overlay_set (0, len , attr); + for (int i = 0; i < len; i++) + { + scr_overlay_set (0, len + 1 + i, fname[i]); + free (fname[i]); + } + +# if ENABLE_COMBINING + if (alloc) + delete [] alloc; +# endif +} +#endif + +void ecb_cold +rxvt_term::commit_iso14755 () +{ + wchar_t ch = iso14755buf & ISO_14755_MASK; + + if (iso14755buf & ISO_14755_51) + { + char mb[MB_LEN_MAX]; + int len; + + // allow verbatim 0-bytes and control-bytes to be entered + if (ch >= 0x20) + len = wctomb (mb, ch); + else + { + mb[0] = ch; + len = 1; + } + + if (len > 0) + tt_write (mb, len); + else + scr_bell (); + } + + iso14755buf = 0; +} + +static int ecb_cold +hex_keyval (XKeyEvent &ev) +{ + // check whether this event corresponds to a hex digit + // if the modifiers had not been pressed. + for (int index = 0; index < 8; index++) + { + KeySym k = XLookupKeysym (&ev, index); + + if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0; + else if (k >= XK_0 && k <= XK_9) return k - XK_0; + else if (k >= XK_a && k <= XK_f) return k - XK_a + 10; + else if (k >= XK_A && k <= XK_F) return k - XK_A + 10; + } + + return -1; +} +#endif + +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 +# 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 + 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; +#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 ecb_cold +rxvt_term::key_press (XKeyEvent &ev) { int ctrl, meta, shft, len; - unsigned int newlen; KeySym keysym; -#ifdef DEBUG_CMD - static int debug_key = 1; /* accessible by a debugger only */ -#endif int valid_keysym; - unsigned char kbuf[KBUFSZ]; + char kbuf[KBUFSZ]; + +#if ISO_14755 + if (iso14755buf & ISO_14755_52) + return; +#endif /* * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an @@ -73,29 +417,25 @@ * * Always permit `shift' to override the current setting */ - shft = (ev.state & ShiftMask); - ctrl = (ev.state & ControlMask); - meta = (ev.state & ModMetaMask); - - if (numlock_state || (ev.state & ModNumLockMask)) - { - numlock_state = (ev.state & ModNumLockMask); - PrivMode ((!numlock_state), PrivMode_aplKP); - } + shft = ev.state & ShiftMask; + ctrl = ev.state & ControlMask; + meta = ev.state & ModMetaMask; kbuf[0] = 0; -#ifdef USE_XIM +#if USE_XIM if (Input_Context) { Status status_return; +#if 0 #ifdef X_HAVE_UTF8_STRING if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful - len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, + len = Xutf8LookupString (Input_Context, &ev, kbuf, KBUFSZ, &keysym, &status_return); else #endif +#endif { wchar_t wkbuf[KBUFSZ + 1]; @@ -103,19 +443,30 @@ // at the point of XOpenIM, so temporarily switch locales if (rs[Rs_imLocale]) SET_LOCALE (rs[Rs_imLocale]); + // assume wchar_t == unicode or better len = XwcLookupString (Input_Context, &ev, wkbuf, KBUFSZ, &keysym, &status_return); + if (rs[Rs_imLocale]) SET_LOCALE (locale); if (status_return == XLookupChars || status_return == XLookupBoth) { - wkbuf[len] = 0; - len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); - if (len < 0) - len = 0; + /* make sure the user can type ctrl-@, i.e. NUL */ + if (len == 1 && *wkbuf == 0) + { + kbuf[0] = 0; + len = 1; + } + else + { + wkbuf[len] = 0; + len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (len < 0) + len = 0; + } } else len = 0; @@ -127,49 +478,34 @@ else #endif { - len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); + len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose); valid_keysym = keysym != NoSymbol; } if (valid_keysym) { - /* for some backwards compatibility */ -#if defined(HOTKEY_CTRL) || defined(HOTKEY_META) -# ifdef HOTKEY_CTRL - if (ctrl) -# else - if (meta) -# endif - { - if (keysym == ks_bigfont) - { - change_font (FONT_UP); - return; - } - else if (keysym == ks_smallfont) - { - change_font (FONT_DN); - return; - } - } +#ifdef KEYSYM_RESOURCE + if (keyboard->dispatch (this, keysym, ev.state)) + return; #endif - if (TermWin.saveLines) + if (saveLines) { #ifdef UNSHIFTED_SCROLLKEYS if (!ctrl && !meta) - { #else if (IS_SCROLL_MOD) - { #endif + { int lnsppg; #ifdef PAGING_CONTEXT_LINES - lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; + lnsppg = nrow - PAGING_CONTEXT_LINES; #else - lnsppg = TermWin.nrow * 4 / 5; + lnsppg = nrow * 4 / 5; #endif + max_it (lnsppg, 1); + if (keysym == XK_Prior) { scr_page (UP, lnsppg); @@ -206,7 +542,7 @@ } else if (keysym == XK_End) { - scr_move_to (1, 0); + scr_move_to (1, 1); return; } } @@ -221,24 +557,80 @@ keysym += (XK_F11 - XK_F1); shft = 0; /* turn off Shift */ } - else if (!ctrl && !meta && (PrivateModes & PrivMode_ShiftKeys)) + else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys)) { switch (keysym) { /* normal XTerm key bindings */ case XK_Insert: /* Shift+Insert = paste mouse selection */ - selection_request (ev.time, 0, 0); + selection_request (ev.time); return; +#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 ENABLE_FRILLS || ISO_14755 + // ISO 14755 support + if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51)) + { + int hv; + + if (iso14755buf & ISO_14755_51 + && (keysym == XK_space || keysym == XK_KP_Space + || keysym == XK_Return || keysym == XK_KP_Enter)) + { + commit_iso14755 (); + iso14755buf = ISO_14755_51; +# if ISO_14755 + iso14755_51 (0); +# endif + return; + } + else if (keysym == XK_BackSpace) + { + iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51; +# if ISO_14755 + iso14755_51 (iso14755buf & ISO_14755_MASK); +# endif + return; + } + else if ((hv = hex_keyval (ev)) >= 0) + { + iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK) + | hv | ISO_14755_51; +# if ISO_14755 + iso14755_51 (iso14755buf & ISO_14755_MASK); +# endif + return; + } + else + { +# if ISO_14755 + scr_overlay_off (); +# endif + iso14755buf = 0; + } + } + 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; +# if ISO_14755 + scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); + scr_overlay_set (0, 0, "ISO 14755 mode"); +# endif + } +#endif + #ifdef PRINTPIPE if (keysym == XK_Print) { @@ -249,361 +641,165 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { -#ifdef KEYSYM_RESOURCE - if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) - { - unsigned int l; - const unsigned char *kbuf0; - const unsigned char ch = C0_ESC; - - kbuf0 = (Keysym_map[keysym & 0xFF]); - l = (unsigned int)*kbuf0++; - - /* escape prefix */ - if (meta) -# ifdef META8_OPTION - if (meta_char == C0_ESC) -# endif - tt_write (&ch, 1); - tt_write (kbuf0, l); - return; - } - else -#endif + 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) { - newlen = 1; - switch (keysym) - { #ifndef NO_BACKSPACE_KEY - case XK_BackSpace: - if (PrivateModes & PrivMode_HaveBackSpace) - { - kbuf[0] = (!! (PrivateModes & PrivMode_BackSpace) - ^ !!ctrl) ? '\b' : '\177'; - kbuf[1] = '\0'; - } - else - STRCPY (kbuf, key_backspace); -# ifdef MULTICHAR_SET - if ((Options & Opt_mc_hack) && screen.cur.col > 0) - { - int col, row; - - newlen = STRLEN (kbuf); - col = screen.cur.col - 1; - row = screen.cur.row + TermWin.saveLines; - if (IS_MULTI2 (screen.rend[row][col])) - MEMMOVE (kbuf + newlen, kbuf, newlen + 1); - } -# endif - 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, key_delete); -# ifdef MULTICHAR_SET - if (Options & Opt_mc_hack) - { - int col, row; - - newlen = STRLEN (kbuf); - col = screen.cur.col; - row = screen.cur.row + TermWin.saveLines; - if (IS_MULTI1 (screen.rend[row][col])) - MEMMOVE (kbuf + newlen, kbuf, newlen + 1); - } -# endif - 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; -#endif - newlen = 0; - } - break; - -#ifdef XK_KP_Left - case XK_KP_Up: /* \033Ox or standard */ - case XK_KP_Down: /* \033Or or standard */ - case XK_KP_Right: /* \033Ov or standard */ - case XK_KP_Left: /* \033Ot or standard */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033OZ"); - kbuf[2] = "txvr"[keysym - XK_KP_Left]; - break; - } - else - /* translate to std. cursor key */ - keysym = XK_Left + (keysym - XK_KP_Left); - /* FALLTHROUGH */ -#endif - 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 (PrivateModes & PrivMode_aplCUR) - kbuf[1] = 'O'; -#ifdef MULTICHAR_SET - //TODO: ?? - if (Options & Opt_mc_hack) - { - int col, row, m; - - col = screen.cur.col; - row = screen.cur.row + TermWin.saveLines; - m = 0; - if (keysym == XK_Right - && IS_MULTI1 (screen.rend[row][col])) - m = 1; - else if (keysym == XK_Left) - { - if (col > 0) - { - if (IS_MULTI2 (screen.rend[row][col - 1])) - m = 1; - } - else if (screen.cur.row > 0) - { - col = screen.tlen[--row]; - if (col == -1) - col = TermWin.ncol - 1; - else - col--; - if (col > 0 - && IS_MULTI2 (screen.rend[row][col])) - m = 1; - } - } - if (m) - MEMMOVE (kbuf + 3, kbuf, 3 + 1); - } + if (ev.state & Mod4Mask) + meta = 1; #endif - break; - -#ifndef UNSHIFTED_SCROLLKEYS -# ifdef XK_KP_Prior - case XK_KP_Prior: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033Oy"); - break; - } - /* FALLTHROUGH */ -# endif - case XK_Prior: - STRCPY (kbuf, "\033[5~"); - break; -# ifdef XK_KP_Next - case XK_KP_Next: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033Os"); - break; - } - /* FALLTHROUGH */ -# endif - case XK_Next: - STRCPY (kbuf, "\033[6~"); - break; -#endif - case XK_KP_Enter: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033OM"); - } - else - { - kbuf[0] = '\r'; - kbuf[1] = '\0'; - } - break; + newlen = 0; + } + break; -#ifdef XK_KP_Begin - case XK_KP_Begin: - STRCPY (kbuf, "\033Ou"); - 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_Insert: - STRCPY (kbuf, "\033Op"); + case XK_KP_Enter: + /* allow shift to override */ + if (kp) + { + strcpy (kbuf, "\033OM"); break; + } - case XK_KP_Delete: - STRCPY (kbuf, "\033On"); - break; -#endif - 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; + /* FALLTHROUGH */ - 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 ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033Oj"); - kbuf[2] += (keysym - XK_KP_Multiply); - } - else - { - kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); - kbuf[1] = '\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_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; -#ifdef XK_KP_End - case XK_KP_End: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033Oq"); - break; - } - /* FALLTHROUGH */ -#endif - case XK_End: - STRCPY (kbuf, KS_END); - break; -#ifdef XK_KP_Home - case XK_KP_Home: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) - { - STRCPY (kbuf, "\033Ow"); - break; - } - /* FALLTHROUGH */ -#endif - 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; } - if (newlen) - len = STRLEN (kbuf); + break; } - /* - * Pass meta for all function keys, if 'meta' option set - */ + + 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) && len > 0) - kbuf[len - 1] |= 0x80; + if (meta && (meta_char == 0x80)) + kbuf[len - 1] |= 0x80; #endif + } } else if (ctrl && keysym == XK_minus) @@ -611,16 +807,22 @@ 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)) { - unsigned char *ch; + char *ch; for (ch = kbuf; ch < kbuf + len; ch++) *ch |= 0x80; + meta = 0; } #endif @@ -628,399 +830,464 @@ } } + 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 (Options & Opt_scrollTtyKeypress) - if (TermWin.view_start) + if (option (Opt_scrollTtyKeypress)) + if (view_start) { - TermWin.view_start = 0; + 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) + && meta_char == C0_ESC #endif ) { - const unsigned char ch = C0_ESC; - + const char ch = C0_ESC; tt_write (&ch, 1); } -#ifdef DEBUG_CMD - if (debug_key) - { /* Display keyboard buffer contents */ - char *p; - int i; - - fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); - for (i = 0, p = kbuf; i < len; i++, p++) - fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); - fprintf (stderr, "'\n"); - } -#endif /* DEBUG_CMD */ + tt_write (kbuf, (unsigned int)len); } -/*}}} */ -#if (MENUBAR_MAX) -/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ -/* attempt to `write' count to the input buffer */ -unsigned int -rxvt_term::cmd_write (const unsigned char *str, unsigned int count) -{ - unsigned int n, s; - - n = cmdbuf_ptr - cmdbuf_base; - s = cmdbuf_base + BUFSIZ - 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_print_error ("data loss: cmd_write too large"); - count = s; - } - for (; count--;) - *cmdbuf_endp++ = *str++; - return 0; +void ecb_cold +rxvt_term::key_release (XKeyEvent &ev) +{ +#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL + KeySym keysym; + + keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ +#endif + +#if ENABLE_FRILLS || ISO_14755 + // ISO 14755 support + if (iso14755buf) + if (iso14755buf & ISO_14755_52) + { +# if ISO_14755 + scr_overlay_off (); +# endif +# if ISO_14755 + // iso14755 part 5.2 handling: release time + // first: controls + if ((ev.state & ControlMask) + && ((keysym >= 0x40 && keysym <= 0x5f) + || (keysym >= 0x61 && keysym <= 0x7f))) + { + iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f); + commit_iso14755 (); + + return; + } + + for (unsigned short *i = iso14755_symtab; i[0]; i += 2) + if (i[0] == keysym) + { + iso14755buf = ISO_14755_51 | i[1]; + commit_iso14755 (); + + return; + } + + scr_bell (); +# endif + iso14755buf = 0; + + return; + } + else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask)) + { +# if ISO_14755 + scr_overlay_off (); +# endif + if (iso14755buf & ISO_14755_51) + commit_iso14755 (); +#if ISO_14755 + else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED) + { + iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair + + scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1); + scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE"); + } +# endif + else + iso14755buf = 0; + } +#endif + + if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END))) + return; + +#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) + if (!(ev.state & ControlMask)) + slip_wheel_ev.stop (); + else if (keysym == XK_Control_L || keysym == XK_Control_R) + mouse_slip_wheel_speed = 0; +#endif } -#endif /* MENUBAR_MAX */ void rxvt_term::flush () { -#ifdef TRANSPARENT - if (want_full_refresh) + flush_ev.stop (); + +#ifdef HAVE_BG_PIXMAP + if (bg_flags & BG_NEEDS_REFRESH) { - want_full_refresh = 0; - scr_clear (); + bg_flags &= ~BG_NEEDS_REFRESH; scr_touch (false); - want_refresh = 1; } #endif if (want_refresh) { - scr_refresh (refresh_type); - scrollbar_show (1); -#ifdef USE_XIM - IMSendSpot (); -#endif + if (SHOULD_INVOKE (HOOK_LINE_UPDATE)) + { + int row = view_start; + int end_row = row + nrow; + + while (row > top_row && ROW (row - 1).is_longer ()) + --row; + + do + { + int start_row = row; + line_t *l; + + do + { + l = &ROW (row++); + + if (!(l->f & LINE_FILTERED)) + { + // line not filtered, mark it as filtered + l->f |= LINE_FILTERED; + while (l->is_longer ()) + { + l = &ROW (row++); + l->f |= LINE_FILTERED; + } + + // and filter it + HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END)); + break; + } + } + while (l->is_longer () && row < end_row); + } + while (row < end_row); + } + + scr_refresh (); + 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::check_cb (check_watcher &w) +rxvt_term::refresh_check () { - SET_R (this); - SET_LOCALE (locale); + if (want_refresh && !flush_ev.is_active ()) + flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally + display->flush (); +} + +void +rxvt_term::flush_cb (ev::timer &w, int revents) +{ + make_current (); + + refresh_count = 0; flush (); } #ifdef CURSOR_BLINK void -rxvt_term::cursor_blink_cb (time_watcher &w) +rxvt_term::cursor_blink_reset () +{ + if (hidden_cursor) + { + hidden_cursor = 0; + want_refresh = 1; + } + + if (option (Opt_cursorBlink)) + 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; - - w.start (w.at + BLINK_INTERVAL); + refresh_check (); } #endif #ifdef TEXT_BLINK void -rxvt_term::text_blink_cb (time_watcher &w) +rxvt_term::text_blink_cb (ev::timer &w, int revents) { if (scr_refresh_rend (RS_Blink, RS_Blink)) { hidden_text = !hidden_text; want_refresh = 1; - w.start (w.at + TEXT_BLINK_INTERVAL); + refresh_check (); } + else + w.stop (); } #endif -bool -rxvt_term::pty_fill () +#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING +void +rxvt_term::cont_scroll_cb (ev::timer &w, int revents) { - ssize_t n = cmdbuf_endp - cmdbuf_ptr; - - memmove (cmdbuf_base, cmdbuf_ptr, n); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp = cmdbuf_ptr + n; - - n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); - - if (n > 0) + if ((scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN) + && scr_page (scrollBar.state == SB_STATE_UP ? UP : DN, 1)) { - cmdbuf_endp += n; - return true; + want_refresh = 1; + refresh_check (); } - else if (n < 0 && errno != EAGAIN) - destroy (); + else + w.stop (); +} +#endif - return false; +#ifdef SELECTION_SCROLLING +void +rxvt_term::sel_scroll_cb (ev::timer &w, int revents) +{ + if (scr_page (scroll_selection_dir, scroll_selection_lines)) + { + selection_extend (selection_save_x, selection_save_y, selection_save_state); + want_refresh = 1; + refresh_check (); + } + else + w.stop (); } +#endif +#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) void -rxvt_term::pty_cb (io_watcher &w, short revents) +rxvt_term::slip_wheel_cb (ev::timer &w, int revents) { - SET_R (this); - SET_LOCALE (locale); + if (scr_changeview (view_start - mouse_slip_wheel_speed)) + { + want_refresh = 1; + refresh_check (); + } - if (revents & EVENT_WRITE) - tt_write (0, 0); - else if (revents & EVENT_READ) + if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0) { - bool flag = true; + mouse_slip_wheel_speed = 0; + w.stop (); + } +} +#endif - // loop, but don't allow a single term to monopolize us - // the number of loops is fully arbitrary, and thus wrong - while (flag && pty_fill ()) - { - if (!seen_input) - { - seen_input = 1; - /* once we know the shell is running, send the screen size. Again! */ - tt_winch (); - } +#if LINUX_YIELD_HACK +static struct event_handler +{ + ev::prepare yield_ev; - uint32_t ch = NOCHAR; + void yield_cb (ev::prepare &w, int revents) + { + // this should really be sched_yield(), but the linux guys thought + // 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. - for (;;) - { - if (ch == NOCHAR) - ch = next_char (); + struct timespec ts = { 0, 1000 }; + nanosleep (&ts, 0); - if (ch == NOCHAR) // TODO: improve - break; + w.stop (); + } - if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') - { - /* Read a text string from the input buffer */ - uint32_t buf[BUFSIZ]; - bool refreshnow = false; - int nlines = 0; - uint32_t *str = buf; + event_handler () + : yield_ev (this, &event_handler::yield_cb) + { + } +} event_handler; +#endif - *str++ = ch; +/* make sure all the cmd data is at beginning of cmdbuf */ +void +rxvt_term::cmdbuf_reify () +{ + if (cmdbuf_ptr == cmdbuf_base) + return; - for (;;) - { - ch = next_char (); + ssize_t used = cmdbuf_endp - cmdbuf_ptr; - if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) - break; - else - { - *str++ = ch; + memmove (cmdbuf_base, cmdbuf_ptr, used); + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr + used; - if (ch == '\n') - { - nlines++; - refresh_count++; - - if (! (Options & Opt_jumpScroll) - || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) - { - refreshnow = true; - flag = false; - ch = NOCHAR; - break; - } - - // scr_add_lines only works for nlines < TermWin.nrow - 1. - if (nlines >= TermWin.nrow - 1) - { - scr_add_lines (buf, nlines, str - buf); - nlines = 0; - str = buf; - } - } - - if (str >= buf + BUFSIZ) - { - ch = NOCHAR; - break; - } - } - } +} - scr_add_lines (buf, nlines, str - buf); +#if defined (KEYSYM_RESOURCE) +void +rxvt_term::cmdbuf_append (const char *str, size_t count) +{ + cmdbuf_reify (); - /* - * If there have been a lot of new lines, then update the screen - * What the heck I'll cheat and only refresh less than every page-full. - * the number of pages between refreshes is refresh_limit, which - * is incremented here because we must be doing flat-out scrolling. - * - * refreshing should be correct for small scrolls, because of the - * time-out - */ - if (refreshnow) - { - if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) - refresh_limit++; + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; - scr_refresh (refresh_type); - } + if (count > avail) + return; - } - else - { - switch (ch) - { - default: - process_nonprinting (ch); - break; - case C0_ESC: /* escape char */ - process_escape_seq (); - break; - /*case 0x9b: */ /* CSI */ - /* process_csi_seq (); */ - } + memcpy (cmdbuf_endp, str, count); + cmdbuf_endp += count; - ch = NOCHAR; - } - } - } - } + cmd_parse (); } +#endif -// read the next character, currently handles UTF-8 -// will probably handle all sorts of other stuff in the future -uint32_t -rxvt_term::next_char () +bool +rxvt_term::pty_fill () { - while (cmdbuf_ptr < cmdbuf_endp) - { - if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh - return *cmdbuf_ptr++; + cmdbuf_reify (); - wchar_t wc; - size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; - if (len == (size_t)-2) - return NOCHAR; + if (!avail) + { + // normally this indicates a "too long" command sequence - just drop the data we have + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr; + avail = CBUFSIZ; + } - if (len == (size_t)-1) - return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + ssize_t r = read (pty->pty, cmdbuf_endp, avail); - // assume wchar == unicode - cmdbuf_ptr += len; - return wc; + if (r > 0) + { + cmdbuf_endp += r; + return true; + } + else if (r < 0 && (errno == EAGAIN || errno == EINTR)) + { +#if LINUX_YIELD_HACK + if (display->is_local) + event_handler.yield_ev.start (); +#endif } + else + { + pty_ev.stop (); - return NOCHAR; + if (!option (Opt_hold)) + destroy (); + } + + return false; } -/* rxvt_cmd_getc () - Return next input character */ -/* - * Return the next input character after first passing any keyboard input - * to the command. - */ -uint32_t -rxvt_term::cmd_getc () +void +rxvt_term::pty_cb (ev::io &w, int revents) { - for (;;) - { - uint32_t c = next_char (); - if (c != NOCHAR) - return c; - - // incomplete sequences should occur rarely, still, a better solution - // would be preferred. either setjmp/longjmp or better design. - fcntl (cmd_fd, F_SETFL, 0); - pty_fill (); - fcntl (cmd_fd, F_SETFL, O_NONBLOCK); - } + make_current (); + + if (revents & ev::READ) + // loop, but don't allow a single term to monopolize us + for (int i = CBUFCNT; i-- && pty_fill (); ) + cmd_parse (); + + if (revents & ev::WRITE) + pty_write (); + + refresh_check (); } -#ifdef POINTER_BLANK -void +void ecb_cold rxvt_term::pointer_unblank () { - XDefineCursor (display->display, TermWin.vt, TermWin_cursor); + XDefineCursor (dpy, vt, TermWin_cursor); recolour_cursor (); +#ifdef POINTER_BLANK hidden_pointer = 0; - if (Options & Opt_pointerBlank) - pointer_ev.start (NOW + pointerBlankDelay); + if (option (Opt_pointerBlank)) + pointer_ev.start (pointerBlankDelay); +#endif } -void +#ifdef POINTER_BLANK +void ecb_cold rxvt_term::pointer_blank () { - if (! (Options & Opt_pointerBlank)) + if (!option (Opt_pointerBlank)) return; - XDefineCursor (display->display, TermWin.vt, blank_cursor); - XFlush (display->display); + XDefineCursor (dpy, vt, display->blank_cursor); + XFlush (dpy); hidden_pointer = 1; } -void -rxvt_term::pointer_cb (time_watcher &w) +void ecb_cold +rxvt_term::pointer_cb (ev::timer &w, int revents) { - SET_R (this); - SET_LOCALE (locale); + make_current (); pointer_blank (); } #endif void -rxvt_term::mouse_report (const XButtonEvent &ev) +rxvt_term::mouse_report (XButtonEvent &ev) { - int button_number, key_state = 0; - int x, y; + int button_number, key_state = 0; + int x, y; + int code = 32; - x = ev.x; - y = ev.y; - pixel_position (&x, &y); + x = Pixel2Col (ev.x) + 1; + y = Pixel2Row (ev.y) + 1; - if (MEvent.button == AnyButton) + if (ev.type == MotionNotify) { - button_number = 3; + if (x == mouse_row && y == mouse_col) + return; + + mouse_row = x; + mouse_col = y; + code += 32; } + + if (MEvent.button == AnyButton) + button_number = 3; else { button_number = MEvent.button - Button1; /* add 0x3D for wheel events, like xterm does */ if (button_number >= 3) - button_number += (64 - 3); + button_number += 64 - 3; } - if (PrivateModes & PrivMode_MouseX10) + if (priv_modes & PrivMode_MouseX10) { /* * do not report ButtonRelease @@ -1045,10 +1312,9 @@ #ifdef MOUSE_REPORT_DOUBLECLICK key_state += ((MEvent.clicks > 1) ? 32 : 0); #endif - } -#ifdef DEBUG_MOUSEREPORT +#if DEBUG_MOUSEREPORT fprintf (stderr, "Mouse ["); if (key_state & 16) fputc ('C', stderr); @@ -1060,140 +1326,56 @@ fputc ('2', stderr); fprintf (stderr, "]: <%d>, %d/%d\n", button_number, - x + 1, - y + 1); -#else - tt_printf ("\033[M%c%c%c", - (32 + button_number + key_state), - (32 + x + 1), - (32 + y + 1)); + x, + y); #endif -} - -#ifdef USING_W11LIB -void -rxvt_W11_process_x_event (XEvent *ev) -{ - rxvt_t *r = rxvt_get_r (); - x_cb (*ev); -} +#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) { - SET_R (this); - SET_LOCALE (locale); - -#if defined(CURSOR_BLINK) - if ((Options & Opt_cursorBlink) && ev.type == KeyPress) - { - if (hidden_cursor) - { - hidden_cursor = 0; - want_refresh = 1; - } + make_current (); - cursor_blink_ev.start (NOW + BLINK_INTERVAL); - } -#endif + dLocal (Display *, dpy); -#if defined(POINTER_BLANK) - if ((Options & Opt_pointerBlank) && pointerBlankDelay > 0) - { - if (ev.type == MotionNotify - || ev.type == ButtonPress - || ev.type == ButtonRelease) - if (hidden_pointer) - pointer_unblank (); - - if (ev.type == KeyPress && hidden_pointer == 0) - pointer_blank (); - } -#endif - -#ifdef USE_XIM - if (XFilterEvent (&ev, None)) + if (ev.xany.window == vt + && SHOULD_INVOKE (HOOK_X_EVENT) + && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) return; -#endif - Window unused_root, unused_child; - int unused_root_x, unused_root_y; - unsigned int unused_mask; - -#ifdef DEBUG_X - const char *const eventnames[] = - { /* mason - this matches my system */ - "", - "", - "KeyPress", - "KeyRelease", - "ButtonPress", - "ButtonRelease", - "MotionNotify", - "EnterNotify", - "LeaveNotify", - "FocusIn", - "FocusOut", - "KeymapNotify", - "Expose", - "GraphicsExpose", - "NoExpose", - "VisibilityNotify", - "CreateNotify", - "DestroyNotify", - "UnmapNotify", - "MapNotify", - "MapRequest", - "ReparentNotify", - "ConfigureNotify", - "ConfigureRequest", - "GravityNotify", - "ResizeRequest", - "CirculateNotify", - "CirculateRequest", - "PropertyNotify", - "SelectionClear", - "SelectionRequest", - "SelectionNotify", - "ColormapNotify", - "ClientMessage", - "MappingNotify" - }; -#endif - -#ifdef DEBUG_X - struct timeval tp; - struct tm *ltt; - (void)gettimeofday (&tp, NULL); - ltt = localtime (& (tp.tv_sec)); - D_X ((stderr, "Event: %-16s %-7s %08lx (%4d-%02d-%02d %02d:%02d:%02d.%.6ld) %s %lu", eventnames[ev.type], (ev.xany.window == TermWin.parent[0] ? "parent" : (ev.xany.window == TermWin.vt ? "vt" : (ev.xany.window == scrollBar.win ? "scroll" : (ev.xany.window == menuBar.win ? "menubar" : "UNKNOWN")))), (ev.xany.window == TermWin.parent[0] ? TermWin.parent[0] : (ev.xany.window == TermWin.vt ? TermWin.vt : (ev.xany.window == scrollBar.win ? scrollBar.win : (ev.xany.window == menuBar.win ? menuBar.win : 0)))), ltt->tm_year + 1900, ltt->tm_mon + 1, ltt->tm_mday, ltt->tm_hour, ltt->tm_min, ltt->tm_sec, tp.tv_usec, ev.xany.send_event ? "S" : " ", ev.xany.serial)); -#endif + // for XQueryPointer + Window unused_root, unused_child; + int unused_root_x, unused_root_y; + unsigned int unused_mask; switch (ev.type) { case KeyPress: - lookup_key (ev.xkey); + key_press (ev.xkey); break; -#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) case KeyRelease: - { - if (! (ev.xkey.state & ControlMask)) - mouse_slip_wheel_speed = 0; - else - { - KeySym ks; - - ks = XKeycodeToKeysym (display->display, ev.xkey.keycode, 0); - if (ks == XK_Control_L || ks == XK_Control_R) - mouse_slip_wheel_speed = 0; - } - break; - } -#endif + key_release (ev.xkey); + break; case ButtonPress: button_press (ev.xbutton); @@ -1205,40 +1387,35 @@ case ClientMessage: if (ev.xclient.format == 32 - && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) - destroy (); -#ifdef OFFIX_DND - /* OffiX Dnd (drag 'n' drop) protocol */ - else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] - && (ev.xclient.data.l[0] == DndFile - || ev.xclient.data.l[0] == DndDir - || ev.xclient.data.l[0] == DndLink)) - { - /* Get Dnd data */ - Atom ActualType; - int ActualFormat; - unsigned char *data; - unsigned long Size, RemainingBytes; - - XGetWindowProperty (display->display, display->root, - xa[XA_DNDSELECTION], - 0L, 1000000L, - False, AnyPropertyType, - &ActualType, &ActualFormat, - &Size, &RemainingBytes, - &data); - XChangeProperty (display->display, display->root, - XA_CUT_BUFFER0, XA_STRING, - 8, PropModeReplace, - data, STRLEN (data)); - selection_paste (display->root, XA_CUT_BUFFER0, True); - XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); + && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END))) + { + if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) + { + if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END))) + { + if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) + { + if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) + destroy (); + } +#if ENABLE_EWMH + else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) + XSendEvent (dpy, ev.xclient.window = display->root, + False, SubstructureRedirectMask | SubstructureNotifyMask, + &ev); +#endif + } + } +#if ENABLE_XEMBED + else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED]) + { + if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) + focus_in (); + else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) + focus_out (); + } +#endif } -#endif /* OFFIX_DND */ - break; - - case MappingNotify: - XRefreshKeyboardMapping (& (ev.xmapping)); break; /* @@ -1267,145 +1444,154 @@ break; case FocusIn: - if (!TermWin.focus) - { - TermWin.focus = 1; - want_refresh = 1; -#ifdef USE_XIM - if (Input_Context != NULL) - XSetICFocus (Input_Context); -#endif -#ifdef CURSOR_BLINK - if (Options & Opt_cursorBlink) - cursor_blink_ev.start (NOW + BLINK_INTERVAL); -#endif - - } + if (ev.xfocus.detail != NotifyInferior + && ev.xfocus.detail != NotifyPointer + && ev.xfocus.mode != NotifyGrab) + focus_in (); break; case FocusOut: - if (TermWin.focus) - { - TermWin.focus = 0; - want_refresh = 1; -#ifdef USE_XIM - if (Input_Context != NULL) - XUnsetICFocus (Input_Context); -#endif -#ifdef CURSOR_BLINK - if (Options & Opt_cursorBlink) - cursor_blink_ev.stop (); - hidden_cursor = 0; -#endif - - } + if (ev.xfocus.detail != NotifyInferior + && ev.xfocus.detail != NotifyPointer + && ev.xfocus.mode != NotifyGrab) + focus_out (); break; case ConfigureNotify: - if (ev.xconfigure.window == TermWin.parent[0]) + if (ev.xconfigure.window == parent) { - int height, width; + while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) + ; - do - { /* Wrap lots of configures into one */ - width = ev.xconfigure.width; - height = ev.xconfigure.height; - D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); + bool want_position_change = SHOULD_INVOKE (HOOK_POSITION_CHANGE); + +#ifdef HAVE_BG_PIXMAP + if (bg_window_position_sensitive ()) + want_position_change = true; +#endif + + bool moved = false; + + 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) + { + HOOK_INVOKE ((this, HOOK_POSITION_CHANGE, DT_INT, x, DT_INT, y, DT_END)); + parent_x = x; + parent_y = y; + } + + if (bg_set_position (x, y) + || !(bg_flags & BG_IS_VALID)) + moved = true; } - while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); - if (szHint.width != width || szHint.height != height) + if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) { - D_SIZE ((stderr, "Size: Resizing from: %4d x %4d", szHint.width, szHint.height)); - resize_all_windows (width, height, 1); + seen_resize = 1; + resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); } -#ifdef DEBUG_SIZE else { - D_SIZE ((stderr, "Size: Not resizing")); - } +#ifdef HAVE_BG_PIXMAP + if (moved) + update_background (); #endif -#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ - if (Options & Opt_transparent) - { - check_our_parents (); - if (am_transparent) - want_full_refresh = 1; } -#endif + HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); } break; - case SelectionClear: - display->set_selection_owner (0); + case PropertyNotify: + HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)); break; - case SelectionNotify: - if (selection_wait == Sel_normal) - selection_paste (ev.xselection.requestor, - ev.xselection.property, True); + case SelectionClear: + selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]); break; case SelectionRequest: selection_send (ev.xselectionrequest); break; - case UnmapNotify: - TermWin.mapped = 0; + case MapNotify: +#ifdef HAVE_BG_PIXMAP + /* This is needed specifically to fix the case of no window manager or a + * non-reparenting window manager. In those cases we never get first + * ConfigureNotify. Also that speeds startup under normal WM, by taking + * care of multiplicity of ConfigureNotify events arriving while WM does + * reparenting. + * We should not render background immediately, as there could be several + * ConfigureNotify's to follow. Lets take care of all of them in one scoop + * by scheduling background redraw as soon as we can, but giving a short + * bit of time for ConfigureNotifies to arrive. + * We should render background PRIOR to drawing any text, but AFTER all + * of ConfigureNotifys for the best results. + */ + if (!(bg_flags & BG_IS_VALID)) + update_background_ev.start (0.025); +#endif + mapped = 1; #ifdef TEXT_BLINK - text_blink_ev.stop (); + text_blink_ev.start (); #endif + HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; - case MapNotify: - TermWin.mapped = 1; + case UnmapNotify: + mapped = 0; #ifdef TEXT_BLINK - text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); + text_blink_ev.stop (); #endif + HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; -#ifdef TRANSPARENT - case ReparentNotify: - rootwin_cb (ev); - break; -#endif /* TRANSPARENT */ - case GraphicsExpose: case Expose: - if (ev.xany.window == TermWin.vt) + if (ev.xany.window == vt) { -#ifdef NO_SLOW_LINK_SUPPORT - scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); -#else - // don't understand this, so commented it out - scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); - //scr_expose (ev.xexpose.x, 0, - // ev.xexpose.width, TermWin.height, False); -#endif + do + { + scr_expose (ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, false); + } + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)); + + ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; + + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) + { + scr_expose (ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, false); + } + want_refresh = 1; } else { XEvent unused_event; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, - Expose, - &unused_event)) ; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, - GraphicsExpose, - &unused_event)) ; - if (isScrollbarWindow (ev.xany.window)) - { - scrollBar.setIdle (); - scrollbar_show (0); - } -#ifdef MENUBAR - if (menubar_visible () && isMenuBarWindow (ev.xany.window)) - menubar_expose (); -#endif + while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event)) + ; + while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) + ; + + if (scrollBar.state && ev.xany.window == scrollBar.win) + { + scrollBar.state = SB_STATE_IDLE; + scrollBar.show (0); + } } break; @@ -1414,161 +1600,304 @@ if (hidden_pointer) pointer_unblank (); #endif -#if MENUBAR - if (isMenuBarWindow (ev.xany.window)) - { - menubar_control (& (ev.xbutton)); - break; - } -#endif - if ((PrivateModes & PrivMode_mouse_report) && ! (bypass_keystate)) + if ((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; - if (ev.xany.window == TermWin.vt) + if (ev.xany.window == vt) { - if ((ev.xbutton.state & (Button1Mask | Button3Mask))) + if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) + && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) + ; // nop + else if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev)) ; - XQueryPointer (display->display, TermWin.vt, - &unused_root, &unused_child, - &unused_root_x, &unused_root_y, - & (ev.xbutton.x), & (ev.xbutton.y), - &unused_mask); + XQueryPointer (dpy, vt, + &unused_root, &unused_child, + &unused_root_x, &unused_root_y, + &ev.xbutton.x, &ev.xbutton.y, + &ev.xbutton.state); #ifdef MOUSE_THRESHOLD /* deal with a `jumpy' mouse */ if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) { #endif - selection_extend ((ev.xbutton.x), (ev.xbutton.y), - (ev.xbutton.state & Button3Mask) ? 2 : 0); +#if ISO_14755 + // 5.4 + if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) + { + iso14755_54 (ev.xbutton.x, ev.xbutton.y); + break; + } +#endif + selection_extend (ev.xbutton.x, ev.xbutton.y, + ev.xbutton.state & Button3Mask ? 2 : 0); + #ifdef SELECTION_SCROLLING - if (ev.xbutton.y < TermWin.int_bwidth - || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) + if (ev.xbutton.y < int_bwidth + || Pixel2Row (ev.xbutton.y) > (nrow-1)) { int dist; - pending_scroll_selection=1; - /* don't clobber the current delay if we are * already in the middle of scrolling. */ - if (scroll_selection_delay<=0) - scroll_selection_delay=SCROLLBAR_CONTINUOUS_DELAY; + if (!sel_scroll_ev.is_active ()) + sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); /* save the event params so we can highlight * the selection in the pending-scroll loop */ - selection_save_x=ev.xbutton.x; - selection_save_y=ev.xbutton.y; - selection_save_state= - (ev.xbutton.state & Button3Mask) ? 2 : 0; + selection_save_x = ev.xbutton.x; + selection_save_y = ev.xbutton.y; + selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; /* calc number of lines to scroll */ - if (ev.xbutton.ydisplay, scrollBar.win, - MotionNotify, &ev)) ; - XQueryPointer (display->display, scrollBar.win, + while (XCheckTypedWindowEvent (dpy, scrollBar.win, + MotionNotify, &ev)) + ; + + XQueryPointer (dpy, scrollBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, - & (ev.xbutton.x), & (ev.xbutton.y), + &ev.xbutton.x, &ev.xbutton.y, &unused_mask); - scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, - scrollbar_size ()); - scr_refresh (refresh_type); - refresh_limit = 0; - scrollbar_show (1); + scr_move_to (scrollBar.position (ev.xbutton.y) - csrO, + scrollBar.size ()); + want_refresh = 1; + scrollBar.show (1); } break; } + +#if defined(CURSOR_BLINK) + if (ev.type == KeyPress) + cursor_blink_reset (); +#endif + +#if defined(POINTER_BLANK) + if (option (Opt_pointerBlank) && pointerBlankDelay > 0) + { + if (ev.type == MotionNotify + || ev.type == ButtonPress + || ev.type == ButtonRelease) + if (hidden_pointer) + pointer_unblank (); + + if (ev.type == KeyPress && hidden_pointer == 0) + 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) + { + focus = 1; + want_refresh = 1; + +#if USE_XIM + if (Input_Context != NULL) + { + im_set_position (); + XSetICFocus (Input_Context); + } +#endif +#if CURSOR_BLINK + if (option (Opt_cursorBlink)) + cursor_blink_ev.again (); +#endif +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + pix_colors = pix_colors_focused; + scr_recolour (); + } +#endif +#if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + set_urgency (0); +#endif + + HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); + } +} + +void ecb_cold +rxvt_term::focus_out () +{ + if (focus) + { + focus = 0; + want_refresh = 1; + +#if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + set_urgency (0); +#endif +#if ENABLE_FRILLS || ISO_14755 + if (iso14755buf) + { + iso14755buf = 0; +# if ISO_14755 + scr_overlay_off (); +# endif + } +#endif +#if USE_XIM + if (Input_Context != NULL) + XUnsetICFocus (Input_Context); +#endif +#if CURSOR_BLINK + if (option (Opt_cursorBlink)) + cursor_blink_ev.stop (); + + hidden_cursor = 0; +#endif +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + pix_colors = pix_colors_unfocused; + scr_recolour (); + } +#endif + + HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); + } +} + +void ecb_cold +rxvt_term::update_fade_color (unsigned int idx) +{ +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + rgba c; + pix_colors [Color_fade].get (c); + pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c); + } +#endif +} + +#if ENABLE_TRANSPARENCY || ENABLE_PERL +void ecb_hot rxvt_term::rootwin_cb (XEvent &ev) { - SET_R (this); - SET_LOCALE (locale); + make_current (); + + if (SHOULD_INVOKE (HOOK_ROOT_EVENT) + && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END))) + return; +# if ENABLE_TRANSPARENCY switch (ev.type) { case PropertyNotify: - if (ev.xproperty.atom == xa[XA_VT_SELECTION]) - { - if (ev.xproperty.state == PropertyNewValue) - selection_property (ev.xproperty.window, ev.xproperty.atom); - break; - } -#ifdef TRANSPARENT - else + /* + * if user used some Esetroot compatible prog to set the root bg, + * use the property to determine the pixmap. We use it later on. + */ + if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID] + || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) { - /* - * if user used some Esetroot compatible prog to set the root bg, - * use the property to determine the pixmap. We use it later on. - */ - if (xa[XA_XROOTPMAPID] == 0) - xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False); - - if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) - return; + bg_set_root_pixmap (); + update_background (); } - /* FALLTHROUGH */ - case ReparentNotify: - if ((Options & Opt_transparent) && check_our_parents ()) - if (am_transparent) - want_full_refresh = 1; break; -#endif } +# endif + + refresh_check (); } +#endif void -rxvt_term::button_press (const XButtonEvent &ev) +rxvt_term::button_press (XButtonEvent &ev) { int reportmode = 0, clickintime; bypass_keystate = ev.state & (ModMetaMask | ShiftMask); + if (!bypass_keystate) - reportmode = !! (PrivateModes & PrivMode_mouse_report); + reportmode = !! (priv_modes & PrivMode_mouse_report); + /* * VT window processing of button press */ - if (ev.window == TermWin.vt) + if (ev.window == vt) { + if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END))) + return; + +#if ISO_14755 + // 5.4 + if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) + { + iso14755_54 (ev.x, ev.y); + return; + } +#endif + clickintime = ev.time - MEvent.time < MULTICLICK_TIME; + if (reportmode) { /* mouse report from vt window */ @@ -1577,8 +1906,9 @@ #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) { /* only report double clicks */ @@ -1600,18 +1930,27 @@ #else MEvent.button = ev.button; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ } else { if (ev.button != MEvent.button) MEvent.clicks = 0; + switch (ev.button) { case Button1: + /* allow meta + click to select rectangular areas */ + /* should be done in screen.C */ +#if ENABLE_FRILLS + selection.rect = !!(ev.state & ModMetaMask); +#else + selection.rect = false; +#endif + /* allow shift+left click to extend selection */ - if (ev.state & ShiftMask && ! (PrivateModes & PrivMode_mouse_report)) + if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report)) { if (MEvent.button == Button1 && clickintime) selection_rotate (ev.x, ev.y); @@ -1636,10 +1975,12 @@ selection_rotate (ev.x, ev.y); else selection_extend (ev.x, ev.y, 1); + MEvent.button = Button3; break; } } + MEvent.time = ev.time; return; } @@ -1647,9 +1988,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 @@ -1668,15 +2016,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) @@ -1693,129 +2035,116 @@ } } else -#endif /* NO_SCROLLBAR_REPORT */ - +#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 - scroll_arrow_delay = SCROLLBAR_INITIAL_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 ()); - scrollBar.setMotion (); + + 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.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, TermWin.nrow - 1); + scr_page (UP, nrow - 1); # else - scr_page (UP, TermWin.nrow / 4); + 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, TermWin.nrow - 1); + scr_page (DN, nrow - 1); # else - scr_page (DN, TermWin.nrow / 4); + scr_page (DN, nrow / 4); # endif else - scrollBar.setMotion (); + scrollBar.state = SB_STATE_MOTION; } else { scr_page ((ev.button == Button1 ? DN : UP), - (TermWin.nrow - * scrollbar_position (ev.y) - / scrollbar_size ())); + (nrow + * scrollBar.position (ev.y) + / scrollBar.size ())); } + break; } } + return; } -#if MENUBAR - /* - * Menubar window processing of button press - */ - if (isMenuBarWindow (ev.window)) - menubar_control (ev); -#endif } void -rxvt_term::button_release (const XButtonEvent &ev) +rxvt_term::button_release (XButtonEvent &ev) { int reportmode = 0; csrO = 0; /* reset csr Offset */ if (!bypass_keystate) - reportmode = !! (PrivateModes & PrivMode_mouse_report); + 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); -#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - refresh_type &= ~SMOOTH_REFRESH; -#endif - + scrollBar.state = SB_STATE_IDLE; + scrollBar.show (0); } + #ifdef SELECTION_SCROLLING - pending_scroll_selection=0; + sel_scroll_ev.stop(); #endif - if (ev.window == TermWin.vt) + + if (ev.window == vt) { + if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) + return; + +#if ISO_14755 + // 5.4 + if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) + return; +#endif + if (reportmode) { /* mouse report from vt window */ @@ -1836,14 +2165,15 @@ #else /* MOUSE_REPORT_DOUBLECLICK */ MEvent.button = AnyButton; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ return; } + /* * dumb hack to compensate for the failure of click-and-drag * when overriding mouse reporting */ - if (PrivateModes & PrivMode_mouse_report + if (priv_modes & PrivMode_mouse_report && bypass_keystate && ev.button == Button1 && MEvent.clicks <= 1) selection_extend (ev.x, ev.y, 0); @@ -1854,9 +2184,12 @@ case Button3: selection_make (ev.time); break; + case Button2: - selection_request (ev.time, ev.x, ev.y); + 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: @@ -1864,300 +2197,276 @@ int i; page_dirn v; - v = (ev.button == Button4) ? UP : DN; + v = ev.button == Button4 ? UP : DN; + if (ev.state & ShiftMask) i = 1; - else if ((Options & Opt_mouseWheelScrollPage)) - i = TermWin.nrow - 1; + else if (option (Opt_mouseWheelScrollPage)) + i = nrow - 1; else i = 5; + # ifdef MOUSE_SLIP_WHEELING if (ev.state & ControlMask) { - mouse_slip_wheel_speed += (v ? -1 : 1); - mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY; + 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; + + if (!slip_wheel_ev.is_active ()) + slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); } + else # endif -# ifdef JUMP_MOUSE_WHEEL - scr_page (v, i); - scr_refresh (SMOOTH_REFRESH); - scrollbar_show (1); -# else - while (i--) { - scr_page (v, 1); - scr_refresh (SMOOTH_REFRESH); - scrollbar_show (1); + scr_page (v, i); + scrollBar.show (1); } -# endif - } break; #endif - } } -#ifdef MENUBAR - else if (isMenuBarWindow (ev.window)) - menubar_control (ev); -#endif } +/*}}} */ -#ifdef TRANSPARENT -/* - * Check our parents are still who we think they are. - * Do transparency updates if required - */ -int -rxvt_term::check_our_parents () +void ecb_hot +rxvt_term::cmd_parse () { - int i, pchanged, aformat, have_pixmap, rootdepth; - unsigned long nitems, bytes_after; - Atom atype; - unsigned char *prop = NULL; - Window root, oldp, *list; - Pixmap rootpixmap = None; - XWindowAttributes wattr, wrootattr; - - pchanged = 0; - - if (! (Options & Opt_transparent)) - return pchanged; /* Don't try any more */ + wchar_t ch = NOCHAR; + char *seq_begin; // remember start of esc-sequence here - XGetWindowAttributes (display->display, display->root, &wrootattr); - rootdepth = wrootattr.depth; - - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); - if (rootdepth != wattr.depth) + for (;;) { - if (am_transparent) + if (ecb_unlikely (ch == NOCHAR)) { - pchanged = 1; - XSetWindowBackground (display->display, TermWin.vt, - PixColors[Color_bg]); - am_transparent = am_pixmap_trans = 0; - } - return pchanged; /* Don't try any more */ - } + seq_begin = cmdbuf_ptr; + ch = next_char (); - /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (display->display, False); + if (ch == NOCHAR) + break; + } - /* - * Make the frame window set by the window manager have - * the root background. Some window managers put multiple nested frame - * windows for each client, so we have to take care about that. - */ - i = (xa[XA_XROOTPMAPID] != 0 - && (XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], - 0L, 1L, False, XA_PIXMAP, &atype, &aformat, - &nitems, &bytes_after, &prop) == Success)); - if (!i || prop == NULL) - have_pixmap = 0; - else - { - have_pixmap = 1; - rootpixmap = * ((Pixmap *)prop); - XFree (prop); - } - if (have_pixmap) - { - /* - * Copy display->root pixmap transparency - */ - int sx, sy, nx, ny; - unsigned int nw, nh; - Window cr; - XImage *image; - GC gc; - XGCValues gcvalue; - - XTranslateCoordinates (display->display, TermWin.parent[0], display->root, - 0, 0, &sx, &sy, &cr); - nw = (unsigned int)szHint.width; - nh = (unsigned int)szHint.height; - nx = ny = 0; - if (sx < 0) - { - nw += sx; - nx = -sx; - sx = 0; - } - if (sy < 0) - { - nh += sy; - ny = -sy; - sy = 0; - } - MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); - MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); - allowedxerror = -1; - image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, - ZPixmap); - /* XXX: handle BadMatch - usually because we're outside the pixmap */ - /* XXX: may need a delay here? */ - allowedxerror = 0; - if (image == NULL) + if (ecb_likely (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)) { - if (am_transparent && am_pixmap_trans) + if (ecb_unlikely (!seen_input)) { - pchanged = 1; - if (TermWin.pixmap != None) + seen_input = 1; + // many badly-written programs (e.g. jed) contain a race condition: + // they first read the screensize and then install a SIGWINCH handler. + // some window managers resize the window early, and these programs + // then sometimes get the size wrong. + // unfortunately other programs are even more buggy and dislike + // being sent SIGWINCH, so only do it when we were in fact being + // resized. + if (seen_resize && cmd_pid) + kill (-cmd_pid, SIGWINCH); + } + + /* Read a text string from the input buffer */ + wchar_t buf[UBUFSIZ]; + bool refreshnow = false; + int nlines = 0; + wchar_t *str = buf; + wchar_t *eol = str + min (ncol, UBUFSIZ); + + for (;;) + { + if (ecb_unlikely (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))) + break; + + *str++ = ch; + + if (ecb_unlikely (ch == C0_LF || str >= eol)) { - XFreePixmap (display->display, TermWin.pixmap); - TermWin.pixmap = None; + if (ch == C0_LF) + nlines++; + + refresh_count++; + + if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1) + { + refresh_count = 0; + + if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.) + { + refreshnow = true; + ch = NOCHAR; + break; + } + } + + // scr_add_lines only works for nlines <= nrow - 1. + if (nlines >= nrow - 1) + { + if (!(SHOULD_INVOKE (HOOK_ADD_LINES) + && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) + scr_add_lines (buf, str - buf, nlines); + + nlines = 0; + str = buf; + eol = str + min (ncol, UBUFSIZ); + } + + if (str >= eol) + { + if (eol >= buf + UBUFSIZ) + { + ch = NOCHAR; + break; + } + else + eol = min (eol + ncol, buf + UBUFSIZ); + } + } + + seq_begin = cmdbuf_ptr; + ch = next_char (); + } + + if (!(SHOULD_INVOKE (HOOK_ADD_LINES) + && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) + scr_add_lines (buf, str - buf, nlines); + + /* + * If there have been a lot of new lines, then update the screen + * What the heck we'll cheat and only refresh less than every page-full. + * if skipScroll is enabled. + */ + if (refreshnow) + { + scr_refresh (); + want_refresh = 1; } - am_pixmap_trans = 0; } else { - if (TermWin.pixmap != None) - XFreePixmap (display->display, TermWin.pixmap); - TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, - (unsigned int)szHint.width, - (unsigned int)szHint.height, - (unsigned int)image->depth); - gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); - XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, - nx, ny, (unsigned int)image->width, - (unsigned int)image->height); - XFreeGC (display->display, gc); - XDestroyImage (image); - XSetWindowBackgroundPixmap (display->display, TermWin.vt, - TermWin.pixmap); - if (!am_transparent || !am_pixmap_trans) - pchanged = 1; - am_transparent = am_pixmap_trans = 1; - } - } - if (!am_pixmap_trans) - { - unsigned int n; - /* - * InheritPixmap transparency - */ - D_X ((stderr, "InheritPixmap Seeking to %08lx", display->root)); - for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); - i++) - { - oldp = TermWin.parent[i]; - XQueryTree (display->display, TermWin.parent[i - 1], &root, - &TermWin.parent[i], &list, &n); - XFree (list); - D_X ((stderr, "InheritPixmap Parent[%d] = %08lx", i, TermWin.parent[i])); - if (TermWin.parent[i] == display->root) + try { - if (oldp != None) - pchanged = 1; - break; + process_nonprinting (ch); } - if (oldp != TermWin.parent[i]) - pchanged = 1; - } - n = 0; - if (pchanged) - { - for (; n < (unsigned int)i; n++) + catch (const class out_of_input &o) { - XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); - D_X ((stderr, "InheritPixmap Checking Parent[%d]: %s", n, (wattr.depth == rootdepth && wattr.class != InputOnly) ? "OK" : "FAIL")); - if (wattr.depth != rootdepth || wattr.c_class == InputOnly) - { - n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; - break; - } + // we ran out of input, retry later + cmdbuf_ptr = seq_begin; + break; } + + ch = NOCHAR; } - if (n > (int) (sizeof (TermWin.parent) - / sizeof (TermWin.parent[0]))) + } +} + +// read the next character +wchar_t ecb_hot +rxvt_term::next_char () NOTHROW +{ + while (cmdbuf_ptr < cmdbuf_endp) + { + // assume 7-bit to be ascii ALWAYS + if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) + return *cmdbuf_ptr++; + + wchar_t wc; + size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); + + if (len == (size_t)-2) { - D_X ((stderr, "InheritPixmap Turning off")); - XSetWindowBackground (display->display, TermWin.parent[0], - PixColors[Color_fg]); - XSetWindowBackground (display->display, TermWin.vt, - PixColors[Color_bg]); - am_transparent = 0; - /* XXX: also turn off Opt_transparent? */ + // the mbstate stores incomplete sequences. didn't know this :/ + cmdbuf_ptr = cmdbuf_endp; + break; } - else + + if (len == (size_t)-1) { - /* wait (an arbitrary period) for the WM to do its thing - * needed for fvwm2.2.2 (and before?) */ -# ifdef HAVE_NANOSLEEP - struct timespec rqt; - - rqt.tv_sec = 1; - rqt.tv_nsec = 0; - nanosleep (&rqt, NULL); -# else - sleep (1); -# endif - D_X ((stderr, "InheritPixmap Turning on (%d parents)", i - 1)); - for (n = 0; n < (unsigned int)i; n++) - XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], - ParentRelative); - XSetWindowBackgroundPixmap (display->display, TermWin.vt, - ParentRelative); - am_transparent = 1; + mbstate.reset (); // reset now undefined conversion state + return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through } - for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) - TermWin.parent[i] = None; + + // assume wchar == unicode + cmdbuf_ptr += len; + return wc & UNICODE_MASK; } - return pchanged; + + return NOCHAR; } -#endif -/*}}} */ +// read the next octet +uint32_t ecb_hot +rxvt_term::next_octet () NOTHROW +{ + return cmdbuf_ptr < cmdbuf_endp + ? (unsigned char)*cmdbuf_ptr++ + : NOCHAR; +} + +static class out_of_input out_of_input; + +wchar_t ecb_hot +rxvt_term::cmd_getc () THROW ((class out_of_input)) +{ + wchar_t c = next_char (); + + if (c == NOCHAR) + throw out_of_input; + + return c; +} + +uint32_t ecb_hot +rxvt_term::cmd_get8 () THROW ((class out_of_input)) +{ + uint32_t c = next_octet (); + + if (c == NOCHAR) + throw out_of_input; + + return c; +} /*{{{ 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_print_error ("can't open printer pipe"); + rxvt_warn ("can't open printer pipe, not printing.\n"); + return stream; } -int +int ecb_cold rxvt_term::pclose_printer (FILE *stream) { fflush (stream); - /* pclose () reported not to work on SunOS 4.1.3 */ -# if defined (__sun__) /* TODO: RESOLVE THIS */ - /* pclose works provided SIGCHLD handler uses waitpid */ - return pclose (stream); /* return fclose (stream); */ -# else return pclose (stream); -# endif } /* * 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]; - unsigned char ch; - unsigned int i, len; + unsigned char buf[8]; + unicode_t ch; + unsigned int i, len; if ((ch = cmd_getc ()) != C0_ESC) { @@ -2182,6 +2491,7 @@ break; /* done = 1 */ } } + for (i = 0; i < len; i++) if (putc (buf[i], fd) == EOF) { @@ -2190,35 +2500,34 @@ } } } + pclose_printer (fd); } -#endif /* PRINTPIPE */ +#endif /* PRINTPIPE */ /*}}} */ -/* *INDENT-OFF* */ enum { C1_40 = 0x40, - C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, + C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, 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 + C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, }; -/* *INDENT-ON* */ /*{{{ process non-printing single characters */ -void -rxvt_term::process_nonprinting (unsigned char ch) +void ecb_hot +rxvt_term::process_nonprinting (unicode_t ch) { switch (ch) { + case C0_ESC: + process_escape_seq (); + break; case C0_ENQ: /* terminal Status */ if (rs[Rs_answerbackstring]) - tt_write ( - (const unsigned char *)rs[Rs_answerbackstring], - (unsigned int)STRLEN (rs[Rs_answerbackstring])); + tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring])); else - tt_write ((unsigned char *)VT100_ANS, - (unsigned int)STRLEN (VT100_ANS)); + tt_write (VT100_ANS, strlen (VT100_ANS)); break; case C0_BEL: /* bell */ scr_bell (); @@ -2243,14 +2552,27 @@ case C0_SI: /* shift in - acs */ scr_charset_choose (0); break; + +#ifdef EIGHT_BIT_CONTROLS + // 8-bit controls + case 0x90: /* DCS */ + process_dcs_seq (); + break; + case 0x9b: /* CSI */ + process_csi_seq (); + break; + case 0x9d: /* OSC */ + process_osc_seq (); + break; +#endif } } /*}}} */ /*{{{ process VT52 escape sequences */ -void -rxvt_term::process_escape_vt52 (unsigned char ch) +void ecb_cold +rxvt_term::process_escape_vt52 (unicode_t ch) { int row, col; @@ -2293,7 +2615,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 */ @@ -2309,12 +2631,12 @@ /*{{{ process escape sequences */ -void +void ecb_hot rxvt_term::process_escape_seq () { - unsigned char ch = cmd_getc (); + unicode_t ch = cmd_getc (); - if (PrivateModes & PrivMode_vt52) + if (priv_modes & PrivMode_vt52) { process_escape_vt52 (ch); return; @@ -2322,7 +2644,6 @@ switch (ch) { - /* case 1: do_tek_mode (); break; */ case '#': if (cmd_getc () == '8') scr_E (); @@ -2339,12 +2660,7 @@ case '+': scr_charset_set (3, (unsigned int)cmd_getc ()); break; -#ifdef MULTICHAR_SET - case '$': - scr_charset_set (-2, (unsigned int)cmd_getc ()); - break; -#endif -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case '6': scr_backindex (); break; @@ -2355,14 +2671,17 @@ case '8': scr_cursor (RESTORE); break; -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case '9': 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: @@ -2375,14 +2694,16 @@ /* 8.3.87: NEXT LINE */ case C1_NEL: /* ESC E */ { - uint32_t nlcr[] = { '\n', '\r' }; - scr_add_lines (nlcr, 1, 2); + wchar_t nlcr[] = { C0_LF, C0_CR }; + 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 */ @@ -2396,10 +2717,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 */ @@ -2408,24 +2729,24 @@ /* 8.3.110: SINGLE CHARACTER INTRODUCER */ case C1_SCI: /* ESC Z */ - tt_write ((const unsigned char *)ESCZ_ANSWER, - (unsigned int) (sizeof (ESCZ_ANSWER) - 1)); + 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) */ @@ -2442,10 +2763,9 @@ /*}}} */ /*{{{ 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, + CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F, @@ -2455,13 +2775,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, */ @@ -2470,28 +2790,28 @@ make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ 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, {, |, }, ~, */ + make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ }; -/* *INDENT-ON* */ -void +void ecb_hot rxvt_term::process_csi_seq () { - unsigned char ch, priv, i; - unsigned int nargs, p; - int n, ndef; - int arg[ESC_ARGS]; + unicode_t ch, priv, i; + unsigned int nargs, p; + int n, ndef; + int arg[ESC_ARGS] = { }; - for (nargs = ESC_ARGS; nargs > 0;) - arg[--nargs] = 0; + nargs = 0; priv = 0; ch = cmd_getc (); - if (ch >= '<' && ch <= '?') - { /* '<' '=' '>' '?' */ + if ((ch >= '<' && ch <= '?') || ch == '!') + { + /* '<' '=' '>' '?' '!' */ priv = ch; ch = cmd_getc (); } + /* read any numerical arguments */ for (n = -1; ch < CSI_ICH; ) { @@ -2508,19 +2828,9 @@ arg[nargs++] = n; n = -1; } - else if (ch == '\b') - { - scr_backspace (); - } - else if (ch == C0_ESC) - { - process_escape_seq (); - return; - } - else if (ch < ' ') - { - process_nonprinting (ch); - } + else if (IS_CONTROL (ch)) + process_nonprinting (ch); + ch = cmd_getc (); } @@ -2536,13 +2846,6 @@ if (arg[p] == -1) arg[p] = ndef; -#ifdef DEBUG_CMD - fprintf (stderr, "CSI "); - for (p = 0; p < nargs; p++) - fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : ""); - fprintf (stderr, "%c\n", ch); -#endif - /* * private mode handling */ @@ -2552,13 +2855,38 @@ { case '>': if (ch == CSI_DA) /* secondary device attributes */ - tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING); + { + // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt, + // 'U' for rxvt-unicode != 7.[34] (where it was broken). + // + // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt + // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later + // versions. + // + 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; } @@ -2582,11 +2910,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; @@ -2667,12 +2995,11 @@ arg[0] = -arg[0]; /* FALLTHROUGH */ case CSI_SU: /* 8.3.148: (1) SCROLL UP */ - scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); + scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); break; case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ - tt_write ((const unsigned char *)VT100_ANS, - (unsigned int) (sizeof (VT100_ANS) - 1)); + tt_write (VT100_ANS, sizeof (VT100_ANS) - 1); break; case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ @@ -2688,13 +3015,12 @@ case 6: /* CPR requested */ scr_report_position (); break; -#if defined (ENABLE_DISPLAY_ANSWER) case 7: /* unofficial extension */ - tt_printf ("%-.250s\n", rs[Rs_display_name]); + if (option (Opt_insecure)) + tt_printf ("%-.250s\012", rs[Rs_display_name]); break; -#endif case 8: /* unofficial extension */ - xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST); + process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); break; } break; @@ -2737,11 +3063,15 @@ case CSI_RM: /* 8.3.107: RESET MODE */ if (arg[0] == 4) scr_insert_mode (0); + else if (arg[0] == 20) + priv_modes &= ~PrivMode_LFNL; break; case CSI_SM: /* 8.3.126: SET MODE */ if (arg[0] == 4) scr_insert_mode (1); + else if (arg[0] == 20) + priv_modes |= PrivMode_LFNL; break; /* @@ -2763,7 +3093,7 @@ scr_cursor (RESTORE); break; -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case CSI_74: process_window_ops (arg, nargs); break; @@ -2772,7 +3102,7 @@ case CSI_78: /* DECREQTPARM */ if (arg[0] == 0 || arg[0] == 1) tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2); - /* FALLTHROUGH */ + break; default: break; @@ -2780,88 +3110,97 @@ } /*}}} */ -#ifndef NO_FRILLS -/* ARGSUSED */ +#if !ENABLE_MINIMAL void rxvt_term::process_window_ops (const int *args, unsigned int nargs) { - int x, y; -#if 0 - char *s; -#endif + int x, y; XWindowAttributes wattr; - Window wdummy; + Window wdummy; + + dLocal (Display *, dpy); if (nargs == 0) return; + switch (args[0]) { - /* - * commands - */ + /* + * commands + */ case 1: /* deiconify window */ - XMapWindow (display->display, TermWin.parent[0]); + XMapWindow (dpy, parent); break; case 2: /* iconify window */ - XIconifyWindow (display->display, TermWin.parent[0], - DefaultScreen (display->display)); + XIconifyWindow (dpy, parent, display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (display->display, TermWin.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 (display->display, TermWin.parent[0]); + XRaiseWindow (dpy, parent); break; case 6: /* lower window */ - XLowerWindow (display->display, TermWin.parent[0]); + XLowerWindow (dpy, parent); break; case 7: /* refresh window */ scr_touch (true); break; case 8: /* set size (chars) */ - set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), - (unsigned int) (args[1] * TermWin.fheight)); + set_widthheight ((unsigned int) (args[2] * fwidth), + (unsigned int) (args[1] * fheight)); break; + + //case 9: NYI, TODO, restore maximized window or maximize window default: if (args[0] >= 24) /* set height (chars) */ - set_widthheight ((unsigned int)TermWin.width, - (unsigned int) (args[1] * TermWin.fheight)); + set_widthheight ((unsigned int)vt_width, + (unsigned int) (args[1] * fheight)); break; - /* - * reports - some output format copied from XTerm - */ + + /* + * reports - some output format copied from XTerm + */ case 11: /* report window state */ - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); - XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, - -wattr.border_width, -wattr.border_width, - &x, &y, &wdummy); + 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 (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; - case 18: /* report window size (chars) */ - tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); + case 18: /* report text area size (chars) */ + tt_printf ("\033[8;%d;%dt", nrow, ncol); + break; + case 19: /* report window size (chars) */ + tt_printf ("\033[9;%d;%dt", nrow, ncol); break; -#if 0 /* XXX: currently disabled due to security concerns */ case 20: /* report icon label */ - XGetIconName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ + { + char *s; + XGetIconName (dpy, parent, &s); + tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFree (s); + } break; case 21: /* report window title */ - XFetchName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ + { + char *s; + XFetchName (dpy, parent, &s); + tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFree (s); + } break; -#endif - } } #endif @@ -2869,41 +3208,51 @@ /*----------------------------------------------------------------------*/ /* * get input up until STRING TERMINATOR (or BEL) - * ends_how is terminator used. returned input must be free ()d + * ends_how is terminator used. returned input must be free()'d */ -unsigned char * -rxvt_term::get_to_st (unsigned char *ends_how) +char * +rxvt_term::get_to_st (unicode_t &ends_how) { - int seen_esc = 0; /* seen escape? */ - unsigned int n = 0; - unsigned char *s; - unsigned char ch, string[STRING_MAX]; + unicode_t ch; + bool seen_esc = false; + unsigned int n = 0; + wchar_t string[STRING_MAX]; - for (; (ch = cmd_getc ());) + while ((ch = cmd_getc ()) != NOCHAR) { - if (ch == C0_BEL - || ch == CHAR_ST - || (ch == 0x5c && seen_esc)) /* 7bit ST */ - break; - if (ch == C0_ESC) + if (seen_esc) { - seen_esc = 1; + if (ch == 0x5c) /* 7bit ST */ + break; + else + return NULL; + } + else if (ch == C0_ESC) + { + seen_esc = true; continue; } - else if (ch == '\t') - ch = ' '; /* translate '\t' to space */ - else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) + else if (ch == C0_BEL || ch == CHAR_ST) + break; + else if (ch == C0_SYN) + ch = cmd_get8 (); + else if (ch < 0x20) return NULL; /* other control character - exit */ - if (n < sizeof (string) - 1) - string[n++] = ch; - seen_esc = 0; + + seen_esc = false; + + if (n >= STRING_MAX - 1) + // stop at some sane length + return NULL; + + string[n++] = ch; } + string[n++] = '\0'; - if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) - return NULL; - *ends_how = (ch == 0x5c ? C0_ESC : ch); - STRNCPY (s, string, n); - return s; + + ends_how = (ch == 0x5c ? C0_ESC : ch); + + return rxvt_wcstombs (string); } /*----------------------------------------------------------------------*/ @@ -2913,13 +3262,15 @@ void rxvt_term::process_dcs_seq () { - unsigned char eh, *s; /* * Not handled yet */ - s = get_to_st (&eh); + + unicode_t eh; + char *s = get_to_st (eh); if (s) free (s); + return; } @@ -2930,159 +3281,253 @@ void rxvt_term::process_osc_seq () { - unsigned char ch, eh, *s; - int arg; + 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 == ';') { - s = get_to_st (&eh); + unicode_t eh; + char *s = get_to_st (eh); + if (s) { - /* - * rxvt_menubar_dispatch () violates the constness of the string, - * so do it here - */ - if (arg == XTerm_Menu) -#if 0 /* XXX: currently disabled due to security concerns */ - menubar_dispatch ((char *)s); -#else - (void)0; -#endif - else - xterm_seq (arg, (char *)s, eh); + process_xterm_seq (arg, s, eh); free (s); } } } + +void +rxvt_term::process_color_seq (int report, int color, const char *str, char resp) +{ + if (str[0] == '?' && !str[1]) + { + rgba c; + pix_colors_focused[color].get (c); + +#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); + else +#endif + tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp); + } + else + set_window_color (color, str); +} + /* * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) - * 0 = change iconName/title - * 1 = change iconName - * 2 = change title - * 4 = change color - * 12 = change text color - * 13 = change mouse foreground color - * 17 = change highlight character colour - * 18 = change bold character color - * 19 = change underlined character color - * 46 = change logfile (not implemented) - * 50 = change font - * - * rxvt extensions: - * 9 = change locale (NYI) - * 10 = menu (may change in future) - * 20 = bg pixmap - * 39 = change default fg color - * 49 = change default bg color - * 55 = dump scrollback buffer and all of screen */ void -rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) +rxvt_term::process_xterm_seq (int op, char *str, char resp) { - int changed = 0; - int color; - char *buf, *name; + int color; + char *buf, *name; + bool query = str[0] == '?' && !str[1]; + int saveop = op; + + dLocal (Display *, dpy); assert (str != NULL); + + if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END))) + return; + switch (op) { case XTerm_name: set_title (str); /* FALLTHROUGH */ case XTerm_iconName: - set_iconName (str); + set_icon_name (str); break; case XTerm_title: set_title (str); break; + case XTerm_property: + if (str[0] == '?') + { + Atom prop = display->atom (str + 1); + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes_after; + unsigned char *value = 0; + const char *str = ""; + + if (prop + && XGetWindowProperty (dpy, parent, + prop, 0, 1<<16, 0, AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &value) == Success + && actual_type != None + && actual_format == 8) + str = (const char *)(value); + + tt_printf ("\033]%d;%s%c", op, str, resp); + + XFree (value); + } + else + { + char *eq = strchr (str, '='); + + if (eq) + { + *eq = 0; + set_utf8_property (display->atom (str), eq + 1); + } + else + XDeleteProperty (dpy, parent, + display->atom (str)); + } + break; + case XTerm_Color: for (buf = (char *)str; buf && *buf;) { - if ((name = STRCHR (buf, ';')) == NULL) + if ((name = strchr (buf, ';')) == NULL) break; + *name++ = '\0'; - color = atoi (buf); - if (color < 0 || color >= TOTAL_COLORS) + color = atoi (buf) + minCOLOR; + + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) break; - if ((buf = STRCHR (name, ';')) != NULL) + + if ((buf = strchr (name, ';')) != NULL) *buf++ = '\0'; - set_window_color (color + minCOLOR, name); + + 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; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - set_window_color (Color_cursor, str); + process_color_seq (op, Color_cursor, str, resp); break; #endif - case XTerm_Color_pointer: - set_window_color (Color_pointer, str); + case XTerm_Color_pointer_fg: + process_color_seq (op, Color_pointer_fg, str, resp); + break; + case XTerm_Color_pointer_bg: + process_color_seq (op, Color_pointer_bg, str, resp); + break; +#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; +#endif #ifndef NO_BOLD_UNDERLINE_REVERSE - case XTerm_Color_BD: - set_window_color (Color_BD, str); + case URxvt_Color_BD: + process_color_seq (op, Color_BD, str, resp); break; - case XTerm_Color_UL: - set_window_color (Color_UL, str); + case URxvt_Color_UL: + process_color_seq (op, Color_UL, str, resp); break; - case XTerm_Color_RV: - set_window_color (Color_RV, str); + case URxvt_Color_IT: + process_color_seq (op, Color_IT, str, resp); break; #endif + case URxvt_Color_border: + process_color_seq (op, Color_border, str, resp); + break; +#if ENABLE_TRANSPARENCY + case URxvt_Color_tint: + process_color_seq (op, Color_tint, str, resp); + { + bool changed = false; + + if (ISSET_PIXCOLOR (Color_tint)) + changed = root_effects.set_tint (pix_colors_focused [Color_tint]); + + if (changed) + update_background (); + } - case XTerm_Menu: - /* - * rxvt_menubar_dispatch () violates the constness of the string, - * so DON'T do it here - */ break; - case XTerm_Pixmap: - if (*str != ';') - { -#if XPM_BACKGROUND - scale_pixmap (""); /* reset to default scaling */ - set_bgPixmap (str); /* change pixmap */ #endif - scr_touch (true); - } - while ((str = STRCHR (str, ';')) != NULL) + +#if BG_IMAGE_FROM_FILE + case Rxvt_Pixmap: + if (!strcmp (str, "?")) { - str++; -#if XPM_BACKGROUND - changed += scale_pixmap (str); -#endif + char str[256]; + int h_scale = 0, v_scale = 0; + int h_align = 0, v_align = 0; + if (image_vec.size () > 0) + { + h_scale = image_vec[0].h_scale; + v_scale = image_vec[0].v_scale; + h_align = image_vec[0].h_align; + v_align = image_vec[0].v_align; + } + sprintf (str, "[%dx%d+%d+%d]", + h_scale, v_scale, + h_align, v_align); + process_xterm_seq (XTerm_title, str, CHAR_ST); } - if (changed) + else { -#ifdef XPM_BACKGROUND - resize_pixmap (); -#endif - scr_touch (true); + bool changed = false; + + if (*str != ';') + { + if (image_vec.size () > 0) + changed = image_vec[0].set_file_geometry (str); + else + { + rxvt_image *image = new_image (); + if (!image->set_file_geometry (str)) + image_vec.pop_back (); + else + changed = true; + } + } + else + { + str++; + if (image_vec.size () > 0) + changed = image_vec[0].set_geometry (str, true); + } + + if (changed) + { + if (bg_window_position_sensitive ()) + { + int x, y; + get_window_origin (x, y); + bg_set_position (x, y); + } + update_background (); + } } break; +#endif - case XTerm_restoreFG: - set_window_color (Color_fg, str); - break; - case XTerm_restoreBG: - set_window_color (Color_bg, str); - break; case XTerm_logfile: + // TODO, when secure mode? break; - case XTerm_font: - change_font (str); - break; - case XTerm_locale: - /* TODO */ - break; + #if 0 - case XTerm_dumpscreen: /* no error notices */ + case Rxvt_dumpscreen: /* no error notices */ { - int fd; + int fd; if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) { scr_dump (fd); @@ -3091,7 +3536,68 @@ } break; #endif + case XTerm_font: + op = URxvt_font; + case URxvt_font: +#if ENABLE_STYLES + case URxvt_boldFont: + case URxvt_italicFont: + case URxvt_boldItalicFont: +#endif + if (query) + tt_printf ("\33]%d;%-.250s%c", saveop, + option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc + ? fontset[op - URxvt_font]->fontdesc : "", + resp); + else + { + const char *&res = rs[Rs_font + (op - URxvt_font)]; + + res = strdup (str); + allocated.push_back ((void *)res); + set_fonts (); + } + break; + + case URxvt_version: + if (query) + tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", + op, + rs[Rs_name], VERSION[0], VERSION[2], + resp); + break; + +#if !ENABLE_MINIMAL + case URxvt_locale: + if (query) + tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp); + else + { + set_locale (str); + pty->set_utf8_mode (enc_utf8); + init_xlocale (); + } + break; + + case URxvt_view_up: + case URxvt_view_down: + { + int lines = atoi (str); + if (lines) + scr_page (op == URxvt_view_up ? UP : DN, lines); + else + scr_erase_savelines (); + } + + break; +#endif + +#if ENABLE_PERL + case URxvt_perl: + HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END)); + break; +#endif } } /*----------------------------------------------------------------------*/ @@ -3106,14 +3612,17 @@ * 't' = toggle * so no need for fancy checking */ -int +int ecb_cold rxvt_term::privcases (int mode, unsigned long bit) { - int state; + int state; if (mode == 's') { - SavedModes |= (PrivateModes & bit); + if (priv_modes & bit) + SavedModes |= bit; + else + SavedModes &= ~bit; return -1; } else @@ -3121,51 +3630,74 @@ if (mode == 'r') state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ else - state = (mode == 't') ? ! (PrivateModes & bit) : mode; - PrivMode (state, bit); + state = (mode == 't') ? ! (priv_modes & bit) : mode; + + if (state) + priv_modes |= bit; + else + priv_modes &= ~bit; } + return state; } /* we're not using priv _yet_ */ void -rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((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; + unsigned int i, j; + int state; + static const struct - { - 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 }, + { + const int argval; + const unsigned long bit; + } argtopriv[] = { + { 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 }, -#ifdef menuBar_esc - { menuBar_esc, PrivMode_menuBar }, -#endif + // 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 - { 25, PrivMode_VisibleCursor }, - { 35, PrivMode_ShiftKeys }, + { 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 }, - { 1010, PrivMode_TtyOutputInh }, - { 1011, PrivMode_Keypress }, + { 1002, PrivMode_MouseBtnEvent }, + { 1003, PrivMode_MouseAnyEvent }, +#if ENABLE_FRILLS + { 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 }, - { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */ + // 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) @@ -3182,7 +3714,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); @@ -3190,127 +3722,139 @@ } /* extra handling for values with state unkept */ - if (state == -1) - switch (arg[i]) - { - case 1048: /* alternative cursor save */ + switch (arg[i]) + { +#if ENABLE_STYLES + case 1021: + set_option (Opt_intensityStyles, mode); + + scr_touch (true); + break; +#endif + case 1048: /* alternative cursor save */ + if (option (Opt_secondaryScreen)) if (mode == 0) scr_cursor (RESTORE); else if (mode == 1) scr_cursor (SAVE); - /* FALLTHROUGH */ - default: - continue; /* for (;i;) */ - } - - /* extra handling for values with valid 0 or 1 state */ - switch (arg[i]) - { - /* case 1: - application cursor keys */ - case 2: /* VT52 mode */ - /* oddball mode. should be set regardless of set/reset - * parameter. Return from VT52 mode with an ESC < from - * within VT52 mode - */ - PrivMode (1, PrivMode_vt52); - break; - case 3: /* 80/132 */ - if (PrivateModes & PrivMode_132OK) - set_widthheight ( (unsigned int) ((state ? 132 : 80) * TermWin.fwidth), - (unsigned int)TermWin.height); - break; - case 4: /* smooth scrolling */ - if (state) - Options &= ~Opt_jumpScroll; - else - Options |= Opt_jumpScroll; - break; - case 5: /* reverse video */ - scr_rvideo_mode (state); - break; - case 6: /* relative/absolute origins */ - scr_relative_origin (state); - break; - case 7: /* autowrap */ - scr_autowrap (state); break; + } + + if (state >= 0) + /* extra handling for values with valid 0 or 1 state */ + switch (arg[i]) + { + /* case 1: - application cursor keys */ + case 2: /* VT52 mode */ + /* oddball mode. should be set regardless of set/reset + * parameter. Return from VT52 mode with an ESC < from + * within VT52 mode + */ + priv_modes |= PrivMode_vt52; + break; + case 3: /* 80/132 */ + if (priv_modes & PrivMode_132OK) + set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight); + break; + case 4: /* smooth scrolling */ + set_option (Opt_jumpScroll, !state); + break; + case 5: /* reverse video */ + scr_rvideo_mode (state); + break; + case 6: /* relative/absolute origins */ + scr_relative_origin (state); + break; + case 7: /* autowrap */ + scr_autowrap (state); + break; /* case 8: - auto repeat, can't do on a per window basis */ - case 9: /* X10 mouse reporting */ - if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX11); - break; -#ifdef menuBar_esc - case menuBar_esc: -#ifdef MENUBAR - map_menuBar (state); -#endif - break; -#endif + case 9: /* X10 mouse reporting */ + if (state) /* orthogonal */ + priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); + break; #ifdef scrollBar_esc - case scrollBar_esc: - if (scrollbar_mapping (state)) - { - resize_all_windows (0, 0, 0); - scr_touch (true); - } - break; + case scrollBar_esc: + scrollBar.map (state); + resize_all_windows (0, 0, 0); + scr_touch (true); + break; #endif - case 25: /* visible/invisible cursor */ - scr_cursor_visible (state); - break; + case 25: /* visible/invisible cursor */ + scr_cursor_visible (state); + break; /* case 35: - shift keys */ /* case 40: - 80 <--> 132 mode */ - case 47: /* secondary screen */ - scr_change_screen (state); - break; + case 47: /* secondary screen */ + scr_change_screen (state); + break; /* case 66: - application key pad */ /* case 67: - backspace key */ - case 1000: /* X11 mouse reporting */ - if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX10); - break; -#if 0 - case 1001: - break; /* X11 mouse highlighting */ -#endif - case 1010: /* scroll to bottom on TTY output inhibit */ - if (state) - Options &= ~Opt_scrollTtyOutput; - else - Options |= Opt_scrollTtyOutput; - break; - case 1011: /* scroll to bottom on key press */ - if (state) - Options |= Opt_scrollTtyKeypress; - else - Options &= ~Opt_scrollTtyKeypress; - break; - case 1047: /* secondary screen w/ clearing */ - case 1049: /* better secondary screen w/ clearing, but not fully implemented */ - if (current_screen != PRIMARY) - scr_erase_screen (2); - scr_change_screen (state); - /* FALLTHROUGH */ - default: - break; - } + case 1000: /* X11 mouse reporting */ + if (state) /* orthogonal */ + priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); + break; + case 1002: + case 1003: + if (state) + { + 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 */ + set_option (Opt_scrollTtyOutput, !state); + break; + case 1011: /* scroll to bottom on key press */ + set_option (Opt_scrollTtyKeypress, state); + break; + case 1047: /* secondary screen w/ clearing last */ + if (option (Opt_secondaryScreen)) + 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 (state) + scr_erase_screen (2); + else + scr_cursor (RESTORE); + break; + default: + break; + } } } /*}}} */ /*{{{ process sgr sequences */ -void +void ecb_hot rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) { - unsigned int i; - short rendset; - int rendstyle; + unsigned int i; + short rendset; + int rendstyle; if (nargs == 0) { scr_rendition (0, ~RS_None); return; } + for (i = 0; i < nargs; i++) { rendset = -1; @@ -3322,28 +3866,56 @@ case 1: rendset = 1, rendstyle = RS_Bold; break; + //case 2: // low intensity + case 3: + rendset = 1, rendstyle = RS_Italic; + break; case 4: rendset = 1, rendstyle = RS_Uline; break; - case 5: + case 5: // slowly blinking + case 6: // rapidly blinking rendset = 1, rendstyle = RS_Blink; break; + //case 6: // scoansi light background case 7: rendset = 1, rendstyle = RS_RVid; break; - case 22: + case 8: + // invisible. NYI + break; + //case 9: // crossed out + //case 10: // scoansi acs off, primary font + //case 11: // scoansi acs on, first alt font + //case 12: // scoansi acs on, |0x80, second alt font + //... + //case 19: // ninth alt font + //case 20: // gothic + case 21: // disable bold, faint, sometimes doubly underlined (iso 8613) + rendset = 0, rendstyle = RS_Bold; + break; + case 22: // normal intensity rendset = 0, rendstyle = RS_Bold; break; + case 23: // disable italic + rendset = 0, rendstyle = RS_Italic; + break; case 24: rendset = 0, rendstyle = RS_Uline; break; case 25: rendset = 0, rendstyle = RS_Blink; break; + case 26: // variable spacing (iso 8613) + rendset = 0, rendstyle = RS_Blink; + break; case 27: rendset = 0, rendstyle = RS_RVid; break; + //case 28: // visible. NYI + //case 29: // not crossed-out } + if (rendset != -1) { scr_rendition (rendset, rendstyle); @@ -3360,19 +3932,15 @@ case 35: case 36: case 37: - scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), - Color_fg); + scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); break; -#ifdef TTY_256COLOR - case 38: + case 38: // set fg color, ISO 8613-6 if (nargs > i + 2 && arg[i + 1] == 5) { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), - Color_fg); + scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); i += 2; } break; -#endif case 39: /* default fg */ scr_color (Color_fg, Color_fg); break; @@ -3385,24 +3953,22 @@ case 45: case 46: case 47: - scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), - Color_bg); + scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); break; -#ifdef TTY_256COLOR - case 48: + case 48: // set bg color, ISO 8613-6 if (nargs > i + 2 && arg[i + 1] == 5) { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), - Color_bg); + scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); i += 2; } break; -#endif case 49: /* default bg */ scr_color (Color_bg, Color_bg); break; -#ifndef NO_BRIGHTCOLOR + //case 50: // not variable spacing + +#if !ENABLE_MINIMAL case 90: case 91: /* set bright fg color */ case 92: @@ -3411,8 +3977,7 @@ case 95: case 96: case 97: - scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), - Color_fg); + scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg); break; case 100: case 101: /* set bright bg color */ @@ -3422,34 +3987,14 @@ case 105: case 106: case 107: - scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), - Color_bg); + scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); break; #endif - } } } /*}}} */ -/*{{{ process Rob Nation's own graphics mode sequences */ -void -rxvt_term::process_graphics () -{ - unsigned char ch, cmd = cmd_getc (); - - if (cmd == 'Q') - { /* query graphics */ - tt_printf ("\033G0\n"); /* no graphics */ - return; - } - /* swallow other graphics sequences until terminating ':' */ - do - ch = cmd_getc (); - while (ch != ':'); -} -/*}}} */ - /* ------------------------------------------------------------------------- */ /* @@ -3460,72 +4005,71 @@ rxvt_term::tt_printf (const char *fmt,...) { va_list arg_ptr; - unsigned char buf[256]; + char buf[256]; va_start (arg_ptr, fmt); vsnprintf ((char *)buf, 256, fmt, arg_ptr); va_end (arg_ptr); - tt_write (buf, STRLEN (buf)); + 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. */ +static const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT + void -rxvt_term::tt_write (const unsigned char *data, unsigned int len) +rxvt_term::tt_write (const char *data, unsigned int len) { - enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT - - if (len) - { - if (v_buflen == 0) - { - ssize_t written = write (cmd_fd, data, min (MAX_PTY_WRITE, len)); + if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) + return; - if ((unsigned int)written == len) - return; + if (pty->pty < 0) + return; - data += written; - len -= written; - } + if (v_buflen == 0) + { + ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE)); + max_it (written, 0); - v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); + if (written == len) + return; - memcpy (v_buffer + v_buflen, data, len); - v_buflen += len; + data += written; + len -= written; } - for (;;) - { - int written = write (cmd_fd, v_buffer, min (MAX_PTY_WRITE, v_buflen)); + v_buffer = (char *)rxvt_realloc (v_buffer, v_buflen + len); - if (written > 0) - { - v_buflen -= written; + memcpy (v_buffer + v_buflen, data, len); + v_buflen += len; - if (v_buflen == 0) - { - free (v_buffer); - v_buffer = 0; - v_buflen = 0; + pty_ev.set (ev::READ | ev::WRITE); +} - pty_ev.set (EVENT_READ); - return; - } +void rxvt_term::pty_write () +{ + int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); - memmove (v_buffer, v_buffer + written, v_buflen); - } - else if (written != -1 || (errno != EAGAIN && errno != EINTR)) - // original code just ignores this... - destroy (); - else + if (written > 0) + { + v_buflen -= written; + + if (v_buflen == 0) { - pty_ev.set (EVENT_READ | EVENT_WRITE); + free (v_buffer); + v_buffer = 0; + + pty_ev.set (ev::READ); return; } + + memmove (v_buffer, v_buffer + written, v_buflen); } + else if (written != -1 || (errno != EAGAIN && errno != EINTR)) + pty_ev.set (ev::READ); } /*----------------------- end-of-file (C source) -----------------------*/