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

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.78 by root, Thu Jan 19 20:30:36 2006 UTC vs.
Revision 1.79 by root, Fri Jan 20 10:27:08 2006 UTC

50#undef LINENO 50#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 52#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
54 54
55#define ENABLE_PERL_FRILLS 1 55typedef int CHAINED UNUSED;
56 56
57///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
58 58
59static wchar_t * 59static wchar_t *
60sv2wcs (SV *sv) 60sv2wcs (SV *sv)
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
120 120
121///////////////////////////////////////////////////////////////////////////// 121/////////////////////////////////////////////////////////////////////////////
122 122
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124
123struct perl_watcher 125struct perl_watcher
124{ 126{
125 SV *cbsv; 127 SV *cbsv;
126 HV *self; 128 HV *self;
127 129
128 perl_watcher () 130 perl_watcher ()
129 : cbsv (newSV (0)) 131 : cbsv (0)
130 { 132 {
131 } 133 }
132 134
133 ~perl_watcher () 135 ~perl_watcher ()
134 { 136 {
135 SvREFCNT_dec (cbsv); 137 SvREFCNT_dec (cbsv);
136 } 138 }
137 139
138 void cb (SV *cb) 140 void cb (SV *cb)
139 { 141 {
140 sv_setsv (cbsv, cb); 142 SvREFCNT_dec (cbsv);
143 cbsv = newSVsv (cb);
141 } 144 }
142 145
143 void invoke (const char *type, SV *self, int arg = -1); 146 void invoke (const char *type, SV *self, int arg = -1);
144}; 147};
145 148
169 if (SvTRUE (ERRSV)) 172 if (SvTRUE (ERRSV))
170 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
171} 174}
172 175
173#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
174#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer")
175 178
176struct timer : time_watcher, perl_watcher 179struct timer : perl_watcher, time_watcher
177{ 180{
178 tstamp interval; 181 tstamp interval;
179 182
180 timer () 183 timer ()
181 : time_watcher (this, &timer::execute) 184 : time_watcher (this, &timer::execute)
190 invoke ("urxvt::timer", newSVtimer (this)); 193 invoke ("urxvt::timer", newSVtimer (this));
191 } 194 }
192}; 195};
193 196
194#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 197#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
195#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") 198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow")
196 199
197struct iow : io_watcher, perl_watcher 200struct iow : perl_watcher, io_watcher
198{ 201{
199 iow () 202 iow ()
200 : io_watcher (this, &iow::execute) 203 : io_watcher (this, &iow::execute)
201 { 204 {
202 } 205 }
203 206
204 void execute (io_watcher &w, short revents) 207 void execute (io_watcher &w, short revents)
205 { 208 {
206 invoke ("urxvt::iow", newSViow (this), revents); 209 invoke ("urxvt::iow", newSViow (this), revents);
210 }
211};
212
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw")
215
216struct iw : perl_watcher, idle_watcher
217{
218 iw ()
219 : idle_watcher (this, &iw::execute)
220 {
221 }
222
223 void execute (idle_watcher &w)
224 {
225 invoke ("urxvt::iw", newSViw (this));
226 }
227};
228
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw")
231
232struct pw : perl_watcher, child_watcher
233{
234 pw ()
235 : child_watcher (this, &pw::execute)
236 {
237 }
238
239 void execute (child_watcher &w, int status)
240 {
241 invoke ("urxvt::pw", newSVpw (this), status);
207 } 242 }
208}; 243};
209 244
210///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
211 246
913 RETVAL 948 RETVAL
914 949
915void 950void
916rxvt_term::destroy () 951rxvt_term::destroy ()
917 952
918#if ENABLE_PERL_FRILLS
919
920void
921rxvt_term::XListProperties (U32 window)
922 PPCODE:
923{
924 int count;
925 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
926
927 EXTEND (SP, count);
928 while (count--)
929 PUSHs (newSVuv ((U32)props [count]));
930
931 XFree (props);
932}
933
934void
935rxvt_term::XGetWindowProperty (U32 window, U32 property)
936 PPCODE:
937{
938 Atom type;
939 int format;
940 unsigned long nitems;
941 unsigned long bytes_after;
942 unsigned char *prop;
943 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
944 0, 1<<30, 0, AnyPropertyType,
945 &type, &format, &nitems, &bytes_after, &prop);
946 if (type != None)
947 {
948 EXTEND (SP, 3);
949 PUSHs (newSVuv ((U32)type));
950 PUSHs (newSViv (format));
951 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
952 XFree (prop);
953 }
954}
955
956void
957rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
958 CODE:
959{
960 STRLEN len;
961 char *data_ = SvPVbyte (data, len);
962
963 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
964 type, format, PropModeReplace,
965 (unsigned char *)data, len * 8 / format);
966}
967
968void
969rxvt_term::XDeleteProperty (U32 window, U32 property)
970 CODE:
971 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
972
973U32
974rxvt_term::DefaultRootWindow ()
975 CODE:
976 RETVAL = (U32)THIS->display->root;
977 OUTPUT:
978 RETVAL
979
980U32
981rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
982 CODE:
983 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
984 x, y, width, height, 0,
985 THIS->pix_colors_focused[Color_border],
986 THIS->pix_colors_focused[Color_border]);
987 OUTPUT:
988 RETVAL
989
990void
991rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
992 CODE:
993 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
994
995void
996rxvt_term::XMapWindow (U32 window)
997 CODE:
998 XMapWindow (THIS->display->display, (Window)window);
999
1000void
1001rxvt_term::XUnmapWindow (U32 window)
1002 CODE:
1003 XUnmapWindow (THIS->display->display, (Window)window);
1004
1005#endif
1006
1007void 953void
1008rxvt_term::set_should_invoke (int htype, int inc) 954rxvt_term::set_should_invoke (int htype, int inc)
1009 CODE: 955 CODE:
1010 THIS->perl.should_invoke [htype] += inc; 956 THIS->perl.should_invoke [htype] += inc;
1011 957
1015 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 961 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
1016 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 962 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1017 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 963 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1018 964
1019bool 965bool
1020rxvt_term::grab (U32 eventtime, int sync = 0) 966rxvt_term::grab (Time eventtime, int sync = 0)
1021 CODE: 967 CODE:
1022{ 968{
1023 int mode = sync ? GrabModeSync : GrabModeAsync; 969 int mode = sync ? GrabModeSync : GrabModeAsync;
1024 970
1025 THIS->perl.grabtime = 0; 971 THIS->perl.grabtime = 0;
1200 if (events != EVENT_UNDEF) 1146 if (events != EVENT_UNDEF)
1201 THIS->pty_ev.set (events); 1147 THIS->pty_ev.set (events);
1202 OUTPUT: 1148 OUTPUT:
1203 RETVAL 1149 RETVAL
1204 1150
1205U32 1151Window
1206rxvt_term::parent () 1152rxvt_term::parent ()
1207 CODE: 1153 CODE:
1208 RETVAL = (U32)THIS->parent [0]; 1154 RETVAL = THIS->parent [0];
1209 OUTPUT: 1155 OUTPUT:
1210 RETVAL 1156 RETVAL
1211 1157
1212U32 1158Window
1213rxvt_term::vt () 1159rxvt_term::vt ()
1214 CODE: 1160 CODE:
1215 RETVAL = (U32)THIS->vt; 1161 RETVAL = THIS->vt;
1216 OUTPUT: 1162 OUTPUT:
1217 RETVAL 1163 RETVAL
1218 1164
1219void 1165void
1220rxvt_term::vt_emask_add (U32 emask) 1166rxvt_term::vt_emask_add (U32 emask)
1576 1522
1577#void 1523#void
1578#rxvt_term::selection_clear () 1524#rxvt_term::selection_clear ()
1579 1525
1580void 1526void
1581rxvt_term::selection_make (U32 eventtime, bool rect = false) 1527rxvt_term::selection_make (Time eventtime, bool rect = false)
1582 CODE: 1528 CODE:
1583 THIS->selection.op = SELECTION_CONT; 1529 THIS->selection.op = SELECTION_CONT;
1584 THIS->selection.rect = rect; 1530 THIS->selection.rect = rect;
1585 THIS->selection_make (eventtime); 1531 THIS->selection_make (eventtime);
1586 1532
1587int 1533int
1588rxvt_term::selection_grab (U32 eventtime) 1534rxvt_term::selection_grab (Time eventtime)
1589 1535
1590void 1536void
1591rxvt_term::selection (SV *newtext = 0) 1537rxvt_term::selection (SV *newtext = 0)
1592 PPCODE: 1538 PPCODE:
1593{ 1539{
1661 o->self = (HV *)SvRV (RETVAL); 1607 o->self = (HV *)SvRV (RETVAL);
1662} 1608}
1663 OUTPUT: 1609 OUTPUT:
1664 RETVAL 1610 RETVAL
1665 1611
1612#############################################################################
1613# Various X Utility Functions
1614#############################################################################
1615
1616void
1617rxvt_term::XListProperties (Window window)
1618 PPCODE:
1619{
1620 int count;
1621 Atom *props = XListProperties (THIS->display->display, window, &count);
1622
1623 EXTEND (SP, count);
1624 while (count--)
1625 PUSHs (newSVuv ((U32)props [count]));
1626
1627 XFree (props);
1628}
1629
1630void
1631rxvt_term::XGetWindowProperty (Window window, Atom property)
1632 PPCODE:
1633{
1634 Atom type;
1635 int format;
1636 unsigned long nitems;
1637 unsigned long bytes_after;
1638 unsigned char *prop;
1639 XGetWindowProperty (THIS->display->display, window, property,
1640 0, 1<<30, 0, AnyPropertyType,
1641 &type, &format, &nitems, &bytes_after, &prop);
1642 if (type != None)
1643 {
1644 EXTEND (SP, 3);
1645 PUSHs (newSVuv ((U32)type));
1646 PUSHs (newSViv (format));
1647 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
1648 XFree (prop);
1649 }
1650}
1651
1652void
1653rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1654 CODE:
1655{
1656 STRLEN len;
1657 char *data_ = SvPVbyte (data, len);
1658
1659 XChangeProperty (THIS->display->display, window, property,
1660 type, format, PropModeReplace,
1661 (unsigned char *)data, len * 8 / format);
1662}
1663
1664void
1665XDeleteProperty (rxvt_term *term, Window window, Atom property)
1666 C_ARGS: term->display->display, window, property
1667
1668Window
1669rxvt_term::DefaultRootWindow ()
1670 CODE:
1671 RETVAL = THIS->display->root;
1672 OUTPUT:
1673 RETVAL
1674
1675Window
1676XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1677 C_ARGS: term->display->display, (Window)parent,
1678 x, y, width, height, 0,
1679 term->pix_colors_focused[Color_border],
1680 term->pix_colors_focused[Color_border]
1681
1682void
1683XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1684 C_ARGS: term->display->display, window, parent, x, y
1685
1686void
1687XMapWindow (rxvt_term *term, Window window)
1688 C_ARGS: term->display->display, window
1689
1690void
1691XUnmapWindow (rxvt_term *term, Window window)
1692 C_ARGS: term->display->display, window
1693
1694void
1695XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1696 C_ARGS: term->display->display, (Window)window, x, y, width, height
1697
1698#############################################################################
1699# urxvt::overlay
1700#############################################################################
1701
1666MODULE = urxvt PACKAGE = urxvt::overlay 1702MODULE = urxvt PACKAGE = urxvt::overlay
1667 1703
1668void 1704void
1669overlay::set (int x, int y, SV *text, SV *rend = 0) 1705overlay::set (int x, int y, SV *text, SV *rend = 0)
1670 1706
1674void 1710void
1675overlay::hide () 1711overlay::hide ()
1676 1712
1677void 1713void
1678overlay::DESTROY () 1714overlay::DESTROY ()
1715
1716#############################################################################
1717# urxvt::watcher
1718#############################################################################
1719
1720MODULE = urxvt PACKAGE = urxvt::watcher
1721
1722CHAINED
1723perl_watcher::cb (SV *cb)
1724 CODE:
1725 THIS->cb (cb);
1726 OUTPUT:
1727 RETVAL
1728
1729#############################################################################
1730# urxvt::timer
1731#############################################################################
1679 1732
1680MODULE = urxvt PACKAGE = urxvt::timer 1733MODULE = urxvt PACKAGE = urxvt::timer
1681 1734
1682SV * 1735SV *
1683timer::new () 1736timer::new ()
1684 CODE: 1737 CODE:
1685 timer *w = new timer; 1738 timer *w = new timer;
1686 w->start (NOW); 1739 w->start (NOW);
1687 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1740 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1688 w->self = (HV *)SvRV (RETVAL); 1741 w->self = (HV *)SvRV (RETVAL);
1689 OUTPUT:
1690 RETVAL
1691
1692timer *
1693timer::cb (SV *cb)
1694 CODE:
1695 THIS->cb (cb);
1696 RETVAL = THIS;
1697 OUTPUT: 1742 OUTPUT:
1698 RETVAL 1743 RETVAL
1699 1744
1700NV 1745NV
1701timer::at () 1746timer::at ()
1702 CODE: 1747 CODE:
1703 RETVAL = THIS->at; 1748 RETVAL = THIS->at;
1704 OUTPUT: 1749 OUTPUT:
1705 RETVAL 1750 RETVAL
1706 1751
1707timer * 1752CHAINED
1708timer::interval (NV interval) 1753timer::interval (NV interval)
1709 CODE: 1754 CODE:
1710 THIS->interval = interval; 1755 THIS->interval = interval;
1756 OUTPUT:
1711 RETVAL = THIS; 1757 RETVAL
1712 OUTPUT:
1713 RETVAL
1714 1758
1715timer * 1759CHAINED
1716timer::set (NV tstamp) 1760timer::set (NV tstamp)
1717 CODE: 1761 CODE:
1718 THIS->set (tstamp); 1762 THIS->set (tstamp);
1763 OUTPUT:
1719 RETVAL = THIS; 1764 RETVAL
1720 OUTPUT:
1721 RETVAL
1722 1765
1723timer * 1766CHAINED
1724timer::start (NV tstamp = THIS->at) 1767timer::start (NV tstamp = THIS->at)
1725 CODE: 1768 CODE:
1726 THIS->start (tstamp); 1769 THIS->start (tstamp);
1770 OUTPUT:
1727 RETVAL = THIS; 1771 RETVAL
1728 OUTPUT:
1729 RETVAL
1730 1772
1731timer * 1773CHAINED
1732timer::after (NV delay) 1774timer::after (NV delay)
1733 CODE: 1775 CODE:
1734 THIS->start (NOW + delay); 1776 THIS->start (NOW + delay);
1777 OUTPUT:
1735 RETVAL = THIS; 1778 RETVAL
1736 OUTPUT:
1737 RETVAL
1738 1779
1739timer * 1780CHAINED
1740timer::stop () 1781timer::stop ()
1741 CODE: 1782 CODE:
1742 THIS->stop (); 1783 THIS->stop ();
1743 RETVAL = THIS;
1744 OUTPUT: 1784 OUTPUT:
1745 RETVAL 1785 RETVAL
1746 1786
1747void 1787void
1748timer::DESTROY () 1788timer::DESTROY ()
1789
1790#############################################################################
1791# urxvt::iow
1792#############################################################################
1749 1793
1750MODULE = urxvt PACKAGE = urxvt::iow 1794MODULE = urxvt PACKAGE = urxvt::iow
1751 1795
1752SV * 1796SV *
1753iow::new () 1797iow::new ()
1754 CODE: 1798 CODE:
1755 iow *w = new iow; 1799 iow *w = new iow;
1756 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1800 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1757 w->self = (HV *)SvRV (RETVAL); 1801 w->self = (HV *)SvRV (RETVAL);
1758 OUTPUT: 1802 OUTPUT:
1759 RETVAL 1803 RETVAL
1760 1804
1761iow * 1805CHAINED
1762iow::cb (SV *cb)
1763 CODE:
1764 THIS->cb (cb);
1765 RETVAL = THIS;
1766 OUTPUT:
1767 RETVAL
1768
1769iow *
1770iow::fd (int fd) 1806iow::fd (int fd)
1771 CODE: 1807 CODE:
1772 THIS->fd = fd; 1808 THIS->fd = fd;
1809 OUTPUT:
1773 RETVAL = THIS; 1810 RETVAL
1774 OUTPUT:
1775 RETVAL
1776 1811
1777iow * 1812CHAINED
1778iow::events (short events) 1813iow::events (short events)
1779 CODE: 1814 CODE:
1780 THIS->events = events; 1815 THIS->events = events;
1816 OUTPUT:
1781 RETVAL = THIS; 1817 RETVAL
1782 OUTPUT:
1783 RETVAL
1784 1818
1785iow * 1819CHAINED
1786iow::start () 1820iow::start ()
1787 CODE: 1821 CODE:
1788 THIS->start (); 1822 THIS->start ();
1823 OUTPUT:
1789 RETVAL = THIS; 1824 RETVAL
1790 OUTPUT:
1791 RETVAL
1792 1825
1793iow * 1826CHAINED
1794iow::stop () 1827iow::stop ()
1795 CODE: 1828 CODE:
1796 THIS->stop (); 1829 THIS->stop ();
1797 RETVAL = THIS;
1798 OUTPUT: 1830 OUTPUT:
1799 RETVAL 1831 RETVAL
1800 1832
1801void 1833void
1802iow::DESTROY () 1834iow::DESTROY ()
1803 1835
1836#############################################################################
1837# urxvt::iw
1838#############################################################################
1804 1839
1840MODULE = urxvt PACKAGE = urxvt::iw
1841
1842SV *
1843iw::new ()
1844 CODE:
1845 iw *w = new iw;
1846 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
1847 w->self = (HV *)SvRV (RETVAL);
1848 OUTPUT:
1849 RETVAL
1850
1851CHAINED
1852iow::start ()
1853 CODE:
1854 THIS->start ();
1855 OUTPUT:
1856 RETVAL
1857
1858CHAINED
1859iow::stop ()
1860 CODE:
1861 THIS->stop ();
1862 OUTPUT:
1863 RETVAL
1864
1865void
1866iw::DESTROY ()
1867
1868#############################################################################
1869# urxvt::pw
1870#############################################################################
1871
1872MODULE = urxvt PACKAGE = urxvt::pw
1873
1874SV *
1875pw::new ()
1876 CODE:
1877 pw *w = new pw;
1878 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
1879 w->self = (HV *)SvRV (RETVAL);
1880 OUTPUT:
1881 RETVAL
1882
1883CHAINED
1884pw::start (int pid)
1885 CODE:
1886 THIS->start (pid);
1887 OUTPUT:
1888 RETVAL
1889
1890CHAINED
1891iow::stop ()
1892 CODE:
1893 THIS->stop ();
1894 OUTPUT:
1895 RETVAL
1896
1897void
1898pw::DESTROY ()
1899
1900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines