--- rxvt-unicode/src/rxvtperl.xs 2006/02/03 05:47:05 1.96 +++ rxvt-unicode/src/rxvtperl.xs 2006/12/14 17:33:53 1.111 @@ -52,8 +52,6 @@ #undef ROW #define ROW(n) THIS->row_buf [LINENO (n)] -typedef int CHAINED UNUSED; - ///////////////////////////////////////////////////////////////////////////// static wchar_t * @@ -119,130 +117,6 @@ ///////////////////////////////////////////////////////////////////////////// -#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher") - -struct perl_watcher -{ - SV *cbsv; - HV *self; - - perl_watcher () - : cbsv (0) - { - } - - ~perl_watcher () - { - SvREFCNT_dec (cbsv); - } - - void cb (SV *cb) - { - SvREFCNT_dec (cbsv); - cbsv = newSVsv (cb); - } - - void invoke (const char *type, SV *self, int arg = -1); -}; - -void -perl_watcher::invoke (const char *type, SV *self, int arg) -{ - dSP; - - ENTER; - SAVETMPS; - - PUSHMARK (SP); - - XPUSHs (sv_2mortal (self)); - - if (arg >= 0) - XPUSHs (sv_2mortal (newSViv (arg))); - - PUTBACK; - call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD); - SPAGAIN; - - PUTBACK; - FREETMPS; - LEAVE; - - if (SvTRUE (ERRSV)) - rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); -} - -#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer") -#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer") - -struct timer : perl_watcher, time_watcher -{ - tstamp interval; - - timer () - : time_watcher (this, &timer::execute) - { - } - - void execute (time_watcher &w) - { - if (interval) - start (at + interval); - - invoke ("urxvt::timer", newSVtimer (this)); - } -}; - -#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow") -#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow") - -struct iow : perl_watcher, io_watcher -{ - iow () - : io_watcher (this, &iow::execute) - { - } - - void execute (io_watcher &w, short revents) - { - invoke ("urxvt::iow", newSViow (this), revents); - } -}; - -#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw") -#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw") - -struct iw : perl_watcher, idle_watcher -{ - iw () - : idle_watcher (this, &iw::execute) - { - } - - void execute (idle_watcher &w) - { - invoke ("urxvt::iw", newSViw (this)); - } -}; - -#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw") -#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw") - -struct pw : perl_watcher, child_watcher -{ - pw () - : child_watcher (this, &pw::execute) - { - } - - void execute (child_watcher &w, int status) - { - invoke ("urxvt::pw", newSVpw (this), status); - } -}; - -///////////////////////////////////////////////////////////////////////////// - #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") class overlay { @@ -270,6 +144,9 @@ overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) { + if (w < 0) w = 0; + if (h < 0) h = 0; + if (border == 2) { w += 2; @@ -357,10 +234,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))); @@ -427,6 +301,10 @@ THIS->want_refresh = 1; } +///////////////////////////////////////////////////////////////////////////// + +#define IOM_CLASS "urxvt" +#include ///////////////////////////////////////////////////////////////////////////// @@ -764,7 +642,7 @@ # undef def HV *stash = gv_stashpv ("urxvt", 1); - struct { + static const struct { const char *name; IV iv; } *civ, const_iv[] = { @@ -793,9 +671,9 @@ const_iv (Button5Mask), const_iv (AnyModifier), - const_iv (EVENT_NONE), - const_iv (EVENT_READ), - const_iv (EVENT_WRITE), + const_iv (NoSymbol), + const_iv (GrabModeSync), + const_iv (GrabModeAsync), const_iv (NoEventMask), const_iv (KeyPressMask), @@ -925,21 +803,21 @@ 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 int GET_CUSTOM (int rend) CODE: - RETVAL = (rend && RS_customMask) >> RS_customShift; + RETVAL = (rend & RS_customMask) >> RS_customShift; OUTPUT: RETVAL @@ -1017,31 +895,35 @@ CODE: THIS->perl.should_invoke [htype] += inc; -void +int rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) CODE: - XGrabButton (THIS->dpy, button, modifiers, window, 1, - ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, - GrabModeSync, GrabModeSync, None, GRAB_CURSOR); + RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1, + ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, + GrabModeSync, GrabModeSync, None, GRAB_CURSOR); + OUTPUT: RETVAL -void +int rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt) CODE: - XUngrabButton (THIS->dpy, button, modifiers, window); - -#if 0 + RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window); + OUTPUT: RETVAL void -XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) - C_ARGS: - THIS->dpy, keycode, modifiers, window, 1, - GrabModeSync, GrabModeSync +rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \ + int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync) + CODE: + XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode); void -XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) - C_ARGS: THIS->dpy, keycode, modifiers, window +rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) + CODE: + XUngrabKey (THIS->dpy, keycode, modifiers, window); -#endif +void +rxvt_term::XUngrabKeyboard (Time eventtime) + CODE: + XUngrabKeyboard (THIS->dpy, eventtime); bool rxvt_term::grab (Time eventtime, int sync = 0) @@ -1086,13 +968,44 @@ ungrab (THIS); int +rxvt_term::XStringToKeysym (char *string) + CODE: + RETVAL = XStringToKeysym (string); + OUTPUT: RETVAL + +char * +rxvt_term::XKeysymToString (int sym) + CODE: + RETVAL = XKeysymToString (sym); + OUTPUT: RETVAL + +int +rxvt_term::XKeysymToKeycode (int sym) + CODE: + RETVAL = XKeysymToKeycode (THIS->dpy, sym); + OUTPUT: RETVAL + +int +rxvt_term::XKeycodeToKeysym (int code, int index) + CODE: + RETVAL = XKeycodeToKeysym (THIS->dpy, code, index); + OUTPUT: RETVAL + +int rxvt_term::strwidth (SV *str) CODE: { wchar_t *wstr = sv2wcs (str); rxvt_push_locale (THIS->locale); - RETVAL = wcswidth (wstr, wcslen (wstr)); + RETVAL = 0; + for (wchar_t *wc = wstr; *wc; wc++) + { + int w = WCWIDTH (*wc); + + if (w) + RETVAL += max (w, 1); + } rxvt_pop_locale (); free (wstr); @@ -1135,6 +1048,13 @@ OUTPUT: RETVAL +char * +rxvt_term::locale () + CODE: + RETVAL = THIS->locale; + OUTPUT: + RETVAL + #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) #define TERM_OFFSET_width TERM_OFFSET(width) @@ -1211,24 +1131,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) @@ -1294,6 +1209,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; @@ -1494,7 +1435,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" @@ -1502,7 +1443,7 @@ # undef reserve }; - struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); + rs = rslist + sizeof (rslist) / sizeof (rslist [0]); do { if (rs-- == rslist) @@ -1788,7 +1729,6 @@ XChangeProperty (THIS->dpy, window, property, type, format, PropModeReplace, (unsigned char *)data_, len / elemsize); - XSync (THIS->dpy, 0); } Atom @@ -1882,188 +1822,5 @@ void overlay::DESTROY () -############################################################################# -# urxvt::watcher -############################################################################# - -MODULE = urxvt PACKAGE = urxvt::watcher - -CHAINED -perl_watcher::cb (SV *cb) - CODE: - THIS->cb (cb); - OUTPUT: - RETVAL - -############################################################################# -# urxvt::timer -############################################################################# - -MODULE = urxvt PACKAGE = urxvt::timer - -SV * -timer::new () - CODE: - timer *w = new timer; - w->start (NOW); - RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer"); - w->self = (HV *)SvRV (RETVAL); - OUTPUT: - RETVAL - -NV -timer::at () - CODE: - RETVAL = THIS->at; - OUTPUT: - RETVAL - -CHAINED -timer::interval (NV interval) - CODE: - THIS->interval = interval; - OUTPUT: - RETVAL - -CHAINED -timer::set (NV tstamp) - CODE: - THIS->set (tstamp); - OUTPUT: - RETVAL - -CHAINED -timer::start (NV tstamp = THIS->at) - CODE: - THIS->start (tstamp); - OUTPUT: - RETVAL - -CHAINED -timer::after (NV delay) - CODE: - THIS->start (NOW + delay); - OUTPUT: - RETVAL - -CHAINED -timer::stop () - CODE: - THIS->stop (); - OUTPUT: - RETVAL - -void -timer::DESTROY () - -############################################################################# -# urxvt::iow -############################################################################# - -MODULE = urxvt PACKAGE = urxvt::iow - -SV * -iow::new () - CODE: - iow *w = new iow; - RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow"); - w->self = (HV *)SvRV (RETVAL); - OUTPUT: - RETVAL - -CHAINED -iow::fd (int fd) - CODE: - THIS->fd = fd; - OUTPUT: - RETVAL - -CHAINED -iow::events (short events) - CODE: - THIS->events = events; - OUTPUT: - RETVAL - -CHAINED -iow::start () - CODE: - THIS->start (); - OUTPUT: - RETVAL - -CHAINED -iow::stop () - CODE: - THIS->stop (); - OUTPUT: - RETVAL - -void -iow::DESTROY () - -############################################################################# -# urxvt::iw -############################################################################# - -MODULE = urxvt PACKAGE = urxvt::iw - -SV * -iw::new () - CODE: - iw *w = new iw; - RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw"); - w->self = (HV *)SvRV (RETVAL); - OUTPUT: - RETVAL - -CHAINED -iw::start () - CODE: - THIS->start (); - OUTPUT: - RETVAL - -CHAINED -iw::stop () - CODE: - THIS->stop (); - OUTPUT: - RETVAL - -void -iw::DESTROY () - -############################################################################# -# urxvt::pw -############################################################################# - -MODULE = urxvt PACKAGE = urxvt::pw - -SV * -pw::new () - CODE: - pw *w = new pw; - RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw"); - w->self = (HV *)SvRV (RETVAL); - OUTPUT: - RETVAL - -CHAINED -pw::start (int pid) - CODE: - THIS->start (pid); - OUTPUT: - RETVAL - -CHAINED -pw::stop () - CODE: - THIS->stop (); - OUTPUT: - RETVAL - -void -pw::DESTROY () - +INCLUDE: $PERL