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 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
140 iso14755buf = ISO_14755_54;
152 rxvt_term::iso14755_51 (unicode_t ch, rend_t r)
154 rxvt_fontset *fs = FONTSET (r);
155 rxvt_font *f = (*fs)[fs->find_font (ch)];
156 wchar_t *chr, *alloc, ch2;
162 len = rxvt_composite.expand (ch, 0);
163 alloc = chr = new wchar_t[len];
164 rxvt_composite.expand (ch, chr);
176 int width = strlen (f->name);
178 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1);
180 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
182 for (int y = 0; y < len; y++)
188 sprintf (buf, "%8x", ch);
189 scr_overlay_set (0, y, buf);
190 scr_overlay_set (9, y, '=');
195 scr_overlay_set (11, y, ch, r);
196 scr_overlay_set (12, y, NOCHAR, r);
199 scr_overlay_set (0, len, f->name);
209 rxvt_term::commit_iso14755 ()
213 ch[0] = iso14755buf & ISO_14755_MASK;
216 if (iso14755buf & ISO_14755_51)
221 // allow verbatim 0-bytes and control-bytes to be entered
223 len = wcstombs (mb, ch, 16);
231 tt_write ((unsigned char *)mb, len);
240 rxvt_term::hex_keyval (XKeyEvent &ev)
242 // check wether this event corresponds to a hex digit
243 // if the modifiers had not been pressed.
244 for (int index = 0; index < 8; index++)
246 KeySym k = XLookupKeysym (&ev, index);
248 if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0;
249 else if (k >= XK_0 && k <= XK_9) return k - XK_0;
250 else if (k >= XK_a && k <= XK_f) return k - XK_a + 10;
251 else if (k >= XK_A && k <= XK_F) return k - XK_A + 10;
258 /*{{{ Convert the keypress event into a string */
260 rxvt_term::lookup_key (XKeyEvent &ev)
262 int ctrl, meta, shft, len;
266 static int debug_key = 1; /* accessible by a debugger only */
269 unsigned char kbuf[KBUFSZ];
272 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
273 * escape sequence to toggle the Keypad.
275 * Always permit `shift' to override the current setting
277 shft = (ev.state & ShiftMask);
278 ctrl = (ev.state & ControlMask);
279 meta = (ev.state & ModMetaMask);
281 if (numlock_state || (ev.state & ModNumLockMask))
283 numlock_state = (ev.state & ModNumLockMask);
284 PrivMode ((!numlock_state), PrivMode_aplKP);
292 Status status_return;
295 #ifdef X_HAVE_UTF8_STRING
296 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
297 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf,
298 KBUFSZ, &keysym, &status_return);
303 wchar_t wkbuf[KBUFSZ + 1];
305 // the XOpenIM manpage lies about hardcoding the locale
306 // at the point of XOpenIM, so temporarily switch locales
308 SET_LOCALE (rs[Rs_imLocale]);
309 // assume wchar_t == unicode or better
310 len = XwcLookupString (Input_Context, &ev, wkbuf,
311 KBUFSZ, &keysym, &status_return);
315 if (status_return == XLookupChars
316 || status_return == XLookupBoth)
318 /* make sure the user can type ctrl-@, i.e. NUL */
319 if (len == 1 && *wkbuf == 0)
327 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
336 valid_keysym = status_return == XLookupKeySym
337 || status_return == XLookupBoth;
342 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose);
343 valid_keysym = keysym != NoSymbol;
348 if (TermWin.saveLines)
350 #ifdef UNSHIFTED_SCROLLKEYS
358 #ifdef PAGING_CONTEXT_LINES
359 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES;
361 lnsppg = TermWin.nrow * 4 / 5;
363 if (keysym == XK_Prior)
365 scr_page (UP, lnsppg);
368 else if (keysym == XK_Next)
370 scr_page (DN, lnsppg);
374 #ifdef SCROLL_ON_UPDOWN_KEYS
382 else if (keysym == XK_Down)
389 #ifdef SCROLL_ON_HOMEEND_KEYS
392 if (keysym == XK_Home)
397 else if (keysym == XK_End)
408 /* Shift + F1 - F10 generates F11 - F20 */
409 if (keysym >= XK_F1 && keysym <= XK_F10)
411 keysym += (XK_F11 - XK_F1);
412 shft = 0; /* turn off Shift */
414 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
418 /* normal XTerm key bindings */
419 case XK_Insert: /* Shift+Insert = paste mouse selection */
420 selection_request (ev.time, 0, 0);
424 case XK_KP_Add: /* Shift+KP_Add = bigger font */
425 change_font (FONT_UP);
427 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
428 change_font (FONT_DN);
435 #if ENABLE_FRILLS || ISO_14755
441 if (iso14755buf & ISO_14755_51
442 && (keysym == XK_space || keysym == XK_KP_Space
443 || keysym == XK_Return || keysym == XK_KP_Enter))
446 iso14755buf = ISO_14755_51;
452 else if ((hv = hex_keyval (ev)) >= 0)
454 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
457 iso14755_51 (iso14755buf & ISO_14755_MASK);
469 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
470 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
471 if (!(iso14755buf & ISO_14755_STARTED))
473 iso14755buf |= ISO_14755_STARTED;
475 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
476 scr_overlay_set (0, 0, "ISO 14755 mode");
482 if (keysym == XK_Print)
484 scr_printscreen (ctrl | shft);
489 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
491 #ifdef KEYSYM_RESOURCE
492 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
495 const unsigned char *kbuf0;
497 kbuf0 = (Keysym_map[keysym & 0xFF]);
498 l = (unsigned int)*kbuf0++;
503 && meta_char == C0_ESC
507 const unsigned char ch = C0_ESC;
520 #ifndef NO_BACKSPACE_KEY
522 if (priv_modes & PrivMode_HaveBackSpace)
524 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
525 ^ !!ctrl) ? '\b' : '\177';
529 strcpy (kbuf, key_backspace);
532 #ifndef NO_DELETE_KEY
534 strcpy (kbuf, key_delete);
539 strcpy (kbuf, "\033[Z");
542 #ifdef CTRL_TAB_MAKES_META
546 #ifdef MOD4_TAB_MAKES_META
547 if (ev.state & Mod4Mask)
555 case XK_KP_Up: /* \033Ox or standard */
556 case XK_KP_Down: /* \033Or or standard */
557 case XK_KP_Right: /* \033Ov or standard */
558 case XK_KP_Left: /* \033Ot or standard */
559 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
561 strcpy (kbuf, "\033OZ");
562 kbuf[2] = "txvr"[keysym - XK_KP_Left];
566 /* translate to std. cursor key */
567 keysym = XK_Left + (keysym - XK_KP_Left);
570 case XK_Up: /* "\033[A" */
571 case XK_Down: /* "\033[B" */
572 case XK_Right: /* "\033[C" */
573 case XK_Left: /* "\033[D" */
574 strcpy (kbuf, "\033[Z");
575 kbuf[2] = "DACB"[keysym - XK_Left];
578 kbuf[2] = "dacb"[keysym - XK_Left];
582 kbuf[2] = "dacb"[keysym - XK_Left];
584 else if (priv_modes & PrivMode_aplCUR)
588 #ifndef UNSHIFTED_SCROLLKEYS
591 /* allow shift to override */
592 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
594 strcpy (kbuf, "\033Oy");
600 strcpy (kbuf, "\033[5~");
604 /* allow shift to override */
605 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
607 strcpy (kbuf, "\033Os");
613 strcpy (kbuf, "\033[6~");
617 /* allow shift to override */
618 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
620 strcpy (kbuf, "\033OM");
627 if (priv_modes & PrivMode_LFNL)
642 strcpy (kbuf, "\033Ou");
646 strcpy (kbuf, "\033Op");
650 strcpy (kbuf, "\033On");
653 case XK_KP_F1: /* "\033OP" */
654 case XK_KP_F2: /* "\033OQ" */
655 case XK_KP_F3: /* "\033OR" */
656 case XK_KP_F4: /* "\033OS" */
657 strcpy (kbuf, "\033OP");
658 kbuf[2] += (keysym - XK_KP_F1);
661 case XK_KP_Multiply: /* "\033Oj" : "*" */
662 case XK_KP_Add: /* "\033Ok" : "+" */
663 case XK_KP_Separator: /* "\033Ol" : "," */
664 case XK_KP_Subtract: /* "\033Om" : "-" */
665 case XK_KP_Decimal: /* "\033On" : "." */
666 case XK_KP_Divide: /* "\033Oo" : "/" */
667 case XK_KP_0: /* "\033Op" : "0" */
668 case XK_KP_1: /* "\033Oq" : "1" */
669 case XK_KP_2: /* "\033Or" : "2" */
670 case XK_KP_3: /* "\033Os" : "3" */
671 case XK_KP_4: /* "\033Ot" : "4" */
672 case XK_KP_5: /* "\033Ou" : "5" */
673 case XK_KP_6: /* "\033Ov" : "6" */
674 case XK_KP_7: /* "\033Ow" : "7" */
675 case XK_KP_8: /* "\033Ox" : "8" */
676 case XK_KP_9: /* "\033Oy" : "9" */
677 /* allow shift to override */
678 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
680 strcpy (kbuf, "\033Oj");
681 kbuf[2] += (keysym - XK_KP_Multiply);
685 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
691 strcpy (kbuf, "\033[1~");
694 strcpy (kbuf, "\033[2~");
696 #ifdef DXK_Remove /* support for DEC remove like key */
701 strcpy (kbuf, "\033[3~");
704 strcpy (kbuf, "\033[4~");
708 /* allow shift to override */
709 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
711 strcpy (kbuf, "\033Oq");
717 strcpy (kbuf, KS_END);
721 /* allow shift to override */
722 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
724 strcpy (kbuf, "\033Ow");
730 strcpy (kbuf, KS_HOME);
733 #define FKEY(n, fkey) \
734 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
736 case XK_F1: /* "\033[11~" */
737 case XK_F2: /* "\033[12~" */
738 case XK_F3: /* "\033[13~" */
739 case XK_F4: /* "\033[14~" */
740 case XK_F5: /* "\033[15~" */
743 case XK_F6: /* "\033[17~" */
744 case XK_F7: /* "\033[18~" */
745 case XK_F8: /* "\033[19~" */
746 case XK_F9: /* "\033[20~" */
747 case XK_F10: /* "\033[21~" */
750 case XK_F11: /* "\033[23~" */
751 case XK_F12: /* "\033[24~" */
752 case XK_F13: /* "\033[25~" */
753 case XK_F14: /* "\033[26~" */
756 case XK_F15: /* "\033[28~" */
757 case XK_F16: /* "\033[29~" */
760 case XK_Help: /* "\033[28~" */
763 case XK_Menu: /* "\033[29~" */
766 case XK_F17: /* "\033[31~" */
767 case XK_F18: /* "\033[32~" */
768 case XK_F19: /* "\033[33~" */
769 case XK_F20: /* "\033[34~" */
770 case XK_F21: /* "\033[35~" */
771 case XK_F22: /* "\033[36~" */
772 case XK_F23: /* "\033[37~" */
773 case XK_F24: /* "\033[38~" */
774 case XK_F25: /* "\033[39~" */
775 case XK_F26: /* "\033[40~" */
776 case XK_F27: /* "\033[41~" */
777 case XK_F28: /* "\033[42~" */
778 case XK_F29: /* "\033[43~" */
779 case XK_F30: /* "\033[44~" */
780 case XK_F31: /* "\033[45~" */
781 case XK_F32: /* "\033[46~" */
782 case XK_F33: /* "\033[47~" */
783 case XK_F34: /* "\033[48~" */
784 case XK_F35: /* "\033[49~" */
797 * Pass meta for all function keys, if 'meta' option set
800 if (meta && (meta_char == 0x80) && len > 0)
801 kbuf[len - 1] |= 0x80;
805 else if (ctrl && keysym == XK_minus)
808 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
814 if (meta && (meta_char == 0x80))
818 for (ch = kbuf; ch < kbuf + len; ch++)
829 return; /* not mapped */
831 if (options & Opt_scrollTtyKeypress)
832 if (TermWin.view_start)
834 TermWin.view_start = 0;
839 * these modifications only affect the static keybuffer
840 * pass Shift/Control indicators for function keys ending with `~'
844 * Shift+Prior = "ESC[5$"
845 * Ctrl+Prior = "ESC[5^"
846 * Ctrl+Shift+Prior = "ESC[5@"
847 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
849 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
850 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
855 && meta_char == C0_ESC
859 const unsigned char ch = C0_ESC;
863 #if defined(DEBUG_CMD)
864 /* Display keyboard buffer contents */
868 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
869 for (i = 0, p = kbuf; i < len; i++, p++)
870 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
871 fprintf (stderr, "'\n");
872 #endif /* DEBUG_CMD */
873 tt_write (kbuf, (unsigned int)len);
878 /*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
879 /* attempt to `write' count to the input buffer */
881 rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
885 n = cmdbuf_ptr - cmdbuf_base;
886 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
888 if (n > 0 && s < count)
890 memmove (cmdbuf_base, cmdbuf_ptr,
891 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
892 cmdbuf_ptr = cmdbuf_base;
899 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
904 *cmdbuf_endp++ = *str++;
910 #endif /* MENUBAR_MAX */
916 if (want_full_refresh)
918 want_full_refresh = 0;
926 scr_refresh (refresh_type);
939 rxvt_term::check_cb (check_watcher &w)
946 if (want_refresh && !flush_ev.active)
947 flush_ev.start (NOW + 0.01);
951 rxvt_term::flush_cb (time_watcher &w)
963 rxvt_term::cursor_blink_cb (time_watcher &w)
965 hidden_cursor = !hidden_cursor;
968 w.start (w.at + BLINK_INTERVAL);
974 rxvt_term::text_blink_cb (time_watcher &w)
976 if (scr_refresh_rend (RS_Blink, RS_Blink))
978 hidden_text = !hidden_text;
980 w.start (w.at + TEXT_BLINK_INTERVAL);
985 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
987 rxvt_term::cont_scroll_cb (time_watcher &w)
989 if ((scrollbar_isUp() || scrollbar_isDn()) &&
990 scr_page (scrollbar_isUp() ? UP : DN, 1))
992 refresh_type |= SMOOTH_REFRESH;
994 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
999 #ifdef SELECTION_SCROLLING
1001 rxvt_term::sel_scroll_cb (time_watcher &w)
1003 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1005 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1006 refresh_type |= SMOOTH_REFRESH;
1008 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1015 rxvt_term::slip_wheel_cb (time_watcher &w)
1017 if (mouse_slip_wheel_speed == 0
1018 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1019 : scr_page (UP, mouse_slip_wheel_speed))
1021 refresh_type |= SMOOTH_REFRESH;
1023 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1029 rxvt_term::pty_fill ()
1031 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1035 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
1039 memmove (cmdbuf_base, cmdbuf_ptr, n);
1040 cmdbuf_ptr = cmdbuf_base;
1041 cmdbuf_endp = cmdbuf_ptr + n;
1043 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1050 else if (n < 0 && errno != EAGAIN)
1057 rxvt_term::pty_cb (io_watcher &w, short revents)
1060 SET_LOCALE (locale);
1062 if (revents & EVENT_WRITE)
1064 else if (revents & EVENT_READ)
1065 // loop, but don't allow a single term to monopolize us
1072 rxvt_term::pointer_unblank ()
1074 XDefineCursor (display->display, TermWin.vt, TermWin_cursor);
1077 #ifdef POINTER_BLANK
1080 if (options & Opt_pointerBlank)
1081 pointer_ev.start (NOW + pointerBlankDelay);
1085 #ifdef POINTER_BLANK
1087 rxvt_term::pointer_blank ()
1089 if (! (options & Opt_pointerBlank))
1092 XDefineCursor (display->display, TermWin.vt, blank_cursor);
1093 XFlush (display->display);
1099 rxvt_term::pointer_cb (time_watcher &w)
1102 SET_LOCALE (locale);
1109 rxvt_term::mouse_report (XButtonEvent &ev)
1111 int button_number, key_state = 0;
1116 pixel_position (&x, &y);
1118 if (MEvent.button == AnyButton)
1122 button_number = MEvent.button - Button1;
1123 /* add 0x3D for wheel events, like xterm does */
1124 if (button_number >= 3)
1125 button_number += (64 - 3);
1128 if (priv_modes & PrivMode_MouseX10)
1131 * do not report ButtonRelease
1132 * no state info allowed
1135 if (button_number == 3)
1140 /* XTerm mouse reporting needs these values:
1144 * plus will add in our own Double-Click reporting
1147 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1148 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1149 + ((MEvent.state & ControlMask) ? 16 : 0);
1150 #ifdef MOUSE_REPORT_DOUBLECLICK
1151 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1155 #if DEBUG_MOUSEREPORT
1156 fprintf (stderr, "Mouse [");
1158 fputc ('C', stderr);
1160 fputc ('S', stderr);
1162 fputc ('A', stderr);
1164 fputc ('2', stderr);
1165 fprintf (stderr, "]: <%d>, %d/%d\n",
1171 tt_printf ("\033[M%c%c%c",
1172 (32 + button_number + key_state),
1179 rxvt_W11_process_x_event (XEvent *ev)
1181 rxvt_t *r = rxvt_get_r ();
1187 /*{{{ process an X event */
1189 rxvt_term::x_cb (XEvent &ev)
1192 SET_LOCALE (locale);
1194 #if defined(CURSOR_BLINK)
1195 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1203 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1207 #if defined(POINTER_BLANK)
1208 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1210 if (ev.type == MotionNotify
1211 || ev.type == ButtonPress
1212 || ev.type == ButtonRelease)
1216 if (ev.type == KeyPress && hidden_pointer == 0)
1222 if (XFilterEvent (&ev, None))
1226 Window unused_root, unused_child;
1227 int unused_root_x, unused_root_y;
1228 unsigned int unused_mask;
1234 if (!(iso14755buf & ISO_14755_52))
1236 lookup_key (ev.xkey);
1242 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1245 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1248 #if ENABLE_FRILLS || ISO_14755
1249 // ISO 14755 support
1251 if (iso14755buf & ISO_14755_52)
1257 // iso14755 part 5.2 handling: release time
1259 if ((ev.xkey.state & ControlMask)
1260 && ((ks >= 0x40 && ks <= 0x5f)
1261 || (ks >= 0x61 && ks <= 0x7f)))
1263 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1265 return; // case-break;
1268 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1271 iso14755buf = ISO_14755_51 | i[1];
1273 return; // case-break;
1281 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1286 if (iso14755buf & ISO_14755_51)
1289 else if (iso14755buf & ISO_14755_STARTED)
1291 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1293 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1294 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1302 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1303 if (!(ev.xkey.state & ControlMask))
1304 slip_wheel_ev.stop ();
1305 else if (ks == XK_Control_L || ks == XK_Control_R)
1306 mouse_slip_wheel_speed = 0;
1312 button_press (ev.xbutton);
1316 button_release (ev.xbutton);
1320 if (ev.xclient.format == 32
1321 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1324 /* OffiX Dnd (drag 'n' drop) protocol */
1325 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1326 && (ev.xclient.data.l[0] == DndFile
1327 || ev.xclient.data.l[0] == DndDir
1328 || ev.xclient.data.l[0] == DndLink))
1333 unsigned char *data;
1334 unsigned long Size, RemainingBytes;
1336 XGetWindowProperty (display->display, display->root,
1337 xa[XA_DNDSELECTION],
1339 False, AnyPropertyType,
1340 &ActualType, &ActualFormat,
1341 &Size, &RemainingBytes,
1343 XChangeProperty (display->display, display->root,
1344 XA_CUT_BUFFER0, XA_STRING,
1346 data, strlen (data));
1348 selection_paste (display->root, XA_CUT_BUFFER0, True);
1349 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1351 #endif /* OFFIX_DND */
1355 XRefreshKeyboardMapping (&ev.xmapping);
1359 * XXX: this is not the _current_ arrangement
1360 * Here's my conclusion:
1361 * If the window is completely unobscured, use bitblt's
1362 * to scroll. Even then, they're only used when doing partial
1363 * screen scrolling. When partially obscured, we have to fill
1364 * in the GraphicsExpose parts, which means that after each refresh,
1365 * we need to wait for the graphics expose or Noexpose events,
1366 * which ought to make things real slow!
1368 case VisibilityNotify:
1369 switch (ev.xvisibility.state)
1371 case VisibilityUnobscured:
1372 refresh_type = FAST_REFRESH;
1374 case VisibilityPartiallyObscured:
1375 refresh_type = SLOW_REFRESH;
1378 refresh_type = NO_REFRESH;
1389 if (Input_Context != NULL)
1391 IMSetStatusPosition ();
1392 XSetICFocus (Input_Context);
1396 if (options & Opt_cursorBlink)
1397 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1399 #ifdef OFF_FOCUS_FADING
1402 pix_colors = pix_colors_focused;
1416 #if ENABLE_FRILLS || ISO_14755
1423 if (Input_Context != NULL)
1424 XUnsetICFocus (Input_Context);
1427 if (options & Opt_cursorBlink)
1428 cursor_blink_ev.stop ();
1431 #ifdef OFF_FOCUS_FADING
1434 pix_colors = pix_colors_unfocused;
1441 case ConfigureNotify:
1442 if (ev.xconfigure.window == TermWin.parent[0])
1447 { /* Wrap lots of configures into one */
1448 width = ev.xconfigure.width;
1449 height = ev.xconfigure.height;
1450 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1452 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev));
1454 if (szHint.width != width || szHint.height != height)
1457 resize_all_windows (width, height, 1);
1460 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1461 if (options & Opt_transparent)
1463 check_our_parents ();
1465 want_refresh = want_full_refresh = 1;
1471 case PropertyNotify:
1472 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1473 && ev.xproperty.state == PropertyNewValue)
1474 selection_property (ev.xproperty.window, ev.xproperty.atom);
1478 case SelectionClear:
1482 case SelectionNotify:
1483 if (selection_wait == Sel_normal)
1484 selection_paste (ev.xselection.requestor,
1485 ev.xselection.property, True);
1488 case SelectionRequest:
1489 selection_send (ev.xselectionrequest);
1495 text_blink_ev.stop ();
1502 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1507 case ReparentNotify:
1510 #endif /* TRANSPARENT */
1512 case GraphicsExpose:
1514 if (ev.xany.window == TermWin.vt)
1517 scr_expose (ev.xexpose.x, ev.xexpose.y,
1518 ev.xexpose.width, ev.xexpose.height, False);
1519 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev));
1521 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1523 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev))
1524 scr_expose (ev.xexpose.x, ev.xexpose.y,
1525 ev.xexpose.width, ev.xexpose.height, False);
1527 scr_refresh (refresh_type);
1531 XEvent unused_event;
1533 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event))
1535 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event))
1538 if (isScrollbarWindow (ev.xany.window))
1540 scrollBar.setIdle ();
1544 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1549 if (am_transparent && ev.xany.window == TermWin.parent[0])
1550 XClearWindow (display->display, ev.xany.window);
1556 #ifdef POINTER_BLANK
1561 if (isMenuBarWindow (ev.xany.window))
1563 menubar_control (ev.xbutton);
1567 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate))
1570 if (ev.xany.window == TermWin.vt)
1572 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1574 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev))
1577 XQueryPointer (display->display, TermWin.vt,
1578 &unused_root, &unused_child,
1579 &unused_root_x, &unused_root_y,
1580 & (ev.xbutton.x), & (ev.xbutton.y),
1582 #ifdef MOUSE_THRESHOLD
1583 /* deal with a `jumpy' mouse */
1584 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1589 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1591 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1595 selection_extend (ev.xbutton.x, ev.xbutton.y,
1596 (ev.xbutton.state & Button3Mask) ? 2 : 0);
1597 #ifdef SELECTION_SCROLLING
1598 if (ev.xbutton.y < TermWin.int_bwidth
1599 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1))
1603 /* don't clobber the current delay if we are
1604 * already in the middle of scrolling.
1606 if (!sel_scroll_ev.active)
1607 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1609 /* save the event params so we can highlight
1610 * the selection in the pending-scroll loop
1612 selection_save_x = ev.xbutton.x;
1613 selection_save_y = ev.xbutton.y;
1614 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1616 /* calc number of lines to scroll */
1617 if (ev.xbutton.y<TermWin.int_bwidth)
1619 scroll_selection_dir = UP;
1620 dist = TermWin.int_bwidth - ev.xbutton.y;
1624 scroll_selection_dir = DN;
1625 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height);
1628 scroll_selection_lines = Pixel2Height (dist)
1629 / SELECTION_SCROLL_LINE_SPEEDUP
1631 MIN_IT (scroll_selection_lines,
1632 SELECTION_SCROLL_MAX_LINES);
1636 /* we are within the text window, so we
1637 * shouldn't be scrolling
1639 if (sel_scroll_ev.active)
1640 sel_scroll_ev.stop();
1643 #ifdef MOUSE_THRESHOLD
1648 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1650 while (XCheckTypedWindowEvent (display->display, scrollBar.win,
1651 MotionNotify, &ev)) ;
1652 XQueryPointer (display->display, scrollBar.win,
1653 &unused_root, &unused_child,
1654 &unused_root_x, &unused_root_y,
1655 & (ev.xbutton.x), & (ev.xbutton.y),
1657 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1659 scr_refresh (refresh_type);
1669 rxvt_term::rootwin_cb (XEvent &ev)
1672 SET_LOCALE (locale);
1676 case PropertyNotify:
1678 * if user used some Esetroot compatible prog to set the root bg,
1679 * use the property to determine the pixmap. We use it later on.
1681 if (xa[XA_XROOTPMAPID] == 0)
1682 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1684 if (ev.xproperty.atom != xa[XA_XROOTPMAPID])
1688 case ReparentNotify:
1689 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1690 want_refresh = want_full_refresh = 1;
1697 rxvt_term::button_press (XButtonEvent &ev)
1699 int reportmode = 0, clickintime;
1701 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1702 if (!bypass_keystate)
1703 reportmode = !! (priv_modes & PrivMode_mouse_report);
1706 * VT window processing of button press
1708 if (ev.window == TermWin.vt)
1712 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1714 iso14755_54 (ev.x, ev.y);
1719 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1722 /* mouse report from vt window */
1723 /* save the xbutton state (for ButtonRelease) */
1724 MEvent.state = ev.state;
1725 #ifdef MOUSE_REPORT_DOUBLECLICK
1726 if (ev.button == MEvent.button && clickintime)
1728 /* same button, within alloted time */
1730 if (MEvent.clicks > 1)
1732 /* only report double clicks */
1736 /* don't report the release */
1738 MEvent.button = AnyButton;
1743 /* different button, or time expired */
1745 MEvent.button = ev.button;
1749 MEvent.button = ev.button;
1751 #endif /* MOUSE_REPORT_DOUBLECLICK */
1756 if (ev.button != MEvent.button)
1761 /* allow shift+left click to extend selection */
1762 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1764 if (MEvent.button == Button1 && clickintime)
1765 selection_rotate (ev.x, ev.y);
1767 selection_extend (ev.x, ev.y, 1);
1771 if (MEvent.button == Button1 && clickintime)
1776 selection_click (MEvent.clicks, ev.x, ev.y);
1779 MEvent.button = Button1;
1783 if (MEvent.button == Button3 && clickintime)
1784 selection_rotate (ev.x, ev.y);
1786 selection_extend (ev.x, ev.y, 1);
1788 MEvent.button = Button3;
1793 MEvent.time = ev.time;
1798 * Scrollbar window processing of button press
1800 if (isScrollbarWindow (ev.window))
1802 scrollBar.setIdle ();
1804 * Rxvt-style scrollbar:
1805 * move up if mouse is above slider
1806 * move dn if mouse is below slider
1808 * XTerm-style scrollbar:
1809 * Move display proportional to pointer location
1810 * pointer near top -> scroll one line
1811 * pointer near bot -> scroll full page
1813 #ifndef NO_SCROLLBAR_REPORT
1817 * Mouse report disabled scrollbar:
1818 * arrow buttons - send up/down
1819 * click on scrollbar - send pageup/down
1821 if ((scrollBar.style == R_SB_NEXT
1822 && scrollbarnext_upButton (ev.y))
1823 || (scrollBar.style == R_SB_RXVT
1824 && scrollbarrxvt_upButton (ev.y)))
1825 tt_printf ("\033[A");
1826 else if ((scrollBar.style == R_SB_NEXT
1827 && scrollbarnext_dnButton (ev.y))
1828 || (scrollBar.style == R_SB_RXVT
1829 && scrollbarrxvt_dnButton (ev.y)))
1830 tt_printf ("\033[B");
1838 tt_printf ("\033[6~");
1841 tt_printf ("\033[5~");
1846 #endif /* NO_SCROLLBAR_REPORT */
1851 if (scrollBar.style == R_SB_NEXT)
1853 if (scrollbarnext_upButton (ev.y))
1854 upordown = -1; /* up */
1855 else if (scrollbarnext_dnButton (ev.y))
1856 upordown = 1; /* down */
1858 else if (scrollBar.style == R_SB_RXVT)
1860 if (scrollbarrxvt_upButton (ev.y))
1861 upordown = -1; /* up */
1862 else if (scrollbarrxvt_dnButton (ev.y))
1863 upordown = 1; /* down */
1867 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1868 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1870 if (scr_page (upordown < 0 ? UP : DN, 1))
1882 switch (scrollbar_align)
1884 case R_SB_ALIGN_TOP:
1887 case R_SB_ALIGN_CENTRE:
1888 csrO = (scrollBar.bot - scrollBar.top) / 2;
1890 case R_SB_ALIGN_BOTTOM:
1891 csrO = scrollBar.bot - scrollBar.top;
1895 if (scrollBar.style == R_SB_XTERM
1896 || scrollbar_above_slider (ev.y)
1897 || scrollbar_below_slider (ev.y))
1898 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
1900 scrollBar.setMotion ();
1904 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1905 csrO = ev.y - scrollBar.top;
1909 if (scrollBar.style != R_SB_XTERM)
1911 if (scrollbar_above_slider (ev.y))
1912 # ifdef RXVT_SCROLL_FULL
1913 scr_page (UP, TermWin.nrow - 1);
1915 scr_page (UP, TermWin.nrow / 4);
1917 else if (scrollbar_below_slider (ev.y))
1918 # ifdef RXVT_SCROLL_FULL
1919 scr_page (DN, TermWin.nrow - 1);
1921 scr_page (DN, TermWin.nrow / 4);
1924 scrollBar.setMotion ();
1928 scr_page ((ev.button == Button1 ? DN : UP),
1930 * scrollbar_position (ev.y)
1931 / scrollbar_size ()));
1941 * Menubar window processing of button press
1943 if (isMenuBarWindow (ev.window))
1944 menubar_control (ev);
1949 rxvt_term::button_release (XButtonEvent &ev)
1953 csrO = 0; /* reset csr Offset */
1954 if (!bypass_keystate)
1955 reportmode = !! (priv_modes & PrivMode_mouse_report);
1957 if (scrollbar_isUpDn ())
1959 scrollBar.setIdle ();
1961 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1962 refresh_type &= ~SMOOTH_REFRESH;
1966 #ifdef SELECTION_SCROLLING
1967 if (sel_scroll_ev.active)
1968 sel_scroll_ev.stop();
1971 if (ev.window == TermWin.vt)
1975 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1980 /* mouse report from vt window */
1981 /* don't report release of wheel "buttons" */
1984 #ifdef MOUSE_REPORT_DOUBLECLICK
1985 /* only report the release of 'slow' single clicks */
1986 if (MEvent.button != AnyButton
1987 && (ev.button != MEvent.button
1988 || (ev.time - MEvent.time
1989 > MULTICLICK_TIME / 2)))
1992 MEvent.button = AnyButton;
1995 #else /* MOUSE_REPORT_DOUBLECLICK */
1996 MEvent.button = AnyButton;
1998 #endif /* MOUSE_REPORT_DOUBLECLICK */
2003 * dumb hack to compensate for the failure of click-and-drag
2004 * when overriding mouse reporting
2006 if (priv_modes & PrivMode_mouse_report
2008 && ev.button == Button1 && MEvent.clicks <= 1)
2009 selection_extend (ev.x, ev.y, 0);
2015 selection_make (ev.time);
2018 selection_request (ev.time, ev.x, ev.y);
2027 v = ev.button == Button4 ? UP : DN;
2029 if (ev.state & ShiftMask)
2031 else if (options & Opt_mouseWheelScrollPage)
2032 i = TermWin.nrow - 1;
2036 # ifdef MOUSE_SLIP_WHEELING
2037 if (ev.state & ControlMask)
2039 mouse_slip_wheel_speed += v ? -1 : 1;
2040 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow;
2041 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2043 if (slip_wheel_ev.at < NOW)
2044 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2046 slip_wheel_ev.start ();
2051 # ifdef JUMP_MOUSE_WHEEL
2053 scr_refresh (SMOOTH_REFRESH);
2059 scr_refresh (SMOOTH_REFRESH);
2063 # ifdef MOUSE_SLIP_WHEELING
2072 else if (isMenuBarWindow (ev.window))
2073 menubar_control (ev);
2079 /* taken from aterm-0.4.2 */
2081 typedef uint32_t RUINT32T;
2083 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2085 int sh_r, sh_g, sh_b;
2086 RUINT32T mask_r, mask_g, mask_b;
2087 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2088 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2089 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2092 Visual* visual = display->visual;
2094 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2096 /* for convenience */
2097 mask_r = visual->red_mask;
2098 mask_g = visual->green_mask;
2099 mask_b = visual->blue_mask;
2101 /* boring lookup table pre-initialization */
2102 switch (srcImage->bits_per_pixel) {
2104 if ((mask_r != 0x7c00) ||
2105 (mask_g != 0x03e0) ||
2108 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2110 lookup_g = lookup+32;
2111 lookup_b = lookup+32+32;
2117 if ((mask_r != 0xf800) ||
2118 (mask_g != 0x07e0) ||
2121 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2123 lookup_g = lookup+32;
2124 lookup_b = lookup+32+64;
2130 if ((mask_r != 0xff0000) ||
2131 (mask_g != 0x00ff00) ||
2132 (mask_b != 0x0000ff))
2134 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2136 lookup_g = lookup+256;
2137 lookup_b = lookup+256+256;
2143 if ((mask_r != 0xff0000) ||
2144 (mask_g != 0x00ff00) ||
2145 (mask_b != 0x0000ff))
2147 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2149 lookup_g = lookup+256;
2150 lookup_b = lookup+256+256;
2156 return; /* we do not support this color depth */
2159 /* prepare limits for color transformation (each channel is handled separately) */
2162 if (shade < 0) shade = 0;
2163 if (shade > 100) shade = 100;
2165 lower_lim_r = 65535-rm;
2166 lower_lim_g = 65535-gm;
2167 lower_lim_b = 65535-bm;
2169 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2170 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2171 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2173 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2175 if (shade < 0) shade = 0;
2176 if (shade > 100) shade = 100;
2178 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2180 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2181 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2182 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2185 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2186 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2191 lower_lim_r = lower_lim_b;
2195 upper_lim_r = upper_lim_b;
2199 /* fill our lookup tables */
2200 for (i = 0; i <= mask_r>>sh_r; i++)
2203 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2204 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2205 lookup_r[i] = (tmp/65535)<<sh_r;
2207 for (i = 0; i <= mask_g>>sh_g; i++)
2210 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2211 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2212 lookup_g[i] = (tmp/65535)<<sh_g;
2214 for (i = 0; i <= mask_b>>sh_b; i++)
2217 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2218 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2219 lookup_b[i] = (tmp/65535)<<sh_b;
2222 /* apply table to input image (replacing colors by newly calculated ones) */
2223 switch (srcImage->bits_per_pixel)
2227 unsigned short *p1, *pf, *p, *pl;
2228 p1 = (unsigned short *) srcImage->data;
2229 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2233 pl = p1 + srcImage->width;
2236 *p = lookup_r[(*p & 0x7c00)>>10] |
2237 lookup_g[(*p & 0x03e0)>> 5] |
2238 lookup_b[(*p & 0x001f)];
2240 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2246 unsigned short *p1, *pf, *p, *pl;
2247 p1 = (unsigned short *) srcImage->data;
2248 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2252 pl = p1 + srcImage->width;
2255 *p = lookup_r[(*p & 0xf800)>>11] |
2256 lookup_g[(*p & 0x07e0)>> 5] |
2257 lookup_b[(*p & 0x001f)];
2259 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2265 unsigned char *p1, *pf, *p, *pl;
2266 p1 = (unsigned char *) srcImage->data;
2267 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2271 pl = p1 + srcImage->width * 3;
2272 for (; p < pl; p += 3)
2274 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2275 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2276 p[2] = lookup_r[(p[2] & 0x0000ff)];
2278 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2284 RUINT32T *p1, *pf, *p, *pl;
2285 p1 = (RUINT32T *) srcImage->data;
2286 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2291 pl = p1 + srcImage->width;
2294 *p = lookup_r[(*p & 0xff0000)>>16] |
2295 lookup_g[(*p & 0x00ff00)>> 8] |
2296 lookup_b[(*p & 0x0000ff)] |
2299 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2310 * Check our parents are still who we think they are.
2311 * Do transparency updates if required
2314 rxvt_term::check_our_parents ()
2316 int i, pchanged, aformat, have_pixmap, rootdepth;
2317 unsigned long nitems, bytes_after;
2319 unsigned char *prop = NULL;
2320 Window root, oldp, *list;
2321 Pixmap rootpixmap = None;
2322 XWindowAttributes wattr, wrootattr;
2326 if (!(options & Opt_transparent))
2327 return pchanged; /* Don't try any more */
2329 XGetWindowAttributes (display->display, display->root, &wrootattr);
2330 rootdepth = wrootattr.depth;
2332 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2334 if (rootdepth != wattr.depth)
2339 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2340 am_transparent = am_pixmap_trans = 0;
2343 return pchanged; /* Don't try any more */
2346 /* Get all X ops out of the queue so that our information is up-to-date. */
2347 XSync (display->display, False);
2350 * Make the frame window set by the window manager have
2351 * the root background. Some window managers put multiple nested frame
2352 * windows for each client, so we have to take care about that.
2354 i = (xa[XA_XROOTPMAPID]
2355 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID],
2356 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2357 &nitems, &bytes_after, &prop) == Success);
2359 if (!i || prop == NULL)
2360 i = (xa[XA_XSETROOTID]
2361 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID],
2362 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2363 &nitems, &bytes_after, &prop) == Success);
2365 if (!i || prop == NULL
2367 || !rs[Rs_color + Color_tint]
2374 rootpixmap = *(Pixmap *)prop;
2381 * Copy display->root pixmap transparency
2384 unsigned int nw, nh;
2390 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
2391 0, 0, &sx, &sy, &cr);
2392 nw = (unsigned int)szHint.width;
2393 nh = (unsigned int)szHint.height;
2410 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2411 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2413 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2415 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2416 /* XXX: may need a delay here? */
2421 if (am_transparent && am_pixmap_trans)
2424 if (TermWin.pixmap != None)
2426 XFreePixmap (display->display, TermWin.pixmap);
2427 TermWin.pixmap = None;
2431 am_pixmap_trans = 0;
2435 if (TermWin.pixmap != None)
2436 XFreePixmap (display->display, TermWin.pixmap);
2439 if (ISSET_PIXCOLOR (Color_tint))
2441 unsigned short rm, gm, bm;
2442 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2444 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2446 ShadeXImage (display, image, shade, rm, gm, bm);
2450 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
2451 szHint.width, szHint.height, image->depth);
2452 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue);
2453 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0,
2454 nx, ny, image->width, image->height);
2455 XFreeGC (display->display, gc);
2456 XDestroyImage (image);
2457 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap);
2458 XClearWindow (display->display, TermWin.parent[0]);
2460 if (!am_transparent || !am_pixmap_trans)
2463 am_transparent = am_pixmap_trans = 1;
2467 if (!am_pixmap_trans)
2471 * InheritPixmap transparency
2473 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2475 oldp = TermWin.parent[i];
2476 XQueryTree (display->display, 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 (display->display, 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 (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]);
2510 XSetWindowBackground (display->display, 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 (display->display, TermWin.parent[n], ParentRelative);
2524 XClearWindow (display->display, TermWin.parent[n]);
2527 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2531 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2532 TermWin.parent[i] = None;
2537 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative);
2538 scrollBar.setIdle ();
2549 rxvt_term::cmd_parse ()
2552 unicode_t ch = NOCHAR;
2553 unsigned char *seq_begin; // remember start of esc-sequence here
2559 seq_begin = cmdbuf_ptr;
2563 if (ch == NOCHAR) // TODO: improve
2566 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2571 // many badly-written programs (e.g. jed) contain a race condition:
2572 // they first read the screensize and then install a SIGWINCH handler.
2573 // some window managers resize the window early, and these programs
2574 // then sometimes get the size wrong.
2575 // unfortunately other programs are even more buggy and dislike
2576 // being sent SIGWINCH, so only do it when we were in fact being
2579 kill (-cmd_pid, SIGWINCH);
2582 /* Read a text string from the input buffer */
2583 unicode_t buf[UBUFSIZ];
2584 bool refreshnow = false;
2586 unicode_t *str = buf;
2590 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2600 if (!(options & Opt_jumpScroll)
2601 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2608 // scr_add_lines only works for nlines <= TermWin.nrow - 1.
2609 if (nlines >= TermWin.nrow - 1)
2611 scr_add_lines (buf, nlines, str - buf);
2617 if (str >= buf + UBUFSIZ)
2623 seq_begin = cmdbuf_ptr;
2627 scr_add_lines (buf, nlines, str - buf);
2630 * If there have been a lot of new lines, then update the screen
2631 * What the heck I'll cheat and only refresh less than every page-full.
2632 * the number of pages between refreshes is refresh_limit, which
2633 * is incremented here because we must be doing flat-out scrolling.
2637 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2642 scr_refresh (refresh_type);
2651 process_nonprinting (ch);
2653 catch (const class out_of_input &o)
2655 // we ran out of input, retry later
2656 cmdbuf_ptr = seq_begin;
2667 // read the next octet
2669 rxvt_term::next_octet ()
2671 return cmdbuf_ptr < cmdbuf_endp
2676 // read the next character
2678 rxvt_term::next_char ()
2680 while (cmdbuf_ptr < cmdbuf_endp)
2682 // assume 7-bit to be ascii ALWAYS
2683 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2684 return *cmdbuf_ptr++;
2687 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2689 if (len == (size_t)-2)
2691 // the mbstate stores incomplete sequences. didn't know this :/
2692 cmdbuf_ptr = cmdbuf_endp;
2696 if (len == (size_t)-1)
2697 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2699 // assume wchar == unicode
2707 /* rxvt_cmd_getc () - Return next input character */
2709 * Return the next input character after first passing any keyboard input
2713 rxvt_term::cmd_getc ()
2715 unicode_t c = next_char ();
2724 rxvt_term::cmd_get8 ()
2726 unicode_t c = next_octet ();
2735 /*----------------------------------------------------------------------*/
2738 rxvt_term::popen_printer ()
2740 FILE *stream = popen (rs[Rs_print_pipe], "w");
2743 rxvt_warn ("can't open printer pipe, not printing.\n");
2749 rxvt_term::pclose_printer (FILE *stream)
2752 return pclose (stream);
2756 * simulate attached vt100 printer
2759 rxvt_term::process_print_pipe ()
2764 if ((fd = popen_printer ()) == NULL)
2768 * Send all input to the printer until either ESC[4i or ESC[?4i
2771 for (done = 0; !done;)
2773 unsigned char buf[8];
2775 unsigned int i, len;
2777 if ((ch = cmd_getc ()) != C0_ESC)
2779 if (putc (ch, fd) == EOF)
2780 break; /* done = 1 */
2787 if ((buf[len++] = cmd_getc ()) == '[')
2789 if ((ch = cmd_getc ()) == '?')
2794 if ((buf[len++] = ch) == '4')
2796 if ((buf[len++] = cmd_getc ()) == 'i')
2797 break; /* done = 1 */
2801 for (i = 0; i < len; i++)
2802 if (putc (buf[i], fd) == EOF)
2810 pclose_printer (fd);
2812 #endif /* PRINTPIPE */
2818 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2819 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2820 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2821 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2825 /*{{{ process non-printing single characters */
2827 rxvt_term::process_nonprinting (unicode_t ch)
2832 process_escape_seq ();
2834 case C0_ENQ: /* terminal Status */
2835 if (rs[Rs_answerbackstring])
2836 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2837 (unsigned int)strlen (rs[Rs_answerbackstring]));
2839 tt_write ((unsigned char *)VT100_ANS,
2840 (unsigned int)strlen (VT100_ANS));
2842 case C0_BEL: /* bell */
2845 case C0_BS: /* backspace */
2848 case C0_HT: /* tab */
2851 case C0_CR: /* carriage return */
2852 scr_gotorc (0, 0, R_RELATIVE);
2854 case C0_VT: /* vertical tab, form feed */
2856 case C0_LF: /* line feed */
2859 case C0_SO: /* shift out - acs */
2860 scr_charset_choose (1);
2862 case C0_SI: /* shift in - acs */
2863 scr_charset_choose (0);
2866 #ifdef EIGHT_BIT_CONTROLS
2868 case 0x90: /* DCS */
2871 case 0x9b: /* CSI */
2874 case 0x9d: /* CSI */
2883 /*{{{ process VT52 escape sequences */
2885 rxvt_term::process_escape_vt52 (unicode_t ch)
2891 case 'A': /* cursor up */
2892 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2894 case 'B': /* cursor down */
2895 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2897 case 'C': /* cursor right */
2898 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2900 case 'D': /* cursor left */
2901 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2903 case 'H': /* cursor home */
2904 scr_gotorc (0, 0, 0);
2906 case 'I': /* cursor up and scroll down if needed */
2909 case 'J': /* erase to end of screen */
2910 scr_erase_screen (0);
2912 case 'K': /* erase to end of line */
2915 case 'Y': /* move to specified row and col */
2916 /* full command is 'ESC Y row col' where row and col
2917 * are encoded by adding 32 and sending the ascii
2918 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2920 row = cmd_getc () - ' ';
2921 col = cmd_getc () - ' ';
2922 scr_gotorc (row, col, 0);
2924 case 'Z': /* identify the terminal type */
2925 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2927 case '<': /* turn off VT52 mode */
2928 PrivMode (0, PrivMode_vt52);
2930 case 'F': /* use special graphics character set */
2931 case 'G': /* use regular character set */
2934 case '=': /* use alternate keypad mode */
2935 case '>': /* use regular keypad mode */
2943 /*{{{ process escape sequences */
2945 rxvt_term::process_escape_seq ()
2947 unicode_t ch = cmd_getc ();
2949 if (priv_modes & PrivMode_vt52)
2951 process_escape_vt52 (ch);
2957 /* case 1: do_tek_mode (); break; */
2959 if (cmd_getc () == '8')
2963 scr_charset_set (0, (unsigned int)cmd_getc ());
2966 scr_charset_set (1, (unsigned int)cmd_getc ());
2969 scr_charset_set (2, (unsigned int)cmd_getc ());
2972 scr_charset_set (3, (unsigned int)cmd_getc ());
2983 scr_cursor (RESTORE);
2987 scr_forwardindex ();
2992 PrivMode ((ch == '='), PrivMode_aplKP);
3002 /* 8.3.87: NEXT LINE */
3003 case C1_NEL: /* ESC E */
3005 unicode_t nlcr[] = { C0_LF, C0_CR };
3006 scr_add_lines (nlcr, 1, 2);
3010 /* kidnapped escape sequence: Should be 8.3.48 */
3011 case C1_ESA: /* ESC G */
3012 process_graphics ();
3015 /* 8.3.63: CHARACTER TABULATION SET */
3016 case C1_HTS: /* ESC H */
3020 /* 8.3.105: REVERSE LINE FEED */
3021 case C1_RI: /* ESC M */
3025 /* 8.3.142: SINGLE-SHIFT TWO */
3026 /*case C1_SS2: scr_single_shift (2); break; */
3028 /* 8.3.143: SINGLE-SHIFT THREE */
3029 /*case C1_SS3: scr_single_shift (3); break; */
3031 /* 8.3.27: DEVICE CONTROL STRING */
3032 case C1_DCS: /* ESC P */
3036 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3037 case C1_SCI: /* ESC Z */
3038 tt_write ((const unsigned char *)ESCZ_ANSWER,
3039 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3040 break; /* steal obsolete ESC [ c */
3042 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3043 case C1_CSI: /* ESC [ */
3047 /* 8.3.90: OPERATING SYSTEM COMMAND */
3048 case C1_OSC: /* ESC ] */
3052 /* 8.3.106: RESET TO INITIAL STATE */
3059 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3061 scr_charset_choose (2);
3064 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3066 scr_charset_choose (3);
3072 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3076 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3077 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3078 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3079 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3080 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3081 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3082 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3083 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3086 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3087 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3088 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3089 #define get_byte_array_bit(array, bit) \
3090 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3092 const unsigned char csi_defaults[] =
3094 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3095 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3096 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3097 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3098 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3099 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3100 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3101 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3106 rxvt_term::process_csi_seq ()
3108 unicode_t ch, priv, i;
3109 unsigned int nargs, p;
3113 for (nargs = ESC_ARGS; nargs > 0;)
3118 if (ch >= '<' && ch <= '?')
3119 { /* '<' '=' '>' '?' */
3124 /* read any numerical arguments */
3125 for (n = -1; ch < CSI_ICH; )
3132 n = n * 10 + ch - '0';
3136 if (nargs < ESC_ARGS)
3140 else if (IS_CONTROL (ch))
3141 process_nonprinting (ch);
3149 if (nargs < ESC_ARGS)
3153 ndef = get_byte_array_bit (csi_defaults, i);
3154 for (p = 0; p < nargs; p++)
3159 fprintf (stderr, "CSI ");
3160 for (p = 0; p < nargs; p++)
3161 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3162 fprintf (stderr, "%c\n", ch);
3166 * private mode handling
3173 if (ch == CSI_DA) /* secondary device attributes */
3174 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING);
3177 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3178 process_terminal_mode (ch, priv, nargs, arg);
3187 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3190 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3193 case 0: /* initiate transfer to primary aux device */
3194 scr_printscreen (0);
3196 case 5: /* start relay to primary aux device */
3197 process_print_pipe ();
3203 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3204 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3207 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3208 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3209 scr_gotorc (arg[0], 0, RELATIVE);
3212 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3213 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3216 #else /* emulate common DEC VTs */
3217 arg[0] = arg[0] ? -arg[0] : -1;
3220 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3221 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3223 scr_gotorc (0, arg[0], RELATIVE);
3224 #else /* emulate common DEC VTs */
3225 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3229 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3232 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3233 scr_gotorc (arg[0], 0, R_RELATIVE);
3236 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3237 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3238 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3241 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3242 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3245 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3246 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3247 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3250 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3253 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3257 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3258 scr_erase_screen (arg[0]);
3261 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3262 scr_erase_line (arg[0]);
3265 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3266 scr_insdel_chars (arg[0], INSERT);
3269 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3270 scr_insdel_lines (arg[0], INSERT);
3273 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3274 scr_insdel_lines (arg[0], DELETE);
3277 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3278 scr_insdel_chars (arg[0], ERASE);
3281 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3282 scr_insdel_chars (arg[0], DELETE);
3285 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3288 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3289 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
3292 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3293 tt_write ((const unsigned char *)VT100_ANS,
3294 (unsigned int) (sizeof (VT100_ANS) - 1));
3297 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3298 process_sgr_mode (nargs, arg);
3301 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3304 case 5: /* DSR requested */
3305 tt_printf ("\033[0n");
3307 case 6: /* CPR requested */
3308 scr_report_position ();
3310 case 7: /* unofficial extension */
3311 if (options & Opt_insecure)
3312 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3314 case 8: /* unofficial extension */
3315 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3320 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3323 case 0: /* char tab stop cleared at active position */
3326 /* case 1: */ /* line tab stop cleared in active line */
3327 /* case 2: */ /* char tab stops cleared in active line */
3328 case 3: /* all char tab stops are cleared */
3329 /* case 4: */ /* all line tab stops are cleared */
3330 case 5: /* all tab stops are cleared */
3336 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3339 case 0: /* char tab stop set at active position */
3341 break; /* = ESC H */
3342 /* case 1: */ /* line tab stop set at active line */
3343 case 2: /* char tab stop cleared at active position */
3345 break; /* = ESC [ 0 g */
3346 /* case 3: */ /* line tab stop cleared at active line */
3347 /* case 4: */ /* char tab stops cleared at active line */
3348 case 5: /* all char tab stops are cleared */
3350 break; /* = ESC [ 3 g */
3351 /* case 6: */ /* all line tab stops are cleared */
3355 case CSI_RM: /* 8.3.107: RESET MODE */
3357 scr_insert_mode (0);
3358 else if (arg[0] == 20)
3359 priv_modes &= ~PrivMode_LFNL;
3362 case CSI_SM: /* 8.3.126: SET MODE */
3364 scr_insert_mode (1);
3365 else if (arg[0] == 20)
3366 priv_modes |= PrivMode_LFNL;
3370 * PRIVATE USE beyond this point. All CSI_7? sequences here
3372 case CSI_72: /* DECSTBM: set top and bottom margins */
3374 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3375 else if (nargs == 0 || arg[0] >= arg[1])
3376 scr_scroll_region (0, MAX_ROWS - 1);
3378 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3385 scr_cursor (RESTORE);
3390 process_window_ops (arg, nargs);
3394 case CSI_78: /* DECREQTPARM */
3395 if (arg[0] == 0 || arg[0] == 1)
3396 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3408 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3411 XWindowAttributes wattr;
3422 case 1: /* deiconify window */
3423 XMapWindow (display->display, TermWin.parent[0]);
3425 case 2: /* iconify window */
3426 XIconifyWindow (display->display, TermWin.parent[0],
3427 DefaultScreen (display->display));
3429 case 3: /* set position (pixels) */
3430 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]);
3432 case 4: /* set size (pixels) */
3433 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3435 case 5: /* raise window */
3436 XRaiseWindow (display->display, TermWin.parent[0]);
3438 case 6: /* lower window */
3439 XLowerWindow (display->display, TermWin.parent[0]);
3441 case 7: /* refresh window */
3444 case 8: /* set size (chars) */
3445 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
3446 (unsigned int) (args[1] * TermWin.fheight));
3449 //case 9: NYI, TODO, restore maximized window or maximize window
3451 if (args[0] >= 24) /* set height (chars) */
3452 set_widthheight ((unsigned int)TermWin.width,
3453 (unsigned int) (args[1] * TermWin.fheight));
3458 * reports - some output format copied from XTerm
3460 case 11: /* report window state */
3461 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3462 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3464 case 13: /* report window position */
3465 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3466 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root,
3467 -wattr.border_width, -wattr.border_width,
3469 tt_printf ("\033[3;%d;%dt", x, y);
3471 case 14: /* report window size (pixels) */
3472 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3473 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3475 case 18: /* report text area size (chars) */
3476 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3478 case 19: /* report window size (chars) */
3479 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3481 case 20: /* report icon label */
3484 XGetIconName (display->display, TermWin.parent[0], &s);
3485 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3489 case 21: /* report window title */
3492 XFetchName (display->display, TermWin.parent[0], &s);
3493 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3501 /*----------------------------------------------------------------------*/
3503 * get input up until STRING TERMINATOR (or BEL)
3504 * ends_how is terminator used. returned input must be free()'d
3507 rxvt_term::get_to_st (unicode_t &ends_how)
3509 unicode_t seen_esc = 0, ch;
3512 unsigned char string[STRING_MAX];
3514 while ((ch = cmd_getc ()) != NOCHAR)
3518 if (ch == 0x5c) /* 7bit ST */
3523 else if (ch == C0_ESC)
3528 else if (ch == C0_BEL || ch == CHAR_ST)
3531 return NULL; /* other control character - exit */
3535 if (n >= sizeof (string) - 1)
3536 // stop at some sane length
3540 string[n++] = cmd_get8 ();
3547 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3550 ends_how = (ch == 0x5c ? C0_ESC : ch);
3551 strncpy (s, string, n);
3555 /*----------------------------------------------------------------------*/
3557 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3560 rxvt_term::process_dcs_seq ()
3575 /*----------------------------------------------------------------------*/
3577 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3580 rxvt_term::process_osc_seq ()
3586 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3587 arg = arg * 10 + (ch - '0');
3591 unsigned char *s = get_to_st (eh);
3595 process_xterm_seq (arg, (char *)s, eh);
3602 rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3604 if (str[0] == '?' && !str[1])
3606 unsigned short r, g, b;
3607 pix_colors_focused[color].get (display, r, g, b);
3608 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3611 set_window_color (color, str);
3615 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3616 * 0 = change iconName/title
3617 * 1 = change iconName
3620 * 10 = change fg color
3621 * 11 = change bg color
3622 * 12 = change text color
3623 * 13 = change mouse foreground color
3624 * 17 = change highlight character colour
3625 * 18 = change bold character color
3626 * 19 = change underlined character color
3627 * 46 = change logfile (not implemented)
3632 * 39 = change default fg color
3633 * 49 = change default bg color
3634 * 55 = dump scrollback buffer and all of screen
3635 * 701 = change locale
3640 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3645 bool query = str[0] == '?' && !str[1];
3648 assert (str != NULL);
3654 case XTerm_iconName:
3655 set_icon_name (str);
3660 case XTerm_property:
3663 Atom prop = XInternAtom (display->display, str + 1, True);
3666 unsigned long nitems;
3667 unsigned long bytes_after;
3668 unsigned char *value = 0;
3669 const char *str = "";
3672 && XGetWindowProperty (display->display, TermWin.parent[0],
3673 prop, 0, 1<<16, 0, AnyPropertyType,
3674 &actual_type, &actual_format,
3675 &nitems, &bytes_after, &value) == Success
3676 && actual_type != None
3677 && actual_format == 8)
3678 str = (const char *)(value);
3680 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3686 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3691 XChangeProperty (display->display, TermWin.parent[0],
3692 display->atom (str), XA_STRING, 8,
3693 PropModeReplace, (unsigned char *)eq + 1,
3697 XDeleteProperty (display->display, TermWin.parent[0],
3698 display->atom (str));
3703 for (buf = (char *)str; buf && *buf;)
3705 if ((name = strchr (buf, ';')) == NULL)
3711 if (color < 0 || color >= TOTAL_COLORS)
3714 if ((buf = strchr (name, ';')) != NULL)
3717 if (name[0] == '?' && !name[1])
3719 unsigned short r, g, b;
3720 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3721 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3724 set_window_color (color + minCOLOR, name);
3728 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3731 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3733 #ifndef NO_CURSORCOLOR
3734 case XTerm_Color_cursor:
3735 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3738 case XTerm_Color_pointer_fg:
3739 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3741 case XTerm_Color_pointer_bg:
3742 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3744 #ifndef NO_BOLD_UNDERLINE_REVERSE
3745 case XTerm_Color_BD:
3746 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3748 case XTerm_Color_IT:
3749 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3751 case XTerm_Color_UL:
3752 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3754 case XTerm_Color_RV:
3755 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3758 #if TRANSPARENT || TINTING
3759 case XTerm_Color_tint:
3760 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3761 check_our_parents ();
3763 want_full_refresh = want_refresh = 1;
3771 scale_pixmap (""); /* reset to default scaling */
3772 set_bgPixmap (str); /* change pixmap */
3776 while ((str = strchr (str, ';')) != NULL)
3780 changed += scale_pixmap (str);
3786 #ifdef XPM_BACKGROUND
3793 case XTerm_restoreFG:
3794 set_window_color (Color_fg, str);
3796 case XTerm_restoreBG:
3797 set_window_color (Color_bg, str);
3801 // TODO, when secure mode?
3808 case URxvt_boldFont:
3809 case URxvt_italicFont:
3810 case URxvt_boldItalicFont:
3813 tt_printf ("\33]%d;%-.250s%c", saveop,
3814 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc
3815 ? TermWin.fontset[op - URxvt_font]->fontdesc : "",
3819 const char *&res = rs[Rs_font + (op - URxvt_font)];
3822 allocated.push_back ((void *)res);
3830 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3843 if (options & Opt_insecure)
3844 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3848 case XTerm_dumpscreen: /* no error notices */
3851 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3861 /*----------------------------------------------------------------------*/
3863 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3865 * mode can only have the following values:
3871 * so no need for fancy checking
3874 rxvt_term::privcases (int mode, unsigned long bit)
3880 SavedModes |= (priv_modes & bit);
3886 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3888 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3889 PrivMode (state, bit);
3895 /* we're not using priv _yet_ */
3897 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3905 const unsigned long bit;
3909 { 1, PrivMode_aplCUR },
3910 { 2, PrivMode_vt52 },
3911 { 3, PrivMode_132 },
3912 { 4, PrivMode_smoothScroll },
3913 { 5, PrivMode_rVideo },
3914 { 6, PrivMode_relOrigin },
3915 { 7, PrivMode_Autowrap },
3916 // 8, bi-directional support mode
3917 { 9, PrivMode_MouseX10 },
3919 { menuBar_esc, PrivMode_menuBar },
3921 // 18, 19 printing-related
3922 { 25, PrivMode_VisibleCursor },
3923 #ifdef scrollBar_esc
3924 { scrollBar_esc, PrivMode_scrollBar },
3926 { 35, PrivMode_ShiftKeys }, // rxvt extension
3927 { 40, PrivMode_132OK },
3928 // 41 xterm more fixes NYI
3929 // 45 margin bell NYI
3931 { 47, PrivMode_Screen },
3932 { 66, PrivMode_aplKP },
3933 #ifndef NO_BACKSPACE_KEY
3934 { 67, PrivMode_BackSpace },
3936 { 1000, PrivMode_MouseX11 },
3937 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3938 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3939 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3940 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3941 { 1011, PrivMode_Keypress }, // rxvt extension
3942 // 1035 enable modifiers for alt, numlock NYI
3943 // 1036 send ESC for meta keys NYI
3944 // 1037 send DEL for keypad delete NYI
3945 { 1047, PrivMode_Screen },
3946 // 1048 save and restore cursor
3947 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3948 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3954 /* make lo/hi boolean */
3956 mode = 0; /* reset */
3957 else if (mode == 'h')
3960 for (i = 0; i < nargs; i++)
3964 /* basic handling */
3965 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
3966 if (argtopriv[j].argval == arg[i])
3968 state = privcases (mode, argtopriv[j].bit);
3972 /* extra handling for values with state unkept */
3975 case 1048: /* alternative cursor save */
3977 if (options & Opt_secondaryScreen)
3979 scr_cursor (RESTORE);
3986 /* extra handling for values with valid 0 or 1 state */
3989 /* case 1: - application cursor keys */
3990 case 2: /* VT52 mode */
3991 /* oddball mode. should be set regardless of set/reset
3992 * parameter. Return from VT52 mode with an ESC < from
3995 PrivMode (1, PrivMode_vt52);
3997 case 3: /* 80/132 */
3998 if (priv_modes & PrivMode_132OK)
3999 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
4001 case 4: /* smooth scrolling */
4003 options &= ~Opt_jumpScroll;
4005 options |= Opt_jumpScroll;
4007 case 5: /* reverse video */
4008 scr_rvideo_mode (state);
4010 case 6: /* relative/absolute origins */
4011 scr_relative_origin (state);
4013 case 7: /* autowrap */
4014 scr_autowrap (state);
4016 /* case 8: - auto repeat, can't do on a per window basis */
4017 case 9: /* X10 mouse reporting */
4018 if (state) /* orthogonal */
4019 priv_modes &= ~PrivMode_MouseX11;
4024 map_menuBar (state);
4028 #ifdef scrollBar_esc
4030 if (scrollbar_mapping (state))
4032 resize_all_windows (0, 0, 0);
4037 case 25: /* visible/invisible cursor */
4038 scr_cursor_visible (state);
4040 /* case 35: - shift keys */
4041 /* case 40: - 80 <--> 132 mode */
4042 case 47: /* secondary screen */
4043 scr_change_screen (state);
4045 /* case 66: - application key pad */
4046 /* case 67: - backspace key */
4047 case 1000: /* X11 mouse reporting */
4048 if (state) /* orthogonal */
4049 priv_modes &= ~PrivMode_MouseX10;
4053 break; /* X11 mouse highlighting */
4055 case 1010: /* scroll to bottom on TTY output inhibit */
4057 options &= ~Opt_scrollTtyOutput;
4059 options |= Opt_scrollTtyOutput;
4061 case 1011: /* scroll to bottom on key press */
4063 options |= Opt_scrollTtyKeypress;
4065 options &= ~Opt_scrollTtyKeypress;
4067 case 1047: /* secondary screen w/ clearing last */
4068 if (options & Opt_secondaryScreen)
4069 if (current_screen != PRIMARY)
4070 scr_erase_screen (2);
4071 scr_change_screen (state);
4073 case 1049: /* secondary screen w/ clearing first */
4074 scr_change_screen (state);
4075 if (options & Opt_secondaryScreen)
4076 if (current_screen != PRIMARY)
4077 scr_erase_screen (2);
4086 /*{{{ process sgr sequences */
4088 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4096 scr_rendition (0, ~RS_None);
4100 for (i = 0; i < nargs; i++)
4106 rendset = 0, rendstyle = ~RS_None;
4109 rendset = 1, rendstyle = RS_Bold;
4111 //case 2: // low intensity
4113 rendset = 1, rendstyle = RS_Italic;
4116 rendset = 1, rendstyle = RS_Uline;
4118 case 5: // slowly blinking
4119 case 6: // rapidly blinking
4120 rendset = 1, rendstyle = RS_Blink;
4122 //case 6: // scoansi light background
4124 rendset = 1, rendstyle = RS_RVid;
4129 //case 9: // crossed out
4130 //case 10: // scoansi acs off, primary font
4131 //case 11: // scoansi acs on, first alt font
4132 //case 12: // scoansi acs on, |0x80, second alt font
4134 //case 19: // ninth alt font
4135 //case 20: // gothic
4136 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4137 rendset = 0, rendstyle = RS_Bold;
4139 case 22: // normal intensity
4140 rendset = 0, rendstyle = RS_Bold;
4142 case 23: // disable italic
4143 rendset = 0, rendstyle = RS_Italic;
4146 rendset = 0, rendstyle = RS_Uline;
4149 rendset = 0, rendstyle = RS_Blink;
4151 case 26: // variable spacing (iso 8613)
4152 rendset = 0, rendstyle = RS_Blink;
4155 rendset = 0, rendstyle = RS_RVid;
4157 //case 28: // visible. NYI
4158 //case 29: // not crossed-out
4163 scr_rendition (rendset, rendstyle);
4164 continue; /* for (;i;) */
4170 case 31: /* set fg color */
4177 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4179 case 38: // set fg color, ISO 8613-6
4180 if (nargs > i + 2 && arg[i + 1] == 5)
4182 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4186 case 39: /* default fg */
4187 scr_color (Color_fg, Color_fg);
4191 case 41: /* set bg color */
4198 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4200 case 48: // set bg color, ISO 8613-6
4201 if (nargs > i + 2 && arg[i + 1] == 5)
4203 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4207 case 49: /* default bg */
4208 scr_color (Color_bg, Color_bg);
4211 //case 50: // not variable spacing
4213 #ifndef NO_BRIGHTCOLOR
4215 case 91: /* set bright fg color */
4222 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4225 case 101: /* set bright bg color */
4232 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4241 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4243 rxvt_term::process_graphics ()
4245 unicode_t ch, cmd = cmd_getc ();
4248 { /* query graphics */
4249 tt_printf ("\033G0\012"); /* no graphics */
4252 /* swallow other graphics sequences until terminating ':' */
4259 /* ------------------------------------------------------------------------- */
4262 * Send printf () formatted output to the command.
4263 * Only use for small amounts of data.
4266 rxvt_term::tt_printf (const char *fmt,...)
4269 unsigned char buf[256];
4271 va_start (arg_ptr, fmt);
4272 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4274 tt_write (buf, strlen (buf));
4277 /* ---------------------------------------------------------------------- */
4278 /* Write data to the pty as typed by the user, pasted with the mouse,
4279 * or generated by us in response to a query ESC sequence.
4282 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4284 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4290 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4292 if ((unsigned int)written == len)
4300 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4302 memcpy (v_buffer + v_buflen, data, len);
4308 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4312 v_buflen -= written;
4320 pty_ev.set (EVENT_READ);
4324 memmove (v_buffer, v_buffer + written, v_buflen);
4326 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4327 // original code just ignores this...
4331 pty_ev.set (EVENT_READ | EVENT_WRITE);
4337 /*----------------------- end-of-file (C source) -----------------------*/