--- rxvt-unicode/src/rxvtperl.xs 2012/06/14 18:59:39 1.198 +++ rxvt-unicode/src/rxvtperl.xs 2021/07/14 13:52:24 1.252 @@ -3,11 +3,11 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2005-2008,2011 Marc Lehmann + * Copyright (c) 2005-2014 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -59,6 +59,7 @@ #if HAVE_PIXBUF typedef GdkPixbuf * urxvt__pixbuf; #endif +#if HAVE_IMG typedef rxvt_img * urxvt__img; typedef rxvt_img::nv rxvt_img__nv; @@ -83,15 +84,15 @@ c.a = rgba::MAX_CC; - c.r = c.g = c.b = float_to_component (SvIV (*av_fetch (av, 0, 0))); + c.r = c.g = c.b = float_to_component (SvNV (*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))); + c.g = float_to_component (SvNV (*av_fetch (av, 1, 0))); + c.b = float_to_component (SvNV (*av_fetch (av, 2, 0))); if (len >= 4) - c.a = float_to_component (SvIV (*av_fetch (av, 3, 0))); + c.a = float_to_component (SvNV (*av_fetch (av, 3, 0))); } } else if (s) @@ -107,6 +108,7 @@ } ///////////////////////////////////////////////////////////////////////////// +#endif static wchar_t * sv2wcs (SV *sv) @@ -291,7 +293,7 @@ for (; i < AvFILL (overlay_av); i++) av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0))); - av_pop (overlay_av); + SvREFCNT_dec (av_pop (overlay_av)); SvREFCNT_dec (overlay_av); overlay_av = 0; @@ -370,15 +372,20 @@ static PerlInterpreter *perl; +#if 0 /* we are not a library anymore, so doing this is just not worth it */ +/*THINK/TODO: this has the side effect of, of course, not calling destructors. */ +/* but therse are not guaranteed anyway... */ rxvt_perl_interp::~rxvt_perl_interp () { if (perl) { + localise_env set_environ (perl_environ); perl_destruct (perl); perl_free (perl); PERL_SYS_TERM (); } } +#endif void rxvt_perl_interp::init () @@ -391,7 +398,7 @@ perl_environ = rxvt_environ; localise_env set_environ (perl_environ); - char *args[] = { + const char *args[] = { "", "-e" "BEGIN {" @@ -399,10 +406,11 @@ " unshift @INC, '" LIBDIR "';" "}" "" - "use urxvt;" + "use urxvt;", + 0 }; - int argc = ecb_array_length (args); - char **argv = args; + int argc = ecb_array_length (args) - 1; + char **argv = (char **)args; PERL_SYS_INIT3 (&argc, &argv, &environ); perl = perl_alloc (); @@ -493,6 +501,25 @@ } static void +_keysym_resource_push (rxvt_term *term, const char *k, const char *v) +{ + unsigned int state; + + if (term->parse_keysym (k, state) == -1) + return; + + dSP; + XPUSHs (sv_2mortal (newSVpv (v, 0))); + PUTBACK; +} + +static void +_keysym_resources (rxvt_term *term) +{ + term->enumerate_keysym_resources (_keysym_resource_push); +} + +static void ungrab (rxvt_term *THIS) { if (THIS->perl.grabtime) @@ -793,6 +820,10 @@ IV iv; } *civ, const_iv[] = { # define const_iv(name) { # name, (IV)name } + const_iv (HOOK_INIT), + const_iv (HOOK_DESTROY), + const_iv (HOOK_ACTION), + const_iv (NUM_RESOURCES), const_iv (DEFAULT_RSTYLE), const_iv (OVERLAY_RSTYLE), @@ -813,6 +844,18 @@ const_iv (RS_RVid), const_iv (RS_Uline), + // TODO: should support all colour constants, create colorinc.h &c + const_iv (Color_fg), + const_iv (Color_bg), +#if OFF_FOCUS_FADING + const_iv (Color_fade), +#endif + const_iv (Color_pointer_fg), + const_iv (Color_pointer_bg), + const_iv (Color_border), + const_iv (NRS_COLORS), + const_iv (TOTAL_COLORS), + const_iv (CurrentTime), const_iv (ShiftMask), const_iv (LockMask), @@ -985,6 +1028,36 @@ const_iv (XIMDontChange), # endif # endif + + /* DEC private modes */ + const_iv (PrivMode_132), + const_iv (PrivMode_132OK), + const_iv (PrivMode_rVideo), + const_iv (PrivMode_relOrigin), + const_iv (PrivMode_Screen), + const_iv (PrivMode_Autowrap), + const_iv (PrivMode_aplCUR), + const_iv (PrivMode_aplKP), + const_iv (PrivMode_HaveBackSpace), + const_iv (PrivMode_BackSpace), + const_iv (PrivMode_ShiftKeys), + const_iv (PrivMode_VisibleCursor), + const_iv (PrivMode_MouseX10), + const_iv (PrivMode_MouseX11), + const_iv (PrivMode_scrollBar), + const_iv (PrivMode_TtyOutputInh), + const_iv (PrivMode_Keypress), + const_iv (PrivMode_smoothScroll), + const_iv (PrivMode_vt52), + const_iv (PrivMode_LFNL), + const_iv (PrivMode_MouseBtnEvent), + const_iv (PrivMode_MouseAnyEvent), + const_iv (PrivMode_BracketPaste), + const_iv (PrivMode_ExtMouseUTF8), + const_iv (PrivMode_ExtMouseUrxvt), + const_iv (PrivMode_BlinkingCursor), + const_iv (PrivMode_mouse_report), + const_iv (PrivMode_Default), }; for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--) @@ -992,17 +1065,17 @@ } void -log (const char *msg) +log (utf8_string msg) CODE: rxvt_log ("%s", msg); void -warn (const char *msg) +warn (utf8_string msg) CODE: rxvt_warn ("%s", msg); void -fatal (const char *msg) +fatal (utf8_string msg) CODE: rxvt_fatal ("%s", msg); @@ -1177,6 +1250,13 @@ CODE: XrmPutStringResource (&THIS->option_db, specifier, value); +void +rxvt_term::_keysym_resources () + PPCODE: + PUTBACK; + _keysym_resources (THIS); + SPAGAIN; + int rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) CODE: @@ -1245,7 +1325,7 @@ ungrab (THIS); int -rxvt_term::XStringToKeysym (char *string) +rxvt_term::XStringToKeysym (octet_string string) CODE: RETVAL = XStringToKeysym (string); OUTPUT: RETVAL @@ -1265,7 +1345,7 @@ int rxvt_term::XKeycodeToKeysym (int code, int index) CODE: - RETVAL = XKeycodeToKeysym (THIS->dpy, code, index); + RETVAL = rxvt_XKeycodeToKeysym (THIS->dpy, code, index); OUTPUT: RETVAL int @@ -1345,7 +1425,7 @@ #define TERM_OFFSET_top_row TERM_OFFSET(top_row) int -rxvt_term::width () +rxvt_term::width (int new_value = NO_INIT) ALIAS: width = TERM_OFFSET_width height = TERM_OFFSET_height @@ -1365,6 +1445,8 @@ top_row = TERM_OFFSET_top_row CODE: RETVAL = *(int *)((char *)THIS + ix); + if (items > 1) + *(int *)((char *)THIS + ix) = new_value; OUTPUT: RETVAL @@ -1376,6 +1458,7 @@ ModNumLockMask = 2 current_screen = 3 hidden_cursor = 4 + priv_modes = 5 CODE: switch (ix) { @@ -1385,7 +1468,10 @@ case 3: RETVAL = THIS->current_screen; break; #ifdef CURSOR_BLINK case 4: RETVAL = THIS->hidden_cursor; break; +#else + case 4: RETVAL = 0; break; #endif + case 5: RETVAL = THIS->priv_modes; break; } OUTPUT: RETVAL @@ -1456,6 +1542,13 @@ OUTPUT: RETVAL +Window +rxvt_term::vt () + CODE: + RETVAL = THIS->vt; + OUTPUT: + RETVAL + void rxvt_term::vt_emask_add (U32 emask) CODE: @@ -1471,14 +1564,13 @@ RETVAL int -rxvt_term::view_start (int newval = 1) +rxvt_term::view_start (int newval = 0) PROTOTYPE: $;$ CODE: { RETVAL = THIS->view_start; - - if (newval <= 0) - THIS->scr_changeview (max (newval, THIS->top_row)); + if (items > 1) + THIS->scr_changeview (newval); } OUTPUT: RETVAL @@ -1525,6 +1617,9 @@ THIS->refresh_check (); void +rxvt_term::refresh_check () + +void rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) PPCODE: { @@ -1677,6 +1772,7 @@ rxvt_pop_locale (); + free (wstr); RETVAL = wcs2sv (rstr, r - rstr); } OUTPUT: @@ -1694,7 +1790,7 @@ if (*s == NOCHAR) ; else if (IS_COMPOSE (*s)) - dlen += rxvt_composite.expand (*s, 0); + dlen += rxvt_composite.expand (*s); else dlen++; @@ -1710,13 +1806,14 @@ else *r++ = *s; + free (wstr); RETVAL = wcs2sv (rstr, r - rstr); } OUTPUT: RETVAL void -rxvt_term::_resource (char *name, int index, SV *newval = 0) +rxvt_term::_resource (octet_string name, int index, SV *newval = 0) PPCODE: { static const struct resval { const char *name; int value; } *rs, rslist [] = { @@ -1741,7 +1838,7 @@ else { --rs; - name = ""; + name = (octet_string)""; } if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) @@ -1764,7 +1861,7 @@ } const char * -rxvt_term::x_resource (const char *name) +rxvt_term::x_resource (octet_string name) bool rxvt_term::option (U8 optval, int set = -1) @@ -1793,6 +1890,7 @@ #endif case Opt_cursorUnderline: + THIS->cursor_type = set ? 1 : 0; THIS->want_refresh = 1; THIS->refresh_check (); break; @@ -1807,10 +1905,22 @@ OUTPUT: RETVAL +SV * +rxvt_term::lookup_keysym (int keysym, unsigned int state) + CODE: +{ + keysym_t *key = THIS->keyboard->lookup_keysym (THIS, keysym, state); + RETVAL = key ? sv_2mortal (newSVpv (key->str, 0)) : &PL_sv_undef; +} + OUTPUT: + RETVAL + bool -rxvt_term::parse_keysym (char *keysym, char *str) +rxvt_term::bind_action (octet_string keysym, octet_string action) + ALIAS: + parse_keysym = 1 CODE: - RETVAL = 0 < THIS->parse_keysym (keysym, str); + RETVAL = 0 < THIS->bind_action (keysym, action); THIS->keyboard->register_done (); OUTPUT: RETVAL @@ -1819,7 +1929,7 @@ rxvt_term::register_command (int keysym, unsigned int state, SV *str) CODE: wchar_t *wstr = sv2wcs (str); - THIS->keyboard->register_user_translation (keysym, state, wstr); + THIS->keyboard->register_action (keysym, state, wstr); free (wstr); void @@ -1872,7 +1982,7 @@ { THIS->selection.screen = THIS->current_screen; - THIS->want_refresh = 1; + THIS->selection_changed (); THIS->refresh_check (); } } @@ -1888,6 +1998,9 @@ RETVAL void +rxvt_term::selection_request (Time tm, int selnum) + +void rxvt_term::selection_clear (bool clipboard = false) void @@ -1938,7 +2051,7 @@ rxvt_term::scr_bell () void -rxvt_term::scr_recolour (bool refresh = true); +rxvt_term::scr_recolor (bool refresh = true); void rxvt_term::scr_change_screen (int screen) @@ -1953,6 +2066,14 @@ } void +rxvt_term::tt_write_user_input (SV *octets) + INIT: + STRLEN len; + char *str = SvPVbyte (octets, len); + C_ARGS: + str, len + +void rxvt_term::tt_write (SV *octets) INIT: STRLEN len; @@ -2157,7 +2278,7 @@ #if HAVE_IMG rxvt_img * -rxvt_term::new_img (SV *format, int x = 0, int y = 0, int width = 1, int height = 1) +rxvt_term::new_img (SV *format = &PL_sv_undef, int x = 0, int y = 0, int width = 1, int height = 1) CODE: XRenderPictFormat *f = SvOK (format) ? XRenderFindStandardFormat (THIS->dpy, SvIV (format)) @@ -2196,23 +2317,29 @@ #endif -#if HAVE_BG_PIXMAP +void +rxvt_term::clr_background () + CODE: + delete THIS->bg_img; + THIS->bg_img = 0; + THIS->bg_flags = rxvt_term::BG_NEEDS_REFRESH; void rxvt_term::set_background (rxvt_img *img, bool border = false) CODE: - THIS->bg_destroy (); - THIS->bg_flags &= ~(rxvt_term::BG_NEEDS_REFRESH | rxvt_term::BG_INHIBIT_RENDER | rxvt_term::BG_IS_TRANSPARENT); + delete THIS->bg_img; + THIS->bg_img = 0; + THIS->bg_flags = rxvt_term::BG_NEEDS_REFRESH; - if (img) // TODO: cannot be false + //if (img) // TODO: cannot be false, maybe allow and get rid of clr_background? { 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); + 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 () @@ -2222,7 +2349,6 @@ ->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; @@ -2230,8 +2356,6 @@ #endif -#endif - ############################################################################# # urxvt::overlay ############################################################################# @@ -2262,7 +2386,7 @@ void DESTROY (urxvt::pixbuf self) CODE: - gdk_pixbuf_unref (self); + g_object_unref (self); #endif @@ -2284,29 +2408,19 @@ int rxvt_img::x () + ALIAS: + x = 0 + y = 1 + w = 2 + h = 3 CODE: - RETVAL = THIS->x; - OUTPUT: - RETVAL - -int -rxvt_img::y () - CODE: - RETVAL = THIS->y; - OUTPUT: - RETVAL - -int -rxvt_img::w () - CODE: - RETVAL = THIS->w; - OUTPUT: - RETVAL - -int -rxvt_img::h () - CODE: - RETVAL = THIS->h; + switch (ix) + { + case 0: RETVAL = THIS->x; break; + case 1: RETVAL = THIS->y; break; + case 2: RETVAL = THIS->w; break; + case 3: RETVAL = THIS->h; break; + } OUTPUT: RETVAL @@ -2318,10 +2432,13 @@ RETVAL void -rxvt_img::fill (SV *c) +rxvt_img::fill (SV *c, int x = 0, int y = 0, int w = THIS->w, int h = THIS->h) + PROTOTYPE: $;$$$$ INIT: - rgba cc = parse_rgba (c, THIS->s); - C_ARGS: cc + rxvt_screen screen; + screen.set (THIS->d); + rgba cc = parse_rgba (c, &screen); + C_ARGS: cc, x, y, w, h void rxvt_img::DESTROY () @@ -2329,11 +2446,14 @@ delete THIS; void +rxvt_img::add_alpha () + +void rxvt_img::unshare () -int +void rxvt_img::repeat_mode (render_repeat_mode repeat = 0) - CODE: + PPCODE: if (items >= 2) THIS->repeat_mode (repeat); if (GIMME_V != G_VOID) @@ -2348,6 +2468,9 @@ void rxvt_img::contrast (rxvt_img::nv r, rxvt_img::nv g, rxvt_img::nv b, rxvt_img::nv a = 1.) +void +rxvt_img::draw (rxvt_img *img, int op = PictOpOver, rxvt_img::nv mask = 1.); + rxvt_img * rxvt_img::clone () @@ -2361,6 +2484,9 @@ rxvt_img::blur (int rh, int rv) rxvt_img * +rxvt_img::muladd (rxvt_img::nv mul, rxvt_img::nv add) + +rxvt_img * 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: rxvt_img::nv matrix[3][3] = { @@ -2376,5 +2502,39 @@ rxvt_img * rxvt_img::rotate (int x, int y, rxvt_img::nv phi) +rxvt_img * +rxvt_img::tint (SV *c) + INIT: + rxvt_screen screen; + screen.set (THIS->d); + rgba cc = parse_rgba (c, &screen); + C_ARGS: cc + +rxvt_img * +rxvt_img::shade (rxvt_img::nv factor) + +rxvt_img * +rxvt_img::filter (octet_string name, SV *params = &PL_sv_undef) + CODE: + rxvt_img::nv *vparams = 0; + int nparams = 0; + + if (SvOK (params)) + { + if (!SvROK (params) || SvTYPE (SvRV (params)) != SVt_PVAV) + croak ("rxvt_img::filter: params must be an array reference with parameter values"); + + nparams = av_len ((AV *)SvRV (params)) + 1; + vparams = (rxvt_img::nv *)malloc (nparams * sizeof (rxvt_img::nv)); + + for (int i = 0; i < nparams; ++i) + vparams [i] = SvNV (*av_fetch ((AV *)SvRV (params), i, 1)); + } + + RETVAL = THIS->filter (name, nparams, vparams); + free (vparams); + OUTPUT: + RETVAL + #endif