--- rxvt-unicode/src/command.C 2004/07/26 18:01:19 1.97 +++ rxvt-unicode/src/command.C 2007/08/26 18:16:52 1.349 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: command.C *----------------------------------------------------------------------* * @@ -27,7 +27,7 @@ * 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-2006 Marc Lehmann * * 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,32 +45,273 @@ *----------------------------------------------------------------------*/ /*{{{ 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 /*----------------------------------------------------------------------*/ #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) -// exception thrown when the command parser runs out of input data -class out_of_input { } out_of_input; +#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 +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--; + } +} -/*{{{ Convert the keypress event into a string */ void -rxvt_term::lookup_key (XKeyEvent &ev) +rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) +{ + rxvt_fontset *fs = FONTSET (r); + rxvt_font *f = (*fs)[fs->find_font (ch)]; + wchar_t *chr, *alloc, ch2, *fname; + int len; + + fname = rxvt_utf8towcs (f->name); + +# 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 = wcswidth (fname, wcslen (fname)); + + max_it (width, 8+5); // for char + hey + max_it (width, strlen (attr)); + + if (y >= 0) + { + y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; + x = 0; + } + + scr_overlay_new (x, y, width, len + 2); + + 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 !UNICODE3 + 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); + scr_overlay_set (0, len + 1, fname); + + free (fname); + +# if ENABLE_COMBINING + if (alloc) + delete [] alloc; +# endif +} +#endif + +void +rxvt_term::commit_iso14755 () +{ + wchar_t ch[2]; + + ch[0] = iso14755buf & ISO_14755_MASK; + ch[1] = 0; + + if (iso14755buf & ISO_14755_51) + { + char mb[16]; + int len; + + // allow verbatim 0-bytes and control-bytes to be entered + if (ch[0] >= 0x20) + len = wcstombs (mb, ch, 16); + else + { + mb[0] = ch[0]; + len = 1; + } + + if (len > 0) + tt_write (mb, len); + else + scr_bell (); + } + + iso14755buf = 0; +} + +int +rxvt_term::hex_keyval (XKeyEvent &ev) +{ + // check wether 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 + +void +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 @@ -78,9 +319,9 @@ * * Always permit `shift' to override the current setting */ - shft = (ev.state & ShiftMask); - ctrl = (ev.state & ControlMask); - meta = (ev.state & ModMetaMask); + shft = ev.state & ShiftMask; + ctrl = ev.state & ControlMask; + meta = ev.state & ModMetaMask; if (numlock_state || (ev.state & ModNumLockMask)) { @@ -98,7 +339,7 @@ #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 @@ -110,9 +351,11 @@ // 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); @@ -143,27 +386,31 @@ else #endif { - len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); + len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose); valid_keysym = keysym != NoSymbol; } if (valid_keysym) { - if (TermWin.saveLines) +#ifdef KEYSYM_RESOURCE + if (keyboard->dispatch (this, keysym, ev.state)) + return; +#endif + + 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 if (keysym == XK_Prior) { @@ -201,7 +448,7 @@ } else if (keysym == XK_End) { - scr_move_to (1, 0); + scr_move_to (1, 1); return; } } @@ -216,14 +463,15 @@ 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); @@ -231,9 +479,65 @@ case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ change_font (FONT_DN); return; +#endif } } } + +#if ENABLE_FRILLS || ISO_14755 + // ISO 14755 support + if (shft && ctrl) + { + 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 ((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) { @@ -244,55 +548,40 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { -#ifdef KEYSYM_RESOURCE - if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) - { - unsigned int l; - const unsigned char *kbuf0; - - kbuf0 = (Keysym_map[keysym & 0xFF]); - l = (unsigned int)*kbuf0++; - - /* escape prefix */ - if (meta -# ifdef META8_OPTION - && meta_char == C0_ESC -# endif - ) - { - const unsigned char ch = C0_ESC; - tt_write (&ch, 1); - } - - tt_write (kbuf0, l); - return; - } - else -#endif { newlen = 1; switch (keysym) { #ifndef NO_BACKSPACE_KEY case XK_BackSpace: - if (PrivateModes & PrivMode_HaveBackSpace) + if (priv_modes & PrivMode_HaveBackSpace) { - kbuf[0] = (!! (PrivateModes & PrivMode_BackSpace) + kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) ^ !!ctrl) ? '\b' : '\177'; kbuf[1] = '\0'; } else - STRCPY (kbuf, key_backspace); + strcpy (kbuf, key_backspace); break; #endif #ifndef NO_DELETE_KEY +# ifdef XK_KP_Prior + case XK_KP_Delete: + /* allow shift to override */ + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) + { + strcpy (kbuf, "\033On"); + break; + } + /* FALLTHROUGH */ +# endif case XK_Delete: - STRCPY (kbuf, key_delete); + strcpy (kbuf, key_delete); break; #endif case XK_Tab: if (shft) - STRCPY (kbuf, "\033[Z"); + strcpy (kbuf, "\033[Z"); else { #ifdef CTRL_TAB_MAKES_META @@ -308,13 +597,13 @@ break; #ifdef XK_KP_Left - case XK_KP_Up: /* \033Ox or standard */ + 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) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033OZ"); + strcpy (kbuf, "\033OZ"); kbuf[2] = "txvr"[keysym - XK_KP_Left]; break; } @@ -327,7 +616,7 @@ case XK_Down: /* "\033[B" */ case XK_Right: /* "\033[C" */ case XK_Left: /* "\033[D" */ - STRCPY (kbuf, "\033[Z"); + strcpy (kbuf, "\033[Z"); kbuf[2] = "DACB"[keysym - XK_Left]; /* do Shift first */ if (shft) @@ -337,7 +626,7 @@ kbuf[1] = 'O'; kbuf[2] = "dacb"[keysym - XK_Left]; } - else if (PrivateModes & PrivMode_aplCUR) + else if (priv_modes & PrivMode_aplCUR) kbuf[1] = 'O'; break; @@ -345,61 +634,65 @@ # ifdef XK_KP_Prior case XK_KP_Prior: /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033Oy"); + strcpy (kbuf, "\033Oy"); break; } /* FALLTHROUGH */ # endif case XK_Prior: - STRCPY (kbuf, "\033[5~"); + strcpy (kbuf, "\033[5~"); break; # ifdef XK_KP_Next case XK_KP_Next: /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033Os"); + strcpy (kbuf, "\033Os"); break; } /* FALLTHROUGH */ # endif case XK_Next: - STRCPY (kbuf, "\033[6~"); + strcpy (kbuf, "\033[6~"); break; #endif case XK_KP_Enter: /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) + { + strcpy (kbuf, "\033OM"); + break; + } + + /* FALLTHROUGH */ + + case XK_Return: + if (priv_modes & PrivMode_LFNL) { - STRCPY (kbuf, "\033OM"); + kbuf[0] = '\015'; + kbuf[1] = '\012'; + kbuf[2] = '\0'; } else { - kbuf[0] = '\r'; + kbuf[0] = '\015'; kbuf[1] = '\0'; } break; #ifdef XK_KP_Begin case XK_KP_Begin: - STRCPY (kbuf, "\033Ou"); + strcpy (kbuf, "\033Ou"); break; - case XK_KP_Insert: - STRCPY (kbuf, "\033Op"); - 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"); + strcpy (kbuf, "\033OP"); kbuf[2] += (keysym - XK_KP_F1); break; @@ -420,9 +713,9 @@ case XK_KP_8: /* "\033Ox" : "8" */ case XK_KP_9: /* "\033Oy" : "9" */ /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033Oj"); + strcpy (kbuf, "\033Oj"); kbuf[2] += (keysym - XK_KP_Multiply); } else @@ -433,46 +726,57 @@ break; case XK_Find: - STRCPY (kbuf, "\033[1~"); + strcpy (kbuf, "\033[1~"); break; + +#ifdef XK_KP_Insert + case XK_KP_Insert: + /* allow shift to override */ + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) + { + strcpy (kbuf, "\033Op"); + break; + } + /* FALLTHROUGH */ +#endif case XK_Insert: - STRCPY (kbuf, "\033[2~"); + 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~"); + strcpy (kbuf, "\033[3~"); break; case XK_Select: - STRCPY (kbuf, "\033[4~"); + strcpy (kbuf, "\033[4~"); break; #ifdef XK_KP_End case XK_KP_End: /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033Oq"); + strcpy (kbuf, "\033Oq"); break; } /* FALLTHROUGH */ #endif case XK_End: - STRCPY (kbuf, KS_END); + strcpy (kbuf, KS_END); break; #ifdef XK_KP_Home case XK_KP_Home: /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) + if ((priv_modes & PrivMode_aplKP) ? !shft : shft) { - STRCPY (kbuf, "\033Ow"); + strcpy (kbuf, "\033Ow"); break; } /* FALLTHROUGH */ #endif case XK_Home: - STRCPY (kbuf, KS_HOME); + strcpy (kbuf, KS_HOME); break; #define FKEY(n, fkey) \ @@ -534,8 +838,9 @@ newlen = 0; break; } + if (newlen) - len = STRLEN (kbuf); + len = strlen (kbuf); } /* @@ -552,13 +857,18 @@ 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; @@ -570,13 +880,16 @@ } } + 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; } @@ -601,29 +914,93 @@ #endif ) { - const unsigned char ch = C0_ESC; + const char ch = C0_ESC; tt_write (&ch, 1); } -#if defined(DEBUG_CMD) - /* Display keyboard buffer contents */ - unsigned 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 */ +void +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 +} + +#if defined (KEYSYM_RESOURCE) unsigned int -rxvt_term::cmd_write (const unsigned char *str, unsigned int count) +rxvt_term::cmd_write (const char *str, unsigned int count) { unsigned int n, s; @@ -632,7 +1009,7 @@ if (n > 0 && s < count) { - MEMMOVE (cmdbuf_base, cmdbuf_ptr, + memmove (cmdbuf_base, cmdbuf_ptr, (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); cmdbuf_ptr = cmdbuf_base; cmdbuf_endp -= n; @@ -652,24 +1029,63 @@ return 0; } -#endif /* MENUBAR_MAX */ +#endif void rxvt_term::flush () { -#ifdef TRANSPARENT + flush_ev.stop (); + +#ifdef ENABLE_TRANSPARENCY if (want_full_refresh) { want_full_refresh = 0; scr_clear (); scr_touch (false); - want_refresh = 1; } #endif if (want_refresh) { - scr_refresh (refresh_type); + 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); #ifdef USE_XIM IMSendSpot (); @@ -682,9 +1098,20 @@ void rxvt_term::check_cb (check_watcher &w) { - SET_R (this); - SET_LOCALE (locale); + make_current (); + + display->flush (); + + if (want_refresh && !flush_ev.active) + flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally +} + +void +rxvt_term::flush_cb (time_watcher &w) +{ + make_current (); + refresh_count = 0; flush (); } @@ -695,7 +1122,7 @@ hidden_cursor = !hidden_cursor; want_refresh = 1; - w.start (w.at + BLINK_INTERVAL); + w.start (w.at + CURSOR_BLINK_INTERVAL); } #endif @@ -719,7 +1146,6 @@ if ((scrollbar_isUp() || scrollbar_isDn()) && scr_page (scrollbar_isUp() ? UP : DN, 1)) { - refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } @@ -733,7 +1159,6 @@ if (scr_page (scroll_selection_dir, scroll_selection_lines)) { selection_extend (selection_save_x, selection_save_y, selection_save_state); - refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } @@ -748,13 +1173,40 @@ || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) : scr_page (UP, mouse_slip_wheel_speed)) { - refresh_type |= SMOOTH_REFRESH; + if (view_start == top_row || view_start == 0) + mouse_slip_wheel_speed = 0; + want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } } #endif +#if LINUX_YIELD_HACK +static struct event_handler +{ + check_watcher yield_ev; + + void yield_cb (check_watcher &w) + { + // 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. + + struct timespec ts = { 0, 0 }; + nanosleep (&ts, 0); + + w.stop (); + } + + event_handler () + : yield_ev (this, &event_handler::yield_cb) + { + } +} event_handler; +#endif + bool rxvt_term::pty_fill () { @@ -762,7 +1214,7 @@ if (CBUFSIZ == n) { - rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); + rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n"); n = 0; } @@ -770,55 +1222,69 @@ cmdbuf_ptr = cmdbuf_base; cmdbuf_endp = cmdbuf_ptr + n; - n = read (cmd_fd, cmdbuf_endp, CBUFSIZ - n); + ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n); - if (n > 0) + if (r > 0) { - cmdbuf_endp += n; + cmdbuf_endp += r; return true; } - else if (n < 0 && errno != EAGAIN) - destroy (); - + 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 (); + + if (!option (Opt_hold)) + destroy (); + } + return false; } void rxvt_term::pty_cb (io_watcher &w, short revents) { - SET_R (this); - SET_LOCALE (locale); + make_current (); - if (revents & EVENT_WRITE) - tt_write (0, 0); - else if (revents & EVENT_READ) + if (revents & EVENT_READ) // loop, but don't allow a single term to monopolize us while (pty_fill ()) if (cmd_parse ()) break; + + if (revents & EVENT_WRITE) + pty_write (); } -#ifdef POINTER_BLANK void 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) + if (option (Opt_pointerBlank)) pointer_ev.start (NOW + pointerBlankDelay); +#endif } +#ifdef POINTER_BLANK void 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; } @@ -826,8 +1292,7 @@ void rxvt_term::pointer_cb (time_watcher &w) { - SET_R (this); - SET_LOCALE (locale); + make_current (); pointer_blank (); } @@ -844,9 +1309,7 @@ pixel_position (&x, &y); if (MEvent.button == AnyButton) - { - button_number = 3; - } + button_number = 3; else { button_number = MEvent.button - Button1; @@ -855,7 +1318,7 @@ button_number += (64 - 3); } - if (PrivateModes & PrivMode_MouseX10) + if (priv_modes & PrivMode_MouseX10) { /* * do not report ButtonRelease @@ -880,10 +1343,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); @@ -897,138 +1359,41 @@ button_number, x + 1, y + 1); -#else +#endif + tt_printf ("\033[M%c%c%c", (32 + button_number + key_state), (32 + x + 1), (32 + y + 1)); -#endif -} - -#ifdef USING_W11LIB -void -rxvt_W11_process_x_event (XEvent *ev) -{ - rxvt_t *r = rxvt_get_r (); - - x_cb (*ev); } -#endif /*{{{ process an X event */ void rxvt_term::x_cb (XEvent &ev) { - SET_R (this); - SET_LOCALE (locale); + make_current (); -#if defined(CURSOR_BLINK) - if ((Options & Opt_cursorBlink) && ev.type == KeyPress) - { - if (hidden_cursor) - { - hidden_cursor = 0; - want_refresh = 1; - } - - 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)) - slip_wheel_ev.stop (); - 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); @@ -1040,41 +1405,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)); - XFree (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; /* @@ -1103,132 +1462,111 @@ 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]) +/* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n", + ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y, + szHint.width, szHint.height);*/ + if (ev.xconfigure.window == parent[0]) { - int height, width; - - 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)); - } - while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); + while (XCheckTypedWindowEvent (dpy, 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 ENABLE_TRANSPARENCY + if (option (Opt_transparent)) + 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 PropertyNotify: + if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) + if (ev.xproperty.atom == xa[XA_VT_SELECTION] + && ev.xproperty.state == PropertyNewValue) + selection_property (ev.xproperty.window, ev.xproperty.atom); + + break; + case SelectionClear: selection_clear (); break; case SelectionNotify: if (selection_wait == Sel_normal) - selection_paste (ev.xselection.requestor, - ev.xselection.property, True); + selection_paste (ev.xselection.requestor, ev.xselection.property, true); break; case SelectionRequest: selection_send (ev.xselectionrequest); break; - case UnmapNotify: - TermWin.mapped = 0; + case MapNotify: + mapped = 1; #ifdef TEXT_BLINK - text_blink_ev.stop (); + text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); #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 +#ifdef ENABLE_TRANSPARENCY case ReparentNotify: rootwin_cb (ev); break; -#endif /* TRANSPARENT */ +#endif /* ENABLE_TRANSPARENCY */ 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 - // I don't understand this, so I changed it :) - 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 (dpy, ev.xany.window, Expose, &unused_event)) ; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) + while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) ; if (isScrollbarWindow (ev.xany.window)) @@ -1236,10 +1574,6 @@ scrollBar.setIdle (); scrollbar_show (0); } -#ifdef MENUBAR - if (menubar_visible () && isMenuBarWindow (ev.xany.window)) - menubar_expose (); -#endif } break; @@ -1248,38 +1582,43 @@ 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_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; @@ -1292,27 +1631,27 @@ /* 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; + want_refresh = 1; scrollbar_show (1); } break; } + +#if defined(CURSOR_BLINK) + if (option (Opt_cursorBlink) && ev.type == KeyPress) + { + if (hidden_cursor) + { + hidden_cursor = 0; + want_refresh = 1; + } + + cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + } +#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 } void +rxvt_term::focus_in () +{ + if (!focus) + { + focus = 1; + want_refresh = 1; + + HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); + +#if USE_XIM + if (Input_Context != NULL) + { + IMSetPosition (); + XSetICFocus (Input_Context); + } +#endif +#if CURSOR_BLINK + if (option (Opt_cursorBlink)) + cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); +#endif +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + pix_colors = pix_colors_focused; + scr_recolour (); + } +#endif +#if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + { + XWMHints *h; + + h = XGetWMHints(dpy, parent[0]); + if (h != NULL) + { + h->flags &= ~XUrgencyHint; + XSetWMHints(dpy, parent[0], h); + } + } +#endif + } +} + +void +rxvt_term::focus_out () +{ + if (focus) + { + focus = 0; + want_refresh = 1; + + HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); + +#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 + } +} + +void +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 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; + bgPixmap.set_root_pixmap (); + update_background (); } - - /* FALLTHROUGH */ - case ReparentNotify: - if ((Options & Opt_transparent) && check_our_parents () && am_transparent) - want_full_refresh = 1; break; -#endif } +# endif } +#endif void rxvt_term::button_press (XButtonEvent &ev) @@ -1393,14 +1845,29 @@ 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 */ @@ -1411,6 +1878,7 @@ { /* same button, within alloted time */ MEvent.clicks++; + if (MEvent.clicks > 1) { /* only report double clicks */ @@ -1439,11 +1907,20 @@ { 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); @@ -1468,10 +1945,12 @@ selection_rotate (ev.x, ev.y); else selection_extend (ev.x, ev.y, 1); + MEvent.button = Button3; break; } } + MEvent.time = ev.time; return; } @@ -1573,11 +2052,12 @@ 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 ()); + scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); + scrollBar.setMotion (); break; @@ -1591,15 +2071,15 @@ { 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)) # 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 (); @@ -1607,22 +2087,17 @@ else { scr_page ((ev.button == Button1 ? DN : UP), - (TermWin.nrow + (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 @@ -1632,23 +2107,30 @@ csrO = 0; /* reset csr Offset */ if (!bypass_keystate) - reportmode = !! (PrivateModes & PrivMode_mouse_report); + reportmode = !! (priv_modes & PrivMode_mouse_report); if (scrollbar_isUpDn ()) { scrollBar.setIdle (); scrollbar_show (0); -#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - refresh_type &= ~SMOOTH_REFRESH; -#endif - } + #ifdef SELECTION_SCROLLING if (sel_scroll_ev.active) 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 */ @@ -1672,11 +2154,12 @@ #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); @@ -1687,9 +2170,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, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? + selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); break; + #ifdef MOUSE_WHEEL case Button4: case Button5: @@ -1701,8 +2187,8 @@ 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; @@ -1710,514 +2196,37 @@ if (ev.state & ControlMask) { mouse_slip_wheel_speed += v ? -1 : 1; - slip_wheel_ev.start (NOW + SCROLLBAR_CONTINUOUS_DELAY); + 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.at < NOW) + slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; + + slip_wheel_ev.start (); } -# endif -# ifdef JUMP_MOUSE_WHEEL - scr_page (v, i); - scr_refresh (SMOOTH_REFRESH); - scrollbar_show (1); -# else - while (i--) + else { - scr_page (v, 1); - scr_refresh (SMOOTH_REFRESH); +# endif + scr_page (v, i); scrollbar_show (1); +# ifdef MOUSE_SLIP_WHEELING } # endif - } break; #endif - - } - } -#ifdef MENUBAR - else if (isMenuBarWindow (ev.window)) - menubar_control (ev); -#endif -} - -#ifdef TRANSPARENT -#if TINTING -/* shading taken from eterm-0.9.2 */ -/* RGB 15 */ - -static void -shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm) -{ - unsigned char *ptr; - int x, y; - - ptr = (unsigned char *)data + (w * sizeof(uint16_t)); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0;) { - for (x = -w; x < 0; x++) { - int r, g, b; - - b = ((uint16_t *) ptr)[x]; - r = (b & 0x7c00) * rm; - g = (b & 0x3e0) * gm; - b = (b & 0x1f) * bm; - ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00) - | ((g >> 8) & 0x3e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } else { - for (y = h; --y >= 0;) { - for (x = -w; x < 0; x++) { - int r, g, b; - - b = ((uint16_t *) ptr)[x]; - r = (b & 0x7c00) * rm; - g = (b & 0x3e0) * gm; - b = (b & 0x1f) * bm; - r |= (!(r >> 15) - 1); - g |= (!(g >> 10) - 1); - b |= (!(b >> 5) - 1); - ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00) - | ((g >> 8) & 0x3e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } -} - -/* RGB 16 */ -static void -shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm) -{ - unsigned char *ptr; - int x, y; - - ptr = (unsigned char *)data + (w * sizeof(uint16_t)); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0;) { - for (x = -w; x < 0; x++) { - int r, g, b; - - b = ((uint16_t *) ptr)[x]; - r = (b & 0xf800) * rm; - g = (b & 0x7e0) * gm; - b = (b & 0x1f) * bm; - ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800) - | ((g >> 8) & 0x7e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } else { - for (y = h; --y >= 0;) { - for (x = -w; x < 0; x++) { - int r, g, b; - - b = ((uint16_t *) ptr)[x]; - r = (b & 0xf800) * rm; - g = (b & 0x7e0) * gm; - b = (b & 0x1f) * bm; - r |= (!(r >> 16) - 1); - g |= (!(g >> 11) - 1); - b |= (!(b >> 5) - 1); - ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800) - | ((g >> 8) & 0x7e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } -} - -/* RGB 24 */ -static void -shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm) -{ - unsigned char *ptr; - int x, y; - - ptr = (unsigned char *)data + (w * 3); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0;) { - for (x = -(w * 3); x < 0; x += 3) { - int r, g, b; - - if (byteorder.big_endian()) { - r = (ptr[x + 0] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 2] * bm) >> 8; - ptr[x + 0] = r; - ptr[x + 1] = g; - ptr[x + 2] = b; - } else { - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; - } - } - ptr += bpl; - } - } else { - for (y = h; --y >= 0;) { - for (x = -(w * 3); x < 0; x += 3) { - int r, g, b; - - if (byteorder.big_endian()) { - r = (ptr[x + 0] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 2] * bm) >> 8; - - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); - - ptr[x + 0] = r; - ptr[x + 1] = g; - ptr[x + 2] = b; - } else { - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); - - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; - } - } - ptr += bpl; - } - } -} - -/* RGB 32 */ -static void -shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) -{ - unsigned char *ptr; - int x, y; - - ptr = (unsigned char *)data + (w * 4); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0;) { - if (byteorder.big_endian()) { - for (x = -(w * 4); x < 0; x += 4) { - int r, g, b; - - r = (ptr[x + 1] * rm) >> 8; - g = (ptr[x + 2] * gm) >> 8; - b = (ptr[x + 3] * bm) >> 8; - ptr[x + 1] = r; - ptr[x + 2] = g; - ptr[x + 3] = b; - } - } else { - for (x = -(w * 4); x < 0; x += 4) { - int r, g, b; - - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; - } - } - ptr += bpl; - } - } else { - for (y = h; --y >= 0;) { - for (x = -(w * 4); x < 0; x += 4) { - int r, g, b; - - if (byteorder.big_endian()) { - r = (ptr[x + 1] * rm) >> 8; - g = (ptr[x + 2] * gm) >> 8; - b = (ptr[x + 3] * bm) >> 8; - - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); - - ptr[x + 1] = r; - ptr[x + 2] = g; - ptr[x + 3] = b; - } else { - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); - - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; - } - } - ptr += bpl; } } } -#endif - -/* - * Check our parents are still who we think they are. - * Do transparency updates if required - */ -int -rxvt_term::check_our_parents () -{ - 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 */ - - XGetWindowAttributes (display->display, display->root, &wrootattr); - rootdepth = wrootattr.depth; - - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); - - if (rootdepth != wattr.depth) - { - if (am_transparent) - { - pchanged = 1; - XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); - am_transparent = am_pixmap_trans = 0; - } - - return pchanged; /* Don't try any more */ - } - - /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (display->display, False); - - /* - * 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] - && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], - 0L, 1L, False, XA_PIXMAP, &atype, &aformat, - &nitems, &bytes_after, &prop) == Success); - - if (!i || prop == NULL) - i = (xa[XA_XSETROOTID] - && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], - 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 (am_transparent && am_pixmap_trans) - { - pchanged = 1; - if (TermWin.pixmap != None) - { - XFreePixmap (display->display, TermWin.pixmap); - TermWin.pixmap = None; - } - } - - am_pixmap_trans = 0; - } - else - { - if (TermWin.pixmap != None) - XFreePixmap (display->display, TermWin.pixmap); - -#if TINTING - if (ISSET_PIXCOLOR (Color_tint)) - { - unsigned short shade, rm, gm, bm; - - PixColors[Color_tint].get (display, rm, gm, bm); - - rm >>= 8; gm >>= 8; bm >>= 8; // not 100% correct, but... - - /* Determine bitshift and bitmask values */ - switch (image->bits_per_pixel) - { - case 15: shade_ximage_15 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; - case 16: shade_ximage_16 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; - case 24: shade_ximage_24 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; - case 32: shade_ximage_32 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; - } - } -#endif - - TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, - szHint.width, szHint.height, image->depth); - gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); - XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, - nx, ny, image->width, 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) - { - if (oldp != None) - pchanged = 1; - - break; - } - - if (oldp != TermWin.parent[i]) - pchanged = 1; - } - - n = 0; - - if (pchanged) - { - for (; n < (unsigned int)i; n++) - { - 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; - } - } - } - - if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) - { - 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? */ - } - else - { -#if WAIT_FOR_WM - /* wait (an arbitrary period) for the WM to do its thing - * needed for fvwm2.2.2 (and before?) */ - 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; - } - - for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) - TermWin.parent[i] = None; - } - - return pchanged; -} -#endif - /*}}} */ bool rxvt_term::cmd_parse () { bool flag = false; - unicode_t ch = NOCHAR; - unsigned char *seq_begin; // remember start of esc-sequence here + wchar_t ch = NOCHAR; + char *seq_begin; // remember start of esc-sequence here for (;;) { @@ -2225,78 +2234,103 @@ { seq_begin = cmdbuf_ptr; ch = next_char (); - } - if (ch == NOCHAR) // TODO: improve - break; + if (ch == NOCHAR) + break; + } if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) { + if (!seen_input) + { + 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 */ - unicode_t buf[UBUFSIZ]; + wchar_t buf[UBUFSIZ]; bool refreshnow = false; int nlines = 0; - unicode_t *str = buf; - - *str++ = ch; + wchar_t *str = buf; + wchar_t *eol = str + min (ncol, UBUFSIZ); for (;;) { - seq_begin = cmdbuf_ptr; - ch = next_char (); - if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) break; *str++ = ch; - if (ch == C0_LF) + if (ch == C0_LF || str >= eol) { - nlines++; + if (ch == C0_LF) + nlines++; + refresh_count++; - if (! (Options & Opt_jumpScroll) - || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) + if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1) { - refreshnow = true; - flag = true; - ch = NOCHAR; - break; + refresh_count = 0; + + if (!option (Opt_skipScroll) || io_manager::now () > NOW + 1. / 60.) + { + refreshnow = true; + ch = NOCHAR; + break; + } } - // scr_add_lines only works for nlines < TermWin.nrow - 1. - if (nlines >= TermWin.nrow - 1) + // scr_add_lines only works for nlines <= nrow - 1. + if (nlines >= nrow - 1) { - scr_add_lines (buf, nlines, str - buf); + 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); } - } - if (str >= buf + UBUFSIZ) - { - ch = NOCHAR; - break; } + + seq_begin = cmdbuf_ptr; + ch = next_char (); } - scr_add_lines (buf, nlines, str - buf); + 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 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 + * What the heck we'll cheat and only refresh less than every page-full. + * if skipScroll is enabled. */ if (refreshnow) { - if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) - refresh_limit++; - else - scr_refresh (refresh_type); + flag = true; + scr_refresh (); + want_refresh = 1; } } @@ -2320,27 +2354,18 @@ return flag; } -// read the next octet -unicode_t -rxvt_term::next_octet () -{ - return cmdbuf_ptr < cmdbuf_endp - ? *cmdbuf_ptr++ - : NOCHAR; -} - // read the next character -unicode_t -rxvt_term::next_char () +wchar_t +rxvt_term::next_char () NOTHROW { while (cmdbuf_ptr < cmdbuf_endp) { // assume 7-bit to be ascii ALWAYS - if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) + if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) return *cmdbuf_ptr++; wchar_t wc; - size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); + size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); if (len == (size_t)-2) { @@ -2350,25 +2375,36 @@ } if (len == (size_t)-1) - return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through // assume wchar == unicode cmdbuf_ptr += len; - return wc; + return wc & UNICODE_MASK; } return NOCHAR; } +// read the next octet +uint32_t +rxvt_term::next_octet () NOTHROW +{ + return cmdbuf_ptr < cmdbuf_endp + ? (unsigned char)*cmdbuf_ptr++ + : NOCHAR; +} + +static class out_of_input out_of_input; + /* rxvt_cmd_getc () - Return next input character */ /* * Return the next input character after first passing any keyboard input * to the command. */ -unicode_t -rxvt_term::cmd_getc () +wchar_t +rxvt_term::cmd_getc () THROW ((class out_of_input)) { - unicode_t c = next_char (); + wchar_t c = next_char (); if (c == NOCHAR) throw out_of_input; @@ -2376,10 +2412,10 @@ return c; } -unicode_t -rxvt_term::cmd_get8 () +uint32_t +rxvt_term::cmd_get8 () THROW ((class out_of_input)) { - unicode_t c = next_octet (); + uint32_t c = next_octet (); if (c == NOCHAR) throw out_of_input; @@ -2453,7 +2489,7 @@ break; /* done = 1 */ } } - + for (i = 0; i < len; i++) if (putc (buf[i], fd) == EOF) { @@ -2489,11 +2525,9 @@ 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 (); @@ -2527,7 +2561,7 @@ case 0x9b: /* CSI */ process_csi_seq (); break; - case 0x9d: /* CSI */ + case 0x9d: /* OSC */ process_osc_seq (); break; #endif @@ -2602,7 +2636,7 @@ { unicode_t ch = cmd_getc (); - if (PrivateModes & PrivMode_vt52) + if (priv_modes & PrivMode_vt52) { process_escape_vt52 (ch); return; @@ -2627,7 +2661,7 @@ case '+': scr_charset_set (3, (unsigned int)cmd_getc ()); break; -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case '6': scr_backindex (); break; @@ -2638,7 +2672,7 @@ case '8': scr_cursor (RESTORE); break; -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case '9': scr_forwardindex (); break; @@ -2658,8 +2692,8 @@ /* 8.3.87: NEXT LINE */ case C1_NEL: /* ESC E */ { - unicode_t nlcr[] = { C0_LF, C0_CR }; - scr_add_lines (nlcr, 1, 2); + wchar_t nlcr[] = { C0_LF, C0_CR }; + scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1); } break; @@ -2691,8 +2725,7 @@ /* 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 */ @@ -2764,10 +2797,9 @@ unicode_t ch, priv, i; unsigned int nargs, p; int n, ndef; - int arg[ESC_ARGS]; + int arg[ESC_ARGS] = { }; - for (nargs = ESC_ARGS; nargs > 0;) - arg[--nargs] = 0; + nargs = 0; priv = 0; ch = cmd_getc (); @@ -2811,13 +2843,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 */ @@ -2827,7 +2852,16 @@ { 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, and 94 for later versions, to signify + // that we do not support xterm mouse reporting (should be 95 when we do). + // + tt_printf ("\033[>%d;94;0c", 'U'); + } break; case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') @@ -2942,12 +2976,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 */ @@ -2964,8 +2997,8 @@ scr_report_position (); break; case 7: /* unofficial extension */ - if (Options & Opt_insecure) - tt_printf ("%-.250s\n", rs[Rs_display_name]); + if (option (Opt_insecure)) + tt_printf ("%-.250s\012", rs[Rs_display_name]); break; case 8: /* unofficial extension */ process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); @@ -3011,11 +3044,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; /* @@ -3037,7 +3074,7 @@ scr_cursor (RESTORE); break; -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL case CSI_74: process_window_ops (arg, nargs); break; @@ -3054,7 +3091,7 @@ } /*}}} */ -#ifndef NO_FRILLS +#if !ENABLE_MINIMAL /* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) @@ -3063,6 +3100,8 @@ XWindowAttributes wattr; Window wdummy; + dLocal (Display *, dpy); + if (nargs == 0) return; @@ -3072,79 +3111,77 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (display->display, TermWin.parent[0]); + XMapWindow (dpy, parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (display->display, TermWin.parent[0], - DefaultScreen (display->display)); + XIconifyWindow (dpy, parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); + XMoveWindow (dpy, parent[0], 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[0]); break; case 6: /* lower window */ - XLowerWindow (display->display, TermWin.parent[0]); + XLowerWindow (dpy, parent[0]); 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)width, + (unsigned int) (args[1] * fheight)); break; - /* * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (dpy, parent[0], &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, + XGetWindowAttributes (dpy, parent[0], &wattr); + XTranslateCoordinates (dpy, parent[0], 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[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ - tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); + tt_printf ("\033[8;%d;%dt", nrow, ncol); break; case 19: /* report window size (chars) */ - tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); + tt_printf ("\033[9;%d;%dt", nrow, ncol); break; case 20: /* report icon label */ - if (Options & Opt_insecure) - { - char *s; - XGetIconName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ - } + { + char *s; + XGetIconName (dpy, parent[0], &s); + tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFree (s); + } break; case 21: /* report window title */ - if (Options & Opt_insecure) - { - char *s; - XFetchName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ - } + { + char *s; + XFetchName (dpy, parent[0], &s); + tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFree (s); + } break; } } @@ -3155,49 +3192,49 @@ * get input up until STRING TERMINATOR (or BEL) * ends_how is terminator used. returned input must be free()'d */ -unsigned char * +char * rxvt_term::get_to_st (unicode_t &ends_how) { - unicode_t prev = 0, ch; + unicode_t ch; + bool seen_esc = false; unsigned int n = 0; - unsigned char *s; - unsigned char string[STRING_MAX]; + wchar_t string[STRING_MAX]; while ((ch = cmd_getc ()) != NOCHAR) { - if (prev == C0_ESC) + if (seen_esc) { if (ch == 0x5c) /* 7bit ST */ break; else return NULL; } + else if (ch == C0_ESC) + { + seen_esc = true; + continue; + } 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) + seen_esc = false; + + if (n >= STRING_MAX - 1) // stop at some sane length return NULL; - if (ch == C0_SYN) - { - string[n++] = cmd_get8 (); - prev = 0; - } - else - string[n++] = prev = ch; + 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; + + return rxvt_wcstombs (string); } /*----------------------------------------------------------------------*/ @@ -3207,7 +3244,7 @@ void rxvt_term::process_dcs_seq () { - unsigned char *s; + char *s; unicode_t eh; /* @@ -3236,27 +3273,30 @@ if (ch == ';') { - unsigned char *s = get_to_st (eh); + char *s = get_to_st (eh); if (s) { - process_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, unsigned char resp) +rxvt_term::process_color_seq (int report, int color, const char *str, char resp) { if (str[0] == '?' && !str[1]) { - if (Options & Opt_insecure) - { - unsigned short r, g, b; - PixColors[color].get (display, r, g, b); - tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); - } + 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); @@ -3264,38 +3304,22 @@ /* * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) - * 0 = change iconName/title - * 1 = change iconName - * 2 = change title - * 4 = change color - * 10 = change fg color - * 11 = change bg 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: - * 20 = bg pixmap - * 39 = change default fg color - * 49 = change default bg color - * 55 = dump scrollback buffer and all of screen - * 701 = change locale - * 702 = find font - * 703 = menu */ void -rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) +rxvt_term::process_xterm_seq (int op, const char *str, char resp) { - int changed = 0; 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: @@ -3310,7 +3334,7 @@ case XTerm_property: if (str[0] == '?') { - Atom prop = XInternAtom (display->display, str + 1, True); + Atom prop = display->atom (str + 1); Atom actual_type; int actual_format; unsigned long nitems; @@ -3319,7 +3343,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (display->display, TermWin.parent[0], + && XGetWindowProperty (dpy, parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3327,7 +3351,7 @@ && actual_format == 8) str = (const char *)(value); - tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); + tt_printf ("\033]%d;%s%c", op, str, resp); XFree (value); } @@ -3338,13 +3362,10 @@ if (eq) { *eq = 0; - XChangeProperty (display->display, TermWin.parent[0], - display->atom (str), XA_STRING, 8, - PropModeReplace, (unsigned char *)eq + 1, - strlen (eq + 1)); + set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (display->display, TermWin.parent[0], + XDeleteProperty (dpy, parent[0], display->atom (str)); } break; @@ -3352,90 +3373,112 @@ 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); + color = atoi (buf) + minCOLOR; - if (color < 0 || color >= TOTAL_COLORS) + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) break; - if ((buf = STRCHR (name, ';')) != NULL) + if ((buf = strchr (name, ';')) != NULL) *buf++ = '\0'; - if (name[0] == '?' && !name[1]) - { - if (Options & Opt_insecure) - { - unsigned short r, g, b; - PixColors[color + minCOLOR].get (display, r, g, b); - tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); - } - } - else - set_window_color (color + minCOLOR, name); + process_color_seq (op, color, name, resp); } break; case XTerm_Color00: - process_color_seq (XTerm_Color00, Color_fg, str, resp); + process_color_seq (op, Color_fg, str, resp); break; case XTerm_Color01: - process_color_seq (XTerm_Color00, Color_bg, str, resp); + process_color_seq (op, Color_bg, str, resp); break; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); + process_color_seq (op, Color_cursor, str, resp); break; #endif case XTerm_Color_pointer_fg: - process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); + process_color_seq (op, Color_pointer_fg, str, resp); break; case XTerm_Color_pointer_bg: - process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); + process_color_seq (op, Color_pointer_bg, str, resp); break; #ifndef NO_BOLD_UNDERLINE_REVERSE - case XTerm_Color_BD: - process_color_seq (XTerm_Color_BD, Color_BD, str, resp); + case XTerm_Color_RV: + process_color_seq (op, Color_RV, str, resp); break; - case XTerm_Color_UL: - process_color_seq (XTerm_Color_UL, Color_UL, str, resp); + case Rxvt_Color_BD: + case URxvt_Color_BD: + process_color_seq (op, Color_BD, str, resp); break; - case XTerm_Color_RV: - process_color_seq (XTerm_Color_RV, Color_RV, str, resp); + case Rxvt_Color_UL: + case URxvt_Color_UL: + process_color_seq (op, Color_UL, str, resp); + break; + case URxvt_Color_IT: + process_color_seq (op, Color_IT, str, resp); break; #endif +#if ENABLE_TRANSPARENCY + case URxvt_Color_tint: + process_color_seq (op, Color_tint, str, resp); + { + bool changed = false; + if (ISSET_PIXCOLOR (Color_tint)) + changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]); + else + changed = bgPixmap.unset_tint (); + if (changed) + update_background (); + } - case XTerm_Pixmap: - if (*str != ';') - { -#if XPM_BACKGROUND - scale_pixmap (""); /* reset to default scaling */ - set_bgPixmap (str); /* change pixmap */ + break; #endif - scr_touch (true); - } - while ((str = STRCHR (str, ';')) != NULL) - { - str++; + #if XPM_BACKGROUND - changed += scale_pixmap (str); -#endif + case Rxvt_Pixmap: + if (!strcmp (str, "?")) + { + char str[256]; + sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ + min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767), + min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767)); + process_xterm_seq (XTerm_title, str, CHAR_ST); } - if (changed) + else { -#ifdef XPM_BACKGROUND - resize_pixmap (); -#endif - scr_touch (true); + int changed = 0; + + if (*str != ';') + { + /* reset to default scaling :*/ + bgPixmap.unset_geometry (); + if (bgPixmap.set_file (str)) /* change pixmap */ + changed++; + str = strchr (str, ';'); + if (str == NULL) + bgPixmap.set_defaultGeometry (); + } + while (str) + { + str++; + if (bgPixmap.set_geometry (str)) + changed++; + str = strchr (str, ';'); + } + if (changed) + update_background (); } break; +#endif - case XTerm_restoreFG: + case Rxvt_restoreFG: set_window_color (Color_fg, str); break; - case XTerm_restoreBG: + case Rxvt_restoreBG: set_window_color (Color_bg, str); break; @@ -3443,62 +3486,79 @@ // TODO, when secure mode? break; +#if 0 + case Rxvt_dumpscreen: /* no error notices */ + { + int fd; + if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) + { + scr_dump (fd); + close (fd); + } + } + 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 { - if (Options & Opt_insecure) - tt_printf ("\33]%d;%-.250s%c", XTerm_font, - TermWin.fontset->fontdesc - ? TermWin.fontset->fontdesc - : "", - resp); + const char *&res = rs[Rs_font + (op - URxvt_font)]; + + res = strdup (str); + allocated.push_back ((void *)res); + set_fonts (); } - else - change_font (str); break; -#ifndef NO_FRILLS - case XTerm_locale: + case URxvt_version: if (query) - { - if (Options & Opt_insecure) - tt_printf ("\33]%d;%-.250s%c", XTerm_locale, locale, resp); - } + 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); -# ifdef USE_XIM - im_cb (); -# endif + pty->set_utf8_mode (enc_utf8); + init_xlocale (); } break; - case XTerm_findfont: - if (Options & Opt_insecure) - { - int fid = TermWin.fontset->find_font (atoi (str)); - tt_printf ("\33]%d;%d;%-.250s%c", XTerm_findfont, - fid, (*TermWin.fontset)[fid]->name, resp); - } + 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 -#ifdef MENUBAR - case XTerm_Menu: - if (Options & Opt_insecure) - menubar_dispatch (const_cast(str)); // casting away constness is checked - break; -#endif -#if 0 - case XTerm_dumpscreen: /* no error notices */ - { - int fd; - if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) - { - scr_dump (fd); - close (fd); - } - } +#if ENABLE_PERL + case URxvt_perl: + if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) + ; // no responses yet break; #endif } @@ -3522,7 +3582,7 @@ if (mode == 's') { - SavedModes |= (PrivateModes & bit); + SavedModes |= (priv_modes & bit); return -1; } else @@ -3530,7 +3590,7 @@ if (mode == 'r') state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ else - state = (mode == 't') ? ! (PrivateModes & bit) : mode; + state = (mode == 't') ? ! (priv_modes & bit) : mode; PrivMode (state, bit); } @@ -3539,18 +3599,16 @@ /* 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 UNUSED, unsigned int nargs, const int *arg) { unsigned int i, j; int state; static const struct - { - const int argval; - const unsigned long bit; - } - - argtopriv[] = { + { + const int argval; + const unsigned long bit; + } argtopriv[] = { { 1, PrivMode_aplCUR }, { 2, PrivMode_vt52 }, { 3, PrivMode_132 }, @@ -3558,16 +3616,13 @@ { 5, PrivMode_rVideo }, { 6, PrivMode_relOrigin }, { 7, PrivMode_Autowrap }, + // 8, bi-directional support mode { 9, PrivMode_MouseX10 }, -#ifdef menuBar_esc - { menuBar_esc, PrivMode_menuBar }, -#endif + // 18, 19 printing-related + { 25, PrivMode_VisibleCursor }, #ifdef scrollBar_esc { scrollBar_esc, PrivMode_scrollBar }, #endif - // 18, 19 printing-related - { 25, PrivMode_VisibleCursor }, - // 30 show scrollbar rxvt. extension { 35, PrivMode_ShiftKeys }, // rxvt extension { 40, PrivMode_132OK }, // 41 xterm more fixes NYI @@ -3617,8 +3672,16 @@ /* extra handling for values with state unkept */ switch (arg[i]) { +#if ENABLE_STYLES + case 1021: + set_option (Opt_intensityStyles, mode); + + scr_touch (true); + break; +#endif case 1048: /* alternative cursor save */ - if (Options & Opt_secondaryScreen) + case 1049: + if (option (Opt_secondaryScreen)) if (mode == 0) scr_cursor (RESTORE); else if (mode == 1) @@ -3639,14 +3702,11 @@ PrivMode (1, PrivMode_vt52); break; case 3: /* 80/132 */ - if (PrivateModes & PrivMode_132OK) - set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); + if (priv_modes & PrivMode_132OK) + set_widthheight (((state ? 132 : 80) * fwidth), height); break; case 4: /* smooth scrolling */ - if (state) - Options &= ~Opt_jumpScroll; - else - Options |= Opt_jumpScroll; + set_option (Opt_jumpScroll, !state); break; case 5: /* reverse video */ scr_rvideo_mode (state); @@ -3660,15 +3720,8 @@ /* case 8: - auto repeat, can't do on a per window basis */ case 9: /* X10 mouse reporting */ if (state) /* orthogonal */ - PrivateModes &= ~PrivMode_MouseX11; + priv_modes &= ~PrivMode_MouseX11; break; -#ifdef menuBar_esc - case menuBar_esc: -#ifdef MENUBAR - map_menuBar (state); -#endif - break; -#endif #ifdef scrollBar_esc case scrollBar_esc: if (scrollbar_mapping (state)) @@ -3690,33 +3743,27 @@ /* case 67: - backspace key */ case 1000: /* X11 mouse reporting */ if (state) /* orthogonal */ - PrivateModes &= ~PrivMode_MouseX10; + priv_modes &= ~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; + set_option (Opt_scrollTtyOutput, !state); break; case 1011: /* scroll to bottom on key press */ - if (state) - Options |= Opt_scrollTtyKeypress; - else - Options &= ~Opt_scrollTtyKeypress; + set_option (Opt_scrollTtyKeypress, state); break; case 1047: /* secondary screen w/ clearing last */ - if (Options & Opt_secondaryScreen) + if (option (Opt_secondaryScreen)) if (current_screen != PRIMARY) scr_erase_screen (2); scr_change_screen (state); break; case 1049: /* secondary screen w/ clearing first */ scr_change_screen (state); - if (Options & Opt_secondaryScreen) + if (option (Opt_secondaryScreen)) if (current_screen != PRIMARY) scr_erase_screen (2); break; @@ -3752,10 +3799,15 @@ 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 @@ -3765,27 +3817,36 @@ case 8: // invisible. NYI break; - //case 10: // scoansi acs off - //case 11: // scoansi acs on - //case 12: // scoansi acs on, |0x80 - case 21: // disable bold, blink and invis (some terminals use this) - rendset = 0, rendstyle = RS_Bold | RS_Blink; + //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: + 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 - break; + //case 28: // visible. NYI + //case 29: // not crossed-out } if (rendset != -1) @@ -3806,15 +3867,13 @@ case 37: 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); i += 2; } break; -#endif case 39: /* default fg */ scr_color (Color_fg, Color_fg); break; @@ -3829,20 +3888,20 @@ case 47: 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); 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: @@ -3851,8 +3910,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 */ @@ -3862,11 +3920,9 @@ 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 - } } } @@ -3880,7 +3936,7 @@ if (cmd == 'Q') { /* query graphics */ - tt_printf ("\033G0\n"); /* no graphics */ + tt_printf ("\033G0\012"); /* no graphics */ return; } /* swallow other graphics sequences until terminating ':' */ @@ -3900,72 +3956,70 @@ 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. */ +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 (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) + return; + + if (pty->pty < 0) + return; - if (len) + if (v_buflen == 0) { - if (v_buflen == 0) - { - ssize_t written = write (cmd_fd, data, min (MAX_PTY_WRITE, len)); + ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE)); - if ((unsigned int)written == len) - return; + if ((unsigned int)written == len) + return; - data += written; - len -= written; - } + data += written; + len -= written; + } + v_buffer = (char *)realloc (v_buffer, v_buflen + len); - v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); + memcpy (v_buffer + v_buflen, data, len); + v_buflen += len; - memcpy (v_buffer + v_buflen, data, len); - v_buflen += len; - } + pty_ev.set (EVENT_READ | EVENT_WRITE); +} - for (;;) +void rxvt_term::pty_write () +{ + int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); + + if (written > 0) { - int written = write (cmd_fd, v_buffer, min (MAX_PTY_WRITE, v_buflen)); + v_buflen -= written; - if (written > 0) + if (v_buflen == 0) { - v_buflen -= written; - - if (v_buflen == 0) - { - free (v_buffer); - v_buffer = 0; - v_buflen = 0; - - pty_ev.set (EVENT_READ); - return; - } + free (v_buffer); + v_buffer = 0; + v_buflen = 0; - memmove (v_buffer, v_buffer + written, v_buflen); - } - else if (written != -1 || (errno != EAGAIN && errno != EINTR)) - // original code just ignores this... - destroy (); - else - { - pty_ev.set (EVENT_READ | EVENT_WRITE); + pty_ev.set (EVENT_READ); return; } + + memmove (v_buffer, v_buffer + written, v_buflen); } + else if (written != -1 || (errno != EAGAIN && errno != EINTR)) + pty_ev.set (EVENT_READ); } /*----------------------- end-of-file (C source) -----------------------*/