1 /*--------------------------------*-C-*---------------------------------*
3 *----------------------------------------------------------------------*
4 * $Id: command.C,v 1.34 2004-01-31 00:20:21 pcg Exp $
6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
10 * - extensive modifications
11 * Copyright (c) 1995 Garrett D'Amore <garrett@netcom.com>
13 * Copyright (c) 1995 Steven Hirsch <hirsch@emba.uvm.edu>
14 * - X11 mouse report mode and support for
15 * DEC "private mode" save/restore functions.
16 * Copyright (c) 1995 Jakub Jelinek <jj@gnu.ai.mit.edu>
17 * - key-related changes to handle Shift+function
19 * Copyright (c) 1997 MJ Olesen <olesen@me.queensu.ca>
20 * - extensive modifications
21 * Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es>
22 * - modification and cleanups for Solaris 2.x
24 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
25 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
26 * - extensive modifications
27 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
28 * Copyright (c) 2001 Marius Gedminas
29 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
30 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/
48 #include "../config.h" /* NECESSARY */
49 #include "rxvt.h" /* NECESSARY */
55 /*----------------------------------------------------------------------*/
57 /*{{{ Convert the keypress event into a string */
59 rxvt_term::lookup_key (XKeyEvent *ev)
61 int ctrl, meta, shft, len;
65 static int debug_key = 1; /* accessible by a debugger only */
68 unsigned char kbuf[KBUFSZ];
71 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
72 * escape sequence to toggle the Keypad.
74 * Always permit `shift' to override the current setting
76 shft = (ev->state & ShiftMask);
77 ctrl = (ev->state & ControlMask);
78 meta = (ev->state & ModMetaMask);
80 if (numlock_state || (ev->state & ModNumLockMask))
82 numlock_state = (ev->state & ModNumLockMask);
83 PrivMode((!numlock_state), PrivMode_aplKP);
93 #ifdef X_HAVE_UTF8_STRING
95 len = Xutf8LookupString (Input_Context, ev, (char *)kbuf,
96 KBUFSZ, &keysym, &status_return);
100 wchar_t wkbuf[KBUFSZ + 1];
102 // the XOpenIM manpage lies about hardcoding the locale
103 // at the point of XOpenIM, so temporarily switch locales
105 SET_LOCALE (rs[Rs_imLocale]);
106 // assume wchar_t == unicode or better
107 len = XwcLookupString (Input_Context, ev, wkbuf,
108 KBUFSZ, &keysym, &status_return);
112 if (status_return == XLookupChars
113 || status_return == XLookupBoth)
116 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
124 valid_keysym = status_return == XLookupKeySym
125 || status_return == XLookupBoth;
130 len = XLookupString (ev, (char *)kbuf, KBUFSZ, &keysym, &compose);
136 /* for some backwards compatibility */
137 #if defined(HOTKEY_CTRL) || defined(HOTKEY_META)
144 if (keysym == ks_bigfont)
146 change_font (0, FONT_UP);
149 else if (keysym == ks_smallfont)
151 change_font (0, FONT_DN);
157 if (TermWin.saveLines) {
158 #ifdef UNSHIFTED_SCROLLKEYS
159 if (!ctrl && !meta) {
165 #ifdef PAGING_CONTEXT_LINES
166 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES;
168 lnsppg = TermWin.nrow * 4 / 5;
170 if (keysym == XK_Prior) {
171 scr_page (UP, lnsppg);
173 } else if (keysym == XK_Next) {
174 scr_page (DN, lnsppg);
178 #ifdef SCROLL_ON_UPDOWN_KEYS
180 if (keysym == XK_Up) {
183 } else if (keysym == XK_Down) {
189 #ifdef SCROLL_ON_HOMEEND_KEYS
191 if (keysym == XK_Home) {
194 } else if (keysym == XK_End) {
203 /* Shift + F1 - F10 generates F11 - F20 */
204 if (keysym >= XK_F1 && keysym <= XK_F10) {
205 keysym += (XK_F11 - XK_F1);
206 shft = 0; /* turn off Shift */
207 } else if (!ctrl && !meta && (PrivateModes & PrivMode_ShiftKeys)) {
209 /* normal XTerm key bindings */
210 case XK_Insert: /* Shift+Insert = paste mouse selection */
211 selection_request (ev->time, 0, 0);
214 case XK_KP_Add: /* Shift+KP_Add = bigger font */
215 change_font (0, FONT_UP);
217 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
218 change_font (0, FONT_DN);
224 if (keysym == XK_Print) {
225 scr_printscreen (ctrl | shft);
230 if (keysym == ks_greekmodeswith) {
231 greek_mode = !greek_mode;
233 xterm_seq (XTerm_title,
234 (greek_getmode() == GREEK_ELOT928
235 ? "[Greek: iso]" : "[Greek: ibm]"), CHAR_ST);
238 xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST);
243 if (keysym >= 0xFF00 && keysym <= 0xFFFF) {
244 #ifdef KEYSYM_RESOURCE
245 if (!(shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) {
247 const unsigned char *kbuf0;
248 const unsigned char ch = C0_ESC;
250 kbuf0 = (Keysym_map[keysym & 0xFF]);
251 l = (unsigned int)*kbuf0++;
256 if (meta_char == C0_ESC)
266 #ifndef NO_BACKSPACE_KEY
268 if (PrivateModes & PrivMode_HaveBackSpace) {
269 kbuf[0] = (!!(PrivateModes & PrivMode_BackSpace)
270 ^ !!ctrl) ? '\b' : '\177';
273 STRCPY(kbuf, key_backspace);
274 # ifdef MULTICHAR_SET
275 if ((Options & Opt_mc_hack) && screen.cur.col > 0) {
278 newlen = STRLEN(kbuf);
279 col = screen.cur.col - 1;
280 row = screen.cur.row + TermWin.saveLines;
281 if (IS_MULTI2(screen.rend[row][col]))
282 MEMMOVE(kbuf + newlen, kbuf, newlen + 1);
287 #ifndef NO_DELETE_KEY
289 STRCPY(kbuf, key_delete);
290 # ifdef MULTICHAR_SET
291 if (Options & Opt_mc_hack) {
294 newlen = STRLEN(kbuf);
295 col = screen.cur.col;
296 row = screen.cur.row + TermWin.saveLines;
297 if (IS_MULTI1(screen.rend[row][col]))
298 MEMMOVE(kbuf + newlen, kbuf, newlen + 1);
305 STRCPY(kbuf, "\033[Z");
307 #ifdef CTRL_TAB_MAKES_META
311 #ifdef MOD4_TAB_MAKES_META
312 if (ev->state & Mod4Mask)
321 case XK_KP_Up: /* \033Ox or standard */
322 case XK_KP_Down: /* \033Or or standard */
323 case XK_KP_Right: /* \033Ov or standard */
324 case XK_KP_Left: /* \033Ot or standard */
325 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
326 STRCPY(kbuf, "\033OZ");
327 kbuf[2] = ("txvr"[keysym - XK_KP_Left]);
330 /* translate to std. cursor key */
331 keysym = XK_Left + (keysym - XK_KP_Left);
334 case XK_Up: /* "\033[A" */
335 case XK_Down: /* "\033[B" */
336 case XK_Right: /* "\033[C" */
337 case XK_Left: /* "\033[D" */
338 STRCPY(kbuf, "\033[Z");
339 kbuf[2] = ("DACB"[keysym - XK_Left]);
342 kbuf[2] = ("dacb"[keysym - XK_Left]);
345 kbuf[2] = ("dacb"[keysym - XK_Left]);
346 } else if (PrivateModes & PrivMode_aplCUR)
350 if (Options & Opt_mc_hack) {
353 col = screen.cur.col;
354 row = screen.cur.row + TermWin.saveLines;
356 if (keysym == XK_Right
357 && IS_MULTI1(screen.rend[row][col]))
359 else if (keysym == XK_Left) {
361 if (IS_MULTI2(screen.rend[row][col - 1]))
363 } else if (screen.cur.row > 0) {
364 col = screen.tlen[--row];
366 col = TermWin.ncol - 1;
370 && IS_MULTI2(screen.rend[row][col]))
375 MEMMOVE(kbuf + 3, kbuf, 3 + 1);
380 #ifndef UNSHIFTED_SCROLLKEYS
383 /* allow shift to override */
384 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
385 STRCPY(kbuf, "\033Oy");
391 STRCPY(kbuf, "\033[5~");
395 /* allow shift to override */
396 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
397 STRCPY(kbuf, "\033Os");
403 STRCPY(kbuf, "\033[6~");
407 /* allow shift to override */
408 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
409 STRCPY(kbuf, "\033OM");
418 STRCPY(kbuf, "\033Ou");
422 STRCPY(kbuf, "\033Op");
426 STRCPY(kbuf, "\033On");
429 case XK_KP_F1: /* "\033OP" */
430 case XK_KP_F2: /* "\033OQ" */
431 case XK_KP_F3: /* "\033OR" */
432 case XK_KP_F4: /* "\033OS" */
433 STRCPY(kbuf, "\033OP");
434 kbuf[2] += (keysym - XK_KP_F1);
437 case XK_KP_Multiply: /* "\033Oj" : "*" */
438 case XK_KP_Add: /* "\033Ok" : "+" */
439 case XK_KP_Separator: /* "\033Ol" : "," */
440 case XK_KP_Subtract: /* "\033Om" : "-" */
441 case XK_KP_Decimal: /* "\033On" : "." */
442 case XK_KP_Divide: /* "\033Oo" : "/" */
443 case XK_KP_0: /* "\033Op" : "0" */
444 case XK_KP_1: /* "\033Oq" : "1" */
445 case XK_KP_2: /* "\033Or" : "2" */
446 case XK_KP_3: /* "\033Os" : "3" */
447 case XK_KP_4: /* "\033Ot" : "4" */
448 case XK_KP_5: /* "\033Ou" : "5" */
449 case XK_KP_6: /* "\033Ov" : "6" */
450 case XK_KP_7: /* "\033Ow" : "7" */
451 case XK_KP_8: /* "\033Ox" : "8" */
452 case XK_KP_9: /* "\033Oy" : "9" */
453 /* allow shift to override */
454 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
455 STRCPY(kbuf, "\033Oj");
456 kbuf[2] += (keysym - XK_KP_Multiply);
458 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
464 STRCPY(kbuf, "\033[1~");
467 STRCPY(kbuf, "\033[2~");
469 #ifdef DXK_Remove /* support for DEC remove like key */
474 STRCPY(kbuf, "\033[3~");
477 STRCPY(kbuf, "\033[4~");
481 /* allow shift to override */
482 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
483 STRCPY(kbuf, "\033Oq");
489 STRCPY(kbuf, KS_END);
493 /* allow shift to override */
494 if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) {
495 STRCPY(kbuf, "\033Ow");
501 STRCPY(kbuf, KS_HOME);
504 #define FKEY(n, fkey) \
505 sprintf((char *)kbuf,"\033[%2d~", (int)((n) + (keysym - fkey)))
507 case XK_F1: /* "\033[11~" */
508 case XK_F2: /* "\033[12~" */
509 case XK_F3: /* "\033[13~" */
510 case XK_F4: /* "\033[14~" */
511 case XK_F5: /* "\033[15~" */
514 case XK_F6: /* "\033[17~" */
515 case XK_F7: /* "\033[18~" */
516 case XK_F8: /* "\033[19~" */
517 case XK_F9: /* "\033[20~" */
518 case XK_F10: /* "\033[21~" */
521 case XK_F11: /* "\033[23~" */
522 case XK_F12: /* "\033[24~" */
523 case XK_F13: /* "\033[25~" */
524 case XK_F14: /* "\033[26~" */
527 case XK_F15: /* "\033[28~" */
528 case XK_F16: /* "\033[29~" */
531 case XK_Help: /* "\033[28~" */
534 case XK_Menu: /* "\033[29~" */
537 case XK_F17: /* "\033[31~" */
538 case XK_F18: /* "\033[32~" */
539 case XK_F19: /* "\033[33~" */
540 case XK_F20: /* "\033[34~" */
541 case XK_F21: /* "\033[35~" */
542 case XK_F22: /* "\033[36~" */
543 case XK_F23: /* "\033[37~" */
544 case XK_F24: /* "\033[38~" */
545 case XK_F25: /* "\033[39~" */
546 case XK_F26: /* "\033[40~" */
547 case XK_F27: /* "\033[41~" */
548 case XK_F28: /* "\033[42~" */
549 case XK_F29: /* "\033[43~" */
550 case XK_F30: /* "\033[44~" */
551 case XK_F31: /* "\033[45~" */
552 case XK_F32: /* "\033[46~" */
553 case XK_F33: /* "\033[47~" */
554 case XK_F34: /* "\033[48~" */
555 case XK_F35: /* "\033[49~" */
567 * Pass meta for all function keys, if 'meta' option set
570 if (meta && (meta_char == 0x80) && len > 0)
571 kbuf[len - 1] |= 0x80;
573 } else if (ctrl && keysym == XK_minus) {
575 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
579 if (meta && (meta_char == 0x80)) {
582 for (ch = kbuf; ch < kbuf + len; ch++)
589 len = greek_xlat(kbuf, len);
596 return; /* not mapped */
598 if (Options & Opt_scrollTtyKeypress)
599 if (TermWin.view_start) {
600 TermWin.view_start = 0;
605 * these modifications only affect the static keybuffer
606 * pass Shift/Control indicators for function keys ending with `~'
610 * Shift+Prior = "ESC[5$"
611 * Ctrl+Prior = "ESC[5^"
612 * Ctrl+Shift+Prior = "ESC[5@"
613 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
615 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
616 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
621 && (meta_char == C0_ESC)
624 const unsigned char ch = C0_ESC;
629 if (debug_key) { /* Display keyboard buffer contents */
633 fprintf(stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
634 for (i = 0, p = kbuf; i < len; i++, p++)
635 fprintf(stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
636 fprintf(stderr, "'\n");
638 #endif /* DEBUG_CMD */
639 tt_write (kbuf, (unsigned int)len);
644 /*{{{ rxvt_cmd_write(), rxvt_cmd_getc() */
645 /* attempt to `write' count to the input buffer */
647 rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
651 n = cmdbuf_ptr - cmdbuf_base;
652 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp;
653 if (n > 0 && s < count) {
654 MEMMOVE(cmdbuf_base, cmdbuf_ptr,
655 (unsigned int)(cmdbuf_endp - cmdbuf_ptr));
656 cmdbuf_ptr = cmdbuf_base;
661 rxvt_print_error("data loss: cmd_write too large");
665 *cmdbuf_endp++ = *str++;
668 #endif /* MENUBAR_MAX */
674 if (want_full_refresh)
676 want_full_refresh = 0;
685 scr_refresh (refresh_type);
696 rxvt_term::check_cb (check_watcher &w)
705 rxvt_term::process_x_events ()
711 XNextEvent (Xdisplay, &xev);
713 #if defined(CURSOR_BLINK)
714 if ((Options & Opt_cursorBlink) && xev.type == KeyPress)
722 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
726 #if defined(POINTER_BLANK)
727 if ((Options & Opt_pointerBlank) && pointerBlankDelay > 0)
729 if (xev.type == MotionNotify
730 || xev.type == ButtonPress
731 || xev.type == ButtonRelease)
735 if (xev.type == KeyPress && hidden_pointer == 0)
741 if (!XFilterEvent (&xev, xev.xany.window))
743 process_x_event (&xev);
745 while (XPending (Xdisplay));
750 rxvt_term::cursor_blink_cb (time_watcher &w)
752 hidden_cursor = !hidden_cursor;
755 w.start (w.at + BLINK_INTERVAL);
761 rxvt_term::text_blink_cb (time_watcher &w)
763 if (scr_refresh_rend (RS_Blink, RS_Blink))
765 hidden_text = !hidden_text;
767 w.start (w.at + TEXT_BLINK_INTERVAL);
773 rxvt_term::x_cb (io_watcher &w, short revents)
782 rxvt_term::pty_fill ()
784 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
786 memmove (cmdbuf_base, cmdbuf_ptr, n);
787 cmdbuf_ptr = cmdbuf_base;
788 cmdbuf_endp = cmdbuf_ptr + n;
790 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
797 else if (n < 0 && errno != EAGAIN)
804 rxvt_term::pty_cb (io_watcher &w, short revents)
809 if (revents & EVENT_WRITE)
811 else if (revents & EVENT_READ)
815 // loop, but don't allow a single term to monopolize us
816 // the number of loops is fully arbitrary, and thus wrong
817 while (flag && pty_fill ())
822 /* once we know the shell is running, send the screen size. Again! */
826 uint32_t ch = NOCHAR;
833 if (ch == NOCHAR) // TODO: improve
836 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
838 /* Read a text string from the input buffer */
839 uint32_t buf[BUFSIZ];
840 bool refreshnow = false;
850 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
861 if (!(Options & Opt_jumpScroll)
862 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
871 if (str >= buf + BUFSIZ)
879 scr_add_lines (buf, nlines, str - buf);
882 * If there have been a lot of new lines, then update the screen
883 * What the heck I'll cheat and only refresh less than every page-full.
884 * the number of pages between refreshes is refresh_limit, which
885 * is incremented here because we must be doing flat-out scrolling.
887 * refreshing should be correct for small scrolls, because of the
892 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
895 scr_refresh (refresh_type);
904 process_nonprinting (ch);
906 case C0_ESC: /* escape char */
907 process_escape_seq ();
909 /*case 0x9b: */ /* CSI */
910 /* process_csi_seq (); */
920 // read the next character, currently handles UTF-8
921 // will probably handle all sorts of other stuff in the future
923 rxvt_term::next_char ()
925 while (cmdbuf_ptr < cmdbuf_endp)
927 if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh
928 return *cmdbuf_ptr++;
931 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, &mbstate.mbs);
933 if (len == (size_t)-2)
936 if (len == (size_t)-1)
937 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
939 // assume wchar == unicode
947 /* rxvt_cmd_getc() - Return next input character */
949 * Return the next input character after first passing any keyboard input
953 rxvt_term::cmd_getc ()
957 uint32_t c = next_char ();
961 // incomplete sequences should occur rarely, still, a better solution
962 // would be preferred. either setjmp/longjmp or better design.
963 fcntl (cmd_fd, F_SETFL, 0);
965 fcntl (cmd_fd, F_SETFL, O_NONBLOCK);
969 #define TIMEOUT_USEC 5000
971 int quick_timeout, select_res;
972 int want_motion_time, want_keypress_time;
973 struct timeval value;
974 #if defined(POINTER_BLANK) || defined(CURSOR_BLINK)
979 /* loop until we can return something */
981 if (v_bufstr < v_bufptr) /* output any pending chars */
984 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
985 if (mouse_slip_wheel_speed) {
987 if (!mouse_slip_wheel_delay--
988 && scr_page (mouse_slip_wheel_speed > 0 ? UP : DN,
989 abs(mouse_slip_wheel_speed))) {
990 mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY;
991 refresh_type |= SMOOTH_REFRESH;
995 #endif /* MOUSE_WHEEL && MOUSE_SLIP_WHEELING */
996 #ifdef SELECTION_SCROLLING
997 if (pending_scroll_selection) {
999 if (!scroll_selection_delay--
1000 && scr_page (scroll_selection_dir,
1001 scroll_selection_lines)) {
1002 selection_extend (selection_save_x,
1003 selection_save_y, selection_save_state);
1004 scroll_selection_delay = SCROLLBAR_CONTINUOUS_DELAY;
1005 refresh_type |= SMOOTH_REFRESH;
1010 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1011 if (scrollbar_isUp() || scrollbar_isDn()) {
1013 if (!scroll_arrow_delay--
1014 && scr_page (scrollbar_isUp() ? UP : DN, 1)) {
1015 scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY;
1016 refresh_type |= SMOOTH_REFRESH;
1020 #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
1023 quick_timeout |= want_full_refresh;
1028 #ifdef POINTER_BLANK
1030 rxvt_term::pointer_unblank ()
1032 XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor);
1037 if (Options & Opt_pointerBlank)
1038 pointer_ev.start (NOW + pointerBlankDelay);
1042 rxvt_term::pointer_blank ()
1044 if (!(Options & Opt_pointerBlank))
1047 XDefineCursor (Xdisplay, TermWin.vt, blank_cursor);
1054 rxvt_term::pointer_cb (time_watcher &w)
1057 SET_LOCALE (locale);
1064 rxvt_term::mouse_report (const XButtonEvent *ev)
1066 int button_number, key_state = 0;
1071 pixel_position (&x, &y);
1073 if (MEvent.button == AnyButton) {
1076 button_number = MEvent.button - Button1;
1077 /* add 0x3D for wheel events, like xterm does */
1078 if (button_number >= 3)
1079 button_number += (64 - 3);
1082 if (PrivateModes & PrivMode_MouseX10) {
1084 * do not report ButtonRelease
1085 * no state info allowed
1088 if (button_number == 3)
1091 /* XTerm mouse reporting needs these values:
1095 * plus will add in our own Double-Click reporting
1098 key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1099 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1100 + ((MEvent.state & ControlMask) ? 16 : 0);
1101 #ifdef MOUSE_REPORT_DOUBLECLICK
1102 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1106 #ifdef DEBUG_MOUSEREPORT
1107 fprintf(stderr, "Mouse [");
1116 fprintf(stderr, "]: <%d>, %d/%d\n",
1121 tt_printf("\033[M%c%c%c",
1122 (32 + button_number + key_state),
1130 rxvt_W11_process_x_event(XEvent *ev)
1132 rxvt_t *r = rxvt_get_r();
1134 process_x_event (ev);
1138 /*{{{ process an X event */
1140 rxvt_term::process_x_event (XEvent *ev)
1142 Window unused_root, unused_child;
1143 int unused_root_x, unused_root_y;
1144 unsigned int unused_mask;
1147 const char *const eventnames[] =
1148 { /* mason - this matches my system */
1190 (void)gettimeofday(&tp, NULL);
1191 ltt = localtime(&(tp.tv_sec));
1192 D_X((stderr, "Event: %-16s %-7s %08lx (%4d-%02d-%02d %02d:%02d:%02d.%.6ld) %s %lu", eventnames[ev->type], (ev->xany.window == TermWin.parent[0] ? "parent" : (ev->xany.window == TermWin.vt ? "vt" : (ev->xany.window == scrollBar.win ? "scroll" : (ev->xany.window == menuBar.win ? "menubar" : "UNKNOWN")))), (ev->xany.window == TermWin.parent[0] ? TermWin.parent[0] : (ev->xany.window == TermWin.vt ? TermWin.vt : (ev->xany.window == scrollBar.win ? scrollBar.win : (ev->xany.window == menuBar.win ? menuBar.win : 0)))), ltt->tm_year + 1900, ltt->tm_mon + 1, ltt->tm_mday, ltt->tm_hour, ltt->tm_min, ltt->tm_sec, tp.tv_usec, ev->xany.send_event ? "S" : " ", ev->xany.serial));
1197 lookup_key ((XKeyEvent *)ev);
1200 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1203 if (!(ev->xkey.state & ControlMask))
1204 mouse_slip_wheel_speed = 0;
1208 ks = XKeycodeToKeysym(Xdisplay, ev->xkey.keycode, 0);
1209 if (ks == XK_Control_L || ks == XK_Control_R)
1210 mouse_slip_wheel_speed = 0;
1217 button_press ((XButtonEvent *)ev);
1221 button_release ((XButtonEvent *)ev);
1225 if (ev->xclient.format == 32
1226 && (Atom)ev->xclient.data.l[0] == xa[XA_WMDELETEWINDOW])
1229 /* OffiX Dnd (drag 'n' drop) protocol */
1230 else if (ev->xclient.message_type == xa[XA_DNDPROTOCOL]
1231 && (ev->xclient.data.l[0] == DndFile
1232 || ev->xclient.data.l[0] == DndDir
1233 || ev->xclient.data.l[0] == DndLink)) {
1237 unsigned char *data;
1238 unsigned long Size, RemainingBytes;
1240 XGetWindowProperty(Xdisplay, Xroot,
1241 xa[XA_DNDSELECTION],
1243 False, AnyPropertyType,
1244 &ActualType, &ActualFormat,
1245 &Size, &RemainingBytes,
1247 XChangeProperty(Xdisplay, Xroot,
1248 XA_CUT_BUFFER0, XA_STRING,
1250 data, STRLEN(data));
1251 selection_paste (Xroot, XA_CUT_BUFFER0, True);
1252 XSetInputFocus(Xdisplay, Xroot, RevertToNone, CurrentTime);
1254 #endif /* OFFIX_DND */
1258 XRefreshKeyboardMapping(&(ev->xmapping));
1262 * XXX: this is not the _current_ arrangement
1263 * Here's my conclusion:
1264 * If the window is completely unobscured, use bitblt's
1265 * to scroll. Even then, they're only used when doing partial
1266 * screen scrolling. When partially obscured, we have to fill
1267 * in the GraphicsExpose parts, which means that after each refresh,
1268 * we need to wait for the graphics expose or Noexpose events,
1269 * which ought to make things real slow!
1271 case VisibilityNotify:
1272 switch (ev->xvisibility.state)
1274 case VisibilityUnobscured:
1275 refresh_type = FAST_REFRESH;
1277 case VisibilityPartiallyObscured:
1278 refresh_type = SLOW_REFRESH;
1281 refresh_type = NO_REFRESH;
1287 if (!TermWin.focus) {
1291 if (Input_Context != NULL)
1292 XSetICFocus(Input_Context);
1295 if (Options & Opt_cursorBlink)
1296 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1302 if (TermWin.focus) {
1306 if (Input_Context != NULL)
1307 XUnsetICFocus(Input_Context);
1310 if (Options & Opt_cursorBlink)
1311 cursor_blink_ev.stop ();
1317 case ConfigureNotify:
1318 if (ev->xconfigure.window == TermWin.parent[0]) {
1321 do { /* Wrap lots of configures into one */
1322 width = ev->xconfigure.width;
1323 height = ev->xconfigure.height;
1324 D_SIZE((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1325 } while (XCheckTypedWindowEvent(Xdisplay, ev->xconfigure.window,
1326 ConfigureNotify, ev));
1327 if (szHint.width != width || szHint.height != height) {
1328 D_SIZE((stderr, "Size: Resizing from: %4d x %4d", szHint.width, szHint.height));
1329 resize_all_windows (width, height, 1);
1333 D_SIZE((stderr, "Size: Not resizing"));
1336 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1337 if (Options & Opt_transparent) {
1338 check_our_parents ();
1340 want_full_refresh = 1;
1346 case SelectionClear:
1350 case SelectionNotify:
1351 if (selection_wait == Sel_normal)
1352 selection_paste (ev->xselection.requestor,
1353 ev->xselection.property, True);
1356 case SelectionRequest:
1357 selection_send (&(ev->xselectionrequest));
1363 text_blink_ev.stop ();
1370 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1374 case PropertyNotify:
1375 if (ev->xproperty.atom == xa[XA_VT_SELECTION]) {
1376 if (ev->xproperty.state == PropertyNewValue)
1377 selection_property (ev->xproperty.window,
1378 ev->xproperty.atom);
1383 * if user used some Esetroot compatible prog to set the root bg,
1384 * use the property to determine the pixmap. We use it later on.
1386 if (xa[XA_XROOTPMAPID] == 0)
1387 xa[XA_XROOTPMAPID] = XInternAtom(Xdisplay,
1388 "_XROOTPMAP_ID", False);
1389 if (ev->xproperty.atom != xa[XA_XROOTPMAPID])
1392 case ReparentNotify:
1393 if ((Options & Opt_transparent) && check_our_parents ()) {
1395 want_full_refresh = 1;
1397 #endif /* TRANSPARENT */
1400 case GraphicsExpose:
1402 if (ev->xany.window == TermWin.vt) {
1403 #ifdef NO_SLOW_LINK_SUPPORT
1404 scr_expose (ev->xexpose.x, ev->xexpose.y,
1405 ev->xexpose.width, ev->xexpose.height, False);
1407 // don't understand this, so commented it out
1408 scr_expose (ev->xexpose.x, ev->xexpose.y,
1409 ev->xexpose.width, ev->xexpose.height, False);
1410 //scr_expose (ev->xexpose.x, 0,
1411 // ev->xexpose.width, TermWin.height, False);
1415 XEvent unused_xevent;
1417 while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window,
1420 while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window,
1423 if (isScrollbarWindow(ev->xany.window)) {
1424 scrollBar.setIdle();
1428 if (menubar_visible () && isMenuBarWindow(ev->xany.window))
1431 #ifdef RXVT_GRAPHICS
1432 Gr_expose (ev->xany.window);
1438 #ifdef POINTER_BLANK
1443 if (isMenuBarWindow(ev->xany.window)) {
1444 menubar_control (&(ev->xbutton));
1448 if ((PrivateModes & PrivMode_mouse_report) && !(bypass_keystate))
1451 if (ev->xany.window == TermWin.vt) {
1452 if ((ev->xbutton.state & (Button1Mask | Button3Mask))) {
1453 while (XCheckTypedWindowEvent(Xdisplay, TermWin.vt,
1454 MotionNotify, ev)) ;
1455 XQueryPointer(Xdisplay, TermWin.vt,
1456 &unused_root, &unused_child,
1457 &unused_root_x, &unused_root_y,
1458 &(ev->xbutton.x), &(ev->xbutton.y),
1460 #ifdef MOUSE_THRESHOLD
1461 /* deal with a `jumpy' mouse */
1462 if ((ev->xmotion.time - MEvent.time) > MOUSE_THRESHOLD) {
1464 selection_extend ((ev->xbutton.x), (ev->xbutton.y),
1465 (ev->xbutton.state & Button3Mask) ? 2 : 0);
1466 #ifdef SELECTION_SCROLLING
1467 if (ev->xbutton.y < TermWin.int_bwidth
1468 || Pixel2Row(ev->xbutton.y) > (TermWin.nrow-1)) {
1471 pending_scroll_selection=1;
1473 /* don't clobber the current delay if we are
1474 * already in the middle of scrolling.
1476 if (scroll_selection_delay<=0)
1477 scroll_selection_delay=SCROLLBAR_CONTINUOUS_DELAY;
1479 /* save the event params so we can highlight
1480 * the selection in the pending-scroll loop
1482 selection_save_x=ev->xbutton.x;
1483 selection_save_y=ev->xbutton.y;
1484 selection_save_state=
1485 (ev->xbutton.state & Button3Mask) ? 2 : 0;
1487 /* calc number of lines to scroll */
1488 if (ev->xbutton.y<TermWin.int_bwidth) {
1489 scroll_selection_dir = UP;
1490 dist = TermWin.int_bwidth - ev->xbutton.y;
1493 scroll_selection_dir = DN;
1494 dist = ev->xbutton.y -
1495 (TermWin.int_bwidth + TermWin.height);
1497 scroll_selection_lines=(Pixel2Height(dist)/
1498 SELECTION_SCROLL_LINE_SPEEDUP)+1;
1499 MIN_IT(scroll_selection_lines,
1500 SELECTION_SCROLL_MAX_LINES);
1503 /* we are within the text window, so we
1504 * shouldn't be scrolling
1506 pending_scroll_selection = 0;
1509 #ifdef MOUSE_THRESHOLD
1513 } else if (isScrollbarWindow(ev->xany.window) && scrollbar_isMotion()) {
1514 while (XCheckTypedWindowEvent(Xdisplay, scrollBar.win,
1515 MotionNotify, ev)) ;
1516 XQueryPointer(Xdisplay, scrollBar.win,
1517 &unused_root, &unused_child,
1518 &unused_root_x, &unused_root_y,
1519 &(ev->xbutton.x), &(ev->xbutton.y),
1521 scr_move_to (scrollbar_position(ev->xbutton.y) - csrO,
1523 scr_refresh (refresh_type);
1532 rxvt_term::button_press (XButtonEvent *ev)
1534 int reportmode = 0, clickintime;
1536 bypass_keystate = ev->state & (ModMetaMask | ShiftMask);
1537 if (!bypass_keystate)
1538 reportmode = !!(PrivateModes & PrivMode_mouse_report);
1540 * VT window processing of button press
1542 if (ev->window == TermWin.vt)
1545 if (ev->subwindow != None)
1546 rxvt_Gr_ButtonPress (ev->x, ev->y);
1550 clickintime = ev->time - MEvent.time < MULTICLICK_TIME;
1553 /* mouse report from vt window */
1554 /* save the xbutton state (for ButtonRelease) */
1555 MEvent.state = ev->state;
1556 #ifdef MOUSE_REPORT_DOUBLECLICK
1557 if (ev->button == MEvent.button && clickintime)
1559 /* same button, within alloted time */
1561 if (MEvent.clicks > 1)
1563 /* only report double clicks */
1567 /* don't report the release */
1569 MEvent.button = AnyButton;
1574 /* different button, or time expired */
1576 MEvent.button = ev->button;
1580 MEvent.button = ev->button;
1582 #endif /* MOUSE_REPORT_DOUBLECLICK */
1586 if (ev->button != MEvent.button)
1591 /* allow shift+left click to extend selection */
1592 if (ev->state & ShiftMask && !(PrivateModes & PrivMode_mouse_report))
1594 if (MEvent.button == Button1 && clickintime)
1595 selection_rotate (ev->x, ev->y);
1597 selection_extend (ev->x, ev->y, 1);
1601 if (MEvent.button == Button1 && clickintime)
1606 selection_click (MEvent.clicks, ev->x, ev->y);
1609 MEvent.button = Button1;
1613 if (MEvent.button == Button3 && clickintime)
1614 selection_rotate (ev->x, ev->y);
1616 selection_extend (ev->x, ev->y, 1);
1617 MEvent.button = Button3;
1621 MEvent.time = ev->time;
1627 * Scrollbar window processing of button press
1629 if (isScrollbarWindow(ev->window))
1631 scrollBar.setIdle ();
1633 * Rxvt-style scrollbar:
1634 * move up if mouse is above slider
1635 * move dn if mouse is below slider
1637 * XTerm-style scrollbar:
1638 * Move display proportional to pointer location
1639 * pointer near top -> scroll one line
1640 * pointer near bot -> scroll full page
1642 #ifndef NO_SCROLLBAR_REPORT
1645 * Mouse report disabled scrollbar:
1646 * arrow buttons - send up/down
1647 * click on scrollbar - send pageup/down
1649 if ((scrollBar.style == R_SB_NEXT
1650 && scrollbarnext_upButton(ev->y))
1651 || (scrollBar.style == R_SB_RXVT
1652 && scrollbarrxvt_upButton(ev->y)))
1653 tt_printf("\033[A");
1654 else if ((scrollBar.style == R_SB_NEXT
1655 && scrollbarnext_dnButton(ev->y))
1656 || (scrollBar.style == R_SB_RXVT
1657 && scrollbarrxvt_dnButton(ev->y)))
1658 tt_printf("\033[B");
1660 switch (ev->button) {
1665 tt_printf("\033[6~");
1668 tt_printf("\033[5~");
1673 #endif /* NO_SCROLLBAR_REPORT */
1677 if (scrollBar.style == R_SB_NEXT) {
1678 if (scrollbarnext_upButton(ev->y))
1679 upordown = -1; /* up */
1680 else if (scrollbarnext_dnButton(ev->y))
1681 upordown = 1; /* down */
1682 } else if (scrollBar.style == R_SB_RXVT) {
1683 if (scrollbarrxvt_upButton(ev->y))
1684 upordown = -1; /* up */
1685 else if (scrollbarrxvt_dnButton(ev->y))
1686 upordown = 1; /* down */
1689 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1690 scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY;
1692 if (scr_page (upordown < 0 ? UP : DN, 1)) {
1699 switch (ev->button) {
1701 switch (scrollbar_align) {
1702 case R_SB_ALIGN_TOP:
1705 case R_SB_ALIGN_CENTRE:
1706 csrO = (scrollBar.bot - scrollBar.top) / 2;
1708 case R_SB_ALIGN_BOTTOM:
1709 csrO = scrollBar.bot - scrollBar.top;
1712 if (scrollBar.style == R_SB_XTERM
1713 || scrollbar_above_slider(ev->y)
1714 || scrollbar_below_slider(ev->y))
1715 scr_move_to ( scrollbar_position(ev->y) - csrO,
1717 scrollBar.setMotion ();
1721 if (scrollbar_align == R_SB_ALIGN_CENTRE)
1722 csrO = ev->y - scrollBar.top;
1726 if (scrollBar.style != R_SB_XTERM) {
1727 if (scrollbar_above_slider(ev->y))
1728 # ifdef RXVT_SCROLL_FULL
1729 scr_page (UP, TermWin.nrow - 1);
1731 scr_page (UP, TermWin.nrow / 4);
1733 else if (scrollbar_below_slider(ev->y))
1734 # ifdef RXVT_SCROLL_FULL
1735 scr_page (DN, TermWin.nrow - 1);
1737 scr_page (DN, TermWin.nrow / 4);
1740 scrollBar.setMotion ();
1742 scr_page ((ev->button == Button1 ? DN : UP),
1744 * scrollbar_position(ev->y)
1745 / scrollbar_size()));
1754 * Menubar window processing of button press
1756 if (isMenuBarWindow(ev->window))
1757 menubar_control (ev);
1762 rxvt_term::button_release (XButtonEvent *ev)
1766 csrO = 0; /* reset csr Offset */
1767 if (!bypass_keystate)
1768 reportmode = !!(PrivateModes & PrivMode_mouse_report);
1770 if (scrollbar_isUpDn()) {
1771 scrollBar.setIdle ();
1773 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1774 refresh_type &= ~SMOOTH_REFRESH;
1777 #ifdef SELECTION_SCROLLING
1778 pending_scroll_selection=0;
1780 if (ev->window == TermWin.vt)
1782 #ifdef RXVT_GRAPHICS
1783 if (ev->subwindow != None)
1784 rxvt_Gr_ButtonRelease(ev->x, ev->y);
1790 /* mouse report from vt window */
1791 /* don't report release of wheel "buttons" */
1792 if (ev->button >= 4)
1794 #ifdef MOUSE_REPORT_DOUBLECLICK
1795 /* only report the release of 'slow' single clicks */
1796 if (MEvent.button != AnyButton
1797 && (ev->button != MEvent.button
1798 || (ev->time - MEvent.time
1799 > MULTICLICK_TIME / 2)))
1802 MEvent.button = AnyButton;
1805 #else /* MOUSE_REPORT_DOUBLECLICK */
1806 MEvent.button = AnyButton;
1808 #endif /* MOUSE_REPORT_DOUBLECLICK */
1812 * dumb hack to compensate for the failure of click-and-drag
1813 * when overriding mouse reporting
1815 if (PrivateModes & PrivMode_mouse_report
1817 && ev->button == Button1 && MEvent.clicks <= 1)
1818 selection_extend (ev->x, ev->y, 0);
1820 switch (ev->button) {
1823 selection_make (ev->time);
1826 selection_request (ev->time, ev->x, ev->y);
1835 v = (ev->button == Button4) ? UP : DN;
1836 if (ev->state & ShiftMask)
1838 else if ((Options & Opt_mouseWheelScrollPage))
1839 i = TermWin.nrow - 1;
1842 # ifdef MOUSE_SLIP_WHEELING
1843 if (ev->state & ControlMask)
1845 mouse_slip_wheel_speed += (v ? -1 : 1);
1846 mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY;
1849 # ifdef JUMP_MOUSE_WHEEL
1851 scr_refresh (SMOOTH_REFRESH);
1857 scr_refresh (SMOOTH_REFRESH);
1868 else if (isMenuBarWindow(ev->window))
1869 menubar_control (ev);
1876 * Check our parents are still who we think they are.
1877 * Do transparency updates if required
1880 rxvt_term::check_our_parents ()
1882 int i, pchanged, aformat, have_pixmap, rootdepth;
1883 unsigned long nitems, bytes_after;
1885 unsigned char *prop = NULL;
1886 Window root, oldp, *list;
1887 Pixmap rootpixmap = None;
1888 XWindowAttributes wattr, wrootattr;
1892 if (!(Options & Opt_transparent))
1893 return pchanged; /* Don't try any more */
1895 XGetWindowAttributes(Xdisplay, Xroot, &wrootattr);
1896 rootdepth = wrootattr.depth;
1898 XGetWindowAttributes(Xdisplay, TermWin.parent[0], &wattr);
1899 if (rootdepth != wattr.depth) {
1900 if (am_transparent) {
1902 XSetWindowBackground(Xdisplay, TermWin.vt,
1903 PixColors[Color_bg]);
1904 am_transparent = am_pixmap_trans = 0;
1906 return pchanged; /* Don't try any more */
1909 /* Get all X ops out of the queue so that our information is up-to-date. */
1910 XSync(Xdisplay, False);
1913 * Make the frame window set by the window manager have
1914 * the root background. Some window managers put multiple nested frame
1915 * windows for each client, so we have to take care about that.
1917 i = (xa[XA_XROOTPMAPID] != 0
1918 && (XGetWindowProperty(Xdisplay, Xroot, xa[XA_XROOTPMAPID],
1919 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1920 &nitems, &bytes_after, &prop) == Success));
1921 if (!i || prop == NULL)
1925 rootpixmap = *((Pixmap *)prop);
1930 * Copy Xroot pixmap transparency
1933 unsigned int nw, nh;
1939 XTranslateCoordinates(Xdisplay, TermWin.parent[0], Xroot,
1940 0, 0, &sx, &sy, &cr);
1941 nw = (unsigned int)szHint.width;
1942 nh = (unsigned int)szHint.height;
1954 MIN_IT(nw, (unsigned int)(wrootattr.width - sx));
1955 MIN_IT(nh, (unsigned int)(wrootattr.height - sy));
1957 image = XGetImage(Xdisplay, rootpixmap, sx, sy, nw, nh, AllPlanes,
1959 /* XXX: handle BadMatch - usually because we're outside the pixmap */
1960 /* XXX: may need a delay here? */
1962 if (image == NULL) {
1963 if (am_transparent && am_pixmap_trans) {
1965 if (TermWin.pixmap != None) {
1966 XFreePixmap(Xdisplay, TermWin.pixmap);
1967 TermWin.pixmap = None;
1970 am_pixmap_trans = 0;
1972 if (TermWin.pixmap != None)
1973 XFreePixmap(Xdisplay, TermWin.pixmap);
1974 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt,
1975 (unsigned int)szHint.width,
1976 (unsigned int)szHint.height,
1977 (unsigned int)image->depth);
1978 gc = XCreateGC(Xdisplay, TermWin.vt, 0UL, &gcvalue);
1979 XPutImage(Xdisplay, TermWin.pixmap, gc, image, 0, 0,
1980 nx, ny, (unsigned int)image->width,
1981 (unsigned int)image->height);
1982 XFreeGC(Xdisplay, gc);
1983 XDestroyImage(image);
1984 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt,
1986 if (!am_transparent || !am_pixmap_trans)
1988 am_transparent = am_pixmap_trans = 1;
1991 if (!am_pixmap_trans) {
1994 * InheritPixmap transparency
1996 D_X((stderr, "InheritPixmap Seeking to %08lx", Xroot));
1997 for (i = 1; i < (int)(sizeof(TermWin.parent) / sizeof(Window));
1999 oldp = TermWin.parent[i];
2000 XQueryTree(Xdisplay, TermWin.parent[i - 1], &root,
2001 &TermWin.parent[i], &list, &n);
2003 D_X((stderr, "InheritPixmap Parent[%d] = %08lx", i, TermWin.parent[i]));
2004 if (TermWin.parent[i] == Xroot) {
2009 if (oldp != TermWin.parent[i])
2014 for (; n < (unsigned int)i; n++) {
2015 XGetWindowAttributes(Xdisplay, TermWin.parent[n], &wattr);
2016 D_X((stderr, "InheritPixmap Checking Parent[%d]: %s", n, (wattr.depth == rootdepth && wattr.class != InputOnly) ? "OK" : "FAIL"));
2017 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) {
2018 n = (int)(sizeof(TermWin.parent) / sizeof(Window)) + 1;
2023 if (n > (int)(sizeof(TermWin.parent)
2024 / sizeof(TermWin.parent[0]))) {
2025 D_X((stderr, "InheritPixmap Turning off"));
2026 XSetWindowBackground(Xdisplay, TermWin.parent[0],
2027 PixColors[Color_fg]);
2028 XSetWindowBackground(Xdisplay, TermWin.vt,
2029 PixColors[Color_bg]);
2031 /* XXX: also turn off Opt_transparent? */
2033 /* wait (an arbitrary period) for the WM to do its thing
2034 * needed for fvwm2.2.2 (and before?) */
2035 # ifdef HAVE_NANOSLEEP
2036 struct timespec rqt;
2040 nanosleep(&rqt, NULL);
2044 D_X((stderr, "InheritPixmap Turning on (%d parents)", i - 1));
2045 for (n = 0; n < (unsigned int)i; n++)
2046 XSetWindowBackgroundPixmap(Xdisplay, TermWin.parent[n],
2048 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt,
2052 for (; i < (int)(sizeof(TermWin.parent) / sizeof(Window)); i++)
2053 TermWin.parent[i] = None;
2062 /*----------------------------------------------------------------------*/
2065 rxvt_term::popen_printer ()
2067 FILE *stream = popen(rs[Rs_print_pipe], "w");
2070 rxvt_print_error("can't open printer pipe");
2075 rxvt_term::pclose_printer (FILE *stream)
2078 /* pclose() reported not to work on SunOS 4.1.3 */
2079 # if defined (__sun__) /* TODO: RESOLVE THIS */
2080 /* pclose works provided SIGCHLD handler uses waitpid */
2081 return pclose (stream); /* return fclose (stream); */
2083 return pclose (stream);
2088 * simulate attached vt100 printer
2091 rxvt_term::process_print_pipe ()
2096 if ((fd = popen_printer ()) == NULL)
2100 * Send all input to the printer until either ESC[4i or ESC[?4i
2103 for (done = 0; !done;) {
2104 unsigned char buf[8];
2106 unsigned int i, len;
2108 if ((ch = cmd_getc ()) != C0_ESC) {
2109 if (putc(ch, fd) == EOF)
2110 break; /* done = 1 */
2115 if ((buf[len++] = cmd_getc ()) == '[') {
2116 if ((ch = cmd_getc ()) == '?') {
2120 if ((buf[len++] = ch) == '4') {
2121 if ((buf[len++] = cmd_getc ()) == 'i')
2122 break; /* done = 1 */
2125 for (i = 0; i < len; i++)
2126 if (putc(buf[i], fd) == EOF) {
2132 pclose_printer (fd);
2134 #endif /* PRINTPIPE */
2140 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2141 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2142 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2143 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC
2147 /*{{{ process non-printing single characters */
2149 rxvt_term::process_nonprinting (unsigned char ch)
2152 case C0_ENQ: /* terminal Status */
2153 if (rs[Rs_answerbackstring])
2155 (const unsigned char *)rs[Rs_answerbackstring],
2156 (unsigned int)STRLEN(rs[Rs_answerbackstring]));
2158 tt_write((unsigned char *)VT100_ANS,
2159 (unsigned int)STRLEN(VT100_ANS));
2161 case C0_BEL: /* bell */
2164 case C0_BS: /* backspace */
2167 case C0_HT: /* tab */
2170 case C0_CR: /* carriage return */
2171 scr_gotorc (0, 0, R_RELATIVE);
2173 case C0_VT: /* vertical tab, form feed */
2175 case C0_LF: /* line feed */
2178 case C0_SO: /* shift out - acs */
2179 scr_charset_choose (1);
2181 case C0_SI: /* shift in - acs */
2182 scr_charset_choose (0);
2189 /*{{{ process VT52 escape sequences */
2191 rxvt_term::process_escape_vt52 (unsigned char ch)
2196 case 'A': /* cursor up */
2197 scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
2199 case 'B': /* cursor down */
2200 scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
2202 case 'C': /* cursor right */
2203 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
2205 case 'D': /* cursor left */
2206 scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
2208 case 'H': /* cursor home */
2209 scr_gotorc (0, 0, 0);
2211 case 'I': /* cursor up and scroll down if needed */
2214 case 'J': /* erase to end of screen */
2215 scr_erase_screen (0);
2217 case 'K': /* erase to end of line */
2220 case 'Y': /* move to specified row and col */
2221 /* full command is 'ESC Y row col' where row and col
2222 * are encoded by adding 32 and sending the ascii
2223 * character. eg. SPACE = 0, '+' = 13, '0' = 18,
2225 row = cmd_getc () - ' ';
2226 col = cmd_getc () - ' ';
2227 scr_gotorc (row, col, 0);
2229 case 'Z': /* identify the terminal type */
2230 tt_printf("\033/Z"); /* I am a VT100 emulating a VT52 */
2232 case '<': /* turn off VT52 mode */
2233 PrivMode(0, PrivMode_vt52);
2235 case 'F': /* use special graphics character set */
2236 case 'G': /* use regular character set */
2239 case '=': /* use alternate keypad mode */
2240 case '>': /* use regular keypad mode */
2248 /*{{{ process escape sequences */
2250 rxvt_term::process_escape_seq ()
2252 unsigned char ch = cmd_getc ();
2254 if (PrivateModes & PrivMode_vt52) {
2255 process_escape_vt52 (ch);
2260 /* case 1: do_tek_mode (); break; */
2262 if (cmd_getc () == '8')
2266 scr_charset_set (0, (unsigned int)cmd_getc ());
2269 scr_charset_set (1, (unsigned int)cmd_getc ());
2272 scr_charset_set (2, (unsigned int)cmd_getc ());
2275 scr_charset_set (3, (unsigned int)cmd_getc ());
2277 #ifdef MULTICHAR_SET
2279 scr_charset_set (-2, (unsigned int)cmd_getc ());
2291 scr_cursor (RESTORE);
2295 scr_forwardindex ();
2300 PrivMode((ch == '='), PrivMode_aplKP);
2310 /* 8.3.87: NEXT LINE */
2311 case C1_NEL: /* ESC E */
2313 uint32_t nlcr[] = { '\n', '\r' };
2314 scr_add_lines (nlcr, 1, 2);
2318 /* kidnapped escape sequence: Should be 8.3.48 */
2319 case C1_ESA: /* ESC G */
2320 process_graphics ();
2323 /* 8.3.63: CHARACTER TABULATION SET */
2324 case C1_HTS: /* ESC H */
2328 /* 8.3.105: REVERSE LINE FEED */
2329 case C1_RI: /* ESC M */
2333 /* 8.3.142: SINGLE-SHIFT TWO */
2334 /*case C1_SS2: scr_single_shift (2); break; */
2336 /* 8.3.143: SINGLE-SHIFT THREE */
2337 /*case C1_SS3: scr_single_shift (3); break; */
2339 /* 8.3.27: DEVICE CONTROL STRING */
2340 case C1_DCS: /* ESC P */
2344 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
2345 case C1_SCI: /* ESC Z */
2346 tt_write((const unsigned char *)ESCZ_ANSWER,
2347 (unsigned int)(sizeof(ESCZ_ANSWER) - 1));
2348 break; /* steal obsolete ESC [ c */
2350 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
2351 case C1_CSI: /* ESC [ */
2355 /* 8.3.90: OPERATING SYSTEM COMMAND */
2356 case C1_OSC: /* ESC ] */
2360 /* 8.3.106: RESET TO INITIAL STATE */
2366 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
2368 scr_charset_choose (2);
2371 /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
2373 scr_charset_choose (3);
2379 /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
2383 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
2384 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
2385 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
2386 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
2387 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
2388 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
2389 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
2390 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
2393 #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
2394 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
2395 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
2396 #define get_byte_array_bit(array, bit) \
2397 (!!((array)[(bit) / 8] & (128 >> ((bit) & 7))))
2399 const unsigned char csi_defaults[] = {
2400 make_byte(1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
2401 make_byte(1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
2402 make_byte(1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
2403 make_byte(1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
2404 make_byte(1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
2405 make_byte(0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
2406 make_byte(0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
2407 make_byte(0,0,0,0,0,0,0,0) /* x, y, z, {, |, }, ~, */
2412 rxvt_term::process_csi_seq ()
2414 unsigned char ch, priv, i;
2415 unsigned int nargs, p;
2419 for (nargs = ESC_ARGS; nargs > 0;)
2424 if (ch >= '<' && ch <= '?') { /* '<' '=' '>' '?' */
2428 /* read any numerical arguments */
2429 for (n = -1; ch < CSI_ICH; ) {
2434 n = n * 10 + ch - '0';
2435 } else if (ch == ';') {
2436 if (nargs < ESC_ARGS)
2439 } else if (ch == '\b') {
2441 } else if (ch == C0_ESC) {
2442 process_escape_seq ();
2444 } else if (ch < ' ') {
2445 process_nonprinting (ch);
2453 if (nargs < ESC_ARGS)
2457 ndef = get_byte_array_bit(csi_defaults, i);
2458 for (p = 0; p < nargs; p++)
2463 fprintf(stderr, "CSI ");
2464 for (p = 0; p < nargs; p++)
2465 fprintf(stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
2466 fprintf(stderr, "%c\n", ch);
2470 * private mode handling
2475 if (ch == CSI_DA) /* secondary device attributes */
2476 tt_printf("\033[>%d;%-.8s;0c", 'R', VSTRING);
2479 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
2480 process_terminal_mode (ch, priv, nargs, arg);
2488 * ISO/IEC 6429:1992(E) CSI sequences (defaults in parentheses)
2491 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
2493 case 0: /* initiate transfer to primary aux device */
2494 scr_printscreen (0);
2496 case 5: /* start relay to primary aux device */
2497 process_print_pipe ();
2503 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
2504 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
2507 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
2508 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
2509 scr_gotorc (arg[0], 0, RELATIVE);
2512 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
2513 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
2516 #else /* emulate common DEC VTs */
2517 arg[0] = arg[0] ? -arg[0] : -1;
2520 case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
2521 case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
2523 scr_gotorc (0, arg[0], RELATIVE);
2524 #else /* emulate common DEC VTs */
2525 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
2529 case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
2532 case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
2533 scr_gotorc (arg[0], 0, R_RELATIVE);
2536 case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
2537 case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
2538 scr_gotorc (0, arg[0] - 1, R_RELATIVE);
2541 case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
2542 scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
2545 case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
2546 case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
2547 scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
2550 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
2553 case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
2557 case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
2558 scr_erase_screen (arg[0]);
2561 case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
2562 scr_erase_line (arg[0]);
2565 case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
2566 scr_insdel_chars (arg[0], INSERT);
2569 case CSI_IL: /* 8.3.68: (1) INSERT LINE */
2570 scr_insdel_lines (arg[0], INSERT);
2573 case CSI_DL: /* 8.3.33: (1) DELETE LINE */
2574 scr_insdel_lines (arg[0], DELETE);
2577 case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
2578 scr_insdel_chars (arg[0], ERASE);
2581 case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
2582 scr_insdel_chars (arg[0], DELETE);
2585 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
2588 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
2589 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0);
2592 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
2593 tt_write((const unsigned char *)VT100_ANS,
2594 (unsigned int)(sizeof(VT100_ANS) - 1));
2597 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
2598 process_sgr_mode (nargs, arg);
2601 case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
2603 case 5: /* DSR requested */
2604 tt_printf("\033[0n");
2606 case 6: /* CPR requested */
2607 scr_report_position ();
2609 #if defined (ENABLE_DISPLAY_ANSWER)
2610 case 7: /* unofficial extension */
2611 tt_printf("%-.250s\n", rs[Rs_display_name]);
2614 case 8: /* unofficial extension */
2615 xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST);
2620 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
2622 case 0: /* char tab stop cleared at active position */
2625 /* case 1: */ /* line tab stop cleared in active line */
2626 /* case 2: */ /* char tab stops cleared in active line */
2627 case 3: /* all char tab stops are cleared */
2628 /* case 4: */ /* all line tab stops are cleared */
2629 case 5: /* all tab stops are cleared */
2635 case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
2637 case 0: /* char tab stop set at active position */
2639 break; /* = ESC H */
2640 /* case 1: */ /* line tab stop set at active line */
2641 case 2: /* char tab stop cleared at active position */
2643 break; /* = ESC [ 0 g */
2644 /* case 3: */ /* line tab stop cleared at active line */
2645 /* case 4: */ /* char tab stops cleared at active line */
2646 case 5: /* all char tab stops are cleared */
2648 break; /* = ESC [ 3 g */
2649 /* case 6: */ /* all line tab stops are cleared */
2653 case CSI_RM: /* 8.3.107: RESET MODE */
2655 scr_insert_mode (0);
2658 case CSI_SM: /* 8.3.126: SET MODE */
2660 scr_insert_mode (1);
2664 * PRIVATE USE beyond this point. All CSI_7? sequences here
2666 case CSI_72: /* DECSTBM: set top and bottom margins */
2668 scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
2669 else if (nargs == 0 || arg[0] >= arg[1])
2670 scr_scroll_region (0, MAX_ROWS - 1);
2672 scr_scroll_region (arg[0] - 1, arg[1] - 1);
2679 scr_cursor (RESTORE);
2684 process_window_ops (arg, nargs);
2688 case CSI_78: /* DECREQTPARM */
2689 if (arg[0] == 0 || arg[0] == 1)
2690 tt_printf("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
2702 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
2708 XWindowAttributes wattr;
2717 case 1: /* deiconify window */
2718 XMapWindow(Xdisplay, TermWin.parent[0]);
2720 case 2: /* iconify window */
2721 XIconifyWindow(Xdisplay, TermWin.parent[0],
2722 DefaultScreen(Xdisplay));
2724 case 3: /* set position (pixels) */
2725 XMoveWindow(Xdisplay, TermWin.parent[0], args[1], args[2]);
2727 case 4: /* set size (pixels) */
2728 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
2730 case 5: /* raise window */
2731 XRaiseWindow(Xdisplay, TermWin.parent[0]);
2733 case 6: /* lower window */
2734 XLowerWindow(Xdisplay, TermWin.parent[0]);
2736 case 7: /* refresh window */
2739 case 8: /* set size (chars) */
2740 set_widthheight ((unsigned int)(args[2] * TermWin.fwidth),
2741 (unsigned int)(args[1] * TermWin.fheight));
2744 if (args[0] >= 24) /* set height (chars) */
2745 set_widthheight ((unsigned int)TermWin.width,
2746 (unsigned int)(args[1] * TermWin.fheight));
2749 * reports - some output format copied from XTerm
2751 case 11: /* report window state */
2752 XGetWindowAttributes(Xdisplay, TermWin.parent[0], &wattr);
2753 tt_printf("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
2755 case 13: /* report window position */
2756 XGetWindowAttributes(Xdisplay, TermWin.parent[0], &wattr);
2757 XTranslateCoordinates(Xdisplay, TermWin.parent[0], wattr.root,
2758 -wattr.border_width, -wattr.border_width,
2760 tt_printf("\033[3;%d;%dt", x, y);
2762 case 14: /* report window size (pixels) */
2763 XGetWindowAttributes(Xdisplay, TermWin.parent[0], &wattr);
2764 tt_printf("\033[4;%d;%dt", wattr.height, wattr.width);
2766 case 18: /* report window size (chars) */
2767 tt_printf("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
2769 #if 0 /* XXX: currently disabled due to security concerns */
2770 case 20: /* report icon label */
2771 XGetIconName(Xdisplay, TermWin.parent[0], &s);
2772 tt_printf("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */
2774 case 21: /* report window title */
2775 XFetchName(Xdisplay, TermWin.parent[0], &s);
2776 tt_printf("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */
2783 /*----------------------------------------------------------------------*/
2785 * get input up until STRING TERMINATOR (or BEL)
2786 * ends_how is terminator used. returned input must be free()d
2789 rxvt_term::get_to_st (unsigned char *ends_how)
2791 int seen_esc = 0; /* seen escape? */
2794 unsigned char ch, string[STRING_MAX];
2796 for (; (ch = cmd_getc ());) {
2799 || (ch == 0x5c && seen_esc)) /* 7bit ST */
2804 } else if (ch == '\t')
2805 ch = ' '; /* translate '\t' to space */
2806 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20))
2807 return NULL; /* other control character - exit */
2808 if (n < sizeof(string) - 1)
2813 if ((s = (unsigned char *)rxvt_malloc(n)) == NULL)
2815 *ends_how = (ch == 0x5c ? C0_ESC : ch);
2816 STRNCPY(s, string, n);
2820 /*----------------------------------------------------------------------*/
2822 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
2825 rxvt_term::process_dcs_seq ()
2827 unsigned char eh, *s;
2831 s = get_to_st (&eh);
2837 /*----------------------------------------------------------------------*/
2839 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
2842 rxvt_term::process_osc_seq ()
2844 unsigned char ch, eh, *s;
2848 for (arg = 0; isdigit(ch); ch = cmd_getc ())
2849 arg = arg * 10 + (ch - '0');
2852 s = get_to_st (&eh);
2855 * rxvt_menubar_dispatch() violates the constness of the string,
2858 if (arg == XTerm_Menu)
2859 #if 0 /* XXX: currently disabled due to security concerns */
2860 menubar_dispatch ((char *)s);
2865 xterm_seq (arg, (char *)s, eh);
2871 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
2872 * 0 = change iconName/title
2873 * 1 = change iconName
2876 * 12 = change text color
2877 * 13 = change mouse foreground color
2878 * 17 = change highlight character colour
2879 * 18 = change bold character color
2880 * 19 = change underlined character color
2881 * 46 = change logfile (not implemented)
2885 * 10 = menu (may change in future)
2887 * 39 = change default fg color
2888 * 49 = change default bg color
2889 * 55 = dump scrollback buffer and all of screen
2892 rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__((unused)))
2898 assert(str != NULL);
2903 case XTerm_iconName:
2910 for (buf = (char *)str; buf && *buf;) {
2911 if ((name = STRCHR(buf, ';')) == NULL)
2915 if (color < 0 || color >= TOTAL_COLORS)
2917 if ((buf = STRCHR(name, ';')) != NULL)
2919 set_window_color (color + minCOLOR, name);
2922 #ifndef NO_CURSORCOLOR
2923 case XTerm_Color_cursor:
2924 set_window_color (Color_cursor, str);
2927 case XTerm_Color_pointer:
2928 set_window_color (Color_pointer, str);
2930 #ifndef NO_BOLD_UNDERLINE_REVERSE
2931 case XTerm_Color_BD:
2932 set_window_color (Color_BD, str);
2934 case XTerm_Color_UL:
2935 set_window_color (Color_UL, str);
2937 case XTerm_Color_RV:
2938 set_window_color (Color_RV, str);
2944 * rxvt_menubar_dispatch() violates the constness of the string,
2945 * so DON'T do it here
2951 scale_pixmap (""); /* reset to default scaling */
2952 set_bgPixmap (str); /* change pixmap */
2956 while ((str = STRCHR(str, ';')) != NULL) {
2959 changed += scale_pixmap (str);
2963 #ifdef XPM_BACKGROUND
2970 case XTerm_restoreFG:
2971 set_window_color (Color_fg, str);
2973 case XTerm_restoreBG:
2974 set_window_color (Color_bg, str);
2979 change_font (0, str);
2982 case XTerm_dumpscreen: /* no error notices */
2985 if ((fd = open(str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) {
2994 /*----------------------------------------------------------------------*/
2996 /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
2998 * mode can only have the following values:
3004 * so no need for fancy checking
3007 rxvt_term::privcases (int mode, unsigned long bit)
3012 SavedModes |= (PrivateModes & bit);
3016 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3018 state = (mode == 't') ? !(PrivateModes & bit) : mode;
3019 PrivMode(state, bit);
3024 /* we're not using priv _yet_ */
3026 rxvt_term::process_terminal_mode (int mode, int priv __attribute__((unused)), unsigned int nargs, const int *arg)
3030 static const struct {
3032 const unsigned long bit;
3034 { 1, PrivMode_aplCUR },
3035 { 2, PrivMode_vt52 },
3036 { 3, PrivMode_132 },
3037 { 4, PrivMode_smoothScroll },
3038 { 5, PrivMode_rVideo },
3039 { 6, PrivMode_relOrigin },
3040 { 7, PrivMode_Autowrap },
3041 { 9, PrivMode_MouseX10 },
3043 { menuBar_esc, PrivMode_menuBar },
3045 #ifdef scrollBar_esc
3046 { scrollBar_esc, PrivMode_scrollBar },
3048 { 25, PrivMode_VisibleCursor },
3049 { 35, PrivMode_ShiftKeys },
3050 { 40, PrivMode_132OK },
3051 { 47, PrivMode_Screen },
3052 { 66, PrivMode_aplKP },
3053 #ifndef NO_BACKSPACE_KEY
3054 { 67, PrivMode_BackSpace },
3056 { 1000, PrivMode_MouseX11 },
3057 { 1010, PrivMode_TtyOutputInh },
3058 { 1011, PrivMode_Keypress },
3059 { 1047, PrivMode_Screen },
3060 { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */
3066 /* make lo/hi boolean */
3068 mode = 0; /* reset */
3069 else if (mode == 'h')
3072 for (i = 0; i < nargs; i++) {
3075 /* basic handling */
3076 for (j = 0; j < (sizeof(argtopriv)/sizeof(argtopriv[0])); j++)
3077 if (argtopriv[j].argval == arg[i]) {
3078 state = privcases (mode, argtopriv[j].bit);
3082 /* extra handling for values with state unkept */
3085 case 1048: /* alternative cursor save */
3087 scr_cursor (RESTORE);
3092 continue; /* for(;i;) */
3095 /* extra handling for values with valid 0 or 1 state */
3097 /* case 1: - application cursor keys */
3098 case 2: /* VT52 mode */
3099 /* oddball mode. should be set regardless of set/reset
3100 * parameter. Return from VT52 mode with an ESC < from
3103 PrivMode(1, PrivMode_vt52);
3105 case 3: /* 80/132 */
3106 if (PrivateModes & PrivMode_132OK)
3107 set_widthheight ( (unsigned int)((state ? 132 : 80) * TermWin.fwidth),
3108 (unsigned int)TermWin.height);
3110 case 4: /* smooth scrolling */
3112 Options &= ~Opt_jumpScroll;
3114 Options |= Opt_jumpScroll;
3116 case 5: /* reverse video */
3117 scr_rvideo_mode (state);
3119 case 6: /* relative/absolute origins */
3120 scr_relative_origin (state);
3122 case 7: /* autowrap */
3123 scr_autowrap (state);
3125 /* case 8: - auto repeat, can't do on a per window basis */
3126 case 9: /* X10 mouse reporting */
3127 if (state) /* orthogonal */
3128 PrivateModes &= ~(PrivMode_MouseX11);
3133 map_menuBar (state);
3137 #ifdef scrollBar_esc
3139 if (scrollbar_mapping (state)) {
3140 resize_all_windows (0, 0, 0);
3145 case 25: /* visible/invisible cursor */
3146 scr_cursor_visible (state);
3148 /* case 35: - shift keys */
3149 /* case 40: - 80 <--> 132 mode */
3150 case 47: /* secondary screen */
3151 scr_change_screen (state);
3153 /* case 66: - application key pad */
3154 /* case 67: - backspace key */
3155 case 1000: /* X11 mouse reporting */
3156 if (state) /* orthogonal */
3157 PrivateModes &= ~(PrivMode_MouseX10);
3161 break; /* X11 mouse highlighting */
3163 case 1010: /* scroll to bottom on TTY output inhibit */
3165 Options &= ~Opt_scrollTtyOutput;
3167 Options |= Opt_scrollTtyOutput;
3169 case 1011: /* scroll to bottom on key press */
3171 Options |= Opt_scrollTtyKeypress;
3173 Options &= ~Opt_scrollTtyKeypress;
3175 case 1047: /* secondary screen w/ clearing */
3176 case 1049: /* better secondary screen w/ clearing, but not fully implemented */
3177 if (current_screen != PRIMARY)
3178 scr_erase_screen (2);
3179 scr_change_screen (state);
3188 /*{{{ process sgr sequences */
3190 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
3197 scr_rendition (0, ~RS_None);
3200 for (i = 0; i < nargs; i++) {
3204 rendset = 0, rendstyle = ~RS_None;
3207 rendset = 1, rendstyle = RS_Bold;
3210 rendset = 1, rendstyle = RS_Uline;
3213 rendset = 1, rendstyle = RS_Blink;
3216 rendset = 1, rendstyle = RS_RVid;
3219 rendset = 0, rendstyle = RS_Bold;
3222 rendset = 0, rendstyle = RS_Uline;
3225 rendset = 0, rendstyle = RS_Blink;
3228 rendset = 0, rendstyle = RS_RVid;
3231 if (rendset != -1) {
3232 scr_rendition (rendset, rendstyle);
3233 continue; /* for(;i;) */
3238 case 31: /* set fg color */
3245 scr_color ((unsigned int)(minCOLOR + (arg[i] - 30)),
3250 if (nargs > i + 2 && arg[i + 1] == 5) {
3251 scr_color ((unsigned int)(minCOLOR + arg[i + 2]),
3257 case 39: /* default fg */
3258 scr_color (Color_fg, Color_fg);
3262 case 41: /* set bg color */
3269 scr_color ((unsigned int)(minCOLOR + (arg[i] - 40)),
3274 if (nargs > i + 2 && arg[i + 1] == 5) {
3275 scr_color ((unsigned int)(minCOLOR + arg[i + 2]),
3281 case 49: /* default bg */
3282 scr_color (Color_bg, Color_bg);
3285 #ifndef NO_BRIGHTCOLOR
3287 case 91: /* set bright fg color */
3294 scr_color ((unsigned int)(minBrightCOLOR + (arg[i] - 90)),
3298 case 101: /* set bright bg color */
3305 scr_color ((unsigned int)(minBrightCOLOR + (arg[i] - 100)),
3314 /*{{{ process Rob Nation's own graphics mode sequences */
3316 rxvt_term::process_graphics ()
3318 unsigned char ch, cmd = cmd_getc ();
3320 #ifndef RXVT_GRAPHICS
3321 if (cmd == 'Q') { /* query graphics */
3322 tt_printf("\033G0\n"); /* no graphics */
3325 /* swallow other graphics sequences until terminating ':' */
3332 unsigned char *text = NULL;
3334 if (cmd == 'Q') { /* query graphics */
3335 tt_printf("\033G1\n"); /* yes, graphics (color) */
3338 for (nargs = 0; nargs < (sizeof(args) / sizeof(args[0])) - 1;) {
3343 if (neg || ch == '+')
3346 for (args[nargs] = 0; isdigit(ch); ch = cmd_getc ())
3347 args[nargs] = args[nargs] * 10 + (ch - '0');
3349 args[nargs] = -args[nargs];
3357 if ((cmd == 'T') && (nargs >= 5)) {
3358 int i, len = args[4];
3360 text = (unsigned char *)rxvt_malloc((len + 1) * sizeof(char));
3363 for (i = 0; i < len; i++)
3364 text[i] = cmd_getc ();
3368 Gr_do_graphics (cmd, nargs, args, text);
3373 /* ------------------------------------------------------------------------- */
3376 * Send printf() formatted output to the command.
3377 * Only use for small amounts of data.
3380 rxvt_term::tt_printf (const char *fmt,...)
3383 unsigned char buf[256];
3385 va_start (arg_ptr, fmt);
3386 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
3388 tt_write (buf, STRLEN (buf));
3391 /* ---------------------------------------------------------------------- */
3392 /* Write data to the pty as typed by the user, pasted with the mouse,
3393 * or generated by us in response to a query ESC sequence.
3396 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
3398 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT
3404 ssize_t written = write (cmd_fd, data, min (MAX_PTY_WRITE, len));
3406 if ((unsigned int)written == len)
3414 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
3416 memcpy (v_buffer + v_buflen, data, len);
3422 int written = write (cmd_fd, v_buffer, min (MAX_PTY_WRITE, v_buflen));
3426 v_buflen -= written;
3434 pty_ev.set (EVENT_READ);
3438 memmove (v_buffer, v_buffer + written, v_buflen);
3440 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
3441 // original code just ignores this...
3445 pty_ev.set (EVENT_READ | EVENT_WRITE);
3451 /*----------------------- end-of-file (C source) -----------------------*/