--- rxvt-unicode/src/rxvtperl.xs 2012/06/07 12:56:27 1.180 +++ rxvt-unicode/src/rxvtperl.xs 2012/06/14 18:59:39 1.198 @@ -56,16 +56,54 @@ typedef int render_repeat_mode; +#if HAVE_PIXBUF typedef GdkPixbuf * urxvt__pixbuf; +#endif typedef rxvt_img * urxvt__img; +typedef rxvt_img::nv rxvt_img__nv; ///////////////////////////////////////////////////////////////////////////// -static void -parse_color (rxvt_screen *s, rxvt_color &c, SV *sv) +static rgba +parse_rgba (SV *sv, rxvt_screen *s = 0) { - //TODO: support component stuff - c.set (s, SvPVbyte_nolen (sv)); + rgba c; + + if (SvROK (sv)) + { + AV *av = (AV *)SvRV (sv); + + if (SvTYPE ((SV *)av) != SVt_PVAV) + croak ("colour must be either a colour string, or an array,"); + + int len = av_len (av) + 1; + + if (len != 1 && len != 3 && len != 4) + croak ("component colour array must have 1, 3 or 4 components,"); + + c.a = rgba::MAX_CC; + + c.r = c.g = c.b = float_to_component (SvIV (*av_fetch (av, 0, 0))); + + if (len >= 3) + { + c.g = float_to_component (SvIV (*av_fetch (av, 1, 0))); + c.b = float_to_component (SvIV (*av_fetch (av, 2, 0))); + + if (len >= 4) + c.a = float_to_component (SvIV (*av_fetch (av, 3, 0))); + } + } + else if (s) + { + rxvt_color rc; + rc.set (s, SvPVbyte_nolen (sv)); + rc.get (c); + } + else + croak ("unable to parse colour,"); + + return c; } ///////////////////////////////////////////////////////////////////////////// @@ -343,7 +381,7 @@ } void -rxvt_perl_interp::init (rxvt_term *term) +rxvt_perl_interp::init () { if (!perl) { @@ -383,8 +421,14 @@ rxvt_pop_locale (); } +} - if (perl) +void +rxvt_perl_interp::init (rxvt_term *term) +{ + init (); + + if (perl && !term->perl.self) { // runs outside of perls ENV term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); @@ -394,6 +438,12 @@ } void +rxvt_perl_interp::eval (const char *str) +{ + eval_pv (str, 1); +} + +void rxvt_perl_interp::usage (rxvt_term *term, int type) { localise_env set_environ (perl_environ); @@ -863,6 +913,62 @@ const_iv (RepeatNormal), const_iv (RepeatPad), const_iv (RepeatReflect), + // all versions + const_iv (PictOpClear), + const_iv (PictOpSrc), + const_iv (PictOpDst), + const_iv (PictOpOver), + const_iv (PictOpOverReverse), + const_iv (PictOpIn), + const_iv (PictOpInReverse), + const_iv (PictOpOut), + const_iv (PictOpOutReverse), + const_iv (PictOpAtop), + const_iv (PictOpAtopReverse), + const_iv (PictOpXor), + const_iv (PictOpAdd), + const_iv (PictOpSaturate), + // 0.2+ + const_iv (PictOpDisjointClear), + const_iv (PictOpDisjointSrc), + const_iv (PictOpDisjointDst), + const_iv (PictOpDisjointOver), + const_iv (PictOpDisjointOverReverse), + const_iv (PictOpDisjointIn), + const_iv (PictOpDisjointInReverse), + const_iv (PictOpDisjointOut), + const_iv (PictOpDisjointOutReverse), + const_iv (PictOpDisjointAtop), + const_iv (PictOpDisjointAtopReverse), + const_iv (PictOpDisjointXor), + const_iv (PictOpConjointClear), + const_iv (PictOpConjointSrc), + const_iv (PictOpConjointDst), + const_iv (PictOpConjointOver), + const_iv (PictOpConjointOverReverse), + const_iv (PictOpConjointIn), + const_iv (PictOpConjointInReverse), + const_iv (PictOpConjointOut), + const_iv (PictOpConjointOutReverse), + const_iv (PictOpConjointAtop), + const_iv (PictOpConjointAtopReverse), + const_iv (PictOpConjointXor), + // 0.11+ + const_iv (PictOpMultiply), + const_iv (PictOpScreen), + const_iv (PictOpOverlay), + const_iv (PictOpDarken), + const_iv (PictOpLighten), + const_iv (PictOpColorDodge), + const_iv (PictOpColorBurn), + const_iv (PictOpHardLight), + const_iv (PictOpSoftLight), + const_iv (PictOpDifference), + const_iv (PictOpExclusion), + const_iv (PictOpHSLHue), + const_iv (PictOpHSLSaturation), + const_iv (PictOpHSLColor), + const_iv (PictOpHSLLuminosity), #endif # if 0 const_iv (XIMForwardChar), @@ -2032,32 +2138,35 @@ ############################################################################# # fancy bg bloatstuff (TODO: should be moved up somewhere) -# TODO: ugly +bool +rxvt_term::has_render () + CODE: + RETVAL = THIS->display->flags & DISPLAY_HAS_RENDER; + OUTPUT: + RETVAL + void -rxvt_term::get_geometry () +rxvt_term::background_geometry (bool border = false) PPCODE: EXTEND (SP, 4); - PUSHs (sv_2mortal (newSViv (THIS->parent_x))); - PUSHs (sv_2mortal (newSViv (THIS->parent_y))); - PUSHs (sv_2mortal (newSViv (THIS->szHint.width))); - PUSHs (sv_2mortal (newSViv (THIS->szHint.height))); + PUSHs (sv_2mortal (newSViv (THIS->parent_x + (border ? THIS->window_vt_x : 0)))); + PUSHs (sv_2mortal (newSViv (THIS->parent_y + (border ? THIS->window_vt_y : 0)))); + PUSHs (sv_2mortal (newSViv (border ? THIS->vt_width : THIS->szHint.width ))); + PUSHs (sv_2mortal (newSViv (border ? THIS->vt_height : THIS->szHint.height))); #if HAVE_IMG -#if 0 - rxvt_img * -rxvt_term::new_img (SV *format, int width, int height) +rxvt_term::new_img (SV *format, int x = 0, int y = 0, int width = 1, int height = 1) CODE: XRenderPictFormat *f = SvOK (format) ? XRenderFindStandardFormat (THIS->dpy, SvIV (format)) : XRenderFindVisualFormat (THIS->dpy, THIS->visual); - RETVAL = new rxvt_img (THIS, f, width, height); + RETVAL = new rxvt_img (THIS, f, x, y, width, height); + RETVAL->alloc (); OUTPUT: RETVAL -#endif - #if ENABLE_TRANSPARENCY rxvt_img * @@ -2093,21 +2202,30 @@ rxvt_term::set_background (rxvt_img *img, bool border = false) CODE: THIS->bg_destroy (); - THIS->bg_pixmap = None; THIS->bg_flags &= ~(rxvt_term::BG_NEEDS_REFRESH | rxvt_term::BG_INHIBIT_RENDER | rxvt_term::BG_IS_TRANSPARENT); if (img) // TODO: cannot be false { - img = img->reify (); - rxvt_img *img2 = img->convert_to (XRenderFindVisualFormat (THIS->dpy, THIS->visual), THIS->pix_colors [Color_bg]); - delete img; - THIS->bg_pixmap = img2->steal (); + img = img->clone (); // own the img + + if (img->repeat != RepeatNormal) // X11 only supports RepeatNormal as bg pixmap + img->sub_rect (0, 0, + border ? THIS->vt_width : THIS->szHint.width, + border ? THIS->vt_height : THIS->szHint.height) + ->replace (img); + + // just in case, should usually be a nop + img->reify () + ->replace (img); + + img->convert_format (XRenderFindVisualFormat (THIS->dpy, THIS->visual), THIS->pix_colors [Color_bg]) + ->replace (img); + + THIS->bg_img = img; THIS->bg_flags |= rxvt_term::BG_NEEDS_REFRESH | rxvt_term::BG_INHIBIT_RENDER; if (!border) THIS->bg_flags |= rxvt_term::BG_IS_TRANSPARENT; - - THIS->bg_valid_since = ev::now (); // TODO: extra bloat } #endif @@ -2155,6 +2273,29 @@ # rxvt_img *new (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) # rxvt_img *rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); +void +rxvt_img::geometry () + PPCODE: + EXTEND (SP, 4); + PUSHs (sv_2mortal (newSViv (THIS->x))); + PUSHs (sv_2mortal (newSViv (THIS->y))); + PUSHs (sv_2mortal (newSViv (THIS->w))); + PUSHs (sv_2mortal (newSViv (THIS->h))); + +int +rxvt_img::x () + CODE: + RETVAL = THIS->x; + OUTPUT: + RETVAL + +int +rxvt_img::y () + CODE: + RETVAL = THIS->y; + OUTPUT: + RETVAL + int rxvt_img::w () CODE: @@ -2179,9 +2320,8 @@ void rxvt_img::fill (SV *c) INIT: - rxvt_color rc; - parse_color (THIS->s, rc, c); - C_ARGS: rc + rgba cc = parse_rgba (c, THIS->s); + C_ARGS: cc void rxvt_img::DESTROY () @@ -2191,17 +2331,22 @@ void rxvt_img::unshare () -void -rxvt_img::repeat_mode (render_repeat_mode repeat = RepeatNormal) +int +rxvt_img::repeat_mode (render_repeat_mode repeat = 0) + CODE: + if (items >= 2) + THIS->repeat_mode (repeat); + if (GIMME_V != G_VOID) + XPUSHs (sv_2mortal (newSViv (THIS->repeat))); void rxvt_img::move (int dx, int dy) void -rxvt_img::brightness (NV r, NV g, NV b, NV a = 1.) +rxvt_img::brightness (rxvt_img::nv r, rxvt_img::nv g, rxvt_img::nv b, rxvt_img::nv a = 1.) void -rxvt_img::contrast (NV r, NV g, NV b, NV a = 1.) +rxvt_img::contrast (rxvt_img::nv r, rxvt_img::nv g, rxvt_img::nv b, rxvt_img::nv a = 1.) rxvt_img * rxvt_img::clone () @@ -2216,20 +2361,20 @@ rxvt_img::blur (int rh, int rv) rxvt_img * -rxvt_img::transform (int new_width, int new_height, NV p11, NV p12, NV p13, NV p21, NV p22, NV p23, NV p31, NV p32, NV p33) +rxvt_img::transform (rxvt_img::nv p11, rxvt_img::nv p12, rxvt_img::nv p13, rxvt_img::nv p21, rxvt_img::nv p22, rxvt_img::nv p23, rxvt_img::nv p31, rxvt_img::nv p32, rxvt_img::nv p33) INIT: - double matrix[9] = { - p11, p12, p13, - p21, p22, p23, - p31, p32, p33 + rxvt_img::nv matrix[3][3] = { + { p11, p12, p13 }, + { p21, p22, p23 }, + { p31, p32, p33 } }; - C_ARGS: new_width, new_height, matrix + C_ARGS: matrix rxvt_img * rxvt_img::scale (int new_width, int new_height) rxvt_img * -rxvt_img::rotate (int new_width, int new_height, int x, int y, NV phi) +rxvt_img::rotate (int x, int y, rxvt_img::nv phi) #endif