1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
31 | #include <cstddef> |
31 | #include <cstddef> |
32 | #include <cstdarg> |
32 | #include <cstdarg> |
33 | |
33 | |
34 | #include "unistd.h" |
34 | #include "unistd.h" |
35 | |
35 | |
36 | #include "iom.h" |
36 | #include "ev_cpp.h" |
37 | #include "rxvt.h" |
37 | #include "rxvt.h" |
38 | #include "keyboard.h" |
38 | #include "keyboard.h" |
39 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
40 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
41 | |
41 | |
42 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
43 | |
43 | |
44 | #ifdef HAVE_SCROLLBARS |
|
|
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
44 | #define GRAB_CURSOR THIS->scrollBar.leftptr_cursor |
46 | #else |
|
|
47 | # define GRAB_CURSOR None |
|
|
48 | #endif |
|
|
49 | |
45 | |
50 | #undef LINENO |
46 | #undef LINENO |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
47 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
52 | #undef ROW |
48 | #undef ROW |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
49 | #define ROW(n) THIS->row_buf [LINENO (n)] |
… | |
… | |
214 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
210 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
215 | )); |
211 | )); |
216 | av_push (overlay_av, newSViv ((long)this)); |
212 | av_push (overlay_av, newSViv ((long)this)); |
217 | |
213 | |
218 | THIS->want_refresh = 1; |
214 | THIS->want_refresh = 1; |
|
|
215 | THIS->refresh_check (); |
219 | } |
216 | } |
220 | |
217 | |
221 | void |
218 | void |
222 | overlay::hide () |
219 | overlay::hide () |
223 | { |
220 | { |
… | |
… | |
237 | |
234 | |
238 | SvREFCNT_dec (overlay_av); |
235 | SvREFCNT_dec (overlay_av); |
239 | overlay_av = 0; |
236 | overlay_av = 0; |
240 | |
237 | |
241 | THIS->want_refresh = 1; |
238 | THIS->want_refresh = 1; |
|
|
239 | THIS->refresh_check (); |
242 | } |
240 | } |
243 | |
241 | |
244 | void overlay::swap () |
242 | void overlay::swap () |
245 | { |
243 | { |
246 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
244 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
… | |
… | |
291 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
289 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
292 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
290 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
293 | } |
291 | } |
294 | |
292 | |
295 | THIS->want_refresh = 1; |
293 | THIS->want_refresh = 1; |
|
|
294 | THIS->refresh_check (); |
296 | } |
295 | } |
297 | |
296 | |
298 | ///////////////////////////////////////////////////////////////////////////// |
297 | ///////////////////////////////////////////////////////////////////////////// |
299 | |
298 | |
300 | #define IOM_CLASS "urxvt" |
299 | #define IOM_CLASS "urxvt" |
301 | #define IOM_WARN rxvt_warn |
300 | #define IOM_WARN rxvt_warn |
302 | #include <iom_perl.h> |
301 | #include "iom_perl.h" |
303 | |
302 | |
304 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
305 | |
304 | |
306 | struct rxvt_perl_interp rxvt_perl; |
305 | struct rxvt_perl_interp rxvt_perl; |
307 | |
306 | |
… | |
… | |
311 | { |
310 | { |
312 | if (perl) |
311 | if (perl) |
313 | { |
312 | { |
314 | perl_destruct (perl); |
313 | perl_destruct (perl); |
315 | perl_free (perl); |
314 | perl_free (perl); |
|
|
315 | PERL_SYS_TERM (); |
316 | } |
316 | } |
317 | } |
317 | } |
318 | |
318 | |
319 | void |
319 | void |
320 | rxvt_perl_interp::init (rxvt_term *term) |
320 | rxvt_perl_interp::init (rxvt_term *term) |
… | |
… | |
324 | rxvt_push_locale (""); // perl init destroys current locale |
324 | rxvt_push_locale (""); // perl init destroys current locale |
325 | |
325 | |
326 | perl_environ = rxvt_environ; |
326 | perl_environ = rxvt_environ; |
327 | swap (perl_environ, environ); |
327 | swap (perl_environ, environ); |
328 | |
328 | |
329 | char *argv[] = { |
329 | char *args[] = { |
330 | "", |
330 | "", |
331 | "-e" |
331 | "-e" |
332 | "BEGIN {" |
332 | "BEGIN {" |
333 | " urxvt->bootstrap;" |
333 | " urxvt->bootstrap;" |
334 | " unshift @INC, '" LIBDIR "';" |
334 | " unshift @INC, '" LIBDIR "';" |
335 | "}" |
335 | "}" |
336 | "" |
336 | "" |
337 | "use urxvt;" |
337 | "use urxvt;" |
338 | }; |
338 | }; |
|
|
339 | int argc = sizeof (args) / sizeof (args[0]); |
|
|
340 | char **argv = args; |
339 | |
341 | |
|
|
342 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
340 | perl = perl_alloc (); |
343 | perl = perl_alloc (); |
341 | perl_construct (perl); |
344 | perl_construct (perl); |
342 | |
345 | |
343 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
346 | if (perl_parse (perl, xs_init, argc, argv, (char **)NULL) |
344 | || perl_run (perl)) |
347 | || perl_run (perl)) |
345 | { |
348 | { |
346 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
349 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
347 | |
350 | |
348 | perl_destruct (perl); |
351 | perl_destruct (perl); |
… | |
… | |
382 | |
385 | |
383 | // pre-handling of some events |
386 | // pre-handling of some events |
384 | if (htype == HOOK_REFRESH_END) |
387 | if (htype == HOOK_REFRESH_END) |
385 | { |
388 | { |
386 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
389 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
387 | |
390 | |
388 | for (int i = 0; i <= AvFILL (av); i++) |
391 | for (int i = 0; i <= AvFILL (av); i++) |
389 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
392 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
390 | } |
393 | } |
391 | |
394 | |
392 | swap (perl_environ, environ); |
395 | swap (perl_environ, environ); |
… | |
… | |
591 | |
594 | |
592 | // post-handling of some events |
595 | // post-handling of some events |
593 | if (htype == HOOK_REFRESH_BEGIN) |
596 | if (htype == HOOK_REFRESH_BEGIN) |
594 | { |
597 | { |
595 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
598 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
596 | |
599 | |
597 | for (int i = AvFILL (av); i >= 0; i--) |
600 | for (int i = AvFILL (av); i >= 0; i--) |
598 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
601 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
599 | } |
602 | } |
600 | else if (htype == HOOK_DESTROY) |
603 | else if (htype == HOOK_DESTROY) |
601 | { |
604 | { |
602 | clearSVptr ((SV *)term->perl.self); |
605 | clearSVptr ((SV *)term->perl.self); |
603 | SvREFCNT_dec ((SV *)term->perl.self); |
606 | SvREFCNT_dec ((SV *)term->perl.self); |
604 | |
607 | |
605 | // don't allow further calls |
608 | // don't allow further calls |
606 | term->perl.self = 0; |
609 | term->perl.self = 0; |
607 | } |
610 | } |
608 | |
611 | |
609 | swap (perl_environ, environ); |
612 | swap (perl_environ, environ); |
… | |
… | |
640 | static const struct { |
643 | static const struct { |
641 | const char *name; |
644 | const char *name; |
642 | IV iv; |
645 | IV iv; |
643 | } *civ, const_iv[] = { |
646 | } *civ, const_iv[] = { |
644 | # define const_iv(name) { # name, (IV)name } |
647 | # define const_iv(name) { # name, (IV)name } |
|
|
648 | const_iv (NUM_RESOURCES), |
645 | const_iv (DEFAULT_RSTYLE), |
649 | const_iv (DEFAULT_RSTYLE), |
646 | const_iv (OVERLAY_RSTYLE), |
650 | const_iv (OVERLAY_RSTYLE), |
647 | const_iv (RS_Bold), |
651 | const_iv (RS_Bold), |
648 | const_iv (RS_Italic), |
652 | const_iv (RS_Italic), |
649 | const_iv (RS_Blink), |
653 | const_iv (RS_Blink), |
… | |
… | |
775 | _exit (int status) |
779 | _exit (int status) |
776 | |
780 | |
777 | NV |
781 | NV |
778 | NOW () |
782 | NOW () |
779 | CODE: |
783 | CODE: |
780 | RETVAL = NOW; |
784 | RETVAL = ev::now (); |
781 | OUTPUT: |
785 | OUTPUT: |
782 | RETVAL |
786 | RETVAL |
783 | |
787 | |
784 | int |
788 | int |
785 | GET_BASEFG (int rend) |
789 | GET_BASEFG (int rend) |
… | |
… | |
857 | for (int i = AvFILL (env) + 1; i--; ) |
861 | for (int i = AvFILL (env) + 1; i--; ) |
858 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
862 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
859 | |
863 | |
860 | envv->push_back (0); |
864 | envv->push_back (0); |
861 | |
865 | |
862 | bool success; |
|
|
863 | |
|
|
864 | try |
866 | try |
865 | { |
867 | { |
866 | success = term->init (argv, envv); |
868 | term->init (argv, envv); |
867 | } |
869 | } |
868 | catch (const class rxvt_failure_exception &e) |
870 | catch (const class rxvt_failure_exception &e) |
869 | { |
|
|
870 | success = false; |
|
|
871 | } |
|
|
872 | |
|
|
873 | if (!success) |
|
|
874 | { |
871 | { |
875 | term->destroy (); |
872 | term->destroy (); |
876 | croak ("error while initializing new terminal instance"); |
873 | croak ("error while initializing new terminal instance"); |
877 | } |
874 | } |
878 | |
875 | |
… | |
… | |
1104 | { |
1101 | { |
1105 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1102 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1106 | case 1: RETVAL = THIS->ModMetaMask; break; |
1103 | case 1: RETVAL = THIS->ModMetaMask; break; |
1107 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1104 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1108 | case 3: RETVAL = THIS->current_screen; break; |
1105 | case 3: RETVAL = THIS->current_screen; break; |
|
|
1106 | #ifdef CURSOR_BLINK |
1109 | case 4: RETVAL = THIS->hidden_cursor; break; |
1107 | case 4: RETVAL = THIS->hidden_cursor; break; |
|
|
1108 | #endif |
1110 | } |
1109 | } |
1111 | OUTPUT: |
1110 | OUTPUT: |
1112 | RETVAL |
1111 | RETVAL |
1113 | |
1112 | |
1114 | char * |
1113 | char * |
… | |
… | |
1139 | if (*i) |
1138 | if (*i) |
1140 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1139 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1141 | } |
1140 | } |
1142 | |
1141 | |
1143 | int |
1142 | int |
1144 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
1143 | rxvt_term::pty_ev_events (int events = ev::UNDEF) |
1145 | CODE: |
1144 | CODE: |
1146 | RETVAL = THIS->pty_ev.events; |
1145 | RETVAL = THIS->pty_ev.events; |
1147 | if (events != EVENT_UNDEF) |
1146 | if (events != ev::UNDEF) |
1148 | THIS->pty_ev.set (events); |
1147 | THIS->pty_ev.set (events); |
1149 | OUTPUT: |
1148 | OUTPUT: |
1150 | RETVAL |
1149 | RETVAL |
1151 | |
1150 | |
1152 | int |
1151 | int |
… | |
… | |
1231 | |
1230 | |
1232 | void |
1231 | void |
1233 | rxvt_term::want_refresh () |
1232 | rxvt_term::want_refresh () |
1234 | CODE: |
1233 | CODE: |
1235 | THIS->want_refresh = 1; |
1234 | THIS->want_refresh = 1; |
|
|
1235 | THIS->refresh_check (); |
1236 | |
1236 | |
1237 | void |
1237 | void |
1238 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1238 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1239 | PPCODE: |
1239 | PPCODE: |
1240 | { |
1240 | { |
… | |
… | |
1437 | # undef reserve |
1437 | # undef reserve |
1438 | }; |
1438 | }; |
1439 | |
1439 | |
1440 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1440 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1441 | |
1441 | |
|
|
1442 | if (*name) |
1442 | do { |
1443 | { |
|
|
1444 | do { |
1443 | if (rs-- == rslist) |
1445 | if (rs-- == rslist) |
1444 | croak ("no such resource '%s', requested", name); |
1446 | croak ("no such resource '%s', requested", name); |
1445 | } while (strcmp (name, rs->name)); |
1447 | } while (strcmp (name, rs->name)); |
1446 | |
1448 | |
1447 | index += rs->value; |
1449 | index += rs->value; |
|
|
1450 | } |
|
|
1451 | else |
|
|
1452 | { |
|
|
1453 | --rs; |
|
|
1454 | name = ""; |
|
|
1455 | } |
1448 | |
1456 | |
1449 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1457 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1450 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1458 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1451 | |
1459 | |
1452 | if (GIMME_V != G_VOID) |
1460 | if (GIMME_V != G_VOID) |
… | |
… | |
1476 | |
1484 | |
1477 | if (set >= 0) |
1485 | if (set >= 0) |
1478 | { |
1486 | { |
1479 | THIS->set_option (optval, set); |
1487 | THIS->set_option (optval, set); |
1480 | |
1488 | |
1481 | if (THIS->check_ev.is_active ()) // avoid doing this before START |
1489 | if (THIS->env_colorfgbg [0]) // avoid doing this before START |
1482 | switch (optval) |
1490 | switch (optval) |
1483 | { |
1491 | { |
1484 | case Opt_skipBuiltinGlyphs: |
1492 | case Opt_skipBuiltinGlyphs: |
1485 | THIS->set_fonts (); |
1493 | THIS->set_fonts (); |
1486 | THIS->scr_remap_chars (); |
1494 | THIS->scr_remap_chars (); |
1487 | THIS->scr_touch (true); |
1495 | THIS->scr_touch (true); |
1488 | THIS->want_refresh = 1; |
1496 | THIS->want_refresh = 1; |
|
|
1497 | THIS->refresh_check (); |
1489 | break; |
1498 | break; |
1490 | |
1499 | |
1491 | case Opt_cursorUnderline: |
1500 | case Opt_cursorUnderline: |
1492 | THIS->want_refresh = 1; |
1501 | THIS->want_refresh = 1; |
|
|
1502 | THIS->refresh_check (); |
1493 | break; |
1503 | break; |
1494 | |
1504 | |
1495 | # case Opt_scrollBar_floating: |
1505 | # case Opt_scrollBar_floating: |
1496 | # case Opt_scrollBar_right: |
1506 | # case Opt_scrollBar_right: |
1497 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
1507 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
… | |
… | |
1555 | |
1565 | |
1556 | clamp_it (rc.col, 0, THIS->ncol); |
1566 | clamp_it (rc.col, 0, THIS->ncol); |
1557 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1567 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1558 | |
1568 | |
1559 | if (ix) |
1569 | if (ix) |
|
|
1570 | { |
1560 | THIS->want_refresh = 1; |
1571 | THIS->want_refresh = 1; |
|
|
1572 | THIS->refresh_check (); |
|
|
1573 | } |
1561 | } |
1574 | } |
1562 | } |
1575 | } |
1563 | |
1576 | |
1564 | char |
1577 | char |
1565 | rxvt_term::cur_charset () |
1578 | rxvt_term::cur_charset () |
… | |
… | |
1672 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1685 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1673 | |
1686 | |
1674 | EXTEND (SP, count); |
1687 | EXTEND (SP, count); |
1675 | while (count--) |
1688 | while (count--) |
1676 | PUSHs (newSVuv ((U32)props [count])); |
1689 | PUSHs (newSVuv ((U32)props [count])); |
1677 | |
1690 | |
1678 | XFree (props); |
1691 | XFree (props); |
1679 | } |
1692 | } |
1680 | |
1693 | |
1681 | void |
1694 | void |
1682 | rxvt_term::XGetWindowProperty (Window window, Atom property) |
1695 | rxvt_term::XGetWindowProperty (Window window, Atom property) |
… | |
… | |
1705 | XFree (prop); |
1718 | XFree (prop); |
1706 | } |
1719 | } |
1707 | } |
1720 | } |
1708 | |
1721 | |
1709 | void |
1722 | void |
1710 | rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) |
1723 | rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data) |
1711 | CODE: |
1724 | CODE: |
1712 | { |
1725 | { |
1713 | STRLEN len; |
1726 | STRLEN len; |
1714 | char *data_ = SvPVbyte (data, len); |
1727 | char *data_ = SvPVbyte (data, len); |
1715 | |
1728 | |