--- rxvt-unicode/src/rxvtperl.xs 2014/09/05 19:02:53 1.228 +++ rxvt-unicode/src/rxvtperl.xs 2023/07/25 18:06:07 1.261 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2005-2014,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 @@ -32,7 +32,14 @@ #include #include -#include "unistd.h" +#include + +#include + +// support old includes (https://bugs.freedesktop.org/show_bug.cgi?id=2799, https://lists.x.org/archives/xorg-arch/2005-March/000004.html) +#ifndef ShapeInput +# define ShapeInput 2 +#endif #include "ev_cpp.h" #include "rxvt.h" @@ -84,15 +91,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) @@ -293,7 +300,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; @@ -372,28 +379,33 @@ 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 these 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 () { if (!perl) { - rxvt_push_locale (""); // perl init destroys current locale + rxvt_push_locale ("C"); // perl init destroys current locale { perl_environ = rxvt_environ; localise_env set_environ (perl_environ); - char *args[] = { + const char *args[] = { "", "-e" "BEGIN {" @@ -401,10 +413,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 (); @@ -525,7 +538,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; @@ -817,6 +830,8 @@ 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), @@ -841,15 +856,16 @@ // TODO: should support all colour constants, create colorinc.h &c const_iv (Color_fg), const_iv (Color_bg), -#if OFF_FOCUS_FADING +# if OFF_FOCUS_FADING const_iv (Color_fade), -#endif +# 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 (None), const_iv (CurrentTime), const_iv (ShiftMask), const_iv (LockMask), @@ -930,6 +946,19 @@ const_iv (ColormapNotify), const_iv (ClientMessage), const_iv (MappingNotify), + + // shape extension + const_iv (ShapeSet), + const_iv (ShapeUnion), + const_iv (ShapeIntersect), + const_iv (ShapeSubtract), + const_iv (ShapeInvert), + + const_iv (ShapeBounding), + const_iv (ShapeClip), + const_iv (ShapeInput), + + // XIM # if ENABLE_XIM_ONTHESPOT const_iv (XIMReverse), const_iv (XIMUnderline), @@ -940,7 +969,8 @@ const_iv (XIMVisibleToForward), const_iv (XIMVisibleToBackword), const_iv (XIMVisibleToCenter), -#if XRENDER +# endif +# if XRENDER const_iv (PictStandardARGB32), const_iv (PictStandardRGB24), const_iv (PictStandardA8), @@ -1006,7 +1036,7 @@ const_iv (PictOpHSLSaturation), const_iv (PictOpHSLColor), const_iv (PictOpHSLLuminosity), -#endif +# endif # if 0 const_iv (XIMForwardChar), const_iv (XIMBackwardChar), @@ -1021,7 +1051,36 @@ const_iv (XIMAbsolutePosition), 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--) @@ -1029,17 +1088,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); @@ -1109,7 +1168,7 @@ CODE: { if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) - croak ("custom value out of range, must be 0..%d", RS_customCount - 1); + croak ("custom value out of range, must be 0..%lu", RS_customCount - 1); RETVAL = (rend & ~RS_customMask) | ((new_value << RS_customShift) & RS_customMask); @@ -1157,6 +1216,41 @@ delete req; +Region +XCreateRegion () + +int +XUnionRectWithRegion (int x, int y, int w, int h, Region src, Region dst) + CODE: + XRectangle rect; + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + RETVAL = XUnionRectWithRegion (&rect, src, dst); + OUTPUT: RETVAL + +int +XIntersectRegion (Region src1, Region src2, Region res) + +int +XUnionRegion (Region src1, Region src2, Region res) + +int +XSubtractRegion (Region src1, Region src2, Region res) + +int +XXorRegion (Region src1, Region src2, Region res) + +int +XOffsetRegion (Region r, int dx, int dy) + +int +XShrinkRegion (Region r, int dx, int dy) + +int +XDestroyRegion (Region r) + MODULE = urxvt PACKAGE = urxvt::term SV * @@ -1289,7 +1383,7 @@ ungrab (THIS); int -rxvt_term::XStringToKeysym (char *string) +rxvt_term::XStringToKeysym (octet_string string) CODE: RETVAL = XStringToKeysym (string); OUTPUT: RETVAL @@ -1338,6 +1432,9 @@ rxvt_term::locale_encode (SV *str) CODE: { + if (!SvOK (str)) + XSRETURN_UNDEF; + wchar_t *wstr = sv2wcs (str); rxvt_push_locale (THIS->locale); @@ -1356,6 +1453,9 @@ rxvt_term::locale_decode (SV *octets) CODE: { + if (!SvOK (octets)) + XSRETURN_UNDEF; + STRLEN len; char *data = SvPVbyte (octets, len); @@ -1389,7 +1489,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 @@ -1409,6 +1509,8 @@ top_row = TERM_OFFSET_top_row CODE: RETVAL = *(int *)((char *)THIS + ix); + if (items > 1) + *(int *)((char *)THIS + ix) = new_value; OUTPUT: RETVAL @@ -1420,6 +1522,7 @@ ModNumLockMask = 2 current_screen = 3 hidden_cursor = 4 + priv_modes = 5 CODE: switch (ix) { @@ -1429,7 +1532,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 @@ -1522,14 +1628,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 @@ -1576,6 +1681,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: { @@ -1728,6 +1836,7 @@ rxvt_pop_locale (); + free (wstr); RETVAL = wcs2sv (rstr, r - rstr); } OUTPUT: @@ -1745,7 +1854,7 @@ if (*s == NOCHAR) ; else if (IS_COMPOSE (*s)) - dlen += rxvt_composite.expand (*s, 0); + dlen += rxvt_composite.expand (*s); else dlen++; @@ -1761,13 +1870,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 [] = { @@ -1792,7 +1902,7 @@ else { --rs; - name = ""; + name = (octet_string)""; } if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) @@ -1815,7 +1925,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) @@ -1859,17 +1969,34 @@ 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::bind_action (char *keysym, char *str) +rxvt_term::bind_action (octet_string keysym, octet_string action) ALIAS: parse_keysym = 1 CODE: - RETVAL = 0 < THIS->bind_action (keysym, str); + RETVAL = 0 < THIS->bind_action (keysym, action); THIS->keyboard->register_done (); OUTPUT: RETVAL void +rxvt_term::register_command (int keysym, unsigned int state, SV *str) + CODE: + wchar_t *wstr = sv2wcs (str); + THIS->keyboard->register_action (keysym, state, wstr); + free (wstr); + +void rxvt_term::screen_cur (...) PROTOTYPE: $;$$ ALIAS: @@ -1988,7 +2115,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) @@ -2071,7 +2198,7 @@ EXTEND (SP, count); while (count--) - PUSHs (newSVuv ((U32)props [count])); + PUSHs (sv_2mortal (newSVuv ((U32)props [count]))); XFree (props); } @@ -2097,9 +2224,9 @@ : 1; EXTEND (SP, 3); - PUSHs (newSVuv ((U32)type)); - PUSHs (newSViv (format)); - PUSHs (newSVpvn ((char *)prop, nitems * elemsize)); + PUSHs (sv_2mortal (newSVuv ((U32)type))); + PUSHs (sv_2mortal (newSViv (format))); + PUSHs (sv_2mortal (newSVpvn ((char *)prop, nitems * elemsize))); XFree (prop); } } @@ -2134,6 +2261,29 @@ XDeleteProperty (rxvt_term *term, Window window, Atom property) C_ARGS: term->dpy, window, property +void +rxvt_term::XShapeQueryVersion () + PPCODE: + int major, minor; + EXTEND (SP, 2); + if (XShapeQueryVersion (THIS->display->dpy, &major, &minor)) + { + PUSHs (sv_2mortal (newSViv (major))); + PUSHs (sv_2mortal (newSViv (minor))); + } + +void +XShapeCombineRegion (rxvt_term *term, Window dest, int destKind, int xOff, int yOff, Region r, int op) + C_ARGS: term->display->dpy, dest, destKind, xOff, yOff, r, op + +void +XShapeCombineMask (rxvt_term *term, XID dest, int destKind, int xOff, int yOff, Pixmap src, int op) + C_ARGS: term->display->dpy, dest, destKind, xOff, yOff, src, op + +void +XShapeCombineShape (rxvt_term *term, XID dest, int destKind, int xOff, int yOff, Pixmap src, int srcKind, int op) + C_ARGS: term->display->dpy, dest, destKind, xOff, yOff, src, srcKind, op + Window rxvt_term::DefaultRootWindow () CODE: @@ -2187,9 +2337,9 @@ if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child)) { EXTEND (SP, 3); - PUSHs (newSViv (dx)); - PUSHs (newSViv (dy)); - PUSHs (newSVuv (child)); + PUSHs (sv_2mortal (newSViv (dx))); + PUSHs (sv_2mortal (newSViv (dy))); + PUSHs (sv_2mortal (newSVuv (child))); } } @@ -2255,13 +2405,20 @@ #endif 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: delete THIS->bg_img; THIS->bg_img = 0; - THIS->bg_flags = 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 @@ -2279,7 +2436,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; @@ -2366,7 +2522,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 @@ -2434,7 +2592,9 @@ 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 *