1 /*--------------------------------*-C-*---------------------------------*
3 *----------------------------------------------------------------------*
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
9 * - extensive modifications
10 * Copyright (c) 1995 Garrett D'Amore <garrett@netcom.com>
12 * Copyright (c) 1995 Steven Hirsch <hirsch@emba.uvm.edu>
13 * - X11 mouse report mode and support for
14 * DEC "private mode" save/restore functions.
15 * Copyright (c) 1995 Jakub Jelinek <jj@gnu.ai.mit.edu>
16 * - key-related changes to handle Shift+function
18 * Copyright (c) 1997 MJ Olesen <olesen@me.queensu.ca>
19 * - extensive modifications
20 * Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es>
21 * - modification and cleanups for Solaris 2.x
23 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
24 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/
48 #include "../config.h" /* NECESSARY */
49 #include "rxvt.h" /* NECESSARY */
55 /*----------------------------------------------------------------------*/
57 #define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
59 // exception thrown when the command parser runs out of input data
60 class out_of_input { } out_of_input;
62 #if ENABLE_FRILLS || ISO_14755
64 #define ISO_14755_STARTED 0x80000000UL
65 #define ISO_14755_51 0x40000000UL // basic (section 5.1)
66 #define ISO_14755_52 0x20000000UL // keycap (section 5.2)
67 #define ISO_14755_54 0x10000000UL // code feedback (section 5.4)
68 #define ISO_14755_MASK 0x0fffffffUL
71 static unsigned short iso14755_symtab[] = {
88 XK_ISO_Left_Tab, 0x21e6,
92 XK_Shift_Lock, 0x21eb,
97 XK_ISO_Level3_Shift, 0x21ee,
98 XK_ISO_Level3_Lock, 0x21ef,
99 XK_ISO_Group_Lock, 0x21f0,
107 XK_BackSpace, 0x232b,
109 XK_Control_L, 0x2388,
110 XK_Control_R, 0x2388,
123 rxvt_term::iso14755_54 (int x, int y)
128 if (x < 0 || x >= TermWin.ncol
129 || y < 0 || y >= TermWin.nrow)
134 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x];
136 if (t != NOCHAR || !x)
138 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x]);
139 iso14755buf = ISO_14755_54;
151 rxvt_term::iso14755_51 (wchar_t ch)
153 wchar_t *chr, *alloc;
159 len = rxvt_composite.expand (ch, 0);
160 alloc = chr = new wchar_t[len];
161 rxvt_composite.expand (ch, chr);
171 scr_overlay_new (0, -1, 8 + 5, len);
173 for (int y = 0; y < len; y++)
179 sprintf (buf, "%8x", ch);
180 scr_overlay_set (0, y, buf);
181 scr_overlay_set (9, y, '=');
186 scr_overlay_set (11, y, ch);
187 scr_overlay_set (12, y, NOCHAR);
198 rxvt_term::commit_iso14755 ()
202 ch[0] = iso14755buf & ISO_14755_MASK;
205 if (iso14755buf & ISO_14755_51)
210 // allow verbatim 0-bytes and control-bytes to be entered
212 len = wcstombs (mb, ch, 16);
220 tt_write ((unsigned char *)mb, len);
229 rxvt_term::hex_keyval (XKeyEvent &ev)
231 // check wether this event corresponds to a hex digit
232 // if the modifiers had not been pressed.
233 for (int index = 0; index < 8; index++)
235 KeySym k = XLookupKeysym (&ev, index);
237 if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0;
238 else if (k >= XK_0 && k <= XK_9) return k - XK_0;
239 else if (k >= XK_a && k <= XK_f) return k - XK_a + 10;
240 else if (k >= XK_A && k <= XK_F) return k - XK_A + 10;
247 /*{{{ Convert the keypress event into a string */
249 rxvt_term::lookup_key (XKeyEvent &ev)
251 int ctrl, meta, shft, len;
255 static int debug_key = 1; /* accessible by a debugger only */
258 unsigned char kbuf[KBUFSZ];
261 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
262 * escape sequence to toggle the Keypad.
264 * Always permit `shift' to override the current setting
266 shft = (ev.state & ShiftMask);
267 ctrl = (ev.state & ControlMask);
268 meta = (ev.state & ModMetaMask);
270 if (numlock_state || (ev.state & ModNumLockMask))
272 numlock_state = (ev.state & ModNumLockMask);
273 PrivMode ((!numlock_state), PrivMode_aplKP);
281 Status status_return;
284 #ifdef X_HAVE_UTF8_STRING
285 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
286 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf,
287 KBUFSZ, &keysym, &status_return);
292 wchar_t wkbuf[KBUFSZ + 1];
294 // the XOpenIM manpage lies about hardcoding the locale
295 // at the point of XOpenIM, so temporarily switch locales
297 SET_LOCALE (rs[Rs_imLocale]);
298 // assume wchar_t == unicode or better
299 len = XwcLookupString (Input_Context, &ev, wkbuf,
300 KBUFSZ, &keysym, &status_return);
304 if (status_return == XLookupChars
305 || status_return == XLookupBoth)
307 /* make sure the user can type ctrl-@, i.e. NUL */
308 if (len == 1 && *wkbuf == 0)
316 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
325 valid_keysym = status_return == XLookupKeySym
326 || status_return == XLookupBoth;
331 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose);
332 valid_keysym = keysym != NoSymbol;
337 if (TermWin.saveLines)
339 #ifdef UNSHIFTED_SCROLLKEYS
347 #ifdef PAGING_CONTEXT_LINES
348 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES;
350 lnsppg = TermWin.nrow * 4 / 5;
352 if (keysym == XK_Prior)
354 scr_page (UP, lnsppg);
357 else if (keysym == XK_Next)
359 scr_page (DN, lnsppg);
363 #ifdef SCROLL_ON_UPDOWN_KEYS
371 else if (keysym == XK_Down)
378 #ifdef SCROLL_ON_HOMEEND_KEYS
381 if (keysym == XK_Home)
386 else if (keysym == XK_End)
397 /* Shift + F1 - F10 generates F11 - F20 */
398 if (keysym >= XK_F1 && keysym <= XK_F10)
400 keysym += (XK_F11 - XK_F1);
401 shft = 0; /* turn off Shift */
403 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
407 /* normal XTerm key bindings */
408 case XK_Insert: /* Shift+Insert = paste mouse selection */
409 selection_request (ev.time, 0, 0);
413 case XK_KP_Add: /* Shift+KP_Add = bigger font */
414 change_font (FONT_UP);
416 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
417 change_font (FONT_DN);
424 #if ENABLE_FRILLS || ISO_14755
430 if (iso14755buf & ISO_14755_51
431 && (keysym == XK_space || keysym == XK_KP_Space
432 || keysym == XK_Return || keysym == XK_KP_Enter))
435 iso14755buf = ISO_14755_51;
441 else if ((hv = hex_keyval (ev)) >= 0)
443 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
446 iso14755_51 (iso14755buf & ISO_14755_MASK);
458 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
459 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
460 if (!(iso14755buf & ISO_14755_STARTED))
462 iso14755buf |= ISO_14755_STARTED;
464 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
465 scr_overlay_set (0, 0, "ISO 14755 mode");
471 if (keysym == XK_Print)
473 scr_printscreen (ctrl | shft);
478 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
480 #ifdef KEYSYM_RESOURCE
481 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
484 const unsigned char *kbuf0;
486 kbuf0 = (Keysym_map[keysym & 0xFF]);
487 l = (unsigned int)*kbuf0++;
492 && meta_char == C0_ESC
496 const unsigned char ch = C0_ESC;
509 #ifndef NO_BACKSPACE_KEY
511 if (priv_modes & PrivMode_HaveBackSpace)
513 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
514 ^ !!ctrl) ? '\b' : '\177';
518 strcpy (kbuf, key_backspace);
521 #ifndef NO_DELETE_KEY
523 strcpy (kbuf, key_delete);
528 strcpy (kbuf, "\033[Z");
531 #ifdef CTRL_TAB_MAKES_META
535 #ifdef MOD4_TAB_MAKES_META
536 if (ev.state & Mod4Mask)
544 case XK_KP_Up: /* \033Ox or standard */
545 case XK_KP_Down: /* \033Or or standard */
546 case XK_KP_Right: /* \033Ov or standard */
547 case XK_KP_Left: /* \033Ot or standard */
548 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
550 strcpy (kbuf, "\033OZ");
551 kbuf[2] = "txvr"[keysym - XK_KP_Left];
555 /* translate to std. cursor key */
556 keysym = XK_Left + (keysym - XK_KP_Left);
559 case XK_Up: /* "\033[A" */
560 case XK_Down: /* "\033[B" */
561 case XK_Right: /* "\033[C" */
562 case XK_Left: /* "\033[D" */
563 strcpy (kbuf, "\033[Z");
564 kbuf[2] = "DACB"[keysym - XK_Left];
567 kbuf[2] = "dacb"[keysym - XK_Left];
571 kbuf[2] = "dacb"[keysym - XK_Left];
573 else if (priv_modes & PrivMode_aplCUR)
577 #ifndef UNSHIFTED_SCROLLKEYS
580 /* allow shift to override */
581 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
583 strcpy (kbuf, "\033Oy");
589 strcpy (kbuf, "\033[5~");
593 /* allow shift to override */
594 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
596 strcpy (kbuf, "\033Os");
602 strcpy (kbuf, "\033[6~");
606 /* allow shift to override */
607 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
609 strcpy (kbuf, "\033OM");
616 if (priv_modes & PrivMode_LFNL)
631 strcpy (kbuf, "\033Ou");
635 strcpy (kbuf, "\033Op");
639 strcpy (kbuf, "\033On");
642 case XK_KP_F1: /* "\033OP" */
643 case XK_KP_F2: /* "\033OQ" */
644 case XK_KP_F3: /* "\033OR" */
645 case XK_KP_F4: /* "\033OS" */
646 strcpy (kbuf, "\033OP");
647 kbuf[2] += (keysym - XK_KP_F1);
650 case XK_KP_Multiply: /* "\033Oj" : "*" */
651 case XK_KP_Add: /* "\033Ok" : "+" */
652 case XK_KP_Separator: /* "\033Ol" : "," */
653 case XK_KP_Subtract: /* "\033Om" : "-" */
654 case XK_KP_Decimal: /* "\033On" : "." */
655 case XK_KP_Divide: /* "\033Oo" : "/" */
656 case XK_KP_0: /* "\033Op" : "0" */
657 case XK_KP_1: /* "\033Oq" : "1" */
658 case XK_KP_2: /* "\033Or" : "2" */
659 case XK_KP_3: /* "\033Os" : "3" */
660 case XK_KP_4: /* "\033Ot" : "4" */
661 case XK_KP_5: /* "\033Ou" : "5" */
662 case XK_KP_6: /* "\033Ov" : "6" */
663 case XK_KP_7: /* "\033Ow" : "7" */
664 case XK_KP_8: /* "\033Ox" : "8" */
665 case XK_KP_9: /* "\033Oy" : "9" */
666 /* allow shift to override */
667 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
669 strcpy (kbuf, "\033Oj");
670 kbuf[2] += (keysym - XK_KP_Multiply);
674 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
680 strcpy (kbuf, "\033[1~");
683 strcpy (kbuf, "\033[2~");
685 #ifdef DXK_Remove /* support for DEC remove like key */
690 strcpy (kbuf, "\033[3~");
693 strcpy (kbuf, "\033[4~");
697 /* allow shift to override */
698 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
700 strcpy (kbuf, "\033Oq");
706 strcpy (kbuf, KS_END);
710 /* allow shift to override */
711 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
713 strcpy (kbuf, "\033Ow");
719 strcpy (kbuf, KS_HOME);
722 #define FKEY(n, fkey) \
723 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
725 case XK_F1: /* "\033[11~" */
726 case XK_F2: /* "\033[12~" */
727 case XK_F3: /* "\033[13~" */
728 case XK_F4: /* "\033[14~" */
729 case XK_F5: /* "\033[15~" */
732 case XK_F6: /* "\033[17~" */
733 case XK_F7: /* "\033[18~" */
734 case XK_F8: /* "\033[19~" */
735 case XK_F9: /* "\033[20~" */
736 case XK_F10: /* "\033[21~" */
739 case XK_F11: /* "\033[23~" */
740 case XK_F12: /* "\033[24~" */
741 case XK_F13: /* "\033[25~" */
742 case XK_F14: /* "\033[26~" */
745 case XK_F15: /* "\033[28~" */
746 case XK_F16: /* "\033[29~" */
749 case XK_Help: /* "\033[28~" */
752 case XK_Menu: /* "\033[29~" */
755 case XK_F17: /* "\033[31~" */
756 case XK_F18: /* "\033[32~" */
757 case XK_F19: /* "\033[33~" */
758 case XK_F20: /* "\033[34~" */
759 case XK_F21: /* "\033[35~" */
760 case XK_F22: /* "\033[36~" */
761 case XK_F23: /* "\033[37~" */
762 case XK_F24: /* "\033[38~" */
763 case XK_F25: /* "\033[39~" */
764 case XK_F26: /* "\033[40~" */
765 case XK_F27: /* "\033[41~" */
766 case XK_F28: /* "\033[42~" */
767 case XK_F29: /* "\033[43~" */
768 case XK_F30: /* "\033[44~" */
769 case XK_F31: /* "\033[45~" */
770 case XK_F32: /* "\033[46~" */
771 case XK_F33: /* "\033[47~" */
772 case XK_F34: /* "\033[48~" */
773 case XK_F35: /* "\033[49~" */
786 * Pass meta for all function keys, if 'meta' option set
789 if (meta && (meta_char == 0x80) && len > 0)
790 kbuf[len - 1] |= 0x80;
794 else if (ctrl && keysym == XK_minus)
797 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
803 if (meta && (meta_char == 0x80))
807 for (ch = kbuf; ch < kbuf + len; ch++)
818 return; /* not mapped */
820 if (options & Opt_scrollTtyKeypress)
821 if (TermWin.view_start)
823 TermWin.view_start = 0;
828 * these modifications only affect the static keybuffer
829 * pass Shift/Control indicators for function keys ending with `~'
833 * Shift+Prior = "ESC[5$"
834 * Ctrl+Prior = "ESC[5^"
835 * Ctrl+Shift+Prior = "ESC[5@"
836 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
838 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
839 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
844 && meta_char == C0_ESC
848 const unsigned char ch = C0_ESC;
852 #if defined(DEBUG_CMD)
853 /* Display keyboard buffer contents */
857 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
858 for (i = 0, p = kbuf; i < len; i++, p++)
859 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
860 fprintf (stderr, "'\n");
861 #endif /* DEBUG_CMD */
862 tt_write (kbuf, (unsigned int)len);
867 /*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
868 /* attempt to `write' count to the input buffer */
870 rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
874 n = cmdbuf_ptr - cmdbuf_base;
875 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
877 if (n > 0 && s < count)
879 memmove (cmdbuf_base, cmdbuf_ptr,
880 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
881 cmdbuf_ptr = cmdbuf_base;
888 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
893 *cmdbuf_endp++ = *str++;
899 #endif /* MENUBAR_MAX */
905 if (want_full_refresh)
907 want_full_refresh = 0;
915 scr_refresh (refresh_type);
928 rxvt_term::check_cb (check_watcher &w)
935 if (want_refresh && !flush_ev.active)
936 flush_ev.start (NOW + 0.01);
940 rxvt_term::flush_cb (time_watcher &w)
952 rxvt_term::cursor_blink_cb (time_watcher &w)
954 hidden_cursor = !hidden_cursor;
957 w.start (w.at + BLINK_INTERVAL);
963 rxvt_term::text_blink_cb (time_watcher &w)
965 if (scr_refresh_rend (RS_Blink, RS_Blink))
967 hidden_text = !hidden_text;
969 w.start (w.at + TEXT_BLINK_INTERVAL);
974 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
976 rxvt_term::cont_scroll_cb (time_watcher &w)
978 if ((scrollbar_isUp() || scrollbar_isDn()) &&
979 scr_page (scrollbar_isUp() ? UP : DN, 1))
981 refresh_type |= SMOOTH_REFRESH;
983 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
988 #ifdef SELECTION_SCROLLING
990 rxvt_term::sel_scroll_cb (time_watcher &w)
992 if (scr_page (scroll_selection_dir, scroll_selection_lines))
994 selection_extend (selection_save_x, selection_save_y, selection_save_state);
995 refresh_type |= SMOOTH_REFRESH;
997 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1002 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1004 rxvt_term::slip_wheel_cb (time_watcher &w)
1006 if (mouse_slip_wheel_speed == 0
1007 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1008 : scr_page (UP, mouse_slip_wheel_speed))
1010 refresh_type |= SMOOTH_REFRESH;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1018 rxvt_term::pty_fill ()
1020 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1024 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
1028 memmove (cmdbuf_base, cmdbuf_ptr, n);
1029 cmdbuf_ptr = cmdbuf_base;
1030 cmdbuf_endp = cmdbuf_ptr + n;
1032 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1039 else if (n < 0 && errno != EAGAIN)
1046 rxvt_term::pty_cb (io_watcher &w, short revents)
1049 SET_LOCALE (locale);
1051 if (revents & EVENT_WRITE)
1053 else if (revents & EVENT_READ)
1054 // loop, but don't allow a single term to monopolize us
1061 rxvt_term::pointer_unblank ()
1063 XDefineCursor (display->display, TermWin.vt, TermWin_cursor);
1066 #ifdef POINTER_BLANK
1069 if (options & Opt_pointerBlank)
1070 pointer_ev.start (NOW + pointerBlankDelay);
1074 #ifdef POINTER_BLANK
1076 rxvt_term::pointer_blank ()
1078 if (! (options & Opt_pointerBlank))
1081 XDefineCursor (display->display, TermWin.vt, blank_cursor);
1082 XFlush (display->display);
1088 rxvt_term::pointer_cb (time_watcher &w)
1091 SET_LOCALE (locale);
1098 rxvt_term::mouse_report (XButtonEvent &ev)
1100 int button_number, key_state = 0;
1105 pixel_position (&x, &y);
1107 if (MEvent.button == AnyButton)
1111 button_number = MEvent.button - Button1;
1112 /* add 0x3D for wheel events, like xterm does */
1113 if (button_number >= 3)
1114 button_number += (64 - 3);
1117 if (priv_modes & PrivMode_MouseX10)
1120 * do not report ButtonRelease
1121 * no state info allowed
1124 if (button_number == 3)
1129 /* XTerm mouse reporting needs these values:
1133 * plus will add in our own Double-Click reporting
1136 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1137 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1138 + ((MEvent.state & ControlMask) ? 16 : 0);
1139 #ifdef MOUSE_REPORT_DOUBLECLICK
1140 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1145 #ifdef DEBUG_MOUSEREPORT
1146 fprintf (stderr, "Mouse [");
1148 fputc ('C', stderr);
1150 fputc ('S', stderr);
1152 fputc ('A', stderr);
1154 fputc ('2', stderr);
1155 fprintf (stderr, "]: <%d>, %d/%d\n",
1160 tt_printf ("\033[M%c%c%c",
1161 (32 + button_number + key_state),
1169 rxvt_W11_process_x_event (XEvent *ev)
1171 rxvt_t *r = rxvt_get_r ();
1177 /*{{{ process an X event */
1179 rxvt_term::x_cb (XEvent &ev)
1182 SET_LOCALE (locale);
1184 #if defined(CURSOR_BLINK)
1185 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1193 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1197 #if defined(POINTER_BLANK)
1198 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1200 if (ev.type == MotionNotify
1201 || ev.type == ButtonPress
1202 || ev.type == ButtonRelease)
1206 if (ev.type == KeyPress && hidden_pointer == 0)
1212 if (XFilterEvent (&ev, None))
1216 Window unused_root, unused_child;
1217 int unused_root_x, unused_root_y;
1218 unsigned int unused_mask;
1224 if (!(iso14755buf & ISO_14755_52))
1226 lookup_key (ev.xkey);
1232 #if (defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)) || defined (ENABLE_FRILLS)
1235 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1238 #if ENABLE_FRILLS || ISO_14755
1239 // ISO 14755 support
1241 if (iso14755buf & ISO_14755_52)
1247 // iso14755 part 5.2 handling: release time
1249 if ((ev.xkey.state & ControlMask)
1250 && ((ks >= 0x40 && ks <= 0x5f)
1251 || (ks >= 0x61 && ks <= 0x7f)))
1253 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1255 return; // case-break;
1258 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1261 iso14755buf = ISO_14755_51 | i[1];
1263 return; // case-break;
1271 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1276 if (iso14755buf & ISO_14755_51)
1279 else if (iso14755buf & ISO_14755_STARTED)
1281 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1283 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1284 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1292 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1293 if (!(ev.xkey.state & ControlMask))
1294 slip_wheel_ev.stop ();
1295 else if (ks == XK_Control_L || ks == XK_Control_R)
1296 mouse_slip_wheel_speed = 0;
1302 button_press (ev.xbutton);
1306 button_release (ev.xbutton);
1310 if (ev.xclient.format == 32
1311 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1314 /* OffiX Dnd (drag 'n' drop) protocol */
1315 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1316 && (ev.xclient.data.l[0] == DndFile
1317 || ev.xclient.data.l[0] == DndDir
1318 || ev.xclient.data.l[0] == DndLink))
1323 unsigned char *data;
1324 unsigned long Size, RemainingBytes;
1326 XGetWindowProperty (display->display, display->root,
1327 xa[XA_DNDSELECTION],
1329 False, AnyPropertyType,
1330 &ActualType, &ActualFormat,
1331 &Size, &RemainingBytes,
1333 XChangeProperty (display->display, display->root,
1334 XA_CUT_BUFFER0, XA_STRING,
1336 data, strlen (data));
1338 selection_paste (display->root, XA_CUT_BUFFER0, True);
1339 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1341 #endif /* OFFIX_DND */
1345 XRefreshKeyboardMapping (&ev.xmapping);
1349 * XXX: this is not the _current_ arrangement
1350 * Here's my conclusion:
1351 * If the window is completely unobscured, use bitblt's
1352 * to scroll. Even then, they're only used when doing partial
1353 * screen scrolling. When partially obscured, we have to fill
1354 * in the GraphicsExpose parts, which means that after each refresh,
1355 * we need to wait for the graphics expose or Noexpose events,
1356 * which ought to make things real slow!
1358 case VisibilityNotify:
1359 switch (ev.xvisibility.state)
1361 case VisibilityUnobscured:
1362 refresh_type = FAST_REFRESH;
1364 case VisibilityPartiallyObscured:
1365 refresh_type = SLOW_REFRESH;
1368 refresh_type = NO_REFRESH;
1379 if (Input_Context != NULL)
1381 IMSetStatusPosition ();
1382 XSetICFocus (Input_Context);
1386 if (options & Opt_cursorBlink)
1387 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1389 #ifdef OFF_FOCUS_FADING
1392 pix_colors = pix_colors_focused;
1408 if (Input_Context != NULL)
1409 XUnsetICFocus (Input_Context);
1412 if (options & Opt_cursorBlink)
1413 cursor_blink_ev.stop ();
1416 #ifdef OFF_FOCUS_FADING
1419 pix_colors = pix_colors_unfocused;
1429 case ConfigureNotify:
1430 if (ev.xconfigure.window == TermWin.parent[0])
1435 { /* Wrap lots of configures into one */
1436 width = ev.xconfigure.width;
1437 height = ev.xconfigure.height;
1438 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1440 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev));
1442 if (szHint.width != width || szHint.height != height)
1443 resize_all_windows (width, height, 1);
1445 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1446 if (options & Opt_transparent)
1448 check_our_parents ();
1450 want_refresh = want_full_refresh = 1;
1456 case PropertyNotify:
1457 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1458 && ev.xproperty.state == PropertyNewValue)
1459 selection_property (ev.xproperty.window, ev.xproperty.atom);
1463 case SelectionClear:
1467 case SelectionNotify:
1468 if (selection_wait == Sel_normal)
1469 selection_paste (ev.xselection.requestor,
1470 ev.xselection.property, True);
1473 case SelectionRequest:
1474 selection_send (ev.xselectionrequest);
1480 text_blink_ev.stop ();
1487 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1492 case ReparentNotify:
1495 #endif /* TRANSPARENT */
1497 case GraphicsExpose:
1499 if (ev.xany.window == TermWin.vt)
1502 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False);
1504 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev));
1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1508 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev))
1509 scr_expose (ev.xexpose.x, ev.xexpose.y,
1510 ev.xexpose.width, ev.xexpose.height, False);
1512 scr_refresh (refresh_type);
1516 XEvent unused_event;
1518 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event))
1520 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event))
1523 if (isScrollbarWindow (ev.xany.window))
1525 scrollBar.setIdle ();
1529 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1534 if (am_transparent && ev.xany.window == TermWin.parent[0])
1535 XClearWindow (display->display, ev.xany.window);
1541 #ifdef POINTER_BLANK
1546 if (isMenuBarWindow (ev.xany.window))
1548 menubar_control (ev.xbutton);
1552 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate))
1555 if (ev.xany.window == TermWin.vt)
1557 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1559 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev))
1562 XQueryPointer (display->display, TermWin.vt,
1563 &unused_root, &unused_child,
1564 &unused_root_x, &unused_root_y,
1565 & (ev.xbutton.x), & (ev.xbutton.y),
1567 #ifdef MOUSE_THRESHOLD
1568 /* deal with a `jumpy' mouse */
1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1574 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1580 selection_extend (ev.xbutton.x, ev.xbutton.y,
1581 (ev.xbutton.state & Button3Mask) ? 2 : 0);
1582 #ifdef SELECTION_SCROLLING
1583 if (ev.xbutton.y < TermWin.int_bwidth
1584 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1))
1588 /* don't clobber the current delay if we are
1589 * already in the middle of scrolling.
1591 if (!sel_scroll_ev.active)
1592 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1594 /* save the event params so we can highlight
1595 * the selection in the pending-scroll loop
1597 selection_save_x = ev.xbutton.x;
1598 selection_save_y = ev.xbutton.y;
1599 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1601 /* calc number of lines to scroll */
1602 if (ev.xbutton.y<TermWin.int_bwidth)
1604 scroll_selection_dir = UP;
1605 dist = TermWin.int_bwidth - ev.xbutton.y;
1609 scroll_selection_dir = DN;
1610 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height);
1613 scroll_selection_lines = Pixel2Height (dist)
1614 / SELECTION_SCROLL_LINE_SPEEDUP
1616 MIN_IT (scroll_selection_lines,
1617 SELECTION_SCROLL_MAX_LINES);
1621 /* we are within the text window, so we
1622 * shouldn't be scrolling
1624 if (sel_scroll_ev.active)
1625 sel_scroll_ev.stop();
1628 #ifdef MOUSE_THRESHOLD
1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1635 while (XCheckTypedWindowEvent (display->display, scrollBar.win,
1636 MotionNotify, &ev)) ;
1637 XQueryPointer (display->display, scrollBar.win,
1638 &unused_root, &unused_child,
1639 &unused_root_x, &unused_root_y,
1640 & (ev.xbutton.x), & (ev.xbutton.y),
1642 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1644 scr_refresh (refresh_type);
1654 rxvt_term::rootwin_cb (XEvent &ev)
1657 SET_LOCALE (locale);
1661 case PropertyNotify:
1663 * if user used some Esetroot compatible prog to set the root bg,
1664 * use the property to determine the pixmap. We use it later on.
1666 if (xa[XA_XROOTPMAPID] == 0)
1667 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1669 if (ev.xproperty.atom != xa[XA_XROOTPMAPID])
1673 case ReparentNotify:
1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1675 want_refresh = want_full_refresh = 1;
1682 rxvt_term::button_press (XButtonEvent &ev)
1684 int reportmode = 0, clickintime;
1686 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1687 if (!bypass_keystate)
1688 reportmode = !! (priv_modes & PrivMode_mouse_report);
1691 * VT window processing of button press
1693 if (ev.window == TermWin.vt)
1697 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1699 iso14755_54 (ev.x, ev.y);
1704 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1707 /* mouse report from vt window */
1708 /* save the xbutton state (for ButtonRelease) */
1709 MEvent.state = ev.state;
1710 #ifdef MOUSE_REPORT_DOUBLECLICK
1711 if (ev.button == MEvent.button && clickintime)
1713 /* same button, within alloted time */
1715 if (MEvent.clicks > 1)
1717 /* only report double clicks */
1721 /* don't report the release */
1723 MEvent.button = AnyButton;
1728 /* different button, or time expired */
1730 MEvent.button = ev.button;
1734 MEvent.button = ev.button;
1736 #endif /* MOUSE_REPORT_DOUBLECLICK */
1741 if (ev.button != MEvent.button)
1746 /* allow shift+left click to extend selection */
1747 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1749 if (MEvent.button == Button1 && clickintime)
1750 selection_rotate (ev.x, ev.y);
1752 selection_extend (ev.x, ev.y, 1);
1756 if (MEvent.button == Button1 && clickintime)
1761 selection_click (MEvent.clicks, ev.x, ev.y);
1764 MEvent.button = Button1;
1768 if (MEvent.button == Button3 && clickintime)
1769 selection_rotate (ev.x, ev.y);
1771 selection_extend (ev.x, ev.y, 1);
1773 MEvent.button = Button3;
1778 MEvent.time = ev.time;
1783 * Scrollbar window processing of button press
1785 if (isScrollbarWindow (ev.window))
1787 scrollBar.setIdle ();
1789 * Rxvt-style scrollbar:
1790 * move up if mouse is above slider
1791 * move dn if mouse is below slider
1793 * XTerm-style scrollbar:
1794 * Move display proportional to pointer location
1795 * pointer near top -> scroll one line
1796 * pointer near bot -> scroll full page
1798 #ifndef NO_SCROLLBAR_REPORT
1802 * Mouse report disabled scrollbar:
1803 * arrow buttons - send up/down
1804 * click on scrollbar - send pageup/down
1806 if ((scrollBar.style == R_SB_NEXT
1807 && scrollbarnext_upButton (ev.y))
1808 || (scrollBar.style == R_SB_RXVT
1809 && scrollbarrxvt_upButton (ev.y)))
1810 tt_printf ("\033[A");
1811 else if ((scrollBar.style == R_SB_NEXT
1812 && scrollbarnext_dnButton (ev.y))
1813 || (scrollBar.style == R_SB_RXVT
1814 && scrollbarrxvt_dnButton (ev.y)))
1815 tt_printf ("\033[B");
1823 tt_printf ("\033[6~");
1826 tt_printf ("\033[5~");
1831 #endif /* NO_SCROLLBAR_REPORT */
1836 if (scrollBar.style == R_SB_NEXT)
1838 if (scrollbarnext_upButton (ev.y))
1839 upordown = -1; /* up */
1840 else if (scrollbarnext_dnButton (ev.y))
1841 upordown = 1; /* down */
1843 else if (scrollBar.style == R_SB_RXVT)
1845 if (scrollbarrxvt_upButton (ev.y))
1846 upordown = -1; /* up */
1847 else if (scrollbarrxvt_dnButton (ev.y))
1848 upordown = 1; /* down */
1852 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1853 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1855 if (scr_page (upordown < 0 ? UP : DN, 1))
1867 switch (scrollbar_align)
1869 case R_SB_ALIGN_TOP:
1872 case R_SB_ALIGN_CENTRE:
1873 csrO = (scrollBar.bot - scrollBar.top) / 2;
1875 case R_SB_ALIGN_BOTTOM:
1876 csrO = scrollBar.bot - scrollBar.top;
1880 if (scrollBar.style == R_SB_XTERM
1881 || scrollbar_above_slider (ev.y)
1882 || scrollbar_below_slider (ev.y))
1883 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
1885 scrollBar.setMotion ();
1889 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1890 csrO = ev.y - scrollBar.top;
1894 if (scrollBar.style != R_SB_XTERM)
1896 if (scrollbar_above_slider (ev.y))
1897 # ifdef RXVT_SCROLL_FULL
1898 scr_page (UP, TermWin.nrow - 1);
1900 scr_page (UP, TermWin.nrow / 4);
1902 else if (scrollbar_below_slider (ev.y))
1903 # ifdef RXVT_SCROLL_FULL
1904 scr_page (DN, TermWin.nrow - 1);
1906 scr_page (DN, TermWin.nrow / 4);
1909 scrollBar.setMotion ();
1913 scr_page ((ev.button == Button1 ? DN : UP),
1915 * scrollbar_position (ev.y)
1916 / scrollbar_size ()));
1926 * Menubar window processing of button press
1928 if (isMenuBarWindow (ev.window))
1929 menubar_control (ev);
1934 rxvt_term::button_release (XButtonEvent &ev)
1938 csrO = 0; /* reset csr Offset */
1939 if (!bypass_keystate)
1940 reportmode = !! (priv_modes & PrivMode_mouse_report);
1942 if (scrollbar_isUpDn ())
1944 scrollBar.setIdle ();
1946 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1947 refresh_type &= ~SMOOTH_REFRESH;
1951 #ifdef SELECTION_SCROLLING
1952 if (sel_scroll_ev.active)
1953 sel_scroll_ev.stop();
1956 if (ev.window == TermWin.vt)
1960 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1965 /* mouse report from vt window */
1966 /* don't report release of wheel "buttons" */
1969 #ifdef MOUSE_REPORT_DOUBLECLICK
1970 /* only report the release of 'slow' single clicks */
1971 if (MEvent.button != AnyButton
1972 && (ev.button != MEvent.button
1973 || (ev.time - MEvent.time
1974 > MULTICLICK_TIME / 2)))
1977 MEvent.button = AnyButton;
1980 #else /* MOUSE_REPORT_DOUBLECLICK */
1981 MEvent.button = AnyButton;
1983 #endif /* MOUSE_REPORT_DOUBLECLICK */
1988 * dumb hack to compensate for the failure of click-and-drag
1989 * when overriding mouse reporting
1991 if (priv_modes & PrivMode_mouse_report
1993 && ev.button == Button1 && MEvent.clicks <= 1)
1994 selection_extend (ev.x, ev.y, 0);
2000 selection_make (ev.time);
2003 selection_request (ev.time, ev.x, ev.y);
2012 v = ev.button == Button4 ? UP : DN;
2014 if (ev.state & ShiftMask)
2016 else if (options & Opt_mouseWheelScrollPage)
2017 i = TermWin.nrow - 1;
2021 # ifdef MOUSE_SLIP_WHEELING
2022 if (ev.state & ControlMask)
2024 mouse_slip_wheel_speed += v ? -1 : 1;
2025 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow;
2026 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2028 if (slip_wheel_ev.at < NOW)
2029 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2031 slip_wheel_ev.start ();
2036 # ifdef JUMP_MOUSE_WHEEL
2038 scr_refresh (SMOOTH_REFRESH);
2044 scr_refresh (SMOOTH_REFRESH);
2048 # ifdef MOUSE_SLIP_WHEELING
2057 else if (isMenuBarWindow (ev.window))
2058 menubar_control (ev);
2064 /* taken from aterm-0.4.2 */
2066 typedef uint32_t RUINT32T;
2068 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2070 int sh_r, sh_g, sh_b;
2071 RUINT32T mask_r, mask_g, mask_b;
2072 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2073 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2074 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2077 Visual* visual = display->visual;
2079 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2081 /* for convenience */
2082 mask_r = visual->red_mask;
2083 mask_g = visual->green_mask;
2084 mask_b = visual->blue_mask;
2086 /* boring lookup table pre-initialization */
2087 switch (srcImage->bits_per_pixel) {
2089 if ((mask_r != 0x7c00) ||
2090 (mask_g != 0x03e0) ||
2093 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2095 lookup_g = lookup+32;
2096 lookup_b = lookup+32+32;
2102 if ((mask_r != 0xf800) ||
2103 (mask_g != 0x07e0) ||
2106 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2108 lookup_g = lookup+32;
2109 lookup_b = lookup+32+64;
2115 if ((mask_r != 0xff0000) ||
2116 (mask_g != 0x00ff00) ||
2117 (mask_b != 0x0000ff))
2119 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2121 lookup_g = lookup+256;
2122 lookup_b = lookup+256+256;
2128 if ((mask_r != 0xff0000) ||
2129 (mask_g != 0x00ff00) ||
2130 (mask_b != 0x0000ff))
2132 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2134 lookup_g = lookup+256;
2135 lookup_b = lookup+256+256;
2141 return; /* we do not support this color depth */
2144 /* prepare limits for color transformation (each channel is handled separately) */
2147 if (shade < 0) shade = 0;
2148 if (shade > 100) shade = 100;
2150 lower_lim_r = 65535-rm;
2151 lower_lim_g = 65535-gm;
2152 lower_lim_b = 65535-bm;
2154 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2155 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2156 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2158 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2160 if (shade < 0) shade = 0;
2161 if (shade > 100) shade = 100;
2163 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2165 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2166 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2167 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2170 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2171 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2176 lower_lim_r = lower_lim_b;
2180 upper_lim_r = upper_lim_b;
2184 /* fill our lookup tables */
2185 for (i = 0; i <= mask_r>>sh_r; i++)
2188 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2189 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2190 lookup_r[i] = (tmp/65535)<<sh_r;
2192 for (i = 0; i <= mask_g>>sh_g; i++)
2195 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2196 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2197 lookup_g[i] = (tmp/65535)<<sh_g;
2199 for (i = 0; i <= mask_b>>sh_b; i++)
2202 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2203 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2204 lookup_b[i] = (tmp/65535)<<sh_b;
2207 /* apply table to input image (replacing colors by newly calculated ones) */
2208 switch (srcImage->bits_per_pixel)
2212 unsigned short *p1, *pf, *p, *pl;
2213 p1 = (unsigned short *) srcImage->data;
2214 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2218 pl = p1 + srcImage->width;
2221 *p = lookup_r[(*p & 0x7c00)>>10] |
2222 lookup_g[(*p & 0x03e0)>> 5] |
2223 lookup_b[(*p & 0x001f)];
2225 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2231 unsigned short *p1, *pf, *p, *pl;
2232 p1 = (unsigned short *) srcImage->data;
2233 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2237 pl = p1 + srcImage->width;
2240 *p = lookup_r[(*p & 0xf800)>>11] |
2241 lookup_g[(*p & 0x07e0)>> 5] |
2242 lookup_b[(*p & 0x001f)];
2244 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2250 unsigned char *p1, *pf, *p, *pl;
2251 p1 = (unsigned char *) srcImage->data;
2252 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2256 pl = p1 + srcImage->width * 3;
2257 for (; p < pl; p += 3)
2259 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2260 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2261 p[2] = lookup_r[(p[2] & 0x0000ff)];
2263 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2269 RUINT32T *p1, *pf, *p, *pl;
2270 p1 = (RUINT32T *) srcImage->data;
2271 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2276 pl = p1 + srcImage->width;
2279 *p = lookup_r[(*p & 0xff0000)>>16] |
2280 lookup_g[(*p & 0x00ff00)>> 8] |
2281 lookup_b[(*p & 0x0000ff)] |
2284 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2295 * Check our parents are still who we think they are.
2296 * Do transparency updates if required
2299 rxvt_term::check_our_parents ()
2301 int i, pchanged, aformat, have_pixmap, rootdepth;
2302 unsigned long nitems, bytes_after;
2304 unsigned char *prop = NULL;
2305 Window root, oldp, *list;
2306 Pixmap rootpixmap = None;
2307 XWindowAttributes wattr, wrootattr;
2311 if (!(options & Opt_transparent))
2312 return pchanged; /* Don't try any more */
2314 XGetWindowAttributes (display->display, display->root, &wrootattr);
2315 rootdepth = wrootattr.depth;
2317 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2319 if (rootdepth != wattr.depth)
2324 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2325 am_transparent = am_pixmap_trans = 0;
2328 return pchanged; /* Don't try any more */
2331 /* Get all X ops out of the queue so that our information is up-to-date. */
2332 XSync (display->display, False);
2335 * Make the frame window set by the window manager have
2336 * the root background. Some window managers put multiple nested frame
2337 * windows for each client, so we have to take care about that.
2339 i = (xa[XA_XROOTPMAPID]
2340 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID],
2341 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2342 &nitems, &bytes_after, &prop) == Success);
2344 if (!i || prop == NULL)
2345 i = (xa[XA_XSETROOTID]
2346 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID],
2347 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2348 &nitems, &bytes_after, &prop) == Success);
2350 if (!i || prop == NULL
2352 || !rs[Rs_color + Color_tint]
2359 rootpixmap = *(Pixmap *)prop;
2366 * Copy display->root pixmap transparency
2369 unsigned int nw, nh;
2375 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
2376 0, 0, &sx, &sy, &cr);
2377 nw = (unsigned int)szHint.width;
2378 nh = (unsigned int)szHint.height;
2395 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2396 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2398 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2400 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2401 /* XXX: may need a delay here? */
2406 if (am_transparent && am_pixmap_trans)
2409 if (TermWin.pixmap != None)
2411 XFreePixmap (display->display, TermWin.pixmap);
2412 TermWin.pixmap = None;
2416 am_pixmap_trans = 0;
2420 if (TermWin.pixmap != None)
2421 XFreePixmap (display->display, TermWin.pixmap);
2424 if (ISSET_PIXCOLOR (Color_tint))
2426 unsigned short rm, gm, bm;
2427 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2429 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2431 ShadeXImage (display, image, shade, rm, gm, bm);
2435 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
2436 szHint.width, szHint.height, image->depth);
2437 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue);
2438 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0,
2439 nx, ny, image->width, image->height);
2440 XFreeGC (display->display, gc);
2441 XDestroyImage (image);
2442 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap);
2443 XClearWindow (display->display, TermWin.parent[0]);
2445 if (!am_transparent || !am_pixmap_trans)
2448 am_transparent = am_pixmap_trans = 1;
2452 if (!am_pixmap_trans)
2456 * InheritPixmap transparency
2458 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2460 oldp = TermWin.parent[i];
2461 XQueryTree (display->display, TermWin.parent[i - 1], &root,
2462 &TermWin.parent[i], &list, &n);
2465 if (TermWin.parent[i] == display->root)
2473 if (oldp != TermWin.parent[i])
2481 for (; n < (unsigned int)i; n++)
2483 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr);
2484 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2486 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2492 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2494 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]);
2495 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2497 /* XXX: also turn off Opt_transparent? */
2502 /* wait (an arbitrary period) for the WM to do its thing
2503 * needed for fvwm2.2.2 (and before?) */
2506 for (n = 0; n < (unsigned int)i; n++)
2508 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative);
2509 XClearWindow (display->display, TermWin.parent[n]);
2512 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2516 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2517 TermWin.parent[i] = None;
2520 // this is experimental
2523 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative);
2524 XClearWindow (display->display, scrollBar.win);
2525 scrollBar.setIdle ();
2536 rxvt_term::cmd_parse ()
2539 unicode_t ch = NOCHAR;
2540 unsigned char *seq_begin; // remember start of esc-sequence here
2546 seq_begin = cmdbuf_ptr;
2550 if (ch == NOCHAR) // TODO: improve
2553 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2558 // many badly-written programs (e.g. jed) contain a race condition:
2559 // they first read the screensize and then install a SIGWINCH handler.
2560 // some window managers resize the window early, and these programs
2561 // then sometimes get the size wrong.
2562 kill (-cmd_pid, SIGWINCH);
2565 /* Read a text string from the input buffer */
2566 unicode_t buf[UBUFSIZ];
2567 bool refreshnow = false;
2569 unicode_t *str = buf;
2573 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2583 if (!(options & Opt_jumpScroll)
2584 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2591 // scr_add_lines only works for nlines <= TermWin.nrow - 1.
2592 if (nlines >= TermWin.nrow - 1)
2594 scr_add_lines (buf, nlines, str - buf);
2600 if (str >= buf + UBUFSIZ)
2606 seq_begin = cmdbuf_ptr;
2610 scr_add_lines (buf, nlines, str - buf);
2613 * If there have been a lot of new lines, then update the screen
2614 * What the heck I'll cheat and only refresh less than every page-full.
2615 * the number of pages between refreshes is refresh_limit, which
2616 * is incremented here because we must be doing flat-out scrolling.
2620 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2625 scr_refresh (refresh_type);
2634 process_nonprinting (ch);
2636 catch (const class out_of_input &o)
2638 // we ran out of input, retry later
2639 cmdbuf_ptr = seq_begin;
2650 // read the next octet
2652 rxvt_term::next_octet ()
2654 return cmdbuf_ptr < cmdbuf_endp
2659 // read the next character
2661 rxvt_term::next_char ()
2663 while (cmdbuf_ptr < cmdbuf_endp)
2665 // assume 7-bit to be ascii ALWAYS
2666 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2667 return *cmdbuf_ptr++;
2670 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2672 if (len == (size_t)-2)
2674 // the mbstate stores incomplete sequences. didn't know this :/
2675 cmdbuf_ptr = cmdbuf_endp;
2679 if (len == (size_t)-1)
2680 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2682 // assume wchar == unicode
2690 /* rxvt_cmd_getc () - Return next input character */
2692 * Return the next input character after first passing any keyboard input
2696 rxvt_term::cmd_getc ()
2698 unicode_t c = next_char ();
2707 rxvt_term::cmd_get8 ()
2709 unicode_t c = next_octet ();
2718 /*----------------------------------------------------------------------*/
2721 rxvt_term::popen_printer ()
2723 FILE *stream = popen (rs[Rs_print_pipe], "w");
2726 rxvt_warn ("can't open printer pipe, not printing.\n");
2732 rxvt_term::pclose_printer (FILE *stream)
2735 return pclose (stream);
2739 * simulate attached vt100 printer
2742 rxvt_term::process_print_pipe ()
2747 if ((fd = popen_printer ()) == NULL)
2751 * Send all input to the printer until either ESC[4i or ESC[?4i
2754 for (done = 0; !done;)
2756 unsigned char buf[8];
2758 unsigned int i, len;
2760 if ((ch = cmd_getc ()) != C0_ESC)
2762 if (putc (ch, fd) == EOF)
2763 break; /* done = 1 */
2770 if ((buf[len++] = cmd_getc ()) == '[')
2772 if ((ch = cmd_getc ()) == '?')
2777 if ((buf[len++] = ch) == '4')
2779 if ((buf[len++] = cmd_getc ()) == 'i')
2780 break; /* done = 1 */
2784 for (i = 0; i < len; i++)
2785 if (putc (buf[i], fd) == EOF)
2793 pclose_printer (fd);
2795 #endif /* PRINTPIPE */
2801 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2802 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2803 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2804 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2808 /*{{{ process non-printing single characters */
2810 rxvt_term::process_nonprinting (unicode_t ch)
2815 process_escape_seq ();
2817 case C0_ENQ: /* terminal Status */
2818 if (rs[Rs_answerbackstring])
2819 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2820 (unsigned int)strlen (rs[Rs_answerbackstring]));
2822 tt_write ((unsigned char *)VT100_ANS,
2823 (unsigned int)strlen (VT100_ANS));
2825 case C0_BEL: /* bell */
2828 case C0_BS: /* backspace */
2831 case C0_HT: /* tab */
2834 case C0_CR: /* carriage return */
2835 scr_gotorc (0, 0, R_RELATIVE);
2837 case C0_VT: /* vertical tab, form feed */
2839 case C0_LF: /* line feed */
2842 case C0_SO: /* shift out - acs */
2843 scr_charset_choose (1);
2845 case C0_SI: /* shift in - acs */
2846 scr_charset_choose (0);
2849 #ifdef EIGHT_BIT_CONTROLS
2851 case 0x90: /* DCS */
2854 case 0x9b: /* CSI */
2857 case 0x9d: /* CSI */
2866 /*{{{ process VT52 escape sequences */
2868 rxvt_term::process_escape_vt52 (unicode_t ch)
2874 case 'A': /* cursor up */
2875 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2877 case 'B': /* cursor down */
2878 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2880 case 'C': /* cursor right */
2881 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2883 case 'D': /* cursor left */
2884 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2886 case 'H': /* cursor home */
2887 scr_gotorc (0, 0, 0);
2889 case 'I': /* cursor up and scroll down if needed */
2892 case 'J': /* erase to end of screen */
2893 scr_erase_screen (0);
2895 case 'K': /* erase to end of line */
2898 case 'Y': /* move to specified row and col */
2899 /* full command is 'ESC Y row col' where row and col
2900 * are encoded by adding 32 and sending the ascii
2901 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2903 row = cmd_getc () - ' ';
2904 col = cmd_getc () - ' ';
2905 scr_gotorc (row, col, 0);
2907 case 'Z': /* identify the terminal type */
2908 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2910 case '<': /* turn off VT52 mode */
2911 PrivMode (0, PrivMode_vt52);
2913 case 'F': /* use special graphics character set */
2914 case 'G': /* use regular character set */
2917 case '=': /* use alternate keypad mode */
2918 case '>': /* use regular keypad mode */
2926 /*{{{ process escape sequences */
2928 rxvt_term::process_escape_seq ()
2930 unicode_t ch = cmd_getc ();
2932 if (priv_modes & PrivMode_vt52)
2934 process_escape_vt52 (ch);
2940 /* case 1: do_tek_mode (); break; */
2942 if (cmd_getc () == '8')
2946 scr_charset_set (0, (unsigned int)cmd_getc ());
2949 scr_charset_set (1, (unsigned int)cmd_getc ());
2952 scr_charset_set (2, (unsigned int)cmd_getc ());
2955 scr_charset_set (3, (unsigned int)cmd_getc ());
2966 scr_cursor (RESTORE);
2970 scr_forwardindex ();
2975 PrivMode ((ch == '='), PrivMode_aplKP);
2985 /* 8.3.87: NEXT LINE */
2986 case C1_NEL: /* ESC E */
2988 unicode_t nlcr[] = { C0_LF, C0_CR };
2989 scr_add_lines (nlcr, 1, 2);
2993 /* kidnapped escape sequence: Should be 8.3.48 */
2994 case C1_ESA: /* ESC G */
2995 process_graphics ();
2998 /* 8.3.63: CHARACTER TABULATION SET */
2999 case C1_HTS: /* ESC H */
3003 /* 8.3.105: REVERSE LINE FEED */
3004 case C1_RI: /* ESC M */
3008 /* 8.3.142: SINGLE-SHIFT TWO */
3009 /*case C1_SS2: scr_single_shift (2); break; */
3011 /* 8.3.143: SINGLE-SHIFT THREE */
3012 /*case C1_SS3: scr_single_shift (3); break; */
3014 /* 8.3.27: DEVICE CONTROL STRING */
3015 case C1_DCS: /* ESC P */
3019 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3020 case C1_SCI: /* ESC Z */
3021 tt_write ((const unsigned char *)ESCZ_ANSWER,
3022 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3023 break; /* steal obsolete ESC [ c */
3025 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3026 case C1_CSI: /* ESC [ */
3030 /* 8.3.90: OPERATING SYSTEM COMMAND */
3031 case C1_OSC: /* ESC ] */
3035 /* 8.3.106: RESET TO INITIAL STATE */
3042 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3044 scr_charset_choose (2);
3047 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3049 scr_charset_choose (3);
3055 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3059 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3060 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3061 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3062 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3063 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3064 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3065 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3066 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3069 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3070 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3071 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3072 #define get_byte_array_bit(array, bit) \
3073 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3075 const unsigned char csi_defaults[] =
3077 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3078 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3079 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3080 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3081 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3082 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3083 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3084 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3089 rxvt_term::process_csi_seq ()
3091 unicode_t ch, priv, i;
3092 unsigned int nargs, p;
3096 for (nargs = ESC_ARGS; nargs > 0;)
3101 if (ch >= '<' && ch <= '?')
3102 { /* '<' '=' '>' '?' */
3107 /* read any numerical arguments */
3108 for (n = -1; ch < CSI_ICH; )
3115 n = n * 10 + ch - '0';
3119 if (nargs < ESC_ARGS)
3123 else if (IS_CONTROL (ch))
3124 process_nonprinting (ch);
3132 if (nargs < ESC_ARGS)
3136 ndef = get_byte_array_bit (csi_defaults, i);
3137 for (p = 0; p < nargs; p++)
3142 fprintf (stderr, "CSI ");
3143 for (p = 0; p < nargs; p++)
3144 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3145 fprintf (stderr, "%c\n", ch);
3149 * private mode handling
3156 if (ch == CSI_DA) /* secondary device attributes */
3157 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING);
3160 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3161 process_terminal_mode (ch, priv, nargs, arg);
3170 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3173 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3176 case 0: /* initiate transfer to primary aux device */
3177 scr_printscreen (0);
3179 case 5: /* start relay to primary aux device */
3180 process_print_pipe ();
3186 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3187 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3190 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3191 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3192 scr_gotorc (arg[0], 0, RELATIVE);
3195 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3196 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3199 #else /* emulate common DEC VTs */
3200 arg[0] = arg[0] ? -arg[0] : -1;
3203 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3204 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3206 scr_gotorc (0, arg[0], RELATIVE);
3207 #else /* emulate common DEC VTs */
3208 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3212 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3215 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3216 scr_gotorc (arg[0], 0, R_RELATIVE);
3219 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3220 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3221 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3224 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3225 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3228 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3229 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3230 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3233 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3236 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3240 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3241 scr_erase_screen (arg[0]);
3244 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3245 scr_erase_line (arg[0]);
3248 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3249 scr_insdel_chars (arg[0], INSERT);
3252 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3253 scr_insdel_lines (arg[0], INSERT);
3256 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3257 scr_insdel_lines (arg[0], DELETE);
3260 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3261 scr_insdel_chars (arg[0], ERASE);
3264 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3265 scr_insdel_chars (arg[0], DELETE);
3268 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3271 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3272 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
3275 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3276 tt_write ((const unsigned char *)VT100_ANS,
3277 (unsigned int) (sizeof (VT100_ANS) - 1));
3280 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3281 process_sgr_mode (nargs, arg);
3284 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3287 case 5: /* DSR requested */
3288 tt_printf ("\033[0n");
3290 case 6: /* CPR requested */
3291 scr_report_position ();
3293 case 7: /* unofficial extension */
3294 if (options & Opt_insecure)
3295 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3297 case 8: /* unofficial extension */
3298 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3303 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3306 case 0: /* char tab stop cleared at active position */
3309 /* case 1: */ /* line tab stop cleared in active line */
3310 /* case 2: */ /* char tab stops cleared in active line */
3311 case 3: /* all char tab stops are cleared */
3312 /* case 4: */ /* all line tab stops are cleared */
3313 case 5: /* all tab stops are cleared */
3319 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3322 case 0: /* char tab stop set at active position */
3324 break; /* = ESC H */
3325 /* case 1: */ /* line tab stop set at active line */
3326 case 2: /* char tab stop cleared at active position */
3328 break; /* = ESC [ 0 g */
3329 /* case 3: */ /* line tab stop cleared at active line */
3330 /* case 4: */ /* char tab stops cleared at active line */
3331 case 5: /* all char tab stops are cleared */
3333 break; /* = ESC [ 3 g */
3334 /* case 6: */ /* all line tab stops are cleared */
3338 case CSI_RM: /* 8.3.107: RESET MODE */
3340 scr_insert_mode (0);
3341 else if (arg[0] == 20)
3342 priv_modes &= ~PrivMode_LFNL;
3345 case CSI_SM: /* 8.3.126: SET MODE */
3347 scr_insert_mode (1);
3348 else if (arg[0] == 20)
3349 priv_modes |= PrivMode_LFNL;
3353 * PRIVATE USE beyond this point. All CSI_7? sequences here
3355 case CSI_72: /* DECSTBM: set top and bottom margins */
3357 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3358 else if (nargs == 0 || arg[0] >= arg[1])
3359 scr_scroll_region (0, MAX_ROWS - 1);
3361 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3368 scr_cursor (RESTORE);
3373 process_window_ops (arg, nargs);
3377 case CSI_78: /* DECREQTPARM */
3378 if (arg[0] == 0 || arg[0] == 1)
3379 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3391 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3394 XWindowAttributes wattr;
3405 case 1: /* deiconify window */
3406 XMapWindow (display->display, TermWin.parent[0]);
3408 case 2: /* iconify window */
3409 XIconifyWindow (display->display, TermWin.parent[0],
3410 DefaultScreen (display->display));
3412 case 3: /* set position (pixels) */
3413 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]);
3415 case 4: /* set size (pixels) */
3416 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3418 case 5: /* raise window */
3419 XRaiseWindow (display->display, TermWin.parent[0]);
3421 case 6: /* lower window */
3422 XLowerWindow (display->display, TermWin.parent[0]);
3424 case 7: /* refresh window */
3427 case 8: /* set size (chars) */
3428 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
3429 (unsigned int) (args[1] * TermWin.fheight));
3432 //case 9: NYI, TODO, restore maximized window or maximize window
3434 if (args[0] >= 24) /* set height (chars) */
3435 set_widthheight ((unsigned int)TermWin.width,
3436 (unsigned int) (args[1] * TermWin.fheight));
3441 * reports - some output format copied from XTerm
3443 case 11: /* report window state */
3444 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3445 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3447 case 13: /* report window position */
3448 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3449 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root,
3450 -wattr.border_width, -wattr.border_width,
3452 tt_printf ("\033[3;%d;%dt", x, y);
3454 case 14: /* report window size (pixels) */
3455 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3456 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3458 case 18: /* report text area size (chars) */
3459 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3461 case 19: /* report window size (chars) */
3462 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3464 case 20: /* report icon label */
3467 XGetIconName (display->display, TermWin.parent[0], &s);
3468 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3472 case 21: /* report window title */
3475 XFetchName (display->display, TermWin.parent[0], &s);
3476 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3484 /*----------------------------------------------------------------------*/
3486 * get input up until STRING TERMINATOR (or BEL)
3487 * ends_how is terminator used. returned input must be free()'d
3490 rxvt_term::get_to_st (unicode_t &ends_how)
3492 unicode_t prev = 0, ch;
3495 unsigned char string[STRING_MAX];
3497 while ((ch = cmd_getc ()) != NOCHAR)
3501 if (ch == 0x5c) /* 7bit ST */
3506 else if (ch == C0_BEL || ch == CHAR_ST)
3509 return NULL; /* other control character - exit */
3511 if (n >= sizeof (string) - 1)
3512 // stop at some sane length
3517 string[n++] = cmd_get8 ();
3521 string[n++] = prev = ch;
3526 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3529 ends_how = (ch == 0x5c ? C0_ESC : ch);
3530 strncpy (s, string, n);
3534 /*----------------------------------------------------------------------*/
3536 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3539 rxvt_term::process_dcs_seq ()
3554 /*----------------------------------------------------------------------*/
3556 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3559 rxvt_term::process_osc_seq ()
3565 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3566 arg = arg * 10 + (ch - '0');
3570 unsigned char *s = get_to_st (eh);
3574 process_xterm_seq (arg, (char *)s, eh);
3581 rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3583 if (str[0] == '?' && !str[1])
3585 unsigned short r, g, b;
3586 pix_colors_focused[color].get (display, r, g, b);
3587 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3590 set_window_color (color, str);
3594 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3595 * 0 = change iconName/title
3596 * 1 = change iconName
3599 * 10 = change fg color
3600 * 11 = change bg color
3601 * 12 = change text color
3602 * 13 = change mouse foreground color
3603 * 17 = change highlight character colour
3604 * 18 = change bold character color
3605 * 19 = change underlined character color
3606 * 46 = change logfile (not implemented)
3611 * 39 = change default fg color
3612 * 49 = change default bg color
3613 * 55 = dump scrollback buffer and all of screen
3614 * 701 = change locale
3619 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3624 bool query = str[0] == '?' && !str[1];
3626 assert (str != NULL);
3632 case XTerm_iconName:
3633 set_icon_name (str);
3638 case XTerm_property:
3641 Atom prop = XInternAtom (display->display, str + 1, True);
3644 unsigned long nitems;
3645 unsigned long bytes_after;
3646 unsigned char *value = 0;
3647 const char *str = "";
3650 && XGetWindowProperty (display->display, TermWin.parent[0],
3651 prop, 0, 1<<16, 0, AnyPropertyType,
3652 &actual_type, &actual_format,
3653 &nitems, &bytes_after, &value) == Success
3654 && actual_type != None
3655 && actual_format == 8)
3656 str = (const char *)(value);
3658 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3664 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3669 XChangeProperty (display->display, TermWin.parent[0],
3670 display->atom (str), XA_STRING, 8,
3671 PropModeReplace, (unsigned char *)eq + 1,
3675 XDeleteProperty (display->display, TermWin.parent[0],
3676 display->atom (str));
3681 for (buf = (char *)str; buf && *buf;)
3683 if ((name = strchr (buf, ';')) == NULL)
3689 if (color < 0 || color >= TOTAL_COLORS)
3692 if ((buf = strchr (name, ';')) != NULL)
3695 if (name[0] == '?' && !name[1])
3697 unsigned short r, g, b;
3698 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3699 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3702 set_window_color (color + minCOLOR, name);
3706 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3709 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3711 #ifndef NO_CURSORCOLOR
3712 case XTerm_Color_cursor:
3713 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3716 case XTerm_Color_pointer_fg:
3717 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3719 case XTerm_Color_pointer_bg:
3720 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3722 #ifndef NO_BOLD_UNDERLINE_REVERSE
3723 case XTerm_Color_BD:
3724 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3726 case XTerm_Color_UL:
3727 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3729 case XTerm_Color_RV:
3730 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3738 scale_pixmap (""); /* reset to default scaling */
3739 set_bgPixmap (str); /* change pixmap */
3743 while ((str = strchr (str, ';')) != NULL)
3747 changed += scale_pixmap (str);
3753 #ifdef XPM_BACKGROUND
3760 case XTerm_restoreFG:
3761 set_window_color (Color_fg, str);
3763 case XTerm_restoreBG:
3764 set_window_color (Color_bg, str);
3768 // TODO, when secure mode?
3773 tt_printf ("\33]%d;%-.250s%c", XTerm_font,
3774 (options & Opt_insecure) && TermWin.fontset->fontdesc
3775 ? TermWin.fontset->fontdesc : "",
3784 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3794 case XTerm_findfont:
3796 int fid = TermWin.fontset->find_font (atoi (str));
3797 tt_printf ("\33]%d;%d;%-.250s%c", XTerm_findfont,
3799 (options & Opt_insecure) ? (*TermWin.fontset)[fid]->name : "",
3807 if (options & Opt_insecure)
3808 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3812 case XTerm_dumpscreen: /* no error notices */
3815 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3825 /*----------------------------------------------------------------------*/
3827 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3829 * mode can only have the following values:
3835 * so no need for fancy checking
3838 rxvt_term::privcases (int mode, unsigned long bit)
3844 SavedModes |= (priv_modes & bit);
3850 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3852 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3853 PrivMode (state, bit);
3859 /* we're not using priv _yet_ */
3861 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3869 const unsigned long bit;
3873 { 1, PrivMode_aplCUR },
3874 { 2, PrivMode_vt52 },
3875 { 3, PrivMode_132 },
3876 { 4, PrivMode_smoothScroll },
3877 { 5, PrivMode_rVideo },
3878 { 6, PrivMode_relOrigin },
3879 { 7, PrivMode_Autowrap },
3880 // 8, bi-directional support mode
3881 { 9, PrivMode_MouseX10 },
3883 { menuBar_esc, PrivMode_menuBar },
3885 // 18, 19 printing-related
3886 { 25, PrivMode_VisibleCursor },
3887 #ifdef scrollBar_esc
3888 { scrollBar_esc, PrivMode_scrollBar },
3890 { 35, PrivMode_ShiftKeys }, // rxvt extension
3891 { 40, PrivMode_132OK },
3892 // 41 xterm more fixes NYI
3893 // 45 margin bell NYI
3895 { 47, PrivMode_Screen },
3896 { 66, PrivMode_aplKP },
3897 #ifndef NO_BACKSPACE_KEY
3898 { 67, PrivMode_BackSpace },
3900 { 1000, PrivMode_MouseX11 },
3901 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3902 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3903 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3904 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3905 { 1011, PrivMode_Keypress }, // rxvt extension
3906 // 1035 enable modifiers for alt, numlock NYI
3907 // 1036 send ESC for meta keys NYI
3908 // 1037 send DEL for keypad delete NYI
3909 { 1047, PrivMode_Screen },
3910 // 1048 save and restore cursor
3911 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3912 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3918 /* make lo/hi boolean */
3920 mode = 0; /* reset */
3921 else if (mode == 'h')
3924 for (i = 0; i < nargs; i++)
3928 /* basic handling */
3929 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
3930 if (argtopriv[j].argval == arg[i])
3932 state = privcases (mode, argtopriv[j].bit);
3936 /* extra handling for values with state unkept */
3939 case 1048: /* alternative cursor save */
3940 if (options & Opt_secondaryScreen)
3942 scr_cursor (RESTORE);
3949 /* extra handling for values with valid 0 or 1 state */
3952 /* case 1: - application cursor keys */
3953 case 2: /* VT52 mode */
3954 /* oddball mode. should be set regardless of set/reset
3955 * parameter. Return from VT52 mode with an ESC < from
3958 PrivMode (1, PrivMode_vt52);
3960 case 3: /* 80/132 */
3961 if (priv_modes & PrivMode_132OK)
3962 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
3964 case 4: /* smooth scrolling */
3966 options &= ~Opt_jumpScroll;
3968 options |= Opt_jumpScroll;
3970 case 5: /* reverse video */
3971 scr_rvideo_mode (state);
3973 case 6: /* relative/absolute origins */
3974 scr_relative_origin (state);
3976 case 7: /* autowrap */
3977 scr_autowrap (state);
3979 /* case 8: - auto repeat, can't do on a per window basis */
3980 case 9: /* X10 mouse reporting */
3981 if (state) /* orthogonal */
3982 priv_modes &= ~PrivMode_MouseX11;
3987 map_menuBar (state);
3991 #ifdef scrollBar_esc
3993 if (scrollbar_mapping (state))
3995 resize_all_windows (0, 0, 0);
4000 case 25: /* visible/invisible cursor */
4001 scr_cursor_visible (state);
4003 /* case 35: - shift keys */
4004 /* case 40: - 80 <--> 132 mode */
4005 case 47: /* secondary screen */
4006 scr_change_screen (state);
4008 /* case 66: - application key pad */
4009 /* case 67: - backspace key */
4010 case 1000: /* X11 mouse reporting */
4011 if (state) /* orthogonal */
4012 priv_modes &= ~PrivMode_MouseX10;
4016 break; /* X11 mouse highlighting */
4018 case 1010: /* scroll to bottom on TTY output inhibit */
4020 options &= ~Opt_scrollTtyOutput;
4022 options |= Opt_scrollTtyOutput;
4024 case 1011: /* scroll to bottom on key press */
4026 options |= Opt_scrollTtyKeypress;
4028 options &= ~Opt_scrollTtyKeypress;
4030 case 1047: /* secondary screen w/ clearing last */
4031 if (options & Opt_secondaryScreen)
4032 if (current_screen != PRIMARY)
4033 scr_erase_screen (2);
4034 scr_change_screen (state);
4036 case 1049: /* secondary screen w/ clearing first */
4037 scr_change_screen (state);
4038 if (options & Opt_secondaryScreen)
4039 if (current_screen != PRIMARY)
4040 scr_erase_screen (2);
4049 /*{{{ process sgr sequences */
4051 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4059 scr_rendition (0, ~RS_None);
4063 for (i = 0; i < nargs; i++)
4069 rendset = 0, rendstyle = ~RS_None;
4072 rendset = 1, rendstyle = RS_Bold;
4074 //case 2: // faint or second colour
4077 rendset = 1, rendstyle = RS_Uline;
4079 case 5: // slowly blinking
4080 case 6: // rapidly blinking
4081 rendset = 1, rendstyle = RS_Blink;
4083 //case 6: // scoansi light background
4085 rendset = 1, rendstyle = RS_RVid;
4090 //case 9: // crossed out
4091 //case 10: // scoansi acs off, primary font
4092 //case 11: // scoansi acs on, first alt font
4093 //case 12: // scoansi acs on, |0x80, second alt font
4095 //case 19: // ninth alt font
4096 //case 20: // gothic
4097 case 21: // disable bold, faint
4098 rendset = 0, rendstyle = RS_Bold;
4101 rendset = 0, rendstyle = RS_Bold;
4103 //case 23: disable italic
4105 rendset = 0, rendstyle = RS_Uline;
4108 rendset = 0, rendstyle = RS_Blink;
4111 rendset = 0, rendstyle = RS_Blink;
4114 rendset = 0, rendstyle = RS_RVid;
4116 //case 28: // visible. NYI
4117 //case 29: // not crossed-out
4122 scr_rendition (rendset, rendstyle);
4123 continue; /* for (;i;) */
4129 case 31: /* set fg color */
4136 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4140 if (nargs > i + 2 && arg[i + 1] == 5)
4142 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4147 case 39: /* default fg */
4148 scr_color (Color_fg, Color_fg);
4152 case 41: /* set bg color */
4159 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4163 if (nargs > i + 2 && arg[i + 1] == 5)
4165 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4170 case 49: /* default bg */
4171 scr_color (Color_bg, Color_bg);
4174 #ifndef NO_BRIGHTCOLOR
4176 case 91: /* set bright fg color */
4183 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)),
4187 case 101: /* set bright bg color */
4194 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)),
4204 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4206 rxvt_term::process_graphics ()
4208 unicode_t ch, cmd = cmd_getc ();
4211 { /* query graphics */
4212 tt_printf ("\033G0\012"); /* no graphics */
4215 /* swallow other graphics sequences until terminating ':' */
4222 /* ------------------------------------------------------------------------- */
4225 * Send printf () formatted output to the command.
4226 * Only use for small amounts of data.
4229 rxvt_term::tt_printf (const char *fmt,...)
4232 unsigned char buf[256];
4234 va_start (arg_ptr, fmt);
4235 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4237 tt_write (buf, strlen (buf));
4240 /* ---------------------------------------------------------------------- */
4241 /* Write data to the pty as typed by the user, pasted with the mouse,
4242 * or generated by us in response to a query ESC sequence.
4245 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4247 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT
4253 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4255 if ((unsigned int)written == len)
4263 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4265 memcpy (v_buffer + v_buflen, data, len);
4271 int written = write (pty.pty, v_buffer, min (MAX_PTY_WRITE, v_buflen));
4275 v_buflen -= written;
4283 pty_ev.set (EVENT_READ);
4287 memmove (v_buffer, v_buffer + written, v_buflen);
4289 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4290 // original code just ignores this...
4294 pty_ev.set (EVENT_READ | EVENT_WRITE);
4300 /*----------------------- end-of-file (C source) -----------------------*/