--- rxvt-unicode/src/rxvtperl.xs 2006/01/29 20:51:28 1.95 +++ rxvt-unicode/src/rxvtperl.xs 2006/07/05 23:34:14 1.101 @@ -82,7 +82,6 @@ return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); } -//TODO: use magic static SV * newSVptr (void *ptr, const char *klass) { @@ -358,10 +357,7 @@ for (i = AvFILL (overlay_av); i >= 0; i--) if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this) - { - av_delete (overlay_av, i, G_DISCARD); - break; - } + break; for (; i < AvFILL (overlay_av); i++) av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0))); @@ -496,8 +492,8 @@ { if (THIS->perl.grabtime) { - XUngrabKeyboard (THIS->xdisp, THIS->perl.grabtime); - XUngrabPointer (THIS->xdisp, THIS->perl.grabtime); + XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime); + XUngrabPointer (THIS->dpy, THIS->perl.grabtime); THIS->perl.grabtime = 0; } } @@ -765,7 +761,7 @@ # undef def HV *stash = gv_stashpv ("urxvt", 1); - struct { + static const struct { const char *name; IV iv; } *civ, const_iv[] = { @@ -885,8 +881,7 @@ # endif }; - for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); - civ-- > const_iv; ) + for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); } @@ -927,14 +922,14 @@ int SET_FGCOLOR (int rend, int new_color) CODE: - RETVAL = SET_FGCOLOR (rend, new_color); + RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1)); OUTPUT: RETVAL int SET_BGCOLOR (int rend, int new_color) CODE: - RETVAL = SET_BGCOLOR (rend, new_color); + RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1)); OUTPUT: RETVAL @@ -1022,26 +1017,26 @@ void rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) CODE: - XGrabButton (THIS->xdisp, button, modifiers, window, 1, + XGrabButton (THIS->dpy, button, modifiers, window, 1, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, GrabModeSync, GrabModeSync, None, GRAB_CURSOR); void rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt) CODE: - XUngrabButton (THIS->xdisp, button, modifiers, window); + XUngrabButton (THIS->dpy, button, modifiers, window); #if 0 void XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) C_ARGS: - THIS->xdisp, keycode, modifiers, window, 1, + THIS->dpy, keycode, modifiers, window, 1, GrabModeSync, GrabModeSync void XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) - C_ARGS: THIS->xdisp, keycode, modifiers, window + C_ARGS: THIS->dpy, keycode, modifiers, window #endif @@ -1053,13 +1048,13 @@ THIS->perl.grabtime = 0; - if (!XGrabPointer (THIS->xdisp, THIS->vt, 0, + if (!XGrabPointer (THIS->dpy, THIS->vt, 0, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, mode, mode, None, GRAB_CURSOR, eventtime)) - if (!XGrabKeyboard (THIS->xdisp, THIS->vt, 0, mode, mode, eventtime)) + if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime)) THIS->perl.grabtime = eventtime; else - XUngrabPointer (THIS->xdisp, eventtime); + XUngrabPointer (THIS->dpy, eventtime); RETVAL = !!THIS->perl.grabtime; } @@ -1069,18 +1064,18 @@ void rxvt_term::allow_events_async () CODE: - XAllowEvents (THIS->xdisp, AsyncBoth, THIS->perl.grabtime); + XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime); void rxvt_term::allow_events_sync () CODE: - XAllowEvents (THIS->xdisp, SyncBoth, THIS->perl.grabtime); + XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime); void rxvt_term::allow_events_replay () CODE: - XAllowEvents (THIS->xdisp, ReplayPointer, THIS->perl.grabtime); - XAllowEvents (THIS->xdisp, ReplayKeyboard, THIS->perl.grabtime); + XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime); + XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime); void rxvt_term::ungrab () @@ -1213,24 +1208,19 @@ RETVAL SV * -rxvt_term::_env () - CODE: +rxvt_term::envv () + ALIAS: + argv = 1 + PPCODE: { - if (THIS->envv) - { - AV *av = newAV (); + stringvec *vec = ix ? THIS->argv : THIS->envv; - for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) - if (*i) - av_push (av, newSVpv (*i, 0)); + EXTEND (SP, vec->size ()); - RETVAL = newRV_noinc ((SV *)av); - } - else - RETVAL = &PL_sv_undef; + for (char **i = vec->begin (); i != vec->end (); ++i) + if (*i) + PUSHs (sv_2mortal (newSVpv (*i, 0))); } - OUTPUT: - RETVAL int rxvt_term::pty_ev_events (int events = EVENT_UNDEF) @@ -1296,6 +1286,32 @@ rxvt_term::focus_out () void +rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime) + ALIAS: + key_release = 1 + CODE: +{ + XKeyEvent xkey; + + memset (&xkey, 0, sizeof (xkey)); + + xkey.time = time; + xkey.state = state; + xkey.keycode = keycode; + + xkey.type = ix ? KeyRelease : KeyPress; + xkey.display = THIS->dpy; + xkey.window = THIS->vt; + xkey.root = THIS->display->root; + xkey.subwindow = THIS->vt; + + if (ix) + THIS->key_release (xkey); + else + THIS->key_press (xkey); +} + +void rxvt_term::want_refresh () CODE: THIS->want_refresh = 1; @@ -1496,7 +1512,7 @@ rxvt_term::_resource (char *name, int index, SV *newval = 0) PPCODE: { - struct resval { const char *name; int value; } rslist [] = { + static const struct resval { const char *name; int value; } *rs, rslist [] = { # define def(name) { # name, Rs_ ## name }, # define reserve(name,count) # include "rsinc.h" @@ -1504,7 +1520,7 @@ # undef reserve }; - struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); + rs = rslist + sizeof (rslist) / sizeof (rslist [0]); do { if (rs-- == rslist) @@ -1739,7 +1755,7 @@ PPCODE: { int count; - Atom *props = XListProperties (THIS->xdisp, window, &count); + Atom *props = XListProperties (THIS->dpy, window, &count); EXTEND (SP, count); while (count--) @@ -1758,7 +1774,7 @@ unsigned long bytes_after; unsigned char *prop; - XGetWindowProperty (THIS->xdisp, window, property, + XGetWindowProperty (THIS->dpy, window, property, 0, 1<<24, 0, AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop); @@ -1787,25 +1803,24 @@ : format == 32 ? sizeof (long) : 1; - XChangeProperty (THIS->xdisp, window, property, + XChangeProperty (THIS->dpy, window, property, type, format, PropModeReplace, (unsigned char *)data_, len / elemsize); - XSync (THIS->xdisp, 0); } Atom XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) - C_ARGS: term->xdisp, atom_name, only_if_exists + C_ARGS: term->dpy, atom_name, only_if_exists char * XGetAtomName (rxvt_term *term, Atom atom) - C_ARGS: term->xdisp, atom + C_ARGS: term->dpy, atom CLEANUP: XFree (RETVAL); void XDeleteProperty (rxvt_term *term, Window window, Atom property) - C_ARGS: term->xdisp, window, property + C_ARGS: term->dpy, window, property Window rxvt_term::DefaultRootWindow () @@ -1818,7 +1833,7 @@ Window XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) - C_ARGS: term->xdisp, (Window)parent, + C_ARGS: term->dpy, (Window)parent, x, y, width, height, 0, term->pix_colors_focused[Color_border], term->pix_colors_focused[Color_border] @@ -1827,27 +1842,27 @@ void XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) - C_ARGS: term->xdisp, window, parent, x, y + C_ARGS: term->dpy, window, parent, x, y void XMapWindow (rxvt_term *term, Window window) - C_ARGS: term->xdisp, window + C_ARGS: term->dpy, window void XUnmapWindow (rxvt_term *term, Window window) - C_ARGS: term->xdisp, window + C_ARGS: term->dpy, window void XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) - C_ARGS: term->xdisp, window, x, y, width, height + C_ARGS: term->dpy, window, x, y, width, height void rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0) CODE: { XWindowAttributes attr; - XGetWindowAttributes (THIS->xdisp, window, &attr); - XSelectInput (THIS->xdisp, window, attr.your_event_mask | add_events & ~del_events); + XGetWindowAttributes (THIS->dpy, window, &attr); + XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events); } void @@ -1857,7 +1872,7 @@ int dx, dy; Window child; - if (XTranslateCoordinates (THIS->xdisp, src, dst, x, y, &dx, &dy, &child)) + if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child)) { EXTEND (SP, 3); PUSHs (newSViv (dx));