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.93 by root, Wed Jan 25 15:02:47 2006 UTC vs.
Revision 1.97 by root, Sat Feb 4 16:12:48 2006 UTC

80new_ref (HV *hv, const char *klass) 80new_ref (HV *hv, const char *klass)
81{ 81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83} 83}
84 84
85//TODO: use magic
86static SV * 85static SV *
87newSVptr (void *ptr, const char *klass) 86newSVptr (void *ptr, const char *klass)
88{ 87{
89 HV *hv = newHV (); 88 HV *hv = newHV ();
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 112 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 113
115 return (long)mg->mg_ptr; 114 return (long)mg->mg_ptr;
116} 115}
117 116
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 117#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 118#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 119
121///////////////////////////////////////////////////////////////////////////// 120/////////////////////////////////////////////////////////////////////////////
122 121
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher") 122#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124 123
171 170
172 if (SvTRUE (ERRSV)) 171 if (SvTRUE (ERRSV))
173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 172 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
174} 173}
175 174
176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 175#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer")
177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer") 176#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer")
178 177
179struct timer : perl_watcher, time_watcher 178struct timer : perl_watcher, time_watcher
180{ 179{
181 tstamp interval; 180 tstamp interval;
182 181
192 191
193 invoke ("urxvt::timer", newSVtimer (this)); 192 invoke ("urxvt::timer", newSVtimer (this));
194 } 193 }
195}; 194};
196 195
197#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 196#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow")
198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow") 197#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow")
199 198
200struct iow : perl_watcher, io_watcher 199struct iow : perl_watcher, io_watcher
201{ 200{
202 iow () 201 iow ()
203 : io_watcher (this, &iow::execute) 202 : io_watcher (this, &iow::execute)
208 { 207 {
209 invoke ("urxvt::iow", newSViow (this), revents); 208 invoke ("urxvt::iow", newSViow (this), revents);
210 } 209 }
211}; 210};
212 211
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw") 212#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw") 213#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw")
215 214
216struct iw : perl_watcher, idle_watcher 215struct iw : perl_watcher, idle_watcher
217{ 216{
218 iw () 217 iw ()
219 : idle_watcher (this, &iw::execute) 218 : idle_watcher (this, &iw::execute)
224 { 223 {
225 invoke ("urxvt::iw", newSViw (this)); 224 invoke ("urxvt::iw", newSViw (this));
226 } 225 }
227}; 226};
228 227
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw") 228#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw") 229#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw")
231 230
232struct pw : perl_watcher, child_watcher 231struct pw : perl_watcher, child_watcher
233{ 232{
234 pw () 233 pw ()
235 : child_watcher (this, &pw::execute) 234 : child_watcher (this, &pw::execute)
494static void 493static void
495ungrab (rxvt_term *THIS) 494ungrab (rxvt_term *THIS)
496{ 495{
497 if (THIS->perl.grabtime) 496 if (THIS->perl.grabtime)
498 { 497 {
499 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 498 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
500 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 499 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
501 THIS->perl.grabtime = 0; 500 THIS->perl.grabtime = 0;
502 } 501 }
503} 502}
504 503
505bool 504bool
558 case DT_STR_LEN: 557 case DT_STR_LEN:
559 { 558 {
560 char *str = va_arg (ap, char *); 559 char *str = va_arg (ap, char *);
561 int len = va_arg (ap, int); 560 int len = va_arg (ap, int);
562 561
563 printf ("pushing str %p:%d\n", str,len);//D
564 XPUSHs (sv_2mortal (newSVpvn (str, len))); 562 XPUSHs (sv_2mortal (newSVpvn (str, len)));
565 } 563 }
566 break; 564 break;
567 565
568 case DT_WCS_LEN: 566 case DT_WCS_LEN:
764# include "optinc.h" 762# include "optinc.h"
765# undef nodef 763# undef nodef
766# undef def 764# undef def
767 765
768 HV *stash = gv_stashpv ("urxvt", 1); 766 HV *stash = gv_stashpv ("urxvt", 1);
769 struct { 767 static const struct {
770 const char *name; 768 const char *name;
771 IV iv; 769 IV iv;
772 } *civ, const_iv[] = { 770 } *civ, const_iv[] = {
773# define const_iv(name) { # name, (IV)name } 771# define const_iv(name) { # name, (IV)name }
774 const_iv (DEFAULT_RSTYLE), 772 const_iv (DEFAULT_RSTYLE),
884 const_iv (XIMDontChange), 882 const_iv (XIMDontChange),
885# endif 883# endif
886# endif 884# endif
887 }; 885 };
888 886
889 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 887 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
890 civ-- > const_iv; )
891 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 888 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
892} 889}
893 890
894void 891void
895warn (const char *msg) 892warn (const char *msg)
957 | ((new_value << RS_customShift) & RS_customMask); 954 | ((new_value << RS_customShift) & RS_customMask);
958} 955}
959 OUTPUT: 956 OUTPUT:
960 RETVAL 957 RETVAL
961 958
959void
960termlist ()
961 PPCODE:
962{
963 EXTEND (SP, rxvt_term::termlist.size ());
964
965 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
966 if ((*t)->perl.self)
967 PUSHs (sv_2mortal (newSVterm (*t)));
968}
969
962MODULE = urxvt PACKAGE = urxvt::term 970MODULE = urxvt PACKAGE = urxvt::term
963 971
964SV * 972SV *
965_new (...) 973_new (AV *env, AV *arg)
966 CODE: 974 CODE:
967{ 975{
968 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
969 croak ("first argument to urxvt::term->_new must be arrayref");
970
971 rxvt_term *term = new rxvt_term; 976 rxvt_term *term = new rxvt_term;
972 977
973 stringvec *argv = new stringvec; 978 stringvec *argv = new stringvec;
974 stringvec *envv = new stringvec; 979 stringvec *envv = new stringvec;
975 980
976 for (int i = 1; i < items; i++) 981 for (int i = 0; i <= AvFILL (arg); i++)
977 argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 982 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
978 983
979 AV *env = (AV *)SvRV (ST (0));
980 for (int i = AvFILL (env) + 1; i--; ) 984 for (int i = AvFILL (env) + 1; i--; )
981 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 985 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
982 986
983 envv->push_back (0); 987 envv->push_back (0);
984 988
1012rxvt_term::set_should_invoke (int htype, int inc) 1016rxvt_term::set_should_invoke (int htype, int inc)
1013 CODE: 1017 CODE:
1014 THIS->perl.should_invoke [htype] += inc; 1018 THIS->perl.should_invoke [htype] += inc;
1015 1019
1016void 1020void
1017rxvt_term::grab_button (int button, U32 modifiers) 1021rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
1018 CODE: 1022 CODE:
1019 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1023 XGrabButton (THIS->dpy, button, modifiers, window, 1,
1020 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1024 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1021 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1025 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1022 1026
1027void
1028rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1029 CODE:
1030 XUngrabButton (THIS->dpy, button, modifiers, window);
1031
1032#if 0
1033
1034void
1035XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1036 C_ARGS:
1037 THIS->dpy, keycode, modifiers, window, 1,
1038 GrabModeSync, GrabModeSync
1039
1040void
1041XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1042 C_ARGS: THIS->dpy, keycode, modifiers, window
1043
1044#endif
1045
1023bool 1046bool
1024rxvt_term::grab (Time eventtime, int sync = 0) 1047rxvt_term::grab (Time eventtime, int sync = 0)
1025 CODE: 1048 CODE:
1026{ 1049{
1027 int mode = sync ? GrabModeSync : GrabModeAsync; 1050 int mode = sync ? GrabModeSync : GrabModeAsync;
1028 1051
1029 THIS->perl.grabtime = 0; 1052 THIS->perl.grabtime = 0;
1030 1053
1031 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1054 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
1032 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1055 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1033 mode, mode, None, GRAB_CURSOR, eventtime)) 1056 mode, mode, None, GRAB_CURSOR, eventtime))
1034 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1057 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
1035 THIS->perl.grabtime = eventtime; 1058 THIS->perl.grabtime = eventtime;
1036 else 1059 else
1037 XUngrabPointer (THIS->display->display, eventtime); 1060 XUngrabPointer (THIS->dpy, eventtime);
1038 1061
1039 RETVAL = !!THIS->perl.grabtime; 1062 RETVAL = !!THIS->perl.grabtime;
1040} 1063}
1041 OUTPUT: 1064 OUTPUT:
1042 RETVAL 1065 RETVAL
1043 1066
1044void 1067void
1045rxvt_term::allow_events_async () 1068rxvt_term::allow_events_async ()
1046 CODE: 1069 CODE:
1047 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1070 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1048 1071
1049void 1072void
1050rxvt_term::allow_events_sync () 1073rxvt_term::allow_events_sync ()
1051 CODE: 1074 CODE:
1052 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1075 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1053 1076
1054void 1077void
1055rxvt_term::allow_events_replay () 1078rxvt_term::allow_events_replay ()
1056 CODE: 1079 CODE:
1057 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1080 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1058 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1081 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1059 1082
1060void 1083void
1061rxvt_term::ungrab () 1084rxvt_term::ungrab ()
1062 CODE: 1085 CODE:
1063 ungrab (THIS); 1086 ungrab (THIS);
1469 1492
1470void 1493void
1471rxvt_term::_resource (char *name, int index, SV *newval = 0) 1494rxvt_term::_resource (char *name, int index, SV *newval = 0)
1472 PPCODE: 1495 PPCODE:
1473{ 1496{
1474 struct resval { const char *name; int value; } rslist [] = { 1497 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1475# define def(name) { # name, Rs_ ## name }, 1498# define def(name) { # name, Rs_ ## name },
1476# define reserve(name,count) 1499# define reserve(name,count)
1477# include "rsinc.h" 1500# include "rsinc.h"
1478# undef def 1501# undef def
1479# undef reserve 1502# undef reserve
1480 }; 1503 };
1481 1504
1482 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1505 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1483 1506
1484 do { 1507 do {
1485 if (rs-- == rslist) 1508 if (rs-- == rslist)
1486 croak ("no such resource '%s', requested", name); 1509 croak ("no such resource '%s', requested", name);
1487 } while (strcmp (name, rs->name)); 1510 } while (strcmp (name, rs->name));
1712void 1735void
1713rxvt_term::XListProperties (Window window) 1736rxvt_term::XListProperties (Window window)
1714 PPCODE: 1737 PPCODE:
1715{ 1738{
1716 int count; 1739 int count;
1717 Atom *props = XListProperties (THIS->display->display, window, &count); 1740 Atom *props = XListProperties (THIS->dpy, window, &count);
1718 1741
1719 EXTEND (SP, count); 1742 EXTEND (SP, count);
1720 while (count--) 1743 while (count--)
1721 PUSHs (newSVuv ((U32)props [count])); 1744 PUSHs (newSVuv ((U32)props [count]));
1722 1745
1731 int format; 1754 int format;
1732 unsigned long nitems; 1755 unsigned long nitems;
1733 unsigned long bytes_after; 1756 unsigned long bytes_after;
1734 unsigned char *prop; 1757 unsigned char *prop;
1735 1758
1736 XGetWindowProperty (THIS->display->display, window, property, 1759 XGetWindowProperty (THIS->dpy, window, property,
1737 0, 1<<24, 0, AnyPropertyType, 1760 0, 1<<24, 0, AnyPropertyType,
1738 &type, &format, &nitems, &bytes_after, &prop); 1761 &type, &format, &nitems, &bytes_after, &prop);
1739 1762
1740 if (type != None) 1763 if (type != None)
1741 { 1764 {
1760 1783
1761 int elemsize = format == 16 ? sizeof (short) 1784 int elemsize = format == 16 ? sizeof (short)
1762 : format == 32 ? sizeof (long) 1785 : format == 32 ? sizeof (long)
1763 : 1; 1786 : 1;
1764 1787
1765 XChangeProperty (THIS->display->display, window, property, 1788 XChangeProperty (THIS->dpy, window, property,
1766 type, format, PropModeReplace, 1789 type, format, PropModeReplace,
1767 (unsigned char *)data_, len / elemsize); 1790 (unsigned char *)data_, len / elemsize);
1768 XSync (THIS->display->display, 0); 1791 XSync (THIS->dpy, 0);
1769} 1792}
1770 1793
1771Atom 1794Atom
1772XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1795XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1773 C_ARGS: term->display->display, atom_name, only_if_exists 1796 C_ARGS: term->dpy, atom_name, only_if_exists
1774 1797
1775char * 1798char *
1776XGetAtomName (rxvt_term *term, Atom atom) 1799XGetAtomName (rxvt_term *term, Atom atom)
1777 C_ARGS: term->display->display, atom 1800 C_ARGS: term->dpy, atom
1778 CLEANUP: 1801 CLEANUP:
1779 XFree (RETVAL); 1802 XFree (RETVAL);
1780 1803
1781void 1804void
1782XDeleteProperty (rxvt_term *term, Window window, Atom property) 1805XDeleteProperty (rxvt_term *term, Window window, Atom property)
1783 C_ARGS: term->display->display, window, property 1806 C_ARGS: term->dpy, window, property
1784 1807
1785Window 1808Window
1786rxvt_term::DefaultRootWindow () 1809rxvt_term::DefaultRootWindow ()
1787 CODE: 1810 CODE:
1788 RETVAL = THIS->display->root; 1811 RETVAL = THIS->display->root;
1791 1814
1792#if 0 1815#if 0
1793 1816
1794Window 1817Window
1795XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1818XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1796 C_ARGS: term->display->display, (Window)parent, 1819 C_ARGS: term->dpy, (Window)parent,
1797 x, y, width, height, 0, 1820 x, y, width, height, 0,
1798 term->pix_colors_focused[Color_border], 1821 term->pix_colors_focused[Color_border],
1799 term->pix_colors_focused[Color_border] 1822 term->pix_colors_focused[Color_border]
1800 1823
1801#endif 1824#endif
1802 1825
1803void 1826void
1804XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1827XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1805 C_ARGS: term->display->display, window, parent, x, y 1828 C_ARGS: term->dpy, window, parent, x, y
1806 1829
1807void 1830void
1808XMapWindow (rxvt_term *term, Window window) 1831XMapWindow (rxvt_term *term, Window window)
1809 C_ARGS: term->display->display, window 1832 C_ARGS: term->dpy, window
1810 1833
1811void 1834void
1812XUnmapWindow (rxvt_term *term, Window window) 1835XUnmapWindow (rxvt_term *term, Window window)
1813 C_ARGS: term->display->display, window 1836 C_ARGS: term->dpy, window
1814 1837
1815void 1838void
1816XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1839XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1817 C_ARGS: term->display->display, window, x, y, width, height 1840 C_ARGS: term->dpy, window, x, y, width, height
1818 1841
1819void 1842void
1820rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0) 1843rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1821 CODE: 1844 CODE:
1822{ 1845{
1823 XWindowAttributes attr; 1846 XWindowAttributes attr;
1824 XGetWindowAttributes (THIS->display->display, window, &attr); 1847 XGetWindowAttributes (THIS->dpy, window, &attr);
1825 XSelectInput (THIS->display->display, window, attr.your_event_mask | add_events & ~del_events); 1848 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1826} 1849}
1827 1850
1828void 1851void
1829rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y) 1852rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1830 PPCODE: 1853 PPCODE:
1831{ 1854{
1832 int dx, dy; 1855 int dx, dy;
1833 Window child; 1856 Window child;
1834 1857
1835 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child)) 1858 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1836 { 1859 {
1837 EXTEND (SP, 3); 1860 EXTEND (SP, 3);
1838 PUSHs (newSViv (dx)); 1861 PUSHs (newSViv (dx));
1839 PUSHs (newSViv (dy)); 1862 PUSHs (newSViv (dy));
1840 PUSHs (newSVuv (child)); 1863 PUSHs (newSVuv (child));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines