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-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de> |
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. |
… | |
… | |
107 | |
107 | |
108 | ///////////////////////////////////////////////////////////////////////////// |
108 | ///////////////////////////////////////////////////////////////////////////// |
109 | |
109 | |
110 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
110 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
111 | |
111 | |
112 | class overlay { |
112 | class overlay : overlay_base |
|
|
113 | { |
113 | rxvt_term *THIS; |
114 | rxvt_term *THIS; |
114 | AV *overlay_av; |
115 | AV *overlay_av; |
115 | int x, y, w, h; |
|
|
116 | int border; |
116 | int border; |
117 | text_t **text; |
|
|
118 | rend_t **rend; |
|
|
119 | |
117 | |
120 | public: |
118 | public: |
121 | HV *self; |
119 | HV *self; |
122 | |
120 | |
123 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
121 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
… | |
… | |
130 | |
128 | |
131 | void set (int x, int y, SV *str, SV *rend); |
129 | void set (int x, int y, SV *str, SV *rend); |
132 | }; |
130 | }; |
133 | |
131 | |
134 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
132 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
135 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) |
133 | : THIS(THIS), border(border == 2), overlay_av (0) |
136 | { |
134 | { |
|
|
135 | x = x_; |
|
|
136 | y = y_; |
|
|
137 | w = w_; |
|
|
138 | h = h_; |
|
|
139 | |
137 | if (w < 0) w = 0; |
140 | if (w < 0) w = 0; |
138 | if (h < 0) h = 0; |
141 | if (h < 0) h = 0; |
139 | |
142 | |
140 | if (border == 2) |
143 | if (border == 2) |
141 | { |
144 | { |
… | |
… | |
245 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
248 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
246 | |
249 | |
247 | int ov_w = min (w, THIS->ncol - ov_x); |
250 | int ov_w = min (w, THIS->ncol - ov_x); |
248 | int ov_h = min (h, THIS->nrow - ov_y); |
251 | int ov_h = min (h, THIS->nrow - ov_y); |
249 | |
252 | |
|
|
253 | // hide cursor if it is within the overlay area |
|
|
254 | if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w) |
|
|
255 | && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h)) |
|
|
256 | THIS->screen.flags &= ~Screen_VisibleCursor; |
|
|
257 | |
250 | for (int y = ov_h; y--; ) |
258 | for (int y = ov_h; y--; ) |
251 | { |
259 | { |
252 | text_t *t1 = text [y]; |
260 | text_t *t1 = text [y]; |
253 | rend_t *r1 = rend [y]; |
261 | rend_t *r1 = rend [y]; |
254 | |
262 | |
… | |
… | |
294 | THIS->refresh_check (); |
302 | THIS->refresh_check (); |
295 | } |
303 | } |
296 | |
304 | |
297 | ///////////////////////////////////////////////////////////////////////////// |
305 | ///////////////////////////////////////////////////////////////////////////// |
298 | |
306 | |
299 | #define IOM_CLASS "urxvt" |
|
|
300 | #define IOM_WARN rxvt_warn |
|
|
301 | #include "iom_perl.h" |
307 | #include "iom_perl.h" |
302 | |
308 | |
303 | ///////////////////////////////////////////////////////////////////////////// |
309 | ///////////////////////////////////////////////////////////////////////////// |
304 | |
310 | |
305 | struct rxvt_perl_interp rxvt_perl; |
311 | struct rxvt_perl_interp rxvt_perl; |
… | |
… | |
310 | { |
316 | { |
311 | if (perl) |
317 | if (perl) |
312 | { |
318 | { |
313 | perl_destruct (perl); |
319 | perl_destruct (perl); |
314 | perl_free (perl); |
320 | perl_free (perl); |
|
|
321 | PERL_SYS_TERM (); |
315 | } |
322 | } |
316 | } |
323 | } |
317 | |
324 | |
318 | void |
325 | void |
319 | rxvt_perl_interp::init (rxvt_term *term) |
326 | rxvt_perl_interp::init (rxvt_term *term) |
320 | { |
327 | { |
321 | if (!perl) |
328 | if (!perl) |
322 | { |
329 | { |
323 | rxvt_push_locale (""); // perl init destroys current locale |
330 | rxvt_push_locale (""); // perl init destroys current locale |
324 | |
331 | |
|
|
332 | { |
325 | perl_environ = rxvt_environ; |
333 | perl_environ = rxvt_environ; |
326 | swap (perl_environ, environ); |
334 | localise_env set_environ (perl_environ); |
327 | |
335 | |
328 | char *argv[] = { |
336 | char *args[] = { |
329 | "", |
337 | "", |
330 | "-e" |
338 | "-e" |
331 | "BEGIN {" |
339 | "BEGIN {" |
332 | " urxvt->bootstrap;" |
340 | " urxvt->bootstrap;" |
333 | " unshift @INC, '" LIBDIR "';" |
341 | " unshift @INC, '" LIBDIR "';" |
334 | "}" |
342 | "}" |
335 | "" |
343 | "" |
336 | "use urxvt;" |
344 | "use urxvt;" |
337 | }; |
345 | }; |
|
|
346 | int argc = ecb_array_length (args); |
|
|
347 | char **argv = args; |
338 | |
348 | |
|
|
349 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
339 | perl = perl_alloc (); |
350 | perl = perl_alloc (); |
340 | perl_construct (perl); |
351 | perl_construct (perl); |
341 | |
352 | |
342 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
353 | if (perl_parse (perl, xs_init, argc, argv, (char **)NULL) |
343 | || perl_run (perl)) |
354 | || perl_run (perl)) |
344 | { |
355 | { |
345 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
356 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
346 | |
357 | |
347 | perl_destruct (perl); |
358 | perl_destruct (perl); |
348 | perl_free (perl); |
359 | perl_free (perl); |
349 | perl = 0; |
360 | perl = 0; |
350 | } |
361 | } |
351 | |
362 | } |
352 | swap (perl_environ, environ); |
|
|
353 | |
363 | |
354 | rxvt_pop_locale (); |
364 | rxvt_pop_locale (); |
355 | } |
365 | } |
356 | |
366 | |
357 | if (perl) |
367 | if (perl) |
… | |
… | |
377 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
387 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
378 | { |
388 | { |
379 | if (!perl || !term->perl.self) |
389 | if (!perl || !term->perl.self) |
380 | return false; |
390 | return false; |
381 | |
391 | |
|
|
392 | localise_env set_environ (perl_environ); |
|
|
393 | |
382 | // pre-handling of some events |
394 | // pre-handling of some events |
383 | if (htype == HOOK_REFRESH_END) |
395 | if (htype == HOOK_REFRESH_END) |
384 | { |
396 | { |
385 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
397 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
386 | |
398 | |
387 | for (int i = 0; i <= AvFILL (av); i++) |
399 | for (int i = 0; i <= AvFILL (av); i++) |
388 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
400 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
389 | } |
401 | } |
390 | |
402 | |
391 | swap (perl_environ, environ); |
|
|
392 | |
|
|
393 | bool event_consumed; |
403 | bool event_consumed; |
394 | |
404 | |
395 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
405 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
396 | || term->perl.should_invoke [htype]) |
406 | || term->perl.should_invoke [htype]) |
397 | try |
|
|
398 | { |
407 | { |
399 | dSP; |
408 | dSP; |
400 | va_list ap; |
409 | va_list ap; |
401 | |
410 | |
402 | va_start (ap, htype); |
411 | va_start (ap, htype); |
403 | |
412 | |
404 | ENTER; |
413 | ENTER; |
405 | SAVETMPS; |
414 | SAVETMPS; |
406 | |
415 | |
407 | PUSHMARK (SP); |
416 | PUSHMARK (SP); |
408 | |
417 | |
|
|
418 | EXTEND (SP, 2); |
409 | XPUSHs (sv_2mortal (newSVterm (term))); |
419 | PUSHs (sv_2mortal (newSVterm (term))); |
410 | XPUSHs (sv_2mortal (newSViv (htype))); |
420 | PUSHs (sv_2mortal (newSViv (htype))); |
411 | |
421 | |
412 | for (;;) { |
422 | for (;;) { |
413 | data_type dt = (data_type)va_arg (ap, int); |
423 | data_type dt = (data_type)va_arg (ap, int); |
414 | |
424 | |
415 | switch (dt) |
425 | switch (dt) |
416 | { |
426 | { |
417 | case DT_INT: |
427 | case DT_INT: |
418 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
428 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
419 | break; |
429 | break; |
420 | |
430 | |
421 | case DT_LONG: |
431 | case DT_LONG: |
422 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
432 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
423 | break; |
433 | break; |
424 | |
434 | |
425 | case DT_STR: |
435 | case DT_STR: |
426 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
436 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
427 | break; |
437 | break; |
428 | |
438 | |
429 | case DT_STR_LEN: |
439 | case DT_STR_LEN: |
430 | { |
440 | { |
431 | char *str = va_arg (ap, char *); |
441 | char *str = va_arg (ap, char *); |
432 | int len = va_arg (ap, int); |
442 | int len = va_arg (ap, int); |
433 | |
443 | |
434 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
444 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
435 | } |
445 | } |
436 | break; |
446 | break; |
437 | |
447 | |
438 | case DT_WCS_LEN: |
448 | case DT_WCS_LEN: |
439 | { |
449 | { |
440 | wchar_t *wstr = va_arg (ap, wchar_t *); |
450 | wchar_t *wstr = va_arg (ap, wchar_t *); |
441 | int wlen = va_arg (ap, int); |
451 | int wlen = va_arg (ap, int); |
442 | |
452 | |
443 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
453 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
444 | } |
454 | } |
445 | break; |
455 | break; |
446 | |
456 | |
447 | case DT_LCS_LEN: |
457 | case DT_LCS_LEN: |
448 | { |
458 | { |
449 | long *lstr = va_arg (ap, long *); |
459 | long *lstr = va_arg (ap, long *); |
450 | int llen = va_arg (ap, int); |
460 | int llen = va_arg (ap, int); |
451 | |
461 | |
452 | XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); |
462 | XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); |
453 | } |
463 | } |
454 | break; |
464 | break; |
455 | |
465 | |
456 | case DT_XEVENT: |
466 | case DT_XEVENT: |
457 | { |
467 | { |
458 | XEvent *xe = va_arg (ap, XEvent *); |
468 | XEvent *xe = va_arg (ap, XEvent *); |
459 | HV *hv = newHV (); |
469 | HV *hv = newHV (); |
460 | |
470 | |
461 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
471 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
462 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
472 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
463 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
473 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
464 | # undef set |
474 | # undef set |
465 | |
475 | |
466 | setiv (type, xe->type); |
476 | setiv (type, xe->type); |
467 | setiv (send_event, xe->xany.send_event); |
477 | setiv (send_event, xe->xany.send_event); |
468 | setiv (serial, xe->xany.serial); |
478 | setiv (serial, xe->xany.serial); |
469 | |
479 | |
470 | switch (xe->type) |
480 | switch (xe->type) |
471 | { |
481 | { |
472 | case KeyPress: |
482 | case KeyPress: |
473 | case KeyRelease: |
483 | case KeyRelease: |
474 | case ButtonPress: |
484 | case ButtonPress: |
475 | case ButtonRelease: |
485 | case ButtonRelease: |
476 | case MotionNotify: |
486 | case MotionNotify: |
477 | setuv (window, xe->xmotion.window); |
487 | setuv (window, xe->xmotion.window); |
478 | setuv (root, xe->xmotion.root); |
488 | setuv (root, xe->xmotion.root); |
479 | setuv (subwindow, xe->xmotion.subwindow); |
489 | setuv (subwindow, xe->xmotion.subwindow); |
480 | setuv (time, xe->xmotion.time); |
490 | setuv (time, xe->xmotion.time); |
481 | setiv (x, xe->xmotion.x); |
491 | setiv (x, xe->xmotion.x); |
482 | setiv (y, xe->xmotion.y); |
492 | setiv (y, xe->xmotion.y); |
483 | setiv (row, xe->xmotion.y / term->fheight + term->view_start); |
493 | setiv (row, xe->xmotion.y / term->fheight + term->view_start); |
484 | setiv (col, xe->xmotion.x / term->fwidth); |
494 | setiv (col, xe->xmotion.x / term->fwidth); |
485 | setiv (x_root, xe->xmotion.x_root); |
495 | setiv (x_root, xe->xmotion.x_root); |
486 | setiv (y_root, xe->xmotion.y_root); |
496 | setiv (y_root, xe->xmotion.y_root); |
487 | setuv (state, xe->xmotion.state); |
497 | setuv (state, xe->xmotion.state); |
488 | |
498 | |
489 | switch (xe->type) |
499 | switch (xe->type) |
490 | { |
500 | { |
491 | case KeyPress: |
501 | case KeyPress: |
492 | case KeyRelease: |
502 | case KeyRelease: |
493 | setuv (keycode, xe->xkey.keycode); |
503 | setuv (keycode, xe->xkey.keycode); |
494 | break; |
504 | break; |
495 | |
505 | |
496 | case ButtonPress: |
506 | case ButtonPress: |
497 | case ButtonRelease: |
507 | case ButtonRelease: |
498 | setuv (button, xe->xbutton.button); |
508 | setuv (button, xe->xbutton.button); |
499 | break; |
509 | break; |
500 | |
510 | |
501 | case MotionNotify: |
511 | case MotionNotify: |
502 | setiv (is_hint, xe->xmotion.is_hint); |
512 | setiv (is_hint, xe->xmotion.is_hint); |
503 | break; |
513 | break; |
504 | } |
514 | } |
505 | |
515 | |
506 | break; |
516 | break; |
507 | |
517 | |
508 | case MapNotify: |
518 | case MapNotify: |
509 | case UnmapNotify: |
519 | case UnmapNotify: |
510 | case ConfigureNotify: |
520 | case ConfigureNotify: |
511 | setuv (event, xe->xconfigure.event); |
521 | setuv (event, xe->xconfigure.event); |
512 | setuv (window, xe->xconfigure.window); |
522 | setuv (window, xe->xconfigure.window); |
513 | |
523 | |
514 | switch (xe->type) |
524 | switch (xe->type) |
515 | { |
525 | { |
516 | case ConfigureNotify: |
526 | case ConfigureNotify: |
517 | setiv (x, xe->xconfigure.x); |
527 | setiv (x, xe->xconfigure.x); |
518 | setiv (y, xe->xconfigure.y); |
528 | setiv (y, xe->xconfigure.y); |
519 | setiv (width, xe->xconfigure.width); |
529 | setiv (width, xe->xconfigure.width); |
520 | setiv (height, xe->xconfigure.height); |
530 | setiv (height, xe->xconfigure.height); |
521 | setuv (above, xe->xconfigure.above); |
531 | setuv (above, xe->xconfigure.above); |
522 | break; |
532 | break; |
523 | } |
533 | } |
524 | |
534 | |
525 | break; |
535 | break; |
526 | |
536 | |
527 | case PropertyNotify: |
537 | case PropertyNotify: |
528 | setuv (window, xe->xproperty.window); |
538 | setuv (window, xe->xproperty.window); |
529 | setuv (atom, xe->xproperty.atom); |
539 | setuv (atom, xe->xproperty.atom); |
530 | setuv (time, xe->xproperty.time); |
540 | setuv (time, xe->xproperty.time); |
531 | setiv (state, xe->xproperty.state); |
541 | setiv (state, xe->xproperty.state); |
532 | break; |
542 | break; |
533 | |
543 | |
534 | case ClientMessage: |
544 | case ClientMessage: |
535 | setuv (window, xe->xclient.window); |
545 | setuv (window, xe->xclient.window); |
536 | setuv (message_type, xe->xclient.message_type); |
546 | setuv (message_type, xe->xclient.message_type); |
537 | setuv (format, xe->xclient.format); |
547 | setuv (format, xe->xclient.format); |
538 | setuv (l0, xe->xclient.data.l[0]); |
548 | setuv (l0, xe->xclient.data.l[0]); |
539 | setuv (l1, xe->xclient.data.l[1]); |
549 | setuv (l1, xe->xclient.data.l[1]); |
540 | setuv (l2, xe->xclient.data.l[2]); |
550 | setuv (l2, xe->xclient.data.l[2]); |
541 | setuv (l3, xe->xclient.data.l[3]); |
551 | setuv (l3, xe->xclient.data.l[3]); |
542 | setuv (l4, xe->xclient.data.l[4]); |
552 | setuv (l4, xe->xclient.data.l[4]); |
543 | break; |
553 | break; |
544 | } |
554 | } |
545 | |
555 | |
546 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
556 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
547 | } |
557 | } |
548 | break; |
558 | break; |
549 | |
559 | |
550 | case DT_END: |
560 | case DT_END: |
551 | goto call; |
561 | goto call; |
552 | |
562 | |
553 | default: |
563 | default: |
554 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
564 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
555 | } |
565 | } |
|
|
566 | } |
|
|
567 | |
|
|
568 | call: |
|
|
569 | va_end (ap); |
|
|
570 | |
|
|
571 | PUTBACK; |
|
|
572 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
573 | SPAGAIN; |
|
|
574 | |
|
|
575 | if (count) |
|
|
576 | { |
|
|
577 | SV *status = POPs; |
|
|
578 | count = SvTRUE (status); |
556 | } |
579 | } |
557 | |
580 | |
558 | call: |
|
|
559 | va_end (ap); |
|
|
560 | |
|
|
561 | PUTBACK; |
581 | PUTBACK; |
562 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
563 | SPAGAIN; |
|
|
564 | |
|
|
565 | if (count) |
|
|
566 | { |
|
|
567 | SV *status = POPs; |
|
|
568 | count = SvTRUE (status); |
|
|
569 | } |
|
|
570 | |
|
|
571 | PUTBACK; |
|
|
572 | FREETMPS; |
582 | FREETMPS; |
573 | LEAVE; |
583 | LEAVE; |
574 | |
584 | |
575 | if (SvTRUE (ERRSV)) |
585 | if (SvTRUE (ERRSV)) |
576 | { |
586 | { |
577 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
587 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV)); |
578 | ungrab (term); // better lose the grab than the session |
588 | ungrab (term); // better lose the grab than the session |
579 | } |
589 | } |
580 | |
590 | |
581 | event_consumed = !!count; |
591 | event_consumed = !!count; |
582 | } |
592 | } |
583 | catch (...) |
|
|
584 | { |
|
|
585 | swap (perl_environ, environ); |
|
|
586 | throw; |
|
|
587 | } |
|
|
588 | else |
593 | else |
589 | event_consumed = false; |
594 | event_consumed = false; |
590 | |
595 | |
591 | // post-handling of some events |
596 | // post-handling of some events |
592 | if (htype == HOOK_REFRESH_BEGIN) |
597 | if (htype == HOOK_REFRESH_BEGIN) |
… | |
… | |
603 | |
608 | |
604 | // don't allow further calls |
609 | // don't allow further calls |
605 | term->perl.self = 0; |
610 | term->perl.self = 0; |
606 | } |
611 | } |
607 | |
612 | |
608 | swap (perl_environ, environ); |
|
|
609 | |
|
|
610 | return event_consumed; |
613 | return event_consumed; |
|
|
614 | } |
|
|
615 | |
|
|
616 | void |
|
|
617 | rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len) |
|
|
618 | { |
|
|
619 | localise_env set_environ (perl_environ); |
|
|
620 | |
|
|
621 | ENTER; |
|
|
622 | SAVETMPS; |
|
|
623 | |
|
|
624 | dSP; |
|
|
625 | XPUSHs (sv_2mortal (newSVpvn (data, len))); |
|
|
626 | call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL); |
|
|
627 | |
|
|
628 | if (SvTRUE (ERRSV)) |
|
|
629 | rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV)); |
|
|
630 | |
|
|
631 | FREETMPS; |
|
|
632 | LEAVE; |
611 | } |
633 | } |
612 | |
634 | |
613 | ///////////////////////////////////////////////////////////////////////////// |
635 | ///////////////////////////////////////////////////////////////////////////// |
614 | |
636 | |
615 | MODULE = urxvt PACKAGE = urxvt |
637 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
627 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
649 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
628 | # include "hookinc.h" |
650 | # include "hookinc.h" |
629 | # undef def |
651 | # undef def |
630 | |
652 | |
631 | HV *option = get_hv ("urxvt::OPTION", 1); |
653 | HV *option = get_hv ("urxvt::OPTION", 1); |
632 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
654 | # define def(name) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
633 | # define nodef(name) |
655 | # define nodef(name) |
634 | # include "optinc.h" |
656 | # include "optinc.h" |
635 | # undef nodef |
657 | # undef nodef |
636 | # undef def |
658 | # undef def |
637 | |
659 | |
… | |
… | |
639 | static const struct { |
661 | static const struct { |
640 | const char *name; |
662 | const char *name; |
641 | IV iv; |
663 | IV iv; |
642 | } *civ, const_iv[] = { |
664 | } *civ, const_iv[] = { |
643 | # define const_iv(name) { # name, (IV)name } |
665 | # define const_iv(name) { # name, (IV)name } |
|
|
666 | const_iv (NUM_RESOURCES), |
644 | const_iv (DEFAULT_RSTYLE), |
667 | const_iv (DEFAULT_RSTYLE), |
645 | const_iv (OVERLAY_RSTYLE), |
668 | const_iv (OVERLAY_RSTYLE), |
|
|
669 | const_iv (Color_Bits), |
|
|
670 | const_iv (RS_bgShift), const_iv (RS_bgMask), |
|
|
671 | const_iv (RS_fgShift), const_iv (RS_fgMask), |
|
|
672 | const_iv (RS_Careful), |
|
|
673 | const_iv (RS_fontCount), |
|
|
674 | const_iv (RS_fontShift), |
|
|
675 | const_iv (RS_fontMask), |
|
|
676 | const_iv (RS_baseattrMask), |
|
|
677 | const_iv (RS_attrMask), |
|
|
678 | const_iv (RS_redraw), |
|
|
679 | const_iv (RS_Sel), |
646 | const_iv (RS_Bold), |
680 | const_iv (RS_Bold), |
647 | const_iv (RS_Italic), |
681 | const_iv (RS_Italic), |
648 | const_iv (RS_Blink), |
682 | const_iv (RS_Blink), |
649 | const_iv (RS_RVid), |
683 | const_iv (RS_RVid), |
650 | const_iv (RS_Uline), |
684 | const_iv (RS_Uline), |
… | |
… | |
754 | const_iv (XIMDontChange), |
788 | const_iv (XIMDontChange), |
755 | # endif |
789 | # endif |
756 | # endif |
790 | # endif |
757 | }; |
791 | }; |
758 | |
792 | |
759 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
793 | for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; ) |
760 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
794 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
761 | } |
795 | } |
762 | |
796 | |
763 | void |
797 | void |
764 | warn (const char *msg) |
798 | warn (const char *msg) |
… | |
… | |
836 | |
870 | |
837 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
871 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
838 | if ((*t)->perl.self) |
872 | if ((*t)->perl.self) |
839 | PUSHs (sv_2mortal (newSVterm (*t))); |
873 | PUSHs (sv_2mortal (newSVterm (*t))); |
840 | } |
874 | } |
|
|
875 | |
|
|
876 | IV |
|
|
877 | _new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb) |
|
|
878 | CODE: |
|
|
879 | rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term); |
|
|
880 | req->cb_sv = newSVsv (cb); |
|
|
881 | RETVAL = (IV)req; |
|
|
882 | OUTPUT: |
|
|
883 | RETVAL |
|
|
884 | |
|
|
885 | void |
|
|
886 | _delete_selection_request (IV req_) |
|
|
887 | CODE: |
|
|
888 | rxvt_selection *req = (rxvt_selection *)req_; |
|
|
889 | delete req; |
841 | |
890 | |
842 | MODULE = urxvt PACKAGE = urxvt::term |
891 | MODULE = urxvt PACKAGE = urxvt::term |
843 | |
892 | |
844 | SV * |
893 | SV * |
845 | _new (AV *env, AV *arg) |
894 | _new (AV *env, AV *arg) |
… | |
… | |
1042 | OUTPUT: |
1091 | OUTPUT: |
1043 | RETVAL |
1092 | RETVAL |
1044 | |
1093 | |
1045 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
1094 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
1046 | |
1095 | |
1047 | #define TERM_OFFSET_width TERM_OFFSET(width) |
1096 | #define TERM_OFFSET_width TERM_OFFSET(width) |
1048 | #define TERM_OFFSET_height TERM_OFFSET(height) |
1097 | #define TERM_OFFSET_height TERM_OFFSET(height) |
1049 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
1098 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
1050 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
1099 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
1051 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
1100 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
1052 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
1101 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
1053 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1102 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1054 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1103 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1055 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1104 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1056 | #define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) |
1105 | #define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) |
1057 | #define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) |
1106 | #define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) |
1058 | #define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) |
1107 | #define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) |
|
|
1108 | #define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace) |
1059 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1109 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1060 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1110 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1061 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
1111 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
1062 | |
1112 | |
1063 | int |
1113 | int |
1064 | rxvt_term::width () |
1114 | rxvt_term::width () |
1065 | ALIAS: |
1115 | ALIAS: |
1066 | width = TERM_OFFSET_width |
1116 | width = TERM_OFFSET_width |
1067 | height = TERM_OFFSET_height |
1117 | height = TERM_OFFSET_height |
1068 | fwidth = TERM_OFFSET_fwidth |
1118 | fwidth = TERM_OFFSET_fwidth |
1069 | fheight = TERM_OFFSET_fheight |
1119 | fheight = TERM_OFFSET_fheight |
1070 | fbase = TERM_OFFSET_fbase |
1120 | fbase = TERM_OFFSET_fbase |
1071 | nrow = TERM_OFFSET_nrow |
1121 | nrow = TERM_OFFSET_nrow |
1072 | ncol = TERM_OFFSET_ncol |
1122 | ncol = TERM_OFFSET_ncol |
1073 | focus = TERM_OFFSET_focus |
1123 | focus = TERM_OFFSET_focus |
1074 | mapped = TERM_OFFSET_mapped |
1124 | mapped = TERM_OFFSET_mapped |
1075 | int_bwidth = TERM_OFFSET_int_bwidth |
1125 | int_bwidth = TERM_OFFSET_int_bwidth |
1076 | ext_bwidth = TERM_OFFSET_ext_bwidth |
1126 | ext_bwidth = TERM_OFFSET_ext_bwidth |
1077 | lineSpace = TERM_OFFSET_lineSpace |
1127 | lineSpace = TERM_OFFSET_lineSpace |
|
|
1128 | letterSpace = TERM_OFFSET_letterSpace |
1078 | saveLines = TERM_OFFSET_saveLines |
1129 | saveLines = TERM_OFFSET_saveLines |
1079 | total_rows = TERM_OFFSET_total_rows |
1130 | total_rows = TERM_OFFSET_total_rows |
1080 | top_row = TERM_OFFSET_top_row |
1131 | top_row = TERM_OFFSET_top_row |
1081 | CODE: |
1132 | CODE: |
1082 | RETVAL = *(int *)((char *)THIS + ix); |
1133 | RETVAL = *(int *)((char *)THIS + ix); |
1083 | OUTPUT: |
1134 | OUTPUT: |
1084 | RETVAL |
1135 | RETVAL |
1085 | |
1136 | |
… | |
… | |
1096 | { |
1147 | { |
1097 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1148 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
1098 | case 1: RETVAL = THIS->ModMetaMask; break; |
1149 | case 1: RETVAL = THIS->ModMetaMask; break; |
1099 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1150 | case 2: RETVAL = THIS->ModNumLockMask; break; |
1100 | case 3: RETVAL = THIS->current_screen; break; |
1151 | case 3: RETVAL = THIS->current_screen; break; |
|
|
1152 | #ifdef CURSOR_BLINK |
1101 | case 4: RETVAL = THIS->hidden_cursor; break; |
1153 | case 4: RETVAL = THIS->hidden_cursor; break; |
|
|
1154 | #endif |
1102 | } |
1155 | } |
1103 | OUTPUT: |
1156 | OUTPUT: |
1104 | RETVAL |
1157 | RETVAL |
1105 | |
1158 | |
1106 | char * |
1159 | char * |
… | |
… | |
1149 | RETVAL |
1202 | RETVAL |
1150 | |
1203 | |
1151 | Window |
1204 | Window |
1152 | rxvt_term::parent () |
1205 | rxvt_term::parent () |
1153 | CODE: |
1206 | CODE: |
1154 | RETVAL = THIS->parent [0]; |
1207 | RETVAL = THIS->parent; |
1155 | OUTPUT: |
1208 | OUTPUT: |
1156 | RETVAL |
1209 | RETVAL |
1157 | |
1210 | |
1158 | Window |
1211 | Window |
1159 | rxvt_term::vt () |
1212 | rxvt_term::vt () |
… | |
… | |
1428 | # include "rsinc.h" |
1481 | # include "rsinc.h" |
1429 | # undef def |
1482 | # undef def |
1430 | # undef reserve |
1483 | # undef reserve |
1431 | }; |
1484 | }; |
1432 | |
1485 | |
1433 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1486 | rs = rslist + ecb_array_length (rslist); |
1434 | |
1487 | |
|
|
1488 | if (*name) |
1435 | do { |
1489 | { |
|
|
1490 | do { |
1436 | if (rs-- == rslist) |
1491 | if (rs-- == rslist) |
1437 | croak ("no such resource '%s', requested", name); |
1492 | croak ("no such resource '%s', requested", name); |
1438 | } while (strcmp (name, rs->name)); |
1493 | } while (strcmp (name, rs->name)); |
1439 | |
1494 | |
1440 | index += rs->value; |
1495 | index += rs->value; |
|
|
1496 | } |
|
|
1497 | else |
|
|
1498 | { |
|
|
1499 | --rs; |
|
|
1500 | name = ""; |
|
|
1501 | } |
1441 | |
1502 | |
1442 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1503 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1443 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1504 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1444 | |
1505 | |
1445 | if (GIMME_V != G_VOID) |
1506 | if (GIMME_V != G_VOID) |
… | |
… | |
1525 | EXTEND (SP, 2); |
1586 | EXTEND (SP, 2); |
1526 | PUSHs (sv_2mortal (newSViv (rc.row))); |
1587 | PUSHs (sv_2mortal (newSViv (rc.row))); |
1527 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1588 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1528 | } |
1589 | } |
1529 | |
1590 | |
1530 | if (items == 3) |
1591 | if (items >= 3) |
1531 | { |
1592 | { |
1532 | rc.row = SvIV (ST (1)); |
1593 | rc.row = SvIV (ST (1)); |
1533 | rc.col = SvIV (ST (2)); |
1594 | rc.col = SvIV (ST (2)); |
1534 | |
1595 | |
1535 | if (ix == 2) |
1596 | if (ix == 2) |
… | |
… | |
1551 | clamp_it (rc.col, 0, THIS->ncol); |
1612 | clamp_it (rc.col, 0, THIS->ncol); |
1552 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1613 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1553 | |
1614 | |
1554 | if (ix) |
1615 | if (ix) |
1555 | { |
1616 | { |
|
|
1617 | THIS->selection.screen = THIS->current_screen; |
|
|
1618 | |
1556 | THIS->want_refresh = 1; |
1619 | THIS->want_refresh = 1; |
1557 | THIS->refresh_check (); |
1620 | THIS->refresh_check (); |
1558 | } |
1621 | } |
1559 | } |
1622 | } |
1560 | } |
1623 | } |
1561 | |
1624 | |
1562 | char |
1625 | int |
1563 | rxvt_term::cur_charset () |
1626 | rxvt_term::selection_screen (int screen = -1) |
1564 | CODE: |
1627 | CODE: |
1565 | RETVAL = THIS->charsets [THIS->screen.charset]; |
1628 | RETVAL = THIS->selection.screen; |
1566 | OUTPUT: |
1629 | if (screen >= 0) |
|
|
1630 | THIS->selection.screen = screen; |
|
|
1631 | OUTPUT: |
1567 | RETVAL |
1632 | RETVAL |
1568 | |
1633 | |
1569 | void |
1634 | void |
1570 | rxvt_term::selection_clear () |
1635 | rxvt_term::selection_clear (bool clipboard = false) |
1571 | |
1636 | |
1572 | void |
1637 | void |
1573 | rxvt_term::selection_make (Time eventtime, bool rect = false) |
1638 | rxvt_term::selection_make (Time eventtime, bool rect = false) |
1574 | CODE: |
1639 | CODE: |
1575 | THIS->selection.op = SELECTION_CONT; |
1640 | THIS->selection.op = SELECTION_CONT; |
1576 | THIS->selection.rect = rect; |
1641 | THIS->selection.rect = rect; |
1577 | THIS->selection_make (eventtime); |
1642 | THIS->selection_make (eventtime); |
1578 | |
1643 | |
1579 | int |
1644 | int |
1580 | rxvt_term::selection_grab (Time eventtime) |
1645 | rxvt_term::selection_grab (Time eventtime, bool clipboard = false) |
1581 | |
1646 | |
1582 | void |
1647 | void |
1583 | rxvt_term::selection (SV *newtext = 0) |
1648 | rxvt_term::selection (SV *newtext = 0, bool clipboard = false) |
1584 | PPCODE: |
1649 | PPCODE: |
1585 | { |
1650 | { |
|
|
1651 | wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text; |
|
|
1652 | unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len; |
|
|
1653 | |
1586 | if (GIMME_V != G_VOID) |
1654 | if (GIMME_V != G_VOID) |
1587 | XPUSHs (THIS->selection.text |
1655 | XPUSHs (text |
1588 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1656 | ? sv_2mortal (wcs2sv (text, len)) |
1589 | : &PL_sv_undef); |
1657 | : &PL_sv_undef); |
1590 | |
1658 | |
1591 | if (newtext) |
1659 | if (newtext) |
1592 | { |
1660 | { |
1593 | free (THIS->selection.text); |
1661 | free (text); |
1594 | |
1662 | |
1595 | THIS->selection.text = sv2wcs (newtext); |
1663 | text = sv2wcs (newtext); |
1596 | THIS->selection.len = wcslen (THIS->selection.text); |
1664 | len = wcslen (text); |
1597 | } |
1665 | } |
1598 | } |
1666 | } |
|
|
1667 | |
|
|
1668 | char |
|
|
1669 | rxvt_term::cur_charset () |
|
|
1670 | CODE: |
|
|
1671 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1672 | OUTPUT: |
|
|
1673 | RETVAL |
1599 | |
1674 | |
1600 | void |
1675 | void |
1601 | 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) |
1676 | 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) |
1602 | |
1677 | |
1603 | void |
1678 | void |
… | |
… | |
1625 | char *str = SvPVbyte (octets, len); |
1700 | char *str = SvPVbyte (octets, len); |
1626 | C_ARGS: |
1701 | C_ARGS: |
1627 | str, len |
1702 | str, len |
1628 | |
1703 | |
1629 | void |
1704 | void |
|
|
1705 | rxvt_term::tt_paste (SV *octets) |
|
|
1706 | INIT: |
|
|
1707 | STRLEN len; |
|
|
1708 | char *str = SvPVbyte (octets, len); |
|
|
1709 | C_ARGS: |
|
|
1710 | str, len |
|
|
1711 | |
|
|
1712 | void |
1630 | rxvt_term::cmd_parse (SV *octets) |
1713 | rxvt_term::cmd_parse (SV *octets) |
1631 | CODE: |
1714 | CODE: |
1632 | { |
1715 | { |
1633 | STRLEN len; |
1716 | STRLEN len; |
1634 | char *str = SvPVbyte (octets, len); |
1717 | char *str = SvPVbyte (octets, len); |
… | |
… | |
1703 | XFree (prop); |
1786 | XFree (prop); |
1704 | } |
1787 | } |
1705 | } |
1788 | } |
1706 | |
1789 | |
1707 | void |
1790 | void |
1708 | rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) |
1791 | rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data) |
1709 | CODE: |
1792 | CODE: |
1710 | { |
1793 | { |
1711 | STRLEN len; |
1794 | STRLEN len; |
1712 | char *data_ = SvPVbyte (data, len); |
1795 | char *data_ = SvPVbyte (data, len); |
1713 | |
1796 | |