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 */
56 /*----------------------------------------------------------------------*/
58 #define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
60 // exception thrown when the command parser runs out of input data
61 class out_of_input { } out_of_input;
63 #if ENABLE_FRILLS || ISO_14755
65 #define ISO_14755_STARTED 0x80000000UL
66 #define ISO_14755_51 0x40000000UL // basic (section 5.1)
67 #define ISO_14755_52 0x20000000UL // keycap (section 5.2)
68 #define ISO_14755_54 0x10000000UL // code feedback (section 5.4)
69 #define ISO_14755_MASK 0x0fffffffUL
72 static unsigned short iso14755_symtab[] = {
89 XK_ISO_Left_Tab, 0x21e6,
93 XK_Shift_Lock, 0x21eb,
98 XK_ISO_Level3_Shift, 0x21ee,
99 XK_ISO_Level3_Lock, 0x21ef,
100 XK_ISO_Group_Lock, 0x21f0,
108 XK_BackSpace, 0x232b,
110 XK_Control_L, 0x2388,
111 XK_Control_R, 0x2388,
124 rxvt_term::iso14755_54 (int x, int y)
129 if (x < 0 || x >= TermWin.ncol
130 || y < 0 || y >= TermWin.nrow)
135 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x];
137 if (t != NOCHAR || !x)
139 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x],
140 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
141 iso14755buf = ISO_14755_54;
153 rxvt_term::iso14755_51 (unicode_t ch, rend_t r)
155 rxvt_fontset *fs = FONTSET (r);
156 rxvt_font *f = (*fs)[fs->find_font (ch)];
157 wchar_t *chr, *alloc, ch2;
163 len = rxvt_composite.expand (ch, 0);
164 alloc = chr = new wchar_t[len];
165 rxvt_composite.expand (ch, chr);
177 int width = strlen (f->name);
179 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1);
181 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
183 for (int y = 0; y < len; y++)
189 sprintf (buf, "%8x", ch);
190 scr_overlay_set (0, y, buf);
191 scr_overlay_set (9, y, '=');
196 scr_overlay_set (11, y, ch, r);
197 scr_overlay_set (12, y, NOCHAR, r);
200 scr_overlay_set (0, len, f->name);
210 rxvt_term::commit_iso14755 ()
214 ch[0] = iso14755buf & ISO_14755_MASK;
217 if (iso14755buf & ISO_14755_51)
222 // allow verbatim 0-bytes and control-bytes to be entered
224 len = wcstombs (mb, ch, 16);
232 tt_write ((unsigned char *)mb, len);
241 rxvt_term::hex_keyval (XKeyEvent &ev)
243 // check wether this event corresponds to a hex digit
244 // if the modifiers had not been pressed.
245 for (int index = 0; index < 8; index++)
247 KeySym k = XLookupKeysym (&ev, index);
249 if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0;
250 else if (k >= XK_0 && k <= XK_9) return k - XK_0;
251 else if (k >= XK_a && k <= XK_f) return k - XK_a + 10;
252 else if (k >= XK_A && k <= XK_F) return k - XK_A + 10;
259 /*{{{ Convert the keypress event into a string */
261 rxvt_term::lookup_key (XKeyEvent &ev)
263 int ctrl, meta, shft, len;
267 static int debug_key = 1; /* accessible by a debugger only */
270 unsigned char kbuf[KBUFSZ];
273 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
274 * escape sequence to toggle the Keypad.
276 * Always permit `shift' to override the current setting
278 shft = (ev.state & ShiftMask);
279 ctrl = (ev.state & ControlMask);
280 meta = (ev.state & ModMetaMask);
282 if (numlock_state || (ev.state & ModNumLockMask))
284 numlock_state = (ev.state & ModNumLockMask);
285 PrivMode ((!numlock_state), PrivMode_aplKP);
293 Status status_return;
296 #ifdef X_HAVE_UTF8_STRING
297 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
298 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf,
299 KBUFSZ, &keysym, &status_return);
304 wchar_t wkbuf[KBUFSZ + 1];
306 // the XOpenIM manpage lies about hardcoding the locale
307 // at the point of XOpenIM, so temporarily switch locales
309 SET_LOCALE (rs[Rs_imLocale]);
310 // assume wchar_t == unicode or better
311 len = XwcLookupString (Input_Context, &ev, wkbuf,
312 KBUFSZ, &keysym, &status_return);
316 if (status_return == XLookupChars
317 || status_return == XLookupBoth)
319 /* make sure the user can type ctrl-@, i.e. NUL */
320 if (len == 1 && *wkbuf == 0)
328 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
337 valid_keysym = status_return == XLookupKeySym
338 || status_return == XLookupBoth;
343 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose);
344 valid_keysym = keysym != NoSymbol;
349 if (TermWin.saveLines)
351 #ifdef UNSHIFTED_SCROLLKEYS
359 #ifdef PAGING_CONTEXT_LINES
360 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES;
362 lnsppg = TermWin.nrow * 4 / 5;
364 if (keysym == XK_Prior)
366 scr_page (UP, lnsppg);
369 else if (keysym == XK_Next)
371 scr_page (DN, lnsppg);
375 #ifdef SCROLL_ON_UPDOWN_KEYS
383 else if (keysym == XK_Down)
390 #ifdef SCROLL_ON_HOMEEND_KEYS
393 if (keysym == XK_Home)
398 else if (keysym == XK_End)
409 /* Shift + F1 - F10 generates F11 - F20 */
410 if (keysym >= XK_F1 && keysym <= XK_F10)
412 keysym += (XK_F11 - XK_F1);
413 shft = 0; /* turn off Shift */
415 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
419 /* normal XTerm key bindings */
420 case XK_Insert: /* Shift+Insert = paste mouse selection */
421 selection_request (ev.time, 0, 0);
425 case XK_KP_Add: /* Shift+KP_Add = bigger font */
426 change_font (FONT_UP);
428 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
429 change_font (FONT_DN);
436 #if ENABLE_FRILLS || ISO_14755
442 if (iso14755buf & ISO_14755_51
443 && (keysym == XK_space || keysym == XK_KP_Space
444 || keysym == XK_Return || keysym == XK_KP_Enter))
447 iso14755buf = ISO_14755_51;
453 else if ((hv = hex_keyval (ev)) >= 0)
455 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
458 iso14755_51 (iso14755buf & ISO_14755_MASK);
470 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
471 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
472 if (!(iso14755buf & ISO_14755_STARTED))
474 iso14755buf |= ISO_14755_STARTED;
476 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
477 scr_overlay_set (0, 0, "ISO 14755 mode");
483 if (keysym == XK_Print)
485 scr_printscreen (ctrl | shft);
490 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
492 #ifdef KEYSYM_RESOURCE
493 if (!(shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
496 const unsigned char *kbuf0;
498 kbuf0 = (Keysym_map[keysym & 0xFF]);
499 l = (unsigned int)*kbuf0++;
504 && meta_char == C0_ESC
508 const unsigned char ch = C0_ESC;
521 #ifndef NO_BACKSPACE_KEY
523 if (priv_modes & PrivMode_HaveBackSpace)
525 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
526 ^ !!ctrl) ? '\b' : '\177';
530 strcpy (kbuf, key_backspace);
533 #ifndef NO_DELETE_KEY
535 strcpy (kbuf, key_delete);
540 strcpy (kbuf, "\033[Z");
543 #ifdef CTRL_TAB_MAKES_META
547 #ifdef MOD4_TAB_MAKES_META
548 if (ev.state & Mod4Mask)
556 case XK_KP_Up: /* \033Ox or standard */
557 case XK_KP_Down: /* \033Or or standard */
558 case XK_KP_Right: /* \033Ov or standard */
559 case XK_KP_Left: /* \033Ot or standard */
560 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
562 strcpy (kbuf, "\033OZ");
563 kbuf[2] = "txvr"[keysym - XK_KP_Left];
567 /* translate to std. cursor key */
568 keysym = XK_Left + (keysym - XK_KP_Left);
571 case XK_Up: /* "\033[A" */
572 case XK_Down: /* "\033[B" */
573 case XK_Right: /* "\033[C" */
574 case XK_Left: /* "\033[D" */
575 strcpy (kbuf, "\033[Z");
576 kbuf[2] = "DACB"[keysym - XK_Left];
579 kbuf[2] = "dacb"[keysym - XK_Left];
583 kbuf[2] = "dacb"[keysym - XK_Left];
585 else if (priv_modes & PrivMode_aplCUR)
589 #ifndef UNSHIFTED_SCROLLKEYS
592 /* allow shift to override */
593 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
595 strcpy (kbuf, "\033Oy");
601 strcpy (kbuf, "\033[5~");
605 /* allow shift to override */
606 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
608 strcpy (kbuf, "\033Os");
614 strcpy (kbuf, "\033[6~");
618 /* allow shift to override */
619 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
621 strcpy (kbuf, "\033OM");
628 if (priv_modes & PrivMode_LFNL)
643 strcpy (kbuf, "\033Ou");
647 strcpy (kbuf, "\033Op");
651 strcpy (kbuf, "\033On");
654 case XK_KP_F1: /* "\033OP" */
655 case XK_KP_F2: /* "\033OQ" */
656 case XK_KP_F3: /* "\033OR" */
657 case XK_KP_F4: /* "\033OS" */
658 strcpy (kbuf, "\033OP");
659 kbuf[2] += (keysym - XK_KP_F1);
662 case XK_KP_Multiply: /* "\033Oj" : "*" */
663 case XK_KP_Add: /* "\033Ok" : "+" */
664 case XK_KP_Separator: /* "\033Ol" : "," */
665 case XK_KP_Subtract: /* "\033Om" : "-" */
666 case XK_KP_Decimal: /* "\033On" : "." */
667 case XK_KP_Divide: /* "\033Oo" : "/" */
668 case XK_KP_0: /* "\033Op" : "0" */
669 case XK_KP_1: /* "\033Oq" : "1" */
670 case XK_KP_2: /* "\033Or" : "2" */
671 case XK_KP_3: /* "\033Os" : "3" */
672 case XK_KP_4: /* "\033Ot" : "4" */
673 case XK_KP_5: /* "\033Ou" : "5" */
674 case XK_KP_6: /* "\033Ov" : "6" */
675 case XK_KP_7: /* "\033Ow" : "7" */
676 case XK_KP_8: /* "\033Ox" : "8" */
677 case XK_KP_9: /* "\033Oy" : "9" */
678 /* allow shift to override */
679 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
681 strcpy (kbuf, "\033Oj");
682 kbuf[2] += (keysym - XK_KP_Multiply);
686 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
692 strcpy (kbuf, "\033[1~");
695 strcpy (kbuf, "\033[2~");
697 #ifdef DXK_Remove /* support for DEC remove like key */
702 strcpy (kbuf, "\033[3~");
705 strcpy (kbuf, "\033[4~");
709 /* allow shift to override */
710 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
712 strcpy (kbuf, "\033Oq");
718 strcpy (kbuf, KS_END);
722 /* allow shift to override */
723 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
725 strcpy (kbuf, "\033Ow");
731 strcpy (kbuf, KS_HOME);
734 #define FKEY(n, fkey) \
735 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
737 case XK_F1: /* "\033[11~" */
738 case XK_F2: /* "\033[12~" */
739 case XK_F3: /* "\033[13~" */
740 case XK_F4: /* "\033[14~" */
741 case XK_F5: /* "\033[15~" */
744 case XK_F6: /* "\033[17~" */
745 case XK_F7: /* "\033[18~" */
746 case XK_F8: /* "\033[19~" */
747 case XK_F9: /* "\033[20~" */
748 case XK_F10: /* "\033[21~" */
751 case XK_F11: /* "\033[23~" */
752 case XK_F12: /* "\033[24~" */
753 case XK_F13: /* "\033[25~" */
754 case XK_F14: /* "\033[26~" */
757 case XK_F15: /* "\033[28~" */
758 case XK_F16: /* "\033[29~" */
761 case XK_Help: /* "\033[28~" */
764 case XK_Menu: /* "\033[29~" */
767 case XK_F17: /* "\033[31~" */
768 case XK_F18: /* "\033[32~" */
769 case XK_F19: /* "\033[33~" */
770 case XK_F20: /* "\033[34~" */
771 case XK_F21: /* "\033[35~" */
772 case XK_F22: /* "\033[36~" */
773 case XK_F23: /* "\033[37~" */
774 case XK_F24: /* "\033[38~" */
775 case XK_F25: /* "\033[39~" */
776 case XK_F26: /* "\033[40~" */
777 case XK_F27: /* "\033[41~" */
778 case XK_F28: /* "\033[42~" */
779 case XK_F29: /* "\033[43~" */
780 case XK_F30: /* "\033[44~" */
781 case XK_F31: /* "\033[45~" */
782 case XK_F32: /* "\033[46~" */
783 case XK_F33: /* "\033[47~" */
784 case XK_F34: /* "\033[48~" */
785 case XK_F35: /* "\033[49~" */
791 && (keysym & 0xfff0) != 0xff70
792 && (keysym & 0xfff0) != 0xffe0)
793 /* generate a keycode for every remaining keypress */
794 sprintf ((char *)kbuf, "\033[%x;%xA", (unsigned char)ev.state, (unsigned short)keysym);
802 * Pass meta for all function keys, if 'meta' option set
805 if (meta && (meta_char == 0x80) && len > 0)
806 kbuf[len - 1] |= 0x80;
810 else if (ctrl && keysym == XK_minus)
813 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
815 else if (keysym == XK_ISO_Left_Tab)
817 strcpy (kbuf, "\033[Z");
821 && (keysym & 0xffe0) != 0xfe00
822 && (keysym < 0xfe50 || keysym > 0xfe6f))
824 /* generate a keycode for every remaining keypress */
825 len = sprintf ((char *)kbuf, "\033[%x;%xA", (unsigned char)ev.state, (unsigned short)keysym);
831 if (meta && (meta_char == 0x80))
835 for (ch = kbuf; ch < kbuf + len; ch++)
846 return; /* not mapped */
848 if (options & Opt_scrollTtyKeypress)
849 if (TermWin.view_start)
851 TermWin.view_start = 0;
856 * these modifications only affect the static keybuffer
857 * pass Shift/Control indicators for function keys ending with `~'
861 * Shift+Prior = "ESC[5$"
862 * Ctrl+Prior = "ESC[5^"
863 * Ctrl+Shift+Prior = "ESC[5@"
864 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
866 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
867 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
872 && meta_char == C0_ESC
876 const unsigned char ch = C0_ESC;
880 #if defined(DEBUG_CMD)
881 /* Display keyboard buffer contents */
885 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
886 for (i = 0, p = kbuf; i < len; i++, p++)
887 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
888 fprintf (stderr, "'\n");
889 #endif /* DEBUG_CMD */
890 tt_write (kbuf, (unsigned int)len);
895 /*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
896 /* attempt to `write' count to the input buffer */
898 rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
902 n = cmdbuf_ptr - cmdbuf_base;
903 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
905 if (n > 0 && s < count)
907 memmove (cmdbuf_base, cmdbuf_ptr,
908 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
909 cmdbuf_ptr = cmdbuf_base;
916 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
921 *cmdbuf_endp++ = *str++;
927 #endif /* MENUBAR_MAX */
935 if (want_full_refresh)
937 want_full_refresh = 0;
945 scr_refresh (refresh_type);
956 rxvt_term::check_cb (check_watcher &w)
963 if (want_refresh && !flush_ev.active)
964 flush_ev.start (NOW + 0.01);
968 rxvt_term::flush_cb (time_watcher &w)
980 rxvt_term::cursor_blink_cb (time_watcher &w)
982 hidden_cursor = !hidden_cursor;
985 w.start (w.at + BLINK_INTERVAL);
991 rxvt_term::text_blink_cb (time_watcher &w)
993 if (scr_refresh_rend (RS_Blink, RS_Blink))
995 hidden_text = !hidden_text;
997 w.start (w.at + TEXT_BLINK_INTERVAL);
1002 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1004 rxvt_term::cont_scroll_cb (time_watcher &w)
1006 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1007 scr_page (scrollbar_isUp() ? UP : DN, 1))
1009 refresh_type |= SMOOTH_REFRESH;
1011 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1016 #ifdef SELECTION_SCROLLING
1018 rxvt_term::sel_scroll_cb (time_watcher &w)
1020 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1022 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1023 refresh_type |= SMOOTH_REFRESH;
1025 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1030 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1032 rxvt_term::slip_wheel_cb (time_watcher &w)
1034 if (mouse_slip_wheel_speed == 0
1035 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1036 : scr_page (UP, mouse_slip_wheel_speed))
1038 refresh_type |= SMOOTH_REFRESH;
1040 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1046 rxvt_term::pty_fill ()
1048 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1052 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
1056 memmove (cmdbuf_base, cmdbuf_ptr, n);
1057 cmdbuf_ptr = cmdbuf_base;
1058 cmdbuf_endp = cmdbuf_ptr + n;
1060 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1067 else if (n < 0 && errno != EAGAIN)
1074 rxvt_term::pty_cb (io_watcher &w, short revents)
1077 SET_LOCALE (locale);
1079 if (revents & EVENT_READ)
1080 // loop, but don't allow a single term to monopolize us
1085 if (revents & EVENT_WRITE)
1090 rxvt_term::pointer_unblank ()
1092 XDefineCursor (display->display, TermWin.vt, TermWin_cursor);
1095 #ifdef POINTER_BLANK
1098 if (options & Opt_pointerBlank)
1099 pointer_ev.start (NOW + pointerBlankDelay);
1103 #ifdef POINTER_BLANK
1105 rxvt_term::pointer_blank ()
1107 if (! (options & Opt_pointerBlank))
1110 XDefineCursor (display->display, TermWin.vt, blank_cursor);
1111 XFlush (display->display);
1117 rxvt_term::pointer_cb (time_watcher &w)
1120 SET_LOCALE (locale);
1127 rxvt_term::mouse_report (XButtonEvent &ev)
1129 int button_number, key_state = 0;
1134 pixel_position (&x, &y);
1136 if (MEvent.button == AnyButton)
1140 button_number = MEvent.button - Button1;
1141 /* add 0x3D for wheel events, like xterm does */
1142 if (button_number >= 3)
1143 button_number += (64 - 3);
1146 if (priv_modes & PrivMode_MouseX10)
1149 * do not report ButtonRelease
1150 * no state info allowed
1153 if (button_number == 3)
1158 /* XTerm mouse reporting needs these values:
1162 * plus will add in our own Double-Click reporting
1165 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1166 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1167 + ((MEvent.state & ControlMask) ? 16 : 0);
1168 #ifdef MOUSE_REPORT_DOUBLECLICK
1169 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1173 #if DEBUG_MOUSEREPORT
1174 fprintf (stderr, "Mouse [");
1176 fputc ('C', stderr);
1178 fputc ('S', stderr);
1180 fputc ('A', stderr);
1182 fputc ('2', stderr);
1183 fprintf (stderr, "]: <%d>, %d/%d\n",
1189 tt_printf ("\033[M%c%c%c",
1190 (32 + button_number + key_state),
1197 rxvt_W11_process_x_event (XEvent *ev)
1199 rxvt_t *r = rxvt_get_r ();
1205 /*{{{ process an X event */
1207 rxvt_term::x_cb (XEvent &ev)
1210 SET_LOCALE (locale);
1212 #if defined(CURSOR_BLINK)
1213 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1221 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1225 #if defined(POINTER_BLANK)
1226 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1228 if (ev.type == MotionNotify
1229 || ev.type == ButtonPress
1230 || ev.type == ButtonRelease)
1234 if (ev.type == KeyPress && hidden_pointer == 0)
1239 Window unused_root, unused_child;
1240 int unused_root_x, unused_root_y;
1241 unsigned int unused_mask;
1247 if (!(iso14755buf & ISO_14755_52))
1249 lookup_key (ev.xkey);
1255 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1258 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1261 #if ENABLE_FRILLS || ISO_14755
1262 // ISO 14755 support
1264 if (iso14755buf & ISO_14755_52)
1270 // iso14755 part 5.2 handling: release time
1272 if ((ev.xkey.state & ControlMask)
1273 && ((ks >= 0x40 && ks <= 0x5f)
1274 || (ks >= 0x61 && ks <= 0x7f)))
1276 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1278 return; // case-break;
1281 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1284 iso14755buf = ISO_14755_51 | i[1];
1286 return; // case-break;
1294 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1299 if (iso14755buf & ISO_14755_51)
1302 else if (iso14755buf & ISO_14755_STARTED)
1304 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1306 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1307 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1315 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1316 if (!(ev.xkey.state & ControlMask))
1317 slip_wheel_ev.stop ();
1318 else if (ks == XK_Control_L || ks == XK_Control_R)
1319 mouse_slip_wheel_speed = 0;
1325 button_press (ev.xbutton);
1329 button_release (ev.xbutton);
1333 if (ev.xclient.format == 32
1334 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1337 /* OffiX Dnd (drag 'n' drop) protocol */
1338 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1339 && (ev.xclient.data.l[0] == DndFile
1340 || ev.xclient.data.l[0] == DndDir
1341 || ev.xclient.data.l[0] == DndLink))
1346 unsigned char *data;
1347 unsigned long Size, RemainingBytes;
1349 XGetWindowProperty (display->display, display->root,
1350 xa[XA_DNDSELECTION],
1352 False, AnyPropertyType,
1353 &ActualType, &ActualFormat,
1354 &Size, &RemainingBytes,
1356 set_string_property (XA_CUT_BUFFER0, data);
1358 selection_paste (display->root, XA_CUT_BUFFER0, true);
1359 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1361 #endif /* OFFIX_DND */
1365 XRefreshKeyboardMapping (&ev.xmapping);
1369 * XXX: this is not the _current_ arrangement
1370 * Here's my conclusion:
1371 * If the window is completely unobscured, use bitblt's
1372 * to scroll. Even then, they're only used when doing partial
1373 * screen scrolling. When partially obscured, we have to fill
1374 * in the GraphicsExpose parts, which means that after each refresh,
1375 * we need to wait for the graphics expose or Noexpose events,
1376 * which ought to make things real slow!
1378 case VisibilityNotify:
1379 switch (ev.xvisibility.state)
1381 case VisibilityUnobscured:
1382 refresh_type = FAST_REFRESH;
1384 case VisibilityPartiallyObscured:
1385 refresh_type = SLOW_REFRESH;
1388 refresh_type = NO_REFRESH;
1399 if (Input_Context != NULL)
1401 IMSetStatusPosition ();
1402 XSetICFocus (Input_Context);
1406 if (options & Opt_cursorBlink)
1407 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1409 #ifdef OFF_FOCUS_FADING
1412 pix_colors = pix_colors_focused;
1426 #if ENABLE_FRILLS || ISO_14755
1433 if (Input_Context != NULL)
1434 XUnsetICFocus (Input_Context);
1437 if (options & Opt_cursorBlink)
1438 cursor_blink_ev.stop ();
1441 #ifdef OFF_FOCUS_FADING
1444 pix_colors = pix_colors_unfocused;
1451 case ConfigureNotify:
1452 if (ev.xconfigure.window == TermWin.parent[0])
1457 { /* Wrap lots of configures into one */
1458 width = ev.xconfigure.width;
1459 height = ev.xconfigure.height;
1460 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1462 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev));
1464 if (szHint.width != width || szHint.height != height)
1467 resize_all_windows (width, height, 1);
1470 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1471 if (options & Opt_transparent)
1472 check_our_parents ();
1477 case PropertyNotify:
1478 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1479 && ev.xproperty.state == PropertyNewValue)
1480 selection_property (ev.xproperty.window, ev.xproperty.atom);
1484 case SelectionClear:
1488 case SelectionNotify:
1489 if (selection_wait == Sel_normal)
1490 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1493 case SelectionRequest:
1494 selection_send (ev.xselectionrequest);
1500 text_blink_ev.stop ();
1507 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1512 case ReparentNotify:
1515 #endif /* TRANSPARENT */
1517 case GraphicsExpose:
1519 if (ev.xany.window == TermWin.vt)
1522 scr_expose (ev.xexpose.x, ev.xexpose.y,
1523 ev.xexpose.width, ev.xexpose.height, False);
1524 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev));
1526 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1528 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev))
1529 scr_expose (ev.xexpose.x, ev.xexpose.y,
1530 ev.xexpose.width, ev.xexpose.height, False);
1532 scr_refresh (refresh_type);
1536 XEvent unused_event;
1538 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event))
1540 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event))
1543 if (isScrollbarWindow (ev.xany.window))
1545 scrollBar.setIdle ();
1549 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1554 if (am_transparent && ev.xany.window == TermWin.parent[0])
1555 XClearWindow (display->display, ev.xany.window);
1561 #ifdef POINTER_BLANK
1566 if (isMenuBarWindow (ev.xany.window))
1568 menubar_control (ev.xbutton);
1572 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1575 if (ev.xany.window == TermWin.vt)
1577 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1579 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev))
1582 XQueryPointer (display->display, TermWin.vt,
1583 &unused_root, &unused_child,
1584 &unused_root_x, &unused_root_y,
1585 &ev.xbutton.x, &ev.xbutton.y,
1587 #ifdef MOUSE_THRESHOLD
1588 /* deal with a `jumpy' mouse */
1589 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1594 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1596 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1600 selection_extend (ev.xbutton.x, ev.xbutton.y,
1601 ev.xbutton.state & Button3Mask ? 2 : 0);
1603 #ifdef SELECTION_SCROLLING
1604 if (ev.xbutton.y < TermWin.int_bwidth
1605 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1))
1609 /* don't clobber the current delay if we are
1610 * already in the middle of scrolling.
1612 if (!sel_scroll_ev.active)
1613 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1615 /* save the event params so we can highlight
1616 * the selection in the pending-scroll loop
1618 selection_save_x = ev.xbutton.x;
1619 selection_save_y = ev.xbutton.y;
1620 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1622 /* calc number of lines to scroll */
1623 if (ev.xbutton.y < TermWin.int_bwidth)
1625 scroll_selection_dir = UP;
1626 dist = TermWin.int_bwidth - ev.xbutton.y;
1630 scroll_selection_dir = DN;
1631 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height);
1634 scroll_selection_lines = Pixel2Height (dist)
1635 / SELECTION_SCROLL_LINE_SPEEDUP
1637 MIN_IT (scroll_selection_lines,
1638 SELECTION_SCROLL_MAX_LINES);
1642 /* we are within the text window, so we
1643 * shouldn't be scrolling
1645 if (sel_scroll_ev.active)
1646 sel_scroll_ev.stop();
1649 #ifdef MOUSE_THRESHOLD
1654 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1656 while (XCheckTypedWindowEvent (display->display, scrollBar.win,
1660 XQueryPointer (display->display, scrollBar.win,
1661 &unused_root, &unused_child,
1662 &unused_root_x, &unused_root_y,
1663 &ev.xbutton.x, &ev.xbutton.y,
1665 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1667 scr_refresh (refresh_type);
1677 rxvt_term::rootwin_cb (XEvent &ev)
1680 SET_LOCALE (locale);
1684 case PropertyNotify:
1686 * if user used some Esetroot compatible prog to set the root bg,
1687 * use the property to determine the pixmap. We use it later on.
1689 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1690 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1694 case ReparentNotify:
1695 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1696 want_refresh = want_full_refresh = 1;
1703 rxvt_term::button_press (XButtonEvent &ev)
1705 int reportmode = 0, clickintime;
1707 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1708 if (!bypass_keystate)
1709 reportmode = !! (priv_modes & PrivMode_mouse_report);
1712 * VT window processing of button press
1714 if (ev.window == TermWin.vt)
1718 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1720 iso14755_54 (ev.x, ev.y);
1725 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1729 /* mouse report from vt window */
1730 /* save the xbutton state (for ButtonRelease) */
1731 MEvent.state = ev.state;
1732 #ifdef MOUSE_REPORT_DOUBLECLICK
1733 if (ev.button == MEvent.button && clickintime)
1735 /* same button, within alloted time */
1737 if (MEvent.clicks > 1)
1739 /* only report double clicks */
1743 /* don't report the release */
1745 MEvent.button = AnyButton;
1750 /* different button, or time expired */
1752 MEvent.button = ev.button;
1756 MEvent.button = ev.button;
1758 #endif /* MOUSE_REPORT_DOUBLECLICK */
1763 if (ev.button != MEvent.button)
1769 /* allow meta + click to select rectangular areas */
1770 /* should be done in screen.C */
1772 selection.rect = !! (ev.state & ModMetaMask);
1774 selection.rect = false;
1777 /* allow shift+left click to extend selection */
1778 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1780 if (MEvent.button == Button1 && clickintime)
1781 selection_rotate (ev.x, ev.y);
1783 selection_extend (ev.x, ev.y, 1);
1787 if (MEvent.button == Button1 && clickintime)
1792 selection_click (MEvent.clicks, ev.x, ev.y);
1795 MEvent.button = Button1;
1799 if (MEvent.button == Button3 && clickintime)
1800 selection_rotate (ev.x, ev.y);
1802 selection_extend (ev.x, ev.y, 1);
1804 MEvent.button = Button3;
1809 MEvent.time = ev.time;
1814 * Scrollbar window processing of button press
1816 if (isScrollbarWindow (ev.window))
1818 scrollBar.setIdle ();
1820 * Rxvt-style scrollbar:
1821 * move up if mouse is above slider
1822 * move dn if mouse is below slider
1824 * XTerm-style scrollbar:
1825 * Move display proportional to pointer location
1826 * pointer near top -> scroll one line
1827 * pointer near bot -> scroll full page
1829 #ifndef NO_SCROLLBAR_REPORT
1833 * Mouse report disabled scrollbar:
1834 * arrow buttons - send up/down
1835 * click on scrollbar - send pageup/down
1837 if ((scrollBar.style == R_SB_NEXT
1838 && scrollbarnext_upButton (ev.y))
1839 || (scrollBar.style == R_SB_RXVT
1840 && scrollbarrxvt_upButton (ev.y)))
1841 tt_printf ("\033[A");
1842 else if ((scrollBar.style == R_SB_NEXT
1843 && scrollbarnext_dnButton (ev.y))
1844 || (scrollBar.style == R_SB_RXVT
1845 && scrollbarrxvt_dnButton (ev.y)))
1846 tt_printf ("\033[B");
1854 tt_printf ("\033[6~");
1857 tt_printf ("\033[5~");
1862 #endif /* NO_SCROLLBAR_REPORT */
1867 if (scrollBar.style == R_SB_NEXT)
1869 if (scrollbarnext_upButton (ev.y))
1870 upordown = -1; /* up */
1871 else if (scrollbarnext_dnButton (ev.y))
1872 upordown = 1; /* down */
1874 else if (scrollBar.style == R_SB_RXVT)
1876 if (scrollbarrxvt_upButton (ev.y))
1877 upordown = -1; /* up */
1878 else if (scrollbarrxvt_dnButton (ev.y))
1879 upordown = 1; /* down */
1883 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1884 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1886 if (scr_page (upordown < 0 ? UP : DN, 1))
1898 switch (scrollbar_align)
1900 case R_SB_ALIGN_TOP:
1903 case R_SB_ALIGN_CENTRE:
1904 csrO = (scrollBar.bot - scrollBar.top) / 2;
1906 case R_SB_ALIGN_BOTTOM:
1907 csrO = scrollBar.bot - scrollBar.top;
1911 if (scrollBar.style == R_SB_XTERM
1912 || scrollbar_above_slider (ev.y)
1913 || scrollbar_below_slider (ev.y))
1914 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
1916 scrollBar.setMotion ();
1920 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1921 csrO = ev.y - scrollBar.top;
1925 if (scrollBar.style != R_SB_XTERM)
1927 if (scrollbar_above_slider (ev.y))
1928 # ifdef RXVT_SCROLL_FULL
1929 scr_page (UP, TermWin.nrow - 1);
1931 scr_page (UP, TermWin.nrow / 4);
1933 else if (scrollbar_below_slider (ev.y))
1934 # ifdef RXVT_SCROLL_FULL
1935 scr_page (DN, TermWin.nrow - 1);
1937 scr_page (DN, TermWin.nrow / 4);
1940 scrollBar.setMotion ();
1944 scr_page ((ev.button == Button1 ? DN : UP),
1946 * scrollbar_position (ev.y)
1947 / scrollbar_size ()));
1957 * Menubar window processing of button press
1959 if (isMenuBarWindow (ev.window))
1960 menubar_control (ev);
1965 rxvt_term::button_release (XButtonEvent &ev)
1969 csrO = 0; /* reset csr Offset */
1970 if (!bypass_keystate)
1971 reportmode = !! (priv_modes & PrivMode_mouse_report);
1973 if (scrollbar_isUpDn ())
1975 scrollBar.setIdle ();
1977 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1978 refresh_type &= ~SMOOTH_REFRESH;
1982 #ifdef SELECTION_SCROLLING
1983 if (sel_scroll_ev.active)
1984 sel_scroll_ev.stop();
1987 if (ev.window == TermWin.vt)
1991 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1996 /* mouse report from vt window */
1997 /* don't report release of wheel "buttons" */
2000 #ifdef MOUSE_REPORT_DOUBLECLICK
2001 /* only report the release of 'slow' single clicks */
2002 if (MEvent.button != AnyButton
2003 && (ev.button != MEvent.button
2004 || (ev.time - MEvent.time
2005 > MULTICLICK_TIME / 2)))
2008 MEvent.button = AnyButton;
2011 #else /* MOUSE_REPORT_DOUBLECLICK */
2012 MEvent.button = AnyButton;
2014 #endif /* MOUSE_REPORT_DOUBLECLICK */
2019 * dumb hack to compensate for the failure of click-and-drag
2020 * when overriding mouse reporting
2022 if (priv_modes & PrivMode_mouse_report
2024 && ev.button == Button1 && MEvent.clicks <= 1)
2025 selection_extend (ev.x, ev.y, 0);
2031 selection_make (ev.time);
2034 selection_request (ev.time, ev.x, ev.y);
2043 v = ev.button == Button4 ? UP : DN;
2045 if (ev.state & ShiftMask)
2047 else if (options & Opt_mouseWheelScrollPage)
2048 i = TermWin.nrow - 1;
2052 # ifdef MOUSE_SLIP_WHEELING
2053 if (ev.state & ControlMask)
2055 mouse_slip_wheel_speed += v ? -1 : 1;
2056 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow;
2057 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2059 if (slip_wheel_ev.at < NOW)
2060 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2062 slip_wheel_ev.start ();
2067 # ifdef JUMP_MOUSE_WHEEL
2069 scr_refresh (SMOOTH_REFRESH);
2075 scr_refresh (SMOOTH_REFRESH);
2079 # ifdef MOUSE_SLIP_WHEELING
2088 else if (isMenuBarWindow (ev.window))
2089 menubar_control (ev);
2095 /* taken from aterm-0.4.2 */
2097 typedef uint32_t RUINT32T;
2099 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2101 int sh_r, sh_g, sh_b;
2102 RUINT32T mask_r, mask_g, mask_b;
2103 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2104 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2105 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2108 Visual* visual = display->visual;
2110 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2112 /* for convenience */
2113 mask_r = visual->red_mask;
2114 mask_g = visual->green_mask;
2115 mask_b = visual->blue_mask;
2117 /* boring lookup table pre-initialization */
2118 switch (srcImage->bits_per_pixel) {
2120 if ((mask_r != 0x7c00) ||
2121 (mask_g != 0x03e0) ||
2124 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2126 lookup_g = lookup+32;
2127 lookup_b = lookup+32+32;
2133 if ((mask_r != 0xf800) ||
2134 (mask_g != 0x07e0) ||
2137 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2139 lookup_g = lookup+32;
2140 lookup_b = lookup+32+64;
2146 if ((mask_r != 0xff0000) ||
2147 (mask_g != 0x00ff00) ||
2148 (mask_b != 0x0000ff))
2150 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2152 lookup_g = lookup+256;
2153 lookup_b = lookup+256+256;
2159 if ((mask_r != 0xff0000) ||
2160 (mask_g != 0x00ff00) ||
2161 (mask_b != 0x0000ff))
2163 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2165 lookup_g = lookup+256;
2166 lookup_b = lookup+256+256;
2172 return; /* we do not support this color depth */
2175 /* prepare limits for color transformation (each channel is handled separately) */
2178 if (shade < 0) shade = 0;
2179 if (shade > 100) shade = 100;
2181 lower_lim_r = 65535-rm;
2182 lower_lim_g = 65535-gm;
2183 lower_lim_b = 65535-bm;
2185 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2186 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2187 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2189 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2191 if (shade < 0) shade = 0;
2192 if (shade > 100) shade = 100;
2194 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2196 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2197 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2198 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2201 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2202 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2207 lower_lim_r = lower_lim_b;
2211 upper_lim_r = upper_lim_b;
2215 /* fill our lookup tables */
2216 for (i = 0; i <= mask_r>>sh_r; i++)
2219 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2220 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2221 lookup_r[i] = (tmp/65535)<<sh_r;
2223 for (i = 0; i <= mask_g>>sh_g; i++)
2226 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2227 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2228 lookup_g[i] = (tmp/65535)<<sh_g;
2230 for (i = 0; i <= mask_b>>sh_b; i++)
2233 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2234 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2235 lookup_b[i] = (tmp/65535)<<sh_b;
2238 /* apply table to input image (replacing colors by newly calculated ones) */
2239 switch (srcImage->bits_per_pixel)
2243 unsigned short *p1, *pf, *p, *pl;
2244 p1 = (unsigned short *) srcImage->data;
2245 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2249 pl = p1 + srcImage->width;
2252 *p = lookup_r[(*p & 0x7c00)>>10] |
2253 lookup_g[(*p & 0x03e0)>> 5] |
2254 lookup_b[(*p & 0x001f)];
2256 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2262 unsigned short *p1, *pf, *p, *pl;
2263 p1 = (unsigned short *) srcImage->data;
2264 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2268 pl = p1 + srcImage->width;
2271 *p = lookup_r[(*p & 0xf800)>>11] |
2272 lookup_g[(*p & 0x07e0)>> 5] |
2273 lookup_b[(*p & 0x001f)];
2275 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2281 unsigned char *p1, *pf, *p, *pl;
2282 p1 = (unsigned char *) srcImage->data;
2283 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2287 pl = p1 + srcImage->width * 3;
2288 for (; p < pl; p += 3)
2290 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2291 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2292 p[2] = lookup_r[(p[2] & 0x0000ff)];
2294 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2300 RUINT32T *p1, *pf, *p, *pl;
2301 p1 = (RUINT32T *) srcImage->data;
2302 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2307 pl = p1 + srcImage->width;
2310 *p = lookup_r[(*p & 0xff0000)>>16] |
2311 lookup_g[(*p & 0x00ff00)>> 8] |
2312 lookup_b[(*p & 0x0000ff)] |
2315 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2326 * Check our parents are still who we think they are.
2327 * Do transparency updates if required
2330 rxvt_term::check_our_parents ()
2332 int i, pchanged, aformat, have_pixmap, rootdepth;
2333 unsigned long nitems, bytes_after;
2335 unsigned char *prop = NULL;
2336 Window root, oldp, *list;
2337 Pixmap rootpixmap = None;
2338 XWindowAttributes wattr, wrootattr;
2342 if (!(options & Opt_transparent))
2343 return pchanged; /* Don't try any more */
2345 XGetWindowAttributes (display->display, display->root, &wrootattr);
2346 rootdepth = wrootattr.depth;
2348 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2350 if (rootdepth != wattr.depth)
2355 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2356 am_transparent = am_pixmap_trans = 0;
2359 return pchanged; /* Don't try any more */
2362 /* Get all X ops out of the queue so that our information is up-to-date. */
2363 XSync (display->display, False);
2366 * Make the frame window set by the window manager have
2367 * the root background. Some window managers put multiple nested frame
2368 * windows for each client, so we have to take care about that.
2370 i = (xa[XA_XROOTPMAP_ID]
2371 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAP_ID],
2372 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2373 &nitems, &bytes_after, &prop) == Success);
2375 if (!i || prop == NULL)
2376 i = (xa[XA_ESETROOT_PMAP_ID]
2377 && XGetWindowProperty (display->display, display->root, xa[XA_ESETROOT_PMAP_ID],
2378 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2379 &nitems, &bytes_after, &prop) == Success);
2381 if (!i || prop == NULL
2383 || !rs[Rs_color + Color_tint]
2390 rootpixmap = *(Pixmap *)prop;
2397 * Copy display->root pixmap transparency
2400 unsigned int nw, nh;
2406 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
2407 0, 0, &sx, &sy, &cr);
2408 nw = (unsigned int)szHint.width;
2409 nh = (unsigned int)szHint.height;
2426 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2427 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2429 XSync (display->display, False);
2431 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2433 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2434 /* XXX: may need a delay here? */
2439 if (am_transparent && am_pixmap_trans)
2442 if (TermWin.pixmap != None)
2444 XFreePixmap (display->display, TermWin.pixmap);
2445 TermWin.pixmap = None;
2449 am_pixmap_trans = 0;
2453 if (TermWin.pixmap != None)
2454 XFreePixmap (display->display, TermWin.pixmap);
2457 if (ISSET_PIXCOLOR (Color_tint))
2459 unsigned short rm, gm, bm;
2460 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2462 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2464 ShadeXImage (display, image, shade, rm, gm, bm);
2468 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
2469 szHint.width, szHint.height, image->depth);
2470 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue);
2471 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0,
2472 nx, ny, image->width, image->height);
2473 XFreeGC (display->display, gc);
2474 XDestroyImage (image);
2475 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap);
2476 XClearWindow (display->display, TermWin.parent[0]);
2478 if (!am_transparent || !am_pixmap_trans)
2481 am_transparent = am_pixmap_trans = 1;
2485 if (am_pixmap_trans)
2486 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2491 * InheritPixmap transparency
2493 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2495 oldp = TermWin.parent[i];
2496 XQueryTree (display->display, TermWin.parent[i - 1], &root,
2497 &TermWin.parent[i], &list, &n);
2500 if (TermWin.parent[i] == display->root)
2508 if (oldp != TermWin.parent[i])
2516 for (; n < (unsigned int)i; n++)
2518 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr);
2519 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2521 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2527 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2529 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]);
2530 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]);
2532 /* XXX: also turn off Opt_transparent? */
2537 /* wait (an arbitrary period) for the WM to do its thing
2538 * needed for fvwm2.2.2 (and before?) */
2541 for (n = 0; n < (unsigned int)i; n++)
2543 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative);
2544 XClearWindow (display->display, TermWin.parent[n]);
2547 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2551 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2552 TermWin.parent[i] = None;
2557 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative);
2558 scrollBar.setIdle ();
2564 want_refresh = want_full_refresh = 1;
2565 if (am_pixmap_trans)
2576 rxvt_term::cmd_parse ()
2579 unicode_t ch = NOCHAR;
2580 unsigned char *seq_begin; // remember start of esc-sequence here
2586 seq_begin = cmdbuf_ptr;
2590 if (ch == NOCHAR) // TODO: improve
2593 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2598 // many badly-written programs (e.g. jed) contain a race condition:
2599 // they first read the screensize and then install a SIGWINCH handler.
2600 // some window managers resize the window early, and these programs
2601 // then sometimes get the size wrong.
2602 // unfortunately other programs are even more buggy and dislike
2603 // being sent SIGWINCH, so only do it when we were in fact being
2606 kill (-cmd_pid, SIGWINCH);
2609 /* Read a text string from the input buffer */
2610 unicode_t buf[UBUFSIZ];
2611 bool refreshnow = false;
2613 unicode_t *str = buf;
2617 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2627 if (!(options & Opt_jumpScroll)
2628 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2635 // scr_add_lines only works for nlines <= TermWin.nrow - 1.
2636 if (nlines >= TermWin.nrow - 1)
2638 scr_add_lines (buf, nlines, str - buf);
2644 if (str >= buf + UBUFSIZ)
2650 seq_begin = cmdbuf_ptr;
2654 scr_add_lines (buf, nlines, str - buf);
2657 * If there have been a lot of new lines, then update the screen
2658 * What the heck I'll cheat and only refresh less than every page-full.
2659 * the number of pages between refreshes is refresh_limit, which
2660 * is incremented here because we must be doing flat-out scrolling.
2664 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2669 scr_refresh (refresh_type);
2678 process_nonprinting (ch);
2680 catch (const class out_of_input &o)
2682 // we ran out of input, retry later
2683 cmdbuf_ptr = seq_begin;
2694 // read the next octet
2696 rxvt_term::next_octet ()
2698 return cmdbuf_ptr < cmdbuf_endp
2703 // read the next character
2705 rxvt_term::next_char ()
2707 while (cmdbuf_ptr < cmdbuf_endp)
2709 // assume 7-bit to be ascii ALWAYS
2710 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2711 return *cmdbuf_ptr++;
2714 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2716 if (len == (size_t)-2)
2718 // the mbstate stores incomplete sequences. didn't know this :/
2719 cmdbuf_ptr = cmdbuf_endp;
2723 if (len == (size_t)-1)
2724 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2726 // assume wchar == unicode
2728 return wc & UNICODE_MASK;
2734 /* rxvt_cmd_getc () - Return next input character */
2736 * Return the next input character after first passing any keyboard input
2740 rxvt_term::cmd_getc ()
2742 unicode_t c = next_char ();
2751 rxvt_term::cmd_get8 ()
2753 unicode_t c = next_octet ();
2762 /*----------------------------------------------------------------------*/
2765 rxvt_term::popen_printer ()
2767 FILE *stream = popen (rs[Rs_print_pipe], "w");
2770 rxvt_warn ("can't open printer pipe, not printing.\n");
2776 rxvt_term::pclose_printer (FILE *stream)
2779 return pclose (stream);
2783 * simulate attached vt100 printer
2786 rxvt_term::process_print_pipe ()
2791 if ((fd = popen_printer ()) == NULL)
2795 * Send all input to the printer until either ESC[4i or ESC[?4i
2798 for (done = 0; !done;)
2800 unsigned char buf[8];
2802 unsigned int i, len;
2804 if ((ch = cmd_getc ()) != C0_ESC)
2806 if (putc (ch, fd) == EOF)
2807 break; /* done = 1 */
2814 if ((buf[len++] = cmd_getc ()) == '[')
2816 if ((ch = cmd_getc ()) == '?')
2821 if ((buf[len++] = ch) == '4')
2823 if ((buf[len++] = cmd_getc ()) == 'i')
2824 break; /* done = 1 */
2828 for (i = 0; i < len; i++)
2829 if (putc (buf[i], fd) == EOF)
2837 pclose_printer (fd);
2839 #endif /* PRINTPIPE */
2845 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2846 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2847 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2848 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2852 /*{{{ process non-printing single characters */
2854 rxvt_term::process_nonprinting (unicode_t ch)
2859 process_escape_seq ();
2861 case C0_ENQ: /* terminal Status */
2862 if (rs[Rs_answerbackstring])
2863 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2864 (unsigned int)strlen (rs[Rs_answerbackstring]));
2866 tt_write ((unsigned char *)VT100_ANS,
2867 (unsigned int)strlen (VT100_ANS));
2869 case C0_BEL: /* bell */
2872 case C0_BS: /* backspace */
2875 case C0_HT: /* tab */
2878 case C0_CR: /* carriage return */
2879 scr_gotorc (0, 0, R_RELATIVE);
2881 case C0_VT: /* vertical tab, form feed */
2883 case C0_LF: /* line feed */
2886 case C0_SO: /* shift out - acs */
2887 scr_charset_choose (1);
2889 case C0_SI: /* shift in - acs */
2890 scr_charset_choose (0);
2893 #ifdef EIGHT_BIT_CONTROLS
2895 case 0x90: /* DCS */
2898 case 0x9b: /* CSI */
2901 case 0x9d: /* CSI */
2910 /*{{{ process VT52 escape sequences */
2912 rxvt_term::process_escape_vt52 (unicode_t ch)
2918 case 'A': /* cursor up */
2919 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2921 case 'B': /* cursor down */
2922 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2924 case 'C': /* cursor right */
2925 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2927 case 'D': /* cursor left */
2928 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2930 case 'H': /* cursor home */
2931 scr_gotorc (0, 0, 0);
2933 case 'I': /* cursor up and scroll down if needed */
2936 case 'J': /* erase to end of screen */
2937 scr_erase_screen (0);
2939 case 'K': /* erase to end of line */
2942 case 'Y': /* move to specified row and col */
2943 /* full command is 'ESC Y row col' where row and col
2944 * are encoded by adding 32 and sending the ascii
2945 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2947 row = cmd_getc () - ' ';
2948 col = cmd_getc () - ' ';
2949 scr_gotorc (row, col, 0);
2951 case 'Z': /* identify the terminal type */
2952 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2954 case '<': /* turn off VT52 mode */
2955 PrivMode (0, PrivMode_vt52);
2957 case 'F': /* use special graphics character set */
2958 case 'G': /* use regular character set */
2961 case '=': /* use alternate keypad mode */
2962 case '>': /* use regular keypad mode */
2970 /*{{{ process escape sequences */
2972 rxvt_term::process_escape_seq ()
2974 unicode_t ch = cmd_getc ();
2976 if (priv_modes & PrivMode_vt52)
2978 process_escape_vt52 (ch);
2984 /* case 1: do_tek_mode (); break; */
2986 if (cmd_getc () == '8')
2990 scr_charset_set (0, (unsigned int)cmd_getc ());
2993 scr_charset_set (1, (unsigned int)cmd_getc ());
2996 scr_charset_set (2, (unsigned int)cmd_getc ());
2999 scr_charset_set (3, (unsigned int)cmd_getc ());
3010 scr_cursor (RESTORE);
3014 scr_forwardindex ();
3019 PrivMode ((ch == '='), PrivMode_aplKP);
3029 /* 8.3.87: NEXT LINE */
3030 case C1_NEL: /* ESC E */
3032 unicode_t nlcr[] = { C0_LF, C0_CR };
3033 scr_add_lines (nlcr, 1, 2);
3037 /* kidnapped escape sequence: Should be 8.3.48 */
3038 case C1_ESA: /* ESC G */
3039 process_graphics ();
3042 /* 8.3.63: CHARACTER TABULATION SET */
3043 case C1_HTS: /* ESC H */
3047 /* 8.3.105: REVERSE LINE FEED */
3048 case C1_RI: /* ESC M */
3052 /* 8.3.142: SINGLE-SHIFT TWO */
3053 /*case C1_SS2: scr_single_shift (2); break; */
3055 /* 8.3.143: SINGLE-SHIFT THREE */
3056 /*case C1_SS3: scr_single_shift (3); break; */
3058 /* 8.3.27: DEVICE CONTROL STRING */
3059 case C1_DCS: /* ESC P */
3063 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3064 case C1_SCI: /* ESC Z */
3065 tt_write ((const unsigned char *)ESCZ_ANSWER,
3066 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3067 break; /* steal obsolete ESC [ c */
3069 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3070 case C1_CSI: /* ESC [ */
3074 /* 8.3.90: OPERATING SYSTEM COMMAND */
3075 case C1_OSC: /* ESC ] */
3079 /* 8.3.106: RESET TO INITIAL STATE */
3086 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3088 scr_charset_choose (2);
3091 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3093 scr_charset_choose (3);
3099 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3103 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3104 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3105 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3106 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3107 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3108 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3109 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3110 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3113 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3114 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3115 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3116 #define get_byte_array_bit(array, bit) \
3117 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3119 const unsigned char csi_defaults[] =
3121 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3122 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3123 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3124 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3125 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3126 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3127 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3128 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3133 rxvt_term::process_csi_seq ()
3135 unicode_t ch, priv, i;
3136 unsigned int nargs, p;
3140 for (nargs = ESC_ARGS; nargs > 0;)
3145 if (ch >= '<' && ch <= '?')
3146 { /* '<' '=' '>' '?' */
3151 /* read any numerical arguments */
3152 for (n = -1; ch < CSI_ICH; )
3159 n = n * 10 + ch - '0';
3163 if (nargs < ESC_ARGS)
3167 else if (IS_CONTROL (ch))
3168 process_nonprinting (ch);
3176 if (nargs < ESC_ARGS)
3180 ndef = get_byte_array_bit (csi_defaults, i);
3181 for (p = 0; p < nargs; p++)
3186 fprintf (stderr, "CSI ");
3187 for (p = 0; p < nargs; p++)
3188 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3189 fprintf (stderr, "%c\n", ch);
3193 * private mode handling
3200 if (ch == CSI_DA) /* secondary device attributes */
3201 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING);
3204 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3205 process_terminal_mode (ch, priv, nargs, arg);
3214 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3217 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3220 case 0: /* initiate transfer to primary aux device */
3221 scr_printscreen (0);
3223 case 5: /* start relay to primary aux device */
3224 process_print_pipe ();
3230 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3231 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3234 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3235 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3236 scr_gotorc (arg[0], 0, RELATIVE);
3239 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3240 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3243 #else /* emulate common DEC VTs */
3244 arg[0] = arg[0] ? -arg[0] : -1;
3247 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3248 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3250 scr_gotorc (0, arg[0], RELATIVE);
3251 #else /* emulate common DEC VTs */
3252 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3256 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3259 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3260 scr_gotorc (arg[0], 0, R_RELATIVE);
3263 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3264 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3265 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3268 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3269 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3272 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3273 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3274 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3277 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3280 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3284 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3285 scr_erase_screen (arg[0]);
3288 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3289 scr_erase_line (arg[0]);
3292 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3293 scr_insdel_chars (arg[0], INSERT);
3296 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3297 scr_insdel_lines (arg[0], INSERT);
3300 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3301 scr_insdel_lines (arg[0], DELETE);
3304 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3305 scr_insdel_chars (arg[0], ERASE);
3308 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3309 scr_insdel_chars (arg[0], DELETE);
3312 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3315 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3316 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
3319 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3320 tt_write ((const unsigned char *)VT100_ANS,
3321 (unsigned int) (sizeof (VT100_ANS) - 1));
3324 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3325 process_sgr_mode (nargs, arg);
3328 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3331 case 5: /* DSR requested */
3332 tt_printf ("\033[0n");
3334 case 6: /* CPR requested */
3335 scr_report_position ();
3337 case 7: /* unofficial extension */
3338 if (options & Opt_insecure)
3339 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3341 case 8: /* unofficial extension */
3342 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3347 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3350 case 0: /* char tab stop cleared at active position */
3353 /* case 1: */ /* line tab stop cleared in active line */
3354 /* case 2: */ /* char tab stops cleared in active line */
3355 case 3: /* all char tab stops are cleared */
3356 /* case 4: */ /* all line tab stops are cleared */
3357 case 5: /* all tab stops are cleared */
3363 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3366 case 0: /* char tab stop set at active position */
3368 break; /* = ESC H */
3369 /* case 1: */ /* line tab stop set at active line */
3370 case 2: /* char tab stop cleared at active position */
3372 break; /* = ESC [ 0 g */
3373 /* case 3: */ /* line tab stop cleared at active line */
3374 /* case 4: */ /* char tab stops cleared at active line */
3375 case 5: /* all char tab stops are cleared */
3377 break; /* = ESC [ 3 g */
3378 /* case 6: */ /* all line tab stops are cleared */
3382 case CSI_RM: /* 8.3.107: RESET MODE */
3384 scr_insert_mode (0);
3385 else if (arg[0] == 20)
3386 priv_modes &= ~PrivMode_LFNL;
3389 case CSI_SM: /* 8.3.126: SET MODE */
3391 scr_insert_mode (1);
3392 else if (arg[0] == 20)
3393 priv_modes |= PrivMode_LFNL;
3397 * PRIVATE USE beyond this point. All CSI_7? sequences here
3399 case CSI_72: /* DECSTBM: set top and bottom margins */
3401 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3402 else if (nargs == 0 || arg[0] >= arg[1])
3403 scr_scroll_region (0, MAX_ROWS - 1);
3405 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3412 scr_cursor (RESTORE);
3417 process_window_ops (arg, nargs);
3421 case CSI_78: /* DECREQTPARM */
3422 if (arg[0] == 0 || arg[0] == 1)
3423 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3435 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3438 XWindowAttributes wattr;
3449 case 1: /* deiconify window */
3450 XMapWindow (display->display, TermWin.parent[0]);
3452 case 2: /* iconify window */
3453 XIconifyWindow (display->display, TermWin.parent[0],
3454 DefaultScreen (display->display));
3456 case 3: /* set position (pixels) */
3457 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]);
3459 case 4: /* set size (pixels) */
3460 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3462 case 5: /* raise window */
3463 XRaiseWindow (display->display, TermWin.parent[0]);
3465 case 6: /* lower window */
3466 XLowerWindow (display->display, TermWin.parent[0]);
3468 case 7: /* refresh window */
3471 case 8: /* set size (chars) */
3472 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth),
3473 (unsigned int) (args[1] * TermWin.fheight));
3476 //case 9: NYI, TODO, restore maximized window or maximize window
3478 if (args[0] >= 24) /* set height (chars) */
3479 set_widthheight ((unsigned int)TermWin.width,
3480 (unsigned int) (args[1] * TermWin.fheight));
3485 * reports - some output format copied from XTerm
3487 case 11: /* report window state */
3488 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3489 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3491 case 13: /* report window position */
3492 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3493 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root,
3494 -wattr.border_width, -wattr.border_width,
3496 tt_printf ("\033[3;%d;%dt", x, y);
3498 case 14: /* report window size (pixels) */
3499 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
3500 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3502 case 18: /* report text area size (chars) */
3503 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3505 case 19: /* report window size (chars) */
3506 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3508 case 20: /* report icon label */
3511 XGetIconName (display->display, TermWin.parent[0], &s);
3512 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3516 case 21: /* report window title */
3519 XFetchName (display->display, TermWin.parent[0], &s);
3520 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3528 /*----------------------------------------------------------------------*/
3530 * get input up until STRING TERMINATOR (or BEL)
3531 * ends_how is terminator used. returned input must be free()'d
3534 rxvt_term::get_to_st (unicode_t &ends_how)
3537 bool seen_esc = false;
3539 wchar_t string[STRING_MAX];
3541 while ((ch = cmd_getc ()) != NOCHAR)
3545 if (ch == 0x5c) /* 7bit ST */
3550 else if (ch == C0_ESC)
3555 else if (ch == C0_BEL || ch == CHAR_ST)
3558 return NULL; /* other control character - exit */
3562 if (n >= sizeof (string) - 1)
3563 // stop at some sane length
3567 string[n++] = cmd_get8 ();
3574 ends_how = (ch == 0x5c ? C0_ESC : ch);
3576 return (unsigned char *)rxvt_wcstombs (string);
3579 /*----------------------------------------------------------------------*/
3581 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3584 rxvt_term::process_dcs_seq ()
3599 /*----------------------------------------------------------------------*/
3601 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3604 rxvt_term::process_osc_seq ()
3610 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3611 arg = arg * 10 + (ch - '0');
3615 unsigned char *s = get_to_st (eh);
3619 process_xterm_seq (arg, (char *)s, eh);
3626 rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3628 if (str[0] == '?' && !str[1])
3630 unsigned short r, g, b;
3631 pix_colors_focused[color].get (display, r, g, b);
3632 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3635 set_window_color (color, str);
3639 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3640 * 0 = change iconName/title
3641 * 1 = change iconName
3644 * 10 = change fg color
3645 * 11 = change bg color
3646 * 12 = change text color
3647 * 13 = change mouse foreground color
3648 * 17 = change highlight character colour
3649 * 18 = change bold character color
3650 * 19 = change underlined character color
3651 * 46 = change logfile (not implemented)
3656 * 39 = change default fg color
3657 * 49 = change default bg color
3658 * 55 = dump scrollback buffer and all of screen
3659 * 701 = change locale
3664 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3669 bool query = str[0] == '?' && !str[1];
3672 assert (str != NULL);
3678 case XTerm_iconName:
3679 set_icon_name (str);
3684 case XTerm_property:
3687 Atom prop = display->atom (str + 1);
3690 unsigned long nitems;
3691 unsigned long bytes_after;
3692 unsigned char *value = 0;
3693 const char *str = "";
3696 && XGetWindowProperty (display->display, TermWin.parent[0],
3697 prop, 0, 1<<16, 0, AnyPropertyType,
3698 &actual_type, &actual_format,
3699 &nitems, &bytes_after, &value) == Success
3700 && actual_type != None
3701 && actual_format == 8)
3702 str = (const char *)(value);
3704 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3710 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3715 set_utf8_property (display->atom (str), eq + 1);
3718 XDeleteProperty (display->display, TermWin.parent[0],
3719 display->atom (str));
3724 for (buf = (char *)str; buf && *buf;)
3726 if ((name = strchr (buf, ';')) == NULL)
3732 if (color < 0 || color >= TOTAL_COLORS)
3735 if ((buf = strchr (name, ';')) != NULL)
3738 if (name[0] == '?' && !name[1])
3740 unsigned short r, g, b;
3741 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3742 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3745 set_window_color (color + minCOLOR, name);
3749 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3752 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3754 #ifndef NO_CURSORCOLOR
3755 case XTerm_Color_cursor:
3756 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3759 case XTerm_Color_pointer_fg:
3760 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3762 case XTerm_Color_pointer_bg:
3763 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3765 #ifndef NO_BOLD_UNDERLINE_REVERSE
3766 case XTerm_Color_BD:
3767 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3769 case XTerm_Color_IT:
3770 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3772 case XTerm_Color_UL:
3773 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3775 case XTerm_Color_RV:
3776 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3779 #if TRANSPARENT && TINTING
3780 case XTerm_Color_tint:
3781 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3782 check_our_parents ();
3784 want_full_refresh = want_refresh = 1;
3792 scale_pixmap (""); /* reset to default scaling */
3793 set_bgPixmap (str); /* change pixmap */
3797 while ((str = strchr (str, ';')) != NULL)
3801 changed += scale_pixmap (str);
3807 #ifdef XPM_BACKGROUND
3814 case XTerm_restoreFG:
3815 set_window_color (Color_fg, str);
3817 case XTerm_restoreBG:
3818 set_window_color (Color_bg, str);
3822 // TODO, when secure mode?
3829 case URxvt_boldFont:
3830 case URxvt_italicFont:
3831 case URxvt_boldItalicFont:
3834 tt_printf ("\33]%d;%-.250s%c", saveop,
3835 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc
3836 ? TermWin.fontset[op - URxvt_font]->fontdesc : "",
3840 const char *&res = rs[Rs_font + (op - URxvt_font)];
3843 allocated.push_back ((void *)res);
3851 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3864 if (options & Opt_insecure)
3865 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3869 case XTerm_dumpscreen: /* no error notices */
3872 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3882 /*----------------------------------------------------------------------*/
3884 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3886 * mode can only have the following values:
3892 * so no need for fancy checking
3895 rxvt_term::privcases (int mode, unsigned long bit)
3901 SavedModes |= (priv_modes & bit);
3907 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3909 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3910 PrivMode (state, bit);
3916 /* we're not using priv _yet_ */
3918 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
3926 const unsigned long bit;
3930 { 1, PrivMode_aplCUR },
3931 { 2, PrivMode_vt52 },
3932 { 3, PrivMode_132 },
3933 { 4, PrivMode_smoothScroll },
3934 { 5, PrivMode_rVideo },
3935 { 6, PrivMode_relOrigin },
3936 { 7, PrivMode_Autowrap },
3937 // 8, bi-directional support mode
3938 { 9, PrivMode_MouseX10 },
3940 { menuBar_esc, PrivMode_menuBar },
3942 // 18, 19 printing-related
3943 { 25, PrivMode_VisibleCursor },
3944 #ifdef scrollBar_esc
3945 { scrollBar_esc, PrivMode_scrollBar },
3947 { 35, PrivMode_ShiftKeys }, // rxvt extension
3948 { 40, PrivMode_132OK },
3949 // 41 xterm more fixes NYI
3950 // 45 margin bell NYI
3952 { 47, PrivMode_Screen },
3953 { 66, PrivMode_aplKP },
3954 #ifndef NO_BACKSPACE_KEY
3955 { 67, PrivMode_BackSpace },
3957 { 1000, PrivMode_MouseX11 },
3958 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3959 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
3960 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3961 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3962 { 1011, PrivMode_Keypress }, // rxvt extension
3963 // 1035 enable modifiers for alt, numlock NYI
3964 // 1036 send ESC for meta keys NYI
3965 // 1037 send DEL for keypad delete NYI
3966 { 1047, PrivMode_Screen },
3967 // 1048 save and restore cursor
3968 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3969 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3975 /* make lo/hi boolean */
3977 mode = 0; /* reset */
3978 else if (mode == 'h')
3981 for (i = 0; i < nargs; i++)
3985 /* basic handling */
3986 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
3987 if (argtopriv[j].argval == arg[i])
3989 state = privcases (mode, argtopriv[j].bit);
3993 /* extra handling for values with state unkept */
3996 case 1048: /* alternative cursor save */
3998 if (options & Opt_secondaryScreen)
4000 scr_cursor (RESTORE);
4007 /* extra handling for values with valid 0 or 1 state */
4010 /* case 1: - application cursor keys */
4011 case 2: /* VT52 mode */
4012 /* oddball mode. should be set regardless of set/reset
4013 * parameter. Return from VT52 mode with an ESC < from
4016 PrivMode (1, PrivMode_vt52);
4018 case 3: /* 80/132 */
4019 if (priv_modes & PrivMode_132OK)
4020 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height);
4022 case 4: /* smooth scrolling */
4024 options &= ~Opt_jumpScroll;
4026 options |= Opt_jumpScroll;
4028 case 5: /* reverse video */
4029 scr_rvideo_mode (state);
4031 case 6: /* relative/absolute origins */
4032 scr_relative_origin (state);
4034 case 7: /* autowrap */
4035 scr_autowrap (state);
4037 /* case 8: - auto repeat, can't do on a per window basis */
4038 case 9: /* X10 mouse reporting */
4039 if (state) /* orthogonal */
4040 priv_modes &= ~PrivMode_MouseX11;
4045 map_menuBar (state);
4049 #ifdef scrollBar_esc
4051 if (scrollbar_mapping (state))
4053 resize_all_windows (0, 0, 0);
4058 case 25: /* visible/invisible cursor */
4059 scr_cursor_visible (state);
4061 /* case 35: - shift keys */
4062 /* case 40: - 80 <--> 132 mode */
4063 case 47: /* secondary screen */
4064 scr_change_screen (state);
4066 /* case 66: - application key pad */
4067 /* case 67: - backspace key */
4068 case 1000: /* X11 mouse reporting */
4069 if (state) /* orthogonal */
4070 priv_modes &= ~PrivMode_MouseX10;
4074 break; /* X11 mouse highlighting */
4076 case 1010: /* scroll to bottom on TTY output inhibit */
4078 options &= ~Opt_scrollTtyOutput;
4080 options |= Opt_scrollTtyOutput;
4082 case 1011: /* scroll to bottom on key press */
4084 options |= Opt_scrollTtyKeypress;
4086 options &= ~Opt_scrollTtyKeypress;
4088 case 1047: /* secondary screen w/ clearing last */
4089 if (options & Opt_secondaryScreen)
4090 if (current_screen != PRIMARY)
4091 scr_erase_screen (2);
4092 scr_change_screen (state);
4094 case 1049: /* secondary screen w/ clearing first */
4095 scr_change_screen (state);
4096 if (options & Opt_secondaryScreen)
4097 if (current_screen != PRIMARY)
4098 scr_erase_screen (2);
4107 /*{{{ process sgr sequences */
4109 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4117 scr_rendition (0, ~RS_None);
4121 for (i = 0; i < nargs; i++)
4127 rendset = 0, rendstyle = ~RS_None;
4130 rendset = 1, rendstyle = RS_Bold;
4132 //case 2: // low intensity
4134 rendset = 1, rendstyle = RS_Italic;
4137 rendset = 1, rendstyle = RS_Uline;
4139 case 5: // slowly blinking
4140 case 6: // rapidly blinking
4141 rendset = 1, rendstyle = RS_Blink;
4143 //case 6: // scoansi light background
4145 rendset = 1, rendstyle = RS_RVid;
4150 //case 9: // crossed out
4151 //case 10: // scoansi acs off, primary font
4152 //case 11: // scoansi acs on, first alt font
4153 //case 12: // scoansi acs on, |0x80, second alt font
4155 //case 19: // ninth alt font
4156 //case 20: // gothic
4157 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4158 rendset = 0, rendstyle = RS_Bold;
4160 case 22: // normal intensity
4161 rendset = 0, rendstyle = RS_Bold;
4163 case 23: // disable italic
4164 rendset = 0, rendstyle = RS_Italic;
4167 rendset = 0, rendstyle = RS_Uline;
4170 rendset = 0, rendstyle = RS_Blink;
4172 case 26: // variable spacing (iso 8613)
4173 rendset = 0, rendstyle = RS_Blink;
4176 rendset = 0, rendstyle = RS_RVid;
4178 //case 28: // visible. NYI
4179 //case 29: // not crossed-out
4184 scr_rendition (rendset, rendstyle);
4185 continue; /* for (;i;) */
4191 case 31: /* set fg color */
4198 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4200 case 38: // set fg color, ISO 8613-6
4201 if (nargs > i + 2 && arg[i + 1] == 5)
4203 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4207 case 39: /* default fg */
4208 scr_color (Color_fg, Color_fg);
4212 case 41: /* set bg color */
4219 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4221 case 48: // set bg color, ISO 8613-6
4222 if (nargs > i + 2 && arg[i + 1] == 5)
4224 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4228 case 49: /* default bg */
4229 scr_color (Color_bg, Color_bg);
4232 //case 50: // not variable spacing
4234 #ifndef NO_BRIGHTCOLOR
4236 case 91: /* set bright fg color */
4243 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4246 case 101: /* set bright bg color */
4253 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4262 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4264 rxvt_term::process_graphics ()
4266 unicode_t ch, cmd = cmd_getc ();
4269 { /* query graphics */
4270 tt_printf ("\033G0\012"); /* no graphics */
4273 /* swallow other graphics sequences until terminating ':' */
4280 /* ------------------------------------------------------------------------- */
4283 * Send printf () formatted output to the command.
4284 * Only use for small amounts of data.
4287 rxvt_term::tt_printf (const char *fmt,...)
4290 unsigned char buf[256];
4292 va_start (arg_ptr, fmt);
4293 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4295 tt_write (buf, strlen (buf));
4298 /* ---------------------------------------------------------------------- */
4299 /* Write data to the pty as typed by the user, pasted with the mouse,
4300 * or generated by us in response to a query ESC sequence.
4302 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4305 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4309 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4311 if ((unsigned int)written == len)
4318 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4320 memcpy (v_buffer + v_buflen, data, len);
4323 pty_ev.set (EVENT_READ | EVENT_WRITE);
4326 void rxvt_term::pty_write ()
4328 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4332 v_buflen -= written;
4340 pty_ev.set (EVENT_READ);
4344 memmove (v_buffer, v_buffer + written, v_buflen);
4346 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4347 // original code just ignores this...
4351 /*----------------------- end-of-file (C source) -----------------------*/