ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.109 by root, Thu Dec 14 15:19:31 2006 UTC vs.
Revision 1.172 by root, Tue Jun 5 22:46:50 2012 UTC

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,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.
23#define line_t perl_line_t 23#define line_t perl_line_t
24#include <EXTERN.h> 24#include <EXTERN.h>
25#include <perl.h> 25#include <perl.h>
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28#undef bool // perl defines it's own bool type, except with g++... what a trap
28 29
29#include "../config.h" 30#include "../config.h"
30 31
31#include <cstddef> 32#include <stddef.h>
32#include <cstdarg> 33#include <stdarg.h>
33 34
34#include "unistd.h" 35#include "unistd.h"
35 36
36#include "iom.h" 37#include "ev_cpp.h"
37#include "rxvt.h" 38#include "rxvt.h"
38#include "keyboard.h" 39#include "keyboard.h"
39#include "rxvtutil.h" 40#include "rxvtutil.h"
40#include "rxvtperl.h" 41#include "rxvtperl.h"
41 42
42#include "perlxsi.c" 43#include "perlxsi.c"
43 44
44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->leftptr_cursor 45#define GRAB_CURSOR THIS->scrollBar.leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
49 46
50#undef LINENO 47#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 49#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
54 51
55typedef int CHAINED UNUSED; 52/////////////////////////////////////////////////////////////////////////////
53
54typedef char * octet_string;
55typedef char * utf8_string;
56
57typedef int render_repeat_mode;
58
59typedef GdkPixbuf * urxvt__pixbuf;
60typedef rxvt_img * urxvt__img;
61
62/////////////////////////////////////////////////////////////////////////////
63
64static void
65parse_color (rxvt_screen *s, rxvt_color &c, SV *sv)
66{
67 //TODO: support component stuff
68 c.set (s, SvPVbyte_nolen (sv));
69}
56 70
57///////////////////////////////////////////////////////////////////////////// 71/////////////////////////////////////////////////////////////////////////////
58 72
59static wchar_t * 73static wchar_t *
60sv2wcs (SV *sv) 74sv2wcs (SV *sv)
75 89
76 return sv; 90 return sv;
77} 91}
78 92
79static SV * 93static SV *
80new_ref (HV *hv, const char *klass)
81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83}
84
85static SV *
86newSVptr (void *ptr, const char *klass) 94newSVptr (void *ptr, const char *klass)
87{ 95{
88 HV *hv = newHV (); 96 HV *hv = newHV ();
89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 97 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
90 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 98 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
119 127
120///////////////////////////////////////////////////////////////////////////// 128/////////////////////////////////////////////////////////////////////////////
121 129
122#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 130#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
123 131
124class overlay { 132class overlay : overlay_base
133{
125 rxvt_term *THIS; 134 rxvt_term *THIS;
126 AV *overlay_av; 135 AV *overlay_av;
127 int x, y, w, h;
128 int border; 136 int border;
129 text_t **text;
130 rend_t **rend;
131 137
132public: 138public:
133 HV *self; 139 HV *self;
134 140
135 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 141 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
142 148
143 void set (int x, int y, SV *str, SV *rend); 149 void set (int x, int y, SV *str, SV *rend);
144}; 150};
145 151
146overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 152overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
147: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) 153: THIS(THIS), border(border == 2), overlay_av (0)
148{ 154{
155 x = x_;
156 y = y_;
157 w = w_;
158 h = h_;
159
149 if (w < 0) w = 0; 160 if (w < 0) w = 0;
150 if (h < 0) h = 0; 161 if (h < 0) h = 0;
151 162
152 if (border == 2) 163 if (border == 2)
153 { 164 {
222 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 233 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
223 )); 234 ));
224 av_push (overlay_av, newSViv ((long)this)); 235 av_push (overlay_av, newSViv ((long)this));
225 236
226 THIS->want_refresh = 1; 237 THIS->want_refresh = 1;
238 THIS->refresh_check ();
227} 239}
228 240
229void 241void
230overlay::hide () 242overlay::hide ()
231{ 243{
245 257
246 SvREFCNT_dec (overlay_av); 258 SvREFCNT_dec (overlay_av);
247 overlay_av = 0; 259 overlay_av = 0;
248 260
249 THIS->want_refresh = 1; 261 THIS->want_refresh = 1;
262 THIS->refresh_check ();
250} 263}
251 264
252void overlay::swap () 265void overlay::swap ()
253{ 266{
254 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 267 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
255 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); 268 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
256 269
257 int ov_w = min (w, THIS->ncol - ov_x); 270 int ov_w = min (w, THIS->ncol - ov_x);
258 int ov_h = min (h, THIS->nrow - ov_y); 271 int ov_h = min (h, THIS->nrow - ov_y);
272
273 // hide cursor if it is within the overlay area
274 if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w)
275 && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h))
276 THIS->screen.flags &= ~Screen_VisibleCursor;
259 277
260 for (int y = ov_h; y--; ) 278 for (int y = ov_h; y--; )
261 { 279 {
262 text_t *t1 = text [y]; 280 text_t *t1 = text [y];
263 rend_t *r1 = rend [y]; 281 rend_t *r1 = rend [y];
299 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 317 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
300 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 318 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
301 } 319 }
302 320
303 THIS->want_refresh = 1; 321 THIS->want_refresh = 1;
322 THIS->refresh_check ();
304} 323}
305 324
306///////////////////////////////////////////////////////////////////////////// 325/////////////////////////////////////////////////////////////////////////////
307 326
308#define IOM_CLASS "urxvt"
309#include <iom_perl.h> 327#include "iom_perl.h"
310 328
311///////////////////////////////////////////////////////////////////////////// 329/////////////////////////////////////////////////////////////////////////////
312 330
313struct rxvt_perl_interp rxvt_perl; 331struct rxvt_perl_interp rxvt_perl;
314 332
318{ 336{
319 if (perl) 337 if (perl)
320 { 338 {
321 perl_destruct (perl); 339 perl_destruct (perl);
322 perl_free (perl); 340 perl_free (perl);
341 PERL_SYS_TERM ();
323 } 342 }
324} 343}
325 344
326void 345void
327rxvt_perl_interp::init (rxvt_term *term) 346rxvt_perl_interp::init (rxvt_term *term)
328{ 347{
329 if (!perl) 348 if (!perl)
330 { 349 {
331 rxvt_push_locale (""); // perl init destroys current locale 350 rxvt_push_locale (""); // perl init destroys current locale
332 351
352 {
333 perl_environ = rxvt_environ; 353 perl_environ = rxvt_environ;
334 swap (perl_environ, environ); 354 localise_env set_environ (perl_environ);
335 355
336 char *argv[] = { 356 char *args[] = {
337 "", 357 "",
338 "-e" 358 "-e"
339 "BEGIN {" 359 "BEGIN {"
340 " urxvt->bootstrap;" 360 " urxvt->bootstrap;"
341 " unshift @INC, '" LIBDIR "';" 361 " unshift @INC, '" LIBDIR "';"
342 "}" 362 "}"
343 "" 363 ""
344 "use urxvt;" 364 "use urxvt;"
345 }; 365 };
366 int argc = ecb_array_length (args);
367 char **argv = args;
346 368
369 PERL_SYS_INIT3 (&argc, &argv, &environ);
347 perl = perl_alloc (); 370 perl = perl_alloc ();
348 perl_construct (perl); 371 perl_construct (perl);
349 372
350 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 373 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
351 || perl_run (perl)) 374 || perl_run (perl))
352 { 375 {
353 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 376 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
354 377
355 perl_destruct (perl); 378 perl_destruct (perl);
356 perl_free (perl); 379 perl_free (perl);
357 perl = 0; 380 perl = 0;
358 } 381 }
359 382 }
360 swap (perl_environ, environ);
361 383
362 rxvt_pop_locale (); 384 rxvt_pop_locale ();
363 } 385 }
364 386
365 if (perl) 387 if (perl)
366 { 388 {
367 // runs outside of perls ENV 389 // runs outside of perls ENV
368 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 390 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
369 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); 391 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
392 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
370 } 393 }
394}
395
396void
397rxvt_perl_interp::usage (rxvt_term *term, int type)
398{
399 localise_env set_environ (perl_environ);
400
401 ENTER;
402 SAVETMPS;
403
404 dSP;
405 EXTEND (SP, 2);
406 PUSHs (sv_2mortal (newSVterm (term)));
407 PUSHs (sv_2mortal (newSViv (type)));
408 PUTBACK;
409 call_pv ("urxvt::usage", G_VOID | G_DISCARD | G_EVAL);
410
411 FREETMPS;
412 LEAVE;
413}
414
415uint8_t
416rxvt_perl_interp::resource (rxvt_term *term, const char *name, bool arg, bool longopt, bool flag, const char *value)
417{
418 localise_env set_environ (perl_environ);
419
420 ENTER;
421 SAVETMPS;
422
423 dSP;
424 EXTEND (SP, 6);
425 PUSHs (sv_2mortal (newSVterm (term)));
426 PUSHs (sv_2mortal (newSVpv (name, 0)));
427 PUSHs (arg ? &PL_sv_yes : &PL_sv_no);
428 PUSHs (longopt ? &PL_sv_yes : &PL_sv_no);
429 PUSHs (flag ? &PL_sv_yes : &PL_sv_no);
430 PUSHs (value ? sv_2mortal (newSVpv (value, 0)) : &PL_sv_undef);
431 PUTBACK;
432 call_pv ("urxvt::resource", G_SCALAR | G_EVAL);
433
434 uint8_t ret = POPi;
435
436 FREETMPS;
437 LEAVE;
438
439 return ret;
371} 440}
372 441
373static void 442static void
374ungrab (rxvt_term *THIS) 443ungrab (rxvt_term *THIS)
375{ 444{
385rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 454rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
386{ 455{
387 if (!perl || !term->perl.self) 456 if (!perl || !term->perl.self)
388 return false; 457 return false;
389 458
459 localise_env set_environ (perl_environ);
460
390 // pre-handling of some events 461 // pre-handling of some events
391 if (htype == HOOK_REFRESH_END) 462 if (htype == HOOK_REFRESH_END)
392 { 463 {
393 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 464 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
394 465
395 for (int i = 0; i <= AvFILL (av); i++) 466 for (int i = 0; i <= AvFILL (av); i++)
396 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 467 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
397 } 468 }
469 else if (htype == HOOK_DESTROY)
470 {
471 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
398 472
399 swap (perl_environ, environ); 473 for (int i = AvFILL (av); i >= 0; i--)
474 {
475 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
476 delete req;
477 }
478 }
400 479
401 bool event_consumed; 480 bool event_consumed;
402 481
403 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
404 || term->perl.should_invoke [htype]) 482 if (term->perl.should_invoke [htype])
405 try
406 { 483 {
407 dSP; 484 dSP;
408 va_list ap; 485 va_list ap;
409 486
410 va_start (ap, htype); 487 va_start (ap, htype);
411 488
412 ENTER; 489 ENTER;
413 SAVETMPS; 490 SAVETMPS;
414 491
415 PUSHMARK (SP); 492 PUSHMARK (SP);
416 493
494 EXTEND (SP, 2);
417 XPUSHs (sv_2mortal (newSVterm (term))); 495 PUSHs (sv_2mortal (newSVterm (term)));
418 XPUSHs (sv_2mortal (newSViv (htype))); 496 PUSHs (sv_2mortal (newSViv (htype)));
419 497
420 for (;;) { 498 for (;;) {
421 data_type dt = (data_type)va_arg (ap, int); 499 data_type dt = (data_type)va_arg (ap, int);
422 500
423 switch (dt) 501 switch (dt)
424 { 502 {
425 case DT_INT: 503 case DT_INT:
426 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
427 break; 505 break;
428 506
429 case DT_LONG: 507 case DT_LONG:
430 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
431 break; 509 break;
432 510
433 case DT_STR: 511 case DT_STR:
434 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 512 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
435 break; 513 break;
436 514
437 case DT_STR_LEN: 515 case DT_STR_LEN:
438 { 516 {
439 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
440 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
441 519
442 XPUSHs (sv_2mortal (newSVpvn (str, len))); 520 XPUSHs (sv_2mortal (newSVpvn (str, len)));
443 } 521 }
444 break; 522 break;
445 523
446 case DT_WCS_LEN: 524 case DT_WCS_LEN:
447 { 525 {
448 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
449 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
450 528
451 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 529 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
452 } 530 }
453 break; 531 break;
454 532
455 case DT_LCS_LEN: 533 case DT_LCS_LEN:
456 { 534 {
457 long *lstr = va_arg (ap, long *); 535 long *lstr = va_arg (ap, long *);
458 int llen = va_arg (ap, int); 536 int llen = va_arg (ap, int);
459 537
460 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); 538 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
461 } 539 }
462 break; 540 break;
463 541
464 case DT_XEVENT: 542 case DT_XEVENT:
465 { 543 {
466 XEvent *xe = va_arg (ap, XEvent *); 544 XEvent *xe = va_arg (ap, XEvent *);
467 HV *hv = newHV (); 545 HV *hv = newHV ();
468 546
469# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 547# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
470# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 548# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
471# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 549# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
472# undef set 550# undef set
473 551
474 setiv (type, xe->type); 552 setiv (type, xe->type);
475 setiv (send_event, xe->xany.send_event); 553 setiv (send_event, xe->xany.send_event);
476 setiv (serial, xe->xany.serial); 554 setiv (serial, xe->xany.serial);
477 555
478 switch (xe->type) 556 switch (xe->type)
479 { 557 {
480 case KeyPress: 558 case KeyPress:
481 case KeyRelease: 559 case KeyRelease:
482 case ButtonPress: 560 case ButtonPress:
483 case ButtonRelease: 561 case ButtonRelease:
484 case MotionNotify: 562 case MotionNotify:
485 setuv (window, xe->xmotion.window); 563 setuv (window, xe->xmotion.window);
486 setuv (root, xe->xmotion.root); 564 setuv (root, xe->xmotion.root);
487 setuv (subwindow, xe->xmotion.subwindow); 565 setuv (subwindow, xe->xmotion.subwindow);
488 setuv (time, xe->xmotion.time); 566 setuv (time, xe->xmotion.time);
489 setiv (x, xe->xmotion.x); 567 setiv (x, xe->xmotion.x);
490 setiv (y, xe->xmotion.y); 568 setiv (y, xe->xmotion.y);
491 setiv (row, xe->xmotion.y / term->fheight + term->view_start); 569 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
492 setiv (col, xe->xmotion.x / term->fwidth); 570 setiv (col, xe->xmotion.x / term->fwidth);
493 setiv (x_root, xe->xmotion.x_root); 571 setiv (x_root, xe->xmotion.x_root);
494 setiv (y_root, xe->xmotion.y_root); 572 setiv (y_root, xe->xmotion.y_root);
495 setuv (state, xe->xmotion.state); 573 setuv (state, xe->xmotion.state);
496 574
497 switch (xe->type) 575 switch (xe->type)
498 { 576 {
499 case KeyPress: 577 case KeyPress:
500 case KeyRelease: 578 case KeyRelease:
501 setuv (keycode, xe->xkey.keycode); 579 setuv (keycode, xe->xkey.keycode);
502 break; 580 break;
503 581
504 case ButtonPress: 582 case ButtonPress:
505 case ButtonRelease: 583 case ButtonRelease:
506 setuv (button, xe->xbutton.button); 584 setuv (button, xe->xbutton.button);
507 break; 585 break;
508 586
509 case MotionNotify: 587 case MotionNotify:
510 setiv (is_hint, xe->xmotion.is_hint); 588 setiv (is_hint, xe->xmotion.is_hint);
511 break; 589 break;
512 } 590 }
513 591
514 break; 592 break;
515 593
516 case MapNotify: 594 case MapNotify:
517 case UnmapNotify: 595 case UnmapNotify:
518 case ConfigureNotify: 596 case ConfigureNotify:
519 setuv (event, xe->xconfigure.event); 597 setuv (event, xe->xconfigure.event);
520 setuv (window, xe->xconfigure.window); 598 setuv (window, xe->xconfigure.window);
521 599
522 switch (xe->type) 600 switch (xe->type)
523 { 601 {
524 case ConfigureNotify: 602 case ConfigureNotify:
525 setiv (x, xe->xconfigure.x); 603 setiv (x, xe->xconfigure.x);
526 setiv (y, xe->xconfigure.y); 604 setiv (y, xe->xconfigure.y);
527 setiv (width, xe->xconfigure.width); 605 setiv (width, xe->xconfigure.width);
528 setiv (height, xe->xconfigure.height); 606 setiv (height, xe->xconfigure.height);
529 setuv (above, xe->xconfigure.above); 607 setuv (above, xe->xconfigure.above);
530 break; 608 break;
531 } 609 }
532 610
533 break; 611 break;
534 612
535 case PropertyNotify: 613 case PropertyNotify:
536 setuv (window, xe->xproperty.window); 614 setuv (window, xe->xproperty.window);
537 setuv (atom, xe->xproperty.atom); 615 setuv (atom, xe->xproperty.atom);
538 setuv (time, xe->xproperty.time); 616 setuv (time, xe->xproperty.time);
539 setiv (state, xe->xproperty.state); 617 setiv (state, xe->xproperty.state);
540 break; 618 break;
541 619
542 case ClientMessage: 620 case ClientMessage:
543 setuv (window, xe->xclient.window); 621 setuv (window, xe->xclient.window);
544 setuv (message_type, xe->xclient.message_type); 622 setuv (message_type, xe->xclient.message_type);
545 setuv (format, xe->xclient.format); 623 setuv (format, xe->xclient.format);
546 setuv (l0, xe->xclient.data.l[0]); 624 setuv (l0, xe->xclient.data.l[0]);
547 setuv (l1, xe->xclient.data.l[1]); 625 setuv (l1, xe->xclient.data.l[1]);
548 setuv (l2, xe->xclient.data.l[2]); 626 setuv (l2, xe->xclient.data.l[2]);
549 setuv (l3, xe->xclient.data.l[3]); 627 setuv (l3, xe->xclient.data.l[3]);
550 setuv (l4, xe->xclient.data.l[4]); 628 setuv (l4, xe->xclient.data.l[4]);
551 break; 629 break;
552 } 630 }
553 631
554 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 632 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
555 } 633 }
556 break; 634 break;
557 635
558 case DT_END: 636 case DT_END:
559 goto call; 637 goto call;
560 638
561 default: 639 default:
562 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 640 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
563 } 641 }
642 }
643
644 call:
645 va_end (ap);
646
647 PUTBACK;
648 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
649 SPAGAIN;
650
651 if (count)
652 {
653 SV *status = POPs;
654 count = SvTRUE (status);
564 } 655 }
565 656
566 call:
567 va_end (ap);
568
569 PUTBACK; 657 PUTBACK;
570 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
571 SPAGAIN;
572
573 if (count)
574 {
575 SV *status = POPs;
576 count = SvTRUE (status);
577 }
578
579 PUTBACK;
580 FREETMPS; 658 FREETMPS;
581 LEAVE; 659 LEAVE;
582 660
583 if (SvTRUE (ERRSV)) 661 if (SvTRUE (ERRSV))
584 { 662 {
585 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 663 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
586 ungrab (term); // better lose the grab than the session 664 ungrab (term); // better lose the grab than the session
587 } 665 }
588 666
589 event_consumed = !!count; 667 event_consumed = !!count;
590 } 668 }
591 catch (...)
592 {
593 swap (perl_environ, environ);
594 throw;
595 }
596 else 669 else
597 event_consumed = false; 670 event_consumed = false;
598 671
599 // post-handling of some events 672 // post-handling of some events
600 if (htype == HOOK_REFRESH_BEGIN) 673 if (htype == HOOK_REFRESH_BEGIN)
601 { 674 {
602 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 675 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
603 676
604 for (int i = AvFILL (av); i >= 0; i--) 677 for (int i = AvFILL (av); i >= 0; i--)
605 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 678 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
606 } 679 }
607 else if (htype == HOOK_DESTROY) 680 else if (htype == HOOK_DESTROY)
608 { 681 {
609 clearSVptr ((SV *)term->perl.self); 682 clearSVptr ((SV *)term->perl.self);
610 SvREFCNT_dec ((SV *)term->perl.self); 683 SvREFCNT_dec ((SV *)term->perl.self);
611 684
612 // don't allow further calls 685 // don't allow further calls
613 term->perl.self = 0; 686 term->perl.self = 0;
614 } 687 }
615 688
616 swap (perl_environ, environ);
617
618 return event_consumed; 689 return event_consumed;
690}
691
692void
693rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
694{
695 localise_env set_environ (perl_environ);
696
697 ENTER;
698 SAVETMPS;
699
700 dSP;
701 XPUSHs (sv_2mortal (newSVpvn (data, len)));
702 PUTBACK;
703 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
704
705 if (SvTRUE (ERRSV))
706 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
707
708 FREETMPS;
709 LEAVE;
619} 710}
620 711
621///////////////////////////////////////////////////////////////////////////// 712/////////////////////////////////////////////////////////////////////////////
622 713
623MODULE = urxvt PACKAGE = urxvt 714MODULE = urxvt PACKAGE = urxvt
635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 726# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
636# include "hookinc.h" 727# include "hookinc.h"
637# undef def 728# undef def
638 729
639 HV *option = get_hv ("urxvt::OPTION", 1); 730 HV *option = get_hv ("urxvt::OPTION", 1);
640# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); 731# define def(name) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
641# define nodef(name) 732# define nodef(name)
642# include "optinc.h" 733# include "optinc.h"
643# undef nodef 734# undef nodef
644# undef def 735# undef def
645 736
647 static const struct { 738 static const struct {
648 const char *name; 739 const char *name;
649 IV iv; 740 IV iv;
650 } *civ, const_iv[] = { 741 } *civ, const_iv[] = {
651# define const_iv(name) { # name, (IV)name } 742# define const_iv(name) { # name, (IV)name }
743 const_iv (NUM_RESOURCES),
652 const_iv (DEFAULT_RSTYLE), 744 const_iv (DEFAULT_RSTYLE),
653 const_iv (OVERLAY_RSTYLE), 745 const_iv (OVERLAY_RSTYLE),
746 const_iv (Color_Bits),
747 const_iv (RS_bgShift), const_iv (RS_bgMask),
748 const_iv (RS_fgShift), const_iv (RS_fgMask),
749 const_iv (RS_Careful),
750 const_iv (RS_fontCount),
751 const_iv (RS_fontShift),
752 const_iv (RS_fontMask),
753 const_iv (RS_baseattrMask),
754 const_iv (RS_attrMask),
755 const_iv (RS_redraw),
756 const_iv (RS_Sel),
654 const_iv (RS_Bold), 757 const_iv (RS_Bold),
655 const_iv (RS_Italic), 758 const_iv (RS_Italic),
656 const_iv (RS_Blink), 759 const_iv (RS_Blink),
657 const_iv (RS_RVid), 760 const_iv (RS_RVid),
658 const_iv (RS_Uline), 761 const_iv (RS_Uline),
674 const_iv (AnyModifier), 777 const_iv (AnyModifier),
675 778
676 const_iv (NoSymbol), 779 const_iv (NoSymbol),
677 const_iv (GrabModeSync), 780 const_iv (GrabModeSync),
678 const_iv (GrabModeAsync), 781 const_iv (GrabModeAsync),
679
680 const_iv (EVENT_NONE),
681 const_iv (EVENT_READ),
682 const_iv (EVENT_WRITE),
683 782
684 const_iv (NoEventMask), 783 const_iv (NoEventMask),
685 const_iv (KeyPressMask), 784 const_iv (KeyPressMask),
686 const_iv (KeyReleaseMask), 785 const_iv (KeyReleaseMask),
687 const_iv (ButtonPressMask), 786 const_iv (ButtonPressMask),
749 const_iv (XIMSecondary), 848 const_iv (XIMSecondary),
750 const_iv (XIMTertiary), 849 const_iv (XIMTertiary),
751 const_iv (XIMVisibleToForward), 850 const_iv (XIMVisibleToForward),
752 const_iv (XIMVisibleToBackword), 851 const_iv (XIMVisibleToBackword),
753 const_iv (XIMVisibleToCenter), 852 const_iv (XIMVisibleToCenter),
853#if XRENDER
854 const_iv (PictStandardARGB32),
855 const_iv (PictStandardRGB24),
856 const_iv (PictStandardA8),
857 const_iv (PictStandardA4),
858 const_iv (PictStandardA1),
859 const_iv (RepeatNone),
860 const_iv (RepeatNormal),
861 const_iv (RepeatPad),
862 const_iv (RepeatReflect),
863#endif
754# if 0 864# if 0
755 const_iv (XIMForwardChar), 865 const_iv (XIMForwardChar),
756 const_iv (XIMBackwardChar), 866 const_iv (XIMBackwardChar),
757 const_iv (XIMForwardWord), 867 const_iv (XIMForwardWord),
758 const_iv (XIMBackwardWord), 868 const_iv (XIMBackwardWord),
766 const_iv (XIMDontChange), 876 const_iv (XIMDontChange),
767# endif 877# endif
768# endif 878# endif
769 }; 879 };
770 880
771 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 881 for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--)
772 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 882 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
773} 883}
884
885void
886log (const char *msg)
887 CODE:
888 rxvt_log ("%s", msg);
774 889
775void 890void
776warn (const char *msg) 891warn (const char *msg)
777 CODE: 892 CODE:
778 rxvt_warn ("%s", msg); 893 rxvt_warn ("%s", msg);
782 CODE: 897 CODE:
783 rxvt_fatal ("%s", msg); 898 rxvt_fatal ("%s", msg);
784 899
785void 900void
786_exit (int status) 901_exit (int status)
902
903void
904catch_fatal (SV *block)
905 PROTOTYPE: &
906 CODE:
907 try
908 {
909 PUSHMARK (SP);
910 PUTBACK;
911 call_sv (block, G_VOID | G_DISCARD);
912 SPAGAIN;
913 }
914 catch (const rxvt_failure_exception &e)
915 {
916 croak ("rxvt_fatal exception caught, trying to continue.");
917 }
787 918
788NV 919NV
789NOW () 920NOW ()
790 CODE: 921 CODE:
791 RETVAL = NOW; 922 RETVAL = ev::now ();
792 OUTPUT: 923 OUTPUT:
793 RETVAL 924 RETVAL
794 925
795int 926int
796GET_BASEFG (int rend) 927GET_BASEFG (int rend)
849 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 980 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
850 if ((*t)->perl.self) 981 if ((*t)->perl.self)
851 PUSHs (sv_2mortal (newSVterm (*t))); 982 PUSHs (sv_2mortal (newSVterm (*t)));
852} 983}
853 984
985IV
986_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
987 CODE:
988 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
989 req->cb_sv = newSVsv (cb);
990 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
991 av_push (av, newSViv ((IV)req));
992 RETVAL = (IV)req;
993 OUTPUT:
994 RETVAL
995
996void
997_delete_selection_request (IV req_)
998 CODE:
999 rxvt_selection *req = (rxvt_selection *)req_;
1000 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
1001 int i;
1002
1003 for (i = AvFILL (av); i >= 0; i--)
1004 if (SvIV (*av_fetch (av, i, 1)) == req_)
1005 break;
1006
1007 for (; i < AvFILL (av); i++)
1008 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
1009
1010 av_pop (av);
1011
1012 delete req;
1013
854MODULE = urxvt PACKAGE = urxvt::term 1014MODULE = urxvt PACKAGE = urxvt::term
855 1015
856SV * 1016SV *
857_new (AV *env, AV *arg) 1017_new (AV *env, AV *arg)
858 CODE: 1018 CODE:
859{ 1019{
860 rxvt_term *term = new rxvt_term; 1020 rxvt_term *term = new rxvt_term;
861 1021
862 stringvec *argv = new stringvec; 1022 stringvec *argv = new stringvec;
863 stringvec *envv = new stringvec;
864
865 for (int i = 0; i <= AvFILL (arg); i++) 1023 for (int i = 0; i <= AvFILL (arg); i++)
866 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 1024 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
867 1025
1026 stringvec *envv = new stringvec;
868 for (int i = AvFILL (env) + 1; i--; ) 1027 for (int i = AvFILL (env) + 1; i--; )
869 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 1028 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
870 1029
871 envv->push_back (0);
872
873 bool success;
874
875 try 1030 try
876 { 1031 {
877 success = term->init (argv, envv); 1032 term->init (argv, envv);
878 } 1033 }
879 catch (const class rxvt_failure_exception &e) 1034 catch (const class rxvt_failure_exception &e)
880 {
881 success = false;
882 }
883
884 if (!success)
885 { 1035 {
886 term->destroy (); 1036 term->destroy ();
887 croak ("error while initializing new terminal instance"); 1037 croak ("error while initializing new terminal instance");
888 } 1038 }
889 1039
897rxvt_term::destroy () 1047rxvt_term::destroy ()
898 1048
899void 1049void
900rxvt_term::set_should_invoke (int htype, int inc) 1050rxvt_term::set_should_invoke (int htype, int inc)
901 CODE: 1051 CODE:
902 THIS->perl.should_invoke [htype] += inc; 1052 uint8_t &count = THIS->perl.should_invoke [htype];
1053 uint8_t prev = count;
1054 count += inc;
1055 if (!prev != !count)
1056 {
1057 // hook status changed, react
1058 switch (htype)
1059 {
1060 case HOOK_POSITION_CHANGE:
1061 if (count)
1062 THIS->get_window_origin (THIS->parent_x, THIS->parent_y);
1063 }
1064 }
903 1065
904int 1066int
905rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) 1067rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
906 CODE: 1068 CODE:
907 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1, 1069 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
923 1085
924void 1086void
925rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 1087rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
926 CODE: 1088 CODE:
927 XUngrabKey (THIS->dpy, keycode, modifiers, window); 1089 XUngrabKey (THIS->dpy, keycode, modifiers, window);
928
929void
930rxvt_term::XUngrabKeyboard (Time eventtime)
931 CODE:
932 XUngrabKeyboard (THIS->dpy, eventtime);
933 1090
934bool 1091bool
935rxvt_term::grab (Time eventtime, int sync = 0) 1092rxvt_term::grab (Time eventtime, int sync = 0)
936 CODE: 1093 CODE:
937{ 1094{
1052 free (wstr); 1209 free (wstr);
1053} 1210}
1054 OUTPUT: 1211 OUTPUT:
1055 RETVAL 1212 RETVAL
1056 1213
1057char *
1058rxvt_term::locale ()
1059 CODE:
1060 RETVAL = THIS->locale;
1061 OUTPUT:
1062 RETVAL
1063
1064#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1214#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1065 1215
1066#define TERM_OFFSET_width TERM_OFFSET(width) 1216#define TERM_OFFSET_width TERM_OFFSET(width)
1067#define TERM_OFFSET_height TERM_OFFSET(height) 1217#define TERM_OFFSET_height TERM_OFFSET(height)
1068#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 1218#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1069#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 1219#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1070#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1220#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1071#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1221#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1072#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1222#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1073#define TERM_OFFSET_focus TERM_OFFSET(focus) 1223#define TERM_OFFSET_focus TERM_OFFSET(focus)
1074#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1224#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1075#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) 1225#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1076#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) 1226#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1077#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) 1227#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1228#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
1078#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1229#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1079#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1230#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1080#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1231#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1081 1232
1082int 1233int
1083rxvt_term::width () 1234rxvt_term::width ()
1084 ALIAS: 1235 ALIAS:
1085 width = TERM_OFFSET_width 1236 width = TERM_OFFSET_width
1086 height = TERM_OFFSET_height 1237 height = TERM_OFFSET_height
1087 fwidth = TERM_OFFSET_fwidth 1238 fwidth = TERM_OFFSET_fwidth
1088 fheight = TERM_OFFSET_fheight 1239 fheight = TERM_OFFSET_fheight
1089 fbase = TERM_OFFSET_fbase 1240 fbase = TERM_OFFSET_fbase
1090 nrow = TERM_OFFSET_nrow 1241 nrow = TERM_OFFSET_nrow
1091 ncol = TERM_OFFSET_ncol 1242 ncol = TERM_OFFSET_ncol
1092 focus = TERM_OFFSET_focus 1243 focus = TERM_OFFSET_focus
1093 mapped = TERM_OFFSET_mapped 1244 mapped = TERM_OFFSET_mapped
1094 int_bwidth = TERM_OFFSET_int_bwidth 1245 int_bwidth = TERM_OFFSET_int_bwidth
1095 ext_bwidth = TERM_OFFSET_ext_bwidth 1246 ext_bwidth = TERM_OFFSET_ext_bwidth
1096 lineSpace = TERM_OFFSET_lineSpace 1247 lineSpace = TERM_OFFSET_lineSpace
1248 letterSpace = TERM_OFFSET_letterSpace
1097 saveLines = TERM_OFFSET_saveLines 1249 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1250 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1251 top_row = TERM_OFFSET_top_row
1100 CODE: 1252 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1253 RETVAL = *(int *)((char *)THIS + ix);
1102 OUTPUT: 1254 OUTPUT:
1103 RETVAL 1255 RETVAL
1104 1256
1115 { 1267 {
1116 case 0: RETVAL = THIS->ModLevel3Mask; break; 1268 case 0: RETVAL = THIS->ModLevel3Mask; break;
1117 case 1: RETVAL = THIS->ModMetaMask; break; 1269 case 1: RETVAL = THIS->ModMetaMask; break;
1118 case 2: RETVAL = THIS->ModNumLockMask; break; 1270 case 2: RETVAL = THIS->ModNumLockMask; break;
1119 case 3: RETVAL = THIS->current_screen; break; 1271 case 3: RETVAL = THIS->current_screen; break;
1272#ifdef CURSOR_BLINK
1120 case 4: RETVAL = THIS->hidden_cursor; break; 1273 case 4: RETVAL = THIS->hidden_cursor; break;
1274#endif
1121 } 1275 }
1122 OUTPUT: 1276 OUTPUT:
1123 RETVAL 1277 RETVAL
1124 1278
1125char * 1279char *
1150 if (*i) 1304 if (*i)
1151 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1305 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1152} 1306}
1153 1307
1154int 1308int
1155rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1309rxvt_term::pty_ev_events (int events = ev::UNDEF)
1156 CODE: 1310 CODE:
1157 RETVAL = THIS->pty_ev.events; 1311 RETVAL = THIS->pty_ev.events;
1158 if (events != EVENT_UNDEF) 1312 if (events != ev::UNDEF)
1159 THIS->pty_ev.set (events); 1313 THIS->pty_ev.set (events);
1160 OUTPUT: 1314 OUTPUT:
1161 RETVAL 1315 RETVAL
1162 1316
1163int 1317int
1168 RETVAL 1322 RETVAL
1169 1323
1170Window 1324Window
1171rxvt_term::parent () 1325rxvt_term::parent ()
1172 CODE: 1326 CODE:
1173 RETVAL = THIS->parent [0]; 1327 RETVAL = THIS->parent;
1174 OUTPUT: 1328 OUTPUT:
1175 RETVAL 1329 RETVAL
1176 1330
1177Window 1331int
1178rxvt_term::vt () 1332rxvt_term::parent_x ()
1179 CODE: 1333 CODE:
1180 RETVAL = THIS->vt; 1334 RETVAL = THIS->parent_x;
1335 OUTPUT:
1336 RETVAL
1337
1338int
1339rxvt_term::parent_y ()
1340 CODE:
1341 RETVAL = THIS->parent_y;
1181 OUTPUT: 1342 OUTPUT:
1182 RETVAL 1343 RETVAL
1183 1344
1184void 1345void
1185rxvt_term::vt_emask_add (U32 emask) 1346rxvt_term::vt_emask_add (U32 emask)
1205 if (newval <= 0) 1366 if (newval <= 0)
1206 THIS->scr_changeview (max (newval, THIS->top_row)); 1367 THIS->scr_changeview (max (newval, THIS->top_row));
1207} 1368}
1208 OUTPUT: 1369 OUTPUT:
1209 RETVAL 1370 RETVAL
1371
1372void
1373rxvt_term::set_urgency (bool enable)
1210 1374
1211void 1375void
1212rxvt_term::focus_in () 1376rxvt_term::focus_in ()
1213 1377
1214void 1378void
1242 1406
1243void 1407void
1244rxvt_term::want_refresh () 1408rxvt_term::want_refresh ()
1245 CODE: 1409 CODE:
1246 THIS->want_refresh = 1; 1410 THIS->want_refresh = 1;
1411 THIS->refresh_check ();
1247 1412
1248void 1413void
1249rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1414rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1250 PPCODE: 1415 PPCODE:
1251{ 1416{
1406SV * 1571SV *
1407rxvt_term::special_decode (SV *text) 1572rxvt_term::special_decode (SV *text)
1408 CODE: 1573 CODE:
1409{ 1574{
1410 wchar_t *wstr = sv2wcs (text); 1575 wchar_t *wstr = sv2wcs (text);
1411 int wlen = wcslen (wstr);
1412 int dlen = 0; 1576 int dlen = 0;
1413 1577
1414 // find length 1578 // find length
1415 for (wchar_t *s = wstr; *s; s++) 1579 for (wchar_t *s = wstr; *s; s++)
1416 if (*s == NOCHAR) 1580 if (*s == NOCHAR)
1447# include "rsinc.h" 1611# include "rsinc.h"
1448# undef def 1612# undef def
1449# undef reserve 1613# undef reserve
1450 }; 1614 };
1451 1615
1452 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1616 rs = rslist + ecb_array_length (rslist);
1453 1617
1618 if (*name)
1454 do { 1619 {
1620 do {
1455 if (rs-- == rslist) 1621 if (rs-- == rslist)
1456 croak ("no such resource '%s', requested", name); 1622 croak ("no such resource '%s', requested", name);
1457 } while (strcmp (name, rs->name)); 1623 } while (strcmp (name, rs->name));
1458 1624
1459 index += rs->value; 1625 index += rs->value;
1626 }
1627 else
1628 {
1629 --rs;
1630 name = "";
1631 }
1460 1632
1461 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1633 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1462 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1634 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1463 1635
1464 if (GIMME_V != G_VOID) 1636 if (GIMME_V != G_VOID)
1479 1651
1480const char * 1652const char *
1481rxvt_term::x_resource (const char *name) 1653rxvt_term::x_resource (const char *name)
1482 1654
1483bool 1655bool
1484rxvt_term::option (U32 optval, int set = -1) 1656rxvt_term::option (U8 optval, int set = -1)
1485 CODE: 1657 CODE:
1486{ 1658{
1487 RETVAL = THIS->options & optval; 1659 RETVAL = THIS->option (optval);
1488 1660
1489 if (set >= 0) 1661 if (set >= 0)
1490 { 1662 {
1491 if (set)
1492 THIS->options |= optval; 1663 THIS->set_option (optval, set);
1493 else
1494 THIS->options &= ~optval;
1495 1664
1496 if (THIS->check_ev.is_active ()) // avoid doing this before START 1665 if (THIS->init_done) // avoid doing this before START
1497 switch (optval) 1666 switch (optval)
1498 { 1667 {
1499 case Opt_skipBuiltinGlyphs: 1668 case Opt_skipBuiltinGlyphs:
1500 THIS->set_fonts (); 1669 THIS->set_fonts ();
1501 THIS->scr_remap_chars (); 1670 THIS->scr_remap_chars ();
1502 THIS->scr_touch (true); 1671 THIS->scr_touch (true);
1503 THIS->want_refresh = 1; 1672 THIS->want_refresh = 1;
1673 THIS->refresh_check ();
1504 break; 1674 break;
1675#ifdef CURSOR_BLINK
1676 case Opt_cursorBlink:
1677 THIS->cursor_blink_reset ();
1678 break;
1679#endif
1505 1680
1506 case Opt_cursorUnderline: 1681 case Opt_cursorUnderline:
1507 THIS->want_refresh = 1; 1682 THIS->want_refresh = 1;
1683 THIS->refresh_check ();
1508 break; 1684 break;
1509 1685
1510# case Opt_scrollBar_floating: 1686# case Opt_scrollBar_floating:
1511# case Opt_scrollBar_right: 1687# case Opt_scrollBar_right:
1512# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1688# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1522 CODE: 1698 CODE:
1523 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1699 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1524 THIS->keyboard->register_done (); 1700 THIS->keyboard->register_done ();
1525 OUTPUT: 1701 OUTPUT:
1526 RETVAL 1702 RETVAL
1703
1704void
1705rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1706 CODE:
1707 wchar_t *wstr = sv2wcs (str);
1708 THIS->keyboard->register_user_translation (keysym, state, wstr);
1709 free (wstr);
1527 1710
1528void 1711void
1529rxvt_term::screen_cur (...) 1712rxvt_term::screen_cur (...)
1530 PROTOTYPE: $;$$ 1713 PROTOTYPE: $;$$
1531 ALIAS: 1714 ALIAS:
1545 EXTEND (SP, 2); 1728 EXTEND (SP, 2);
1546 PUSHs (sv_2mortal (newSViv (rc.row))); 1729 PUSHs (sv_2mortal (newSViv (rc.row)));
1547 PUSHs (sv_2mortal (newSViv (rc.col))); 1730 PUSHs (sv_2mortal (newSViv (rc.col)));
1548 } 1731 }
1549 1732
1550 if (items == 3) 1733 if (items >= 3)
1551 { 1734 {
1552 rc.row = SvIV (ST (1)); 1735 rc.row = SvIV (ST (1));
1553 rc.col = SvIV (ST (2)); 1736 rc.col = SvIV (ST (2));
1554 1737
1555 if (ix == 2) 1738 if (ix == 2)
1570 1753
1571 clamp_it (rc.col, 0, THIS->ncol); 1754 clamp_it (rc.col, 0, THIS->ncol);
1572 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1755 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1573 1756
1574 if (ix) 1757 if (ix)
1758 {
1759 THIS->selection.screen = THIS->current_screen;
1760
1575 THIS->want_refresh = 1; 1761 THIS->want_refresh = 1;
1762 THIS->refresh_check ();
1576 } 1763 }
1764 }
1577} 1765}
1578 1766
1579char 1767int
1580rxvt_term::cur_charset () 1768rxvt_term::selection_screen (int screen = -1)
1581 CODE: 1769 CODE:
1582 RETVAL = THIS->charsets [THIS->screen.charset]; 1770 RETVAL = THIS->selection.screen;
1583 OUTPUT: 1771 if (screen >= 0)
1772 THIS->selection.screen = screen;
1773 OUTPUT:
1584 RETVAL 1774 RETVAL
1585 1775
1586void 1776void
1587rxvt_term::selection_clear () 1777rxvt_term::selection_clear (bool clipboard = false)
1588 1778
1589void 1779void
1590rxvt_term::selection_make (Time eventtime, bool rect = false) 1780rxvt_term::selection_make (Time eventtime, bool rect = false)
1591 CODE: 1781 CODE:
1592 THIS->selection.op = SELECTION_CONT; 1782 THIS->selection.op = SELECTION_CONT;
1593 THIS->selection.rect = rect; 1783 THIS->selection.rect = rect;
1594 THIS->selection_make (eventtime); 1784 THIS->selection_make (eventtime);
1595 1785
1596int 1786int
1597rxvt_term::selection_grab (Time eventtime) 1787rxvt_term::selection_grab (Time eventtime, bool clipboard = false)
1598 1788
1599void 1789void
1600rxvt_term::selection (SV *newtext = 0) 1790rxvt_term::selection (SV *newtext = 0, bool clipboard = false)
1601 PPCODE: 1791 PPCODE:
1602{ 1792{
1793 wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text;
1794 unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len;
1795
1603 if (GIMME_V != G_VOID) 1796 if (GIMME_V != G_VOID)
1604 XPUSHs (THIS->selection.text 1797 XPUSHs (text
1605 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) 1798 ? sv_2mortal (wcs2sv (text, len))
1606 : &PL_sv_undef); 1799 : &PL_sv_undef);
1607 1800
1608 if (newtext) 1801 if (newtext)
1609 { 1802 {
1610 free (THIS->selection.text); 1803 free (text);
1611 1804
1612 THIS->selection.text = sv2wcs (newtext); 1805 text = sv2wcs (newtext);
1613 THIS->selection.len = wcslen (THIS->selection.text); 1806 len = wcslen (text);
1614 } 1807 }
1615} 1808}
1809
1810char
1811rxvt_term::cur_charset ()
1812 CODE:
1813 RETVAL = THIS->charsets [THIS->screen.charset];
1814 OUTPUT:
1815 RETVAL
1616 1816
1617void 1817void
1618rxvt_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) 1818rxvt_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)
1619 1819
1620void 1820void
1621rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1821rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1622 1822
1623void 1823void
1624rxvt_term::scr_bell () 1824rxvt_term::scr_bell ()
1825
1826void
1827rxvt_term::scr_recolour (bool refresh = true);
1625 1828
1626void 1829void
1627rxvt_term::scr_change_screen (int screen) 1830rxvt_term::scr_change_screen (int screen)
1628 1831
1629void 1832void
1642 char *str = SvPVbyte (octets, len); 1845 char *str = SvPVbyte (octets, len);
1643 C_ARGS: 1846 C_ARGS:
1644 str, len 1847 str, len
1645 1848
1646void 1849void
1850rxvt_term::tt_paste (SV *octets)
1851 INIT:
1852 STRLEN len;
1853 char *str = SvPVbyte (octets, len);
1854 C_ARGS:
1855 str, len
1856
1857void
1647rxvt_term::cmd_parse (SV *octets) 1858rxvt_term::cmd_parse (SV *octets)
1648 CODE: 1859 CODE:
1649{ 1860{
1650 STRLEN len; 1861 STRLEN len;
1651 char *str = SvPVbyte (octets, len); 1862 char *str = SvPVbyte (octets, len);
1687 Atom *props = XListProperties (THIS->dpy, window, &count); 1898 Atom *props = XListProperties (THIS->dpy, window, &count);
1688 1899
1689 EXTEND (SP, count); 1900 EXTEND (SP, count);
1690 while (count--) 1901 while (count--)
1691 PUSHs (newSVuv ((U32)props [count])); 1902 PUSHs (newSVuv ((U32)props [count]));
1692 1903
1693 XFree (props); 1904 XFree (props);
1694} 1905}
1695 1906
1696void 1907void
1697rxvt_term::XGetWindowProperty (Window window, Atom property) 1908rxvt_term::XGetWindowProperty (Window window, Atom property)
1720 XFree (prop); 1931 XFree (prop);
1721 } 1932 }
1722} 1933}
1723 1934
1724void 1935void
1725rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1936rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1726 CODE: 1937 CODE:
1727{ 1938{
1728 STRLEN len; 1939 STRLEN len;
1729 char *data_ = SvPVbyte (data, len); 1940 char *data_ = SvPVbyte (data, len);
1730 1941
1736 type, format, PropModeReplace, 1947 type, format, PropModeReplace,
1737 (unsigned char *)data_, len / elemsize); 1948 (unsigned char *)data_, len / elemsize);
1738} 1949}
1739 1950
1740Atom 1951Atom
1741XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1952XInternAtom (rxvt_term *term, octet_string atom_name, int only_if_exists = FALSE)
1742 C_ARGS: term->dpy, atom_name, only_if_exists 1953 C_ARGS: term->dpy, atom_name, only_if_exists
1743 1954
1744char * 1955char *
1745XGetAtomName (rxvt_term *term, Atom atom) 1956XGetAtomName (rxvt_term *term, Atom atom)
1746 C_ARGS: term->dpy, atom 1957 C_ARGS: term->dpy, atom
1747 CLEANUP: 1958 CLEANUP:
1748 XFree (RETVAL); 1959 XFree (RETVAL);
1749 1960
1750void 1961void
1751XDeleteProperty (rxvt_term *term, Window window, Atom property) 1962XDeleteProperty (rxvt_term *term, Window window, Atom property)
1752 C_ARGS: term->dpy, window, property 1963 C_ARGS: term->dpy, window, property
1753 1964
1754Window 1965Window
1755rxvt_term::DefaultRootWindow () 1966rxvt_term::DefaultRootWindow ()
1756 CODE: 1967 CODE:
1757 RETVAL = THIS->display->root; 1968 RETVAL = THIS->display->root;
1809 PUSHs (newSVuv (child)); 2020 PUSHs (newSVuv (child));
1810 } 2021 }
1811} 2022}
1812 2023
1813############################################################################# 2024#############################################################################
2025# fancy bg bloatstuff (TODO: should be moved up somewhere)
2026
2027# TODO: ugly
2028void
2029rxvt_term::get_geometry ()
2030 PPCODE:
2031 EXTEND (SP, 4);
2032 PUSHs (sv_2mortal (newSViv (THIS->parent_x)));
2033 PUSHs (sv_2mortal (newSViv (THIS->parent_y)));
2034 PUSHs (sv_2mortal (newSViv (THIS->szHint.width)));
2035 PUSHs (sv_2mortal (newSViv (THIS->szHint.height)));
2036
2037#if HAVE_IMG
2038
2039rxvt_img *
2040rxvt_term::new_img (SV *format, int width, int height)
2041 CODE:
2042 XRenderPictFormat *f = SvOK (format)
2043 ? XRenderFindStandardFormat (THIS->dpy, SvIV (format))
2044 : XRenderFindVisualFormat (THIS->dpy, THIS->visual);
2045 RETVAL = new rxvt_img (THIS, f, width, height);
2046 OUTPUT:
2047 RETVAL
2048
2049#if ENABLE_TRANSPARENCY
2050
2051rxvt_img *
2052rxvt_term::new_img_from_root ()
2053 CODE:
2054 RETVAL = rxvt_img::new_from_root (THIS);
2055 OUTPUT:
2056 RETVAL
2057
2058#endif
2059
2060#if HAVE_PIXBUF
2061
2062rxvt_img *
2063rxvt_term::new_img_from_file (octet_string filename)
2064 CODE:
2065 try
2066 {
2067 RETVAL = rxvt_img::new_from_file (THIS, filename);
2068 }
2069 catch (const class rxvt_failure_exception &e)
2070 {
2071 croak ("new_img_from_file failed");
2072 }
2073 OUTPUT:
2074 RETVAL
2075
2076#endif
2077
2078#if HAVE_BG_PIXMAP
2079
2080void
2081rxvt_term::set_background (rxvt_img *img)
2082 CODE:
2083 THIS->bg_destroy ();
2084 THIS->bg_pixmap = None;
2085 THIS->bg_flags &= ~rxvt_term::BG_NEEDS_REFRESH;
2086
2087 if (img) // TODO: cannot be false
2088 {
2089 img->unshare ();
2090 //TODO: convetr to visual, possibly precompose with colour
2091 THIS->bg_pixmap = img->steal ();
2092 THIS->bg_flags |= rxvt_term::BG_NEEDS_REFRESH;
2093 THIS->bg_valid_since = ev::now (); // TODO: extra bloat
2094 }
2095
2096#endif
2097
2098#endif
2099
2100#############################################################################
1814# urxvt::overlay 2101# urxvt::overlay
1815############################################################################# 2102#############################################################################
1816 2103
1817MODULE = urxvt PACKAGE = urxvt::overlay 2104MODULE = urxvt PACKAGE = urxvt::overlay
1818 2105
1828void 2115void
1829overlay::DESTROY () 2116overlay::DESTROY ()
1830 2117
1831INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g | 2118INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1832 2119
2120MODULE = urxvt PACKAGE = urxvt::pixbuf PREFIX = gdk_pixbuf_
2121
2122#if HAVE_PIXBUF
2123
2124urxvt::pixbuf gdk_pixbuf_new_from_file (SV *klass, octet_string filename)
2125 C_ARGS: filename, 0
2126
2127void
2128DESTROY (urxvt::pixbuf self)
2129 CODE:
2130 gdk_pixbuf_unref (self);
2131
2132#endif
2133
2134MODULE = urxvt PACKAGE = urxvt::img
2135
2136#if HAVE_IMG
2137
2138# rxvt_img *new (rxvt_screen *screen, XRenderPictFormat *format, int width, int height)
2139# rxvt_img *rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap);
2140
2141int
2142rxvt_img::w ()
2143 CODE:
2144 RETVAL = THIS->w;
2145 OUTPUT:
2146 RETVAL
2147
2148int
2149rxvt_img::h ()
2150 CODE:
2151 RETVAL = THIS->h;
2152 OUTPUT:
2153 RETVAL
2154
2155bool
2156rxvt_img::shared ()
2157 CODE:
2158 RETVAL = THIS->shared;
2159 OUTPUT:
2160 RETVAL
2161
2162Pixmap
2163rxvt_img::pm ()
2164 CODE:
2165 RETVAL = THIS->pm;
2166 OUTPUT:
2167 RETVAL
2168
2169void
2170rxvt_img::fill (SV *c)
2171 INIT:
2172 rxvt_color rc;
2173 parse_color (THIS->s, rc, c);
2174 C_ARGS: rc
2175
2176void
2177rxvt_img::DESTROY ()
2178 CODE:
2179 delete THIS;
2180
2181rxvt_img *
2182rxvt_img::blur (int rh, int rv)
2183
2184void
2185rxvt_img::brightness (NV r, NV g, NV b, NV a = 1.)
2186
2187void
2188rxvt_img::contrast (NV r, NV g, NV b, NV a = 1.)
2189
2190void
2191rxvt_img::unshare ()
2192
2193rxvt_img *
2194rxvt_img::clone ()
2195
2196rxvt_img *
2197rxvt_img::sub_rect (int x, int y, int width, int height, render_repeat_mode repeat = RepeatNormal)
2198
2199rxvt_img *
2200rxvt_img::transform (int new_width, int new_height, NV p11, NV p12, NV p13, NV p21, NV p22, NV p23, NV p31, NV p32, NV p33, render_repeat_mode repeat = RepeatNormal)
2201 INIT:
2202 double matrix[9] = {
2203 p11, p12, p13,
2204 p21, p22, p23,
2205 p31, p32, p33
2206 };
2207 C_ARGS: new_width, new_height, matrix, repeat
2208
2209rxvt_img *
2210rxvt_img::scale (int new_width, int new_height)
2211
2212rxvt_img *
2213rxvt_img::rotate (int new_width, int new_height, int x, int y, NV phi, render_repeat_mode repeat = RepeatNormal)
2214
2215#endif
2216

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines