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-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 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. |
… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
|
|
34 | #include "unistd.h" |
|
|
35 | |
|
|
36 | #include "iom.h" |
33 | #include "rxvt.h" |
37 | #include "rxvt.h" |
34 | #include "iom.h" |
38 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
37 | |
41 | |
38 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
|
|
43 | |
|
|
44 | #ifdef HAVE_SCROLLBARS |
|
|
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
46 | #else |
|
|
47 | # define GRAB_CURSOR None |
|
|
48 | #endif |
39 | |
49 | |
40 | #undef LINENO |
50 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
52 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
54 | |
|
|
55 | #define ENABLE_PERL_FRILLS 1 |
|
|
56 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
58 | |
47 | static wchar_t * |
59 | static wchar_t * |
48 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
49 | { |
61 | { |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
113 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
114 | |
103 | return (long)mg->mg_ptr; |
115 | return (long)mg->mg_ptr; |
104 | } |
116 | } |
105 | |
117 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
118 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
119 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
120 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
121 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
122 | |
111 | struct perl_watcher |
123 | struct perl_watcher |
… | |
… | |
290 | void |
302 | void |
291 | overlay::show () |
303 | overlay::show () |
292 | { |
304 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
305 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
306 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
307 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
308 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
309 | } |
298 | |
310 | |
299 | void |
311 | void |
300 | overlay::hide () |
312 | overlay::hide () |
301 | { |
313 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
314 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
315 | |
304 | if (ovs) |
316 | if (ovs) |
305 | { |
317 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
318 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
319 | |
… | |
… | |
321 | for (int y = ov_h; y--; ) |
333 | for (int y = ov_h; y--; ) |
322 | { |
334 | { |
323 | text_t *t1 = text [y]; |
335 | text_t *t1 = text [y]; |
324 | rend_t *r1 = rend [y]; |
336 | rend_t *r1 = rend [y]; |
325 | |
337 | |
326 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
338 | text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x; |
327 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
339 | rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x; |
328 | |
340 | |
329 | for (int x = ov_w; x--; ) |
341 | for (int x = ov_w; x--; ) |
330 | { |
342 | { |
331 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
343 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
332 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
344 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
… | |
… | |
369 | |
381 | |
370 | struct rxvt_perl_interp rxvt_perl; |
382 | struct rxvt_perl_interp rxvt_perl; |
371 | |
383 | |
372 | static PerlInterpreter *perl; |
384 | static PerlInterpreter *perl; |
373 | |
385 | |
374 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
375 | { |
|
|
376 | } |
|
|
377 | |
|
|
378 | rxvt_perl_interp::~rxvt_perl_interp () |
386 | rxvt_perl_interp::~rxvt_perl_interp () |
379 | { |
387 | { |
380 | if (perl) |
388 | if (perl) |
381 | { |
389 | { |
382 | perl_destruct (perl); |
390 | perl_destruct (perl); |
383 | perl_free (perl); |
391 | perl_free (perl); |
384 | } |
392 | } |
385 | } |
393 | } |
386 | |
394 | |
387 | void |
395 | void |
388 | rxvt_perl_interp::init () |
396 | rxvt_perl_interp::init (rxvt_term *term) |
389 | { |
397 | { |
390 | if (!perl) |
398 | if (!perl) |
391 | { |
399 | { |
|
|
400 | rxvt_push_locale (""); // perl init destroys current locale |
|
|
401 | |
|
|
402 | perl_environ = rxvt_environ; |
|
|
403 | swap (perl_environ, environ); |
|
|
404 | |
392 | char *argv[] = { |
405 | char *argv[] = { |
393 | "", |
406 | "", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
407 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
395 | }; |
408 | }; |
396 | |
409 | |
… | |
… | |
404 | |
417 | |
405 | perl_destruct (perl); |
418 | perl_destruct (perl); |
406 | perl_free (perl); |
419 | perl_free (perl); |
407 | perl = 0; |
420 | perl = 0; |
408 | } |
421 | } |
|
|
422 | |
|
|
423 | swap (perl_environ, environ); |
|
|
424 | |
|
|
425 | rxvt_pop_locale (); |
|
|
426 | } |
|
|
427 | |
|
|
428 | if (perl) |
|
|
429 | { |
|
|
430 | // runs outside of perls ENV |
|
|
431 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
432 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
433 | } |
|
|
434 | } |
|
|
435 | |
|
|
436 | static void |
|
|
437 | ungrab (rxvt_term *THIS) |
|
|
438 | { |
|
|
439 | if (THIS->perl.grabtime) |
|
|
440 | { |
|
|
441 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
442 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | THIS->perl.grabtime = 0; |
|
|
444 | } |
|
|
445 | } |
|
|
446 | |
|
|
447 | static void |
|
|
448 | swap_overlays (rxvt_term *term) |
|
|
449 | { |
|
|
450 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
451 | |
|
|
452 | if (HvKEYS (hv)) |
|
|
453 | { |
|
|
454 | hv_iterinit (hv); |
|
|
455 | |
|
|
456 | while (HE *he = hv_iternext (hv)) |
|
|
457 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
409 | } |
458 | } |
410 | } |
459 | } |
411 | |
460 | |
412 | bool |
461 | bool |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
462 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | { |
463 | { |
415 | if (!perl) |
464 | if (!perl || !term->perl.self) |
416 | return false; |
465 | return false; |
417 | |
466 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
467 | // pre-handling of some events |
|
|
468 | if (htype == HOOK_REFRESH_END) |
|
|
469 | swap_overlays (term); |
|
|
470 | |
|
|
471 | swap (perl_environ, environ); |
|
|
472 | |
|
|
473 | bool event_consumed; |
|
|
474 | |
|
|
475 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
|
|
476 | || term->perl.should_invoke [htype]) |
|
|
477 | try |
419 | { |
478 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
479 | dSP; |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
480 | va_list ap; |
|
|
481 | |
|
|
482 | va_start (ap, htype); |
|
|
483 | |
|
|
484 | ENTER; |
|
|
485 | SAVETMPS; |
|
|
486 | |
|
|
487 | PUSHMARK (SP); |
|
|
488 | |
|
|
489 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
490 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
491 | |
|
|
492 | for (;;) { |
|
|
493 | data_type dt = (data_type)va_arg (ap, int); |
|
|
494 | |
|
|
495 | switch (dt) |
|
|
496 | { |
|
|
497 | case DT_INT: |
|
|
498 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
499 | break; |
|
|
500 | |
|
|
501 | case DT_LONG: |
|
|
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
503 | break; |
|
|
504 | |
|
|
505 | case DT_STR: |
|
|
506 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
507 | break; |
|
|
508 | |
|
|
509 | case DT_STR_LEN: |
|
|
510 | { |
|
|
511 | char *str = va_arg (ap, char *); |
|
|
512 | int len = va_arg (ap, int); |
|
|
513 | |
|
|
514 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
515 | } |
|
|
516 | break; |
|
|
517 | |
|
|
518 | case DT_WCS_LEN: |
|
|
519 | { |
|
|
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
521 | int wlen = va_arg (ap, int); |
|
|
522 | |
|
|
523 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
524 | } |
|
|
525 | break; |
|
|
526 | |
|
|
527 | case DT_XEVENT: |
|
|
528 | { |
|
|
529 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
530 | HV *hv = newHV (); |
|
|
531 | |
|
|
532 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
533 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
534 | # undef set |
|
|
535 | |
|
|
536 | setiv (type, xe->type); |
|
|
537 | setiv (send_event, xe->xany.send_event); |
|
|
538 | setiv (serial, xe->xany.serial); |
|
|
539 | |
|
|
540 | switch (xe->type) |
|
|
541 | { |
|
|
542 | case KeyPress: |
|
|
543 | case KeyRelease: |
|
|
544 | case ButtonPress: |
|
|
545 | case ButtonRelease: |
|
|
546 | case MotionNotify: |
|
|
547 | setiv (time, xe->xmotion.time); |
|
|
548 | setiv (x, xe->xmotion.x); |
|
|
549 | setiv (y, xe->xmotion.y); |
|
|
550 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
551 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
552 | setiv (x_root, xe->xmotion.x_root); |
|
|
553 | setiv (y_root, xe->xmotion.y_root); |
|
|
554 | setiv (state, xe->xmotion.state); |
|
|
555 | break; |
|
|
556 | } |
|
|
557 | |
|
|
558 | switch (xe->type) |
|
|
559 | { |
|
|
560 | case KeyPress: |
|
|
561 | case KeyRelease: |
|
|
562 | setiv (keycode, xe->xkey.keycode); |
|
|
563 | break; |
|
|
564 | |
|
|
565 | case ButtonPress: |
|
|
566 | case ButtonRelease: |
|
|
567 | setiv (button, xe->xbutton.button); |
|
|
568 | break; |
|
|
569 | |
|
|
570 | case MotionNotify: |
|
|
571 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
572 | break; |
|
|
573 | } |
|
|
574 | |
|
|
575 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
576 | } |
|
|
577 | break; |
|
|
578 | |
|
|
579 | case DT_END: |
|
|
580 | goto call; |
|
|
581 | |
|
|
582 | default: |
|
|
583 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
584 | } |
|
|
585 | } |
|
|
586 | |
|
|
587 | call: |
|
|
588 | va_end (ap); |
|
|
589 | |
|
|
590 | PUTBACK; |
|
|
591 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
592 | SPAGAIN; |
|
|
593 | |
|
|
594 | if (count) |
|
|
595 | { |
|
|
596 | SV *status = POPs; |
|
|
597 | count = SvTRUE (status); |
|
|
598 | } |
|
|
599 | |
|
|
600 | PUTBACK; |
|
|
601 | FREETMPS; |
|
|
602 | LEAVE; |
|
|
603 | |
|
|
604 | if (SvTRUE (ERRSV)) |
|
|
605 | { |
|
|
606 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
607 | ungrab (term); // better lose the grab than the session |
|
|
608 | } |
|
|
609 | |
|
|
610 | event_consumed = !!count; |
422 | } |
611 | } |
423 | else if (!term->self) |
612 | catch (...) |
424 | return false; // perl not initialized for this instance |
613 | { |
|
|
614 | swap (perl_environ, environ); |
|
|
615 | throw; |
|
|
616 | } |
|
|
617 | else |
|
|
618 | event_consumed = false; |
|
|
619 | |
|
|
620 | // post-handling of some events |
|
|
621 | if (htype == HOOK_REFRESH_BEGIN) |
|
|
622 | swap_overlays (term); |
425 | else if (htype == HOOK_DESTROY) |
623 | else if (htype == HOOK_DESTROY) |
426 | { |
624 | { |
427 | // handled later |
625 | clearSVptr ((SV *)term->perl.self); |
|
|
626 | SvREFCNT_dec ((SV *)term->perl.self); |
428 | } |
627 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
430 | { |
|
|
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
|
|
432 | |
628 | |
433 | if (HvKEYS (hv)) |
629 | swap (perl_environ, environ); |
434 | { |
|
|
435 | hv_iterinit (hv); |
|
|
436 | |
630 | |
437 | while (HE *he = hv_iternext (hv)) |
631 | return event_consumed; |
438 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
439 | } |
|
|
440 | } |
|
|
441 | else if (!should_invoke [htype]) |
|
|
442 | return false; |
|
|
443 | |
|
|
444 | dSP; |
|
|
445 | va_list ap; |
|
|
446 | |
|
|
447 | va_start (ap, htype); |
|
|
448 | |
|
|
449 | ENTER; |
|
|
450 | SAVETMPS; |
|
|
451 | |
|
|
452 | PUSHMARK (SP); |
|
|
453 | |
|
|
454 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
455 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
456 | |
|
|
457 | for (;;) { |
|
|
458 | data_type dt = (data_type)va_arg (ap, int); |
|
|
459 | |
|
|
460 | switch (dt) |
|
|
461 | { |
|
|
462 | case DT_INT: |
|
|
463 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
464 | break; |
|
|
465 | |
|
|
466 | case DT_LONG: |
|
|
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
468 | break; |
|
|
469 | |
|
|
470 | case DT_STRING: |
|
|
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
472 | break; |
|
|
473 | |
|
|
474 | case DT_USTRING_LEN: |
|
|
475 | { |
|
|
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
477 | int ulen = va_arg (ap, int); |
|
|
478 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
479 | |
|
|
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
484 | |
|
|
485 | delete [] wstr; |
|
|
486 | } |
|
|
487 | |
|
|
488 | case DT_END: |
|
|
489 | { |
|
|
490 | va_end (ap); |
|
|
491 | |
|
|
492 | PUTBACK; |
|
|
493 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
494 | SPAGAIN; |
|
|
495 | |
|
|
496 | if (count) |
|
|
497 | { |
|
|
498 | SV *status = POPs; |
|
|
499 | count = SvTRUE (status); |
|
|
500 | } |
|
|
501 | |
|
|
502 | PUTBACK; |
|
|
503 | FREETMPS; |
|
|
504 | LEAVE; |
|
|
505 | |
|
|
506 | if (SvTRUE (ERRSV)) |
|
|
507 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
508 | |
|
|
509 | if (htype == HOOK_DESTROY) |
|
|
510 | { |
|
|
511 | clearSVptr ((SV *)term->self); |
|
|
512 | SvREFCNT_dec ((SV *)term->self); |
|
|
513 | } |
|
|
514 | |
|
|
515 | return count; |
|
|
516 | } |
|
|
517 | |
|
|
518 | default: |
|
|
519 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
520 | } |
|
|
521 | } |
|
|
522 | } |
632 | } |
523 | |
633 | |
524 | ///////////////////////////////////////////////////////////////////////////// |
634 | ///////////////////////////////////////////////////////////////////////////// |
525 | |
635 | |
526 | MODULE = urxvt PACKAGE = urxvt |
636 | MODULE = urxvt PACKAGE = urxvt |
527 | |
637 | |
528 | PROTOTYPES: ENABLE |
638 | PROTOTYPES: ENABLE |
529 | |
639 | |
530 | BOOT: |
640 | BOOT: |
531 | { |
641 | { |
532 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
642 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
643 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
644 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
645 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
646 | |
533 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
647 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
534 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
648 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
535 | # include "hookinc.h" |
649 | # include "hookinc.h" |
536 | # undef def |
650 | # undef def |
537 | |
651 | |
|
|
652 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
653 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
654 | # define nodef(name) |
|
|
655 | # include "optinc.h" |
|
|
656 | # undef nodef |
|
|
657 | # undef def |
|
|
658 | |
|
|
659 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
660 | struct { |
|
|
661 | const char *name; |
|
|
662 | IV iv; |
|
|
663 | } *civ, const_iv[] = { |
|
|
664 | # define const_iv(name) { # name, (IV)name } |
538 | export_const (DEFAULT_RSTYLE); |
665 | const_iv (DEFAULT_RSTYLE), |
539 | export_const (OVERLAY_RSTYLE); |
666 | const_iv (OVERLAY_RSTYLE), |
540 | export_const (RS_Bold); |
667 | const_iv (RS_Bold), |
541 | export_const (RS_Italic); |
668 | const_iv (RS_Italic), |
542 | export_const (RS_Blink); |
669 | const_iv (RS_Blink), |
543 | export_const (RS_RVid); |
670 | const_iv (RS_RVid), |
544 | export_const (RS_Uline); |
671 | const_iv (RS_Uline), |
545 | |
672 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
673 | const_iv (CurrentTime), |
547 | } |
674 | const_iv (ShiftMask), |
|
|
675 | const_iv (LockMask), |
|
|
676 | const_iv (ControlMask), |
|
|
677 | const_iv (Mod1Mask), |
|
|
678 | const_iv (Mod2Mask), |
|
|
679 | const_iv (Mod3Mask), |
|
|
680 | const_iv (Mod4Mask), |
|
|
681 | const_iv (Mod5Mask), |
|
|
682 | const_iv (Button1Mask), |
|
|
683 | const_iv (Button2Mask), |
|
|
684 | const_iv (Button3Mask), |
|
|
685 | const_iv (Button4Mask), |
|
|
686 | const_iv (Button5Mask), |
|
|
687 | const_iv (AnyModifier), |
548 | |
688 | |
549 | SV * |
689 | const_iv (EVENT_NONE), |
550 | new (...) |
690 | const_iv (EVENT_READ), |
551 | CODE: |
691 | const_iv (EVENT_WRITE), |
552 | { |
|
|
553 | stringvec *argv = new stringvec; |
|
|
554 | bool success; |
|
|
555 | |
692 | |
556 | for (int i = 0; i < items ;i++) |
693 | const_iv (NoEventMask), |
557 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
694 | const_iv (KeyPressMask), |
|
|
695 | const_iv (KeyReleaseMask), |
|
|
696 | const_iv (ButtonPressMask), |
|
|
697 | const_iv (ButtonReleaseMask), |
|
|
698 | const_iv (EnterWindowMask), |
|
|
699 | const_iv (LeaveWindowMask), |
|
|
700 | const_iv (PointerMotionMask), |
|
|
701 | const_iv (PointerMotionHintMask), |
|
|
702 | const_iv (Button1MotionMask), |
|
|
703 | const_iv (Button2MotionMask), |
|
|
704 | const_iv (Button3MotionMask), |
|
|
705 | const_iv (Button4MotionMask), |
|
|
706 | const_iv (Button5MotionMask), |
|
|
707 | const_iv (ButtonMotionMask), |
|
|
708 | const_iv (KeymapStateMask), |
|
|
709 | const_iv (ExposureMask), |
|
|
710 | const_iv (VisibilityChangeMask), |
|
|
711 | const_iv (StructureNotifyMask), |
|
|
712 | const_iv (ResizeRedirectMask), |
|
|
713 | const_iv (SubstructureNotifyMask), |
|
|
714 | const_iv (SubstructureRedirectMask), |
|
|
715 | const_iv (FocusChangeMask), |
|
|
716 | const_iv (PropertyChangeMask), |
|
|
717 | const_iv (ColormapChangeMask), |
|
|
718 | const_iv (OwnerGrabButtonMask), |
558 | |
719 | |
559 | rxvt_term *term = new rxvt_term; |
720 | const_iv (KeyPress), |
|
|
721 | const_iv (KeyRelease), |
|
|
722 | const_iv (ButtonPress), |
|
|
723 | const_iv (ButtonRelease), |
|
|
724 | const_iv (MotionNotify), |
|
|
725 | const_iv (EnterNotify), |
|
|
726 | const_iv (LeaveNotify), |
|
|
727 | const_iv (FocusIn), |
|
|
728 | const_iv (FocusOut), |
|
|
729 | const_iv (KeymapNotify), |
|
|
730 | const_iv (Expose), |
|
|
731 | const_iv (GraphicsExpose), |
|
|
732 | const_iv (NoExpose), |
|
|
733 | const_iv (VisibilityNotify), |
|
|
734 | const_iv (CreateNotify), |
|
|
735 | const_iv (DestroyNotify), |
|
|
736 | const_iv (UnmapNotify), |
|
|
737 | const_iv (MapNotify), |
|
|
738 | const_iv (MapRequest), |
|
|
739 | const_iv (ReparentNotify), |
|
|
740 | const_iv (ConfigureNotify), |
|
|
741 | const_iv (ConfigureRequest), |
|
|
742 | const_iv (GravityNotify), |
|
|
743 | const_iv (ResizeRequest), |
|
|
744 | const_iv (CirculateNotify), |
|
|
745 | const_iv (CirculateRequest), |
|
|
746 | const_iv (PropertyNotify), |
|
|
747 | const_iv (SelectionClear), |
|
|
748 | const_iv (SelectionRequest), |
|
|
749 | const_iv (SelectionNotify), |
|
|
750 | const_iv (ColormapNotify), |
|
|
751 | const_iv (ClientMessage), |
|
|
752 | const_iv (MappingNotify), |
|
|
753 | }; |
560 | |
754 | |
561 | term->argv = argv; |
755 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); |
562 | |
756 | civ-- > const_iv; ) |
563 | try |
757 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
564 | { |
|
|
565 | if (!term->init (argv->size (), argv->begin ())) |
|
|
566 | term = 0; |
|
|
567 | } |
|
|
568 | catch (const class rxvt_failure_exception &e) |
|
|
569 | { |
|
|
570 | term->destroy (); |
|
|
571 | croak ("exception caught while initializing new terminal instance"); |
|
|
572 | } |
|
|
573 | |
|
|
574 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
575 | } |
758 | } |
576 | OUTPUT: |
|
|
577 | RETVAL |
|
|
578 | |
|
|
579 | void |
|
|
580 | set_should_invoke (int htype, int value) |
|
|
581 | CODE: |
|
|
582 | rxvt_perl.should_invoke [htype] = value; |
|
|
583 | |
759 | |
584 | void |
760 | void |
585 | warn (const char *msg) |
761 | warn (const char *msg) |
586 | CODE: |
762 | CODE: |
587 | rxvt_warn ("%s", msg); |
763 | rxvt_warn ("%s", msg); |
588 | |
764 | |
589 | void |
765 | void |
590 | fatal (const char *msg) |
766 | fatal (const char *msg) |
591 | CODE: |
767 | CODE: |
592 | rxvt_fatal ("%s", msg); |
768 | rxvt_fatal ("%s", msg); |
|
|
769 | |
|
|
770 | void |
|
|
771 | _exit (int status) |
593 | |
772 | |
594 | NV |
773 | NV |
595 | NOW () |
774 | NOW () |
596 | CODE: |
775 | CODE: |
597 | RETVAL = NOW; |
776 | RETVAL = NOW; |
… | |
… | |
646 | OUTPUT: |
825 | OUTPUT: |
647 | RETVAL |
826 | RETVAL |
648 | |
827 | |
649 | MODULE = urxvt PACKAGE = urxvt::term |
828 | MODULE = urxvt PACKAGE = urxvt::term |
650 | |
829 | |
|
|
830 | SV * |
|
|
831 | _new (...) |
|
|
832 | CODE: |
|
|
833 | { |
|
|
834 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
835 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
836 | |
|
|
837 | rxvt_term *term = new rxvt_term; |
|
|
838 | |
|
|
839 | term->argv = new stringvec; |
|
|
840 | term->envv = new stringvec; |
|
|
841 | |
|
|
842 | for (int i = 1; i < items; i++) |
|
|
843 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
844 | |
|
|
845 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
846 | for (int i = av_len (envv) + 1; i--; ) |
|
|
847 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
848 | |
|
|
849 | term->envv->push_back (0); |
|
|
850 | |
|
|
851 | bool success; |
|
|
852 | |
|
|
853 | try |
|
|
854 | { |
|
|
855 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
856 | } |
|
|
857 | catch (const class rxvt_failure_exception &e) |
|
|
858 | { |
|
|
859 | success = false; |
|
|
860 | } |
|
|
861 | |
|
|
862 | if (!success) |
|
|
863 | { |
|
|
864 | term->destroy (); |
|
|
865 | croak ("error while initializing new terminal instance"); |
|
|
866 | } |
|
|
867 | |
|
|
868 | RETVAL = term && term->perl.self |
|
|
869 | ? newSVterm (term) : &PL_sv_undef; |
|
|
870 | } |
|
|
871 | OUTPUT: |
|
|
872 | RETVAL |
|
|
873 | |
651 | void |
874 | void |
652 | rxvt_term::destroy () |
875 | rxvt_term::destroy () |
|
|
876 | |
|
|
877 | #if ENABLE_PERL_FRILLS |
|
|
878 | |
|
|
879 | void |
|
|
880 | rxvt_term::XListProperties (U32 window) |
|
|
881 | PPCODE: |
|
|
882 | { |
|
|
883 | int count; |
|
|
884 | Atom *props = XListProperties (THIS->display->display, (Window)window, &count); |
|
|
885 | |
|
|
886 | EXTEND (SP, count); |
|
|
887 | while (count--) |
|
|
888 | PUSHs (newSVuv ((U32)props [count])); |
|
|
889 | |
|
|
890 | XFree (props); |
|
|
891 | } |
|
|
892 | |
|
|
893 | void |
|
|
894 | rxvt_term::XGetWindowProperty (U32 window, U32 property) |
|
|
895 | PPCODE: |
|
|
896 | { |
|
|
897 | Atom type; |
|
|
898 | int format; |
|
|
899 | unsigned long nitems; |
|
|
900 | unsigned long bytes_after; |
|
|
901 | unsigned char *prop; |
|
|
902 | XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
903 | 0, 1<<30, 0, AnyPropertyType, |
|
|
904 | &type, &format, &nitems, &bytes_after, &prop); |
|
|
905 | if (type != None) |
|
|
906 | { |
|
|
907 | EXTEND (SP, 3); |
|
|
908 | PUSHs (newSVuv ((U32)type)); |
|
|
909 | PUSHs (newSViv (format)); |
|
|
910 | PUSHs (newSVpvn ((char *)prop, nitems * format / 8)); |
|
|
911 | XFree (prop); |
|
|
912 | } |
|
|
913 | } |
|
|
914 | |
|
|
915 | void |
|
|
916 | rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data) |
|
|
917 | CODE: |
|
|
918 | { |
|
|
919 | STRLEN len; |
|
|
920 | char *data_ = SvPVbyte (data, len); |
|
|
921 | |
|
|
922 | XChangeProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
923 | type, format, PropModeReplace, |
|
|
924 | (unsigned char *)data, len * 8 / format); |
|
|
925 | } |
|
|
926 | |
|
|
927 | void |
|
|
928 | rxvt_term::XDeleteProperty (U32 window, U32 property) |
|
|
929 | CODE: |
|
|
930 | XDeleteProperty (THIS->display->display, (Window)window, (Atom)property); |
|
|
931 | |
|
|
932 | U32 |
|
|
933 | rxvt_term::DefaultRootWindow () |
|
|
934 | CODE: |
|
|
935 | RETVAL = (U32)THIS->display->root; |
|
|
936 | OUTPUT: |
|
|
937 | RETVAL |
|
|
938 | |
|
|
939 | U32 |
|
|
940 | rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height) |
|
|
941 | CODE: |
|
|
942 | RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent, |
|
|
943 | x, y, width, height, 0, |
|
|
944 | THIS->pix_colors_focused[Color_border], |
|
|
945 | THIS->pix_colors_focused[Color_border]); |
|
|
946 | OUTPUT: |
|
|
947 | RETVAL |
|
|
948 | |
|
|
949 | void |
|
|
950 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
|
|
951 | CODE: |
|
|
952 | XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y); |
|
|
953 | |
|
|
954 | void |
|
|
955 | rxvt_term::XMapWindow (U32 window) |
|
|
956 | CODE: |
|
|
957 | XMapWindow (THIS->display->display, (Window)window); |
|
|
958 | |
|
|
959 | void |
|
|
960 | rxvt_term::XUnmapWindow (U32 window) |
|
|
961 | CODE: |
|
|
962 | XUnmapWindow (THIS->display->display, (Window)window); |
|
|
963 | |
|
|
964 | #endif |
|
|
965 | |
|
|
966 | void |
|
|
967 | rxvt_term::set_should_invoke (int htype, int inc) |
|
|
968 | CODE: |
|
|
969 | THIS->perl.should_invoke [htype] += inc; |
|
|
970 | |
|
|
971 | void |
|
|
972 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
973 | CODE: |
|
|
974 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
975 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
976 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
977 | |
|
|
978 | bool |
|
|
979 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
980 | CODE: |
|
|
981 | { |
|
|
982 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
983 | |
|
|
984 | THIS->perl.grabtime = 0; |
|
|
985 | |
|
|
986 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
987 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
988 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
989 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
990 | THIS->perl.grabtime = eventtime; |
|
|
991 | else |
|
|
992 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
993 | |
|
|
994 | RETVAL = !!THIS->perl.grabtime; |
|
|
995 | } |
|
|
996 | OUTPUT: |
|
|
997 | RETVAL |
|
|
998 | |
|
|
999 | void |
|
|
1000 | rxvt_term::allow_events_async () |
|
|
1001 | CODE: |
|
|
1002 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
1003 | |
|
|
1004 | void |
|
|
1005 | rxvt_term::allow_events_sync () |
|
|
1006 | CODE: |
|
|
1007 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
1008 | |
|
|
1009 | void |
|
|
1010 | rxvt_term::allow_events_replay () |
|
|
1011 | CODE: |
|
|
1012 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
1013 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
1014 | |
|
|
1015 | void |
|
|
1016 | rxvt_term::ungrab () |
|
|
1017 | CODE: |
|
|
1018 | ungrab (THIS); |
653 | |
1019 | |
654 | int |
1020 | int |
655 | rxvt_term::strwidth (SV *str) |
1021 | rxvt_term::strwidth (SV *str) |
656 | CODE: |
1022 | CODE: |
657 | { |
1023 | { |
… | |
… | |
699 | free (wstr); |
1065 | free (wstr); |
700 | } |
1066 | } |
701 | OUTPUT: |
1067 | OUTPUT: |
702 | RETVAL |
1068 | RETVAL |
703 | |
1069 | |
704 | # very portable, especially on objects as opposed to pods |
1070 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
705 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
706 | |
1071 | |
707 | #define TERM_OFFSET_width TERM_OFFSET(width) |
1072 | #define TERM_OFFSET_width TERM_OFFSET(width) |
708 | #define TERM_OFFSET_height TERM_OFFSET(height) |
1073 | #define TERM_OFFSET_height TERM_OFFSET(height) |
709 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
1074 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
710 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
1075 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
713 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1078 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
714 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1079 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
715 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1080 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
716 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1081 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
717 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1082 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
718 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
1083 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
719 | |
1084 | |
720 | int |
1085 | int |
721 | rxvt_term::width () |
1086 | rxvt_term::width () |
722 | ALIAS: |
1087 | ALIAS: |
723 | width = TERM_OFFSET_width |
1088 | width = TERM_OFFSET_width |
… | |
… | |
729 | ncol = TERM_OFFSET_ncol |
1094 | ncol = TERM_OFFSET_ncol |
730 | focus = TERM_OFFSET_focus |
1095 | focus = TERM_OFFSET_focus |
731 | mapped = TERM_OFFSET_mapped |
1096 | mapped = TERM_OFFSET_mapped |
732 | saveLines = TERM_OFFSET_saveLines |
1097 | saveLines = TERM_OFFSET_saveLines |
733 | total_rows = TERM_OFFSET_total_rows |
1098 | total_rows = TERM_OFFSET_total_rows |
734 | nsaved = TERM_OFFSET_nsaved |
1099 | top_row = TERM_OFFSET_top_row |
735 | CODE: |
1100 | CODE: |
736 | RETVAL = *(int *)((char *)THIS + ix); |
1101 | RETVAL = *(int *)((char *)THIS + ix); |
737 | OUTPUT: |
1102 | OUTPUT: |
738 | RETVAL |
1103 | RETVAL |
|
|
1104 | |
|
|
1105 | unsigned int |
|
|
1106 | rxvt_term::ModLevel3Mask () |
|
|
1107 | ALIAS: |
|
|
1108 | ModLevel3Mask = 0 |
|
|
1109 | ModMetaMask = 1 |
|
|
1110 | ModNumLockMask = 2 |
|
|
1111 | CODE: |
|
|
1112 | switch (ix) |
|
|
1113 | { |
|
|
1114 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
1115 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
1116 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
1117 | } |
|
|
1118 | OUTPUT: |
|
|
1119 | RETVAL |
|
|
1120 | |
|
|
1121 | char * |
|
|
1122 | rxvt_term::display_id () |
|
|
1123 | ALIAS: |
|
|
1124 | display_id = 0 |
|
|
1125 | locale = 1 |
|
|
1126 | CODE: |
|
|
1127 | switch (ix) |
|
|
1128 | { |
|
|
1129 | case 0: RETVAL = THIS->display->id; break; |
|
|
1130 | case 1: RETVAL = THIS->locale; break; |
|
|
1131 | } |
|
|
1132 | OUTPUT: |
|
|
1133 | RETVAL |
|
|
1134 | |
|
|
1135 | SV * |
|
|
1136 | rxvt_term::_env () |
|
|
1137 | CODE: |
|
|
1138 | { |
|
|
1139 | if (THIS->envv) |
|
|
1140 | { |
|
|
1141 | AV *av = newAV (); |
|
|
1142 | |
|
|
1143 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1144 | if (*i) |
|
|
1145 | av_push (av, newSVpv (*i, 0)); |
|
|
1146 | |
|
|
1147 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1148 | } |
|
|
1149 | else |
|
|
1150 | RETVAL = &PL_sv_undef; |
|
|
1151 | } |
|
|
1152 | OUTPUT: |
|
|
1153 | RETVAL |
|
|
1154 | |
|
|
1155 | int |
|
|
1156 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1157 | CODE: |
|
|
1158 | RETVAL = THIS->pty_ev.events; |
|
|
1159 | if (events != EVENT_UNDEF) |
|
|
1160 | THIS->pty_ev.set (events); |
|
|
1161 | OUTPUT: |
|
|
1162 | RETVAL |
|
|
1163 | |
|
|
1164 | U32 |
|
|
1165 | rxvt_term::parent () |
|
|
1166 | CODE: |
|
|
1167 | RETVAL = (U32)THIS->parent [0]; |
|
|
1168 | OUTPUT: |
|
|
1169 | RETVAL |
|
|
1170 | |
|
|
1171 | U32 |
|
|
1172 | rxvt_term::vt () |
|
|
1173 | CODE: |
|
|
1174 | RETVAL = (U32)THIS->vt; |
|
|
1175 | OUTPUT: |
|
|
1176 | RETVAL |
|
|
1177 | |
|
|
1178 | void |
|
|
1179 | rxvt_term::vt_emask_add (U32 emask) |
|
|
1180 | CODE: |
|
|
1181 | THIS->vt_emask_perl |= emask; |
|
|
1182 | THIS->vt_select_input (); |
739 | |
1183 | |
740 | U32 |
1184 | U32 |
741 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
1185 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
742 | CODE: |
1186 | CODE: |
743 | { |
|
|
744 | RETVAL = THIS->rstyle; |
1187 | RETVAL = THIS->rstyle; |
745 | THIS->rstyle = new_rstyle; |
1188 | THIS->rstyle = new_rstyle; |
746 | } |
|
|
747 | OUTPUT: |
1189 | OUTPUT: |
748 | RETVAL |
1190 | RETVAL |
749 | |
1191 | |
750 | int |
1192 | int |
751 | rxvt_term::view_start (int newval = -1) |
1193 | rxvt_term::view_start (int newval = 1) |
|
|
1194 | PROTOTYPE: $;$ |
752 | CODE: |
1195 | CODE: |
753 | { |
1196 | { |
754 | RETVAL = THIS->view_start; |
1197 | RETVAL = THIS->view_start; |
755 | |
1198 | |
756 | if (newval >= 0) |
1199 | if (newval <= 0) |
757 | { |
1200 | THIS->scr_changeview (max (newval, THIS->top_row)); |
758 | THIS->view_start = min (newval, THIS->nsaved); |
|
|
759 | THIS->scr_changeview (RETVAL); |
|
|
760 | } |
|
|
761 | } |
1201 | } |
762 | OUTPUT: |
1202 | OUTPUT: |
763 | RETVAL |
1203 | RETVAL |
764 | |
1204 | |
765 | void |
1205 | void |
… | |
… | |
769 | |
1209 | |
770 | void |
1210 | void |
771 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1211 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
772 | PPCODE: |
1212 | PPCODE: |
773 | { |
1213 | { |
774 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1214 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
775 | XSRETURN_EMPTY; |
1215 | XSRETURN_EMPTY; |
776 | |
1216 | |
777 | line_t &l = ROW(row_number); |
1217 | line_t &l = ROW(row_number); |
778 | |
1218 | |
779 | if (GIMME_V != G_VOID) |
1219 | if (GIMME_V != G_VOID) |
780 | { |
1220 | { |
781 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1221 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
782 | |
1222 | |
783 | for (int col = 0; col <THIS->ncol; col++) |
1223 | for (int col = 0; col < THIS->ncol; col++) |
784 | wstr [col] = l.t [col]; |
1224 | wstr [col] = l.t [col]; |
785 | |
1225 | |
786 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
1226 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
787 | |
1227 | |
788 | delete [] wstr; |
1228 | delete [] wstr; |
789 | } |
1229 | } |
790 | |
1230 | |
791 | if (new_text) |
1231 | if (new_text) |
… | |
… | |
812 | |
1252 | |
813 | void |
1253 | void |
814 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1254 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
815 | PPCODE: |
1255 | PPCODE: |
816 | { |
1256 | { |
817 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1257 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
818 | XSRETURN_EMPTY; |
1258 | XSRETURN_EMPTY; |
819 | |
1259 | |
820 | line_t &l = ROW(row_number); |
1260 | line_t &l = ROW(row_number); |
821 | |
1261 | |
822 | if (GIMME_V != G_VOID) |
1262 | if (GIMME_V != G_VOID) |
… | |
… | |
852 | |
1292 | |
853 | int |
1293 | int |
854 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1294 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
855 | CODE: |
1295 | CODE: |
856 | { |
1296 | { |
857 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1297 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
858 | XSRETURN_EMPTY; |
1298 | XSRETURN_EMPTY; |
859 | |
1299 | |
860 | line_t &l = ROW(row_number); |
1300 | line_t &l = ROW(row_number); |
861 | RETVAL = l.l; |
1301 | RETVAL = l.l; |
862 | |
1302 | |
… | |
… | |
868 | |
1308 | |
869 | bool |
1309 | bool |
870 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1310 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
871 | CODE: |
1311 | CODE: |
872 | { |
1312 | { |
873 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1313 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
874 | XSRETURN_EMPTY; |
1314 | XSRETURN_EMPTY; |
875 | |
1315 | |
876 | line_t &l = ROW(row_number); |
1316 | line_t &l = ROW(row_number); |
877 | RETVAL = l.is_longer (); |
1317 | RETVAL = l.is_longer (); |
878 | |
1318 | |
… | |
… | |
881 | } |
1321 | } |
882 | OUTPUT: |
1322 | OUTPUT: |
883 | RETVAL |
1323 | RETVAL |
884 | |
1324 | |
885 | SV * |
1325 | SV * |
886 | rxvt_term::special_encode (SV *str) |
1326 | rxvt_term::special_encode (SV *string) |
887 | CODE: |
1327 | CODE: |
888 | abort ();//TODO |
1328 | { |
|
|
1329 | wchar_t *wstr = sv2wcs (string); |
|
|
1330 | int wlen = wcslen (wstr); |
|
|
1331 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1332 | |
|
|
1333 | rxvt_push_locale (THIS->locale); |
|
|
1334 | |
|
|
1335 | wchar_t *r = rstr; |
|
|
1336 | for (wchar_t *s = wstr; *s; s++) |
|
|
1337 | if (wcwidth (*s) == 0) |
|
|
1338 | { |
|
|
1339 | if (r == rstr) |
|
|
1340 | croak ("leading combining character unencodable"); |
|
|
1341 | |
|
|
1342 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1343 | if (n == NOCHAR) |
|
|
1344 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1345 | |
|
|
1346 | r[-1] = n; |
|
|
1347 | } |
|
|
1348 | #if !UNICODE_3 |
|
|
1349 | else if (*s >= 0x10000) |
|
|
1350 | *r++ = rxvt_composite.compose (*s); |
|
|
1351 | #endif |
|
|
1352 | else |
|
|
1353 | *r++ = *s; |
|
|
1354 | |
|
|
1355 | rxvt_pop_locale (); |
|
|
1356 | |
|
|
1357 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1358 | |
|
|
1359 | delete [] rstr; |
|
|
1360 | } |
|
|
1361 | OUTPUT: |
|
|
1362 | RETVAL |
889 | |
1363 | |
890 | SV * |
1364 | SV * |
891 | rxvt_term::special_decode (SV *str) |
1365 | rxvt_term::special_decode (SV *text) |
892 | CODE: |
1366 | CODE: |
893 | abort ();//TODO |
1367 | { |
|
|
1368 | wchar_t *wstr = sv2wcs (text); |
|
|
1369 | int wlen = wcslen (wstr); |
|
|
1370 | int dlen = 0; |
|
|
1371 | |
|
|
1372 | // find length |
|
|
1373 | for (wchar_t *s = wstr; *s; s++) |
|
|
1374 | if (*s == NOCHAR) |
|
|
1375 | ; |
|
|
1376 | else if (IS_COMPOSE (*s)) |
|
|
1377 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1378 | else |
|
|
1379 | dlen++; |
|
|
1380 | |
|
|
1381 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1382 | |
|
|
1383 | // decode |
|
|
1384 | wchar_t *r = rstr; |
|
|
1385 | for (wchar_t *s = wstr; *s; s++) |
|
|
1386 | if (*s == NOCHAR) |
|
|
1387 | ; |
|
|
1388 | else if (IS_COMPOSE (*s)) |
|
|
1389 | r += rxvt_composite.expand (*s, r); |
|
|
1390 | else |
|
|
1391 | *r++ = *s; |
|
|
1392 | |
|
|
1393 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1394 | |
|
|
1395 | delete [] rstr; |
|
|
1396 | } |
|
|
1397 | OUTPUT: |
|
|
1398 | RETVAL |
894 | |
1399 | |
895 | void |
1400 | void |
896 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1401 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
897 | PPCODE: |
1402 | PPCODE: |
898 | { |
1403 | { |
… | |
… | |
930 | else |
1435 | else |
931 | THIS->rs [index] = 0; |
1436 | THIS->rs [index] = 0; |
932 | } |
1437 | } |
933 | } |
1438 | } |
934 | |
1439 | |
|
|
1440 | const char * |
|
|
1441 | rxvt_term::x_resource (const char *name) |
|
|
1442 | |
|
|
1443 | bool |
|
|
1444 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1445 | CODE: |
|
|
1446 | { |
|
|
1447 | RETVAL = THIS->options & optval; |
|
|
1448 | |
|
|
1449 | if (set >= 0) |
|
|
1450 | { |
|
|
1451 | if (set) |
|
|
1452 | THIS->options |= optval; |
|
|
1453 | else |
|
|
1454 | THIS->options &= ~optval; |
|
|
1455 | |
|
|
1456 | switch (optval) |
|
|
1457 | { |
|
|
1458 | case Opt_skipBuiltinGlyphs: |
|
|
1459 | THIS->set_fonts (); |
|
|
1460 | THIS->scr_remap_chars (); |
|
|
1461 | THIS->scr_touch (true); |
|
|
1462 | THIS->want_refresh = 1; |
|
|
1463 | break; |
|
|
1464 | |
|
|
1465 | case Opt_cursorUnderline: |
|
|
1466 | THIS->want_refresh = 1; |
|
|
1467 | break; |
|
|
1468 | |
|
|
1469 | # case Opt_scrollBar_floating: |
|
|
1470 | # case Opt_scrollBar_right: |
|
|
1471 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1472 | # break; |
|
|
1473 | } |
|
|
1474 | } |
|
|
1475 | } |
|
|
1476 | OUTPUT: |
|
|
1477 | RETVAL |
|
|
1478 | |
|
|
1479 | bool |
|
|
1480 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1481 | CODE: |
|
|
1482 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1483 | THIS->keyboard->register_done (); |
|
|
1484 | OUTPUT: |
|
|
1485 | RETVAL |
|
|
1486 | |
935 | void |
1487 | void |
936 | rxvt_term::cur (...) |
1488 | rxvt_term::screen_cur (...) |
937 | PROTOTYPE: $;$$ |
1489 | PROTOTYPE: $;$$ |
938 | ALIAS: |
1490 | ALIAS: |
939 | screen_cur = 0 |
1491 | screen_cur = 0 |
940 | selection_beg = 1 |
1492 | selection_beg = 1 |
941 | selection_end = 2 |
1493 | selection_end = 2 |
… | |
… | |
954 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1506 | PUSHs (sv_2mortal (newSViv (rc.col))); |
955 | } |
1507 | } |
956 | |
1508 | |
957 | if (items == 3) |
1509 | if (items == 3) |
958 | { |
1510 | { |
959 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1511 | rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); |
960 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1512 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
961 | |
1513 | |
962 | if (ix) |
1514 | if (ix) |
963 | THIS->want_refresh = 1; |
1515 | THIS->want_refresh = 1; |
964 | } |
1516 | } |
965 | } |
1517 | } |
966 | |
1518 | |
|
|
1519 | char |
|
|
1520 | rxvt_term::cur_charset () |
|
|
1521 | CODE: |
|
|
1522 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1523 | OUTPUT: |
|
|
1524 | RETVAL |
|
|
1525 | |
|
|
1526 | #void |
|
|
1527 | #rxvt_term::selection_clear () |
|
|
1528 | |
|
|
1529 | void |
|
|
1530 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1531 | CODE: |
|
|
1532 | THIS->selection.op = SELECTION_CONT; |
|
|
1533 | THIS->selection.rect = rect; |
|
|
1534 | THIS->selection_make (eventtime); |
|
|
1535 | |
967 | int |
1536 | int |
968 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1537 | rxvt_term::selection_grab (U32 eventtime) |
969 | |
1538 | |
970 | void |
1539 | void |
971 | rxvt_term::selection (SV *newtext = 0) |
1540 | rxvt_term::selection (SV *newtext = 0) |
972 | PPCODE: |
1541 | PPCODE: |
973 | { |
1542 | { |
974 | if (GIMME_V != G_VOID) |
1543 | if (GIMME_V != G_VOID) |
|
|
1544 | XPUSHs (THIS->selection.text |
975 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1545 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
|
|
1546 | : &PL_sv_undef); |
976 | |
1547 | |
977 | if (newtext) |
1548 | if (newtext) |
978 | { |
1549 | { |
979 | free (THIS->selection.text); |
1550 | free (THIS->selection.text); |
980 | |
1551 | |
… | |
… | |
982 | THIS->selection.len = wcslen (THIS->selection.text); |
1553 | THIS->selection.len = wcslen (THIS->selection.text); |
983 | } |
1554 | } |
984 | } |
1555 | } |
985 | |
1556 | |
986 | void |
1557 | void |
|
|
1558 | rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline) |
|
|
1559 | |
|
|
1560 | void |
|
|
1561 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1562 | |
|
|
1563 | void |
|
|
1564 | rxvt_term::scr_bell () |
|
|
1565 | |
|
|
1566 | void |
987 | rxvt_term::scr_add_lines (SV *string) |
1567 | rxvt_term::scr_add_lines (SV *string) |
988 | CODE: |
1568 | CODE: |
989 | { |
1569 | { |
990 | wchar_t *wstr = sv2wcs (string); |
1570 | wchar_t *wstr = sv2wcs (string); |
991 | int wlen = wcslen (wstr); |
|
|
992 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
993 | int nlines = 0; |
|
|
994 | |
|
|
995 | for (int i = wlen; i--; ) |
|
|
996 | { |
|
|
997 | ustr [i] = wstr [i]; |
|
|
998 | nlines += ustr [i] == '\012'; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | THIS->scr_add_lines (ustr, nlines, wlen); |
1571 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1002 | |
|
|
1003 | free (wstr); |
1572 | free (wstr); |
1004 | delete [] ustr; |
|
|
1005 | } |
1573 | } |
1006 | |
1574 | |
1007 | void |
1575 | void |
1008 | rxvt_term::tt_write (SV *octets) |
1576 | rxvt_term::tt_write (SV *octets) |
1009 | INIT: |
1577 | INIT: |
… | |
… | |
1023 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1591 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1024 | |
1592 | |
1025 | THIS->cmdbuf_ptr = str; |
1593 | THIS->cmdbuf_ptr = str; |
1026 | THIS->cmdbuf_endp = str + len; |
1594 | THIS->cmdbuf_endp = str + len; |
1027 | |
1595 | |
|
|
1596 | rxvt_push_locale (THIS->locale); |
1028 | THIS->cmd_parse (); |
1597 | THIS->cmd_parse (); |
|
|
1598 | rxvt_pop_locale (); |
1029 | |
1599 | |
1030 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1600 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1031 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1601 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1032 | } |
1602 | } |
1033 | |
1603 | |