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 */
53 #ifdef KEYSYM_RESOURCE
54 # include "keyboard.h"
59 /*----------------------------------------------------------------------*/
61 #define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
63 // exception thrown when the command parser runs out of input data
64 class out_of_input { } out_of_input;
66 #if ENABLE_FRILLS || ISO_14755
68 #define ISO_14755_STARTED 0x80000000UL
69 #define ISO_14755_51 0x40000000UL // basic (section 5.1)
70 #define ISO_14755_52 0x20000000UL // keycap (section 5.2)
71 #define ISO_14755_54 0x10000000UL // code feedback (section 5.4)
72 #define ISO_14755_MASK 0x0fffffffUL
75 static unsigned short iso14755_symtab[] = {
92 XK_ISO_Left_Tab, 0x21e6,
96 XK_Shift_Lock, 0x21eb,
101 XK_ISO_Level3_Shift, 0x21ee,
102 XK_ISO_Level3_Lock, 0x21ef,
103 XK_ISO_Group_Lock, 0x21f0,
111 XK_BackSpace, 0x232b,
113 XK_Control_L, 0x2388,
114 XK_Control_R, 0x2388,
127 rxvt_term::iso14755_54 (int x, int y)
132 if (x < 0 || x >= TermWin.ncol
133 || y < 0 || y >= TermWin.nrow)
138 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x];
140 if (t != NOCHAR || !x)
142 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x],
143 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
144 iso14755buf = ISO_14755_54;
156 rxvt_term::iso14755_51 (unicode_t ch, rend_t r)
158 rxvt_fontset *fs = FONTSET (r);
159 rxvt_font *f = (*fs)[fs->find_font (ch)];
160 wchar_t *chr, *alloc, ch2;
166 len = rxvt_composite.expand (ch, 0);
167 alloc = chr = new wchar_t[len];
168 rxvt_composite.expand (ch, chr);
180 int width = strlen (f->name);
182 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1);
184 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
186 for (int y = 0; y < len; y++)
192 sprintf (buf, "%8x", ch);
193 scr_overlay_set (0, y, buf);
194 scr_overlay_set (9, y, '=');
199 scr_overlay_set (11, y, ch, r);
200 scr_overlay_set (12, y, NOCHAR, r);
203 scr_overlay_set (0, len, f->name);
213 rxvt_term::commit_iso14755 ()
217 ch[0] = iso14755buf & ISO_14755_MASK;
220 if (iso14755buf & ISO_14755_51)
225 // allow verbatim 0-bytes and control-bytes to be entered
227 len = wcstombs (mb, ch, 16);
235 tt_write ((unsigned char *)mb, len);
244 rxvt_term::hex_keyval (XKeyEvent &ev)
246 // check wether this event corresponds to a hex digit
247 // if the modifiers had not been pressed.
248 for (int index = 0; index < 8; index++)
250 KeySym k = XLookupKeysym (&ev, index);
252 if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0;
253 else if (k >= XK_0 && k <= XK_9) return k - XK_0;
254 else if (k >= XK_a && k <= XK_f) return k - XK_a + 10;
255 else if (k >= XK_A && k <= XK_F) return k - XK_A + 10;
262 /*{{{ Convert the keypress event into a string */
264 rxvt_term::lookup_key (XKeyEvent &ev)
266 int ctrl, meta, shft, len;
270 static int debug_key = 1; /* accessible by a debugger only */
273 unsigned char kbuf[KBUFSZ];
276 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
277 * escape sequence to toggle the Keypad.
279 * Always permit `shift' to override the current setting
281 shft = (ev.state & ShiftMask);
282 ctrl = (ev.state & ControlMask);
283 meta = (ev.state & ModMetaMask);
285 if (numlock_state || (ev.state & ModNumLockMask))
287 numlock_state = (ev.state & ModNumLockMask);
288 PrivMode ((!numlock_state), PrivMode_aplKP);
296 Status status_return;
299 #ifdef X_HAVE_UTF8_STRING
300 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
301 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf,
302 KBUFSZ, &keysym, &status_return);
307 wchar_t wkbuf[KBUFSZ + 1];
309 // the XOpenIM manpage lies about hardcoding the locale
310 // at the point of XOpenIM, so temporarily switch locales
312 SET_LOCALE (rs[Rs_imLocale]);
313 // assume wchar_t == unicode or better
314 len = XwcLookupString (Input_Context, &ev, wkbuf,
315 KBUFSZ, &keysym, &status_return);
319 if (status_return == XLookupChars
320 || status_return == XLookupBoth)
322 /* make sure the user can type ctrl-@, i.e. NUL */
323 if (len == 1 && *wkbuf == 0)
331 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
340 valid_keysym = status_return == XLookupKeySym
341 || status_return == XLookupBoth;
346 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose);
347 valid_keysym = keysym != NoSymbol;
352 #ifdef KEYSYM_RESOURCE
353 if (keyboard->dispatch (this, keysym, ev.state))
357 if (TermWin.saveLines)
359 #ifdef UNSHIFTED_SCROLLKEYS
367 #ifdef PAGING_CONTEXT_LINES
368 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES;
370 lnsppg = TermWin.nrow * 4 / 5;
372 if (keysym == XK_Prior)
374 scr_page (UP, lnsppg);
377 else if (keysym == XK_Next)
379 scr_page (DN, lnsppg);
383 #ifdef SCROLL_ON_UPDOWN_KEYS
391 else if (keysym == XK_Down)
398 #ifdef SCROLL_ON_HOMEEND_KEYS
401 if (keysym == XK_Home)
406 else if (keysym == XK_End)
417 /* Shift + F1 - F10 generates F11 - F20 */
418 if (keysym >= XK_F1 && keysym <= XK_F10)
420 keysym += (XK_F11 - XK_F1);
421 shft = 0; /* turn off Shift */
423 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
427 /* normal XTerm key bindings */
428 case XK_Insert: /* Shift+Insert = paste mouse selection */
429 selection_request (ev.time, 0, 0);
433 case XK_KP_Add: /* Shift+KP_Add = bigger font */
434 change_font (FONT_UP);
436 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
437 change_font (FONT_DN);
444 #if ENABLE_FRILLS || ISO_14755
450 if (iso14755buf & ISO_14755_51
451 && (keysym == XK_space || keysym == XK_KP_Space
452 || keysym == XK_Return || keysym == XK_KP_Enter))
455 iso14755buf = ISO_14755_51;
461 else if ((hv = hex_keyval (ev)) >= 0)
463 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
466 iso14755_51 (iso14755buf & ISO_14755_MASK);
478 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
479 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
480 if (!(iso14755buf & ISO_14755_STARTED))
482 iso14755buf |= ISO_14755_STARTED;
484 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
485 scr_overlay_set (0, 0, "ISO 14755 mode");
491 if (keysym == XK_Print)
493 scr_printscreen (ctrl | shft);
498 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
504 #ifndef NO_BACKSPACE_KEY
506 if (priv_modes & PrivMode_HaveBackSpace)
508 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
509 ^ !!ctrl) ? '\b' : '\177';
513 strcpy (kbuf, key_backspace);
516 #ifndef NO_DELETE_KEY
518 strcpy (kbuf, key_delete);
523 strcpy (kbuf, "\033[Z");
526 #ifdef CTRL_TAB_MAKES_META
530 #ifdef MOD4_TAB_MAKES_META
531 if (ev.state & Mod4Mask)
539 case XK_KP_Up: /* \033Ox or standard */
540 case XK_KP_Down: /* \033Or or standard */
541 case XK_KP_Right: /* \033Ov or standard */
542 case XK_KP_Left: /* \033Ot or standard */
543 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
545 strcpy (kbuf, "\033OZ");
546 kbuf[2] = "txvr"[keysym - XK_KP_Left];
550 /* translate to std. cursor key */
551 keysym = XK_Left + (keysym - XK_KP_Left);
554 case XK_Up: /* "\033[A" */
555 case XK_Down: /* "\033[B" */
556 case XK_Right: /* "\033[C" */
557 case XK_Left: /* "\033[D" */
558 strcpy (kbuf, "\033[Z");
559 kbuf[2] = "DACB"[keysym - XK_Left];
562 kbuf[2] = "dacb"[keysym - XK_Left];
566 kbuf[2] = "dacb"[keysym - XK_Left];
568 else if (priv_modes & PrivMode_aplCUR)
572 #ifndef UNSHIFTED_SCROLLKEYS
575 /* allow shift to override */
576 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
578 strcpy (kbuf, "\033Oy");
584 strcpy (kbuf, "\033[5~");
588 /* allow shift to override */
589 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
591 strcpy (kbuf, "\033Os");
597 strcpy (kbuf, "\033[6~");
601 /* allow shift to override */
602 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
604 strcpy (kbuf, "\033OM");
611 if (priv_modes & PrivMode_LFNL)
626 strcpy (kbuf, "\033Ou");
630 strcpy (kbuf, "\033Op");
634 strcpy (kbuf, "\033On");
637 case XK_KP_F1: /* "\033OP" */
638 case XK_KP_F2: /* "\033OQ" */
639 case XK_KP_F3: /* "\033OR" */
640 case XK_KP_F4: /* "\033OS" */
641 strcpy (kbuf, "\033OP");
642 kbuf[2] += (keysym - XK_KP_F1);
645 case XK_KP_Multiply: /* "\033Oj" : "*" */
646 case XK_KP_Add: /* "\033Ok" : "+" */
647 case XK_KP_Separator: /* "\033Ol" : "," */
648 case XK_KP_Subtract: /* "\033Om" : "-" */
649 case XK_KP_Decimal: /* "\033On" : "." */
650 case XK_KP_Divide: /* "\033Oo" : "/" */
651 case XK_KP_0: /* "\033Op" : "0" */
652 case XK_KP_1: /* "\033Oq" : "1" */
653 case XK_KP_2: /* "\033Or" : "2" */
654 case XK_KP_3: /* "\033Os" : "3" */
655 case XK_KP_4: /* "\033Ot" : "4" */
656 case XK_KP_5: /* "\033Ou" : "5" */
657 case XK_KP_6: /* "\033Ov" : "6" */
658 case XK_KP_7: /* "\033Ow" : "7" */
659 case XK_KP_8: /* "\033Ox" : "8" */
660 case XK_KP_9: /* "\033Oy" : "9" */
661 /* allow shift to override */
662 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
664 strcpy (kbuf, "\033Oj");
665 kbuf[2] += (keysym - XK_KP_Multiply);
669 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
675 strcpy (kbuf, "\033[1~");
678 strcpy (kbuf, "\033[2~");
680 #ifdef DXK_Remove /* support for DEC remove like key */
685 strcpy (kbuf, "\033[3~");
688 strcpy (kbuf, "\033[4~");
692 /* allow shift to override */
693 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
695 strcpy (kbuf, "\033Oq");
701 strcpy (kbuf, KS_END);
705 /* allow shift to override */
706 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
708 strcpy (kbuf, "\033Ow");
714 strcpy (kbuf, KS_HOME);
717 #define FKEY(n, fkey) \
718 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
720 case XK_F1: /* "\033[11~" */
721 case XK_F2: /* "\033[12~" */
722 case XK_F3: /* "\033[13~" */
723 case XK_F4: /* "\033[14~" */
724 case XK_F5: /* "\033[15~" */
727 case XK_F6: /* "\033[17~" */
728 case XK_F7: /* "\033[18~" */
729 case XK_F8: /* "\033[19~" */
730 case XK_F9: /* "\033[20~" */
731 case XK_F10: /* "\033[21~" */
734 case XK_F11: /* "\033[23~" */
735 case XK_F12: /* "\033[24~" */
736 case XK_F13: /* "\033[25~" */
737 case XK_F14: /* "\033[26~" */
740 case XK_F15: /* "\033[28~" */
741 case XK_F16: /* "\033[29~" */
744 case XK_Help: /* "\033[28~" */
747 case XK_Menu: /* "\033[29~" */
750 case XK_F17: /* "\033[31~" */
751 case XK_F18: /* "\033[32~" */
752 case XK_F19: /* "\033[33~" */
753 case XK_F20: /* "\033[34~" */
754 case XK_F21: /* "\033[35~" */
755 case XK_F22: /* "\033[36~" */
756 case XK_F23: /* "\033[37~" */
757 case XK_F24: /* "\033[38~" */
758 case XK_F25: /* "\033[39~" */
759 case XK_F26: /* "\033[40~" */
760 case XK_F27: /* "\033[41~" */
761 case XK_F28: /* "\033[42~" */
762 case XK_F29: /* "\033[43~" */
763 case XK_F30: /* "\033[44~" */
764 case XK_F31: /* "\033[45~" */
765 case XK_F32: /* "\033[46~" */
766 case XK_F33: /* "\033[47~" */
767 case XK_F34: /* "\033[48~" */
768 case XK_F35: /* "\033[49~" */
782 * Pass meta for all function keys, if 'meta' option set
785 if (meta && (meta_char == 0x80) && len > 0)
786 kbuf[len - 1] |= 0x80;
790 else if (ctrl && keysym == XK_minus)
793 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
795 else if (keysym == XK_ISO_Left_Tab)
797 strcpy (kbuf, "\033[Z");
804 if (meta && (meta_char == 0x80))
808 for (ch = kbuf; ch < kbuf + len; ch++)
819 return; /* not mapped */
821 if (options & Opt_scrollTtyKeypress)
822 if (TermWin.view_start)
824 TermWin.view_start = 0;
829 * these modifications only affect the static keybuffer
830 * pass Shift/Control indicators for function keys ending with `~'
834 * Shift+Prior = "ESC[5$"
835 * Ctrl+Prior = "ESC[5^"
836 * Ctrl+Shift+Prior = "ESC[5@"
837 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
839 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
840 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
845 && meta_char == C0_ESC
849 const unsigned char ch = C0_ESC;
853 #if defined(DEBUG_CMD)
854 /* Display keyboard buffer contents */
858 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
859 for (i = 0, p = kbuf; i < len; i++, p++)
860 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
861 fprintf (stderr, "'\n");
862 #endif /* DEBUG_CMD */
863 tt_write (kbuf, (unsigned int)len);
867 #if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
868 /*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
869 /* attempt to `write' count to the input buffer */
871 rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
875 n = cmdbuf_ptr - cmdbuf_base;
876 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
878 if (n > 0 && s < count)
880 memmove (cmdbuf_base, cmdbuf_ptr,
881 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
882 cmdbuf_ptr = cmdbuf_base;
889 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
894 *cmdbuf_endp++ = *str++;
908 if (want_full_refresh)
910 want_full_refresh = 0;
918 scr_refresh (refresh_type);
929 rxvt_term::check_cb (check_watcher &w)
936 if (want_refresh && !flush_ev.active)
937 flush_ev.start (NOW + 0.01);
941 rxvt_term::flush_cb (time_watcher &w)
953 rxvt_term::cursor_blink_cb (time_watcher &w)
955 hidden_cursor = !hidden_cursor;
958 w.start (w.at + BLINK_INTERVAL);
964 rxvt_term::text_blink_cb (time_watcher &w)
966 if (scr_refresh_rend (RS_Blink, RS_Blink))
968 hidden_text = !hidden_text;
970 w.start (w.at + TEXT_BLINK_INTERVAL);
975 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
977 rxvt_term::cont_scroll_cb (time_watcher &w)
979 if ((scrollbar_isUp() || scrollbar_isDn()) &&
980 scr_page (scrollbar_isUp() ? UP : DN, 1))
982 refresh_type |= SMOOTH_REFRESH;
984 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
989 #ifdef SELECTION_SCROLLING
991 rxvt_term::sel_scroll_cb (time_watcher &w)
993 if (scr_page (scroll_selection_dir, scroll_selection_lines))
995 selection_extend (selection_save_x, selection_save_y, selection_save_state);
996 refresh_type |= SMOOTH_REFRESH;
998 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1003 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1005 rxvt_term::slip_wheel_cb (time_watcher &w)
1007 if (mouse_slip_wheel_speed == 0
1008 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1009 : scr_page (UP, mouse_slip_wheel_speed))
1011 if (TermWin.view_start == TermWin.nscrolled ||
1012 TermWin.view_start == 0)
1013 mouse_slip_wheel_speed = 0;
1015 refresh_type |= SMOOTH_REFRESH;
1017 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1023 rxvt_term::pty_fill ()
1025 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1029 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
1033 memmove (cmdbuf_base, cmdbuf_ptr, n);
1034 cmdbuf_ptr = cmdbuf_base;
1035 cmdbuf_endp = cmdbuf_ptr + n;
1037 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1044 else if (n < 0 && errno != EAGAIN)
1051 rxvt_term::pty_cb (io_watcher &w, short revents)
1054 SET_LOCALE (locale);
1056 if (revents & EVENT_READ)
1057 // loop, but don't allow a single term to monopolize us
1062 if (revents & EVENT_WRITE)
1067 rxvt_term::pointer_unblank ()
1069 XDefineCursor (display->display, TermWin.vt, TermWin_cursor);
1072 #ifdef POINTER_BLANK
1075 if (options & Opt_pointerBlank)
1076 pointer_ev.start (NOW + pointerBlankDelay);
1080 #ifdef POINTER_BLANK
1082 rxvt_term::pointer_blank ()
1084 if (! (options & Opt_pointerBlank))
1087 XDefineCursor (display->display, TermWin.vt, display->blank_cursor);
1088 XFlush (display->display);
1094 rxvt_term::pointer_cb (time_watcher &w)
1097 SET_LOCALE (locale);
1104 rxvt_term::mouse_report (XButtonEvent &ev)
1106 int button_number, key_state = 0;
1111 pixel_position (&x, &y);
1113 if (MEvent.button == AnyButton)
1117 button_number = MEvent.button - Button1;
1118 /* add 0x3D for wheel events, like xterm does */
1119 if (button_number >= 3)
1120 button_number += (64 - 3);
1123 if (priv_modes & PrivMode_MouseX10)
1126 * do not report ButtonRelease
1127 * no state info allowed
1130 if (button_number == 3)
1135 /* XTerm mouse reporting needs these values:
1139 * plus will add in our own Double-Click reporting
1142 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1143 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1144 + ((MEvent.state & ControlMask) ? 16 : 0);
1145 #ifdef MOUSE_REPORT_DOUBLECLICK
1146 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1150 #if DEBUG_MOUSEREPORT
1151 fprintf (stderr, "Mouse [");
1153 fputc ('C', stderr);
1155 fputc ('S', stderr);
1157 fputc ('A', stderr);
1159 fputc ('2', stderr);
1160 fprintf (stderr, "]: <%d>, %d/%d\n",
1166 tt_printf ("\033[M%c%c%c",
1167 (32 + button_number + key_state),
1174 rxvt_W11_process_x_event (XEvent *ev)
1176 rxvt_t *r = rxvt_get_r ();
1182 /*{{{ process an X event */
1184 rxvt_term::x_cb (XEvent &ev)
1189 SET_LOCALE (locale);
1191 #if defined(CURSOR_BLINK)
1192 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1200 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1204 #if defined(POINTER_BLANK)
1205 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1207 if (ev.type == MotionNotify
1208 || ev.type == ButtonPress
1209 || ev.type == ButtonRelease)
1213 if (ev.type == KeyPress && hidden_pointer == 0)
1218 Window unused_root, unused_child;
1219 int unused_root_x, unused_root_y;
1220 unsigned int unused_mask;
1226 if (!(iso14755buf & ISO_14755_52))
1228 lookup_key (ev.xkey);
1234 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1237 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1240 #if ENABLE_FRILLS || ISO_14755
1241 // ISO 14755 support
1243 if (iso14755buf & ISO_14755_52)
1249 // iso14755 part 5.2 handling: release time
1251 if ((ev.xkey.state & ControlMask)
1252 && ((ks >= 0x40 && ks <= 0x5f)
1253 || (ks >= 0x61 && ks <= 0x7f)))
1255 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1257 return; // case-break;
1260 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1263 iso14755buf = ISO_14755_51 | i[1];
1265 return; // case-break;
1273 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1278 if (iso14755buf & ISO_14755_51)
1281 else if (iso14755buf & ISO_14755_STARTED)
1283 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1285 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1286 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1294 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1295 if (!(ev.xkey.state & ControlMask))
1296 slip_wheel_ev.stop ();
1297 else if (ks == XK_Control_L || ks == XK_Control_R)
1298 mouse_slip_wheel_speed = 0;
1304 button_press (ev.xbutton);
1308 button_release (ev.xbutton);
1312 if (ev.xclient.format == 32
1313 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1316 /* OffiX Dnd (drag 'n' drop) protocol */
1317 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1318 && (ev.xclient.data.l[0] == DndFile
1319 || ev.xclient.data.l[0] == DndDir
1320 || ev.xclient.data.l[0] == DndLink))
1325 unsigned char *data;
1326 unsigned long Size, RemainingBytes;
1328 XGetWindowProperty (disp, display->root,
1329 xa[XA_DNDSELECTION],
1331 False, AnyPropertyType,
1332 &ActualType, &ActualFormat,
1333 &Size, &RemainingBytes,
1335 set_string_property (XA_CUT_BUFFER0, data);
1337 selection_paste (display->root, XA_CUT_BUFFER0, true);
1338 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1340 #endif /* OFFIX_DND */
1344 XRefreshKeyboardMapping (&ev.xmapping);
1348 * XXX: this is not the _current_ arrangement
1349 * Here's my conclusion:
1350 * If the window is completely unobscured, use bitblt's
1351 * to scroll. Even then, they're only used when doing partial
1352 * screen scrolling. When partially obscured, we have to fill
1353 * in the GraphicsExpose parts, which means that after each refresh,
1354 * we need to wait for the graphics expose or Noexpose events,
1355 * which ought to make things real slow!
1357 case VisibilityNotify:
1358 switch (ev.xvisibility.state)
1360 case VisibilityUnobscured:
1361 refresh_type = FAST_REFRESH;
1363 case VisibilityPartiallyObscured:
1364 refresh_type = SLOW_REFRESH;
1367 refresh_type = NO_REFRESH;
1378 if (Input_Context != NULL)
1380 IMSetStatusPosition ();
1381 XSetICFocus (Input_Context);
1385 if (options & Opt_cursorBlink)
1386 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1388 #ifdef OFF_FOCUS_FADING
1391 pix_colors = pix_colors_focused;
1405 #if ENABLE_FRILLS || ISO_14755
1412 if (Input_Context != NULL)
1413 XUnsetICFocus (Input_Context);
1416 if (options & Opt_cursorBlink)
1417 cursor_blink_ev.stop ();
1420 #ifdef OFF_FOCUS_FADING
1423 pix_colors = pix_colors_unfocused;
1430 case ConfigureNotify:
1431 if (ev.xconfigure.window == TermWin.parent[0])
1436 { /* Wrap lots of configures into one */
1437 width = ev.xconfigure.width;
1438 height = ev.xconfigure.height;
1439 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1441 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev));
1443 if (szHint.width != width || szHint.height != height)
1446 resize_all_windows (width, height, 1);
1449 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1450 if (options & Opt_transparent)
1451 check_our_parents ();
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, ev.xselection.property, true);
1472 case SelectionRequest:
1473 selection_send (ev.xselectionrequest);
1479 text_blink_ev.stop ();
1486 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1491 case ReparentNotify:
1494 #endif /* TRANSPARENT */
1496 case GraphicsExpose:
1498 if (ev.xany.window == TermWin.vt)
1501 scr_expose (ev.xexpose.x, ev.xexpose.y,
1502 ev.xexpose.width, ev.xexpose.height, False);
1503 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev));
1505 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1507 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev))
1508 scr_expose (ev.xexpose.x, ev.xexpose.y,
1509 ev.xexpose.width, ev.xexpose.height, False);
1511 scr_refresh (refresh_type);
1515 XEvent unused_event;
1517 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1519 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1522 if (isScrollbarWindow (ev.xany.window))
1524 scrollBar.setIdle ();
1528 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1533 if (am_transparent && ev.xany.window == TermWin.parent[0])
1534 XClearWindow (disp, ev.xany.window);
1540 #ifdef POINTER_BLANK
1545 if (isMenuBarWindow (ev.xany.window))
1547 menubar_control (ev.xbutton);
1551 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1554 if (ev.xany.window == TermWin.vt)
1556 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1558 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev))
1561 XQueryPointer (disp, TermWin.vt,
1562 &unused_root, &unused_child,
1563 &unused_root_x, &unused_root_y,
1564 &ev.xbutton.x, &ev.xbutton.y,
1566 #ifdef MOUSE_THRESHOLD
1567 /* deal with a `jumpy' mouse */
1568 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1573 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1575 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1579 selection_extend (ev.xbutton.x, ev.xbutton.y,
1580 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 (disp, scrollBar.win,
1639 XQueryPointer (disp, scrollBar.win,
1640 &unused_root, &unused_child,
1641 &unused_root_x, &unused_root_y,
1642 &ev.xbutton.x, &ev.xbutton.y,
1644 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1646 scr_refresh (refresh_type);
1656 rxvt_term::rootwin_cb (XEvent &ev)
1659 SET_LOCALE (locale);
1663 case PropertyNotify:
1665 * if user used some Esetroot compatible prog to set the root bg,
1666 * use the property to determine the pixmap. We use it later on.
1668 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1669 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
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;
1708 /* mouse report from vt window */
1709 /* save the xbutton state (for ButtonRelease) */
1710 MEvent.state = ev.state;
1711 #ifdef MOUSE_REPORT_DOUBLECLICK
1712 if (ev.button == MEvent.button && clickintime)
1714 /* same button, within alloted time */
1716 if (MEvent.clicks > 1)
1718 /* only report double clicks */
1722 /* don't report the release */
1724 MEvent.button = AnyButton;
1729 /* different button, or time expired */
1731 MEvent.button = ev.button;
1735 MEvent.button = ev.button;
1737 #endif /* MOUSE_REPORT_DOUBLECLICK */
1742 if (ev.button != MEvent.button)
1748 /* allow meta + click to select rectangular areas */
1749 /* should be done in screen.C */
1751 selection.rect = !!(ev.state & ModMetaMask);
1753 selection.rect = false;
1756 /* allow shift+left click to extend selection */
1757 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1759 if (MEvent.button == Button1 && clickintime)
1760 selection_rotate (ev.x, ev.y);
1762 selection_extend (ev.x, ev.y, 1);
1766 if (MEvent.button == Button1 && clickintime)
1771 selection_click (MEvent.clicks, ev.x, ev.y);
1774 MEvent.button = Button1;
1778 if (MEvent.button == Button3 && clickintime)
1779 selection_rotate (ev.x, ev.y);
1781 selection_extend (ev.x, ev.y, 1);
1783 MEvent.button = Button3;
1788 MEvent.time = ev.time;
1793 * Scrollbar window processing of button press
1795 if (isScrollbarWindow (ev.window))
1797 scrollBar.setIdle ();
1799 * Rxvt-style scrollbar:
1800 * move up if mouse is above slider
1801 * move dn if mouse is below slider
1803 * XTerm-style scrollbar:
1804 * Move display proportional to pointer location
1805 * pointer near top -> scroll one line
1806 * pointer near bot -> scroll full page
1808 #ifndef NO_SCROLLBAR_REPORT
1812 * Mouse report disabled scrollbar:
1813 * arrow buttons - send up/down
1814 * click on scrollbar - send pageup/down
1816 if ((scrollBar.style == R_SB_NEXT
1817 && scrollbarnext_upButton (ev.y))
1818 || (scrollBar.style == R_SB_RXVT
1819 && scrollbarrxvt_upButton (ev.y)))
1820 tt_printf ("\033[A");
1821 else if ((scrollBar.style == R_SB_NEXT
1822 && scrollbarnext_dnButton (ev.y))
1823 || (scrollBar.style == R_SB_RXVT
1824 && scrollbarrxvt_dnButton (ev.y)))
1825 tt_printf ("\033[B");
1833 tt_printf ("\033[6~");
1836 tt_printf ("\033[5~");
1841 #endif /* NO_SCROLLBAR_REPORT */
1846 if (scrollBar.style == R_SB_NEXT)
1848 if (scrollbarnext_upButton (ev.y))
1849 upordown = -1; /* up */
1850 else if (scrollbarnext_dnButton (ev.y))
1851 upordown = 1; /* down */
1853 else if (scrollBar.style == R_SB_RXVT)
1855 if (scrollbarrxvt_upButton (ev.y))
1856 upordown = -1; /* up */
1857 else if (scrollbarrxvt_dnButton (ev.y))
1858 upordown = 1; /* down */
1862 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1863 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1865 if (scr_page (upordown < 0 ? UP : DN, 1))
1877 switch (scrollbar_align)
1879 case R_SB_ALIGN_TOP:
1882 case R_SB_ALIGN_CENTRE:
1883 csrO = (scrollBar.bot - scrollBar.top) / 2;
1885 case R_SB_ALIGN_BOTTOM:
1886 csrO = scrollBar.bot - scrollBar.top;
1890 if (scrollBar.style == R_SB_XTERM
1891 || scrollbar_above_slider (ev.y)
1892 || scrollbar_below_slider (ev.y))
1893 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
1895 scrollBar.setMotion ();
1899 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1900 csrO = ev.y - scrollBar.top;
1904 if (scrollBar.style != R_SB_XTERM)
1906 if (scrollbar_above_slider (ev.y))
1907 # ifdef RXVT_SCROLL_FULL
1908 scr_page (UP, TermWin.nrow - 1);
1910 scr_page (UP, TermWin.nrow / 4);
1912 else if (scrollbar_below_slider (ev.y))
1913 # ifdef RXVT_SCROLL_FULL
1914 scr_page (DN, TermWin.nrow - 1);
1916 scr_page (DN, TermWin.nrow / 4);
1919 scrollBar.setMotion ();
1923 scr_page ((ev.button == Button1 ? DN : UP),
1925 * scrollbar_position (ev.y)
1926 / scrollbar_size ()));
1936 * Menubar window processing of button press
1938 if (isMenuBarWindow (ev.window))
1939 menubar_control (ev);
1944 rxvt_term::button_release (XButtonEvent &ev)
1948 csrO = 0; /* reset csr Offset */
1949 if (!bypass_keystate)
1950 reportmode = !! (priv_modes & PrivMode_mouse_report);
1952 if (scrollbar_isUpDn ())
1954 scrollBar.setIdle ();
1956 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1957 refresh_type &= ~SMOOTH_REFRESH;
1961 #ifdef SELECTION_SCROLLING
1962 if (sel_scroll_ev.active)
1963 sel_scroll_ev.stop();
1966 if (ev.window == TermWin.vt)
1970 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1975 /* mouse report from vt window */
1976 /* don't report release of wheel "buttons" */
1979 #ifdef MOUSE_REPORT_DOUBLECLICK
1980 /* only report the release of 'slow' single clicks */
1981 if (MEvent.button != AnyButton
1982 && (ev.button != MEvent.button
1983 || (ev.time - MEvent.time
1984 > MULTICLICK_TIME / 2)))
1987 MEvent.button = AnyButton;
1990 #else /* MOUSE_REPORT_DOUBLECLICK */
1991 MEvent.button = AnyButton;
1993 #endif /* MOUSE_REPORT_DOUBLECLICK */
1998 * dumb hack to compensate for the failure of click-and-drag
1999 * when overriding mouse reporting
2001 if (priv_modes & PrivMode_mouse_report
2003 && ev.button == Button1 && MEvent.clicks <= 1)
2004 selection_extend (ev.x, ev.y, 0);
2010 selection_make (ev.time);
2013 selection_request (ev.time, ev.x, ev.y);
2022 v = ev.button == Button4 ? UP : DN;
2024 if (ev.state & ShiftMask)
2026 else if (options & Opt_mouseWheelScrollPage)
2027 i = TermWin.nrow - 1;
2031 # ifdef MOUSE_SLIP_WHEELING
2032 if (ev.state & ControlMask)
2034 mouse_slip_wheel_speed += v ? -1 : 1;
2035 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow;
2036 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2038 if (slip_wheel_ev.at < NOW)
2039 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2041 slip_wheel_ev.start ();
2046 # ifdef JUMP_MOUSE_WHEEL
2048 scr_refresh (SMOOTH_REFRESH);
2054 scr_refresh (SMOOTH_REFRESH);
2058 # ifdef MOUSE_SLIP_WHEELING
2067 else if (isMenuBarWindow (ev.window))
2068 menubar_control (ev);
2074 /* taken from aterm-0.4.2 */
2076 typedef uint32_t RUINT32T;
2078 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2080 int sh_r, sh_g, sh_b;
2081 RUINT32T mask_r, mask_g, mask_b;
2082 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2083 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2084 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2087 Visual *visual = display->visual;
2089 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2091 /* for convenience */
2092 mask_r = visual->red_mask;
2093 mask_g = visual->green_mask;
2094 mask_b = visual->blue_mask;
2096 /* boring lookup table pre-initialization */
2097 switch (srcImage->bits_per_pixel) {
2099 if ((mask_r != 0x7c00) ||
2100 (mask_g != 0x03e0) ||
2103 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2105 lookup_g = lookup+32;
2106 lookup_b = lookup+32+32;
2112 if ((mask_r != 0xf800) ||
2113 (mask_g != 0x07e0) ||
2116 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2118 lookup_g = lookup+32;
2119 lookup_b = lookup+32+64;
2125 if ((mask_r != 0xff0000) ||
2126 (mask_g != 0x00ff00) ||
2127 (mask_b != 0x0000ff))
2129 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2131 lookup_g = lookup+256;
2132 lookup_b = lookup+256+256;
2138 if ((mask_r != 0xff0000) ||
2139 (mask_g != 0x00ff00) ||
2140 (mask_b != 0x0000ff))
2142 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2144 lookup_g = lookup+256;
2145 lookup_b = lookup+256+256;
2151 return; /* we do not support this color depth */
2154 /* prepare limits for color transformation (each channel is handled separately) */
2157 if (shade < 0) shade = 0;
2158 if (shade > 100) shade = 100;
2160 lower_lim_r = 65535-rm;
2161 lower_lim_g = 65535-gm;
2162 lower_lim_b = 65535-bm;
2164 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2165 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2166 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2168 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2170 if (shade < 0) shade = 0;
2171 if (shade > 100) shade = 100;
2173 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2175 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2176 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2177 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2180 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2181 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2186 lower_lim_r = lower_lim_b;
2190 upper_lim_r = upper_lim_b;
2194 /* fill our lookup tables */
2195 for (i = 0; i <= mask_r>>sh_r; i++)
2198 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2199 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2200 lookup_r[i] = (tmp/65535)<<sh_r;
2202 for (i = 0; i <= mask_g>>sh_g; i++)
2205 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2206 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2207 lookup_g[i] = (tmp/65535)<<sh_g;
2209 for (i = 0; i <= mask_b>>sh_b; i++)
2212 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2213 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2214 lookup_b[i] = (tmp/65535)<<sh_b;
2217 /* apply table to input image (replacing colors by newly calculated ones) */
2218 switch (srcImage->bits_per_pixel)
2222 unsigned short *p1, *pf, *p, *pl;
2223 p1 = (unsigned short *) srcImage->data;
2224 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2228 pl = p1 + srcImage->width;
2231 *p = lookup_r[(*p & 0x7c00)>>10] |
2232 lookup_g[(*p & 0x03e0)>> 5] |
2233 lookup_b[(*p & 0x001f)];
2235 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2241 unsigned short *p1, *pf, *p, *pl;
2242 p1 = (unsigned short *) srcImage->data;
2243 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2247 pl = p1 + srcImage->width;
2250 *p = lookup_r[(*p & 0xf800)>>11] |
2251 lookup_g[(*p & 0x07e0)>> 5] |
2252 lookup_b[(*p & 0x001f)];
2254 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2260 unsigned char *p1, *pf, *p, *pl;
2261 p1 = (unsigned char *) srcImage->data;
2262 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2266 pl = p1 + srcImage->width * 3;
2267 for (; p < pl; p += 3)
2269 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2270 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2271 p[2] = lookup_r[(p[2] & 0x0000ff)];
2273 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2279 RUINT32T *p1, *pf, *p, *pl;
2280 p1 = (RUINT32T *) srcImage->data;
2281 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2286 pl = p1 + srcImage->width;
2289 *p = lookup_r[(*p & 0xff0000)>>16] |
2290 lookup_g[(*p & 0x00ff00)>> 8] |
2291 lookup_b[(*p & 0x0000ff)] |
2294 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2305 * Check our parents are still who we think they are.
2306 * Do transparency updates if required
2309 rxvt_term::check_our_parents ()
2311 int i, pchanged, aformat, have_pixmap, rootdepth;
2312 unsigned long nitems, bytes_after;
2314 unsigned char *prop = NULL;
2315 Window root, oldp, *list;
2316 Pixmap rootpixmap = None;
2317 XWindowAttributes wattr, wrootattr;
2322 if (!(options & Opt_transparent))
2323 return pchanged; /* Don't try any more */
2325 XGetWindowAttributes (disp, display->root, &wrootattr);
2326 rootdepth = wrootattr.depth;
2328 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2330 if (rootdepth != wattr.depth)
2335 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2336 am_transparent = am_pixmap_trans = 0;
2339 return pchanged; /* Don't try any more */
2342 /* Get all X ops out of the queue so that our information is up-to-date. */
2343 XSync (disp, False);
2346 * Make the frame window set by the window manager have
2347 * the root background. Some window managers put multiple nested frame
2348 * windows for each client, so we have to take care about that.
2350 i = (xa[XA_XROOTPMAP_ID]
2351 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2352 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2353 &nitems, &bytes_after, &prop) == Success);
2355 if (!i || prop == NULL)
2356 i = (xa[XA_ESETROOT_PMAP_ID]
2357 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2358 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2359 &nitems, &bytes_after, &prop) == Success);
2361 if (!i || prop == NULL
2363 || !rs[Rs_color + Color_tint]
2370 rootpixmap = *(Pixmap *)prop;
2377 * Copy display->root pixmap transparency
2380 unsigned int nw, nh;
2386 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2387 0, 0, &sx, &sy, &cr);
2388 nw = (unsigned int)szHint.width;
2389 nh = (unsigned int)szHint.height;
2406 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2407 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2409 XSync (disp, False);
2411 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2413 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2414 /* XXX: may need a delay here? */
2419 if (am_transparent && am_pixmap_trans)
2422 if (TermWin.pixmap != None)
2424 XFreePixmap (disp, TermWin.pixmap);
2425 TermWin.pixmap = None;
2429 am_pixmap_trans = 0;
2433 if (TermWin.pixmap != None)
2434 XFreePixmap (disp, TermWin.pixmap);
2437 if (ISSET_PIXCOLOR (Color_tint))
2439 unsigned short rm, gm, bm;
2440 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2442 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2444 ShadeXImage (display, image, shade, rm, gm, bm);
2448 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2449 szHint.width, szHint.height, image->depth);
2450 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2451 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2452 nx, ny, image->width, image->height);
2454 XDestroyImage (image);
2455 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2456 XClearWindow (disp, TermWin.parent[0]);
2458 if (!am_transparent || !am_pixmap_trans)
2461 am_transparent = am_pixmap_trans = 1;
2465 if (am_pixmap_trans)
2466 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2471 * InheritPixmap transparency
2473 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2475 oldp = TermWin.parent[i];
2476 XQueryTree (disp, TermWin.parent[i - 1], &root,
2477 &TermWin.parent[i], &list, &n);
2480 if (TermWin.parent[i] == display->root)
2488 if (oldp != TermWin.parent[i])
2496 for (; n < (unsigned int)i; n++)
2498 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2499 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2501 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2507 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2509 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2510 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2512 /* XXX: also turn off Opt_transparent? */
2517 /* wait (an arbitrary period) for the WM to do its thing
2518 * needed for fvwm2.2.2 (and before?) */
2521 for (n = 0; n < (unsigned int)i; n++)
2523 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2524 XClearWindow (disp, TermWin.parent[n]);
2527 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2531 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2532 TermWin.parent[i] = None;
2537 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2538 scrollBar.setIdle ();
2544 want_refresh = want_full_refresh = 1;
2545 if (am_pixmap_trans)
2556 rxvt_term::cmd_parse ()
2559 unicode_t ch = NOCHAR;
2560 unsigned char *seq_begin; // remember start of esc-sequence here
2566 seq_begin = cmdbuf_ptr;
2570 if (ch == NOCHAR) // TODO: improve
2573 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2578 // many badly-written programs (e.g. jed) contain a race condition:
2579 // they first read the screensize and then install a SIGWINCH handler.
2580 // some window managers resize the window early, and these programs
2581 // then sometimes get the size wrong.
2582 // unfortunately other programs are even more buggy and dislike
2583 // being sent SIGWINCH, so only do it when we were in fact being
2586 kill (-cmd_pid, SIGWINCH);
2589 /* Read a text string from the input buffer */
2590 unicode_t buf[UBUFSIZ];
2591 bool refreshnow = false;
2593 unicode_t *str = buf;
2597 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2607 if (!(options & Opt_jumpScroll)
2608 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2615 // scr_add_lines only works for nlines <= TermWin.nrow - 1.
2616 if (nlines >= TermWin.nrow - 1)
2618 scr_add_lines (buf, nlines, str - buf);
2624 if (str >= buf + UBUFSIZ)
2630 seq_begin = cmdbuf_ptr;
2634 scr_add_lines (buf, nlines, str - buf);
2637 * If there have been a lot of new lines, then update the screen
2638 * What the heck I'll cheat and only refresh less than every page-full.
2639 * the number of pages between refreshes is refresh_limit, which
2640 * is incremented here because we must be doing flat-out scrolling.
2644 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2649 scr_refresh (refresh_type);
2658 process_nonprinting (ch);
2660 catch (const class out_of_input &o)
2662 // we ran out of input, retry later
2663 cmdbuf_ptr = seq_begin;
2674 // read the next octet
2676 rxvt_term::next_octet ()
2678 return cmdbuf_ptr < cmdbuf_endp
2683 // read the next character
2685 rxvt_term::next_char ()
2687 while (cmdbuf_ptr < cmdbuf_endp)
2689 // assume 7-bit to be ascii ALWAYS
2690 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2691 return *cmdbuf_ptr++;
2694 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2696 if (len == (size_t)-2)
2698 // the mbstate stores incomplete sequences. didn't know this :/
2699 cmdbuf_ptr = cmdbuf_endp;
2703 if (len == (size_t)-1)
2704 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2706 // assume wchar == unicode
2708 return wc & UNICODE_MASK;
2714 /* rxvt_cmd_getc () - Return next input character */
2716 * Return the next input character after first passing any keyboard input
2720 rxvt_term::cmd_getc ()
2722 unicode_t c = next_char ();
2731 rxvt_term::cmd_get8 ()
2733 unicode_t c = next_octet ();
2742 /*----------------------------------------------------------------------*/
2745 rxvt_term::popen_printer ()
2747 FILE *stream = popen (rs[Rs_print_pipe], "w");
2750 rxvt_warn ("can't open printer pipe, not printing.\n");
2756 rxvt_term::pclose_printer (FILE *stream)
2759 return pclose (stream);
2763 * simulate attached vt100 printer
2766 rxvt_term::process_print_pipe ()
2771 if ((fd = popen_printer ()) == NULL)
2775 * Send all input to the printer until either ESC[4i or ESC[?4i
2778 for (done = 0; !done;)
2780 unsigned char buf[8];
2782 unsigned int i, len;
2784 if ((ch = cmd_getc ()) != C0_ESC)
2786 if (putc (ch, fd) == EOF)
2787 break; /* done = 1 */
2794 if ((buf[len++] = cmd_getc ()) == '[')
2796 if ((ch = cmd_getc ()) == '?')
2801 if ((buf[len++] = ch) == '4')
2803 if ((buf[len++] = cmd_getc ()) == 'i')
2804 break; /* done = 1 */
2808 for (i = 0; i < len; i++)
2809 if (putc (buf[i], fd) == EOF)
2817 pclose_printer (fd);
2819 #endif /* PRINTPIPE */
2825 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2826 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2827 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2828 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2832 /*{{{ process non-printing single characters */
2834 rxvt_term::process_nonprinting (unicode_t ch)
2839 process_escape_seq ();
2841 case C0_ENQ: /* terminal Status */
2842 if (rs[Rs_answerbackstring])
2843 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2844 (unsigned int)strlen (rs[Rs_answerbackstring]));
2846 tt_write ((unsigned char *)VT100_ANS,
2847 (unsigned int)strlen (VT100_ANS));
2849 case C0_BEL: /* bell */
2852 case C0_BS: /* backspace */
2855 case C0_HT: /* tab */
2858 case C0_CR: /* carriage return */
2859 scr_gotorc (0, 0, R_RELATIVE);
2861 case C0_VT: /* vertical tab, form feed */
2863 case C0_LF: /* line feed */
2866 case C0_SO: /* shift out - acs */
2867 scr_charset_choose (1);
2869 case C0_SI: /* shift in - acs */
2870 scr_charset_choose (0);
2873 #ifdef EIGHT_BIT_CONTROLS
2875 case 0x90: /* DCS */
2878 case 0x9b: /* CSI */
2881 case 0x9d: /* CSI */
2890 /*{{{ process VT52 escape sequences */
2892 rxvt_term::process_escape_vt52 (unicode_t ch)
2898 case 'A': /* cursor up */
2899 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2901 case 'B': /* cursor down */
2902 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2904 case 'C': /* cursor right */
2905 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2907 case 'D': /* cursor left */
2908 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2910 case 'H': /* cursor home */
2911 scr_gotorc (0, 0, 0);
2913 case 'I': /* cursor up and scroll down if needed */
2916 case 'J': /* erase to end of screen */
2917 scr_erase_screen (0);
2919 case 'K': /* erase to end of line */
2922 case 'Y': /* move to specified row and col */
2923 /* full command is 'ESC Y row col' where row and col
2924 * are encoded by adding 32 and sending the ascii
2925 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2927 row = cmd_getc () - ' ';
2928 col = cmd_getc () - ' ';
2929 scr_gotorc (row, col, 0);
2931 case 'Z': /* identify the terminal type */
2932 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2934 case '<': /* turn off VT52 mode */
2935 PrivMode (0, PrivMode_vt52);
2937 case 'F': /* use special graphics character set */
2938 case 'G': /* use regular character set */
2941 case '=': /* use alternate keypad mode */
2942 case '>': /* use regular keypad mode */
2950 /*{{{ process escape sequences */
2952 rxvt_term::process_escape_seq ()
2954 unicode_t ch = cmd_getc ();
2956 if (priv_modes & PrivMode_vt52)
2958 process_escape_vt52 (ch);
2964 /* case 1: do_tek_mode (); break; */
2966 if (cmd_getc () == '8')
2970 scr_charset_set (0, (unsigned int)cmd_getc ());
2973 scr_charset_set (1, (unsigned int)cmd_getc ());
2976 scr_charset_set (2, (unsigned int)cmd_getc ());
2979 scr_charset_set (3, (unsigned int)cmd_getc ());
2990 scr_cursor (RESTORE);
2994 scr_forwardindex ();
2999 PrivMode ((ch == '='), PrivMode_aplKP);
3009 /* 8.3.87: NEXT LINE */
3010 case C1_NEL: /* ESC E */
3012 unicode_t nlcr[] = { C0_LF, C0_CR };
3013 scr_add_lines (nlcr, 1, 2);
3017 /* kidnapped escape sequence: Should be 8.3.48 */
3018 case C1_ESA: /* ESC G */
3019 process_graphics ();
3022 /* 8.3.63: CHARACTER TABULATION SET */
3023 case C1_HTS: /* ESC H */
3027 /* 8.3.105: REVERSE LINE FEED */
3028 case C1_RI: /* ESC M */
3032 /* 8.3.142: SINGLE-SHIFT TWO */
3033 /*case C1_SS2: scr_single_shift (2); break; */
3035 /* 8.3.143: SINGLE-SHIFT THREE */
3036 /*case C1_SS3: scr_single_shift (3); break; */
3038 /* 8.3.27: DEVICE CONTROL STRING */
3039 case C1_DCS: /* ESC P */
3043 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3044 case C1_SCI: /* ESC Z */
3045 tt_write ((const unsigned char *)ESCZ_ANSWER,
3046 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3047 break; /* steal obsolete ESC [ c */
3049 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3050 case C1_CSI: /* ESC [ */
3054 /* 8.3.90: OPERATING SYSTEM COMMAND */
3055 case C1_OSC: /* ESC ] */
3059 /* 8.3.106: RESET TO INITIAL STATE */
3066 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3068 scr_charset_choose (2);
3071 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3073 scr_charset_choose (3);
3079 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3083 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3084 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3085 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3086 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3087 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3088 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3089 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3090 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3093 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3094 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3095 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3096 #define get_byte_array_bit(array, bit) \
3097 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3099 const unsigned char csi_defaults[] =
3101 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3102 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3103 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3104 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3105 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3106 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3107 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3108 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3113 rxvt_term::process_csi_seq ()
3115 unicode_t ch, priv, i;
3116 unsigned int nargs, p;
3120 for (nargs = ESC_ARGS; nargs > 0;)
3125 if (ch >= '<' && ch <= '?')
3126 { /* '<' '=' '>' '?' */
3131 /* read any numerical arguments */
3132 for (n = -1; ch < CSI_ICH; )
3139 n = n * 10 + ch - '0';
3143 if (nargs < ESC_ARGS)
3147 else if (IS_CONTROL (ch))
3148 process_nonprinting (ch);
3156 if (nargs < ESC_ARGS)
3160 ndef = get_byte_array_bit (csi_defaults, i);
3161 for (p = 0; p < nargs; p++)
3166 fprintf (stderr, "CSI ");
3167 for (p = 0; p < nargs; p++)
3168 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3169 fprintf (stderr, "%c\n", ch);
3173 * private mode handling
3180 if (ch == CSI_DA) /* secondary device attributes */
3181 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING);
3184 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3185 process_terminal_mode (ch, priv, nargs, arg);
3194 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3197 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3200 case 0: /* initiate transfer to primary aux device */
3201 scr_printscreen (0);
3203 case 5: /* start relay to primary aux device */
3204 process_print_pipe ();
3210 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3211 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3214 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3215 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3216 scr_gotorc (arg[0], 0, RELATIVE);
3219 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3220 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3223 #else /* emulate common DEC VTs */
3224 arg[0] = arg[0] ? -arg[0] : -1;
3227 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3228 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3230 scr_gotorc (0, arg[0], RELATIVE);
3231 #else /* emulate common DEC VTs */
3232 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3236 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3239 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3240 scr_gotorc (arg[0], 0, R_RELATIVE);
3243 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3244 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3245 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3248 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3249 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3252 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3253 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3254 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3257 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3260 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3264 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3265 scr_erase_screen (arg[0]);
3268 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3269 scr_erase_line (arg[0]);
3272 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3273 scr_insdel_chars (arg[0], INSERT);
3276 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3277 scr_insdel_lines (arg[0], INSERT);
3280 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3281 scr_insdel_lines (arg[0], DELETE);
3284 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3285 scr_insdel_chars (arg[0], ERASE);
3288 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3289 scr_insdel_chars (arg[0], DELETE);
3292 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3295 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3296 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
3299 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3300 tt_write ((const unsigned char *)VT100_ANS,
3301 (unsigned int) (sizeof (VT100_ANS) - 1));
3304 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3305 process_sgr_mode (nargs, arg);
3308 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3311 case 5: /* DSR requested */
3312 tt_printf ("\033[0n");
3314 case 6: /* CPR requested */
3315 scr_report_position ();
3317 case 7: /* unofficial extension */
3318 if (options & Opt_insecure)
3319 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3321 case 8: /* unofficial extension */
3322 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3327 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3330 case 0: /* char tab stop cleared at active position */
3333 /* case 1: */ /* line tab stop cleared in active line */
3334 /* case 2: */ /* char tab stops cleared in active line */
3335 case 3: /* all char tab stops are cleared */
3336 /* case 4: */ /* all line tab stops are cleared */
3337 case 5: /* all tab stops are cleared */
3343 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3346 case 0: /* char tab stop set at active position */
3348 break; /* = ESC H */
3349 /* case 1: */ /* line tab stop set at active line */
3350 case 2: /* char tab stop cleared at active position */
3352 break; /* = ESC [ 0 g */
3353 /* case 3: */ /* line tab stop cleared at active line */
3354 /* case 4: */ /* char tab stops cleared at active line */
3355 case 5: /* all char tab stops are cleared */
3357 break; /* = ESC [ 3 g */
3358 /* case 6: */ /* all line tab stops are cleared */
3362 case CSI_RM: /* 8.3.107: RESET MODE */
3364 scr_insert_mode (0);
3365 else if (arg[0] == 20)
3366 priv_modes &= ~PrivMode_LFNL;
3369 case CSI_SM: /* 8.3.126: SET MODE */
3371 scr_insert_mode (1);
3372 else if (arg[0] == 20)
3373 priv_modes |= PrivMode_LFNL;
3377 * PRIVATE USE beyond this point. All CSI_7? sequences here
3379 case CSI_72: /* DECSTBM: set top and bottom margins */
3381 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3382 else if (nargs == 0 || arg[0] >= arg[1])
3383 scr_scroll_region (0, MAX_ROWS - 1);
3385 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3392 scr_cursor (RESTORE);
3397 process_window_ops (arg, nargs);
3401 case CSI_78: /* DECREQTPARM */
3402 if (arg[0] == 0 || arg[0] == 1)
3403 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3415 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3418 XWindowAttributes wattr;
3430 case 1: /* deiconify window */
3431 XMapWindow (disp, TermWin.parent[0]);
3433 case 2: /* iconify window */
3434 XIconifyWindow (disp, TermWin.parent[0], display->screen);
3436 case 3: /* set position (pixels) */
3437 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]);
3439 case 4: /* set size (pixels) */
3440 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3442 case 5: /* raise window */
3443 XRaiseWindow (disp, TermWin.parent[0]);
3445 case 6: /* lower window */
3446 XLowerWindow (disp, TermWin.parent[0]);
3448 case 7: /* refresh window */
3451 case 8: /* set size (chars) */
3452 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
3453 (unsigned int) (args[1] * TermWin.fheight));
3456 //case 9: NYI, TODO, restore maximized window or maximize window
3458 if (args[0] >= 24) /* set height (chars) */
3459 set_widthheight ((unsigned int)TermWin.width,
3460 (unsigned int) (args[1] * TermWin.fheight));
3465 * reports - some output format copied from XTerm
3467 case 11: /* report window state */
3468 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3469 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3471 case 13: /* report window position */
3472 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3473 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root,
3474 -wattr.border_width, -wattr.border_width,
3476 tt_printf ("\033[3;%d;%dt", x, y);
3478 case 14: /* report window size (pixels) */
3479 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3480 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3482 case 18: /* report text area size (chars) */
3483 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3485 case 19: /* report window size (chars) */
3486 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3488 case 20: /* report icon label */
3491 XGetIconName (disp, TermWin.parent[0], &s);
3492 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3496 case 21: /* report window title */
3499 XFetchName (disp, TermWin.parent[0], &s);
3500 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3508 /*----------------------------------------------------------------------*/
3510 * get input up until STRING TERMINATOR (or BEL)
3511 * ends_how is terminator used. returned input must be free()'d
3514 rxvt_term::get_to_st (unicode_t &ends_how)
3517 bool seen_esc = false;
3519 wchar_t string[STRING_MAX];
3521 while ((ch = cmd_getc ()) != NOCHAR)
3525 if (ch == 0x5c) /* 7bit ST */
3530 else if (ch == C0_ESC)
3535 else if (ch == C0_BEL || ch == CHAR_ST)
3538 return NULL; /* other control character - exit */
3542 if (n >= sizeof (string) - 1)
3543 // stop at some sane length
3547 string[n++] = cmd_get8 ();
3554 ends_how = (ch == 0x5c ? C0_ESC : ch);
3556 return (unsigned char *)rxvt_wcstombs (string);
3559 /*----------------------------------------------------------------------*/
3561 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3564 rxvt_term::process_dcs_seq ()
3579 /*----------------------------------------------------------------------*/
3581 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3584 rxvt_term::process_osc_seq ()
3590 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3591 arg = arg * 10 + (ch - '0');
3595 unsigned char *s = get_to_st (eh);
3599 process_xterm_seq (arg, (char *)s, eh);
3606 rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3608 if (str[0] == '?' && !str[1])
3610 unsigned short r, g, b;
3611 pix_colors_focused[color].get (display, r, g, b);
3612 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3615 set_window_color (color, str);
3619 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3620 * 0 = change iconName/title
3621 * 1 = change iconName
3624 * 10 = change fg color
3625 * 11 = change bg color
3626 * 12 = change text color
3627 * 13 = change mouse foreground color
3628 * 17 = change highlight character colour
3629 * 18 = change bold character color
3630 * 19 = change underlined character color
3631 * 46 = change logfile (not implemented)
3636 * 39 = change default fg color
3637 * 49 = change default bg color
3638 * 55 = dump scrollback buffer and all of screen
3639 * 701 = change locale
3644 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3649 bool query = str[0] == '?' && !str[1];
3653 assert (str != NULL);
3659 case XTerm_iconName:
3660 set_icon_name (str);
3665 case XTerm_property:
3668 Atom prop = display->atom (str + 1);
3671 unsigned long nitems;
3672 unsigned long bytes_after;
3673 unsigned char *value = 0;
3674 const char *str = "";
3677 && XGetWindowProperty (disp, TermWin.parent[0],
3678 prop, 0, 1<<16, 0, AnyPropertyType,
3679 &actual_type, &actual_format,
3680 &nitems, &bytes_after, &value) == Success
3681 && actual_type != None
3682 && actual_format == 8)
3683 str = (const char *)(value);
3685 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3691 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3696 set_utf8_property (display->atom (str), eq + 1);
3699 XDeleteProperty (disp, TermWin.parent[0],
3700 display->atom (str));
3705 for (buf = (char *)str; buf && *buf;)
3707 if ((name = strchr (buf, ';')) == NULL)
3713 if (color < 0 || color >= TOTAL_COLORS)
3716 if ((buf = strchr (name, ';')) != NULL)
3719 if (name[0] == '?' && !name[1])
3721 unsigned short r, g, b;
3722 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3723 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3726 set_window_color (color + minCOLOR, name);
3730 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3733 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3735 #ifndef NO_CURSORCOLOR
3736 case XTerm_Color_cursor:
3737 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3740 case XTerm_Color_pointer_fg:
3741 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3743 case XTerm_Color_pointer_bg:
3744 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3746 #ifndef NO_BOLD_UNDERLINE_REVERSE
3747 case XTerm_Color_BD:
3748 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3750 case XTerm_Color_IT:
3751 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3753 case XTerm_Color_UL:
3754 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3756 case XTerm_Color_RV:
3757 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3760 #if TRANSPARENT && TINTING
3761 case XTerm_Color_tint:
3762 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3763 check_our_parents ();
3765 want_full_refresh = want_refresh = 1;
3773 scale_pixmap (""); /* reset to default scaling */
3774 set_bgPixmap (str); /* change pixmap */
3778 while ((str = strchr (str, ';')) != NULL)
3782 changed += scale_pixmap (str);
3788 #ifdef XPM_BACKGROUND
3795 case XTerm_restoreFG:
3796 set_window_color (Color_fg, str);
3798 case XTerm_restoreBG:
3799 set_window_color (Color_bg, str);
3803 // TODO, when secure mode?
3810 case URxvt_boldFont:
3811 case URxvt_italicFont:
3812 case URxvt_boldItalicFont:
3815 tt_printf ("\33]%d;%-.250s%c", saveop,
3816 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc
3817 ? TermWin.fontset[op - URxvt_font]->fontdesc : "",
3821 const char *&res = rs[Rs_font + (op - URxvt_font)];
3824 allocated.push_back ((void *)res);
3832 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3836 pty.set_utf8_mode (enc_utf8);
3846 if (options & Opt_insecure)
3847 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3851 case XTerm_dumpscreen: /* no error notices */
3854 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3864 /*----------------------------------------------------------------------*/
3866 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3868 * mode can only have the following values:
3874 * so no need for fancy checking
3877 rxvt_term::privcases (int mode, unsigned long bit)
3883 SavedModes |= (priv_modes & bit);
3889 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3891 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3892 PrivMode (state, bit);
3898 /* we're not using priv _yet_ */
3900 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3908 const unsigned long bit;
3912 { 1, PrivMode_aplCUR },
3913 { 2, PrivMode_vt52 },
3914 { 3, PrivMode_132 },
3915 { 4, PrivMode_smoothScroll },
3916 { 5, PrivMode_rVideo },
3917 { 6, PrivMode_relOrigin },
3918 { 7, PrivMode_Autowrap },
3919 // 8, bi-directional support mode
3920 { 9, PrivMode_MouseX10 },
3922 { menuBar_esc, PrivMode_menuBar },
3924 // 18, 19 printing-related
3925 { 25, PrivMode_VisibleCursor },
3926 #ifdef scrollBar_esc
3927 { scrollBar_esc, PrivMode_scrollBar },
3929 { 35, PrivMode_ShiftKeys }, // rxvt extension
3930 { 40, PrivMode_132OK },
3931 // 41 xterm more fixes NYI
3932 // 45 margin bell NYI
3934 { 47, PrivMode_Screen },
3935 { 66, PrivMode_aplKP },
3936 #ifndef NO_BACKSPACE_KEY
3937 { 67, PrivMode_BackSpace },
3939 { 1000, PrivMode_MouseX11 },
3940 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3941 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3942 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3943 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3944 { 1011, PrivMode_Keypress }, // rxvt extension
3945 // 1035 enable modifiers for alt, numlock NYI
3946 // 1036 send ESC for meta keys NYI
3947 // 1037 send DEL for keypad delete NYI
3948 { 1047, PrivMode_Screen },
3949 // 1048 save and restore cursor
3950 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3951 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3957 /* make lo/hi boolean */
3959 mode = 0; /* reset */
3960 else if (mode == 'h')
3963 for (i = 0; i < nargs; i++)
3967 /* basic handling */
3968 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
3969 if (argtopriv[j].argval == arg[i])
3971 state = privcases (mode, argtopriv[j].bit);
3975 /* extra handling for values with state unkept */
3978 case 1048: /* alternative cursor save */
3980 if (options & Opt_secondaryScreen)
3982 scr_cursor (RESTORE);
3989 /* extra handling for values with valid 0 or 1 state */
3992 /* case 1: - application cursor keys */
3993 case 2: /* VT52 mode */
3994 /* oddball mode. should be set regardless of set/reset
3995 * parameter. Return from VT52 mode with an ESC < from
3998 PrivMode (1, PrivMode_vt52);
4000 case 3: /* 80/132 */
4001 if (priv_modes & PrivMode_132OK)
4002 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
4004 case 4: /* smooth scrolling */
4006 options &= ~Opt_jumpScroll;
4008 options |= Opt_jumpScroll;
4010 case 5: /* reverse video */
4011 scr_rvideo_mode (state);
4013 case 6: /* relative/absolute origins */
4014 scr_relative_origin (state);
4016 case 7: /* autowrap */
4017 scr_autowrap (state);
4019 /* case 8: - auto repeat, can't do on a per window basis */
4020 case 9: /* X10 mouse reporting */
4021 if (state) /* orthogonal */
4022 priv_modes &= ~PrivMode_MouseX11;
4027 map_menuBar (state);
4031 #ifdef scrollBar_esc
4033 if (scrollbar_mapping (state))
4035 resize_all_windows (0, 0, 0);
4040 case 25: /* visible/invisible cursor */
4041 scr_cursor_visible (state);
4043 /* case 35: - shift keys */
4044 /* case 40: - 80 <--> 132 mode */
4045 case 47: /* secondary screen */
4046 scr_change_screen (state);
4048 /* case 66: - application key pad */
4049 /* case 67: - backspace key */
4050 case 1000: /* X11 mouse reporting */
4051 if (state) /* orthogonal */
4052 priv_modes &= ~PrivMode_MouseX10;
4056 break; /* X11 mouse highlighting */
4058 case 1010: /* scroll to bottom on TTY output inhibit */
4060 options &= ~Opt_scrollTtyOutput;
4062 options |= Opt_scrollTtyOutput;
4064 case 1011: /* scroll to bottom on key press */
4066 options |= Opt_scrollTtyKeypress;
4068 options &= ~Opt_scrollTtyKeypress;
4070 case 1047: /* secondary screen w/ clearing last */
4071 if (options & Opt_secondaryScreen)
4072 if (current_screen != PRIMARY)
4073 scr_erase_screen (2);
4074 scr_change_screen (state);
4076 case 1049: /* secondary screen w/ clearing first */
4077 scr_change_screen (state);
4078 if (options & Opt_secondaryScreen)
4079 if (current_screen != PRIMARY)
4080 scr_erase_screen (2);
4089 /*{{{ process sgr sequences */
4091 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4099 scr_rendition (0, ~RS_None);
4103 for (i = 0; i < nargs; i++)
4109 rendset = 0, rendstyle = ~RS_None;
4112 rendset = 1, rendstyle = RS_Bold;
4114 //case 2: // low intensity
4116 rendset = 1, rendstyle = RS_Italic;
4119 rendset = 1, rendstyle = RS_Uline;
4121 case 5: // slowly blinking
4122 case 6: // rapidly blinking
4123 rendset = 1, rendstyle = RS_Blink;
4125 //case 6: // scoansi light background
4127 rendset = 1, rendstyle = RS_RVid;
4132 //case 9: // crossed out
4133 //case 10: // scoansi acs off, primary font
4134 //case 11: // scoansi acs on, first alt font
4135 //case 12: // scoansi acs on, |0x80, second alt font
4137 //case 19: // ninth alt font
4138 //case 20: // gothic
4139 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4140 rendset = 0, rendstyle = RS_Bold;
4142 case 22: // normal intensity
4143 rendset = 0, rendstyle = RS_Bold;
4145 case 23: // disable italic
4146 rendset = 0, rendstyle = RS_Italic;
4149 rendset = 0, rendstyle = RS_Uline;
4152 rendset = 0, rendstyle = RS_Blink;
4154 case 26: // variable spacing (iso 8613)
4155 rendset = 0, rendstyle = RS_Blink;
4158 rendset = 0, rendstyle = RS_RVid;
4160 //case 28: // visible. NYI
4161 //case 29: // not crossed-out
4166 scr_rendition (rendset, rendstyle);
4167 continue; /* for (;i;) */
4173 case 31: /* set fg color */
4180 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4182 case 38: // set fg color, ISO 8613-6
4183 if (nargs > i + 2 && arg[i + 1] == 5)
4185 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4189 case 39: /* default fg */
4190 scr_color (Color_fg, Color_fg);
4194 case 41: /* set bg color */
4201 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4203 case 48: // set bg color, ISO 8613-6
4204 if (nargs > i + 2 && arg[i + 1] == 5)
4206 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4210 case 49: /* default bg */
4211 scr_color (Color_bg, Color_bg);
4214 //case 50: // not variable spacing
4216 #ifndef NO_BRIGHTCOLOR
4218 case 91: /* set bright fg color */
4225 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4228 case 101: /* set bright bg color */
4235 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4244 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4246 rxvt_term::process_graphics ()
4248 unicode_t ch, cmd = cmd_getc ();
4251 { /* query graphics */
4252 tt_printf ("\033G0\012"); /* no graphics */
4255 /* swallow other graphics sequences until terminating ':' */
4262 /* ------------------------------------------------------------------------- */
4265 * Send printf () formatted output to the command.
4266 * Only use for small amounts of data.
4269 rxvt_term::tt_printf (const char *fmt,...)
4272 unsigned char buf[256];
4274 va_start (arg_ptr, fmt);
4275 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4277 tt_write (buf, strlen (buf));
4280 /* ---------------------------------------------------------------------- */
4281 /* Write data to the pty as typed by the user, pasted with the mouse,
4282 * or generated by us in response to a query ESC sequence.
4284 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4287 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4291 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4293 if ((unsigned int)written == len)
4300 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4302 memcpy (v_buffer + v_buflen, data, len);
4305 pty_ev.set (EVENT_READ | EVENT_WRITE);
4308 void rxvt_term::pty_write ()
4310 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4314 v_buflen -= written;
4322 pty_ev.set (EVENT_READ);
4326 memmove (v_buffer, v_buffer + written, v_buflen);
4328 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4329 // original code just ignores this...
4333 /*----------------------- end-of-file (C source) -----------------------*/