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.272 by root, Thu Jan 19 16:22:12 2006 UTC vs.
Revision 1.284 by root, Wed Jan 25 02:42:06 2006 UTC

64 64
65/*----------------------------------------------------------------------*/ 65/*----------------------------------------------------------------------*/
66 66
67#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 67#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
68 68
69// exception thrown when the command parser runs out of input data
70class out_of_input { } out_of_input;
71
72#if ENABLE_FRILLS || ISO_14755 69#if ENABLE_FRILLS || ISO_14755
73 70
74#define ISO_14755_STARTED 0x80000000UL 71#define ISO_14755_STARTED 0x80000000UL
75#define ISO_14755_51 0x40000000UL // basic (section 5.1) 72#define ISO_14755_51 0x40000000UL // basic (section 5.1)
76#define ISO_14755_52 0x20000000UL // keycap (section 5.2) 73#define ISO_14755_52 0x20000000UL // keycap (section 5.2)
302rxvt_term::lookup_key (XKeyEvent &ev) 299rxvt_term::lookup_key (XKeyEvent &ev)
303{ 300{
304 int ctrl, meta, shft, len; 301 int ctrl, meta, shft, len;
305 unsigned int newlen; 302 unsigned int newlen;
306 KeySym keysym; 303 KeySym keysym;
307#ifdef DEBUG_CMD
308 static int debug_key = 1; /* accessible by a debugger only */
309#endif
310 int valid_keysym; 304 int valid_keysym;
311 char kbuf[KBUFSZ]; 305 char kbuf[KBUFSZ];
312 306
313 /* 307 /*
314 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 308 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
905 { 899 {
906 const char ch = C0_ESC; 900 const char ch = C0_ESC;
907 tt_write (&ch, 1); 901 tt_write (&ch, 1);
908 } 902 }
909 903
910#if defined(DEBUG_CMD)
911 /* Display keyboard buffer contents */
912 unsigned char *p;
913 int i;
914
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); 904 tt_write (kbuf, (unsigned int)len);
921} 905}
922/*}}} */ 906/*}}} */
923 907
924#if defined (KEYSYM_RESOURCE) 908#if defined (KEYSYM_RESOURCE)
1044rxvt_term::cursor_blink_cb (time_watcher &w) 1028rxvt_term::cursor_blink_cb (time_watcher &w)
1045{ 1029{
1046 hidden_cursor = !hidden_cursor; 1030 hidden_cursor = !hidden_cursor;
1047 want_refresh = 1; 1031 want_refresh = 1;
1048 1032
1049 w.start (w.at + BLINK_INTERVAL); 1033 w.start (w.at + CURSOR_BLINK_INTERVAL);
1050} 1034}
1051#endif 1035#endif
1052 1036
1053#ifdef TEXT_BLINK 1037#ifdef TEXT_BLINK
1054void 1038void
1281 tt_printf ("\033[M%c%c%c", 1265 tt_printf ("\033[M%c%c%c",
1282 (32 + button_number + key_state), 1266 (32 + button_number + key_state),
1283 (32 + x + 1), 1267 (32 + x + 1),
1284 (32 + y + 1)); 1268 (32 + y + 1));
1285} 1269}
1286
1287#ifdef USING_W11LIB
1288void
1289rxvt_W11_process_x_event (XEvent *ev)
1290{
1291 rxvt_t *r = rxvt_get_r ();
1292
1293 x_cb (*ev);
1294}
1295#endif
1296 1270
1297/*{{{ process an X event */ 1271/*{{{ process an X event */
1298void 1272void
1299rxvt_term::x_cb (XEvent &ev) 1273rxvt_term::x_cb (XEvent &ev)
1300{ 1274{
1405 button_release (ev.xbutton); 1379 button_release (ev.xbutton);
1406 break; 1380 break;
1407 1381
1408 case ClientMessage: 1382 case ClientMessage:
1409 if (ev.xclient.format == 32 1383 if (ev.xclient.format == 32
1410 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) 1384 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1411 { 1385 {
1386 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1387 {
1388 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1389 {
1412 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1390 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1391 {
1392 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1413 destroy (); 1393 destroy ();
1394 }
1414#if ENABLE_EWMH 1395#if ENABLE_EWMH
1415 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1396 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1416 XSendEvent (disp, ev.xclient.window = display->root, 1397 XSendEvent (disp, ev.xclient.window = display->root,
1417 False, SubstructureRedirectMask | SubstructureNotifyMask, 1398 False, SubstructureRedirectMask | SubstructureNotifyMask,
1418 &ev); 1399 &ev);
1400#endif
1401 }
1402 }
1403#if ENABLE_XEMBED
1404 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1405 {
1406 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1407 focus_in ();
1408 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1409 focus_out ();
1410 }
1419#endif 1411#endif
1420 } 1412 }
1421#if ENABLE_XEMBED
1422 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1423 {
1424 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1425 focus_in ();
1426 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1427 focus_out ();
1428 }
1429#endif
1430#ifdef OFFIX_DND
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))
1436 {
1437 /* Get Dnd data */
1438 Atom ActualType;
1439 int ActualFormat;
1440 unsigned char *data;
1441 unsigned long Size, RemainingBytes;
1442
1443 XGetWindowProperty (disp, display->root,
1444 xa[XA_DNDSELECTION],
1445 0L, 1000000L,
1446 False, AnyPropertyType,
1447 &ActualType, &ActualFormat,
1448 &Size, &RemainingBytes,
1449 &data);
1450 set_string_property (XA_CUT_BUFFER0, data);
1451 XFree (data);
1452 selection_paste (display->root, XA_CUT_BUFFER0, true);
1453 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1454 }
1455#endif /* OFFIX_DND */
1456 break; 1413 break;
1457 1414
1458 case MappingNotify: 1415 case MappingNotify:
1459 XRefreshKeyboardMapping (&ev.xmapping); 1416 XRefreshKeyboardMapping (&ev.xmapping);
1460 break; 1417 break;
1512#endif 1469#endif
1513 } 1470 }
1514 break; 1471 break;
1515 1472
1516 case PropertyNotify: 1473 case PropertyNotify:
1474 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1517 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1475 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1518 && ev.xproperty.state == PropertyNewValue) 1476 && ev.xproperty.state == PropertyNewValue)
1519 selection_property (ev.xproperty.window, ev.xproperty.atom); 1477 selection_property (ev.xproperty.window, ev.xproperty.atom);
1520 1478
1521 break; 1479 break;
1522 1480
1523 case SelectionClear: 1481 case SelectionClear:
1524 selection_clear (); 1482 selection_clear ();
1713 { 1671 {
1714 hidden_cursor = 0; 1672 hidden_cursor = 0;
1715 want_refresh = 1; 1673 want_refresh = 1;
1716 } 1674 }
1717 1675
1718 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1676 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1719 } 1677 }
1720#endif 1678#endif
1721 1679
1722#if defined(POINTER_BLANK) 1680#if defined(POINTER_BLANK)
1723 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) 1681 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1751 XSetICFocus (Input_Context); 1709 XSetICFocus (Input_Context);
1752 } 1710 }
1753#endif 1711#endif
1754#if CURSOR_BLINK 1712#if CURSOR_BLINK
1755 if (OPTION (Opt_cursorBlink)) 1713 if (OPTION (Opt_cursorBlink))
1756 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1714 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1757#endif 1715#endif
1758#if OFF_FOCUS_FADING 1716#if OFF_FOCUS_FADING
1759 if (rs[Rs_fade]) 1717 if (rs[Rs_fade])
1760 { 1718 {
1761 pix_colors = pix_colors_focused; 1719 pix_colors = pix_colors_focused;
1842 /* 1800 /*
1843 * VT window processing of button press 1801 * VT window processing of button press
1844 */ 1802 */
1845 if (ev.window == vt) 1803 if (ev.window == vt)
1846 { 1804 {
1805 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1806 return;
1807
1847#if ISO_14755 1808#if ISO_14755
1848 // 5.4 1809 // 5.4
1849 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1810 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1850 { 1811 {
1851 iso14755_54 (ev.x, ev.y); 1812 iso14755_54 (ev.x, ev.y);
1893 else 1854 else
1894 { 1855 {
1895 if (ev.button != MEvent.button) 1856 if (ev.button != MEvent.button)
1896 MEvent.clicks = 0; 1857 MEvent.clicks = 0;
1897 1858
1898 if (!HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1899 switch (ev.button) 1859 switch (ev.button)
1900 { 1860 {
1901 case Button1: 1861 case Button1:
1902 /* allow meta + click to select rectangular areas */ 1862 /* allow meta + click to select rectangular areas */
1903 /* should be done in screen.C */ 1863 /* should be done in screen.C */
1904#if ENABLE_FRILLS 1864#if ENABLE_FRILLS
1905 selection.rect = !!(ev.state & ModMetaMask); 1865 selection.rect = !!(ev.state & ModMetaMask);
1906#else 1866#else
1907 selection.rect = false; 1867 selection.rect = false;
1908#endif 1868#endif
1909 1869
1910 /* allow shift+left click to extend selection */ 1870 /* allow shift+left click to extend selection */
1911 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report)) 1871 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1912 { 1872 {
1913 if (MEvent.button == Button1 && clickintime) 1873 if (MEvent.button == Button1 && clickintime)
1914 selection_rotate (ev.x, ev.y); 1874 selection_rotate (ev.x, ev.y);
1915 else 1875 else
1916 selection_extend (ev.x, ev.y, 1); 1876 selection_extend (ev.x, ev.y, 1);
1917 } 1877 }
1918 else 1878 else
1919 { 1879 {
1920 if (MEvent.button == Button1 && clickintime) 1880 if (MEvent.button == Button1 && clickintime)
1921 MEvent.clicks++; 1881 MEvent.clicks++;
1922 else 1882 else
1923 MEvent.clicks = 1; 1883 MEvent.clicks = 1;
1924 1884
1925 selection_click (MEvent.clicks, ev.x, ev.y); 1885 selection_click (MEvent.clicks, ev.x, ev.y);
1926 } 1886 }
1927 1887
1928 MEvent.button = Button1; 1888 MEvent.button = Button1;
1929 break; 1889 break;
1930 1890
1931 case Button3: 1891 case Button3:
1932 if (MEvent.button == Button3 && clickintime) 1892 if (MEvent.button == Button3 && clickintime)
1933 selection_rotate (ev.x, ev.y); 1893 selection_rotate (ev.x, ev.y);
1934 else 1894 else
1935 selection_extend (ev.x, ev.y, 1); 1895 selection_extend (ev.x, ev.y, 1);
1936 1896
1937 MEvent.button = Button3; 1897 MEvent.button = Button3;
1938 break; 1898 break;
1939 } 1899 }
1940 } 1900 }
1941 1901
1942 MEvent.time = ev.time; 1902 MEvent.time = ev.time;
1943 return; 1903 return;
1944 } 1904 }
1945 1905
2108 sel_scroll_ev.stop(); 2068 sel_scroll_ev.stop();
2109#endif 2069#endif
2110 2070
2111 if (ev.window == vt) 2071 if (ev.window == vt)
2112 { 2072 {
2073 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2074 return;
2075
2113#if ISO_14755 2076#if ISO_14755
2114 // 5.4 2077 // 5.4
2115 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2078 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2116 return; 2079 return;
2117#endif 2080#endif
2081
2118 if (reportmode) 2082 if (reportmode)
2119 { 2083 {
2120 /* mouse report from vt window */ 2084 /* mouse report from vt window */
2121 /* don't report release of wheel "buttons" */ 2085 /* don't report release of wheel "buttons" */
2122 if (ev.button >= 4) 2086 if (ev.button >= 4)
2146 if (priv_modes & PrivMode_mouse_report 2110 if (priv_modes & PrivMode_mouse_report
2147 && bypass_keystate 2111 && bypass_keystate
2148 && ev.button == Button1 && MEvent.clicks <= 1) 2112 && ev.button == Button1 && MEvent.clicks <= 1)
2149 selection_extend (ev.x, ev.y, 0); 2113 selection_extend (ev.x, ev.y, 0);
2150 2114
2151 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2152 return;
2153
2154 switch (ev.button) 2115 switch (ev.button)
2155 { 2116 {
2156 case Button1: 2117 case Button1:
2157 case Button3: 2118 case Button3:
2158 selection_make (ev.time); 2119 selection_make (ev.time);
2159 break; 2120 break;
2160 2121
2161 case Button2: 2122 case Button2:
2162 if (IN_RANGE_EXC (ev.x, 0, width) 2123 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2163 && IN_RANGE_EXC (ev.y, 0, height)) // inside window? 2124 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary);
2164 selection_request (ev.time);
2165
2166 break; 2125 break;
2167 2126
2168#ifdef MOUSE_WHEEL 2127#ifdef MOUSE_WHEEL
2169 case Button4: 2128 case Button4:
2170 case Button5: 2129 case Button5:
2650 am_transparent = 0; 2609 am_transparent = 0;
2651 /* XXX: also turn off Opt_transparent? */ 2610 /* XXX: also turn off Opt_transparent? */
2652 } 2611 }
2653 else 2612 else
2654 { 2613 {
2655#if WAIT_FOR_WM
2656 /* wait (an arbitrary period) for the WM to do its thing
2657 * needed for fvwm2.2.2 (and before?) */
2658 sleep (1);
2659#endif
2660 for (n = 0; n < (unsigned int)i; n++) 2614 for (n = 0; n < (unsigned int)i; n++)
2661 { 2615 {
2662 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative); 2616 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2663 XClearWindow (disp, parent[n]); 2617 XClearWindow (disp, parent[n]);
2664 } 2618 }
2827 return flag; 2781 return flag;
2828} 2782}
2829 2783
2830// read the next character 2784// read the next character
2831wchar_t 2785wchar_t
2832rxvt_term::next_char () 2786rxvt_term::next_char () NOTHROW
2833{ 2787{
2834 while (cmdbuf_ptr < cmdbuf_endp) 2788 while (cmdbuf_ptr < cmdbuf_endp)
2835 { 2789 {
2836 // assume 7-bit to be ascii ALWAYS 2790 // assume 7-bit to be ascii ALWAYS
2837 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2791 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2858 return NOCHAR; 2812 return NOCHAR;
2859} 2813}
2860 2814
2861// read the next octet 2815// read the next octet
2862uint32_t 2816uint32_t
2863rxvt_term::next_octet () 2817rxvt_term::next_octet () NOTHROW
2864{ 2818{
2865 return cmdbuf_ptr < cmdbuf_endp 2819 return cmdbuf_ptr < cmdbuf_endp
2866 ? (unsigned char)*cmdbuf_ptr++ 2820 ? (unsigned char)*cmdbuf_ptr++
2867 : NOCHAR; 2821 : NOCHAR;
2868} 2822}
2823
2824static class out_of_input out_of_input;
2869 2825
2870/* rxvt_cmd_getc () - Return next input character */ 2826/* rxvt_cmd_getc () - Return next input character */
2871/* 2827/*
2872 * Return the next input character after first passing any keyboard input 2828 * Return the next input character after first passing any keyboard input
2873 * to the command. 2829 * to the command.
2874 */ 2830 */
2875wchar_t 2831wchar_t
2876rxvt_term::cmd_getc () 2832rxvt_term::cmd_getc () THROW ((class out_of_input))
2877{ 2833{
2878 wchar_t c = next_char (); 2834 wchar_t c = next_char ();
2879 2835
2880 if (c == NOCHAR) 2836 if (c == NOCHAR)
2881 throw out_of_input; 2837 throw out_of_input;
2882 2838
2883 return c; 2839 return c;
2884} 2840}
2885 2841
2886uint32_t 2842uint32_t
2887rxvt_term::cmd_get8 () 2843rxvt_term::cmd_get8 () THROW ((class out_of_input))
2888{ 2844{
2889 uint32_t c = next_octet (); 2845 uint32_t c = next_octet ();
2890 2846
2891 if (c == NOCHAR) 2847 if (c == NOCHAR)
2892 throw out_of_input; 2848 throw out_of_input;
3313 ndef = get_byte_array_bit (csi_defaults, i); 3269 ndef = get_byte_array_bit (csi_defaults, i);
3314 for (p = 0; p < nargs; p++) 3270 for (p = 0; p < nargs; p++)
3315 if (arg[p] == -1) 3271 if (arg[p] == -1)
3316 arg[p] = ndef; 3272 arg[p] = ndef;
3317 3273
3318#ifdef DEBUG_CMD
3319 fprintf (stderr, "CSI ");
3320 for (p = 0; p < nargs; p++)
3321 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3322 fprintf (stderr, "%c\n", ch);
3323#endif
3324
3325 /* 3274 /*
3326 * private mode handling 3275 * private mode handling
3327 */ 3276 */
3328 if (priv) 3277 if (priv)
3329 { 3278 {
3330 switch (priv) 3279 switch (priv)
3331 { 3280 {
3332 case '>': 3281 case '>':
3333 if (ch == CSI_DA) /* secondary device attributes */ 3282 if (ch == CSI_DA) /* secondary device attributes */
3283 {
3284 // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt,
3285 // 'U' for rxvt-unicode <= 7.2, and Mm85 (e.g. 7385 for 7.3) for later versions.
3286 //
3287 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
3288 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify
3289 // that we do not support xterm mouse reporting (should be 95 when we do).
3290 //
3334 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 3291 tt_printf ("\033[>%c%c85;94;0c", VERSION[0], VERSION[1]);
3292 }
3335 break; 3293 break;
3336 case '?': 3294 case '?':
3337 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3295 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3338 process_terminal_mode (ch, priv, nargs, arg); 3296 process_terminal_mode (ch, priv, nargs, arg);
3339 break; 3297 break;
4042 return state; 4000 return state;
4043} 4001}
4044 4002
4045/* we're not using priv _yet_ */ 4003/* we're not using priv _yet_ */
4046void 4004void
4047rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 4005rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
4048{ 4006{
4049 unsigned int i, j; 4007 unsigned int i, j;
4050 int state; 4008 int state;
4051 4009
4052 static const struct 4010 static const struct

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines