ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.415 by root, Sat Apr 26 03:37:18 2008 UTC vs.
Revision 1.426 by root, Wed Nov 5 13:49:36 2008 UTC

1127 { 1127 {
1128 // this should really be sched_yield(), but the linux guys thought 1128 // this should really be sched_yield(), but the linux guys thought
1129 // that giving a process calling sched_yield () less cpu time than 1129 // that giving a process calling sched_yield () less cpu time than
1130 // ones with high nice levels is a useful thing to do. It surely is is 1130 // ones with high nice levels is a useful thing to do. It surely is is
1131 // allowed by the sus... as is returning ENOSYS. 1131 // allowed by the sus... as is returning ENOSYS.
1132 // since the linux guys additionally thought that breaking the only
1133 // known workaroudn against their unusable sched_yield hack is cool,
1134 // we just nanosleep a bit and hope for the best.
1132 1135
1133 struct timespec ts = { 0, 0 }; 1136 struct timespec ts = { 0, 1000 };
1134 nanosleep (&ts, 0); 1137 nanosleep (&ts, 0);
1135 1138
1136 w.stop (); 1139 w.stop ();
1137 } 1140 }
1138 1141
1188{ 1191{
1189 make_current (); 1192 make_current ();
1190 1193
1191 if (revents & ev::READ) 1194 if (revents & ev::READ)
1192 // loop, but don't allow a single term to monopolize us 1195 // loop, but don't allow a single term to monopolize us
1193 while (pty_fill ()) 1196 for (int i = CBUFCNT; i-- && pty_fill (); )
1194 if (cmd_parse ()) 1197 cmd_parse ();
1195 break;
1196 1198
1197 if (revents & ev::WRITE) 1199 if (revents & ev::WRITE)
1198 pty_write (); 1200 pty_write ();
1199 1201
1200 refresh_check (); 1202 refresh_check ();
1683 1685
1684 refresh_check (); 1686 refresh_check ();
1685} 1687}
1686 1688
1687void 1689void
1690rxvt_term::set_urgency (bool enable)
1691{
1692 if (enable == urgency_hint)
1693 return;
1694
1695 if (XWMHints *h = XGetWMHints (dpy, parent[0]))
1696 {
1697 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1698 XSetWMHints (dpy, parent[0], h);
1699 urgency_hint = enable;
1700 }
1701}
1702
1703void
1688rxvt_term::focus_in () 1704rxvt_term::focus_in ()
1689{ 1705{
1690 if (!focus) 1706 if (!focus)
1691 { 1707 {
1692 focus = 1; 1708 focus = 1;
1693 want_refresh = 1; 1709 want_refresh = 1;
1694
1695 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1696 1710
1697#if USE_XIM 1711#if USE_XIM
1698 if (Input_Context != NULL) 1712 if (Input_Context != NULL)
1699 { 1713 {
1700 IMSetPosition (); 1714 IMSetPosition ();
1712 scr_recolour (); 1726 scr_recolour ();
1713 } 1727 }
1714#endif 1728#endif
1715#if ENABLE_FRILLS 1729#if ENABLE_FRILLS
1716 if (option (Opt_urgentOnBell)) 1730 if (option (Opt_urgentOnBell))
1717 { 1731 set_urgency (0);
1718 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1719 {
1720 h->flags &= ~XUrgencyHint;
1721 XSetWMHints (dpy, parent[0], h);
1722 }
1723 }
1724#endif 1732#endif
1733
1734 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1725 } 1735 }
1726} 1736}
1727 1737
1728void 1738void
1729rxvt_term::focus_out () 1739rxvt_term::focus_out ()
1731 if (focus) 1741 if (focus)
1732 { 1742 {
1733 focus = 0; 1743 focus = 0;
1734 want_refresh = 1; 1744 want_refresh = 1;
1735 1745
1736 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); 1746#if ENABLE_FRILLS
1737 1747 if (option (Opt_urgentOnBell))
1748 set_urgency (0);
1749#endif
1738#if ENABLE_FRILLS || ISO_14755 1750#if ENABLE_FRILLS || ISO_14755
1739 if (iso14755buf) 1751 if (iso14755buf)
1740 { 1752 {
1741 iso14755buf = 0; 1753 iso14755buf = 0;
1742# if ISO_14755 1754# if ISO_14755
1759 { 1771 {
1760 pix_colors = pix_colors_unfocused; 1772 pix_colors = pix_colors_unfocused;
1761 scr_recolour (); 1773 scr_recolour ();
1762 } 1774 }
1763#endif 1775#endif
1776
1777 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1764 } 1778 }
1765} 1779}
1766 1780
1767void 1781void
1768rxvt_term::update_fade_color (unsigned int idx) 1782rxvt_term::update_fade_color (unsigned int idx)
2170 } 2184 }
2171} 2185}
2172 2186
2173/*}}} */ 2187/*}}} */
2174 2188
2175bool 2189void
2176rxvt_term::cmd_parse () 2190rxvt_term::cmd_parse ()
2177{ 2191{
2178 bool flag = false;
2179 wchar_t ch = NOCHAR; 2192 wchar_t ch = NOCHAR;
2180 char *seq_begin; // remember start of esc-sequence here 2193 char *seq_begin; // remember start of esc-sequence here
2181 2194
2182 for (;;) 2195 for (;;)
2183 { 2196 {
2184 if (ch == NOCHAR) 2197 if (expect_false (ch == NOCHAR))
2185 { 2198 {
2186 seq_begin = cmdbuf_ptr; 2199 seq_begin = cmdbuf_ptr;
2187 ch = next_char (); 2200 ch = next_char ();
2188 2201
2189 if (ch == NOCHAR) 2202 if (ch == NOCHAR)
2190 break; 2203 break;
2191 } 2204 }
2192 2205
2193 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2206 if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2194 { 2207 {
2195 if (!seen_input) 2208 if (expect_false (!seen_input))
2196 { 2209 {
2197 seen_input = 1; 2210 seen_input = 1;
2198 // many badly-written programs (e.g. jed) contain a race condition: 2211 // many badly-written programs (e.g. jed) contain a race condition:
2199 // they first read the screensize and then install a SIGWINCH handler. 2212 // they first read the screensize and then install a SIGWINCH handler.
2200 // some window managers resize the window early, and these programs 2213 // some window managers resize the window early, and these programs
2213 wchar_t *str = buf; 2226 wchar_t *str = buf;
2214 wchar_t *eol = str + min (ncol, UBUFSIZ); 2227 wchar_t *eol = str + min (ncol, UBUFSIZ);
2215 2228
2216 for (;;) 2229 for (;;)
2217 { 2230 {
2218 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2231 if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2219 break; 2232 break;
2220 2233
2221 *str++ = ch; 2234 *str++ = ch;
2222 2235
2223 if (ch == C0_LF || str >= eol) 2236 if (expect_false (ch == C0_LF || str >= eol))
2224 { 2237 {
2225 if (ch == C0_LF) 2238 if (ch == C0_LF)
2226 nlines++; 2239 nlines++;
2227 2240
2228 refresh_count++; 2241 refresh_count++;
2277 * What the heck we'll cheat and only refresh less than every page-full. 2290 * What the heck we'll cheat and only refresh less than every page-full.
2278 * if skipScroll is enabled. 2291 * if skipScroll is enabled.
2279 */ 2292 */
2280 if (refreshnow) 2293 if (refreshnow)
2281 { 2294 {
2282 flag = true;
2283 scr_refresh (); 2295 scr_refresh ();
2284 want_refresh = 1; 2296 want_refresh = 1;
2285 } 2297 }
2286
2287 } 2298 }
2288 else 2299 else
2289 { 2300 {
2290 try 2301 try
2291 { 2302 {
2299 } 2310 }
2300 2311
2301 ch = NOCHAR; 2312 ch = NOCHAR;
2302 } 2313 }
2303 } 2314 }
2304
2305 return flag;
2306} 2315}
2307 2316
2308// read the next character 2317// read the next character
2309wchar_t 2318wchar_t
2310rxvt_term::next_char () NOTHROW 2319rxvt_term::next_char () NOTHROW
2311{ 2320{
2312 while (cmdbuf_ptr < cmdbuf_endp) 2321 while (cmdbuf_ptr < cmdbuf_endp)
2313 { 2322 {
2314 // assume 7-bit to be ascii ALWAYS 2323 // assume 7-bit to be ascii ALWAYS
2315 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2324 if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2316 return *cmdbuf_ptr++; 2325 return *cmdbuf_ptr++;
2317 2326
2318 wchar_t wc; 2327 wchar_t wc;
2319 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2328 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2320 2329
2381/*----------------------------------------------------------------------*/ 2390/*----------------------------------------------------------------------*/
2382#ifdef PRINTPIPE 2391#ifdef PRINTPIPE
2383FILE * 2392FILE *
2384rxvt_term::popen_printer () 2393rxvt_term::popen_printer ()
2385{ 2394{
2386 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2395 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2387 2396
2388 if (stream == NULL) 2397 if (stream == NULL)
2389 rxvt_warn ("can't open printer pipe, not printing.\n"); 2398 rxvt_warn ("can't open printer pipe, not printing.\n");
2390 2399
2391 return stream; 2400 return stream;
2402 * simulate attached vt100 printer 2411 * simulate attached vt100 printer
2403 */ 2412 */
2404void 2413void
2405rxvt_term::process_print_pipe () 2414rxvt_term::process_print_pipe ()
2406{ 2415{
2407 int done; 2416 FILE *fd = popen_printer ();
2408 FILE *fd;
2409 2417
2410 if ((fd = popen_printer ()) == NULL) 2418 if (!fd)
2411 return; 2419 return;
2412 2420
2413 /* 2421 /*
2414 * Send all input to the printer until either ESC[4i or ESC[?4i 2422 * Send all input to the printer until either ESC[4i or ESC[?4i
2415 * is received. 2423 * is received.
2416 */ 2424 */
2417 for (done = 0; !done;) 2425 for (int done = 0; !done; )
2418 { 2426 {
2419 unsigned char buf[8]; 2427 unsigned char buf[8];
2420 unicode_t ch; 2428 unicode_t ch;
2421 unsigned int i, len; 2429 unsigned int i, len;
2422 2430
2680 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2688 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
2681 case C1_SCI: /* ESC Z */ 2689 case C1_SCI: /* ESC Z */
2682 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); 2690 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
2683 break; /* steal obsolete ESC [ c */ 2691 break; /* steal obsolete ESC [ c */
2684 2692
2685 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2693 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
2686 case C1_CSI: /* ESC [ */ 2694 case C1_CSI: /* ESC [ */
2687 process_csi_seq (); 2695 process_csi_seq ();
2688 break; 2696 break;
2689 2697
2690 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2698 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
2691 case C1_OSC: /* ESC ] */ 2699 case C1_OSC: /* ESC ] */
2692 process_osc_seq (); 2700 process_osc_seq ();
2693 break; 2701 break;
2694 2702
2695 /* 8.3.106: RESET TO INITIAL STATE */ 2703 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
2696 case 'c': 2704 case 'c':
2697 mbstate.reset (); 2705 mbstate.reset ();
2698 scr_poweron (); 2706 scr_poweron ();
2699 scrollBar.show (1); 2707 scrollBar.show (1);
2700 break; 2708 break;
2755 2763
2756 nargs = 0; 2764 nargs = 0;
2757 2765
2758 priv = 0; 2766 priv = 0;
2759 ch = cmd_getc (); 2767 ch = cmd_getc ();
2760 if (ch >= '<' && ch <= '?') 2768 if ((ch >= '<' && ch <= '?') || ch == '!')
2761 { 2769 {
2762 /* '<' '=' '>' '?' */ 2770 /* '<' '=' '>' '?' '!' */
2763 priv = ch; 2771 priv = ch;
2764 ch = cmd_getc (); 2772 ch = cmd_getc ();
2765 } 2773 }
2766 2774
2767 /* read any numerical arguments */ 2775 /* read any numerical arguments */
2821 2829
2822 case '?': 2830 case '?':
2823 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2831 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
2824 process_terminal_mode (ch, priv, nargs, arg); 2832 process_terminal_mode (ch, priv, nargs, arg);
2825 break; 2833 break;
2834
2835 case '!':
2836 if (ch == CSI_70)
2837 {
2838 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2839 scr_soft_reset ();
2840
2841 static const int pm_h[] = { 7, 25 };
2842 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1049 };
2843
2844 process_terminal_mode ('h', 0, sizeof (pm_h) / sizeof (pm_h[0]), pm_h);
2845 process_terminal_mode ('l', 0, sizeof (pm_l) / sizeof (pm_l[0]), pm_l);
2826 } 2846 }
2847 break;
2848 }
2849
2827 return; 2850 return;
2828 } 2851 }
2829 2852
2830 switch (ch) 2853 switch (ch)
2831 { 2854 {
3510 break; 3533 break;
3511#endif 3534#endif
3512 3535
3513#if ENABLE_PERL 3536#if ENABLE_PERL
3514 case URxvt_perl: 3537 case URxvt_perl:
3515 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) 3538 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3516 ; // no responses yet
3517 break; 3539 break;
3518#endif 3540#endif
3519 } 3541 }
3520} 3542}
3521/*----------------------------------------------------------------------*/ 3543/*----------------------------------------------------------------------*/
3562 static const struct 3584 static const struct
3563 { 3585 {
3564 const int argval; 3586 const int argval;
3565 const unsigned long bit; 3587 const unsigned long bit;
3566 } argtopriv[] = { 3588 } argtopriv[] = {
3567 { 1, PrivMode_aplCUR }, 3589 { 1, PrivMode_aplCUR }, // DECCKM
3568 { 2, PrivMode_vt52 }, 3590 { 2, PrivMode_vt52 },
3569 { 3, PrivMode_132 }, 3591 { 3, PrivMode_132 }, // DECCOLM
3570 { 4, PrivMode_smoothScroll }, 3592 { 4, PrivMode_smoothScroll }, // DECSCLM
3571 { 5, PrivMode_rVideo }, 3593 { 5, PrivMode_rVideo }, // DECSCNM
3572 { 6, PrivMode_relOrigin }, 3594 { 6, PrivMode_relOrigin }, // DECOM
3573 { 7, PrivMode_Autowrap }, 3595 { 7, PrivMode_Autowrap }, // DECAWM
3574 // 8, bi-directional support mode 3596 // 8, auto-repeat keys // DECARM
3575 { 9, PrivMode_MouseX10 }, 3597 { 9, PrivMode_MouseX10 },
3576 // 18, 19 printing-related 3598 // 18 end FF to printer after print screen
3599 // 19 Print screen prints full screen/scorll region
3577 { 25, PrivMode_VisibleCursor }, 3600 { 25, PrivMode_VisibleCursor }, // cnorm/cvvis/civis
3578#ifdef scrollBar_esc 3601#ifdef scrollBar_esc
3579 { scrollBar_esc, PrivMode_scrollBar }, 3602 { scrollBar_esc, PrivMode_scrollBar },
3580#endif 3603#endif
3581 { 35, PrivMode_ShiftKeys }, // rxvt extension 3604 { 35, PrivMode_ShiftKeys }, // rxvt extension
3605 // 38, tektronix mode // DECTEK
3582 { 40, PrivMode_132OK }, 3606 { 40, PrivMode_132OK },
3583 // 41 xterm more fixes NYI 3607 // 41 xterm more fixes NYI
3584 // 45 margin bell NYI 3608 // 45 margin bell NYI
3585 // 46 start logging 3609 // 46 start logging
3586 { 47, PrivMode_Screen }, 3610 { 47, PrivMode_Screen },
3587 { 66, PrivMode_aplKP }, 3611 { 66, PrivMode_aplKP }, // DECPAM/DECPNM
3588#ifndef NO_BACKSPACE_KEY 3612#ifndef NO_BACKSPACE_KEY
3589 { 67, PrivMode_BackSpace }, 3613 { 67, PrivMode_BackSpace }, // DECBKM
3590#endif 3614#endif
3591 { 1000, PrivMode_MouseX11 }, 3615 { 1000, PrivMode_MouseX11 },
3592 { 1002, PrivMode_MouseBtnEvent }, 3616 { 1002, PrivMode_MouseBtnEvent },
3593 { 1003, PrivMode_MouseAnyEvent }, 3617 { 1003, PrivMode_MouseAnyEvent },
3594 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3618 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3656 */ 3680 */
3657 set_privmode (PrivMode_vt52, 1); 3681 set_privmode (PrivMode_vt52, 1);
3658 break; 3682 break;
3659 case 3: /* 80/132 */ 3683 case 3: /* 80/132 */
3660 if (priv_modes & PrivMode_132OK) 3684 if (priv_modes & PrivMode_132OK)
3661 {
3662 scr_poweron ();
3663 set_widthheight (((state ? 132 : 80) * fwidth), 24 * fheight); 3685 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
3664 }
3665 break; 3686 break;
3666 case 4: /* smooth scrolling */ 3687 case 4: /* smooth scrolling */
3667 set_option (Opt_jumpScroll, !state); 3688 set_option (Opt_jumpScroll, !state);
3668 break; 3689 break;
3669 case 5: /* reverse video */ 3690 case 5: /* reverse video */
3711 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent; 3732 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3712 vt_emask_mouse = PointerMotionMask; 3733 vt_emask_mouse = PointerMotionMask;
3713 } 3734 }
3714 else 3735 else
3715 vt_emask_mouse = NoEventMask; 3736 vt_emask_mouse = NoEventMask;
3737
3716 vt_select_input (); 3738 vt_select_input ();
3717 break; 3739 break;
3718 case 1010: /* scroll to bottom on TTY output inhibit */ 3740 case 1010: /* scroll to bottom on TTY output inhibit */
3719 set_option (Opt_scrollTtyOutput, !state); 3741 set_option (Opt_scrollTtyOutput, !state);
3720 break; 3742 break;
3723 break; 3745 break;
3724 case 1047: /* secondary screen w/ clearing last */ 3746 case 1047: /* secondary screen w/ clearing last */
3725 if (option (Opt_secondaryScreen)) 3747 if (option (Opt_secondaryScreen))
3726 if (current_screen != PRIMARY) 3748 if (current_screen != PRIMARY)
3727 scr_erase_screen (2); 3749 scr_erase_screen (2);
3750
3728 scr_change_screen (state); 3751 scr_change_screen (state);
3729 break; 3752 break;
3730 case 1049: /* secondary screen w/ clearing first */ 3753 case 1049: /* secondary screen w/ clearing first */
3731 scr_change_screen (state); 3754 scr_change_screen (state);
3732 if (option (Opt_secondaryScreen)) 3755 if (option (Opt_secondaryScreen))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines