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.95 by root, Sun Jan 29 20:51:28 2006 UTC vs.
Revision 1.101 by root, Wed Jul 5 23:34:14 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);
356 355
357 int i; 356 int i;
358 357
359 for (i = AvFILL (overlay_av); i >= 0; i--) 358 for (i = AvFILL (overlay_av); i >= 0; i--)
360 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this) 359 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
361 {
362 av_delete (overlay_av, i, G_DISCARD);
363 break; 360 break;
364 }
365 361
366 for (; i < AvFILL (overlay_av); i++) 362 for (; i < AvFILL (overlay_av); i++)
367 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0))); 363 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
368 364
369 av_pop (overlay_av); 365 av_pop (overlay_av);
494static void 490static void
495ungrab (rxvt_term *THIS) 491ungrab (rxvt_term *THIS)
496{ 492{
497 if (THIS->perl.grabtime) 493 if (THIS->perl.grabtime)
498 { 494 {
499 XUngrabKeyboard (THIS->xdisp, THIS->perl.grabtime); 495 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
500 XUngrabPointer (THIS->xdisp, THIS->perl.grabtime); 496 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
501 THIS->perl.grabtime = 0; 497 THIS->perl.grabtime = 0;
502 } 498 }
503} 499}
504 500
505bool 501bool
763# include "optinc.h" 759# include "optinc.h"
764# undef nodef 760# undef nodef
765# undef def 761# undef def
766 762
767 HV *stash = gv_stashpv ("urxvt", 1); 763 HV *stash = gv_stashpv ("urxvt", 1);
768 struct { 764 static const struct {
769 const char *name; 765 const char *name;
770 IV iv; 766 IV iv;
771 } *civ, const_iv[] = { 767 } *civ, const_iv[] = {
772# define const_iv(name) { # name, (IV)name } 768# define const_iv(name) { # name, (IV)name }
773 const_iv (DEFAULT_RSTYLE), 769 const_iv (DEFAULT_RSTYLE),
883 const_iv (XIMDontChange), 879 const_iv (XIMDontChange),
884# endif 880# endif
885# endif 881# endif
886 }; 882 };
887 883
888 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 884 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
889 civ-- > const_iv; )
890 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 885 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
891} 886}
892 887
893void 888void
894warn (const char *msg) 889warn (const char *msg)
925 RETVAL 920 RETVAL
926 921
927int 922int
928SET_FGCOLOR (int rend, int new_color) 923SET_FGCOLOR (int rend, int new_color)
929 CODE: 924 CODE:
930 RETVAL = SET_FGCOLOR (rend, new_color); 925 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
931 OUTPUT: 926 OUTPUT:
932 RETVAL 927 RETVAL
933 928
934int 929int
935SET_BGCOLOR (int rend, int new_color) 930SET_BGCOLOR (int rend, int new_color)
936 CODE: 931 CODE:
937 RETVAL = SET_BGCOLOR (rend, new_color); 932 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
938 OUTPUT: 933 OUTPUT:
939 RETVAL 934 RETVAL
940 935
941int 936int
942GET_CUSTOM (int rend) 937GET_CUSTOM (int rend)
1020 THIS->perl.should_invoke [htype] += inc; 1015 THIS->perl.should_invoke [htype] += inc;
1021 1016
1022void 1017void
1023rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) 1018rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
1024 CODE: 1019 CODE:
1025 XGrabButton (THIS->xdisp, button, modifiers, window, 1, 1020 XGrabButton (THIS->dpy, button, modifiers, window, 1,
1026 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1021 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1027 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1022 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1028 1023
1029void 1024void
1030rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt) 1025rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1031 CODE: 1026 CODE:
1032 XUngrabButton (THIS->xdisp, button, modifiers, window); 1027 XUngrabButton (THIS->dpy, button, modifiers, window);
1033 1028
1034#if 0 1029#if 0
1035 1030
1036void 1031void
1037XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) 1032XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1038 C_ARGS: 1033 C_ARGS:
1039 THIS->xdisp, keycode, modifiers, window, 1, 1034 THIS->dpy, keycode, modifiers, window, 1,
1040 GrabModeSync, GrabModeSync 1035 GrabModeSync, GrabModeSync
1041 1036
1042void 1037void
1043XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) 1038XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1044 C_ARGS: THIS->xdisp, keycode, modifiers, window 1039 C_ARGS: THIS->dpy, keycode, modifiers, window
1045 1040
1046#endif 1041#endif
1047 1042
1048bool 1043bool
1049rxvt_term::grab (Time eventtime, int sync = 0) 1044rxvt_term::grab (Time eventtime, int sync = 0)
1051{ 1046{
1052 int mode = sync ? GrabModeSync : GrabModeAsync; 1047 int mode = sync ? GrabModeSync : GrabModeAsync;
1053 1048
1054 THIS->perl.grabtime = 0; 1049 THIS->perl.grabtime = 0;
1055 1050
1056 if (!XGrabPointer (THIS->xdisp, THIS->vt, 0, 1051 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
1057 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1052 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1058 mode, mode, None, GRAB_CURSOR, eventtime)) 1053 mode, mode, None, GRAB_CURSOR, eventtime))
1059 if (!XGrabKeyboard (THIS->xdisp, THIS->vt, 0, mode, mode, eventtime)) 1054 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
1060 THIS->perl.grabtime = eventtime; 1055 THIS->perl.grabtime = eventtime;
1061 else 1056 else
1062 XUngrabPointer (THIS->xdisp, eventtime); 1057 XUngrabPointer (THIS->dpy, eventtime);
1063 1058
1064 RETVAL = !!THIS->perl.grabtime; 1059 RETVAL = !!THIS->perl.grabtime;
1065} 1060}
1066 OUTPUT: 1061 OUTPUT:
1067 RETVAL 1062 RETVAL
1068 1063
1069void 1064void
1070rxvt_term::allow_events_async () 1065rxvt_term::allow_events_async ()
1071 CODE: 1066 CODE:
1072 XAllowEvents (THIS->xdisp, AsyncBoth, THIS->perl.grabtime); 1067 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1073 1068
1074void 1069void
1075rxvt_term::allow_events_sync () 1070rxvt_term::allow_events_sync ()
1076 CODE: 1071 CODE:
1077 XAllowEvents (THIS->xdisp, SyncBoth, THIS->perl.grabtime); 1072 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1078 1073
1079void 1074void
1080rxvt_term::allow_events_replay () 1075rxvt_term::allow_events_replay ()
1081 CODE: 1076 CODE:
1082 XAllowEvents (THIS->xdisp, ReplayPointer, THIS->perl.grabtime); 1077 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1083 XAllowEvents (THIS->xdisp, ReplayKeyboard, THIS->perl.grabtime); 1078 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1084 1079
1085void 1080void
1086rxvt_term::ungrab () 1081rxvt_term::ungrab ()
1087 CODE: 1082 CODE:
1088 ungrab (THIS); 1083 ungrab (THIS);
1211 } 1206 }
1212 OUTPUT: 1207 OUTPUT:
1213 RETVAL 1208 RETVAL
1214 1209
1215SV * 1210SV *
1216rxvt_term::_env () 1211rxvt_term::envv ()
1212 ALIAS:
1213 argv = 1
1217 CODE: 1214 PPCODE:
1218{ 1215{
1219 if (THIS->envv) 1216 stringvec *vec = ix ? THIS->argv : THIS->envv;
1220 {
1221 AV *av = newAV ();
1222 1217
1218 EXTEND (SP, vec->size ());
1219
1223 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1220 for (char **i = vec->begin (); i != vec->end (); ++i)
1224 if (*i) 1221 if (*i)
1225 av_push (av, newSVpv (*i, 0)); 1222 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1226
1227 RETVAL = newRV_noinc ((SV *)av);
1228 }
1229 else
1230 RETVAL = &PL_sv_undef;
1231} 1223}
1232 OUTPUT:
1233 RETVAL
1234 1224
1235int 1225int
1236rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1226rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1237 CODE: 1227 CODE:
1238 RETVAL = THIS->pty_ev.events; 1228 RETVAL = THIS->pty_ev.events;
1292void 1282void
1293rxvt_term::focus_in () 1283rxvt_term::focus_in ()
1294 1284
1295void 1285void
1296rxvt_term::focus_out () 1286rxvt_term::focus_out ()
1287
1288void
1289rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1290 ALIAS:
1291 key_release = 1
1292 CODE:
1293{
1294 XKeyEvent xkey;
1295
1296 memset (&xkey, 0, sizeof (xkey));
1297
1298 xkey.time = time;
1299 xkey.state = state;
1300 xkey.keycode = keycode;
1301
1302 xkey.type = ix ? KeyRelease : KeyPress;
1303 xkey.display = THIS->dpy;
1304 xkey.window = THIS->vt;
1305 xkey.root = THIS->display->root;
1306 xkey.subwindow = THIS->vt;
1307
1308 if (ix)
1309 THIS->key_release (xkey);
1310 else
1311 THIS->key_press (xkey);
1312}
1297 1313
1298void 1314void
1299rxvt_term::want_refresh () 1315rxvt_term::want_refresh ()
1300 CODE: 1316 CODE:
1301 THIS->want_refresh = 1; 1317 THIS->want_refresh = 1;
1494 1510
1495void 1511void
1496rxvt_term::_resource (char *name, int index, SV *newval = 0) 1512rxvt_term::_resource (char *name, int index, SV *newval = 0)
1497 PPCODE: 1513 PPCODE:
1498{ 1514{
1499 struct resval { const char *name; int value; } rslist [] = { 1515 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1500# define def(name) { # name, Rs_ ## name }, 1516# define def(name) { # name, Rs_ ## name },
1501# define reserve(name,count) 1517# define reserve(name,count)
1502# include "rsinc.h" 1518# include "rsinc.h"
1503# undef def 1519# undef def
1504# undef reserve 1520# undef reserve
1505 }; 1521 };
1506 1522
1507 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1523 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1508 1524
1509 do { 1525 do {
1510 if (rs-- == rslist) 1526 if (rs-- == rslist)
1511 croak ("no such resource '%s', requested", name); 1527 croak ("no such resource '%s', requested", name);
1512 } while (strcmp (name, rs->name)); 1528 } while (strcmp (name, rs->name));
1737void 1753void
1738rxvt_term::XListProperties (Window window) 1754rxvt_term::XListProperties (Window window)
1739 PPCODE: 1755 PPCODE:
1740{ 1756{
1741 int count; 1757 int count;
1742 Atom *props = XListProperties (THIS->xdisp, window, &count); 1758 Atom *props = XListProperties (THIS->dpy, window, &count);
1743 1759
1744 EXTEND (SP, count); 1760 EXTEND (SP, count);
1745 while (count--) 1761 while (count--)
1746 PUSHs (newSVuv ((U32)props [count])); 1762 PUSHs (newSVuv ((U32)props [count]));
1747 1763
1756 int format; 1772 int format;
1757 unsigned long nitems; 1773 unsigned long nitems;
1758 unsigned long bytes_after; 1774 unsigned long bytes_after;
1759 unsigned char *prop; 1775 unsigned char *prop;
1760 1776
1761 XGetWindowProperty (THIS->xdisp, window, property, 1777 XGetWindowProperty (THIS->dpy, window, property,
1762 0, 1<<24, 0, AnyPropertyType, 1778 0, 1<<24, 0, AnyPropertyType,
1763 &type, &format, &nitems, &bytes_after, &prop); 1779 &type, &format, &nitems, &bytes_after, &prop);
1764 1780
1765 if (type != None) 1781 if (type != None)
1766 { 1782 {
1785 1801
1786 int elemsize = format == 16 ? sizeof (short) 1802 int elemsize = format == 16 ? sizeof (short)
1787 : format == 32 ? sizeof (long) 1803 : format == 32 ? sizeof (long)
1788 : 1; 1804 : 1;
1789 1805
1790 XChangeProperty (THIS->xdisp, window, property, 1806 XChangeProperty (THIS->dpy, window, property,
1791 type, format, PropModeReplace, 1807 type, format, PropModeReplace,
1792 (unsigned char *)data_, len / elemsize); 1808 (unsigned char *)data_, len / elemsize);
1793 XSync (THIS->xdisp, 0);
1794} 1809}
1795 1810
1796Atom 1811Atom
1797XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1812XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1798 C_ARGS: term->xdisp, atom_name, only_if_exists 1813 C_ARGS: term->dpy, atom_name, only_if_exists
1799 1814
1800char * 1815char *
1801XGetAtomName (rxvt_term *term, Atom atom) 1816XGetAtomName (rxvt_term *term, Atom atom)
1802 C_ARGS: term->xdisp, atom 1817 C_ARGS: term->dpy, atom
1803 CLEANUP: 1818 CLEANUP:
1804 XFree (RETVAL); 1819 XFree (RETVAL);
1805 1820
1806void 1821void
1807XDeleteProperty (rxvt_term *term, Window window, Atom property) 1822XDeleteProperty (rxvt_term *term, Window window, Atom property)
1808 C_ARGS: term->xdisp, window, property 1823 C_ARGS: term->dpy, window, property
1809 1824
1810Window 1825Window
1811rxvt_term::DefaultRootWindow () 1826rxvt_term::DefaultRootWindow ()
1812 CODE: 1827 CODE:
1813 RETVAL = THIS->display->root; 1828 RETVAL = THIS->display->root;
1816 1831
1817#if 0 1832#if 0
1818 1833
1819Window 1834Window
1820XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1835XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1821 C_ARGS: term->xdisp, (Window)parent, 1836 C_ARGS: term->dpy, (Window)parent,
1822 x, y, width, height, 0, 1837 x, y, width, height, 0,
1823 term->pix_colors_focused[Color_border], 1838 term->pix_colors_focused[Color_border],
1824 term->pix_colors_focused[Color_border] 1839 term->pix_colors_focused[Color_border]
1825 1840
1826#endif 1841#endif
1827 1842
1828void 1843void
1829XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1844XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1830 C_ARGS: term->xdisp, window, parent, x, y 1845 C_ARGS: term->dpy, window, parent, x, y
1831 1846
1832void 1847void
1833XMapWindow (rxvt_term *term, Window window) 1848XMapWindow (rxvt_term *term, Window window)
1834 C_ARGS: term->xdisp, window 1849 C_ARGS: term->dpy, window
1835 1850
1836void 1851void
1837XUnmapWindow (rxvt_term *term, Window window) 1852XUnmapWindow (rxvt_term *term, Window window)
1838 C_ARGS: term->xdisp, window 1853 C_ARGS: term->dpy, window
1839 1854
1840void 1855void
1841XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1856XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1842 C_ARGS: term->xdisp, window, x, y, width, height 1857 C_ARGS: term->dpy, window, x, y, width, height
1843 1858
1844void 1859void
1845rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0) 1860rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1846 CODE: 1861 CODE:
1847{ 1862{
1848 XWindowAttributes attr; 1863 XWindowAttributes attr;
1849 XGetWindowAttributes (THIS->xdisp, window, &attr); 1864 XGetWindowAttributes (THIS->dpy, window, &attr);
1850 XSelectInput (THIS->xdisp, window, attr.your_event_mask | add_events & ~del_events); 1865 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1851} 1866}
1852 1867
1853void 1868void
1854rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y) 1869rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1855 PPCODE: 1870 PPCODE:
1856{ 1871{
1857 int dx, dy; 1872 int dx, dy;
1858 Window child; 1873 Window child;
1859 1874
1860 if (XTranslateCoordinates (THIS->xdisp, src, dst, x, y, &dx, &dy, &child)) 1875 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1861 { 1876 {
1862 EXTEND (SP, 3); 1877 EXTEND (SP, 3);
1863 PUSHs (newSViv (dx)); 1878 PUSHs (newSViv (dx));
1864 PUSHs (newSViv (dy)); 1879 PUSHs (newSViv (dy));
1865 PUSHs (newSVuv (child)); 1880 PUSHs (newSVuv (child));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines