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)] |
… | |
… | |
70 | SV *sv = newSVpv (str, 0); |
66 | SV *sv = newSVpv (str, 0); |
71 | SvUTF8_on (sv); |
67 | SvUTF8_on (sv); |
72 | free (str); |
68 | free (str); |
73 | |
69 | |
74 | return sv; |
70 | return sv; |
75 | } |
|
|
76 | |
|
|
77 | static SV * |
|
|
78 | new_ref (HV *hv, const char *klass) |
|
|
79 | { |
|
|
80 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
81 | } |
71 | } |
82 | |
72 | |
83 | static SV * |
73 | static SV * |
84 | newSVptr (void *ptr, const char *klass) |
74 | newSVptr (void *ptr, const char *klass) |
85 | { |
75 | { |
… | |
… | |
220 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
210 | *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) |
221 | )); |
211 | )); |
222 | av_push (overlay_av, newSViv ((long)this)); |
212 | av_push (overlay_av, newSViv ((long)this)); |
223 | |
213 | |
224 | THIS->want_refresh = 1; |
214 | THIS->want_refresh = 1; |
|
|
215 | THIS->refresh_check (); |
225 | } |
216 | } |
226 | |
217 | |
227 | void |
218 | void |
228 | overlay::hide () |
219 | overlay::hide () |
229 | { |
220 | { |
… | |
… | |
243 | |
234 | |
244 | SvREFCNT_dec (overlay_av); |
235 | SvREFCNT_dec (overlay_av); |
245 | overlay_av = 0; |
236 | overlay_av = 0; |
246 | |
237 | |
247 | THIS->want_refresh = 1; |
238 | THIS->want_refresh = 1; |
|
|
239 | THIS->refresh_check (); |
248 | } |
240 | } |
249 | |
241 | |
250 | void overlay::swap () |
242 | void overlay::swap () |
251 | { |
243 | { |
252 | 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)); |
… | |
… | |
297 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
289 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
298 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
290 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
299 | } |
291 | } |
300 | |
292 | |
301 | THIS->want_refresh = 1; |
293 | THIS->want_refresh = 1; |
|
|
294 | THIS->refresh_check (); |
302 | } |
295 | } |
303 | |
296 | |
304 | ///////////////////////////////////////////////////////////////////////////// |
297 | ///////////////////////////////////////////////////////////////////////////// |
305 | |
298 | |
306 | #define IOM_CLASS "urxvt" |
299 | #define IOM_CLASS "urxvt" |
307 | #define IOM_WARN rxvt_warn |
300 | #define IOM_WARN rxvt_warn |
308 | #include <iom_perl.h> |
301 | #include "iom_perl.h" |
309 | |
302 | |
310 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
311 | |
304 | |
312 | struct rxvt_perl_interp rxvt_perl; |
305 | struct rxvt_perl_interp rxvt_perl; |
313 | |
306 | |
… | |
… | |
388 | |
381 | |
389 | // pre-handling of some events |
382 | // pre-handling of some events |
390 | if (htype == HOOK_REFRESH_END) |
383 | if (htype == HOOK_REFRESH_END) |
391 | { |
384 | { |
392 | 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)); |
393 | |
386 | |
394 | for (int i = 0; i <= AvFILL (av); i++) |
387 | for (int i = 0; i <= AvFILL (av); i++) |
395 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
388 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
396 | } |
389 | } |
397 | |
390 | |
398 | swap (perl_environ, environ); |
391 | swap (perl_environ, environ); |
… | |
… | |
597 | |
590 | |
598 | // post-handling of some events |
591 | // post-handling of some events |
599 | if (htype == HOOK_REFRESH_BEGIN) |
592 | if (htype == HOOK_REFRESH_BEGIN) |
600 | { |
593 | { |
601 | 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)); |
602 | |
595 | |
603 | for (int i = AvFILL (av); i >= 0; i--) |
596 | for (int i = AvFILL (av); i >= 0; i--) |
604 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
597 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
605 | } |
598 | } |
606 | else if (htype == HOOK_DESTROY) |
599 | else if (htype == HOOK_DESTROY) |
607 | { |
600 | { |
608 | clearSVptr ((SV *)term->perl.self); |
601 | clearSVptr ((SV *)term->perl.self); |
609 | SvREFCNT_dec ((SV *)term->perl.self); |
602 | SvREFCNT_dec ((SV *)term->perl.self); |
610 | |
603 | |
611 | // don't allow further calls |
604 | // don't allow further calls |
612 | term->perl.self = 0; |
605 | term->perl.self = 0; |
613 | } |
606 | } |
614 | |
607 | |
615 | swap (perl_environ, environ); |
608 | swap (perl_environ, environ); |
… | |
… | |
781 | _exit (int status) |
774 | _exit (int status) |
782 | |
775 | |
783 | NV |
776 | NV |
784 | NOW () |
777 | NOW () |
785 | CODE: |
778 | CODE: |
786 | RETVAL = NOW; |
779 | RETVAL = ev::now (); |
787 | OUTPUT: |
780 | OUTPUT: |
788 | RETVAL |
781 | RETVAL |
789 | |
782 | |
790 | int |
783 | int |
791 | GET_BASEFG (int rend) |
784 | GET_BASEFG (int rend) |
… | |
… | |
863 | for (int i = AvFILL (env) + 1; i--; ) |
856 | for (int i = AvFILL (env) + 1; i--; ) |
864 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
857 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
865 | |
858 | |
866 | envv->push_back (0); |
859 | envv->push_back (0); |
867 | |
860 | |
868 | bool success; |
|
|
869 | |
|
|
870 | try |
861 | try |
871 | { |
862 | { |
872 | success = term->init (argv, envv); |
863 | term->init (argv, envv); |
873 | } |
864 | } |
874 | catch (const class rxvt_failure_exception &e) |
865 | catch (const class rxvt_failure_exception &e) |
875 | { |
|
|
876 | success = false; |
|
|
877 | } |
|
|
878 | |
|
|
879 | if (!success) |
|
|
880 | { |
866 | { |
881 | term->destroy (); |
867 | term->destroy (); |
882 | croak ("error while initializing new terminal instance"); |
868 | croak ("error while initializing new terminal instance"); |
883 | } |
869 | } |
884 | |
870 | |
… | |
… | |
1145 | if (*i) |
1131 | if (*i) |
1146 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1132 | PUSHs (sv_2mortal (newSVpv (*i, 0))); |
1147 | } |
1133 | } |
1148 | |
1134 | |
1149 | int |
1135 | int |
1150 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
1136 | rxvt_term::pty_ev_events (int events = ev::UNDEF) |
1151 | CODE: |
1137 | CODE: |
1152 | RETVAL = THIS->pty_ev.events; |
1138 | RETVAL = THIS->pty_ev.events; |
1153 | if (events != EVENT_UNDEF) |
1139 | if (events != ev::UNDEF) |
1154 | THIS->pty_ev.set (events); |
1140 | THIS->pty_ev.set (events); |
1155 | OUTPUT: |
1141 | OUTPUT: |
1156 | RETVAL |
1142 | RETVAL |
1157 | |
1143 | |
1158 | int |
1144 | int |
… | |
… | |
1237 | |
1223 | |
1238 | void |
1224 | void |
1239 | rxvt_term::want_refresh () |
1225 | rxvt_term::want_refresh () |
1240 | CODE: |
1226 | CODE: |
1241 | THIS->want_refresh = 1; |
1227 | THIS->want_refresh = 1; |
|
|
1228 | THIS->refresh_check (); |
1242 | |
1229 | |
1243 | void |
1230 | void |
1244 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1231 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1245 | PPCODE: |
1232 | PPCODE: |
1246 | { |
1233 | { |
… | |
… | |
1401 | SV * |
1388 | SV * |
1402 | rxvt_term::special_decode (SV *text) |
1389 | rxvt_term::special_decode (SV *text) |
1403 | CODE: |
1390 | CODE: |
1404 | { |
1391 | { |
1405 | wchar_t *wstr = sv2wcs (text); |
1392 | wchar_t *wstr = sv2wcs (text); |
1406 | int wlen = wcslen (wstr); |
|
|
1407 | int dlen = 0; |
1393 | int dlen = 0; |
1408 | |
1394 | |
1409 | // find length |
1395 | // find length |
1410 | for (wchar_t *s = wstr; *s; s++) |
1396 | for (wchar_t *s = wstr; *s; s++) |
1411 | if (*s == NOCHAR) |
1397 | if (*s == NOCHAR) |
… | |
… | |
1474 | |
1460 | |
1475 | const char * |
1461 | const char * |
1476 | rxvt_term::x_resource (const char *name) |
1462 | rxvt_term::x_resource (const char *name) |
1477 | |
1463 | |
1478 | bool |
1464 | bool |
1479 | rxvt_term::option (U32 optval, int set = -1) |
1465 | rxvt_term::option (U8 optval, int set = -1) |
1480 | CODE: |
1466 | CODE: |
1481 | { |
1467 | { |
1482 | RETVAL = THIS->options & optval; |
1468 | RETVAL = THIS->option (optval); |
1483 | |
1469 | |
1484 | if (set >= 0) |
1470 | if (set >= 0) |
1485 | { |
1471 | { |
1486 | if (set) |
|
|
1487 | THIS->options |= optval; |
1472 | THIS->set_option (optval, set); |
1488 | else |
|
|
1489 | THIS->options &= ~optval; |
|
|
1490 | |
1473 | |
1491 | if (THIS->check_ev.is_active ()) // avoid doing this before START |
1474 | if (THIS->env_colorfgbg [0]) // avoid doing this before START |
1492 | switch (optval) |
1475 | switch (optval) |
1493 | { |
1476 | { |
1494 | case Opt_skipBuiltinGlyphs: |
1477 | case Opt_skipBuiltinGlyphs: |
1495 | THIS->set_fonts (); |
1478 | THIS->set_fonts (); |
1496 | THIS->scr_remap_chars (); |
1479 | THIS->scr_remap_chars (); |
1497 | THIS->scr_touch (true); |
1480 | THIS->scr_touch (true); |
1498 | THIS->want_refresh = 1; |
1481 | THIS->want_refresh = 1; |
|
|
1482 | THIS->refresh_check (); |
1499 | break; |
1483 | break; |
1500 | |
1484 | |
1501 | case Opt_cursorUnderline: |
1485 | case Opt_cursorUnderline: |
1502 | THIS->want_refresh = 1; |
1486 | THIS->want_refresh = 1; |
|
|
1487 | THIS->refresh_check (); |
1503 | break; |
1488 | break; |
1504 | |
1489 | |
1505 | # case Opt_scrollBar_floating: |
1490 | # case Opt_scrollBar_floating: |
1506 | # case Opt_scrollBar_right: |
1491 | # case Opt_scrollBar_right: |
1507 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
1492 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
… | |
… | |
1565 | |
1550 | |
1566 | clamp_it (rc.col, 0, THIS->ncol); |
1551 | clamp_it (rc.col, 0, THIS->ncol); |
1567 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1552 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1568 | |
1553 | |
1569 | if (ix) |
1554 | if (ix) |
|
|
1555 | { |
1570 | THIS->want_refresh = 1; |
1556 | THIS->want_refresh = 1; |
|
|
1557 | THIS->refresh_check (); |
|
|
1558 | } |
1571 | } |
1559 | } |
1572 | } |
1560 | } |
1573 | |
1561 | |
1574 | char |
1562 | char |
1575 | rxvt_term::cur_charset () |
1563 | rxvt_term::cur_charset () |
… | |
… | |
1682 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1670 | Atom *props = XListProperties (THIS->dpy, window, &count); |
1683 | |
1671 | |
1684 | EXTEND (SP, count); |
1672 | EXTEND (SP, count); |
1685 | while (count--) |
1673 | while (count--) |
1686 | PUSHs (newSVuv ((U32)props [count])); |
1674 | PUSHs (newSVuv ((U32)props [count])); |
1687 | |
1675 | |
1688 | XFree (props); |
1676 | XFree (props); |
1689 | } |
1677 | } |
1690 | |
1678 | |
1691 | void |
1679 | void |
1692 | rxvt_term::XGetWindowProperty (Window window, Atom property) |
1680 | rxvt_term::XGetWindowProperty (Window window, Atom property) |