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.81 by pcg, Sun Mar 28 02:07:08 2004 UTC vs.
Revision 1.95 by pcg, Sun May 9 18:19:49 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: command.c 2 * File: command.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
7 * - original version 7 * - original version
672 scr_refresh (refresh_type); 672 scr_refresh (refresh_type);
673 scrollbar_show (1); 673 scrollbar_show (1);
674#ifdef USE_XIM 674#ifdef USE_XIM
675 IMSendSpot (); 675 IMSendSpot ();
676#endif 676#endif
677
678 } 677 }
679 678
680 display->flush (); 679 display->flush ();
681} 680}
682 681
715 714
716bool 715bool
717rxvt_term::pty_fill () 716rxvt_term::pty_fill ()
718{ 717{
719 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 718 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
719
720 if (CBUFSIZ == n)
721 {
722 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
723 n = 0;
724 }
720 725
721 memmove (cmdbuf_base, cmdbuf_ptr, n); 726 memmove (cmdbuf_base, cmdbuf_ptr, n);
722 cmdbuf_ptr = cmdbuf_base; 727 cmdbuf_ptr = cmdbuf_base;
723 cmdbuf_endp = cmdbuf_ptr + n; 728 cmdbuf_endp = cmdbuf_ptr + n;
724 729
742 SET_LOCALE (locale); 747 SET_LOCALE (locale);
743 748
744 if (revents & EVENT_WRITE) 749 if (revents & EVENT_WRITE)
745 tt_write (0, 0); 750 tt_write (0, 0);
746 else if (revents & EVENT_READ) 751 else if (revents & EVENT_READ)
747 {
748 // loop, but don't allow a single term to monopolize us 752 // loop, but don't allow a single term to monopolize us
749 // the number of loops is fully arbitrary, and thus wrong
750 while (pty_fill ()) 753 while (pty_fill ())
751 {
752 if (!seen_input)
753 {
754 seen_input = 1;
755 /* once we know the shell is running, send the screen size. Again! */
756 // I don't know why, btw.
757 tt_winch ();
758 }
759
760 if (cmd_parse ()) 754 if (cmd_parse ())
761 break; 755 break;
762 }
763 }
764} 756}
765 757
766#ifdef POINTER_BLANK 758#ifdef POINTER_BLANK
767void 759void
768rxvt_term::pointer_unblank () 760rxvt_term::pointer_unblank ()
1013 && (ev.xclient.data.l[0] == DndFile 1005 && (ev.xclient.data.l[0] == DndFile
1014 || ev.xclient.data.l[0] == DndDir 1006 || ev.xclient.data.l[0] == DndDir
1015 || ev.xclient.data.l[0] == DndLink)) 1007 || ev.xclient.data.l[0] == DndLink))
1016 { 1008 {
1017 /* Get Dnd data */ 1009 /* Get Dnd data */
1018 Atom ActualType; 1010 Atom ActualType;
1019 int ActualFormat; 1011 int ActualFormat;
1020 unsigned char *data; 1012 unsigned char *data;
1021 unsigned long Size, RemainingBytes; 1013 unsigned long Size, RemainingBytes;
1022 1014
1023 XGetWindowProperty (display->display, display->root, 1015 XGetWindowProperty (display->display, display->root,
1024 xa[XA_DNDSELECTION], 1016 xa[XA_DNDSELECTION],
1025 0L, 1000000L, 1017 0L, 1000000L,
1026 False, AnyPropertyType, 1018 False, AnyPropertyType,
1029 &data); 1021 &data);
1030 XChangeProperty (display->display, display->root, 1022 XChangeProperty (display->display, display->root,
1031 XA_CUT_BUFFER0, XA_STRING, 1023 XA_CUT_BUFFER0, XA_STRING,
1032 8, PropModeReplace, 1024 8, PropModeReplace,
1033 data, STRLEN (data)); 1025 data, STRLEN (data));
1026 XFree (data);
1034 selection_paste (display->root, XA_CUT_BUFFER0, True); 1027 selection_paste (display->root, XA_CUT_BUFFER0, True);
1035 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1028 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1036 } 1029 }
1037#endif /* OFFIX_DND */ 1030#endif /* OFFIX_DND */
1038 break; 1031 break;
1131 check_our_parents (); 1124 check_our_parents ();
1132 if (am_transparent) 1125 if (am_transparent)
1133 want_full_refresh = 1; 1126 want_full_refresh = 1;
1134 } 1127 }
1135#endif 1128#endif
1136
1137 } 1129 }
1138 break; 1130 break;
1139 1131
1140 case SelectionClear: 1132 case SelectionClear:
1141 selection_clear (); 1133 selection_clear ();
1177 { 1169 {
1178#ifdef NO_SLOW_LINK_SUPPORT 1170#ifdef NO_SLOW_LINK_SUPPORT
1179 scr_expose (ev.xexpose.x, ev.xexpose.y, 1171 scr_expose (ev.xexpose.x, ev.xexpose.y,
1180 ev.xexpose.width, ev.xexpose.height, False); 1172 ev.xexpose.width, ev.xexpose.height, False);
1181#else 1173#else
1182 // don't understand this, so commented it out 1174 // I don't understand this, so I changed it :)
1183 scr_expose (ev.xexpose.x, ev.xexpose.y, 1175 scr_expose (ev.xexpose.x, ev.xexpose.y,
1184 ev.xexpose.width, ev.xexpose.height, False); 1176 ev.xexpose.width, ev.xexpose.height, False);
1185 //scr_expose (ev.xexpose.x, 0, 1177 //scr_expose (ev.xexpose.x, 0,
1186 // ev.xexpose.width, TermWin.height, False); 1178 // ev.xexpose.width, TermWin.height, False);
1187#endif 1179#endif
1189 } 1181 }
1190 else 1182 else
1191 { 1183 {
1192 XEvent unused_event; 1184 XEvent unused_event;
1193 1185
1194 while (XCheckTypedWindowEvent (display->display, ev.xany.window, 1186 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event))
1195 Expose, 1187 ;
1196 &unused_event)) ;
1197 while (XCheckTypedWindowEvent (display->display, ev.xany.window, 1188 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event))
1198 GraphicsExpose, 1189 ;
1199 &unused_event)) ; 1190
1200 if (isScrollbarWindow (ev.xany.window)) 1191 if (isScrollbarWindow (ev.xany.window))
1201 { 1192 {
1202 scrollBar.setIdle (); 1193 scrollBar.setIdle ();
1203 scrollbar_show (0); 1194 scrollbar_show (0);
1204 } 1195 }
1345 return; 1336 return;
1346 } 1337 }
1347 1338
1348 /* FALLTHROUGH */ 1339 /* FALLTHROUGH */
1349 case ReparentNotify: 1340 case ReparentNotify:
1350 if ((Options & Opt_transparent) && check_our_parents ()) 1341 if ((Options & Opt_transparent) && check_our_parents () && am_transparent)
1351 if (am_transparent)
1352 want_full_refresh = 1; 1342 want_full_refresh = 1;
1353 break; 1343 break;
1354#endif 1344#endif
1355 } 1345 }
1356} 1346}
1357 1347
1701 else if (isMenuBarWindow (ev.window)) 1691 else if (isMenuBarWindow (ev.window))
1702 menubar_control (ev); 1692 menubar_control (ev);
1703#endif 1693#endif
1704} 1694}
1705 1695
1706
1707#ifdef TRANSPARENT 1696#ifdef TRANSPARENT
1697#if TINTING
1698/* shading taken from eterm-0.9.2 */
1699/* RGB 15 */
1700
1701static void
1702shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm)
1703{
1704 unsigned char *ptr;
1705 int x, y;
1706
1707 ptr = (unsigned char *)data + (w * sizeof(uint16_t));
1708 if ((rm <= 256) && (gm <= 256) && (bm <= 256)) {
1709 /* No saturation */
1710 for (y = h; --y >= 0;) {
1711 for (x = -w; x < 0; x++) {
1712 int r, g, b;
1713
1714 b = ((uint16_t *) ptr)[x];
1715 r = (b & 0x7c00) * rm;
1716 g = (b & 0x3e0) * gm;
1717 b = (b & 0x1f) * bm;
1718 ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00)
1719 | ((g >> 8) & 0x3e0)
1720 | ((b >> 8) & 0x1f);
1721 }
1722 ptr += bpl;
1723 }
1724 } else {
1725 for (y = h; --y >= 0;) {
1726 for (x = -w; x < 0; x++) {
1727 int r, g, b;
1728
1729 b = ((uint16_t *) ptr)[x];
1730 r = (b & 0x7c00) * rm;
1731 g = (b & 0x3e0) * gm;
1732 b = (b & 0x1f) * bm;
1733 r |= (!(r >> 15) - 1);
1734 g |= (!(g >> 10) - 1);
1735 b |= (!(b >> 5) - 1);
1736 ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00)
1737 | ((g >> 8) & 0x3e0)
1738 | ((b >> 8) & 0x1f);
1739 }
1740 ptr += bpl;
1741 }
1742 }
1743}
1744
1745/* RGB 16 */
1746static void
1747shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm)
1748{
1749 unsigned char *ptr;
1750 int x, y;
1751
1752 ptr = (unsigned char *)data + (w * sizeof(uint16_t));
1753 if ((rm <= 256) && (gm <= 256) && (bm <= 256)) {
1754 /* No saturation */
1755 for (y = h; --y >= 0;) {
1756 for (x = -w; x < 0; x++) {
1757 int r, g, b;
1758
1759 b = ((uint16_t *) ptr)[x];
1760 r = (b & 0xf800) * rm;
1761 g = (b & 0x7e0) * gm;
1762 b = (b & 0x1f) * bm;
1763 ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800)
1764 | ((g >> 8) & 0x7e0)
1765 | ((b >> 8) & 0x1f);
1766 }
1767 ptr += bpl;
1768 }
1769 } else {
1770 for (y = h; --y >= 0;) {
1771 for (x = -w; x < 0; x++) {
1772 int r, g, b;
1773
1774 b = ((uint16_t *) ptr)[x];
1775 r = (b & 0xf800) * rm;
1776 g = (b & 0x7e0) * gm;
1777 b = (b & 0x1f) * bm;
1778 r |= (!(r >> 16) - 1);
1779 g |= (!(g >> 11) - 1);
1780 b |= (!(b >> 5) - 1);
1781 ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800)
1782 | ((g >> 8) & 0x7e0)
1783 | ((b >> 8) & 0x1f);
1784 }
1785 ptr += bpl;
1786 }
1787 }
1788}
1789
1790/* RGB 24 */
1791static void
1792shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm)
1793{
1794 unsigned char *ptr;
1795 int x, y;
1796
1797 ptr = (unsigned char *)data + (w * 3);
1798 if ((rm <= 256) && (gm <= 256) && (bm <= 256)) {
1799 /* No saturation */
1800 for (y = h; --y >= 0;) {
1801 for (x = -(w * 3); x < 0; x += 3) {
1802 int r, g, b;
1803
1804 if (byteorder.big_endian()) {
1805 r = (ptr[x + 0] * rm) >> 8;
1806 g = (ptr[x + 1] * gm) >> 8;
1807 b = (ptr[x + 2] * bm) >> 8;
1808 ptr[x + 0] = r;
1809 ptr[x + 1] = g;
1810 ptr[x + 2] = b;
1811 } else {
1812 r = (ptr[x + 2] * rm) >> 8;
1813 g = (ptr[x + 1] * gm) >> 8;
1814 b = (ptr[x + 0] * bm) >> 8;
1815 ptr[x + 2] = r;
1816 ptr[x + 1] = g;
1817 ptr[x + 0] = b;
1818 }
1819 }
1820 ptr += bpl;
1821 }
1822 } else {
1823 for (y = h; --y >= 0;) {
1824 for (x = -(w * 3); x < 0; x += 3) {
1825 int r, g, b;
1826
1827 if (byteorder.big_endian()) {
1828 r = (ptr[x + 0] * rm) >> 8;
1829 g = (ptr[x + 1] * gm) >> 8;
1830 b = (ptr[x + 2] * bm) >> 8;
1831
1832 r |= (!(r >> 8) - 1);
1833 g |= (!(g >> 8) - 1);
1834 b |= (!(b >> 8) - 1);
1835
1836 ptr[x + 0] = r;
1837 ptr[x + 1] = g;
1838 ptr[x + 2] = b;
1839 } else {
1840 r = (ptr[x + 2] * rm) >> 8;
1841 g = (ptr[x + 1] * gm) >> 8;
1842 b = (ptr[x + 0] * bm) >> 8;
1843
1844 r |= (!(r >> 8) - 1);
1845 g |= (!(g >> 8) - 1);
1846 b |= (!(b >> 8) - 1);
1847
1848 ptr[x + 2] = r;
1849 ptr[x + 1] = g;
1850 ptr[x + 0] = b;
1851 }
1852 }
1853 ptr += bpl;
1854 }
1855 }
1856}
1857
1858/* RGB 32 */
1859static void
1860shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm)
1861{
1862 unsigned char *ptr;
1863 int x, y;
1864
1865 ptr = (unsigned char *)data + (w * 4);
1866 if ((rm <= 256) && (gm <= 256) && (bm <= 256)) {
1867 /* No saturation */
1868 for (y = h; --y >= 0;) {
1869 if (byteorder.big_endian()) {
1870 for (x = -(w * 4); x < 0; x += 4) {
1871 int r, g, b;
1872
1873 r = (ptr[x + 1] * rm) >> 8;
1874 g = (ptr[x + 2] * gm) >> 8;
1875 b = (ptr[x + 3] * bm) >> 8;
1876 ptr[x + 1] = r;
1877 ptr[x + 2] = g;
1878 ptr[x + 3] = b;
1879 }
1880 } else {
1881 for (x = -(w * 4); x < 0; x += 4) {
1882 int r, g, b;
1883
1884 r = (ptr[x + 2] * rm) >> 8;
1885 g = (ptr[x + 1] * gm) >> 8;
1886 b = (ptr[x + 0] * bm) >> 8;
1887 ptr[x + 2] = r;
1888 ptr[x + 1] = g;
1889 ptr[x + 0] = b;
1890 }
1891 }
1892 ptr += bpl;
1893 }
1894 } else {
1895 for (y = h; --y >= 0;) {
1896 for (x = -(w * 4); x < 0; x += 4) {
1897 int r, g, b;
1898
1899 if (byteorder.big_endian()) {
1900 r = (ptr[x + 1] * rm) >> 8;
1901 g = (ptr[x + 2] * gm) >> 8;
1902 b = (ptr[x + 3] * bm) >> 8;
1903
1904 r |= (!(r >> 8) - 1);
1905 g |= (!(g >> 8) - 1);
1906 b |= (!(b >> 8) - 1);
1907
1908 ptr[x + 1] = r;
1909 ptr[x + 2] = g;
1910 ptr[x + 3] = b;
1911 } else {
1912 r = (ptr[x + 2] * rm) >> 8;
1913 g = (ptr[x + 1] * gm) >> 8;
1914 b = (ptr[x + 0] * bm) >> 8;
1915
1916 r |= (!(r >> 8) - 1);
1917 g |= (!(g >> 8) - 1);
1918 b |= (!(b >> 8) - 1);
1919
1920 ptr[x + 2] = r;
1921 ptr[x + 1] = g;
1922 ptr[x + 0] = b;
1923 }
1924 }
1925 ptr += bpl;
1926 }
1927 }
1928}
1929
1930#endif
1931
1708/* 1932/*
1709 * Check our parents are still who we think they are. 1933 * Check our parents are still who we think they are.
1710 * Do transparency updates if required 1934 * Do transparency updates if required
1711 */ 1935 */
1712int 1936int
1713rxvt_term::check_our_parents () 1937rxvt_term::check_our_parents ()
1714{ 1938{
1715 int i, pchanged, aformat, have_pixmap, rootdepth; 1939 int i, pchanged, aformat, have_pixmap, rootdepth;
1716 unsigned long nitems, bytes_after; 1940 unsigned long nitems, bytes_after;
1717 Atom atype; 1941 Atom atype;
1718 unsigned char *prop = NULL; 1942 unsigned char *prop = NULL;
1719 Window root, oldp, *list; 1943 Window root, oldp, *list;
1720 Pixmap rootpixmap = None; 1944 Pixmap rootpixmap = None;
1721 XWindowAttributes wattr, wrootattr; 1945 XWindowAttributes wattr, wrootattr;
1722 1946
1723 pchanged = 0; 1947 pchanged = 0;
1724 1948
1725 if (! (Options & Opt_transparent)) 1949 if (!(Options & Opt_transparent))
1726 return pchanged; /* Don't try any more */ 1950 return pchanged; /* Don't try any more */
1727 1951
1728 XGetWindowAttributes (display->display, display->root, &wrootattr); 1952 XGetWindowAttributes (display->display, display->root, &wrootattr);
1729 rootdepth = wrootattr.depth; 1953 rootdepth = wrootattr.depth;
1730 1954
1731 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 1955 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
1956
1732 if (rootdepth != wattr.depth) 1957 if (rootdepth != wattr.depth)
1733 { 1958 {
1734 if (am_transparent) 1959 if (am_transparent)
1735 { 1960 {
1736 pchanged = 1; 1961 pchanged = 1;
1737 XSetWindowBackground (display->display, TermWin.vt, 1962 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
1738 PixColors[Color_bg]);
1739 am_transparent = am_pixmap_trans = 0; 1963 am_transparent = am_pixmap_trans = 0;
1740 } 1964 }
1965
1741 return pchanged; /* Don't try any more */ 1966 return pchanged; /* Don't try any more */
1742 } 1967 }
1743 1968
1744 /* Get all X ops out of the queue so that our information is up-to-date. */ 1969 /* Get all X ops out of the queue so that our information is up-to-date. */
1745 XSync (display->display, False); 1970 XSync (display->display, False);
1747 /* 1972 /*
1748 * Make the frame window set by the window manager have 1973 * Make the frame window set by the window manager have
1749 * the root background. Some window managers put multiple nested frame 1974 * the root background. Some window managers put multiple nested frame
1750 * windows for each client, so we have to take care about that. 1975 * windows for each client, so we have to take care about that.
1751 */ 1976 */
1752 i = (xa[XA_XROOTPMAPID] != 0 1977 i = (xa[XA_XROOTPMAPID]
1753 && (XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 1978 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID],
1754 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1979 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1755 &nitems, &bytes_after, &prop) == Success)); 1980 &nitems, &bytes_after, &prop) == Success);
1981
1982 if (!i || prop == NULL)
1983 i = (xa[XA_XSETROOTID]
1984 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID],
1985 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1986 &nitems, &bytes_after, &prop) == Success);
1987
1756 if (!i || prop == NULL) 1988 if (!i || prop == NULL)
1757 have_pixmap = 0; 1989 have_pixmap = 0;
1758 else 1990 else
1759 { 1991 {
1760 have_pixmap = 1; 1992 have_pixmap = 1;
1761 rootpixmap = * ((Pixmap *)prop); 1993 rootpixmap = *(Pixmap *)prop;
1762 XFree (prop); 1994 XFree (prop);
1763 } 1995 }
1996
1764 if (have_pixmap) 1997 if (have_pixmap)
1765 { 1998 {
1766 /* 1999 /*
1767 * Copy display->root pixmap transparency 2000 * Copy display->root pixmap transparency
1768 */ 2001 */
1772 XImage *image; 2005 XImage *image;
1773 GC gc; 2006 GC gc;
1774 XGCValues gcvalue; 2007 XGCValues gcvalue;
1775 2008
1776 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2009 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
1777 0, 0, &sx, &sy, &cr); 2010 0, 0, &sx, &sy, &cr);
1778 nw = (unsigned int)szHint.width; 2011 nw = (unsigned int)szHint.width;
1779 nh = (unsigned int)szHint.height; 2012 nh = (unsigned int)szHint.height;
1780 nx = ny = 0; 2013 nx = ny = 0;
1781 2014
1782 if (sx < 0) 2015 if (sx < 0)
1794 } 2027 }
1795 2028
1796 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2029 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
1797 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2030 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
1798 allowedxerror = -1; 2031 allowedxerror = -1;
1799 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, 2032 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
1800 ZPixmap); 2033
1801 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2034 /* XXX: handle BadMatch - usually because we're outside the pixmap */
1802 /* XXX: may need a delay here? */ 2035 /* XXX: may need a delay here? */
1803 allowedxerror = 0; 2036 allowedxerror = 0;
2037
1804 if (image == NULL) 2038 if (image == NULL)
1805 { 2039 {
1806 if (am_transparent && am_pixmap_trans) 2040 if (am_transparent && am_pixmap_trans)
1807 { 2041 {
1808 pchanged = 1; 2042 pchanged = 1;
1810 { 2044 {
1811 XFreePixmap (display->display, TermWin.pixmap); 2045 XFreePixmap (display->display, TermWin.pixmap);
1812 TermWin.pixmap = None; 2046 TermWin.pixmap = None;
1813 } 2047 }
1814 } 2048 }
2049
1815 am_pixmap_trans = 0; 2050 am_pixmap_trans = 0;
1816 } 2051 }
1817 else 2052 else
1818 { 2053 {
1819 if (TermWin.pixmap != None) 2054 if (TermWin.pixmap != None)
1820 XFreePixmap (display->display, TermWin.pixmap); 2055 XFreePixmap (display->display, TermWin.pixmap);
2056
2057#if TINTING
2058 if (ISSET_PIXCOLOR (Color_tint))
2059 {
2060 unsigned short shade, rm, gm, bm;
2061
2062 PixColors[Color_tint].get (display, rm, gm, bm);
2063
2064 rm >>= 8; gm >>= 8; bm >>= 8; // not 100% correct, but...
2065
2066 /* Determine bitshift and bitmask values */
2067 switch (image->bits_per_pixel)
2068 {
2069 case 15: shade_ximage_15 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break;
2070 case 16: shade_ximage_16 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break;
2071 case 24: shade_ximage_24 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break;
2072 case 32: shade_ximage_32 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break;
2073 }
2074 }
2075#endif
2076
1821 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2077 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
1822 (unsigned int)szHint.width,
1823 (unsigned int)szHint.height, 2078 szHint.width, szHint.height, image->depth);
1824 (unsigned int)image->depth);
1825 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2079 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue);
1826 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2080 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0,
1827 nx, ny, (unsigned int)image->width,
1828 (unsigned int)image->height); 2081 nx, ny, image->width, image->height);
1829 XFreeGC (display->display, gc); 2082 XFreeGC (display->display, gc);
1830 XDestroyImage (image); 2083 XDestroyImage (image);
1831 XSetWindowBackgroundPixmap (display->display, TermWin.vt, 2084 XSetWindowBackgroundPixmap (display->display, TermWin.vt,
1832 TermWin.pixmap); 2085 TermWin.pixmap);
2086
1833 if (!am_transparent || !am_pixmap_trans) 2087 if (!am_transparent || !am_pixmap_trans)
1834 pchanged = 1; 2088 pchanged = 1;
2089
1835 am_transparent = am_pixmap_trans = 1; 2090 am_transparent = am_pixmap_trans = 1;
1836 } 2091 }
1837 } 2092 }
1838 2093
1839 if (!am_pixmap_trans) 2094 if (!am_pixmap_trans)
1840 { 2095 {
1841 unsigned int n; 2096 unsigned int n;
1842 /* 2097 /*
1843 * InheritPixmap transparency 2098 * InheritPixmap transparency
1844 */ 2099 */
1845 D_X ((stderr, "InheritPixmap Seeking to %08lx", display->root)); 2100 D_X ((stderr, "InheritPixmap Seeking to %08lx", display->root));
1846 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); 2101 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
1847 i++)
1848 { 2102 {
1849 oldp = TermWin.parent[i]; 2103 oldp = TermWin.parent[i];
1850 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2104 XQueryTree (display->display, TermWin.parent[i - 1], &root,
1851 &TermWin.parent[i], &list, &n); 2105 &TermWin.parent[i], &list, &n);
1852 XFree (list); 2106 XFree (list);
1853 D_X ((stderr, "InheritPixmap Parent[%d] = %08lx", i, TermWin.parent[i])); 2107 D_X ((stderr, "InheritPixmap Parent[%d] = %08lx", i, TermWin.parent[i]));
2108
1854 if (TermWin.parent[i] == display->root) 2109 if (TermWin.parent[i] == display->root)
1855 { 2110 {
1856 if (oldp != None) 2111 if (oldp != None)
1857 pchanged = 1; 2112 pchanged = 1;
2113
1858 break; 2114 break;
1859 } 2115 }
2116
1860 if (oldp != TermWin.parent[i]) 2117 if (oldp != TermWin.parent[i])
1861 pchanged = 1; 2118 pchanged = 1;
1862 } 2119 }
1863 2120
1864 n = 0; 2121 n = 0;
1875 break; 2132 break;
1876 } 2133 }
1877 } 2134 }
1878 } 2135 }
1879 2136
1880 if (n > (int) (sizeof (TermWin.parent) 2137 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
1881 / sizeof (TermWin.parent[0])))
1882 { 2138 {
1883 D_X ((stderr, "InheritPixmap Turning off")); 2139 D_X ((stderr, "InheritPixmap Turning off"));
1884 XSetWindowBackground (display->display, TermWin.parent[0], 2140 XSetWindowBackground (display->display, TermWin.parent[0], PixColors[Color_fg]);
1885 PixColors[Color_fg]);
1886 XSetWindowBackground (display->display, TermWin.vt, 2141 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
1887 PixColors[Color_bg]);
1888 am_transparent = 0; 2142 am_transparent = 0;
1889 /* XXX: also turn off Opt_transparent? */ 2143 /* XXX: also turn off Opt_transparent? */
1890 } 2144 }
1891 else 2145 else
1892 { 2146 {
2147#if WAIT_FOR_WM
1893 /* wait (an arbitrary period) for the WM to do its thing 2148 /* wait (an arbitrary period) for the WM to do its thing
1894 * needed for fvwm2.2.2 (and before?) */ 2149 * needed for fvwm2.2.2 (and before?) */
1895# ifdef HAVE_NANOSLEEP
1896 struct timespec rqt;
1897
1898 rqt.tv_sec = 1;
1899 rqt.tv_nsec = 0;
1900 nanosleep (&rqt, NULL);
1901# else
1902 sleep (1); 2150 sleep (1);
1903# endif 2151#endif
1904 D_X ((stderr, "InheritPixmap Turning on (%d parents)", i - 1)); 2152 D_X ((stderr, "InheritPixmap Turning on (%d parents)", i - 1));
1905 for (n = 0; n < (unsigned int)i; n++) 2153 for (n = 0; n < (unsigned int)i; n++)
1906 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], 2154 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative);
1907 ParentRelative); 2155
1908 XSetWindowBackgroundPixmap (display->display, TermWin.vt, 2156 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
1909 ParentRelative);
1910 am_transparent = 1; 2157 am_transparent = 1;
1911 } 2158 }
1912 2159
1913 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2160 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
1914 TermWin.parent[i] = None; 2161 TermWin.parent[i] = None;
1915 } 2162 }
2163
1916 return pchanged; 2164 return pchanged;
1917} 2165}
1918#endif 2166#endif
1919 2167
1920/*}}} */ 2168/*}}} */
1935 } 2183 }
1936 2184
1937 if (ch == NOCHAR) // TODO: improve 2185 if (ch == NOCHAR) // TODO: improve
1938 break; 2186 break;
1939 2187
1940 if (!IS_CONTROL (ch) || ch == '\t' || ch == '\n' || ch == '\r') 2188 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
1941 { 2189 {
1942 /* Read a text string from the input buffer */ 2190 /* Read a text string from the input buffer */
1943 unicode_t buf[UBUFSIZ]; 2191 unicode_t buf[UBUFSIZ];
1944 bool refreshnow = false; 2192 bool refreshnow = false;
1945 int nlines = 0; 2193 int nlines = 0;
1950 for (;;) 2198 for (;;)
1951 { 2199 {
1952 seq_begin = cmdbuf_ptr; 2200 seq_begin = cmdbuf_ptr;
1953 ch = next_char (); 2201 ch = next_char ();
1954 2202
1955 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != '\t' && ch != '\n' && ch != '\r')) 2203 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
1956 break; 2204 break;
1957 2205
1958 *str++ = ch; 2206 *str++ = ch;
1959 2207
1960 if (ch == '\n') 2208 if (ch == C0_LF)
1961 { 2209 {
1962 nlines++; 2210 nlines++;
1963 refresh_count++; 2211 refresh_count++;
1964 2212
1965 if (! (Options & Opt_jumpScroll) 2213 if (! (Options & Opt_jumpScroll)
2000 */ 2248 */
2001 if (refreshnow) 2249 if (refreshnow)
2002 { 2250 {
2003 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2251 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2004 refresh_limit++; 2252 refresh_limit++;
2005 2253 else
2006 scr_refresh (refresh_type); 2254 scr_refresh (refresh_type);
2007 } 2255 }
2008 2256
2009 } 2257 }
2010 else 2258 else
2011 { 2259 {
2156/*}}} */ 2404/*}}} */
2157 2405
2158/* *INDENT-OFF* */ 2406/* *INDENT-OFF* */
2159enum { 2407enum {
2160 C1_40 = 0x40, 2408 C1_40 = 0x40,
2161 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, 2409 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2162 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, 2410 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2163 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, 2411 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2164 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC 2412 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2165}; 2413};
2166/* *INDENT-ON* */ 2414/* *INDENT-ON* */
2167 2415
2168/*{{{ process non-printing single characters */ 2416/*{{{ process non-printing single characters */
2169void 2417void
2174 case C0_ESC: 2422 case C0_ESC:
2175 process_escape_seq (); 2423 process_escape_seq ();
2176 break; 2424 break;
2177 case C0_ENQ: /* terminal Status */ 2425 case C0_ENQ: /* terminal Status */
2178 if (rs[Rs_answerbackstring]) 2426 if (rs[Rs_answerbackstring])
2179 tt_write (
2180 (const unsigned char *)rs[Rs_answerbackstring], 2427 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2181 (unsigned int)STRLEN (rs[Rs_answerbackstring])); 2428 (unsigned int)STRLEN (rs[Rs_answerbackstring]));
2182 else 2429 else
2183 tt_write ((unsigned char *)VT100_ANS, 2430 tt_write ((unsigned char *)VT100_ANS,
2184 (unsigned int)STRLEN (VT100_ANS)); 2431 (unsigned int)STRLEN (VT100_ANS));
2185 break; 2432 break;
2186 case C0_BEL: /* bell */ 2433 case C0_BEL: /* bell */
2187 scr_bell (); 2434 scr_bell ();
2188 break; 2435 break;
2189 case C0_BS: /* backspace */ 2436 case C0_BS: /* backspace */
2342 break; 2589 break;
2343 2590
2344 /* 8.3.87: NEXT LINE */ 2591 /* 8.3.87: NEXT LINE */
2345 case C1_NEL: /* ESC E */ 2592 case C1_NEL: /* ESC E */
2346 { 2593 {
2347 unicode_t nlcr[] = { L'\n', L'\r' }; 2594 unicode_t nlcr[] = { C0_LF, C0_CR };
2348 scr_add_lines (nlcr, 1, 2); 2595 scr_add_lines (nlcr, 1, 2);
2349 } 2596 }
2350 break; 2597 break;
2351 2598
2352 /* kidnapped escape sequence: Should be 8.3.48 */ 2599 /* kidnapped escape sequence: Should be 8.3.48 */
2363 case C1_RI: /* ESC M */ 2610 case C1_RI: /* ESC M */
2364 scr_index (DN); 2611 scr_index (DN);
2365 break; 2612 break;
2366 2613
2367 /* 8.3.142: SINGLE-SHIFT TWO */ 2614 /* 8.3.142: SINGLE-SHIFT TWO */
2368 /*case C1_SS2: scr_single_shift (2); break; */ 2615 /*case C1_SS2: scr_single_shift (2); break; */
2369 2616
2370 /* 8.3.143: SINGLE-SHIFT THREE */ 2617 /* 8.3.143: SINGLE-SHIFT THREE */
2371 /*case C1_SS3: scr_single_shift (3); break; */ 2618 /*case C1_SS3: scr_single_shift (3); break; */
2372 2619
2373 /* 8.3.27: DEVICE CONTROL STRING */ 2620 /* 8.3.27: DEVICE CONTROL STRING */
2374 case C1_DCS: /* ESC P */ 2621 case C1_DCS: /* ESC P */
2375 process_dcs_seq (); 2622 process_dcs_seq ();
2376 break; 2623 break;
2391 process_osc_seq (); 2638 process_osc_seq ();
2392 break; 2639 break;
2393 2640
2394 /* 8.3.106: RESET TO INITIAL STATE */ 2641 /* 8.3.106: RESET TO INITIAL STATE */
2395 case 'c': 2642 case 'c':
2643 mbstate.reset ();
2396 scr_poweron (); 2644 scr_poweron ();
2397 scrollbar_show (1); 2645 scrollbar_show (1);
2398 break; 2646 break;
2399 2647
2400 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2648 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
2412 2660
2413/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ 2661/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
2414/* *INDENT-OFF* */ 2662/* *INDENT-OFF* */
2415enum { 2663enum {
2416 CSI_ICH = 0x40, 2664 CSI_ICH = 0x40,
2417 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, 2665 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
2418 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , 2666 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
2419 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, 2667 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
2420 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F, 2668 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
2421 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC, 2669 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
2422 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ, 2670 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
2437 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */ 2685 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
2438 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */ 2686 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
2439 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ 2687 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
2440 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ 2688 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
2441 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ 2689 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
2442 make_byte (0,0,0,0,0,0,0,0) /* x, y, z, {, |, }, ~, */ 2690 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
2443 }; 2691 };
2444/* *INDENT-ON* */ 2692/* *INDENT-ON* */
2445 2693
2446void 2694void
2447rxvt_term::process_csi_seq () 2695rxvt_term::process_csi_seq ()
2646 tt_printf ("\033[0n"); 2894 tt_printf ("\033[0n");
2647 break; 2895 break;
2648 case 6: /* CPR requested */ 2896 case 6: /* CPR requested */
2649 scr_report_position (); 2897 scr_report_position ();
2650 break; 2898 break;
2651#if defined (ENABLE_DISPLAY_ANSWER)
2652 case 7: /* unofficial extension */ 2899 case 7: /* unofficial extension */
2900 if (Options & Opt_insecure)
2653 tt_printf ("%-.250s\n", rs[Rs_display_name]); 2901 tt_printf ("%-.250s\n", rs[Rs_display_name]);
2654 break; 2902 break;
2655#endif
2656 case 8: /* unofficial extension */ 2903 case 8: /* unofficial extension */
2657 xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2904 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
2658 break; 2905 break;
2659 } 2906 }
2660 break; 2907 break;
2661 2908
2662 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */ 2909 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
2800 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3047 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
2801 break; 3048 break;
2802 case 13: /* report window position */ 3049 case 13: /* report window position */
2803 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3050 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2804 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3051 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root,
2805 -wattr.border_width, -wattr.border_width, 3052 -wattr.border_width, -wattr.border_width,
2806 &x, &y, &wdummy); 3053 &x, &y, &wdummy);
2807 tt_printf ("\033[3;%d;%dt", x, y); 3054 tt_printf ("\033[3;%d;%dt", x, y);
2808 break; 3055 break;
2809 case 14: /* report window size (pixels) */ 3056 case 14: /* report window size (pixels) */
2810 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3057 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr);
2811 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3058 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
2814 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3061 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
2815 break; 3062 break;
2816 case 19: /* report window size (chars) */ 3063 case 19: /* report window size (chars) */
2817 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3064 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
2818 break; 3065 break;
2819#if 0 /* XXX: currently disabled due to security concerns */
2820 case 20: /* report icon label */ 3066 case 20: /* report icon label */
3067 if (Options & Opt_insecure)
3068 {
3069 char *s;
2821 XGetIconName (display->display, TermWin.parent[0], &s); 3070 XGetIconName (display->display, TermWin.parent[0], &s);
2822 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ 3071 tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */
3072 }
2823 break; 3073 break;
2824 case 21: /* report window title */ 3074 case 21: /* report window title */
3075 if (Options & Opt_insecure)
3076 {
3077 char *s;
2825 XFetchName (display->display, TermWin.parent[0], &s); 3078 XFetchName (display->display, TermWin.parent[0], &s);
2826 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ 3079 tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */
3080 }
2827 break; 3081 break;
2828#endif
2829 } 3082 }
2830} 3083}
2831#endif 3084#endif
2832 3085
2833/*----------------------------------------------------------------------*/ 3086/*----------------------------------------------------------------------*/
2834/* 3087/*
2835 * get input up until STRING TERMINATOR (or BEL) 3088 * get input up until STRING TERMINATOR (or BEL)
2836 * ends_how is terminator used. returned input must be free ()d 3089 * ends_how is terminator used. returned input must be free()'d
2837 */ 3090 */
2838unsigned char * 3091unsigned char *
2839rxvt_term::get_to_st (unicode_t &ends_how) 3092rxvt_term::get_to_st (unicode_t &ends_how)
2840{ 3093{
2841 int seen_esc = 0; /* seen escape? */ 3094 int seen_esc = 0; /* seen escape? */
2844 unicode_t ch; 3097 unicode_t ch;
2845 unsigned char string[STRING_MAX]; 3098 unsigned char string[STRING_MAX];
2846 3099
2847 while ((ch = cmd_getc ())) 3100 while ((ch = cmd_getc ()))
2848 { 3101 {
2849 if (ch == C0_BEL 3102 if (ch == C0_BEL || ch == CHAR_ST)
2850 || ch == CHAR_ST 3103 break;
3104
3105 if (seen_esc)
2851 || (ch == 0x5c && seen_esc)) /* 7bit ST */ 3106 if (ch == 0x5c) /* 7bit ST */
2852 break; 3107 break;
3108 else
3109 return NULL;
2853 3110
2854 if (ch == C0_ESC) 3111 if (ch == C0_ESC)
2855 { 3112 {
2856 seen_esc = 1; 3113 seen_esc = 1;
2857 continue; 3114 continue;
2858 } 3115 }
2859 else if (ch == '\t') 3116 else if (ch == C0_HT)
2860 ch = ' '; /* translate '\t' to space */ 3117 ch = ' '; /* translate '\t' to space */
2861 else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) 3118 else if (ch < 0x20 && (ch != C0_LF && ch != C0_CR))
2862 return NULL; /* other control character - exit */ 3119 return NULL; /* other control character - exit */
2863 3120
2864 if (n < sizeof (string) - 1) 3121 if (n >= sizeof (string) - 1)
3122 // stop at some sane length
3123 return NULL;
3124
2865 string[n++] = ch; 3125 string[n++] = ch;
2866
2867 seen_esc = 0; 3126 seen_esc = 0;
2868 } 3127 }
2869 3128
2870 string[n++] = '\0'; 3129 string[n++] = '\0';
2871 3130
2915 { 3174 {
2916 unsigned char *s = get_to_st (eh); 3175 unsigned char *s = get_to_st (eh);
2917 3176
2918 if (s) 3177 if (s)
2919 { 3178 {
2920 /*
2921 * rxvt_menubar_dispatch () violates the constness of the string,
2922 * so do it here
2923 */
2924 if (arg == XTerm_Menu)
2925#if 0 /* XXX: currently disabled due to security concerns */
2926 menubar_dispatch ((char *)s);
2927#else
2928 (void)0;
2929#endif
2930 else
2931 xterm_seq (arg, (char *)s, eh); 3179 process_xterm_seq (arg, (char *)s, eh);
2932
2933 free (s); 3180 free (s);
2934 } 3181 }
2935 } 3182 }
2936} 3183}
3184
3185void
3186rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3187{
3188 if (str[0] == '?' && !str[1])
3189 {
3190 if (Options & Opt_insecure)
3191 {
3192 unsigned short r, g, b;
3193 PixColors[color].get (display, r, g, b);
3194 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3195 }
3196 }
3197 else
3198 set_window_color (color, str);
3199}
3200
2937/* 3201/*
2938 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3202 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
2939 * 0 = change iconName/title 3203 * 0 = change iconName/title
2940 * 1 = change iconName 3204 * 1 = change iconName
2941 * 2 = change title 3205 * 2 = change title
2942 * 4 = change color 3206 * 4 = change color
3207 * 10 = change fg color
3208 * 11 = change bg color
2943 * 12 = change text color 3209 * 12 = change text color
2944 * 13 = change mouse foreground color 3210 * 13 = change mouse foreground color
2945 * 17 = change highlight character colour 3211 * 17 = change highlight character colour
2946 * 18 = change bold character color 3212 * 18 = change bold character color
2947 * 19 = change underlined character color 3213 * 19 = change underlined character color
2948 * 46 = change logfile (not implemented) 3214 * 46 = change logfile (not implemented)
2949 * 50 = change font 3215 * 50 = change font
2950 * 3216 *
2951 * rxvt extensions: 3217 * rxvt extensions:
2952 * 10 = menu (may change in future)
2953 * 20 = bg pixmap 3218 * 20 = bg pixmap
2954 * 39 = change default fg color 3219 * 39 = change default fg color
2955 * 49 = change default bg color 3220 * 49 = change default bg color
2956 * 55 = dump scrollback buffer and all of screen 3221 * 55 = dump scrollback buffer and all of screen
2957 * 701 = change locale 3222 * 701 = change locale
2958 * 702 = find font 3223 * 702 = find font
3224 * 703 = menu
2959 */ 3225 */
2960void 3226void
2961rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) 3227rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
2962{ 3228{
2963 int changed = 0; 3229 int changed = 0;
2964 int color; 3230 int color;
2965 char *buf, *name; 3231 char *buf, *name;
3232 bool query = str[0] == '?' && !str[1];
2966 3233
2967 assert (str != NULL); 3234 assert (str != NULL);
2968 switch (op) 3235 switch (op)
2969 { 3236 {
2970 case XTerm_name: 3237 case XTerm_name:
2974 set_icon_name (str); 3241 set_icon_name (str);
2975 break; 3242 break;
2976 case XTerm_title: 3243 case XTerm_title:
2977 set_title (str); 3244 set_title (str);
2978 break; 3245 break;
3246 case XTerm_property:
3247 if (str[0] == '?')
3248 {
3249 Atom prop = XInternAtom (display->display, str + 1, True);
3250 Atom actual_type;
3251 int actual_format;
3252 unsigned long nitems;
3253 unsigned long bytes_after;
3254 unsigned char *value = 0;
3255 const char *str = "";
3256
3257 if (prop
3258 && XGetWindowProperty (display->display, TermWin.parent[0],
3259 prop, 0, 1<<16, 0, AnyPropertyType,
3260 &actual_type, &actual_format,
3261 &nitems, &bytes_after, &value) == Success
3262 && actual_type != None
3263 && actual_format == 8)
3264 str = (const char *)(value);
3265
3266 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3267
3268 XFree (value);
3269 }
3270 else
3271 {
3272 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3273
3274 if (eq)
3275 {
3276 *eq = 0;
3277 XChangeProperty (display->display, TermWin.parent[0],
3278 display->atom (str), XA_STRING, 8,
3279 PropModeReplace, (unsigned char *)eq + 1,
3280 strlen (eq + 1));
3281 }
3282 else
3283 XDeleteProperty (display->display, TermWin.parent[0],
3284 display->atom (str));
3285 }
3286 break;
3287
2979 case XTerm_Color: 3288 case XTerm_Color:
2980 for (buf = (char *)str; buf && *buf;) 3289 for (buf = (char *)str; buf && *buf;)
2981 { 3290 {
2982 if ((name = STRCHR (buf, ';')) == NULL) 3291 if ((name = STRCHR (buf, ';')) == NULL)
2983 break; 3292 break;
2989 break; 3298 break;
2990 3299
2991 if ((buf = STRCHR (name, ';')) != NULL) 3300 if ((buf = STRCHR (name, ';')) != NULL)
2992 *buf++ = '\0'; 3301 *buf++ = '\0';
2993 3302
3303 if (name[0] == '?' && !name[1])
3304 {
3305 if (Options & Opt_insecure)
3306 {
3307 unsigned short r, g, b;
3308 PixColors[color + minCOLOR].get (display, r, g, b);
3309 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3310 }
3311 }
3312 else
2994 set_window_color (color + minCOLOR, name); 3313 set_window_color (color + minCOLOR, name);
2995 } 3314 }
3315 break;
3316 case XTerm_Color00:
3317 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3318 break;
3319 case XTerm_Color01:
3320 process_color_seq (XTerm_Color00, Color_bg, str, resp);
2996 break; 3321 break;
2997#ifndef NO_CURSORCOLOR 3322#ifndef NO_CURSORCOLOR
2998 case XTerm_Color_cursor: 3323 case XTerm_Color_cursor:
2999 set_window_color (Color_cursor, str); 3324 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3000 break; 3325 break;
3001#endif 3326#endif
3002 case XTerm_Color_pointer: 3327 case XTerm_Color_pointer_fg:
3003 set_window_color (Color_pointer, str); 3328 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3329 break;
3330 case XTerm_Color_pointer_bg:
3331 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3004 break; 3332 break;
3005#ifndef NO_BOLD_UNDERLINE_REVERSE 3333#ifndef NO_BOLD_UNDERLINE_REVERSE
3006 case XTerm_Color_BD: 3334 case XTerm_Color_BD:
3007 set_window_color (Color_BD, str); 3335 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3008 break; 3336 break;
3009 case XTerm_Color_UL: 3337 case XTerm_Color_UL:
3010 set_window_color (Color_UL, str); 3338 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3011 break; 3339 break;
3012 case XTerm_Color_RV: 3340 case XTerm_Color_RV:
3013 set_window_color (Color_RV, str); 3341 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3014 break; 3342 break;
3015#endif 3343#endif
3016 3344
3017 case XTerm_Menu:
3018 /*
3019 * rxvt_menubar_dispatch () violates the constness of the string,
3020 * so DON'T do it here
3021 */
3022 break;
3023 case XTerm_Pixmap: 3345 case XTerm_Pixmap:
3024 if (*str != ';') 3346 if (*str != ';')
3025 { 3347 {
3026#if XPM_BACKGROUND 3348#if XPM_BACKGROUND
3027 scale_pixmap (""); /* reset to default scaling */ 3349 scale_pixmap (""); /* reset to default scaling */
3050 set_window_color (Color_fg, str); 3372 set_window_color (Color_fg, str);
3051 break; 3373 break;
3052 case XTerm_restoreBG: 3374 case XTerm_restoreBG:
3053 set_window_color (Color_bg, str); 3375 set_window_color (Color_bg, str);
3054 break; 3376 break;
3377
3055 case XTerm_logfile: 3378 case XTerm_logfile:
3056 // TODO, when secure mode? 3379 // TODO, when secure mode?
3057 break; 3380 break;
3381
3058 case XTerm_font: 3382 case XTerm_font:
3383 if (query)
3384 {
3385 if (Options & Opt_insecure)
3386 tt_printf ("\33]%d;%-.250s%c", XTerm_font,
3387 TermWin.fontset->fontdesc
3388 ? TermWin.fontset->fontdesc
3389 : "",
3390 resp);
3391 }
3392 else
3059 change_font (str); 3393 change_font (str);
3060 break; 3394 break;
3395
3061#ifndef NO_FRILLS 3396#ifndef NO_FRILLS
3062 case XTerm_locale: 3397 case XTerm_locale:
3063 if (str[0] == '?' && !str[1]) 3398 if (query)
3064 tt_printf ("%-.250s\n", locale); 3399 {
3400 if (Options & Opt_insecure)
3401 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, locale, resp);
3402 }
3065 else 3403 else
3066 { 3404 {
3067 set_locale (str); 3405 set_locale (str);
3068# ifdef USE_XIM 3406# ifdef USE_XIM
3069 im_cb (); 3407 im_cb ();
3070# endif 3408# endif
3071 } 3409 }
3072 break; 3410 break;
3411
3073 case XTerm_findfont: 3412 case XTerm_findfont:
3413 if (Options & Opt_insecure)
3074 { 3414 {
3075 int fid = TermWin.fontset->find_font (atoi (str)); 3415 int fid = TermWin.fontset->find_font (atoi (str));
3076 tt_printf ("%d %-.250s\n", fid, (*TermWin.fontset)[fid]->name); 3416 tt_printf ("\33]%d;%d;%-.250s%c", XTerm_findfont,
3417 fid, (*TermWin.fontset)[fid]->name, resp);
3077 } 3418 }
3419 break;
3420#endif
3421
3422#ifdef MENUBAR
3423 case XTerm_Menu:
3424 if (Options & Opt_insecure)
3425 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3078 break; 3426 break;
3079#endif 3427#endif
3080#if 0 3428#if 0
3081 case XTerm_dumpscreen: /* no error notices */ 3429 case XTerm_dumpscreen: /* no error notices */
3082 { 3430 {
3083 int fd; 3431 int fd;
3084 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3432 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3085 { 3433 {
3086 scr_dump (fd); 3434 scr_dump (fd);
3087 close (fd); 3435 close (fd);
3088 } 3436 }
3175 // 1035 enable modifiers for alt, numlock NYI 3523 // 1035 enable modifiers for alt, numlock NYI
3176 // 1036 send ESC for meta keys NYI 3524 // 1036 send ESC for meta keys NYI
3177 // 1037 send DEL for keypad delete NYI 3525 // 1037 send DEL for keypad delete NYI
3178 { 1047, PrivMode_Screen }, 3526 { 1047, PrivMode_Screen },
3179 // 1048 save and restore cursor 3527 // 1048 save and restore cursor
3180 { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */ 3528 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3181 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3529 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3182 }; 3530 };
3183 3531
3184 if (nargs == 0) 3532 if (nargs == 0)
3185 return; 3533 return;
3204 3552
3205 /* extra handling for values with state unkept */ 3553 /* extra handling for values with state unkept */
3206 switch (arg[i]) 3554 switch (arg[i])
3207 { 3555 {
3208 case 1048: /* alternative cursor save */ 3556 case 1048: /* alternative cursor save */
3209 case 1049: 3557 if (Options & Opt_secondaryScreen)
3210 if (mode == 0) 3558 if (mode == 0)
3211 scr_cursor (RESTORE); 3559 scr_cursor (RESTORE);
3212 else if (mode == 1) 3560 else if (mode == 1)
3213 scr_cursor (SAVE); 3561 scr_cursor (SAVE);
3214 /* FALLTHROUGH */ 3562 break;
3215 } 3563 }
3216 3564
3217 if (state >= 0) 3565 if (state >= 0)
3218 /* extra handling for values with valid 0 or 1 state */ 3566 /* extra handling for values with valid 0 or 1 state */
3219 switch (arg[i]) 3567 switch (arg[i])
3243 scr_relative_origin (state); 3591 scr_relative_origin (state);
3244 break; 3592 break;
3245 case 7: /* autowrap */ 3593 case 7: /* autowrap */
3246 scr_autowrap (state); 3594 scr_autowrap (state);
3247 break; 3595 break;
3248 /* case 8: - auto repeat, can't do on a per window basis */ 3596 /* case 8: - auto repeat, can't do on a per window basis */
3249 case 9: /* X10 mouse reporting */ 3597 case 9: /* X10 mouse reporting */
3250 if (state) /* orthogonal */ 3598 if (state) /* orthogonal */
3251 PrivateModes &= ~PrivMode_MouseX11; 3599 PrivateModes &= ~PrivMode_MouseX11;
3252 break; 3600 break;
3253#ifdef menuBar_esc 3601#ifdef menuBar_esc
3267 break; 3615 break;
3268#endif 3616#endif
3269 case 25: /* visible/invisible cursor */ 3617 case 25: /* visible/invisible cursor */
3270 scr_cursor_visible (state); 3618 scr_cursor_visible (state);
3271 break; 3619 break;
3272 /* case 35: - shift keys */ 3620 /* case 35: - shift keys */
3273 /* case 40: - 80 <--> 132 mode */ 3621 /* case 40: - 80 <--> 132 mode */
3274 case 47: /* secondary screen */ 3622 case 47: /* secondary screen */
3275 scr_change_screen (state); 3623 scr_change_screen (state);
3276 break; 3624 break;
3277 /* case 66: - application key pad */ 3625 /* case 66: - application key pad */
3278 /* case 67: - backspace key */ 3626 /* case 67: - backspace key */
3279 case 1000: /* X11 mouse reporting */ 3627 case 1000: /* X11 mouse reporting */
3280 if (state) /* orthogonal */ 3628 if (state) /* orthogonal */
3281 PrivateModes &= ~PrivMode_MouseX10; 3629 PrivateModes &= ~PrivMode_MouseX10;
3282 break; 3630 break;
3283#if 0 3631#if 0
3294 if (state) 3642 if (state)
3295 Options |= Opt_scrollTtyKeypress; 3643 Options |= Opt_scrollTtyKeypress;
3296 else 3644 else
3297 Options &= ~Opt_scrollTtyKeypress; 3645 Options &= ~Opt_scrollTtyKeypress;
3298 break; 3646 break;
3299 case 1047: /* secondary screen w/ clearing */ 3647 case 1047: /* secondary screen w/ clearing last */
3300 case 1049: /* better secondary screen w/ clearing, but not fully implemented */ 3648 if (Options & Opt_secondaryScreen)
3301 if (current_screen != PRIMARY) 3649 if (current_screen != PRIMARY)
3302 scr_erase_screen (2); 3650 scr_erase_screen (2);
3303
3304 scr_change_screen (state); 3651 scr_change_screen (state);
3305 /* FALLTHROUGH */ 3652 break;
3653 case 1049: /* secondary screen w/ clearing first */
3654 scr_change_screen (state);
3655 if (Options & Opt_secondaryScreen)
3656 if (current_screen != PRIMARY)
3657 scr_erase_screen (2);
3658 break;
3306 default: 3659 default:
3307 break; 3660 break;
3308 } 3661 }
3309 } 3662 }
3310} 3663}
3339 rendset = 1, rendstyle = RS_Uline; 3692 rendset = 1, rendstyle = RS_Uline;
3340 break; 3693 break;
3341 case 5: 3694 case 5:
3342 rendset = 1, rendstyle = RS_Blink; 3695 rendset = 1, rendstyle = RS_Blink;
3343 break; 3696 break;
3697 //case 6: // scoansi light background
3344 case 7: 3698 case 7:
3345 rendset = 1, rendstyle = RS_RVid; 3699 rendset = 1, rendstyle = RS_RVid;
3346 break; 3700 break;
3347 case 8: 3701 case 8:
3348 // invisible. NYI 3702 // invisible. NYI
3703 break;
3704 //case 10: // scoansi acs off
3705 //case 11: // scoansi acs on
3706 //case 12: // scoansi acs on, |0x80
3707 case 21: // disable bold, blink and invis (some terminals use this)
3708 rendset = 0, rendstyle = RS_Bold | RS_Blink;
3349 break; 3709 break;
3350 case 22: 3710 case 22:
3351 rendset = 0, rendstyle = RS_Bold; 3711 rendset = 0, rendstyle = RS_Bold;
3352 break; 3712 break;
3353 case 24: 3713 case 24:
3446 } 3806 }
3447 } 3807 }
3448} 3808}
3449/*}}} */ 3809/*}}} */
3450 3810
3451/*{{{ process Rob Nation's own graphics mode sequences */ 3811/*{{{ (do not) process Rob Nation's own graphics mode sequences */
3452void 3812void
3453rxvt_term::process_graphics () 3813rxvt_term::process_graphics ()
3454{ 3814{
3455 unicode_t ch, cmd = cmd_getc (); 3815 unicode_t ch, cmd = cmd_getc ();
3456 3816

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines