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 */
918 if (want_full_refresh)
920 want_full_refresh = 0;
928 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)
1221 Window unused_root, unused_child;
1222 int unused_root_x, unused_root_y;
1223 unsigned int unused_mask;
1229 if (!(iso14755buf & ISO_14755_52))
1231 lookup_key (ev.xkey);
1237 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1240 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1243 #if ENABLE_FRILLS || ISO_14755
1244 // ISO 14755 support
1246 if (iso14755buf & ISO_14755_52)
1252 // iso14755 part 5.2 handling: release time
1254 if ((ev.xkey.state & ControlMask)
1255 && ((ks >= 0x40 && ks <= 0x5f)
1256 || (ks >= 0x61 && ks <= 0x7f)))
1258 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1260 return; // case-break;
1263 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1266 iso14755buf = ISO_14755_51 | i[1];
1268 return; // case-break;
1276 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1281 if (iso14755buf & ISO_14755_51)
1284 else if (iso14755buf & ISO_14755_STARTED)
1286 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1288 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1289 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1297 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1298 if (!(ev.xkey.state & ControlMask))
1299 slip_wheel_ev.stop ();
1300 else if (ks == XK_Control_L || ks == XK_Control_R)
1301 mouse_slip_wheel_speed = 0;
1307 button_press (ev.xbutton);
1311 button_release (ev.xbutton);
1315 if (ev.xclient.format == 32
1316 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1319 /* OffiX Dnd (drag 'n' drop) protocol */
1320 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1321 && (ev.xclient.data.l[0] == DndFile
1322 || ev.xclient.data.l[0] == DndDir
1323 || ev.xclient.data.l[0] == DndLink))
1328 unsigned char *data;
1329 unsigned long Size, RemainingBytes;
1331 XGetWindowProperty (display->display, display->root,
1332 xa[XA_DNDSELECTION],
1334 False, AnyPropertyType,
1335 &ActualType, &ActualFormat,
1336 &Size, &RemainingBytes,
1338 XChangeProperty (display->display, display->root,
1339 XA_CUT_BUFFER0, XA_STRING,
1341 data, strlen (data));
1343 selection_paste (display->root, XA_CUT_BUFFER0, True);
1344 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1346 #endif /* OFFIX_DND */
1350 XRefreshKeyboardMapping (&ev.xmapping);
1354 * XXX: this is not the _current_ arrangement
1355 * Here's my conclusion:
1356 * If the window is completely unobscured, use bitblt's
1357 * to scroll. Even then, they're only used when doing partial
1358 * screen scrolling. When partially obscured, we have to fill
1359 * in the GraphicsExpose parts, which means that after each refresh,
1360 * we need to wait for the graphics expose or Noexpose events,
1361 * which ought to make things real slow!
1363 case VisibilityNotify:
1364 switch (ev.xvisibility.state)
1366 case VisibilityUnobscured:
1367 refresh_type = FAST_REFRESH;
1369 case VisibilityPartiallyObscured:
1370 refresh_type = SLOW_REFRESH;
1373 refresh_type = NO_REFRESH;
1384 if (Input_Context != NULL)
1386 IMSetStatusPosition ();
1387 XSetICFocus (Input_Context);
1391 if (options & Opt_cursorBlink)
1392 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1394 #ifdef OFF_FOCUS_FADING
1397 pix_colors = pix_colors_focused;
1411 #if ENABLE_FRILLS || ISO_14755
1418 if (Input_Context != NULL)
1419 XUnsetICFocus (Input_Context);
1422 if (options & Opt_cursorBlink)
1423 cursor_blink_ev.stop ();
1426 #ifdef OFF_FOCUS_FADING
1429 pix_colors = pix_colors_unfocused;
1436 case ConfigureNotify:
1437 if (ev.xconfigure.window == TermWin.parent[0])
1442 { /* Wrap lots of configures into one */
1443 width = ev.xconfigure.width;
1444 height = ev.xconfigure.height;
1445 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1447 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev));
1449 if (szHint.width != width || szHint.height != height)
1452 resize_all_windows (width, height, 1);
1455 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1456 if (options & Opt_transparent)
1458 check_our_parents ();
1460 want_refresh = want_full_refresh = 1;
1466 case PropertyNotify:
1467 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1468 && ev.xproperty.state == PropertyNewValue)
1469 selection_property (ev.xproperty.window, ev.xproperty.atom);
1473 case SelectionClear:
1477 case SelectionNotify:
1478 if (selection_wait == Sel_normal)
1479 selection_paste (ev.xselection.requestor,
1480 ev.xselection.property, True);
1483 case SelectionRequest:
1484 selection_send (ev.xselectionrequest);
1490 text_blink_ev.stop ();
1497 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1502 case ReparentNotify:
1505 #endif /* TRANSPARENT */
1507 case GraphicsExpose:
1509 if (ev.xany.window == TermWin.vt)
1512 scr_expose (ev.xexpose.x, ev.xexpose.y,
1513 ev.xexpose.width, ev.xexpose.height, False);
1514 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev));
1516 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1518 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev))
1519 scr_expose (ev.xexpose.x, ev.xexpose.y,
1520 ev.xexpose.width, ev.xexpose.height, False);
1522 scr_refresh (refresh_type);
1526 XEvent unused_event;
1528 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event))
1530 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event))
1533 if (isScrollbarWindow (ev.xany.window))
1535 scrollBar.setIdle ();
1539 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1544 if (am_transparent && ev.xany.window == TermWin.parent[0])
1545 XClearWindow (display->display, ev.xany.window);
1551 #ifdef POINTER_BLANK
1556 if (isMenuBarWindow (ev.xany.window))
1558 menubar_control (ev.xbutton);
1562 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1565 if (ev.xany.window == TermWin.vt)
1567 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1569 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev))
1572 XQueryPointer (display->display, TermWin.vt,
1573 &unused_root, &unused_child,
1574 &unused_root_x, &unused_root_y,
1575 &ev.xbutton.x, &ev.xbutton.y,
1577 #ifdef MOUSE_THRESHOLD
1578 /* deal with a `jumpy' mouse */
1579 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1584 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1586 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1590 selection_extend (ev.xbutton.x, ev.xbutton.y,
1591 ev.xbutton.state & Button3Mask ? 2 : 0);
1593 #ifdef SELECTION_SCROLLING
1594 if (ev.xbutton.y < TermWin.int_bwidth
1595 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1))
1599 /* don't clobber the current delay if we are
1600 * already in the middle of scrolling.
1602 if (!sel_scroll_ev.active)
1603 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1605 /* save the event params so we can highlight
1606 * the selection in the pending-scroll loop
1608 selection_save_x = ev.xbutton.x;
1609 selection_save_y = ev.xbutton.y;
1610 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1612 /* calc number of lines to scroll */
1613 if (ev.xbutton.y < TermWin.int_bwidth)
1615 scroll_selection_dir = UP;
1616 dist = TermWin.int_bwidth - ev.xbutton.y;
1620 scroll_selection_dir = DN;
1621 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height);
1624 scroll_selection_lines = Pixel2Height (dist)
1625 / SELECTION_SCROLL_LINE_SPEEDUP
1627 MIN_IT (scroll_selection_lines,
1628 SELECTION_SCROLL_MAX_LINES);
1632 /* we are within the text window, so we
1633 * shouldn't be scrolling
1635 if (sel_scroll_ev.active)
1636 sel_scroll_ev.stop();
1639 #ifdef MOUSE_THRESHOLD
1644 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1646 while (XCheckTypedWindowEvent (display->display, scrollBar.win,
1650 XQueryPointer (display->display, scrollBar.win,
1651 &unused_root, &unused_child,
1652 &unused_root_x, &unused_root_y,
1653 &ev.xbutton.x, &ev.xbutton.y,
1655 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1657 scr_refresh (refresh_type);
1667 rxvt_term::rootwin_cb (XEvent &ev)
1670 SET_LOCALE (locale);
1674 case PropertyNotify:
1676 * if user used some Esetroot compatible prog to set the root bg,
1677 * use the property to determine the pixmap. We use it later on.
1679 if (xa[XA_XROOTPMAPID] == 0)
1680 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1682 if (ev.xproperty.atom != xa[XA_XROOTPMAPID])
1686 case ReparentNotify:
1687 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1688 want_refresh = want_full_refresh = 1;
1695 rxvt_term::button_press (XButtonEvent &ev)
1697 int reportmode = 0, clickintime;
1699 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1700 if (!bypass_keystate)
1701 reportmode = !! (priv_modes & PrivMode_mouse_report);
1704 * VT window processing of button press
1706 if (ev.window == TermWin.vt)
1710 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1712 iso14755_54 (ev.x, ev.y);
1717 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1721 /* mouse report from vt window */
1722 /* save the xbutton state (for ButtonRelease) */
1723 MEvent.state = ev.state;
1724 #ifdef MOUSE_REPORT_DOUBLECLICK
1725 if (ev.button == MEvent.button && clickintime)
1727 /* same button, within alloted time */
1729 if (MEvent.clicks > 1)
1731 /* only report double clicks */
1735 /* don't report the release */
1737 MEvent.button = AnyButton;
1742 /* different button, or time expired */
1744 MEvent.button = ev.button;
1748 MEvent.button = ev.button;
1750 #endif /* MOUSE_REPORT_DOUBLECLICK */
1755 if (ev.button != MEvent.button)
1761 /* allow meta + click to select rectangular areas */
1762 /* should be done in screen.C */
1764 selection.rect = !! (ev.state & ModMetaMask);
1766 selection.rect = false;
1769 /* allow shift+left click to extend selection */
1770 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1772 if (MEvent.button == Button1 && clickintime)
1773 selection_rotate (ev.x, ev.y);
1775 selection_extend (ev.x, ev.y, 1);
1779 if (MEvent.button == Button1 && clickintime)
1784 selection_click (MEvent.clicks, ev.x, ev.y);
1787 MEvent.button = Button1;
1791 if (MEvent.button == Button3 && clickintime)
1792 selection_rotate (ev.x, ev.y);
1794 selection_extend (ev.x, ev.y, 1);
1796 MEvent.button = Button3;
1801 MEvent.time = ev.time;
1806 * Scrollbar window processing of button press
1808 if (isScrollbarWindow (ev.window))
1810 scrollBar.setIdle ();
1812 * Rxvt-style scrollbar:
1813 * move up if mouse is above slider
1814 * move dn if mouse is below slider
1816 * XTerm-style scrollbar:
1817 * Move display proportional to pointer location
1818 * pointer near top -> scroll one line
1819 * pointer near bot -> scroll full page
1821 #ifndef NO_SCROLLBAR_REPORT
1825 * Mouse report disabled scrollbar:
1826 * arrow buttons - send up/down
1827 * click on scrollbar - send pageup/down
1829 if ((scrollBar.style == R_SB_NEXT
1830 && scrollbarnext_upButton (ev.y))
1831 || (scrollBar.style == R_SB_RXVT
1832 && scrollbarrxvt_upButton (ev.y)))
1833 tt_printf ("\033[A");
1834 else if ((scrollBar.style == R_SB_NEXT
1835 && scrollbarnext_dnButton (ev.y))
1836 || (scrollBar.style == R_SB_RXVT
1837 && scrollbarrxvt_dnButton (ev.y)))
1838 tt_printf ("\033[B");
1846 tt_printf ("\033[6~");
1849 tt_printf ("\033[5~");
1854 #endif /* NO_SCROLLBAR_REPORT */
1859 if (scrollBar.style == R_SB_NEXT)
1861 if (scrollbarnext_upButton (ev.y))
1862 upordown = -1; /* up */
1863 else if (scrollbarnext_dnButton (ev.y))
1864 upordown = 1; /* down */
1866 else if (scrollBar.style == R_SB_RXVT)
1868 if (scrollbarrxvt_upButton (ev.y))
1869 upordown = -1; /* up */
1870 else if (scrollbarrxvt_dnButton (ev.y))
1871 upordown = 1; /* down */
1875 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1876 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1878 if (scr_page (upordown < 0 ? UP : DN, 1))
1890 switch (scrollbar_align)
1892 case R_SB_ALIGN_TOP:
1895 case R_SB_ALIGN_CENTRE:
1896 csrO = (scrollBar.bot - scrollBar.top) / 2;
1898 case R_SB_ALIGN_BOTTOM:
1899 csrO = scrollBar.bot - scrollBar.top;
1903 if (scrollBar.style == R_SB_XTERM
1904 || scrollbar_above_slider (ev.y)
1905 || scrollbar_below_slider (ev.y))
1906 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
1908 scrollBar.setMotion ();
1912 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1913 csrO = ev.y - scrollBar.top;
1917 if (scrollBar.style != R_SB_XTERM)
1919 if (scrollbar_above_slider (ev.y))
1920 # ifdef RXVT_SCROLL_FULL
1921 scr_page (UP, TermWin.nrow - 1);
1923 scr_page (UP, TermWin.nrow / 4);
1925 else if (scrollbar_below_slider (ev.y))
1926 # ifdef RXVT_SCROLL_FULL
1927 scr_page (DN, TermWin.nrow - 1);
1929 scr_page (DN, TermWin.nrow / 4);
1932 scrollBar.setMotion ();
1936 scr_page ((ev.button == Button1 ? DN : UP),
1938 * scrollbar_position (ev.y)
1939 / scrollbar_size ()));
1949 * Menubar window processing of button press
1951 if (isMenuBarWindow (ev.window))
1952 menubar_control (ev);
1957 rxvt_term::button_release (XButtonEvent &ev)
1961 csrO = 0; /* reset csr Offset */
1962 if (!bypass_keystate)
1963 reportmode = !! (priv_modes & PrivMode_mouse_report);
1965 if (scrollbar_isUpDn ())
1967 scrollBar.setIdle ();
1969 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1970 refresh_type &= ~SMOOTH_REFRESH;
1974 #ifdef SELECTION_SCROLLING
1975 if (sel_scroll_ev.active)
1976 sel_scroll_ev.stop();
1979 if (ev.window == TermWin.vt)
1983 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1988 /* mouse report from vt window */
1989 /* don't report release of wheel "buttons" */
1992 #ifdef MOUSE_REPORT_DOUBLECLICK
1993 /* only report the release of 'slow' single clicks */
1994 if (MEvent.button != AnyButton
1995 && (ev.button != MEvent.button
1996 || (ev.time - MEvent.time
1997 > MULTICLICK_TIME / 2)))
2000 MEvent.button = AnyButton;
2003 #else /* MOUSE_REPORT_DOUBLECLICK */
2004 MEvent.button = AnyButton;
2006 #endif /* MOUSE_REPORT_DOUBLECLICK */
2011 * dumb hack to compensate for the failure of click-and-drag
2012 * when overriding mouse reporting
2014 if (priv_modes & PrivMode_mouse_report
2016 && ev.button == Button1 && MEvent.clicks <= 1)
2017 selection_extend (ev.x, ev.y, 0);
2023 selection_make (ev.time);
2026 selection_request (ev.time, ev.x, ev.y);
2035 v = ev.button == Button4 ? UP : DN;
2037 if (ev.state & ShiftMask)
2039 else if (options & Opt_mouseWheelScrollPage)
2040 i = TermWin.nrow - 1;
2044 # ifdef MOUSE_SLIP_WHEELING
2045 if (ev.state & ControlMask)
2047 mouse_slip_wheel_speed += v ? -1 : 1;
2048 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow;
2049 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2051 if (slip_wheel_ev.at < NOW)
2052 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2054 slip_wheel_ev.start ();
2059 # ifdef JUMP_MOUSE_WHEEL
2061 scr_refresh (SMOOTH_REFRESH);
2067 scr_refresh (SMOOTH_REFRESH);
2071 # ifdef MOUSE_SLIP_WHEELING
2080 else if (isMenuBarWindow (ev.window))
2081 menubar_control (ev);
2087 /* taken from aterm-0.4.2 */
2089 typedef uint32_t RUINT32T;
2091 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2093 int sh_r, sh_g, sh_b;
2094 RUINT32T mask_r, mask_g, mask_b;
2095 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2096 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2097 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2100 Visual* visual = display->visual;
2102 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2104 /* for convenience */
2105 mask_r = visual->red_mask;
2106 mask_g = visual->green_mask;
2107 mask_b = visual->blue_mask;
2109 /* boring lookup table pre-initialization */
2110 switch (srcImage->bits_per_pixel) {
2112 if ((mask_r != 0x7c00) ||
2113 (mask_g != 0x03e0) ||
2116 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2118 lookup_g = lookup+32;
2119 lookup_b = lookup+32+32;
2125 if ((mask_r != 0xf800) ||
2126 (mask_g != 0x07e0) ||
2129 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2131 lookup_g = lookup+32;
2132 lookup_b = lookup+32+64;
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 if ((mask_r != 0xff0000) ||
2152 (mask_g != 0x00ff00) ||
2153 (mask_b != 0x0000ff))
2155 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2157 lookup_g = lookup+256;
2158 lookup_b = lookup+256+256;
2164 return; /* we do not support this color depth */
2167 /* prepare limits for color transformation (each channel is handled separately) */
2170 if (shade < 0) shade = 0;
2171 if (shade > 100) shade = 100;
2173 lower_lim_r = 65535-rm;
2174 lower_lim_g = 65535-gm;
2175 lower_lim_b = 65535-bm;
2177 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2178 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2179 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2181 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2183 if (shade < 0) shade = 0;
2184 if (shade > 100) shade = 100;
2186 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2188 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2189 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2190 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2193 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2194 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2199 lower_lim_r = lower_lim_b;
2203 upper_lim_r = upper_lim_b;
2207 /* fill our lookup tables */
2208 for (i = 0; i <= mask_r>>sh_r; i++)
2211 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2212 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2213 lookup_r[i] = (tmp/65535)<<sh_r;
2215 for (i = 0; i <= mask_g>>sh_g; i++)
2218 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2219 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2220 lookup_g[i] = (tmp/65535)<<sh_g;
2222 for (i = 0; i <= mask_b>>sh_b; i++)
2225 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2226 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2227 lookup_b[i] = (tmp/65535)<<sh_b;
2230 /* apply table to input image (replacing colors by newly calculated ones) */
2231 switch (srcImage->bits_per_pixel)
2235 unsigned short *p1, *pf, *p, *pl;
2236 p1 = (unsigned short *) srcImage->data;
2237 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2241 pl = p1 + srcImage->width;
2244 *p = lookup_r[(*p & 0x7c00)>>10] |
2245 lookup_g[(*p & 0x03e0)>> 5] |
2246 lookup_b[(*p & 0x001f)];
2248 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2254 unsigned short *p1, *pf, *p, *pl;
2255 p1 = (unsigned short *) srcImage->data;
2256 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2260 pl = p1 + srcImage->width;
2263 *p = lookup_r[(*p & 0xf800)>>11] |
2264 lookup_g[(*p & 0x07e0)>> 5] |
2265 lookup_b[(*p & 0x001f)];
2267 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2273 unsigned char *p1, *pf, *p, *pl;
2274 p1 = (unsigned char *) srcImage->data;
2275 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2279 pl = p1 + srcImage->width * 3;
2280 for (; p < pl; p += 3)
2282 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2283 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2284 p[2] = lookup_r[(p[2] & 0x0000ff)];
2286 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2292 RUINT32T *p1, *pf, *p, *pl;
2293 p1 = (RUINT32T *) srcImage->data;
2294 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2299 pl = p1 + srcImage->width;
2302 *p = lookup_r[(*p & 0xff0000)>>16] |
2303 lookup_g[(*p & 0x00ff00)>> 8] |
2304 lookup_b[(*p & 0x0000ff)] |
2307 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2318 * Check our parents are still who we think they are.
2319 * Do transparency updates if required
2322 rxvt_term::check_our_parents ()
2324 int i, pchanged, aformat, have_pixmap, rootdepth;
2325 unsigned long nitems, bytes_after;
2327 unsigned char *prop = NULL;
2328 Window root, oldp, *list;
2329 Pixmap rootpixmap = None;
2330 XWindowAttributes wattr, wrootattr;
2334 if (!(options & Opt_transparent))
2335 return pchanged; /* Don't try any more */
2337 XGetWindowAttributes (display->display, display->root, &wrootattr);
2338 rootdepth = wrootattr.depth;
2340 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2342 if (rootdepth != wattr.depth)
2347 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2348 am_transparent = am_pixmap_trans = 0;
2351 return pchanged; /* Don't try any more */
2354 /* Get all X ops out of the queue so that our information is up-to-date. */
2355 XSync (display->display, False);
2358 * Make the frame window set by the window manager have
2359 * the root background. Some window managers put multiple nested frame
2360 * windows for each client, so we have to take care about that.
2362 i = (xa[XA_XROOTPMAPID]
2363 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID],
2364 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2365 &nitems, &bytes_after, &prop) == Success);
2367 if (!i || prop == NULL)
2368 i = (xa[XA_XSETROOTID]
2369 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID],
2370 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2371 &nitems, &bytes_after, &prop) == Success);
2373 if (!i || prop == NULL
2375 || !rs[Rs_color + Color_tint]
2382 rootpixmap = *(Pixmap *)prop;
2389 * Copy display->root pixmap transparency
2392 unsigned int nw, nh;
2398 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
2399 0, 0, &sx, &sy, &cr);
2400 nw = (unsigned int)szHint.width;
2401 nh = (unsigned int)szHint.height;
2418 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2419 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2421 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2423 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2424 /* XXX: may need a delay here? */
2429 if (am_transparent && am_pixmap_trans)
2432 if (TermWin.pixmap != None)
2434 XFreePixmap (display->display, TermWin.pixmap);
2435 TermWin.pixmap = None;
2439 am_pixmap_trans = 0;
2443 if (TermWin.pixmap != None)
2444 XFreePixmap (display->display, TermWin.pixmap);
2447 if (ISSET_PIXCOLOR (Color_tint))
2449 unsigned short rm, gm, bm;
2450 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2452 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2454 ShadeXImage (display, image, shade, rm, gm, bm);
2458 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
2459 szHint.width, szHint.height, image->depth);
2460 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue);
2461 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0,
2462 nx, ny, image->width, image->height);
2463 XFreeGC (display->display, gc);
2464 XDestroyImage (image);
2465 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap);
2466 XClearWindow (display->display, TermWin.parent[0]);
2468 if (!am_transparent || !am_pixmap_trans)
2471 am_transparent = am_pixmap_trans = 1;
2475 if (!am_pixmap_trans)
2479 * InheritPixmap transparency
2481 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2483 oldp = TermWin.parent[i];
2484 XQueryTree (display->display, TermWin.parent[i - 1], &root,
2485 &TermWin.parent[i], &list, &n);
2488 if (TermWin.parent[i] == display->root)
2496 if (oldp != TermWin.parent[i])
2504 for (; n < (unsigned int)i; n++)
2506 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr);
2507 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2509 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2515 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2517 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]);
2518 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2520 /* XXX: also turn off Opt_transparent? */
2525 /* wait (an arbitrary period) for the WM to do its thing
2526 * needed for fvwm2.2.2 (and before?) */
2529 for (n = 0; n < (unsigned int)i; n++)
2531 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative);
2532 XClearWindow (display->display, TermWin.parent[n]);
2535 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2539 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2540 TermWin.parent[i] = None;
2545 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative);
2546 scrollBar.setIdle ();
2557 rxvt_term::cmd_parse ()
2560 unicode_t ch = NOCHAR;
2561 unsigned char *seq_begin; // remember start of esc-sequence here
2567 seq_begin = cmdbuf_ptr;
2571 if (ch == NOCHAR) // TODO: improve
2574 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2579 // many badly-written programs (e.g. jed) contain a race condition:
2580 // they first read the screensize and then install a SIGWINCH handler.
2581 // some window managers resize the window early, and these programs
2582 // then sometimes get the size wrong.
2583 // unfortunately other programs are even more buggy and dislike
2584 // being sent SIGWINCH, so only do it when we were in fact being
2587 kill (-cmd_pid, SIGWINCH);
2590 /* Read a text string from the input buffer */
2591 unicode_t buf[UBUFSIZ];
2592 bool refreshnow = false;
2594 unicode_t *str = buf;
2598 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2608 if (!(options & Opt_jumpScroll)
2609 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2616 // scr_add_lines only works for nlines <= TermWin.nrow - 1.
2617 if (nlines >= TermWin.nrow - 1)
2619 scr_add_lines (buf, nlines, str - buf);
2625 if (str >= buf + UBUFSIZ)
2631 seq_begin = cmdbuf_ptr;
2635 scr_add_lines (buf, nlines, str - buf);
2638 * If there have been a lot of new lines, then update the screen
2639 * What the heck I'll cheat and only refresh less than every page-full.
2640 * the number of pages between refreshes is refresh_limit, which
2641 * is incremented here because we must be doing flat-out scrolling.
2645 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2650 scr_refresh (refresh_type);
2659 process_nonprinting (ch);
2661 catch (const class out_of_input &o)
2663 // we ran out of input, retry later
2664 cmdbuf_ptr = seq_begin;
2675 // read the next octet
2677 rxvt_term::next_octet ()
2679 return cmdbuf_ptr < cmdbuf_endp
2684 // read the next character
2686 rxvt_term::next_char ()
2688 while (cmdbuf_ptr < cmdbuf_endp)
2690 // assume 7-bit to be ascii ALWAYS
2691 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2692 return *cmdbuf_ptr++;
2695 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2697 if (len == (size_t)-2)
2699 // the mbstate stores incomplete sequences. didn't know this :/
2700 cmdbuf_ptr = cmdbuf_endp;
2704 if (len == (size_t)-1)
2705 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2707 // assume wchar == unicode
2715 /* rxvt_cmd_getc () - Return next input character */
2717 * Return the next input character after first passing any keyboard input
2721 rxvt_term::cmd_getc ()
2723 unicode_t c = next_char ();
2732 rxvt_term::cmd_get8 ()
2734 unicode_t c = next_octet ();
2743 /*----------------------------------------------------------------------*/
2746 rxvt_term::popen_printer ()
2748 FILE *stream = popen (rs[Rs_print_pipe], "w");
2751 rxvt_warn ("can't open printer pipe, not printing.\n");
2757 rxvt_term::pclose_printer (FILE *stream)
2760 return pclose (stream);
2764 * simulate attached vt100 printer
2767 rxvt_term::process_print_pipe ()
2772 if ((fd = popen_printer ()) == NULL)
2776 * Send all input to the printer until either ESC[4i or ESC[?4i
2779 for (done = 0; !done;)
2781 unsigned char buf[8];
2783 unsigned int i, len;
2785 if ((ch = cmd_getc ()) != C0_ESC)
2787 if (putc (ch, fd) == EOF)
2788 break; /* done = 1 */
2795 if ((buf[len++] = cmd_getc ()) == '[')
2797 if ((ch = cmd_getc ()) == '?')
2802 if ((buf[len++] = ch) == '4')
2804 if ((buf[len++] = cmd_getc ()) == 'i')
2805 break; /* done = 1 */
2809 for (i = 0; i < len; i++)
2810 if (putc (buf[i], fd) == EOF)
2818 pclose_printer (fd);
2820 #endif /* PRINTPIPE */
2826 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2827 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2828 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2829 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2833 /*{{{ process non-printing single characters */
2835 rxvt_term::process_nonprinting (unicode_t ch)
2840 process_escape_seq ();
2842 case C0_ENQ: /* terminal Status */
2843 if (rs[Rs_answerbackstring])
2844 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2845 (unsigned int)strlen (rs[Rs_answerbackstring]));
2847 tt_write ((unsigned char *)VT100_ANS,
2848 (unsigned int)strlen (VT100_ANS));
2850 case C0_BEL: /* bell */
2853 case C0_BS: /* backspace */
2856 case C0_HT: /* tab */
2859 case C0_CR: /* carriage return */
2860 scr_gotorc (0, 0, R_RELATIVE);
2862 case C0_VT: /* vertical tab, form feed */
2864 case C0_LF: /* line feed */
2867 case C0_SO: /* shift out - acs */
2868 scr_charset_choose (1);
2870 case C0_SI: /* shift in - acs */
2871 scr_charset_choose (0);
2874 #ifdef EIGHT_BIT_CONTROLS
2876 case 0x90: /* DCS */
2879 case 0x9b: /* CSI */
2882 case 0x9d: /* CSI */
2891 /*{{{ process VT52 escape sequences */
2893 rxvt_term::process_escape_vt52 (unicode_t ch)
2899 case 'A': /* cursor up */
2900 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2902 case 'B': /* cursor down */
2903 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2905 case 'C': /* cursor right */
2906 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2908 case 'D': /* cursor left */
2909 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2911 case 'H': /* cursor home */
2912 scr_gotorc (0, 0, 0);
2914 case 'I': /* cursor up and scroll down if needed */
2917 case 'J': /* erase to end of screen */
2918 scr_erase_screen (0);
2920 case 'K': /* erase to end of line */
2923 case 'Y': /* move to specified row and col */
2924 /* full command is 'ESC Y row col' where row and col
2925 * are encoded by adding 32 and sending the ascii
2926 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2928 row = cmd_getc () - ' ';
2929 col = cmd_getc () - ' ';
2930 scr_gotorc (row, col, 0);
2932 case 'Z': /* identify the terminal type */
2933 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2935 case '<': /* turn off VT52 mode */
2936 PrivMode (0, PrivMode_vt52);
2938 case 'F': /* use special graphics character set */
2939 case 'G': /* use regular character set */
2942 case '=': /* use alternate keypad mode */
2943 case '>': /* use regular keypad mode */
2951 /*{{{ process escape sequences */
2953 rxvt_term::process_escape_seq ()
2955 unicode_t ch = cmd_getc ();
2957 if (priv_modes & PrivMode_vt52)
2959 process_escape_vt52 (ch);
2965 /* case 1: do_tek_mode (); break; */
2967 if (cmd_getc () == '8')
2971 scr_charset_set (0, (unsigned int)cmd_getc ());
2974 scr_charset_set (1, (unsigned int)cmd_getc ());
2977 scr_charset_set (2, (unsigned int)cmd_getc ());
2980 scr_charset_set (3, (unsigned int)cmd_getc ());
2991 scr_cursor (RESTORE);
2995 scr_forwardindex ();
3000 PrivMode ((ch == '='), PrivMode_aplKP);
3010 /* 8.3.87: NEXT LINE */
3011 case C1_NEL: /* ESC E */
3013 unicode_t nlcr[] = { C0_LF, C0_CR };
3014 scr_add_lines (nlcr, 1, 2);
3018 /* kidnapped escape sequence: Should be 8.3.48 */
3019 case C1_ESA: /* ESC G */
3020 process_graphics ();
3023 /* 8.3.63: CHARACTER TABULATION SET */
3024 case C1_HTS: /* ESC H */
3028 /* 8.3.105: REVERSE LINE FEED */
3029 case C1_RI: /* ESC M */
3033 /* 8.3.142: SINGLE-SHIFT TWO */
3034 /*case C1_SS2: scr_single_shift (2); break; */
3036 /* 8.3.143: SINGLE-SHIFT THREE */
3037 /*case C1_SS3: scr_single_shift (3); break; */
3039 /* 8.3.27: DEVICE CONTROL STRING */
3040 case C1_DCS: /* ESC P */
3044 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3045 case C1_SCI: /* ESC Z */
3046 tt_write ((const unsigned char *)ESCZ_ANSWER,
3047 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3048 break; /* steal obsolete ESC [ c */
3050 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3051 case C1_CSI: /* ESC [ */
3055 /* 8.3.90: OPERATING SYSTEM COMMAND */
3056 case C1_OSC: /* ESC ] */
3060 /* 8.3.106: RESET TO INITIAL STATE */
3067 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3069 scr_charset_choose (2);
3072 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3074 scr_charset_choose (3);
3080 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3084 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3085 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3086 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3087 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3088 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3089 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3090 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3091 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3094 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3095 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3096 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3097 #define get_byte_array_bit(array, bit) \
3098 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3100 const unsigned char csi_defaults[] =
3102 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3103 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3104 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3105 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3106 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3107 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3108 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3109 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3114 rxvt_term::process_csi_seq ()
3116 unicode_t ch, priv, i;
3117 unsigned int nargs, p;
3121 for (nargs = ESC_ARGS; nargs > 0;)
3126 if (ch >= '<' && ch <= '?')
3127 { /* '<' '=' '>' '?' */
3132 /* read any numerical arguments */
3133 for (n = -1; ch < CSI_ICH; )
3140 n = n * 10 + ch - '0';
3144 if (nargs < ESC_ARGS)
3148 else if (IS_CONTROL (ch))
3149 process_nonprinting (ch);
3157 if (nargs < ESC_ARGS)
3161 ndef = get_byte_array_bit (csi_defaults, i);
3162 for (p = 0; p < nargs; p++)
3167 fprintf (stderr, "CSI ");
3168 for (p = 0; p < nargs; p++)
3169 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3170 fprintf (stderr, "%c\n", ch);
3174 * private mode handling
3181 if (ch == CSI_DA) /* secondary device attributes */
3182 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING);
3185 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3186 process_terminal_mode (ch, priv, nargs, arg);
3195 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3198 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3201 case 0: /* initiate transfer to primary aux device */
3202 scr_printscreen (0);
3204 case 5: /* start relay to primary aux device */
3205 process_print_pipe ();
3211 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3212 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3215 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3216 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3217 scr_gotorc (arg[0], 0, RELATIVE);
3220 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3221 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3224 #else /* emulate common DEC VTs */
3225 arg[0] = arg[0] ? -arg[0] : -1;
3228 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3229 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3231 scr_gotorc (0, arg[0], RELATIVE);
3232 #else /* emulate common DEC VTs */
3233 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3237 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3240 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3241 scr_gotorc (arg[0], 0, R_RELATIVE);
3244 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3245 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3246 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3249 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3250 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3253 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3254 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3255 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3258 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3261 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3265 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3266 scr_erase_screen (arg[0]);
3269 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3270 scr_erase_line (arg[0]);
3273 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3274 scr_insdel_chars (arg[0], INSERT);
3277 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3278 scr_insdel_lines (arg[0], INSERT);
3281 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3282 scr_insdel_lines (arg[0], DELETE);
3285 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3286 scr_insdel_chars (arg[0], ERASE);
3289 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3290 scr_insdel_chars (arg[0], DELETE);
3293 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3296 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3297 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
3300 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3301 tt_write ((const unsigned char *)VT100_ANS,
3302 (unsigned int) (sizeof (VT100_ANS) - 1));
3305 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3306 process_sgr_mode (nargs, arg);
3309 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3312 case 5: /* DSR requested */
3313 tt_printf ("\033[0n");
3315 case 6: /* CPR requested */
3316 scr_report_position ();
3318 case 7: /* unofficial extension */
3319 if (options & Opt_insecure)
3320 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3322 case 8: /* unofficial extension */
3323 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3328 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3331 case 0: /* char tab stop cleared at active position */
3334 /* case 1: */ /* line tab stop cleared in active line */
3335 /* case 2: */ /* char tab stops cleared in active line */
3336 case 3: /* all char tab stops are cleared */
3337 /* case 4: */ /* all line tab stops are cleared */
3338 case 5: /* all tab stops are cleared */
3344 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3347 case 0: /* char tab stop set at active position */
3349 break; /* = ESC H */
3350 /* case 1: */ /* line tab stop set at active line */
3351 case 2: /* char tab stop cleared at active position */
3353 break; /* = ESC [ 0 g */
3354 /* case 3: */ /* line tab stop cleared at active line */
3355 /* case 4: */ /* char tab stops cleared at active line */
3356 case 5: /* all char tab stops are cleared */
3358 break; /* = ESC [ 3 g */
3359 /* case 6: */ /* all line tab stops are cleared */
3363 case CSI_RM: /* 8.3.107: RESET MODE */
3365 scr_insert_mode (0);
3366 else if (arg[0] == 20)
3367 priv_modes &= ~PrivMode_LFNL;
3370 case CSI_SM: /* 8.3.126: SET MODE */
3372 scr_insert_mode (1);
3373 else if (arg[0] == 20)
3374 priv_modes |= PrivMode_LFNL;
3378 * PRIVATE USE beyond this point. All CSI_7? sequences here
3380 case CSI_72: /* DECSTBM: set top and bottom margins */
3382 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3383 else if (nargs == 0 || arg[0] >= arg[1])
3384 scr_scroll_region (0, MAX_ROWS - 1);
3386 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3393 scr_cursor (RESTORE);
3398 process_window_ops (arg, nargs);
3402 case CSI_78: /* DECREQTPARM */
3403 if (arg[0] == 0 || arg[0] == 1)
3404 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3416 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3419 XWindowAttributes wattr;
3430 case 1: /* deiconify window */
3431 XMapWindow (display->display, TermWin.parent[0]);
3433 case 2: /* iconify window */
3434 XIconifyWindow (display->display, TermWin.parent[0],
3435 DefaultScreen (display->display));
3437 case 3: /* set position (pixels) */
3438 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]);
3440 case 4: /* set size (pixels) */
3441 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3443 case 5: /* raise window */
3444 XRaiseWindow (display->display, TermWin.parent[0]);
3446 case 6: /* lower window */
3447 XLowerWindow (display->display, TermWin.parent[0]);
3449 case 7: /* refresh window */
3452 case 8: /* set size (chars) */
3453 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
3454 (unsigned int) (args[1] * TermWin.fheight));
3457 //case 9: NYI, TODO, restore maximized window or maximize window
3459 if (args[0] >= 24) /* set height (chars) */
3460 set_widthheight ((unsigned int)TermWin.width,
3461 (unsigned int) (args[1] * TermWin.fheight));
3466 * reports - some output format copied from XTerm
3468 case 11: /* report window state */
3469 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3470 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3472 case 13: /* report window position */
3473 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3474 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root,
3475 -wattr.border_width, -wattr.border_width,
3477 tt_printf ("\033[3;%d;%dt", x, y);
3479 case 14: /* report window size (pixels) */
3480 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3481 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3483 case 18: /* report text area size (chars) */
3484 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3486 case 19: /* report window size (chars) */
3487 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3489 case 20: /* report icon label */
3492 XGetIconName (display->display, TermWin.parent[0], &s);
3493 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3497 case 21: /* report window title */
3500 XFetchName (display->display, TermWin.parent[0], &s);
3501 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3509 /*----------------------------------------------------------------------*/
3511 * get input up until STRING TERMINATOR (or BEL)
3512 * ends_how is terminator used. returned input must be free()'d
3515 rxvt_term::get_to_st (unicode_t &ends_how)
3517 unicode_t seen_esc = 0, ch;
3520 unsigned char string[STRING_MAX];
3522 while ((ch = cmd_getc ()) != NOCHAR)
3526 if (ch == 0x5c) /* 7bit ST */
3531 else if (ch == C0_ESC)
3536 else if (ch == C0_BEL || ch == CHAR_ST)
3539 return NULL; /* other control character - exit */
3543 if (n >= sizeof (string) - 1)
3544 // stop at some sane length
3548 string[n++] = cmd_get8 ();
3555 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3558 ends_how = (ch == 0x5c ? C0_ESC : ch);
3559 strncpy (s, string, n);
3563 /*----------------------------------------------------------------------*/
3565 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3568 rxvt_term::process_dcs_seq ()
3583 /*----------------------------------------------------------------------*/
3585 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3588 rxvt_term::process_osc_seq ()
3594 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3595 arg = arg * 10 + (ch - '0');
3599 unsigned char *s = get_to_st (eh);
3603 process_xterm_seq (arg, (char *)s, eh);
3610 rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3612 if (str[0] == '?' && !str[1])
3614 unsigned short r, g, b;
3615 pix_colors_focused[color].get (display, r, g, b);
3616 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3619 set_window_color (color, str);
3623 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3624 * 0 = change iconName/title
3625 * 1 = change iconName
3628 * 10 = change fg color
3629 * 11 = change bg color
3630 * 12 = change text color
3631 * 13 = change mouse foreground color
3632 * 17 = change highlight character colour
3633 * 18 = change bold character color
3634 * 19 = change underlined character color
3635 * 46 = change logfile (not implemented)
3640 * 39 = change default fg color
3641 * 49 = change default bg color
3642 * 55 = dump scrollback buffer and all of screen
3643 * 701 = change locale
3648 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3653 bool query = str[0] == '?' && !str[1];
3656 assert (str != NULL);
3662 case XTerm_iconName:
3663 set_icon_name (str);
3668 case XTerm_property:
3671 Atom prop = XInternAtom (display->display, str + 1, True);
3674 unsigned long nitems;
3675 unsigned long bytes_after;
3676 unsigned char *value = 0;
3677 const char *str = "";
3680 && XGetWindowProperty (display->display, TermWin.parent[0],
3681 prop, 0, 1<<16, 0, AnyPropertyType,
3682 &actual_type, &actual_format,
3683 &nitems, &bytes_after, &value) == Success
3684 && actual_type != None
3685 && actual_format == 8)
3686 str = (const char *)(value);
3688 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3694 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3699 XChangeProperty (display->display, TermWin.parent[0],
3700 display->atom (str), XA_STRING, 8,
3701 PropModeReplace, (unsigned char *)eq + 1,
3705 XDeleteProperty (display->display, TermWin.parent[0],
3706 display->atom (str));
3711 for (buf = (char *)str; buf && *buf;)
3713 if ((name = strchr (buf, ';')) == NULL)
3719 if (color < 0 || color >= TOTAL_COLORS)
3722 if ((buf = strchr (name, ';')) != NULL)
3725 if (name[0] == '?' && !name[1])
3727 unsigned short r, g, b;
3728 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3729 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3732 set_window_color (color + minCOLOR, name);
3736 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3739 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3741 #ifndef NO_CURSORCOLOR
3742 case XTerm_Color_cursor:
3743 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3746 case XTerm_Color_pointer_fg:
3747 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3749 case XTerm_Color_pointer_bg:
3750 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3752 #ifndef NO_BOLD_UNDERLINE_REVERSE
3753 case XTerm_Color_BD:
3754 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3756 case XTerm_Color_IT:
3757 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3759 case XTerm_Color_UL:
3760 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3762 case XTerm_Color_RV:
3763 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3766 #if TRANSPARENT && TINTING
3767 case XTerm_Color_tint:
3768 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3769 check_our_parents ();
3771 want_full_refresh = want_refresh = 1;
3779 scale_pixmap (""); /* reset to default scaling */
3780 set_bgPixmap (str); /* change pixmap */
3784 while ((str = strchr (str, ';')) != NULL)
3788 changed += scale_pixmap (str);
3794 #ifdef XPM_BACKGROUND
3801 case XTerm_restoreFG:
3802 set_window_color (Color_fg, str);
3804 case XTerm_restoreBG:
3805 set_window_color (Color_bg, str);
3809 // TODO, when secure mode?
3816 case URxvt_boldFont:
3817 case URxvt_italicFont:
3818 case URxvt_boldItalicFont:
3821 tt_printf ("\33]%d;%-.250s%c", saveop,
3822 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc
3823 ? TermWin.fontset[op - URxvt_font]->fontdesc : "",
3827 const char *&res = rs[Rs_font + (op - URxvt_font)];
3830 allocated.push_back ((void *)res);
3838 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3851 if (options & Opt_insecure)
3852 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3856 case XTerm_dumpscreen: /* no error notices */
3859 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3869 /*----------------------------------------------------------------------*/
3871 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3873 * mode can only have the following values:
3879 * so no need for fancy checking
3882 rxvt_term::privcases (int mode, unsigned long bit)
3888 SavedModes |= (priv_modes & bit);
3894 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3896 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3897 PrivMode (state, bit);
3903 /* we're not using priv _yet_ */
3905 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3913 const unsigned long bit;
3917 { 1, PrivMode_aplCUR },
3918 { 2, PrivMode_vt52 },
3919 { 3, PrivMode_132 },
3920 { 4, PrivMode_smoothScroll },
3921 { 5, PrivMode_rVideo },
3922 { 6, PrivMode_relOrigin },
3923 { 7, PrivMode_Autowrap },
3924 // 8, bi-directional support mode
3925 { 9, PrivMode_MouseX10 },
3927 { menuBar_esc, PrivMode_menuBar },
3929 // 18, 19 printing-related
3930 { 25, PrivMode_VisibleCursor },
3931 #ifdef scrollBar_esc
3932 { scrollBar_esc, PrivMode_scrollBar },
3934 { 35, PrivMode_ShiftKeys }, // rxvt extension
3935 { 40, PrivMode_132OK },
3936 // 41 xterm more fixes NYI
3937 // 45 margin bell NYI
3939 { 47, PrivMode_Screen },
3940 { 66, PrivMode_aplKP },
3941 #ifndef NO_BACKSPACE_KEY
3942 { 67, PrivMode_BackSpace },
3944 { 1000, PrivMode_MouseX11 },
3945 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3946 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3947 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3948 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3949 { 1011, PrivMode_Keypress }, // rxvt extension
3950 // 1035 enable modifiers for alt, numlock NYI
3951 // 1036 send ESC for meta keys NYI
3952 // 1037 send DEL for keypad delete NYI
3953 { 1047, PrivMode_Screen },
3954 // 1048 save and restore cursor
3955 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3956 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3962 /* make lo/hi boolean */
3964 mode = 0; /* reset */
3965 else if (mode == 'h')
3968 for (i = 0; i < nargs; i++)
3972 /* basic handling */
3973 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
3974 if (argtopriv[j].argval == arg[i])
3976 state = privcases (mode, argtopriv[j].bit);
3980 /* extra handling for values with state unkept */
3983 case 1048: /* alternative cursor save */
3985 if (options & Opt_secondaryScreen)
3987 scr_cursor (RESTORE);
3994 /* extra handling for values with valid 0 or 1 state */
3997 /* case 1: - application cursor keys */
3998 case 2: /* VT52 mode */
3999 /* oddball mode. should be set regardless of set/reset
4000 * parameter. Return from VT52 mode with an ESC < from
4003 PrivMode (1, PrivMode_vt52);
4005 case 3: /* 80/132 */
4006 if (priv_modes & PrivMode_132OK)
4007 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
4009 case 4: /* smooth scrolling */
4011 options &= ~Opt_jumpScroll;
4013 options |= Opt_jumpScroll;
4015 case 5: /* reverse video */
4016 scr_rvideo_mode (state);
4018 case 6: /* relative/absolute origins */
4019 scr_relative_origin (state);
4021 case 7: /* autowrap */
4022 scr_autowrap (state);
4024 /* case 8: - auto repeat, can't do on a per window basis */
4025 case 9: /* X10 mouse reporting */
4026 if (state) /* orthogonal */
4027 priv_modes &= ~PrivMode_MouseX11;
4032 map_menuBar (state);
4036 #ifdef scrollBar_esc
4038 if (scrollbar_mapping (state))
4040 resize_all_windows (0, 0, 0);
4045 case 25: /* visible/invisible cursor */
4046 scr_cursor_visible (state);
4048 /* case 35: - shift keys */
4049 /* case 40: - 80 <--> 132 mode */
4050 case 47: /* secondary screen */
4051 scr_change_screen (state);
4053 /* case 66: - application key pad */
4054 /* case 67: - backspace key */
4055 case 1000: /* X11 mouse reporting */
4056 if (state) /* orthogonal */
4057 priv_modes &= ~PrivMode_MouseX10;
4061 break; /* X11 mouse highlighting */
4063 case 1010: /* scroll to bottom on TTY output inhibit */
4065 options &= ~Opt_scrollTtyOutput;
4067 options |= Opt_scrollTtyOutput;
4069 case 1011: /* scroll to bottom on key press */
4071 options |= Opt_scrollTtyKeypress;
4073 options &= ~Opt_scrollTtyKeypress;
4075 case 1047: /* secondary screen w/ clearing last */
4076 if (options & Opt_secondaryScreen)
4077 if (current_screen != PRIMARY)
4078 scr_erase_screen (2);
4079 scr_change_screen (state);
4081 case 1049: /* secondary screen w/ clearing first */
4082 scr_change_screen (state);
4083 if (options & Opt_secondaryScreen)
4084 if (current_screen != PRIMARY)
4085 scr_erase_screen (2);
4094 /*{{{ process sgr sequences */
4096 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4104 scr_rendition (0, ~RS_None);
4108 for (i = 0; i < nargs; i++)
4114 rendset = 0, rendstyle = ~RS_None;
4117 rendset = 1, rendstyle = RS_Bold;
4119 //case 2: // low intensity
4121 rendset = 1, rendstyle = RS_Italic;
4124 rendset = 1, rendstyle = RS_Uline;
4126 case 5: // slowly blinking
4127 case 6: // rapidly blinking
4128 rendset = 1, rendstyle = RS_Blink;
4130 //case 6: // scoansi light background
4132 rendset = 1, rendstyle = RS_RVid;
4137 //case 9: // crossed out
4138 //case 10: // scoansi acs off, primary font
4139 //case 11: // scoansi acs on, first alt font
4140 //case 12: // scoansi acs on, |0x80, second alt font
4142 //case 19: // ninth alt font
4143 //case 20: // gothic
4144 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4145 rendset = 0, rendstyle = RS_Bold;
4147 case 22: // normal intensity
4148 rendset = 0, rendstyle = RS_Bold;
4150 case 23: // disable italic
4151 rendset = 0, rendstyle = RS_Italic;
4154 rendset = 0, rendstyle = RS_Uline;
4157 rendset = 0, rendstyle = RS_Blink;
4159 case 26: // variable spacing (iso 8613)
4160 rendset = 0, rendstyle = RS_Blink;
4163 rendset = 0, rendstyle = RS_RVid;
4165 //case 28: // visible. NYI
4166 //case 29: // not crossed-out
4171 scr_rendition (rendset, rendstyle);
4172 continue; /* for (;i;) */
4178 case 31: /* set fg color */
4185 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4187 case 38: // set fg color, ISO 8613-6
4188 if (nargs > i + 2 && arg[i + 1] == 5)
4190 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4194 case 39: /* default fg */
4195 scr_color (Color_fg, Color_fg);
4199 case 41: /* set bg color */
4206 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4208 case 48: // set bg color, ISO 8613-6
4209 if (nargs > i + 2 && arg[i + 1] == 5)
4211 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4215 case 49: /* default bg */
4216 scr_color (Color_bg, Color_bg);
4219 //case 50: // not variable spacing
4221 #ifndef NO_BRIGHTCOLOR
4223 case 91: /* set bright fg color */
4230 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4233 case 101: /* set bright bg color */
4240 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4249 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4251 rxvt_term::process_graphics ()
4253 unicode_t ch, cmd = cmd_getc ();
4256 { /* query graphics */
4257 tt_printf ("\033G0\012"); /* no graphics */
4260 /* swallow other graphics sequences until terminating ':' */
4267 /* ------------------------------------------------------------------------- */
4270 * Send printf () formatted output to the command.
4271 * Only use for small amounts of data.
4274 rxvt_term::tt_printf (const char *fmt,...)
4277 unsigned char buf[256];
4279 va_start (arg_ptr, fmt);
4280 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4282 tt_write (buf, strlen (buf));
4285 /* ---------------------------------------------------------------------- */
4286 /* Write data to the pty as typed by the user, pasted with the mouse,
4287 * or generated by us in response to a query ESC sequence.
4290 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4292 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4298 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4300 if ((unsigned int)written == len)
4308 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4310 memcpy (v_buffer + v_buflen, data, len);
4316 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4320 v_buflen -= written;
4328 pty_ev.set (EVENT_READ);
4332 memmove (v_buffer, v_buffer + written, v_buflen);
4334 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4335 // original code just ignores this...
4339 pty_ev.set (EVENT_READ | EVENT_WRITE);
4345 /*----------------------- end-of-file (C source) -----------------------*/