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-2006 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"
55 #undef HAVE_SCHED_YIELD // disabled for the time being
59 #ifdef KEYSYM_RESOURCE
60 # include "keyboard.h"
65 /*----------------------------------------------------------------------*/
67 #define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
69 // exception thrown when the command parser runs out of input data
70 class out_of_input { } out_of_input;
72 #if ENABLE_FRILLS || ISO_14755
74 #define ISO_14755_STARTED 0x80000000UL
75 #define ISO_14755_51 0x40000000UL // basic (section 5.1)
76 #define ISO_14755_52 0x20000000UL // keycap (section 5.2)
77 #define ISO_14755_54 0x10000000UL // code feedback (section 5.4)
78 #define ISO_14755_MASK 0x0fffffffUL
81 static unsigned short iso14755_symtab[] = {
98 XK_ISO_Left_Tab, 0x21e6,
102 XK_Shift_Lock, 0x21eb,
105 XK_Caps_Lock, 0x21ec,
107 XK_ISO_Level3_Shift, 0x21ee,
108 XK_ISO_Level3_Lock, 0x21ef,
109 XK_ISO_Group_Lock, 0x21f0,
117 XK_BackSpace, 0x232b,
119 XK_Control_L, 0x2388,
120 XK_Control_R, 0x2388,
133 XK_KP_Insert, 0x2380,
134 XK_KP_Delete, 0x2326,
141 rxvt_term::iso14755_54 (int x, int y)
146 if (!IN_RANGE_EXC (x, 0, ncol)
147 || !IN_RANGE_EXC (y, 0, nrow))
152 const line_t &l = ROW(y + view_start);
156 if (t != NOCHAR || !x)
158 iso14755_51 (l.t[x], l.r[x], x, y);
159 iso14755buf = ISO_14755_54;
168 rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
170 rxvt_fontset *fs = FONTSET (r);
171 rxvt_font *f = (*fs)[fs->find_font (ch)];
172 wchar_t *chr, *alloc, ch2, *fname;
175 fname = rxvt_utf8towcs (f->name);
177 # if ENABLE_COMBINING
180 len = rxvt_composite.expand (ch, 0);
181 alloc = chr = new wchar_t[len];
182 rxvt_composite.expand (ch, chr);
194 char attr[80]; // plenty
196 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
198 fgcolor_of (r), bgcolor_of (r),
199 r & RS_Bold ? " bold" : "",
200 r & RS_Italic ? " italic" : "",
201 r & RS_Blink ? " blink" : "",
202 r & RS_RVid ? " rvid" : "",
203 r & RS_Uline ? " uline" : "",
204 r & RS_Careful ? " careful" : "");
206 int width = wcswidth (fname, wcslen (fname));
208 max_it (width, 8+5); // for char + hey
209 max_it (width, strlen (attr));
213 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
217 scr_overlay_new (x, y, width, len + 2);
219 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
221 for (int y = 0; y < len; y++)
227 sprintf (buf, "%8x", ch);
228 scr_overlay_set (0, y, buf);
229 scr_overlay_set (9, y, '=');
234 scr_overlay_set (11, y, ch, r);
235 scr_overlay_set (12, y, NOCHAR, r);
238 scr_overlay_set (0, len , attr);
239 scr_overlay_set (0, len + 1, fname);
243 # if ENABLE_COMBINING
251 rxvt_term::commit_iso14755 ()
255 ch[0] = iso14755buf & ISO_14755_MASK;
258 if (iso14755buf & ISO_14755_51)
263 // allow verbatim 0-bytes and control-bytes to be entered
265 len = wcstombs (mb, ch, 16);
282 rxvt_term::hex_keyval (XKeyEvent &ev)
284 // check wether this event corresponds to a hex digit
285 // if the modifiers had not been pressed.
286 for (int index = 0; index < 8; index++)
288 KeySym k = XLookupKeysym (&ev, index);
290 if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0;
291 else if (k >= XK_0 && k <= XK_9) return k - XK_0;
292 else if (k >= XK_a && k <= XK_f) return k - XK_a + 10;
293 else if (k >= XK_A && k <= XK_F) return k - XK_A + 10;
300 /*{{{ Convert the keypress event into a string */
302 rxvt_term::lookup_key (XKeyEvent &ev)
304 int ctrl, meta, shft, len;
308 static int debug_key = 1; /* accessible by a debugger only */
314 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
315 * escape sequence to toggle the Keypad.
317 * Always permit `shift' to override the current setting
319 shft = ev.state & ShiftMask;
320 ctrl = ev.state & ControlMask;
321 meta = ev.state & ModMetaMask;
323 if (numlock_state || (ev.state & ModNumLockMask))
325 numlock_state = (ev.state & ModNumLockMask);
326 PrivMode ((!numlock_state), PrivMode_aplKP);
334 Status status_return;
337 #ifdef X_HAVE_UTF8_STRING
338 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
339 len = Xutf8LookupString (Input_Context, &ev, kbuf,
340 KBUFSZ, &keysym, &status_return);
345 wchar_t wkbuf[KBUFSZ + 1];
347 // the XOpenIM manpage lies about hardcoding the locale
348 // at the point of XOpenIM, so temporarily switch locales
350 SET_LOCALE (rs[Rs_imLocale]);
352 // assume wchar_t == unicode or better
353 len = XwcLookupString (Input_Context, &ev, wkbuf,
354 KBUFSZ, &keysym, &status_return);
359 if (status_return == XLookupChars
360 || status_return == XLookupBoth)
362 /* make sure the user can type ctrl-@, i.e. NUL */
363 if (len == 1 && *wkbuf == 0)
371 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
380 valid_keysym = status_return == XLookupKeySym
381 || status_return == XLookupBoth;
386 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
387 valid_keysym = keysym != NoSymbol;
392 #ifdef KEYSYM_RESOURCE
393 if (keyboard->dispatch (this, keysym, ev.state))
399 #ifdef UNSHIFTED_SCROLLKEYS
407 #ifdef PAGING_CONTEXT_LINES
408 lnsppg = nrow - PAGING_CONTEXT_LINES;
410 lnsppg = nrow * 4 / 5;
412 if (keysym == XK_Prior)
414 scr_page (UP, lnsppg);
417 else if (keysym == XK_Next)
419 scr_page (DN, lnsppg);
423 #ifdef SCROLL_ON_UPDOWN_KEYS
431 else if (keysym == XK_Down)
438 #ifdef SCROLL_ON_HOMEEND_KEYS
441 if (keysym == XK_Home)
446 else if (keysym == XK_End)
457 /* Shift + F1 - F10 generates F11 - F20 */
458 if (keysym >= XK_F1 && keysym <= XK_F10)
460 keysym += (XK_F11 - XK_F1);
461 shft = 0; /* turn off Shift */
463 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
467 /* normal XTerm key bindings */
468 case XK_Insert: /* Shift+Insert = paste mouse selection */
469 selection_request (ev.time, 0, 0);
473 case XK_KP_Add: /* Shift+KP_Add = bigger font */
474 change_font (FONT_UP);
476 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
477 change_font (FONT_DN);
484 #if ENABLE_FRILLS || ISO_14755
490 if (iso14755buf & ISO_14755_51
491 && (keysym == XK_space || keysym == XK_KP_Space
492 || keysym == XK_Return || keysym == XK_KP_Enter))
495 iso14755buf = ISO_14755_51;
501 else if ((hv = hex_keyval (ev)) >= 0)
503 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
506 iso14755_51 (iso14755buf & ISO_14755_MASK);
518 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
519 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
520 if (!(iso14755buf & ISO_14755_STARTED))
522 iso14755buf |= ISO_14755_STARTED;
524 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
525 scr_overlay_set (0, 0, "ISO 14755 mode");
531 if (keysym == XK_Print)
533 scr_printscreen (ctrl | shft);
538 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
544 #ifndef NO_BACKSPACE_KEY
546 if (priv_modes & PrivMode_HaveBackSpace)
548 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
549 ^ !!ctrl) ? '\b' : '\177';
553 strcpy (kbuf, key_backspace);
556 #ifndef NO_DELETE_KEY
559 /* allow shift to override */
560 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
562 strcpy (kbuf, "\033On");
568 strcpy (kbuf, key_delete);
573 strcpy (kbuf, "\033[Z");
576 #ifdef CTRL_TAB_MAKES_META
580 #ifdef MOD4_TAB_MAKES_META
581 if (ev.state & Mod4Mask)
589 case XK_KP_Up: /* \033Ox or standard */
590 case XK_KP_Down: /* \033Or or standard */
591 case XK_KP_Right: /* \033Ov or standard */
592 case XK_KP_Left: /* \033Ot or standard */
593 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
595 strcpy (kbuf, "\033OZ");
596 kbuf[2] = "txvr"[keysym - XK_KP_Left];
600 /* translate to std. cursor key */
601 keysym = XK_Left + (keysym - XK_KP_Left);
604 case XK_Up: /* "\033[A" */
605 case XK_Down: /* "\033[B" */
606 case XK_Right: /* "\033[C" */
607 case XK_Left: /* "\033[D" */
608 strcpy (kbuf, "\033[Z");
609 kbuf[2] = "DACB"[keysym - XK_Left];
612 kbuf[2] = "dacb"[keysym - XK_Left];
616 kbuf[2] = "dacb"[keysym - XK_Left];
618 else if (priv_modes & PrivMode_aplCUR)
622 #ifndef UNSHIFTED_SCROLLKEYS
625 /* allow shift to override */
626 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
628 strcpy (kbuf, "\033Oy");
634 strcpy (kbuf, "\033[5~");
638 /* allow shift to override */
639 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
641 strcpy (kbuf, "\033Os");
647 strcpy (kbuf, "\033[6~");
651 /* allow shift to override */
652 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
654 strcpy (kbuf, "\033OM");
661 if (priv_modes & PrivMode_LFNL)
676 strcpy (kbuf, "\033Ou");
680 case XK_KP_F1: /* "\033OP" */
681 case XK_KP_F2: /* "\033OQ" */
682 case XK_KP_F3: /* "\033OR" */
683 case XK_KP_F4: /* "\033OS" */
684 strcpy (kbuf, "\033OP");
685 kbuf[2] += (keysym - XK_KP_F1);
688 case XK_KP_Multiply: /* "\033Oj" : "*" */
689 case XK_KP_Add: /* "\033Ok" : "+" */
690 case XK_KP_Separator: /* "\033Ol" : "," */
691 case XK_KP_Subtract: /* "\033Om" : "-" */
692 case XK_KP_Decimal: /* "\033On" : "." */
693 case XK_KP_Divide: /* "\033Oo" : "/" */
694 case XK_KP_0: /* "\033Op" : "0" */
695 case XK_KP_1: /* "\033Oq" : "1" */
696 case XK_KP_2: /* "\033Or" : "2" */
697 case XK_KP_3: /* "\033Os" : "3" */
698 case XK_KP_4: /* "\033Ot" : "4" */
699 case XK_KP_5: /* "\033Ou" : "5" */
700 case XK_KP_6: /* "\033Ov" : "6" */
701 case XK_KP_7: /* "\033Ow" : "7" */
702 case XK_KP_8: /* "\033Ox" : "8" */
703 case XK_KP_9: /* "\033Oy" : "9" */
704 /* allow shift to override */
705 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
707 strcpy (kbuf, "\033Oj");
708 kbuf[2] += (keysym - XK_KP_Multiply);
712 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
718 strcpy (kbuf, "\033[1~");
723 /* allow shift to override */
724 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
726 strcpy (kbuf, "\033Op");
732 strcpy (kbuf, "\033[2~");
734 #ifdef DXK_Remove /* support for DEC remove like key */
739 strcpy (kbuf, "\033[3~");
742 strcpy (kbuf, "\033[4~");
746 /* allow shift to override */
747 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
749 strcpy (kbuf, "\033Oq");
755 strcpy (kbuf, KS_END);
759 /* allow shift to override */
760 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
762 strcpy (kbuf, "\033Ow");
768 strcpy (kbuf, KS_HOME);
771 #define FKEY(n, fkey) \
772 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
774 case XK_F1: /* "\033[11~" */
775 case XK_F2: /* "\033[12~" */
776 case XK_F3: /* "\033[13~" */
777 case XK_F4: /* "\033[14~" */
778 case XK_F5: /* "\033[15~" */
781 case XK_F6: /* "\033[17~" */
782 case XK_F7: /* "\033[18~" */
783 case XK_F8: /* "\033[19~" */
784 case XK_F9: /* "\033[20~" */
785 case XK_F10: /* "\033[21~" */
788 case XK_F11: /* "\033[23~" */
789 case XK_F12: /* "\033[24~" */
790 case XK_F13: /* "\033[25~" */
791 case XK_F14: /* "\033[26~" */
794 case XK_F15: /* "\033[28~" */
795 case XK_F16: /* "\033[29~" */
798 case XK_Help: /* "\033[28~" */
801 case XK_Menu: /* "\033[29~" */
804 case XK_F17: /* "\033[31~" */
805 case XK_F18: /* "\033[32~" */
806 case XK_F19: /* "\033[33~" */
807 case XK_F20: /* "\033[34~" */
808 case XK_F21: /* "\033[35~" */
809 case XK_F22: /* "\033[36~" */
810 case XK_F23: /* "\033[37~" */
811 case XK_F24: /* "\033[38~" */
812 case XK_F25: /* "\033[39~" */
813 case XK_F26: /* "\033[40~" */
814 case XK_F27: /* "\033[41~" */
815 case XK_F28: /* "\033[42~" */
816 case XK_F29: /* "\033[43~" */
817 case XK_F30: /* "\033[44~" */
818 case XK_F31: /* "\033[45~" */
819 case XK_F32: /* "\033[46~" */
820 case XK_F33: /* "\033[47~" */
821 case XK_F34: /* "\033[48~" */
822 case XK_F35: /* "\033[49~" */
836 * Pass meta for all function keys, if 'meta' option set
839 if (meta && (meta_char == 0x80) && len > 0)
840 kbuf[len - 1] |= 0x80;
844 else if (ctrl && keysym == XK_minus)
847 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
849 else if (keysym == XK_ISO_Left_Tab)
851 strcpy (kbuf, "\033[Z");
858 if (meta && (meta_char == 0x80))
862 for (ch = kbuf; ch < kbuf + len; ch++)
872 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
876 return; /* not mapped */
878 if (OPTION (Opt_scrollTtyKeypress))
886 * these modifications only affect the static keybuffer
887 * pass Shift/Control indicators for function keys ending with `~'
891 * Shift+Prior = "ESC[5$"
892 * Ctrl+Prior = "ESC[5^"
893 * Ctrl+Shift+Prior = "ESC[5@"
894 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
896 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
897 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
902 && meta_char == C0_ESC
906 const char ch = C0_ESC;
910 #if defined(DEBUG_CMD)
911 /* Display keyboard buffer contents */
915 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
916 for (i = 0, p = kbuf; i < len; i++, p++)
917 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
918 fprintf (stderr, "'\n");
919 #endif /* DEBUG_CMD */
920 tt_write (kbuf, (unsigned int)len);
924 #if defined (KEYSYM_RESOURCE)
926 rxvt_term::cmd_write (const char *str, unsigned int count)
930 n = cmdbuf_ptr - cmdbuf_base;
931 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
933 if (n > 0 && s < count)
935 memmove (cmdbuf_base, cmdbuf_ptr,
936 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
937 cmdbuf_ptr = cmdbuf_base;
944 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
949 *cmdbuf_endp++ = *str++;
963 if (want_full_refresh)
965 want_full_refresh = 0;
973 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
975 int row = view_start;
976 int end_row = row + nrow;
978 while (row > top_row && ROW (row - 1).is_longer ())
990 if (!(l->f & LINE_FILTERED))
992 // line not filtered, mark it as filtered
993 l->f |= LINE_FILTERED;
994 while (l->is_longer ())
997 l->f |= LINE_FILTERED;
1001 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
1006 while (l->is_longer () && row < end_row);
1008 while (row < end_row);
1022 rxvt_term::check_cb (check_watcher &w)
1028 if (want_refresh && !flush_ev.active)
1029 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
1033 rxvt_term::flush_cb (time_watcher &w)
1044 rxvt_term::cursor_blink_cb (time_watcher &w)
1046 hidden_cursor = !hidden_cursor;
1049 w.start (w.at + BLINK_INTERVAL);
1055 rxvt_term::text_blink_cb (time_watcher &w)
1057 if (scr_refresh_rend (RS_Blink, RS_Blink))
1059 hidden_text = !hidden_text;
1061 w.start (w.at + TEXT_BLINK_INTERVAL);
1066 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1068 rxvt_term::cont_scroll_cb (time_watcher &w)
1070 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1071 scr_page (scrollbar_isUp() ? UP : DN, 1))
1074 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1079 #ifdef SELECTION_SCROLLING
1081 rxvt_term::sel_scroll_cb (time_watcher &w)
1083 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1085 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1087 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1092 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1094 rxvt_term::slip_wheel_cb (time_watcher &w)
1096 if (mouse_slip_wheel_speed == 0
1097 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1098 : scr_page (UP, mouse_slip_wheel_speed))
1100 if (view_start == top_row || view_start == 0)
1101 mouse_slip_wheel_speed = 0;
1104 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1109 #if HAVE_SCHED_YIELD
1110 static struct event_handler
1112 check_watcher cw_yield;
1114 void yield (check_watcher &w)
1121 : cw_yield (this, &event_handler::yield)
1128 rxvt_term::pty_fill ()
1130 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1134 rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n");
1138 memmove (cmdbuf_base, cmdbuf_ptr, n);
1139 cmdbuf_ptr = cmdbuf_base;
1140 cmdbuf_endp = cmdbuf_ptr + n;
1142 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1149 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1151 #if HAVE_SCHED_YIELD
1152 if (display->is_local)
1153 event_handler.cw_yield.start ();
1160 if (!OPTION (Opt_hold))
1168 rxvt_term::pty_cb (io_watcher &w, short revents)
1172 if (revents & EVENT_READ)
1173 // loop, but don't allow a single term to monopolize us
1178 if (revents & EVENT_WRITE)
1183 rxvt_term::pointer_unblank ()
1185 XDefineCursor (display->display, vt, TermWin_cursor);
1188 #ifdef POINTER_BLANK
1191 if (OPTION (Opt_pointerBlank))
1192 pointer_ev.start (NOW + pointerBlankDelay);
1196 #ifdef POINTER_BLANK
1198 rxvt_term::pointer_blank ()
1200 if (!OPTION (Opt_pointerBlank))
1203 XDefineCursor (display->display, vt, display->blank_cursor);
1204 XFlush (display->display);
1210 rxvt_term::pointer_cb (time_watcher &w)
1219 rxvt_term::mouse_report (XButtonEvent &ev)
1221 int button_number, key_state = 0;
1226 pixel_position (&x, &y);
1228 if (MEvent.button == AnyButton)
1232 button_number = MEvent.button - Button1;
1233 /* add 0x3D for wheel events, like xterm does */
1234 if (button_number >= 3)
1235 button_number += (64 - 3);
1238 if (priv_modes & PrivMode_MouseX10)
1241 * do not report ButtonRelease
1242 * no state info allowed
1245 if (button_number == 3)
1250 /* XTerm mouse reporting needs these values:
1254 * plus will add in our own Double-Click reporting
1257 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1258 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1259 + ((MEvent.state & ControlMask) ? 16 : 0);
1260 #ifdef MOUSE_REPORT_DOUBLECLICK
1261 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1265 #if DEBUG_MOUSEREPORT
1266 fprintf (stderr, "Mouse [");
1268 fputc ('C', stderr);
1270 fputc ('S', stderr);
1272 fputc ('A', stderr);
1274 fputc ('2', stderr);
1275 fprintf (stderr, "]: <%d>, %d/%d\n",
1281 tt_printf ("\033[M%c%c%c",
1282 (32 + button_number + key_state),
1289 rxvt_W11_process_x_event (XEvent *ev)
1291 rxvt_t *r = rxvt_get_r ();
1297 /*{{{ process an X event */
1299 rxvt_term::x_cb (XEvent &ev)
1305 if (ev.xany.window == vt
1306 && SHOULD_INVOKE (HOOK_X_EVENT)
1307 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1310 // for XQueryPointer
1311 Window unused_root, unused_child;
1312 int unused_root_x, unused_root_y;
1313 unsigned int unused_mask;
1319 if (!(iso14755buf & ISO_14755_52))
1321 lookup_key (ev.xkey);
1327 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1330 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1333 #if ENABLE_FRILLS || ISO_14755
1334 // ISO 14755 support
1336 if (iso14755buf & ISO_14755_52)
1342 // iso14755 part 5.2 handling: release time
1344 if ((ev.xkey.state & ControlMask)
1345 && ((keysym >= 0x40 && keysym <= 0x5f)
1346 || (keysym >= 0x61 && keysym <= 0x7f)))
1348 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1353 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1356 iso14755buf = ISO_14755_51 | i[1];
1366 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1371 if (iso14755buf & ISO_14755_51)
1374 else if (iso14755buf & ISO_14755_STARTED)
1376 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1378 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1379 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1387 if (ev.xany.window == vt
1388 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1391 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1392 if (!(ev.xkey.state & ControlMask))
1393 slip_wheel_ev.stop ();
1394 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1395 mouse_slip_wheel_speed = 0;
1401 button_press (ev.xbutton);
1405 button_release (ev.xbutton);
1409 if (ev.xclient.format == 32
1410 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1412 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1415 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1416 XSendEvent (disp, ev.xclient.window = display->root,
1417 False, SubstructureRedirectMask | SubstructureNotifyMask,
1422 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1424 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1426 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1431 /* OffiX Dnd (drag 'n' drop) protocol */
1432 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1433 && (ev.xclient.data.l[0] == DndFile
1434 || ev.xclient.data.l[0] == DndDir
1435 || ev.xclient.data.l[0] == DndLink))
1440 unsigned char *data;
1441 unsigned long Size, RemainingBytes;
1443 XGetWindowProperty (disp, display->root,
1444 xa[XA_DNDSELECTION],
1446 False, AnyPropertyType,
1447 &ActualType, &ActualFormat,
1448 &Size, &RemainingBytes,
1450 set_string_property (XA_CUT_BUFFER0, data);
1452 selection_paste (display->root, XA_CUT_BUFFER0, true);
1453 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1455 #endif /* OFFIX_DND */
1459 XRefreshKeyboardMapping (&ev.xmapping);
1463 * XXX: this is not the _current_ arrangement
1464 * Here's my conclusion:
1465 * If the window is completely unobscured, use bitblt's
1466 * to scroll. Even then, they're only used when doing partial
1467 * screen scrolling. When partially obscured, we have to fill
1468 * in the GraphicsExpose parts, which means that after each refresh,
1469 * we need to wait for the graphics expose or Noexpose events,
1470 * which ought to make things real slow!
1472 case VisibilityNotify:
1473 switch (ev.xvisibility.state)
1475 case VisibilityUnobscured:
1476 refresh_type = FAST_REFRESH;
1478 case VisibilityPartiallyObscured:
1479 refresh_type = SLOW_REFRESH;
1482 refresh_type = NO_REFRESH;
1495 case ConfigureNotify:
1496 if (ev.xconfigure.window == parent[0])
1498 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev))
1501 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1504 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1507 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1508 if (OPTION (Opt_transparent))
1509 check_our_parents ();
1514 case PropertyNotify:
1515 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1516 && ev.xproperty.state == PropertyNewValue)
1517 selection_property (ev.xproperty.window, ev.xproperty.atom);
1521 case SelectionClear:
1525 case SelectionNotify:
1526 if (selection_wait == Sel_normal)
1527 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1530 case SelectionRequest:
1531 selection_send (ev.xselectionrequest);
1537 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1539 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1545 text_blink_ev.stop ();
1547 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1551 case ReparentNotify:
1554 #endif /* TRANSPARENT */
1556 case GraphicsExpose:
1558 if (ev.xany.window == vt)
1561 scr_expose (ev.xexpose.x, ev.xexpose.y,
1562 ev.xexpose.width, ev.xexpose.height, False);
1563 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev));
1565 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1567 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1568 scr_expose (ev.xexpose.x, ev.xexpose.y,
1569 ev.xexpose.width, ev.xexpose.height, False);
1575 XEvent unused_event;
1577 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1579 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1582 if (isScrollbarWindow (ev.xany.window))
1584 scrollBar.setIdle ();
1589 if (am_transparent && ev.xany.window == parent[0])
1590 XClearWindow (disp, ev.xany.window);
1596 #ifdef POINTER_BLANK
1600 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1603 if (ev.xany.window == vt)
1605 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1606 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1608 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1610 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1613 XQueryPointer (disp, vt,
1614 &unused_root, &unused_child,
1615 &unused_root_x, &unused_root_y,
1616 &ev.xbutton.x, &ev.xbutton.y,
1618 #ifdef MOUSE_THRESHOLD
1619 /* deal with a `jumpy' mouse */
1620 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1625 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1627 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1631 selection_extend (ev.xbutton.x, ev.xbutton.y,
1632 ev.xbutton.state & Button3Mask ? 2 : 0);
1634 #ifdef SELECTION_SCROLLING
1635 if (ev.xbutton.y < int_bwidth
1636 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1640 /* don't clobber the current delay if we are
1641 * already in the middle of scrolling.
1643 if (!sel_scroll_ev.active)
1644 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1646 /* save the event params so we can highlight
1647 * the selection in the pending-scroll loop
1649 selection_save_x = ev.xbutton.x;
1650 selection_save_y = ev.xbutton.y;
1651 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1653 /* calc number of lines to scroll */
1654 if (ev.xbutton.y < int_bwidth)
1656 scroll_selection_dir = UP;
1657 dist = int_bwidth - ev.xbutton.y;
1661 scroll_selection_dir = DN;
1662 dist = ev.xbutton.y - (int_bwidth + height);
1665 scroll_selection_lines = Pixel2Height (dist)
1666 / SELECTION_SCROLL_LINE_SPEEDUP
1668 min_it (scroll_selection_lines,
1669 SELECTION_SCROLL_MAX_LINES);
1673 /* we are within the text window, so we
1674 * shouldn't be scrolling
1676 if (sel_scroll_ev.active)
1677 sel_scroll_ev.stop();
1680 #ifdef MOUSE_THRESHOLD
1685 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1687 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1691 XQueryPointer (disp, scrollBar.win,
1692 &unused_root, &unused_child,
1693 &unused_root_x, &unused_root_y,
1694 &ev.xbutton.x, &ev.xbutton.y,
1696 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1707 #if defined(CURSOR_BLINK)
1708 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress)
1716 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1720 #if defined(POINTER_BLANK)
1721 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1723 if (ev.type == MotionNotify
1724 || ev.type == ButtonPress
1725 || ev.type == ButtonRelease)
1729 if (ev.type == KeyPress && hidden_pointer == 0)
1736 rxvt_term::focus_in ()
1743 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1746 if (Input_Context != NULL)
1748 IMSetStatusPosition ();
1749 XSetICFocus (Input_Context);
1753 if (OPTION (Opt_cursorBlink))
1754 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1756 #if OFF_FOCUS_FADING
1759 pix_colors = pix_colors_focused;
1767 rxvt_term::focus_out ()
1774 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1776 #if ENABLE_FRILLS || ISO_14755
1786 if (Input_Context != NULL)
1787 XUnsetICFocus (Input_Context);
1790 if (OPTION (Opt_cursorBlink))
1791 cursor_blink_ev.stop ();
1794 #if OFF_FOCUS_FADING
1797 pix_colors = pix_colors_unfocused;
1806 rxvt_term::rootwin_cb (XEvent &ev)
1812 case PropertyNotify:
1814 * if user used some Esetroot compatible prog to set the root bg,
1815 * use the property to determine the pixmap. We use it later on.
1817 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1818 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1822 case ReparentNotify:
1823 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1824 want_refresh = want_full_refresh = 1;
1831 rxvt_term::button_press (XButtonEvent &ev)
1833 int reportmode = 0, clickintime;
1835 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1837 if (!bypass_keystate)
1838 reportmode = !! (priv_modes & PrivMode_mouse_report);
1841 * VT window processing of button press
1843 if (ev.window == vt)
1847 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1849 iso14755_54 (ev.x, ev.y);
1854 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1858 /* mouse report from vt window */
1859 /* save the xbutton state (for ButtonRelease) */
1860 MEvent.state = ev.state;
1861 #ifdef MOUSE_REPORT_DOUBLECLICK
1862 if (ev.button == MEvent.button && clickintime)
1864 /* same button, within alloted time */
1867 if (MEvent.clicks > 1)
1869 /* only report double clicks */
1873 /* don't report the release */
1875 MEvent.button = AnyButton;
1880 /* different button, or time expired */
1882 MEvent.button = ev.button;
1886 MEvent.button = ev.button;
1888 #endif /* MOUSE_REPORT_DOUBLECLICK */
1893 if (ev.button != MEvent.button)
1896 if (!HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1900 /* allow meta + click to select rectangular areas */
1901 /* should be done in screen.C */
1903 selection.rect = !!(ev.state & ModMetaMask);
1905 selection.rect = false;
1908 /* allow shift+left click to extend selection */
1909 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1911 if (MEvent.button == Button1 && clickintime)
1912 selection_rotate (ev.x, ev.y);
1914 selection_extend (ev.x, ev.y, 1);
1918 if (MEvent.button == Button1 && clickintime)
1923 selection_click (MEvent.clicks, ev.x, ev.y);
1926 MEvent.button = Button1;
1930 if (MEvent.button == Button3 && clickintime)
1931 selection_rotate (ev.x, ev.y);
1933 selection_extend (ev.x, ev.y, 1);
1935 MEvent.button = Button3;
1940 MEvent.time = ev.time;
1945 * Scrollbar window processing of button press
1947 if (isScrollbarWindow (ev.window))
1949 scrollBar.setIdle ();
1951 * Rxvt-style scrollbar:
1952 * move up if mouse is above slider
1953 * move dn if mouse is below slider
1955 * XTerm-style scrollbar:
1956 * Move display proportional to pointer location
1957 * pointer near top -> scroll one line
1958 * pointer near bot -> scroll full page
1960 #ifndef NO_SCROLLBAR_REPORT
1964 * Mouse report disabled scrollbar:
1965 * arrow buttons - send up/down
1966 * click on scrollbar - send pageup/down
1968 if ((scrollBar.style == R_SB_NEXT
1969 && scrollbarnext_upButton (ev.y))
1970 || (scrollBar.style == R_SB_RXVT
1971 && scrollbarrxvt_upButton (ev.y)))
1972 tt_printf ("\033[A");
1973 else if ((scrollBar.style == R_SB_NEXT
1974 && scrollbarnext_dnButton (ev.y))
1975 || (scrollBar.style == R_SB_RXVT
1976 && scrollbarrxvt_dnButton (ev.y)))
1977 tt_printf ("\033[B");
1985 tt_printf ("\033[6~");
1988 tt_printf ("\033[5~");
1993 #endif /* NO_SCROLLBAR_REPORT */
1998 if (scrollBar.style == R_SB_NEXT)
2000 if (scrollbarnext_upButton (ev.y))
2001 upordown = -1; /* up */
2002 else if (scrollbarnext_dnButton (ev.y))
2003 upordown = 1; /* down */
2005 else if (scrollBar.style == R_SB_RXVT)
2007 if (scrollbarrxvt_upButton (ev.y))
2008 upordown = -1; /* up */
2009 else if (scrollbarrxvt_dnButton (ev.y))
2010 upordown = 1; /* down */
2014 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2015 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
2017 if (scr_page (upordown < 0 ? UP : DN, 1))
2029 switch (scrollbar_align)
2031 case R_SB_ALIGN_TOP:
2034 case R_SB_ALIGN_CENTRE:
2035 csrO = (scrollBar.bot - scrollBar.top) / 2;
2037 case R_SB_ALIGN_BOTTOM:
2038 csrO = scrollBar.bot - scrollBar.top;
2042 if (scrollBar.style == R_SB_XTERM
2043 || scrollbar_above_slider (ev.y)
2044 || scrollbar_below_slider (ev.y))
2045 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
2047 scrollBar.setMotion ();
2051 if (scrollbar_align == R_SB_ALIGN_CENTRE)
2052 csrO = ev.y - scrollBar.top;
2056 if (scrollBar.style != R_SB_XTERM)
2058 if (scrollbar_above_slider (ev.y))
2059 # ifdef RXVT_SCROLL_FULL
2060 scr_page (UP, nrow - 1);
2062 scr_page (UP, nrow / 4);
2064 else if (scrollbar_below_slider (ev.y))
2065 # ifdef RXVT_SCROLL_FULL
2066 scr_page (DN, nrow - 1);
2068 scr_page (DN, nrow / 4);
2071 scrollBar.setMotion ();
2075 scr_page ((ev.button == Button1 ? DN : UP),
2077 * scrollbar_position (ev.y)
2078 / scrollbar_size ()));
2090 rxvt_term::button_release (XButtonEvent &ev)
2094 csrO = 0; /* reset csr Offset */
2095 if (!bypass_keystate)
2096 reportmode = !! (priv_modes & PrivMode_mouse_report);
2098 if (scrollbar_isUpDn ())
2100 scrollBar.setIdle ();
2104 #ifdef SELECTION_SCROLLING
2105 if (sel_scroll_ev.active)
2106 sel_scroll_ev.stop();
2109 if (ev.window == vt)
2113 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2118 /* mouse report from vt window */
2119 /* don't report release of wheel "buttons" */
2122 #ifdef MOUSE_REPORT_DOUBLECLICK
2123 /* only report the release of 'slow' single clicks */
2124 if (MEvent.button != AnyButton
2125 && (ev.button != MEvent.button
2126 || (ev.time - MEvent.time
2127 > MULTICLICK_TIME / 2)))
2130 MEvent.button = AnyButton;
2133 #else /* MOUSE_REPORT_DOUBLECLICK */
2134 MEvent.button = AnyButton;
2136 #endif /* MOUSE_REPORT_DOUBLECLICK */
2141 * dumb hack to compensate for the failure of click-and-drag
2142 * when overriding mouse reporting
2144 if (priv_modes & PrivMode_mouse_report
2146 && ev.button == Button1 && MEvent.clicks <= 1)
2147 selection_extend (ev.x, ev.y, 0);
2149 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2156 selection_make (ev.time);
2159 selection_request (ev.time, ev.x, ev.y);
2168 v = ev.button == Button4 ? UP : DN;
2170 if (ev.state & ShiftMask)
2172 else if (OPTION (Opt_mouseWheelScrollPage))
2177 # ifdef MOUSE_SLIP_WHEELING
2178 if (ev.state & ControlMask)
2180 mouse_slip_wheel_speed += v ? -1 : 1;
2181 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2182 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2184 if (slip_wheel_ev.at < NOW)
2185 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2187 slip_wheel_ev.start ();
2194 # ifdef MOUSE_SLIP_WHEELING
2206 /* taken from aterm-0.4.2 */
2208 typedef uint32_t RUINT32T;
2210 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2212 int sh_r, sh_g, sh_b;
2213 RUINT32T mask_r, mask_g, mask_b;
2214 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2215 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2216 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2219 Visual *visual = display->visual;
2221 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2223 /* for convenience */
2224 mask_r = visual->red_mask;
2225 mask_g = visual->green_mask;
2226 mask_b = visual->blue_mask;
2228 /* boring lookup table pre-initialization */
2229 switch (srcImage->bits_per_pixel) {
2231 if ((mask_r != 0x7c00) ||
2232 (mask_g != 0x03e0) ||
2235 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2237 lookup_g = lookup+32;
2238 lookup_b = lookup+32+32;
2244 if ((mask_r != 0xf800) ||
2245 (mask_g != 0x07e0) ||
2248 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2250 lookup_g = lookup+32;
2251 lookup_b = lookup+32+64;
2257 if ((mask_r != 0xff0000) ||
2258 (mask_g != 0x00ff00) ||
2259 (mask_b != 0x0000ff))
2261 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2263 lookup_g = lookup+256;
2264 lookup_b = lookup+256+256;
2270 if ((mask_r != 0xff0000) ||
2271 (mask_g != 0x00ff00) ||
2272 (mask_b != 0x0000ff))
2274 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2276 lookup_g = lookup+256;
2277 lookup_b = lookup+256+256;
2283 return; /* we do not support this color depth */
2286 /* prepare limits for color transformation (each channel is handled separately) */
2289 if (shade < 0) shade = 0;
2290 if (shade > 100) shade = 100;
2292 lower_lim_r = 65535-rm;
2293 lower_lim_g = 65535-gm;
2294 lower_lim_b = 65535-bm;
2296 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2297 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2298 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2300 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2302 if (shade < 0) shade = 0;
2303 if (shade > 100) shade = 100;
2305 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2307 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2308 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2309 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2312 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2313 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2318 lower_lim_r = lower_lim_b;
2322 upper_lim_r = upper_lim_b;
2326 /* fill our lookup tables */
2327 for (i = 0; i <= mask_r>>sh_r; i++)
2330 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2331 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2332 lookup_r[i] = (tmp/65535)<<sh_r;
2334 for (i = 0; i <= mask_g>>sh_g; i++)
2337 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2338 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2339 lookup_g[i] = (tmp/65535)<<sh_g;
2341 for (i = 0; i <= mask_b>>sh_b; i++)
2344 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2345 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2346 lookup_b[i] = (tmp/65535)<<sh_b;
2349 /* apply table to input image (replacing colors by newly calculated ones) */
2350 switch (srcImage->bits_per_pixel)
2354 unsigned short *p1, *pf, *p, *pl;
2355 p1 = (unsigned short *) srcImage->data;
2356 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2360 pl = p1 + srcImage->width;
2363 *p = lookup_r[(*p & 0x7c00)>>10] |
2364 lookup_g[(*p & 0x03e0)>> 5] |
2365 lookup_b[(*p & 0x001f)];
2367 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2373 unsigned short *p1, *pf, *p, *pl;
2374 p1 = (unsigned short *) srcImage->data;
2375 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2379 pl = p1 + srcImage->width;
2382 *p = lookup_r[(*p & 0xf800)>>11] |
2383 lookup_g[(*p & 0x07e0)>> 5] |
2384 lookup_b[(*p & 0x001f)];
2386 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2392 unsigned char *p1, *pf, *p, *pl;
2393 p1 = (unsigned char *) srcImage->data;
2394 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2398 pl = p1 + srcImage->width * 3;
2399 for (; p < pl; p += 3)
2401 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2402 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2403 p[2] = lookup_r[(p[2] & 0x0000ff)];
2405 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2411 RUINT32T *p1, *pf, *p, *pl;
2412 p1 = (RUINT32T *) srcImage->data;
2413 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2418 pl = p1 + srcImage->width;
2421 *p = lookup_r[(*p & 0xff0000)>>16] |
2422 lookup_g[(*p & 0x00ff00)>> 8] |
2423 lookup_b[(*p & 0x0000ff)] |
2426 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2437 * Check our parents are still who we think they are.
2438 * Do transparency updates if required
2441 rxvt_term::check_our_parents ()
2443 int i, pchanged, aformat, have_pixmap, rootdepth;
2444 unsigned long nitems, bytes_after;
2446 unsigned char *prop = NULL;
2447 Window root, oldp, *list;
2448 Pixmap rootpixmap = None;
2449 XWindowAttributes wattr, wrootattr;
2454 if (!OPTION (Opt_transparent))
2455 return pchanged; /* Don't try any more */
2457 XGetWindowAttributes (disp, display->root, &wrootattr);
2458 rootdepth = wrootattr.depth;
2460 XGetWindowAttributes (disp, parent[0], &wattr);
2462 if (rootdepth != wattr.depth)
2467 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2468 am_transparent = am_pixmap_trans = 0;
2471 return pchanged; /* Don't try any more */
2474 /* Get all X ops out of the queue so that our information is up-to-date. */
2475 XSync (disp, False);
2478 * Make the frame window set by the window manager have
2479 * the root background. Some window managers put multiple nested frame
2480 * windows for each client, so we have to take care about that.
2482 i = (xa[XA_XROOTPMAP_ID]
2483 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2484 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2485 &nitems, &bytes_after, &prop) == Success);
2487 if (!i || prop == NULL)
2488 i = (xa[XA_ESETROOT_PMAP_ID]
2489 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2490 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2491 &nitems, &bytes_after, &prop) == Success);
2493 if (!i || prop == NULL
2495 || !rs[Rs_color + Color_tint]
2502 rootpixmap = *(Pixmap *)prop;
2509 * Copy display->root pixmap transparency
2512 unsigned int nw, nh;
2518 XTranslateCoordinates (disp, parent[0], display->root,
2519 0, 0, &sx, &sy, &cr);
2520 nw = (unsigned int)szHint.width;
2521 nh = (unsigned int)szHint.height;
2538 min_it (nw, (unsigned int) (wrootattr.width - sx));
2539 min_it (nh, (unsigned int) (wrootattr.height - sy));
2541 XSync (disp, False);
2543 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2545 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2546 /* XXX: may need a delay here? */
2551 if (am_transparent && am_pixmap_trans)
2556 XFreePixmap (disp, pixmap);
2561 am_pixmap_trans = 0;
2566 XFreePixmap (disp, pixmap);
2569 if (ISSET_PIXCOLOR (Color_tint))
2571 unsigned short rm, gm, bm;
2572 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2574 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2576 ShadeXImage (display, image, shade, rm, gm, bm);
2580 pixmap = XCreatePixmap (disp, vt,
2581 szHint.width, szHint.height, image->depth);
2582 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2583 XPutImage (disp, pixmap, gc, image, 0, 0,
2584 nx, ny, image->width, image->height);
2586 XDestroyImage (image);
2587 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2588 XClearWindow (disp, parent[0]);
2590 if (!am_transparent || !am_pixmap_trans)
2593 am_transparent = am_pixmap_trans = 1;
2597 if (am_pixmap_trans)
2598 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2603 * InheritPixmap transparency
2605 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2608 XQueryTree (disp, parent[i - 1], &root,
2609 &parent[i], &list, &n);
2612 if (parent[i] == display->root)
2620 if (oldp != parent[i])
2628 for (; n < (unsigned int)i; n++)
2630 XGetWindowAttributes (disp, parent[n], &wattr);
2631 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2633 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2639 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2641 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2642 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2644 /* XXX: also turn off Opt_transparent? */
2649 /* wait (an arbitrary period) for the WM to do its thing
2650 * needed for fvwm2.2.2 (and before?) */
2653 for (n = 0; n < (unsigned int)i; n++)
2655 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2656 XClearWindow (disp, parent[n]);
2659 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2663 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2669 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2670 scrollBar.setIdle ();
2676 want_refresh = want_full_refresh = 1;
2677 if (am_pixmap_trans)
2688 rxvt_term::cmd_parse ()
2691 wchar_t ch = NOCHAR;
2692 char *seq_begin; // remember start of esc-sequence here
2698 seq_begin = cmdbuf_ptr;
2705 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2710 // many badly-written programs (e.g. jed) contain a race condition:
2711 // they first read the screensize and then install a SIGWINCH handler.
2712 // some window managers resize the window early, and these programs
2713 // then sometimes get the size wrong.
2714 // unfortunately other programs are even more buggy and dislike
2715 // being sent SIGWINCH, so only do it when we were in fact being
2717 if (seen_resize && cmd_pid)
2718 kill (-cmd_pid, SIGWINCH);
2721 /* Read a text string from the input buffer */
2722 wchar_t buf[UBUFSIZ];
2723 bool refreshnow = false;
2726 wchar_t *eol = str + min (ncol, UBUFSIZ);
2730 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2735 if (ch == C0_LF || str >= eol)
2742 if (!OPTION (Opt_jumpScroll)
2743 || (refresh_count >= refresh_limit * (nrow - 1)))
2751 // scr_add_lines only works for nlines <= nrow - 1.
2752 if (nlines >= nrow - 1)
2754 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2755 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2756 scr_add_lines (buf, str - buf, nlines);
2760 eol = str + min (ncol, UBUFSIZ);
2765 if (eol >= buf + UBUFSIZ)
2771 eol = min (eol + ncol, buf + UBUFSIZ);
2776 seq_begin = cmdbuf_ptr;
2780 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2781 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2782 scr_add_lines (buf, str - buf, nlines);
2785 * If there have been a lot of new lines, then update the screen
2786 * What the heck I'll cheat and only refresh less than every page-full.
2787 * the number of pages between refreshes is refresh_limit, which
2788 * is incremented here because we must be doing flat-out scrolling.
2792 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2807 process_nonprinting (ch);
2809 catch (const class out_of_input &o)
2811 // we ran out of input, retry later
2812 cmdbuf_ptr = seq_begin;
2823 // read the next character
2825 rxvt_term::next_char ()
2827 while (cmdbuf_ptr < cmdbuf_endp)
2829 // assume 7-bit to be ascii ALWAYS
2830 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2831 return *cmdbuf_ptr++;
2834 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2836 if (len == (size_t)-2)
2838 // the mbstate stores incomplete sequences. didn't know this :/
2839 cmdbuf_ptr = cmdbuf_endp;
2843 if (len == (size_t)-1)
2844 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2846 // assume wchar == unicode
2848 return wc & UNICODE_MASK;
2854 // read the next octet
2856 rxvt_term::next_octet ()
2858 return cmdbuf_ptr < cmdbuf_endp
2859 ? (unsigned char)*cmdbuf_ptr++
2863 /* rxvt_cmd_getc () - Return next input character */
2865 * Return the next input character after first passing any keyboard input
2869 rxvt_term::cmd_getc ()
2871 wchar_t c = next_char ();
2880 rxvt_term::cmd_get8 ()
2882 uint32_t c = next_octet ();
2891 /*----------------------------------------------------------------------*/
2894 rxvt_term::popen_printer ()
2896 FILE *stream = popen (rs[Rs_print_pipe], "w");
2899 rxvt_warn ("can't open printer pipe, not printing.\n");
2905 rxvt_term::pclose_printer (FILE *stream)
2908 return pclose (stream);
2912 * simulate attached vt100 printer
2915 rxvt_term::process_print_pipe ()
2920 if ((fd = popen_printer ()) == NULL)
2924 * Send all input to the printer until either ESC[4i or ESC[?4i
2927 for (done = 0; !done;)
2929 unsigned char buf[8];
2931 unsigned int i, len;
2933 if ((ch = cmd_getc ()) != C0_ESC)
2935 if (putc (ch, fd) == EOF)
2936 break; /* done = 1 */
2943 if ((buf[len++] = cmd_getc ()) == '[')
2945 if ((ch = cmd_getc ()) == '?')
2950 if ((buf[len++] = ch) == '4')
2952 if ((buf[len++] = cmd_getc ()) == 'i')
2953 break; /* done = 1 */
2957 for (i = 0; i < len; i++)
2958 if (putc (buf[i], fd) == EOF)
2966 pclose_printer (fd);
2968 #endif /* PRINTPIPE */
2974 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2975 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2976 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2977 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2981 /*{{{ process non-printing single characters */
2983 rxvt_term::process_nonprinting (unicode_t ch)
2988 process_escape_seq ();
2990 case C0_ENQ: /* terminal Status */
2991 if (rs[Rs_answerbackstring])
2992 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2994 tt_write (VT100_ANS, strlen (VT100_ANS));
2996 case C0_BEL: /* bell */
2999 case C0_BS: /* backspace */
3002 case C0_HT: /* tab */
3005 case C0_CR: /* carriage return */
3006 scr_gotorc (0, 0, R_RELATIVE);
3008 case C0_VT: /* vertical tab, form feed */
3010 case C0_LF: /* line feed */
3013 case C0_SO: /* shift out - acs */
3014 scr_charset_choose (1);
3016 case C0_SI: /* shift in - acs */
3017 scr_charset_choose (0);
3020 #ifdef EIGHT_BIT_CONTROLS
3022 case 0x90: /* DCS */
3025 case 0x9b: /* CSI */
3028 case 0x9d: /* CSI */
3037 /*{{{ process VT52 escape sequences */
3039 rxvt_term::process_escape_vt52 (unicode_t ch)
3045 case 'A': /* cursor up */
3046 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
3048 case 'B': /* cursor down */
3049 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
3051 case 'C': /* cursor right */
3052 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
3054 case 'D': /* cursor left */
3055 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
3057 case 'H': /* cursor home */
3058 scr_gotorc (0, 0, 0);
3060 case 'I': /* cursor up and scroll down if needed */
3063 case 'J': /* erase to end of screen */
3064 scr_erase_screen (0);
3066 case 'K': /* erase to end of line */
3069 case 'Y': /* move to specified row and col */
3070 /* full command is 'ESC Y row col' where row and col
3071 * are encoded by adding 32 and sending the ascii
3072 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
3074 row = cmd_getc () - ' ';
3075 col = cmd_getc () - ' ';
3076 scr_gotorc (row, col, 0);
3078 case 'Z': /* identify the terminal type */
3079 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3081 case '<': /* turn off VT52 mode */
3082 PrivMode (0, PrivMode_vt52);
3084 case 'F': /* use special graphics character set */
3085 case 'G': /* use regular character set */
3088 case '=': /* use alternate keypad mode */
3089 case '>': /* use regular keypad mode */
3097 /*{{{ process escape sequences */
3099 rxvt_term::process_escape_seq ()
3101 unicode_t ch = cmd_getc ();
3103 if (priv_modes & PrivMode_vt52)
3105 process_escape_vt52 (ch);
3111 /* case 1: do_tek_mode (); break; */
3113 if (cmd_getc () == '8')
3117 scr_charset_set (0, (unsigned int)cmd_getc ());
3120 scr_charset_set (1, (unsigned int)cmd_getc ());
3123 scr_charset_set (2, (unsigned int)cmd_getc ());
3126 scr_charset_set (3, (unsigned int)cmd_getc ());
3137 scr_cursor (RESTORE);
3141 scr_forwardindex ();
3146 PrivMode ((ch == '='), PrivMode_aplKP);
3156 /* 8.3.87: NEXT LINE */
3157 case C1_NEL: /* ESC E */
3159 wchar_t nlcr[] = { C0_LF, C0_CR };
3160 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3164 /* kidnapped escape sequence: Should be 8.3.48 */
3165 case C1_ESA: /* ESC G */
3166 process_graphics ();
3169 /* 8.3.63: CHARACTER TABULATION SET */
3170 case C1_HTS: /* ESC H */
3174 /* 8.3.105: REVERSE LINE FEED */
3175 case C1_RI: /* ESC M */
3179 /* 8.3.142: SINGLE-SHIFT TWO */
3180 /*case C1_SS2: scr_single_shift (2); break; */
3182 /* 8.3.143: SINGLE-SHIFT THREE */
3183 /*case C1_SS3: scr_single_shift (3); break; */
3185 /* 8.3.27: DEVICE CONTROL STRING */
3186 case C1_DCS: /* ESC P */
3190 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3191 case C1_SCI: /* ESC Z */
3192 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3193 break; /* steal obsolete ESC [ c */
3195 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3196 case C1_CSI: /* ESC [ */
3200 /* 8.3.90: OPERATING SYSTEM COMMAND */
3201 case C1_OSC: /* ESC ] */
3205 /* 8.3.106: RESET TO INITIAL STATE */
3212 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3214 scr_charset_choose (2);
3217 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3219 scr_charset_choose (3);
3225 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3229 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3230 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3231 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3232 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3233 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3234 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3235 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3236 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3239 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3240 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3241 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3242 #define get_byte_array_bit(array, bit) \
3243 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3245 const unsigned char csi_defaults[] =
3247 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3248 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3249 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3250 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3251 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3252 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3253 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3254 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3259 rxvt_term::process_csi_seq ()
3261 unicode_t ch, priv, i;
3262 unsigned int nargs, p;
3266 for (nargs = ESC_ARGS; nargs > 0;)
3271 if (ch >= '<' && ch <= '?')
3272 { /* '<' '=' '>' '?' */
3277 /* read any numerical arguments */
3278 for (n = -1; ch < CSI_ICH; )
3285 n = n * 10 + ch - '0';
3289 if (nargs < ESC_ARGS)
3293 else if (IS_CONTROL (ch))
3294 process_nonprinting (ch);
3302 if (nargs < ESC_ARGS)
3306 ndef = get_byte_array_bit (csi_defaults, i);
3307 for (p = 0; p < nargs; p++)
3312 fprintf (stderr, "CSI ");
3313 for (p = 0; p < nargs; p++)
3314 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3315 fprintf (stderr, "%c\n", ch);
3319 * private mode handling
3326 if (ch == CSI_DA) /* secondary device attributes */
3327 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3330 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3331 process_terminal_mode (ch, priv, nargs, arg);
3340 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3343 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3346 case 0: /* initiate transfer to primary aux device */
3347 scr_printscreen (0);
3349 case 5: /* start relay to primary aux device */
3350 process_print_pipe ();
3356 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3357 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3360 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3361 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3362 scr_gotorc (arg[0], 0, RELATIVE);
3365 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3366 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3369 #else /* emulate common DEC VTs */
3370 arg[0] = arg[0] ? -arg[0] : -1;
3373 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3374 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3376 scr_gotorc (0, arg[0], RELATIVE);
3377 #else /* emulate common DEC VTs */
3378 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3382 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3385 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3386 scr_gotorc (arg[0], 0, R_RELATIVE);
3389 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3390 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3391 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3394 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3395 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3398 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3399 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3400 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3403 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3406 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3410 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3411 scr_erase_screen (arg[0]);
3414 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3415 scr_erase_line (arg[0]);
3418 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3419 scr_insdel_chars (arg[0], INSERT);
3422 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3423 scr_insdel_lines (arg[0], INSERT);
3426 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3427 scr_insdel_lines (arg[0], DELETE);
3430 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3431 scr_insdel_chars (arg[0], ERASE);
3434 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3435 scr_insdel_chars (arg[0], DELETE);
3438 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3441 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3442 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3445 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3446 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3449 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3450 process_sgr_mode (nargs, arg);
3453 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3456 case 5: /* DSR requested */
3457 tt_printf ("\033[0n");
3459 case 6: /* CPR requested */
3460 scr_report_position ();
3462 case 7: /* unofficial extension */
3463 if (OPTION (Opt_insecure))
3464 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3466 case 8: /* unofficial extension */
3467 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3472 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3475 case 0: /* char tab stop cleared at active position */
3478 /* case 1: */ /* line tab stop cleared in active line */
3479 /* case 2: */ /* char tab stops cleared in active line */
3480 case 3: /* all char tab stops are cleared */
3481 /* case 4: */ /* all line tab stops are cleared */
3482 case 5: /* all tab stops are cleared */
3488 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3491 case 0: /* char tab stop set at active position */
3493 break; /* = ESC H */
3494 /* case 1: */ /* line tab stop set at active line */
3495 case 2: /* char tab stop cleared at active position */
3497 break; /* = ESC [ 0 g */
3498 /* case 3: */ /* line tab stop cleared at active line */
3499 /* case 4: */ /* char tab stops cleared at active line */
3500 case 5: /* all char tab stops are cleared */
3502 break; /* = ESC [ 3 g */
3503 /* case 6: */ /* all line tab stops are cleared */
3507 case CSI_RM: /* 8.3.107: RESET MODE */
3509 scr_insert_mode (0);
3510 else if (arg[0] == 20)
3511 priv_modes &= ~PrivMode_LFNL;
3514 case CSI_SM: /* 8.3.126: SET MODE */
3516 scr_insert_mode (1);
3517 else if (arg[0] == 20)
3518 priv_modes |= PrivMode_LFNL;
3522 * PRIVATE USE beyond this point. All CSI_7? sequences here
3524 case CSI_72: /* DECSTBM: set top and bottom margins */
3526 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3527 else if (nargs == 0 || arg[0] >= arg[1])
3528 scr_scroll_region (0, MAX_ROWS - 1);
3530 scr_scroll_region (arg[0] - 1, arg[1] - 1);
3537 scr_cursor (RESTORE);
3542 process_window_ops (arg, nargs);
3546 case CSI_78: /* DECREQTPARM */
3547 if (arg[0] == 0 || arg[0] == 1)
3548 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3560 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3563 XWindowAttributes wattr;
3575 case 1: /* deiconify window */
3576 XMapWindow (disp, parent[0]);
3578 case 2: /* iconify window */
3579 XIconifyWindow (disp, parent[0], display->screen);
3581 case 3: /* set position (pixels) */
3582 XMoveWindow (disp, parent[0], args[1], args[2]);
3584 case 4: /* set size (pixels) */
3585 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3587 case 5: /* raise window */
3588 XRaiseWindow (disp, parent[0]);
3590 case 6: /* lower window */
3591 XLowerWindow (disp, parent[0]);
3593 case 7: /* refresh window */
3596 case 8: /* set size (chars) */
3597 set_widthheight ((unsigned int) (args[2] * fwidth),
3598 (unsigned int) (args[1] * fheight));
3601 //case 9: NYI, TODO, restore maximized window or maximize window
3603 if (args[0] >= 24) /* set height (chars) */
3604 set_widthheight ((unsigned int)width,
3605 (unsigned int) (args[1] * fheight));
3610 * reports - some output format copied from XTerm
3612 case 11: /* report window state */
3613 XGetWindowAttributes (disp, parent[0], &wattr);
3614 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3616 case 13: /* report window position */
3617 XGetWindowAttributes (disp, parent[0], &wattr);
3618 XTranslateCoordinates (disp, parent[0], wattr.root,
3619 -wattr.border_width, -wattr.border_width,
3621 tt_printf ("\033[3;%d;%dt", x, y);
3623 case 14: /* report window size (pixels) */
3624 XGetWindowAttributes (disp, parent[0], &wattr);
3625 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3627 case 18: /* report text area size (chars) */
3628 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3630 case 19: /* report window size (chars) */
3631 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3633 case 20: /* report icon label */
3636 XGetIconName (disp, parent[0], &s);
3637 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3641 case 21: /* report window title */
3644 XFetchName (disp, parent[0], &s);
3645 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3653 /*----------------------------------------------------------------------*/
3655 * get input up until STRING TERMINATOR (or BEL)
3656 * ends_how is terminator used. returned input must be free()'d
3659 rxvt_term::get_to_st (unicode_t &ends_how)
3662 bool seen_esc = false;
3664 wchar_t string[STRING_MAX];
3666 while ((ch = cmd_getc ()) != NOCHAR)
3670 if (ch == 0x5c) /* 7bit ST */
3675 else if (ch == C0_ESC)
3680 else if (ch == C0_BEL || ch == CHAR_ST)
3683 return NULL; /* other control character - exit */
3687 if (n >= STRING_MAX - 1)
3688 // stop at some sane length
3692 string[n++] = cmd_get8 ();
3699 ends_how = (ch == 0x5c ? C0_ESC : ch);
3701 return rxvt_wcstombs (string);
3704 /*----------------------------------------------------------------------*/
3706 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3709 rxvt_term::process_dcs_seq ()
3724 /*----------------------------------------------------------------------*/
3726 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3729 rxvt_term::process_osc_seq ()
3735 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3736 arg = arg * 10 + (ch - '0');
3740 char *s = get_to_st (eh);
3744 process_xterm_seq (arg, s, eh);
3751 rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3753 if (str[0] == '?' && !str[1])
3755 unsigned short r, g, b;
3756 pix_colors_focused[color].get (display, r, g, b);
3757 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3760 set_window_color (color, str);
3764 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3767 rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3772 bool query = str[0] == '?' && !str[1];
3776 assert (str != NULL);
3782 case XTerm_iconName:
3783 set_icon_name (str);
3788 case XTerm_property:
3791 Atom prop = display->atom (str + 1);
3794 unsigned long nitems;
3795 unsigned long bytes_after;
3796 unsigned char *value = 0;
3797 const char *str = "";
3800 && XGetWindowProperty (disp, parent[0],
3801 prop, 0, 1<<16, 0, AnyPropertyType,
3802 &actual_type, &actual_format,
3803 &nitems, &bytes_after, &value) == Success
3804 && actual_type != None
3805 && actual_format == 8)
3806 str = (const char *)(value);
3808 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3814 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3819 set_utf8_property (display->atom (str), eq + 1);
3822 XDeleteProperty (disp, parent[0],
3823 display->atom (str));
3828 for (buf = (char *)str; buf && *buf;)
3830 if ((name = strchr (buf, ';')) == NULL)
3834 color = atoi (buf) + minCOLOR;
3836 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3839 if ((buf = strchr (name, ';')) != NULL)
3842 if (name[0] == '?' && !name[1])
3844 unsigned short r, g, b;
3845 pix_colors_focused[color].get (display, r, g, b);
3846 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3849 set_window_color (color, name);
3853 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3856 process_color_seq (XTerm_Color01, Color_bg, str, resp);
3858 #ifndef NO_CURSORCOLOR
3859 case XTerm_Color_cursor:
3860 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3863 case XTerm_Color_pointer_fg:
3864 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3866 case XTerm_Color_pointer_bg:
3867 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3869 #ifndef NO_BOLD_UNDERLINE_REVERSE
3870 case XTerm_Color_RV:
3871 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3874 case URxvt_Color_BD:
3875 process_color_seq (op, Color_BD, str, resp);
3878 case URxvt_Color_UL:
3879 process_color_seq (op, Color_UL, str, resp);
3881 case URxvt_Color_IT:
3882 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3885 #if TRANSPARENT && TINTING
3886 case URxvt_Color_tint:
3887 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3888 check_our_parents ();
3890 want_full_refresh = want_refresh = 1;
3898 scale_pixmap (""); /* reset to default scaling */
3899 set_bgPixmap (str); /* change pixmap */
3904 while ((str = strchr (str, ';')) != NULL)
3908 changed += scale_pixmap (str);
3914 #ifdef XPM_BACKGROUND
3921 case Rxvt_restoreFG:
3922 set_window_color (Color_fg, str);
3924 case Rxvt_restoreBG:
3925 set_window_color (Color_bg, str);
3929 // TODO, when secure mode?
3933 case Rxvt_dumpscreen: /* no error notices */
3936 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3948 case URxvt_boldFont:
3949 case URxvt_italicFont:
3950 case URxvt_boldItalicFont:
3953 tt_printf ("\33]%d;%-.250s%c", saveop,
3954 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3955 ? fontset[op - URxvt_font]->fontdesc : "",
3959 const char *&res = rs[Rs_font + (op - URxvt_font)];
3962 allocated.push_back ((void *)res);
3970 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp);
3974 pty->set_utf8_mode (enc_utf8);
3980 case URxvt_view_down:
3982 int lines = atoi (str);
3985 scr_page (op == URxvt_view_up ? UP : DN, lines);
3987 scr_erase_savelines ();
3995 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END)))
3996 ; // no responses yet
4001 /*----------------------------------------------------------------------*/
4003 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
4005 * mode can only have the following values:
4011 * so no need for fancy checking
4014 rxvt_term::privcases (int mode, unsigned long bit)
4020 SavedModes |= (priv_modes & bit);
4026 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
4028 state = (mode == 't') ? ! (priv_modes & bit) : mode;
4029 PrivMode (state, bit);
4035 /* we're not using priv _yet_ */
4037 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
4045 const unsigned long bit;
4049 { 1, PrivMode_aplCUR },
4050 { 2, PrivMode_vt52 },
4051 { 3, PrivMode_132 },
4052 { 4, PrivMode_smoothScroll },
4053 { 5, PrivMode_rVideo },
4054 { 6, PrivMode_relOrigin },
4055 { 7, PrivMode_Autowrap },
4056 // 8, bi-directional support mode
4057 { 9, PrivMode_MouseX10 },
4058 // 18, 19 printing-related
4059 { 25, PrivMode_VisibleCursor },
4060 #ifdef scrollBar_esc
4061 { scrollBar_esc, PrivMode_scrollBar },
4063 { 35, PrivMode_ShiftKeys }, // rxvt extension
4064 { 40, PrivMode_132OK },
4065 // 41 xterm more fixes NYI
4066 // 45 margin bell NYI
4068 { 47, PrivMode_Screen },
4069 { 66, PrivMode_aplKP },
4070 #ifndef NO_BACKSPACE_KEY
4071 { 67, PrivMode_BackSpace },
4073 { 1000, PrivMode_MouseX11 },
4074 // 1001 Use Hilite Mouse Tracking. NYI, TODO
4075 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
4076 // 1003 Use All Motion Mouse Tracking. NYI, TODO
4077 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4078 { 1011, PrivMode_Keypress }, // rxvt extension
4079 // 1035 enable modifiers for alt, numlock NYI
4080 // 1036 send ESC for meta keys NYI
4081 // 1037 send DEL for keypad delete NYI
4082 { 1047, PrivMode_Screen },
4083 // 1048 save and restore cursor
4084 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4085 // 1051, 1052, 1060, 1061 keyboard emulation NYI
4091 /* make lo/hi boolean */
4093 mode = 0; /* reset */
4094 else if (mode == 'h')
4097 for (i = 0; i < nargs; i++)
4101 /* basic handling */
4102 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
4103 if (argtopriv[j].argval == arg[i])
4105 state = privcases (mode, argtopriv[j].bit);
4109 /* extra handling for values with state unkept */
4114 set_option (Opt_intensityStyles, mode);
4119 case 1048: /* alternative cursor save */
4121 if (OPTION (Opt_secondaryScreen))
4123 scr_cursor (RESTORE);
4130 /* extra handling for values with valid 0 or 1 state */
4133 /* case 1: - application cursor keys */
4134 case 2: /* VT52 mode */
4135 /* oddball mode. should be set regardless of set/reset
4136 * parameter. Return from VT52 mode with an ESC < from
4139 PrivMode (1, PrivMode_vt52);
4141 case 3: /* 80/132 */
4142 if (priv_modes & PrivMode_132OK)
4143 set_widthheight (((state ? 132 : 80) * fwidth), height);
4145 case 4: /* smooth scrolling */
4146 set_option (Opt_jumpScroll, !state);
4148 case 5: /* reverse video */
4149 scr_rvideo_mode (state);
4151 case 6: /* relative/absolute origins */
4152 scr_relative_origin (state);
4154 case 7: /* autowrap */
4155 scr_autowrap (state);
4157 /* case 8: - auto repeat, can't do on a per window basis */
4158 case 9: /* X10 mouse reporting */
4159 if (state) /* orthogonal */
4160 priv_modes &= ~PrivMode_MouseX11;
4162 #ifdef scrollBar_esc
4164 if (scrollbar_mapping (state))
4166 resize_all_windows (0, 0, 0);
4171 case 25: /* visible/invisible cursor */
4172 scr_cursor_visible (state);
4174 /* case 35: - shift keys */
4175 /* case 40: - 80 <--> 132 mode */
4176 case 47: /* secondary screen */
4177 scr_change_screen (state);
4179 /* case 66: - application key pad */
4180 /* case 67: - backspace key */
4181 case 1000: /* X11 mouse reporting */
4182 if (state) /* orthogonal */
4183 priv_modes &= ~PrivMode_MouseX10;
4187 break; /* X11 mouse highlighting */
4189 case 1010: /* scroll to bottom on TTY output inhibit */
4190 set_option (Opt_scrollTtyOutput, !state);
4192 case 1011: /* scroll to bottom on key press */
4193 set_option (Opt_scrollTtyKeypress, state);
4195 case 1047: /* secondary screen w/ clearing last */
4196 if (OPTION (Opt_secondaryScreen))
4197 if (current_screen != PRIMARY)
4198 scr_erase_screen (2);
4199 scr_change_screen (state);
4201 case 1049: /* secondary screen w/ clearing first */
4202 scr_change_screen (state);
4203 if (OPTION (Opt_secondaryScreen))
4204 if (current_screen != PRIMARY)
4205 scr_erase_screen (2);
4214 /*{{{ process sgr sequences */
4216 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4224 scr_rendition (0, ~RS_None);
4228 for (i = 0; i < nargs; i++)
4234 rendset = 0, rendstyle = ~RS_None;
4237 rendset = 1, rendstyle = RS_Bold;
4239 //case 2: // low intensity
4241 rendset = 1, rendstyle = RS_Italic;
4244 rendset = 1, rendstyle = RS_Uline;
4246 case 5: // slowly blinking
4247 case 6: // rapidly blinking
4248 rendset = 1, rendstyle = RS_Blink;
4250 //case 6: // scoansi light background
4252 rendset = 1, rendstyle = RS_RVid;
4257 //case 9: // crossed out
4258 //case 10: // scoansi acs off, primary font
4259 //case 11: // scoansi acs on, first alt font
4260 //case 12: // scoansi acs on, |0x80, second alt font
4262 //case 19: // ninth alt font
4263 //case 20: // gothic
4264 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4265 rendset = 0, rendstyle = RS_Bold;
4267 case 22: // normal intensity
4268 rendset = 0, rendstyle = RS_Bold;
4270 case 23: // disable italic
4271 rendset = 0, rendstyle = RS_Italic;
4274 rendset = 0, rendstyle = RS_Uline;
4277 rendset = 0, rendstyle = RS_Blink;
4279 case 26: // variable spacing (iso 8613)
4280 rendset = 0, rendstyle = RS_Blink;
4283 rendset = 0, rendstyle = RS_RVid;
4285 //case 28: // visible. NYI
4286 //case 29: // not crossed-out
4291 scr_rendition (rendset, rendstyle);
4292 continue; /* for (;i;) */
4298 case 31: /* set fg color */
4305 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4307 case 38: // set fg color, ISO 8613-6
4308 if (nargs > i + 2 && arg[i + 1] == 5)
4310 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4314 case 39: /* default fg */
4315 scr_color (Color_fg, Color_fg);
4319 case 41: /* set bg color */
4326 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4328 case 48: // set bg color, ISO 8613-6
4329 if (nargs > i + 2 && arg[i + 1] == 5)
4331 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4335 case 49: /* default bg */
4336 scr_color (Color_bg, Color_bg);
4339 //case 50: // not variable spacing
4343 case 91: /* set bright fg color */
4350 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4353 case 101: /* set bright bg color */
4360 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4368 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4370 rxvt_term::process_graphics ()
4372 unicode_t ch, cmd = cmd_getc ();
4375 { /* query graphics */
4376 tt_printf ("\033G0\012"); /* no graphics */
4379 /* swallow other graphics sequences until terminating ':' */
4386 /* ------------------------------------------------------------------------- */
4389 * Send printf () formatted output to the command.
4390 * Only use for small amounts of data.
4393 rxvt_term::tt_printf (const char *fmt,...)
4398 va_start (arg_ptr, fmt);
4399 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4401 tt_write (buf, strlen (buf));
4404 /* ---------------------------------------------------------------------- */
4405 /* Write data to the pty as typed by the user, pasted with the mouse,
4406 * or generated by us in response to a query ESC sequence.
4408 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4411 rxvt_term::tt_write (const char *data, unsigned int len)
4413 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4421 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4423 if ((unsigned int)written == len)
4430 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4432 memcpy (v_buffer + v_buflen, data, len);
4435 pty_ev.set (EVENT_READ | EVENT_WRITE);
4438 void rxvt_term::pty_write ()
4440 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4444 v_buflen -= written;
4452 pty_ev.set (EVENT_READ);
4456 memmove (v_buffer, v_buffer + written, v_buflen);
4458 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4459 pty_ev.set (EVENT_READ);
4462 /*----------------------- end-of-file (C source) -----------------------*/