--- rxvt-unicode/src/rxvtperl.xs 2012/07/07 07:00:17 1.206 +++ rxvt-unicode/src/rxvtperl.xs 2021/11/21 23:00:48 1.255 @@ -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) @@ -504,7 +531,7 @@ } bool -rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) +rxvt_perl_interp::invoke (rxvt_term *term, int htype, ...) { if (!perl || !term->perl.self) return false; @@ -793,6 +820,12 @@ 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 (HOOK_OSC_SEQ), + const_iv (HOOK_OSC_SEQ_PERL), + const_iv (NUM_RESOURCES), const_iv (DEFAULT_RSTYLE), const_iv (OVERLAY_RSTYLE), @@ -813,6 +846,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 +1030,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 +1067,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 +1252,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 +1327,7 @@ ungrab (THIS); int -rxvt_term::XStringToKeysym (char *string) +rxvt_term::XStringToKeysym (octet_string string) CODE: RETVAL = XStringToKeysym (string); OUTPUT: RETVAL @@ -1265,7 +1347,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 @@ -1294,6 +1376,9 @@ rxvt_term::locale_encode (SV *str) CODE: { + if (!SvOK (str)) + XSRETURN_UNDEF; + wchar_t *wstr = sv2wcs (str); rxvt_push_locale (THIS->locale); @@ -1312,6 +1397,9 @@ rxvt_term::locale_decode (SV *octets) CODE: { + if (!SvOK (octets)) + XSRETURN_UNDEF; + STRLEN len; char *data = SvPVbyte (octets, len); @@ -1345,7 +1433,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 +1453,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 +1466,7 @@ ModNumLockMask = 2 current_screen = 3 hidden_cursor = 4 + priv_modes = 5 CODE: switch (ix) { @@ -1385,7 +1476,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 @@ -1478,14 +1572,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 @@ -1532,6 +1625,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: { @@ -1684,6 +1780,7 @@ rxvt_pop_locale (); + free (wstr); RETVAL = wcs2sv (rstr, r - rstr); } OUTPUT: @@ -1701,7 +1798,7 @@ if (*s == NOCHAR) ; else if (IS_COMPOSE (*s)) - dlen += rxvt_composite.expand (*s, 0); + dlen += rxvt_composite.expand (*s); else dlen++; @@ -1717,13 +1814,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 [] = { @@ -1748,7 +1846,7 @@ else { --rs; - name = ""; + name = (octet_string)""; } if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) @@ -1771,7 +1869,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) @@ -1800,6 +1898,7 @@ #endif case Opt_cursorUnderline: + THIS->cursor_type = set ? 1 : 0; THIS->want_refresh = 1; THIS->refresh_check (); break; @@ -1814,10 +1913,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 @@ -1826,7 +1937,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 @@ -1879,7 +1990,7 @@ { THIS->selection.screen = THIS->current_screen; - THIS->want_refresh = 1; + THIS->selection_changed (); THIS->refresh_check (); } } @@ -1895,6 +2006,9 @@ RETVAL void +rxvt_term::selection_request (Time tm, int selnum) + +void rxvt_term::selection_clear (bool clipboard = false) void @@ -1945,7 +2059,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) @@ -1960,6 +2074,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; @@ -2203,15 +2325,21 @@ #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 @@ -2229,7 +2357,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; @@ -2237,8 +2364,6 @@ #endif -#endif - ############################################################################# # urxvt::overlay ############################################################################# @@ -2318,7 +2443,9 @@ 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); + rxvt_screen screen; + screen.set (THIS->d); + rgba cc = parse_rgba (c, &screen); C_ARGS: cc, x, y, w, h void @@ -2386,10 +2513,15 @@ rxvt_img * rxvt_img::tint (SV *c) INIT: - rgba cc = parse_rgba (c, THIS->s); + 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; @@ -2397,20 +2529,18 @@ if (SvOK (params)) { - // we overlay rxvt_temp_buf, what a hack - assert (sizeof (rxvt_img::nv) >= sizeof (int)); - 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_temp_buf (nparams); + 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