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)] |
54 | |
50 | |
55 | typedef int CHAINED UNUSED; |
|
|
56 | |
|
|
57 | ///////////////////////////////////////////////////////////////////////////// |
51 | ///////////////////////////////////////////////////////////////////////////// |
58 | |
52 | |
59 | static wchar_t * |
53 | static wchar_t * |
60 | sv2wcs (SV *sv) |
54 | sv2wcs (SV *sv) |
61 | { |
55 | { |
… | |
… | |
72 | SV *sv = newSVpv (str, 0); |
66 | SV *sv = newSVpv (str, 0); |
73 | SvUTF8_on (sv); |
67 | SvUTF8_on (sv); |
74 | free (str); |
68 | free (str); |
75 | |
69 | |
76 | return sv; |
70 | return sv; |
77 | } |
|
|
78 | |
|
|
79 | static SV * |
|
|
80 | new_ref (HV *hv, const char *klass) |
|
|
81 | { |
|
|
82 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
83 | } |
71 | } |
84 | |
72 | |
85 | static SV * |
73 | static SV * |
86 | newSVptr (void *ptr, const char *klass) |
74 | newSVptr (void *ptr, const char *klass) |
87 | { |
75 | { |
… | |
… | |
222 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
210 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
223 | )); |
211 | )); |
224 | av_push (overlay_av, newSViv ((long)this)); |
212 | av_push (overlay_av, newSViv ((long)this)); |
225 | |
213 | |
226 | THIS->want_refresh = 1; |
214 | THIS->want_refresh = 1; |
|
|
215 | THIS->refresh_check (); |
227 | } |
216 | } |
228 | |
217 | |
229 | void |
218 | void |
230 | overlay::hide () |
219 | overlay::hide () |
231 | { |
220 | { |
… | |
… | |
245 | |
234 | |
246 | SvREFCNT_dec (overlay_av); |
235 | SvREFCNT_dec (overlay_av); |
247 | overlay_av = 0; |
236 | overlay_av = 0; |
248 | |
237 | |
249 | THIS->want_refresh = 1; |
238 | THIS->want_refresh = 1; |
|
|
239 | THIS->refresh_check (); |
250 | } |
240 | } |
251 | |
241 | |
252 | void overlay::swap () |
242 | void overlay::swap () |
253 | { |
243 | { |
254 | 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)); |
… | |
… | |
299 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
289 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
300 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
290 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
301 | } |
291 | } |
302 | |
292 | |
303 | THIS->want_refresh = 1; |
293 | THIS->want_refresh = 1; |
|
|
294 | THIS->refresh_check (); |
304 | } |
295 | } |
305 | |
296 | |
306 | ///////////////////////////////////////////////////////////////////////////// |
297 | ///////////////////////////////////////////////////////////////////////////// |
307 | |
298 | |
308 | #define IOM_CLASS "urxvt" |
299 | #define IOM_CLASS "urxvt" |
|
|
300 | #define IOM_WARN rxvt_warn |
309 | #include <iom_perl.h> |
301 | #include "iom_perl.h" |
310 | |
302 | |
311 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
312 | |
304 | |
313 | struct rxvt_perl_interp rxvt_perl; |
305 | struct rxvt_perl_interp rxvt_perl; |
314 | |
306 | |
… | |
… | |
389 | |
381 | |
390 | // pre-handling of some events |
382 | // pre-handling of some events |
391 | if (htype == HOOK_REFRESH_END) |
383 | if (htype == HOOK_REFRESH_END) |
392 | { |
384 | { |
393 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
385 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
394 | |
386 | |
395 | for (int i = 0; i <= AvFILL (av); i++) |
387 | for (int i = 0; i <= AvFILL (av); i++) |
396 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
388 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
397 | } |
389 | } |
398 | |
390 | |
399 | swap (perl_environ, environ); |
391 | swap (perl_environ, environ); |
… | |
… | |
598 | |
590 | |
599 | // post-handling of some events |
591 | // post-handling of some events |
600 | if (htype == HOOK_REFRESH_BEGIN) |
592 | if (htype == HOOK_REFRESH_BEGIN) |
601 | { |
593 | { |
602 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
594 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
603 | |
595 | |
604 | for (int i = AvFILL (av); i >= 0; i--) |
596 | for (int i = AvFILL (av); i >= 0; i--) |
605 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
597 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
606 | } |
598 | } |
607 | else if (htype == HOOK_DESTROY) |
599 | else if (htype == HOOK_DESTROY) |
608 | { |
600 | { |
609 | clearSVptr ((SV *)term->perl.self); |
601 | clearSVptr ((SV *)term->perl.self); |
610 | SvREFCNT_dec ((SV *)term->perl.self); |
602 | SvREFCNT_dec ((SV *)term->perl.self); |
611 | |
603 | |
612 | // don't allow further calls |
604 | // don't allow further calls |
613 | term->perl.self = 0; |
605 | term->perl.self = 0; |
614 | } |
606 | } |
615 | |
607 | |
616 | swap (perl_environ, environ); |
608 | swap (perl_environ, environ); |
… | |
… | |
647 | static const struct { |
639 | static const struct { |
648 | const char *name; |
640 | const char *name; |
649 | IV iv; |
641 | IV iv; |
650 | } *civ, const_iv[] = { |
642 | } *civ, const_iv[] = { |
651 | # define const_iv(name) { # name, (IV)name } |
643 | # define const_iv(name) { # name, (IV)name } |
|
|
644 | const_iv (NUM_RESOURCES), |
652 | const_iv (DEFAULT_RSTYLE), |
645 | const_iv (DEFAULT_RSTYLE), |
653 | const_iv (OVERLAY_RSTYLE), |
646 | const_iv (OVERLAY_RSTYLE), |
654 | const_iv (RS_Bold), |
647 | const_iv (RS_Bold), |
655 | const_iv (RS_Italic), |
648 | const_iv (RS_Italic), |
656 | const_iv (RS_Blink), |
649 | const_iv (RS_Blink), |
… | |
… | |
782 | _exit (int status) |
775 | _exit (int status) |
783 | |
776 | |
784 | NV |
777 | NV |
785 | NOW () |
778 | NOW () |
786 | CODE: |
779 | CODE: |
787 | RETVAL = NOW; |
780 | RETVAL = ev::now (); |
788 | OUTPUT: |
781 | OUTPUT: |
789 | RETVAL |
782 | RETVAL |
790 | |
783 | |
791 | int |
784 | int |
792 | GET_BASEFG (int rend) |
785 | GET_BASEFG (int rend) |
… | |
… | |
864 | for (int i = AvFILL (env) + 1; i--; ) |
857 | for (int i = AvFILL (env) + 1; i--; ) |
865 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
858 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
866 | |
859 | |
867 | envv->push_back (0); |
860 | envv->push_back (0); |
868 | |
861 | |
869 | bool success; |
|
|
870 | |
|
|
871 | try |
862 | try |
872 | { |
863 | { |
873 | success = term->init (argv, envv); |
864 | term->init (argv, envv); |
874 | } |
865 | } |
875 | catch (const class rxvt_failure_exception &e) |
866 | catch (const class rxvt_failure_exception &e) |
876 | { |
|
|
877 | success = false; |
|
|
878 | } |
|
|
879 | |
|
|
880 | if (!success) |
|
|
881 | { |
867 | { |
882 | term->destroy (); |
868 | term->destroy (); |
883 | croak ("error while initializing new terminal instance"); |
869 | croak ("error while initializing new terminal instance"); |
884 | } |
870 | } |
885 | |
871 | |
… | |
… | |
1111 | { |
1097 | { |
1112 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1098 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1113 | case 1: RETVAL = THIS->ModMetaMask; break; |
1099 | case 1: RETVAL = THIS->ModMetaMask; break; |
1114 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1100 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1115 | case 3: RETVAL = THIS->current_screen; break; |
1101 | case 3: RETVAL = THIS->current_screen; break; |
|
|
1102 | #ifdef CURSOR_BLINK |
1116 | case 4: RETVAL = THIS->hidden_cursor; break; |
1103 | case 4: RETVAL = THIS->hidden_cursor; break; |
|
|
1104 | #endif |
1117 | } |
1105 | } |
1118 | OUTPUT: |
1106 | OUTPUT: |
1119 | RETVAL |
1107 | RETVAL |
1120 | |
1108 | |
1121 | char * |
1109 | char * |
… | |
… | |
1146 | if (*i) |
1134 | if (*i) |
1147 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1135 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1148 | } |
1136 | } |
1149 | |
1137 | |
1150 | int |
1138 | int |
1151 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
1139 | rxvt_term::pty_ev_events (int events = ev::UNDEF) |
1152 | CODE: |
1140 | CODE: |
1153 | RETVAL = THIS->pty_ev.events; |
1141 | RETVAL = THIS->pty_ev.events; |
1154 | if (events != EVENT_UNDEF) |
1142 | if (events != ev::UNDEF) |
1155 | THIS->pty_ev.set (events); |
1143 | THIS->pty_ev.set (events); |
1156 | OUTPUT: |
1144 | OUTPUT: |
1157 | RETVAL |
1145 | RETVAL |
1158 | |
1146 | |
1159 | int |
1147 | int |
… | |
… | |
1238 | |
1226 | |
1239 | void |
1227 | void |
1240 | rxvt_term::want_refresh () |
1228 | rxvt_term::want_refresh () |
1241 | CODE: |
1229 | CODE: |
1242 | THIS->want_refresh = 1; |
1230 | THIS->want_refresh = 1; |
|
|
1231 | THIS->refresh_check (); |
1243 | |
1232 | |
1244 | void |
1233 | void |
1245 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1234 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1246 | PPCODE: |
1235 | PPCODE: |
1247 | { |
1236 | { |
… | |
… | |
1402 | SV * |
1391 | SV * |
1403 | rxvt_term::special_decode (SV *text) |
1392 | rxvt_term::special_decode (SV *text) |
1404 | CODE: |
1393 | CODE: |
1405 | { |
1394 | { |
1406 | wchar_t *wstr = sv2wcs (text); |
1395 | wchar_t *wstr = sv2wcs (text); |
1407 | int wlen = wcslen (wstr); |
|
|
1408 | int dlen = 0; |
1396 | int dlen = 0; |
1409 | |
1397 | |
1410 | // find length |
1398 | // find length |
1411 | for (wchar_t *s = wstr; *s; s++) |
1399 | for (wchar_t *s = wstr; *s; s++) |
1412 | if (*s == NOCHAR) |
1400 | if (*s == NOCHAR) |
… | |
… | |
1445 | # undef reserve |
1433 | # undef reserve |
1446 | }; |
1434 | }; |
1447 | |
1435 | |
1448 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1436 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1449 | |
1437 | |
|
|
1438 | if (*name) |
1450 | do { |
1439 | { |
|
|
1440 | do { |
1451 | if (rs-- == rslist) |
1441 | if (rs-- == rslist) |
1452 | croak ("no such resource '%s', requested", name); |
1442 | croak ("no such resource '%s', requested", name); |
1453 | } while (strcmp (name, rs->name)); |
1443 | } while (strcmp (name, rs->name)); |
1454 | |
1444 | |
1455 | index += rs->value; |
1445 | index += rs->value; |
|
|
1446 | } |
|
|
1447 | else |
|
|
1448 | { |
|
|
1449 | --rs; |
|
|
1450 | name = ""; |
|
|
1451 | } |
1456 | |
1452 | |
1457 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1453 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1458 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1454 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1459 | |
1455 | |
1460 | if (GIMME_V != G_VOID) |
1456 | if (GIMME_V != G_VOID) |
… | |
… | |
1475 | |
1471 | |
1476 | const char * |
1472 | const char * |
1477 | rxvt_term::x_resource (const char *name) |
1473 | rxvt_term::x_resource (const char *name) |
1478 | |
1474 | |
1479 | bool |
1475 | bool |
1480 | rxvt_term::option (U32 optval, int set = -1) |
1476 | rxvt_term::option (U8 optval, int set = -1) |
1481 | CODE: |
1477 | CODE: |
1482 | { |
1478 | { |
1483 | RETVAL = THIS->options & optval; |
1479 | RETVAL = THIS->option (optval); |
1484 | |
1480 | |
1485 | if (set >= 0) |
1481 | if (set >= 0) |
1486 | { |
1482 | { |
1487 | if (set) |
|
|
1488 | THIS->options |= optval; |
1483 | THIS->set_option (optval, set); |
1489 | else |
|
|
1490 | THIS->options &= ~optval; |
|
|
1491 | |
1484 | |
1492 | if (THIS->check_ev.is_active ()) // avoid doing this before START |
1485 | if (THIS->env_colorfgbg [0]) // avoid doing this before START |
1493 | switch (optval) |
1486 | switch (optval) |
1494 | { |
1487 | { |
1495 | case Opt_skipBuiltinGlyphs: |
1488 | case Opt_skipBuiltinGlyphs: |
1496 | THIS->set_fonts (); |
1489 | THIS->set_fonts (); |
1497 | THIS->scr_remap_chars (); |
1490 | THIS->scr_remap_chars (); |
1498 | THIS->scr_touch (true); |
1491 | THIS->scr_touch (true); |
1499 | THIS->want_refresh = 1; |
1492 | THIS->want_refresh = 1; |
|
|
1493 | THIS->refresh_check (); |
1500 | break; |
1494 | break; |
1501 | |
1495 | |
1502 | case Opt_cursorUnderline: |
1496 | case Opt_cursorUnderline: |
1503 | THIS->want_refresh = 1; |
1497 | THIS->want_refresh = 1; |
|
|
1498 | THIS->refresh_check (); |
1504 | break; |
1499 | break; |
1505 | |
1500 | |
1506 | # case Opt_scrollBar_floating: |
1501 | # case Opt_scrollBar_floating: |
1507 | # case Opt_scrollBar_right: |
1502 | # case Opt_scrollBar_right: |
1508 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
1503 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
… | |
… | |
1566 | |
1561 | |
1567 | clamp_it (rc.col, 0, THIS->ncol); |
1562 | clamp_it (rc.col, 0, THIS->ncol); |
1568 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1563 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1569 | |
1564 | |
1570 | if (ix) |
1565 | if (ix) |
|
|
1566 | { |
1571 | THIS->want_refresh = 1; |
1567 | THIS->want_refresh = 1; |
|
|
1568 | THIS->refresh_check (); |
|
|
1569 | } |
1572 | } |
1570 | } |
1573 | } |
1571 | } |
1574 | |
1572 | |
1575 | char |
1573 | char |
1576 | rxvt_term::cur_charset () |
1574 | rxvt_term::cur_charset () |
… | |
… | |
1683 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1681 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1684 | |
1682 | |
1685 | EXTEND (SP, count); |
1683 | EXTEND (SP, count); |
1686 | while (count--) |
1684 | while (count--) |
1687 | PUSHs (newSVuv ((U32)props [count])); |
1685 | PUSHs (newSVuv ((U32)props [count])); |
1688 | |
1686 | |
1689 | XFree (props); |
1687 | XFree (props); |
1690 | } |
1688 | } |
1691 | |
1689 | |
1692 | void |
1690 | void |
1693 | rxvt_term::XGetWindowProperty (Window window, Atom property) |
1691 | rxvt_term::XGetWindowProperty (Window window, Atom property) |
… | |
… | |
1716 | XFree (prop); |
1714 | XFree (prop); |
1717 | } |
1715 | } |
1718 | } |
1716 | } |
1719 | |
1717 | |
1720 | void |
1718 | void |
1721 | rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) |
1719 | rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data) |
1722 | CODE: |
1720 | CODE: |
1723 | { |
1721 | { |
1724 | STRLEN len; |
1722 | STRLEN len; |
1725 | char *data_ = SvPVbyte (data, len); |
1723 | char *data_ = SvPVbyte (data, len); |
1726 | |
1724 | |