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.5 by root, Mon Jan 2 20:35:39 2006 UTC vs.
Revision 1.78 by root, Thu Jan 19 20:30:36 2006 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-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
49
50#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)]
54
55#define ENABLE_PERL_FRILLS 1
39 56
40///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
41 58
42static wchar_t * 59static wchar_t *
43sv2wcs (SV *sv) 60sv2wcs (SV *sv)
46 char *str = SvPVutf8 (sv, len); 63 char *str = SvPVutf8 (sv, len);
47 return rxvt_utf8towcs (str, len); 64 return rxvt_utf8towcs (str, len);
48} 65}
49 66
50static SV * 67static SV *
68wcs2sv (wchar_t *wstr, int len = -1)
69{
70 char *str = rxvt_wcstoutf8 (wstr, len);
71
72 SV *sv = newSVpv (str, 0);
73 SvUTF8_on (sv);
74 free (str);
75
76 return sv;
77}
78
79static SV *
51new_ref (HV *hv, const char *klass) 80new_ref (HV *hv, const char *klass)
52{ 81{
53 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
54} 83}
55 84
56//TODO: use magic 85//TODO: use magic
57static SV * 86static SV *
58newSVptr (void *ptr, const char *klass) 87newSVptr (void *ptr, const char *klass)
59{ 88{
60 HV *hv = newHV (); 89 HV *hv = newHV ();
61 hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); 90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
62 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 91 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
92}
93
94static void
95clearSVptr (SV *sv)
96{
97 if (SvROK (sv))
98 sv = SvRV (sv);
99
100 hv_clear ((HV *)sv);
101 sv_unmagic (sv, PERL_MAGIC_ext);
63} 102}
64 103
65static long 104static long
66SvPTR (SV *sv, const char *klass) 105SvPTR (SV *sv, const char *klass)
67{ 106{
68 if (!sv_derived_from (sv, klass)) 107 if (!sv_derived_from (sv, klass))
69 croak ("object of type %s expected", klass); 108 croak ("object of type %s expected", klass);
70 109
71 IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); 110 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
72 111
73 if (!iv) 112 if (!mg)
74 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);
75 114
76 return (long)iv; 115 return (long)mg->mg_ptr;
77} 116}
78 117
79#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
80#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
81 120
82///////////////////////////////////////////////////////////////////////////// 121/////////////////////////////////////////////////////////////////////////////
83 122
84struct perl_watcher 123struct perl_watcher
134#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 173#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
135#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 174#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
136 175
137struct timer : time_watcher, perl_watcher 176struct timer : time_watcher, perl_watcher
138{ 177{
178 tstamp interval;
179
139 timer () 180 timer ()
140 : time_watcher (this, &timer::execute) 181 : time_watcher (this, &timer::execute)
141 { 182 {
142 } 183 }
143 184
144 void execute (time_watcher &w) 185 void execute (time_watcher &w)
145 { 186 {
187 if (interval)
188 start (at + interval);
189
146 invoke ("urxvt::timer", newSVtimer (this)); 190 invoke ("urxvt::timer", newSVtimer (this));
147 } 191 }
148}; 192};
149 193
150#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 194#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
163 } 207 }
164}; 208};
165 209
166///////////////////////////////////////////////////////////////////////////// 210/////////////////////////////////////////////////////////////////////////////
167 211
212#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
213
214struct overlay {
215 HV *self;
216 bool visible;
217 rxvt_term *THIS;
218 int x, y, w, h;
219 int border;
220 text_t **text;
221 rend_t **rend;
222
223 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
224 ~overlay ();
225
226 void show ();
227 void hide ();
228
229 void swap ();
230
231 void set (int x, int y, SV *str, SV *rend);
232};
233
234overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
235: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false)
236{
237 if (border == 2)
238 {
239 w += 2;
240 h += 2;
241 }
242
243 text = new text_t *[h];
244 rend = new rend_t *[h];
245
246 for (int y = 0; y < h; y++)
247 {
248 text_t *tp = text[y] = new text_t[w];
249 rend_t *rp = rend[y] = new rend_t[w];
250
251 text_t t0, t1, t2;
252 rend_t r = rstyle;
253
254 if (border == 2)
255 {
256 if (y == 0)
257 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
258 else if (y < h - 1)
259 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
260 else
261 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
262
263 *tp++ = t0;
264 *rp++ = r;
265
266 for (int x = w - 2; x-- > 0; )
267 {
268 *tp++ = t1;
269 *rp++ = r;
270 }
271
272 *tp = t2;
273 *rp = r;
274 }
275 else
276 for (int x = w; x-- > 0; )
277 {
278 *tp++ = 0x0020;
279 *rp++ = r;
280 }
281 }
282
283 show ();
284 THIS->want_refresh = 1;
285}
286
287overlay::~overlay ()
288{
289 hide ();
290
291 for (int y = h; y--; )
292 {
293 delete [] text[y];
294 delete [] rend[y];
295 }
296
297 delete [] text;
298 delete [] rend;
299
300 THIS->want_refresh = 1;
301}
302
303void
304overlay::show ()
305{
306 if (visible)
307 return;
308
309 visible = true;
310
311 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
312 av_push (av, newSViv ((long)this));
313}
314
315void
316overlay::hide ()
317{
318 if (!visible)
319 return;
320
321 visible = false;
322
323 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
324
325 int i;
326
327 for (i = AvFILL (av); i >= 0; i--)
328 if (SvIV (*av_fetch (av, i, 1)) == (long)this)
329 {
330 av_delete (av, i, G_DISCARD);
331 break;
332 }
333
334 for (; i < AvFILL (av); i++)
335 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
336
337 av_pop (av);
338}
339
340void overlay::swap ()
341{
342 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
343 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
344
345 int ov_w = min (w, THIS->ncol - ov_x);
346 int ov_h = min (h, THIS->nrow - ov_y);
347
348 for (int y = ov_h; y--; )
349 {
350 text_t *t1 = text [y];
351 rend_t *r1 = rend [y];
352
353 text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
354 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
355
356 for (int x = ov_w; x--; )
357 {
358 text_t t = *t1; *t1++ = *t2; *t2++ = t;
359 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
360 }
361 }
362
363}
364
365void overlay::set (int x, int y, SV *text, SV *rend)
366{
367 x += border;
368 y += border;
369
370 if (!IN_RANGE_EXC (y, 0, h - border))
371 return;
372
373 wchar_t *wtext = sv2wcs (text);
374
375 for (int col = min (wcslen (wtext), w - x - border); col--; )
376 this->text [y][x + col] = wtext [col];
377
378 free (wtext);
379
380 if (rend)
381 {
382 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
383 croak ("rend must be arrayref");
384
385 AV *av = (AV *)SvRV (rend);
386
387 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
388 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
389 }
390
391 THIS->want_refresh = 1;
392}
393
394
395/////////////////////////////////////////////////////////////////////////////
396
168struct rxvt_perl_interp rxvt_perl; 397struct rxvt_perl_interp rxvt_perl;
169 398
170static PerlInterpreter *perl; 399static PerlInterpreter *perl;
171
172rxvt_perl_interp::rxvt_perl_interp ()
173{
174}
175 400
176rxvt_perl_interp::~rxvt_perl_interp () 401rxvt_perl_interp::~rxvt_perl_interp ()
177{ 402{
178 if (perl) 403 if (perl)
179 { 404 {
181 perl_free (perl); 406 perl_free (perl);
182 } 407 }
183} 408}
184 409
185void 410void
186rxvt_perl_interp::init () 411rxvt_perl_interp::init (rxvt_term *term)
187{ 412{
188 if (!perl) 413 if (!perl)
189 { 414 {
415 rxvt_push_locale (""); // perl init destroys current locale
416
417 perl_environ = rxvt_environ;
418 swap (perl_environ, environ);
419
190 char *argv[] = { 420 char *argv[] = {
191 "", 421 "",
192 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 422 "-e"
423 "BEGIN {"
424 " urxvt->bootstrap;"
425 " unshift @INC, '" LIBDIR "';"
426 "}"
427 ""
428 "use urxvt;"
193 }; 429 };
194 430
195 perl = perl_alloc (); 431 perl = perl_alloc ();
196 perl_construct (perl); 432 perl_construct (perl);
197 433
202 438
203 perl_destruct (perl); 439 perl_destruct (perl);
204 perl_free (perl); 440 perl_free (perl);
205 perl = 0; 441 perl = 0;
206 } 442 }
443
444 swap (perl_environ, environ);
445
446 rxvt_pop_locale ();
447 }
448
449 if (perl)
450 {
451 // runs outside of perls ENV
452 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
453 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
454 }
455}
456
457static void
458ungrab (rxvt_term *THIS)
459{
460 if (THIS->perl.grabtime)
461 {
462 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
463 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
464 THIS->perl.grabtime = 0;
207 } 465 }
208} 466}
209 467
210bool 468bool
211rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 469rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
212{ 470{
213 if (!perl 471 if (!perl || !term->perl.self)
214 || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY))
215 return false; 472 return false;
216
217 if (htype == HOOK_INIT) // first hook ever called
218 term->self = (void *)newSVptr ((void *)term, "urxvt::term");
219 473
220 dSP; 474 // pre-handling of some events
221 va_list ap; 475 if (htype == HOOK_REFRESH_END)
476 {
477 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
478
479 for (int i = 0; i <= AvFILL (av); i++)
480 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
481 }
222 482
223 va_start (ap, htype); 483 swap (perl_environ, environ);
224 484
225 ENTER; 485 bool event_consumed;
226 SAVETMPS;
227 486
228 PUSHMARK (SP); 487 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
229 488 || term->perl.should_invoke [htype])
230 XPUSHs (sv_2mortal (newSVterm (term))); 489 try
231 XPUSHs (sv_2mortal (newSViv (htype)));
232
233 for (;;) {
234 data_type dt = (data_type)va_arg (ap, int);
235
236 switch (dt)
237 { 490 {
491 dSP;
492 va_list ap;
493
494 va_start (ap, htype);
495
496 ENTER;
497 SAVETMPS;
498
499 PUSHMARK (SP);
500
501 XPUSHs (sv_2mortal (newSVterm (term)));
502 XPUSHs (sv_2mortal (newSViv (htype)));
503
504 for (;;) {
505 data_type dt = (data_type)va_arg (ap, int);
506
507 switch (dt)
508 {
238 case DT_INT: 509 case DT_INT:
239 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 510 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
240 break; 511 break;
241 512
242 case DT_LONG: 513 case DT_LONG:
243 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 514 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
515 break;
516
517 case DT_STR:
518 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
519 break;
520
521 case DT_STR_LEN:
522 {
523 char *str = va_arg (ap, char *);
524 int len = va_arg (ap, int);
525
526 XPUSHs (sv_2mortal (newSVpvn (str, len)));
527 }
528 break;
529
530 case DT_WCS_LEN:
531 {
532 wchar_t *wstr = va_arg (ap, wchar_t *);
533 int wlen = va_arg (ap, int);
534
535 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
536 }
244 break; 537 break;
245 538
539 case DT_XEVENT:
540 {
541 XEvent *xe = va_arg (ap, XEvent *);
542 HV *hv = newHV ();
543
544# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
545# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
546# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
547# undef set
548
549 setiv (type, xe->type);
550 setiv (send_event, xe->xany.send_event);
551 setiv (serial, xe->xany.serial);
552
553 switch (xe->type)
554 {
555 case KeyPress:
556 case KeyRelease:
557 case ButtonPress:
558 case ButtonRelease:
559 case MotionNotify:
560 setuv (window, xe->xmotion.window);
561 setuv (root, xe->xmotion.root);
562 setuv (subwindow, xe->xmotion.subwindow);
563 setuv (time, xe->xmotion.time);
564 setiv (x, xe->xmotion.x);
565 setiv (y, xe->xmotion.y);
566 setiv (row, xe->xmotion.y / term->fheight);
567 setiv (col, xe->xmotion.x / term->fwidth);
568 setiv (x_root, xe->xmotion.x_root);
569 setiv (y_root, xe->xmotion.y_root);
570 setuv (state, xe->xmotion.state);
571
572 switch (xe->type)
573 {
574 case KeyPress:
575 case KeyRelease:
576 setuv (keycode, xe->xkey.keycode);
577 break;
578
579 case ButtonPress:
580 case ButtonRelease:
581 setuv (button, xe->xbutton.button);
582 break;
583
584 case MotionNotify:
585 setiv (is_hint, xe->xmotion.is_hint);
586 break;
587 }
588
589 break;
590
591 case MapNotify:
592 case UnmapNotify:
593 case ConfigureNotify:
594 setuv (event, xe->xconfigure.event);
595 setuv (window, xe->xconfigure.window);
596
597 switch (xe->type)
598 {
599 case ConfigureNotify:
600 setiv (x, xe->xconfigure.x);
601 setiv (y, xe->xconfigure.y);
602 setiv (width, xe->xconfigure.width);
603 setiv (height, xe->xconfigure.height);
604 setuv (above, xe->xconfigure.above);
605 break;
606 }
607
608 break;
609 }
610
611 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
612 }
613 break;
614
246 case DT_END: 615 case DT_END:
616 goto call;
617
618 default:
619 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
620 }
621 }
622
623 call:
624 va_end (ap);
625
626 PUTBACK;
627 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
628 SPAGAIN;
629
630 if (count)
247 { 631 {
248 va_end (ap);
249
250 PUTBACK;
251 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
252 SPAGAIN;
253
254 if (count)
255 {
256 SV *status = POPs; 632 SV *status = POPs;
257 count = SvTRUE (status); 633 count = SvTRUE (status);
258 }
259
260 PUTBACK;
261 FREETMPS;
262 LEAVE;
263
264 if (SvTRUE (ERRSV))
265 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
266
267 if (htype == HOOK_DESTROY)
268 {
269 // TODO: clear magic
270 hv_clear ((HV *)SvRV ((SV *)term->self));
271 SvREFCNT_dec ((SV *)term->self);
272 }
273
274 return count;
275 } 634 }
276 635
277 default: 636 PUTBACK;
278 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 637 FREETMPS;
638 LEAVE;
639
640 if (SvTRUE (ERRSV))
641 {
642 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
643 ungrab (term); // better lose the grab than the session
644 }
645
646 event_consumed = !!count;
279 } 647 }
648 catch (...)
649 {
650 swap (perl_environ, environ);
651 throw;
652 }
653 else
654 event_consumed = false;
655
656 // post-handling of some events
657 if (htype == HOOK_REFRESH_BEGIN)
658 {
659 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
660
661 for (int i = AvFILL (av); i >= 0; i--)
662 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
280 } 663 }
664 else if (htype == HOOK_DESTROY)
665 {
666 clearSVptr ((SV *)term->perl.self);
667 SvREFCNT_dec ((SV *)term->perl.self);
668 }
669
670 swap (perl_environ, environ);
671
672 return event_consumed;
281} 673}
282 674
283///////////////////////////////////////////////////////////////////////////// 675/////////////////////////////////////////////////////////////////////////////
284 676
285MODULE = urxvt PACKAGE = urxvt 677MODULE = urxvt PACKAGE = urxvt
286 678
287PROTOTYPES: ENABLE 679PROTOTYPES: ENABLE
288 680
289BOOT: 681BOOT:
290{ 682{
291# define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) 683 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
684 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
685 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
686 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
687
292 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 688 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
293 set_hookname (INIT); 689# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
294 set_hookname (RESET); 690# include "hookinc.h"
295 set_hookname (START); 691# undef def
296 set_hookname (DESTROY);
297 set_hookname (SEL_BEGIN);
298 set_hookname (SEL_EXTEND);
299 set_hookname (SEL_MAKE);
300 set_hookname (SEL_GRAB);
301 set_hookname (FOCUS_IN);
302 set_hookname (FOCUS_OUT);
303 set_hookname (VIEW_CHANGE);
304 set_hookname (SCROLL_BACK);
305 set_hookname (TTY_ACTIVITY);
306 set_hookname (REFRESH_BEGIN);
307 set_hookname (REFRESH_END);
308 692
309 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 693 HV *option = get_hv ("urxvt::OPTION", 1);
310} 694# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
695# define nodef(name)
696# include "optinc.h"
697# undef nodef
698# undef def
311 699
312void 700 HV *stash = gv_stashpv ("urxvt", 1);
313set_should_invoke (int htype, int value) 701 struct {
314 CODE: 702 const char *name;
315 rxvt_perl.should_invoke [htype] = value; 703 IV iv;
704 } *civ, const_iv[] = {
705# define const_iv(name) { # name, (IV)name }
706 const_iv (DEFAULT_RSTYLE),
707 const_iv (OVERLAY_RSTYLE),
708 const_iv (RS_Bold),
709 const_iv (RS_Italic),
710 const_iv (RS_Blink),
711 const_iv (RS_RVid),
712 const_iv (RS_Uline),
713
714 const_iv (CurrentTime),
715 const_iv (ShiftMask),
716 const_iv (LockMask),
717 const_iv (ControlMask),
718 const_iv (Mod1Mask),
719 const_iv (Mod2Mask),
720 const_iv (Mod3Mask),
721 const_iv (Mod4Mask),
722 const_iv (Mod5Mask),
723 const_iv (Button1Mask),
724 const_iv (Button2Mask),
725 const_iv (Button3Mask),
726 const_iv (Button4Mask),
727 const_iv (Button5Mask),
728 const_iv (AnyModifier),
729
730 const_iv (EVENT_NONE),
731 const_iv (EVENT_READ),
732 const_iv (EVENT_WRITE),
733
734 const_iv (NoEventMask),
735 const_iv (KeyPressMask),
736 const_iv (KeyReleaseMask),
737 const_iv (ButtonPressMask),
738 const_iv (ButtonReleaseMask),
739 const_iv (EnterWindowMask),
740 const_iv (LeaveWindowMask),
741 const_iv (PointerMotionMask),
742 const_iv (PointerMotionHintMask),
743 const_iv (Button1MotionMask),
744 const_iv (Button2MotionMask),
745 const_iv (Button3MotionMask),
746 const_iv (Button4MotionMask),
747 const_iv (Button5MotionMask),
748 const_iv (ButtonMotionMask),
749 const_iv (KeymapStateMask),
750 const_iv (ExposureMask),
751 const_iv (VisibilityChangeMask),
752 const_iv (StructureNotifyMask),
753 const_iv (ResizeRedirectMask),
754 const_iv (SubstructureNotifyMask),
755 const_iv (SubstructureRedirectMask),
756 const_iv (FocusChangeMask),
757 const_iv (PropertyChangeMask),
758 const_iv (ColormapChangeMask),
759 const_iv (OwnerGrabButtonMask),
760
761 const_iv (KeyPress),
762 const_iv (KeyRelease),
763 const_iv (ButtonPress),
764 const_iv (ButtonRelease),
765 const_iv (MotionNotify),
766 const_iv (EnterNotify),
767 const_iv (LeaveNotify),
768 const_iv (FocusIn),
769 const_iv (FocusOut),
770 const_iv (KeymapNotify),
771 const_iv (Expose),
772 const_iv (GraphicsExpose),
773 const_iv (NoExpose),
774 const_iv (VisibilityNotify),
775 const_iv (CreateNotify),
776 const_iv (DestroyNotify),
777 const_iv (UnmapNotify),
778 const_iv (MapNotify),
779 const_iv (MapRequest),
780 const_iv (ReparentNotify),
781 const_iv (ConfigureNotify),
782 const_iv (ConfigureRequest),
783 const_iv (GravityNotify),
784 const_iv (ResizeRequest),
785 const_iv (CirculateNotify),
786 const_iv (CirculateRequest),
787 const_iv (PropertyNotify),
788 const_iv (SelectionClear),
789 const_iv (SelectionRequest),
790 const_iv (SelectionNotify),
791 const_iv (ColormapNotify),
792 const_iv (ClientMessage),
793 const_iv (MappingNotify),
794 };
795
796 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
797 civ-- > const_iv; )
798 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
799}
316 800
317void 801void
318warn (const char *msg) 802warn (const char *msg)
319 CODE: 803 CODE:
320 rxvt_warn ("%s", msg); 804 rxvt_warn ("%s", msg);
321 805
322void 806void
323fatal (const char *msg) 807fatal (const char *msg)
324 CODE: 808 CODE:
325 rxvt_fatal ("%s", msg); 809 rxvt_fatal ("%s", msg);
810
811void
812_exit (int status)
326 813
327NV 814NV
328NOW () 815NOW ()
329 CODE: 816 CODE:
330 RETVAL = NOW; 817 RETVAL = NOW;
331 OUTPUT: 818 OUTPUT:
332 RETVAL 819 RETVAL
333 820
821int
822GET_BASEFG (int rend)
823 CODE:
824 RETVAL = GET_BASEFG (rend);
825 OUTPUT:
826 RETVAL
827
828int
829GET_BASEBG (int rend)
830 CODE:
831 RETVAL = GET_BASEBG (rend);
832 OUTPUT:
833 RETVAL
834
835int
836SET_FGCOLOR (int rend, int new_color)
837 CODE:
838 RETVAL = SET_FGCOLOR (rend, new_color);
839 OUTPUT:
840 RETVAL
841
842int
843SET_BGCOLOR (int rend, int new_color)
844 CODE:
845 RETVAL = SET_BGCOLOR (rend, new_color);
846 OUTPUT:
847 RETVAL
848
849int
850GET_CUSTOM (int rend)
851 CODE:
852 RETVAL = (rend && RS_customMask) >> RS_customShift;
853 OUTPUT:
854 RETVAL
855
856int
857SET_CUSTOM (int rend, int new_value)
858 CODE:
859{
860 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
861 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
862
863 RETVAL = (rend & ~RS_customMask)
864 | ((new_value << RS_customShift) & RS_customMask);
865}
866 OUTPUT:
867 RETVAL
868
334MODULE = urxvt PACKAGE = urxvt::term 869MODULE = urxvt PACKAGE = urxvt::term
870
871SV *
872_new (...)
873 CODE:
874{
875 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
876 croak ("first argument to urxvt::term->_new must be arrayref");
877
878 rxvt_term *term = new rxvt_term;
879
880 term->argv = new stringvec;
881 term->envv = new stringvec;
882
883 for (int i = 1; i < items; i++)
884 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
885
886 AV *envv = (AV *)SvRV (ST (0));
887 for (int i = AvFILL (envv) + 1; i--; )
888 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
889
890 term->envv->push_back (0);
891
892 bool success;
893
894 try
895 {
896 success = term->init (term->argv->size (), term->argv->begin ());
897 }
898 catch (const class rxvt_failure_exception &e)
899 {
900 success = false;
901 }
902
903 if (!success)
904 {
905 term->destroy ();
906 croak ("error while initializing new terminal instance");
907 }
908
909 RETVAL = term && term->perl.self
910 ? newSVterm (term) : &PL_sv_undef;
911}
912 OUTPUT:
913 RETVAL
914
915void
916rxvt_term::destroy ()
917
918#if ENABLE_PERL_FRILLS
919
920void
921rxvt_term::XListProperties (U32 window)
922 PPCODE:
923{
924 int count;
925 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
926
927 EXTEND (SP, count);
928 while (count--)
929 PUSHs (newSVuv ((U32)props [count]));
930
931 XFree (props);
932}
933
934void
935rxvt_term::XGetWindowProperty (U32 window, U32 property)
936 PPCODE:
937{
938 Atom type;
939 int format;
940 unsigned long nitems;
941 unsigned long bytes_after;
942 unsigned char *prop;
943 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
944 0, 1<<30, 0, AnyPropertyType,
945 &type, &format, &nitems, &bytes_after, &prop);
946 if (type != None)
947 {
948 EXTEND (SP, 3);
949 PUSHs (newSVuv ((U32)type));
950 PUSHs (newSViv (format));
951 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
952 XFree (prop);
953 }
954}
955
956void
957rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
958 CODE:
959{
960 STRLEN len;
961 char *data_ = SvPVbyte (data, len);
962
963 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
964 type, format, PropModeReplace,
965 (unsigned char *)data, len * 8 / format);
966}
967
968void
969rxvt_term::XDeleteProperty (U32 window, U32 property)
970 CODE:
971 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
972
973U32
974rxvt_term::DefaultRootWindow ()
975 CODE:
976 RETVAL = (U32)THIS->display->root;
977 OUTPUT:
978 RETVAL
979
980U32
981rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
982 CODE:
983 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
984 x, y, width, height, 0,
985 THIS->pix_colors_focused[Color_border],
986 THIS->pix_colors_focused[Color_border]);
987 OUTPUT:
988 RETVAL
989
990void
991rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
992 CODE:
993 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
994
995void
996rxvt_term::XMapWindow (U32 window)
997 CODE:
998 XMapWindow (THIS->display->display, (Window)window);
999
1000void
1001rxvt_term::XUnmapWindow (U32 window)
1002 CODE:
1003 XUnmapWindow (THIS->display->display, (Window)window);
1004
1005#endif
1006
1007void
1008rxvt_term::set_should_invoke (int htype, int inc)
1009 CODE:
1010 THIS->perl.should_invoke [htype] += inc;
1011
1012void
1013rxvt_term::grab_button (int button, U32 modifiers)
1014 CODE:
1015 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
1016 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1017 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1018
1019bool
1020rxvt_term::grab (U32 eventtime, int sync = 0)
1021 CODE:
1022{
1023 int mode = sync ? GrabModeSync : GrabModeAsync;
1024
1025 THIS->perl.grabtime = 0;
1026
1027 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
1028 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1029 mode, mode, None, GRAB_CURSOR, eventtime))
1030 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
1031 THIS->perl.grabtime = eventtime;
1032 else
1033 XUngrabPointer (THIS->display->display, eventtime);
1034
1035 RETVAL = !!THIS->perl.grabtime;
1036}
1037 OUTPUT:
1038 RETVAL
1039
1040void
1041rxvt_term::allow_events_async ()
1042 CODE:
1043 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
1044
1045void
1046rxvt_term::allow_events_sync ()
1047 CODE:
1048 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
1049
1050void
1051rxvt_term::allow_events_replay ()
1052 CODE:
1053 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
1054 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
1055
1056void
1057rxvt_term::ungrab ()
1058 CODE:
1059 ungrab (THIS);
335 1060
336int 1061int
337rxvt_term::strwidth (SV *str) 1062rxvt_term::strwidth (SV *str)
338 CODE: 1063 CODE:
339{ 1064{
375 1100
376 rxvt_push_locale (THIS->locale); 1101 rxvt_push_locale (THIS->locale);
377 wchar_t *wstr = rxvt_mbstowcs (data, len); 1102 wchar_t *wstr = rxvt_mbstowcs (data, len);
378 rxvt_pop_locale (); 1103 rxvt_pop_locale ();
379 1104
380 char *str = rxvt_wcstoutf8 (wstr); 1105 RETVAL = wcs2sv (wstr);
381 free (wstr); 1106 free (wstr);
1107}
1108 OUTPUT:
1109 RETVAL
382 1110
383 RETVAL = newSVpv (str, 0); 1111#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
384 SvUTF8_on (RETVAL); 1112
1113#define TERM_OFFSET_width TERM_OFFSET(width)
1114#define TERM_OFFSET_height TERM_OFFSET(height)
1115#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1116#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1117#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1118#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1119#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1120#define TERM_OFFSET_focus TERM_OFFSET(focus)
1121#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1122#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1123#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1124#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1125
1126int
1127rxvt_term::width ()
1128 ALIAS:
1129 width = TERM_OFFSET_width
1130 height = TERM_OFFSET_height
1131 fwidth = TERM_OFFSET_fwidth
1132 fheight = TERM_OFFSET_fheight
1133 fbase = TERM_OFFSET_fbase
1134 nrow = TERM_OFFSET_nrow
1135 ncol = TERM_OFFSET_ncol
1136 focus = TERM_OFFSET_focus
1137 mapped = TERM_OFFSET_mapped
1138 saveLines = TERM_OFFSET_saveLines
1139 total_rows = TERM_OFFSET_total_rows
1140 top_row = TERM_OFFSET_top_row
1141 CODE:
1142 RETVAL = *(int *)((char *)THIS + ix);
1143 OUTPUT:
1144 RETVAL
1145
1146unsigned int
1147rxvt_term::ModLevel3Mask ()
1148 ALIAS:
1149 ModLevel3Mask = 0
1150 ModMetaMask = 1
1151 ModNumLockMask = 2
1152 CODE:
1153 switch (ix)
1154 {
1155 case 0: RETVAL = THIS->ModLevel3Mask; break;
1156 case 1: RETVAL = THIS->ModMetaMask; break;
1157 case 2: RETVAL = THIS->ModNumLockMask; break;
1158 }
1159 OUTPUT:
1160 RETVAL
1161
1162char *
1163rxvt_term::display_id ()
1164 ALIAS:
1165 display_id = 0
1166 locale = 1
1167 CODE:
1168 switch (ix)
1169 {
1170 case 0: RETVAL = THIS->display->id; break;
1171 case 1: RETVAL = THIS->locale; break;
1172 }
1173 OUTPUT:
1174 RETVAL
1175
1176SV *
1177rxvt_term::_env ()
1178 CODE:
1179{
1180 if (THIS->envv)
1181 {
1182 AV *av = newAV ();
1183
1184 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1185 if (*i)
1186 av_push (av, newSVpv (*i, 0));
1187
1188 RETVAL = newRV_noinc ((SV *)av);
1189 }
1190 else
1191 RETVAL = &PL_sv_undef;
1192}
1193 OUTPUT:
1194 RETVAL
1195
1196int
1197rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1198 CODE:
1199 RETVAL = THIS->pty_ev.events;
1200 if (events != EVENT_UNDEF)
1201 THIS->pty_ev.set (events);
1202 OUTPUT:
1203 RETVAL
1204
1205U32
1206rxvt_term::parent ()
1207 CODE:
1208 RETVAL = (U32)THIS->parent [0];
1209 OUTPUT:
1210 RETVAL
1211
1212U32
1213rxvt_term::vt ()
1214 CODE:
1215 RETVAL = (U32)THIS->vt;
1216 OUTPUT:
1217 RETVAL
1218
1219void
1220rxvt_term::vt_emask_add (U32 emask)
1221 CODE:
1222 THIS->vt_emask_perl |= emask;
1223 THIS->vt_select_input ();
1224
1225U32
1226rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
1227 CODE:
1228 RETVAL = THIS->rstyle;
1229 THIS->rstyle = new_rstyle;
1230 OUTPUT:
1231 RETVAL
1232
1233int
1234rxvt_term::view_start (int newval = 1)
1235 PROTOTYPE: $;$
1236 CODE:
1237{
1238 RETVAL = THIS->view_start;
1239
1240 if (newval <= 0)
1241 THIS->scr_changeview (max (newval, THIS->top_row));
1242}
1243 OUTPUT:
1244 RETVAL
1245
1246void
1247rxvt_term::want_refresh ()
1248 CODE:
1249 THIS->want_refresh = 1;
1250
1251void
1252rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1253 PPCODE:
1254{
1255 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1256 XSRETURN_EMPTY;
1257
1258 line_t &l = ROW(row_number);
1259
1260 if (GIMME_V != G_VOID)
1261 {
1262 wchar_t *wstr = new wchar_t [THIS->ncol];
1263
1264 for (int col = 0; col < THIS->ncol; col++)
1265 wstr [col] = l.t [col];
1266
1267 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1268
1269 delete [] wstr;
1270 }
1271
1272 if (new_text)
1273 {
1274 wchar_t *wstr = sv2wcs (new_text);
1275
1276 int len = min (wcslen (wstr) - start_ofs, max_len);
1277
1278 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1279 {
1280 free (wstr);
1281 croak ("new_text extends beyond horizontal margins");
1282 }
1283
1284 for (int col = start_col; col < start_col + len; col++)
1285 {
1286 l.t [col] = wstr [start_ofs + col - start_col];
1287 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
1288 }
1289
385 free (str); 1290 free (wstr);
1291 }
1292}
1293
1294void
1295rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1296 PPCODE:
1297{
1298 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1299 XSRETURN_EMPTY;
1300
1301 line_t &l = ROW(row_number);
1302
1303 if (GIMME_V != G_VOID)
1304 {
1305 AV *av = newAV ();
1306
1307 av_extend (av, THIS->ncol - 1);
1308 for (int col = 0; col < THIS->ncol; col++)
1309 av_store (av, col, newSViv (l.r [col]));
1310
1311 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1312 }
1313
1314 if (new_rend)
1315 {
1316 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1317 croak ("new_rend must be arrayref");
1318
1319 AV *av = (AV *)SvRV (new_rend);
1320 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1321
1322 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1323 croak ("new_rend array extends beyond horizontal margins");
1324
1325 for (int col = start_col; col < start_col + len; col++)
1326 {
1327 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1328
1329 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
1330 }
1331 }
1332}
1333
1334int
1335rxvt_term::ROW_l (int row_number, int new_length = -1)
1336 CODE:
1337{
1338 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1339 XSRETURN_EMPTY;
1340
1341 line_t &l = ROW(row_number);
1342 RETVAL = l.l;
1343
1344 if (new_length >= 0)
1345 l.l = new_length;
1346}
1347 OUTPUT:
1348 RETVAL
1349
1350bool
1351rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1352 CODE:
1353{
1354 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1355 XSRETURN_EMPTY;
1356
1357 line_t &l = ROW(row_number);
1358 RETVAL = l.is_longer ();
1359
1360 if (new_is_longer >= 0)
1361 l.is_longer (new_is_longer);
1362}
1363 OUTPUT:
1364 RETVAL
1365
1366SV *
1367rxvt_term::special_encode (SV *string)
1368 CODE:
1369{
1370 wchar_t *wstr = sv2wcs (string);
1371 int wlen = wcslen (wstr);
1372 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1373
1374 rxvt_push_locale (THIS->locale);
1375
1376 wchar_t *r = rstr;
1377 for (wchar_t *s = wstr; *s; s++)
1378 if (wcwidth (*s) == 0)
1379 {
1380 if (r == rstr)
1381 croak ("leading combining character unencodable");
1382
1383 unicode_t n = rxvt_compose (r[-1], *s);
1384 if (n == NOCHAR)
1385 n = rxvt_composite.compose (r[-1], *s);
1386
1387 r[-1] = n;
1388 }
1389#if !UNICODE_3
1390 else if (*s >= 0x10000)
1391 *r++ = rxvt_composite.compose (*s);
1392#endif
1393 else
1394 *r++ = *s;
1395
1396 rxvt_pop_locale ();
1397
1398 RETVAL = wcs2sv (rstr, r - rstr);
1399
1400 delete [] rstr;
1401}
1402 OUTPUT:
1403 RETVAL
1404
1405SV *
1406rxvt_term::special_decode (SV *text)
1407 CODE:
1408{
1409 wchar_t *wstr = sv2wcs (text);
1410 int wlen = wcslen (wstr);
1411 int dlen = 0;
1412
1413 // find length
1414 for (wchar_t *s = wstr; *s; s++)
1415 if (*s == NOCHAR)
1416 ;
1417 else if (IS_COMPOSE (*s))
1418 dlen += rxvt_composite.expand (*s, 0);
1419 else
1420 dlen++;
1421
1422 wchar_t *rstr = new wchar_t [dlen];
1423
1424 // decode
1425 wchar_t *r = rstr;
1426 for (wchar_t *s = wstr; *s; s++)
1427 if (*s == NOCHAR)
1428 ;
1429 else if (IS_COMPOSE (*s))
1430 r += rxvt_composite.expand (*s, r);
1431 else
1432 *r++ = *s;
1433
1434 RETVAL = wcs2sv (rstr, r - rstr);
1435
1436 delete [] rstr;
386} 1437}
387 OUTPUT: 1438 OUTPUT:
388 RETVAL 1439 RETVAL
389 1440
390void 1441void
391rxvt_term::_resource (char *name, int index, SV *newval = 0) 1442rxvt_term::_resource (char *name, int index, SV *newval = 0)
392 PPCODE: 1443 PPCODE:
393{ 1444{
394 struct resval { const char *name; int value; } rslist [] = { 1445 struct resval { const char *name; int value; } rslist [] = {
395# define Rs_def(name) { # name, Rs_ ## name }, 1446# define def(name) { # name, Rs_ ## name },
396# define Rs_reserve(name,count) 1447# define reserve(name,count)
397# include "rsinc.h" 1448# include "rsinc.h"
398# undef Rs_def 1449# undef def
399# undef Rs_reserve 1450# undef reserve
400 }; 1451 };
401 1452
402 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1453 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
403 1454
404 do { 1455 do {
425 else 1476 else
426 THIS->rs [index] = 0; 1477 THIS->rs [index] = 0;
427 } 1478 }
428} 1479}
429 1480
1481const char *
1482rxvt_term::x_resource (const char *name)
1483
1484bool
1485rxvt_term::option (U32 optval, int set = -1)
1486 CODE:
1487{
1488 RETVAL = THIS->options & optval;
1489
1490 if (set >= 0)
1491 {
1492 if (set)
1493 THIS->options |= optval;
1494 else
1495 THIS->options &= ~optval;
1496
1497 if (THIS->check_ev.is_active ()) // avoid doing this before START
1498 switch (optval)
1499 {
1500 case Opt_skipBuiltinGlyphs:
1501 THIS->set_fonts ();
1502 THIS->scr_remap_chars ();
1503 THIS->scr_touch (true);
1504 THIS->want_refresh = 1;
1505 break;
1506
1507 case Opt_cursorUnderline:
1508 THIS->want_refresh = 1;
1509 break;
1510
1511# case Opt_scrollBar_floating:
1512# case Opt_scrollBar_right:
1513# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1514# break;
1515 }
1516 }
1517}
1518 OUTPUT:
1519 RETVAL
1520
1521bool
1522rxvt_term::parse_keysym (char *keysym, char *str)
1523 CODE:
1524 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1525 THIS->keyboard->register_done ();
1526 OUTPUT:
1527 RETVAL
1528
430void 1529void
431rxvt_term::selection_mark (...) 1530rxvt_term::screen_cur (...)
432 PROTOTYPE: $;$$ 1531 PROTOTYPE: $;$$
433 ALIAS: 1532 ALIAS:
1533 screen_cur = 0
434 selection_beg = 1 1534 selection_beg = 1
435 selection_end = 2 1535 selection_end = 2
1536 selection_mark = 3
436 PPCODE: 1537 PPCODE:
437{ 1538{
438 row_col_t &sel = ix == 1 ? THIS->selection.beg 1539 row_col_t &rc = ix == 0 ? THIS->screen.cur
1540 : ix == 1 ? THIS->selection.beg
439 : ix == 2 ? THIS->selection.end 1541 : ix == 2 ? THIS->selection.end
440 : THIS->selection.mark; 1542 : THIS->selection.mark;
441 1543
442 if (GIMME_V != G_VOID) 1544 if (GIMME_V != G_VOID)
443 { 1545 {
444 EXTEND (SP, 2); 1546 EXTEND (SP, 2);
445 PUSHs (sv_2mortal (newSViv (sel.row))); 1547 PUSHs (sv_2mortal (newSViv (rc.row)));
446 PUSHs (sv_2mortal (newSViv (sel.col))); 1548 PUSHs (sv_2mortal (newSViv (rc.col)));
447 } 1549 }
448 1550
449 if (items == 3) 1551 if (items == 3)
450 { 1552 {
451 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1553 rc.row = SvIV (ST (1));
452 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1554 rc.col = SvIV (ST (2));
1555
1556 if (ix == 2 && rc.col == 0)
1557 {
1558 rc.row--;
1559 rc.col = THIS->ncol;
1560 }
1561
1562 clamp_it (rc.col, 0, THIS->ncol);
1563 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
453 1564
454 if (ix) 1565 if (ix)
455 THIS->want_refresh = 1; 1566 THIS->want_refresh = 1;
456 } 1567 }
457} 1568}
458 1569
1570char
1571rxvt_term::cur_charset ()
1572 CODE:
1573 RETVAL = THIS->charsets [THIS->screen.charset];
1574 OUTPUT:
1575 RETVAL
1576
1577#void
1578#rxvt_term::selection_clear ()
1579
1580void
1581rxvt_term::selection_make (U32 eventtime, bool rect = false)
1582 CODE:
1583 THIS->selection.op = SELECTION_CONT;
1584 THIS->selection.rect = rect;
1585 THIS->selection_make (eventtime);
1586
459int 1587int
460rxvt_term::selection_grab (int eventtime) 1588rxvt_term::selection_grab (U32 eventtime)
461 1589
462void 1590void
463rxvt_term::selection (SV *newtext = 0) 1591rxvt_term::selection (SV *newtext = 0)
464 PPCODE: 1592 PPCODE:
465{ 1593{
466 if (GIMME_V != G_VOID) 1594 if (GIMME_V != G_VOID)
467 { 1595 XPUSHs (THIS->selection.text
468 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); 1596 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
469 SV *sv = newSVpv (sel, 0); 1597 : &PL_sv_undef);
470 SvUTF8_on (sv);
471 free (sel);
472 XPUSHs (sv_2mortal (sv));
473 }
474 1598
475 if (newtext) 1599 if (newtext)
476 { 1600 {
477 free (THIS->selection.text); 1601 free (THIS->selection.text);
478 1602
479 THIS->selection.text = sv2wcs (newtext); 1603 THIS->selection.text = sv2wcs (newtext);
480 THIS->selection.len = wcslen (THIS->selection.text); 1604 THIS->selection.len = wcslen (THIS->selection.text);
481 } 1605 }
482} 1606}
483
484void
485rxvt_term::scr_overlay_new (int x, int y, int w, int h)
486 1607
487void 1608void
1609rxvt_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)
1610
1611void
1612rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1613
1614void
488rxvt_term::scr_overlay_off () 1615rxvt_term::scr_bell ()
489 1616
490void 1617void
491rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE) 1618rxvt_term::scr_add_lines (SV *string)
492 CODE: 1619 CODE:
493 THIS->scr_overlay_set (x, y, text, rend);
494
495void
496rxvt_term::scr_overlay_set (int x, int y, SV *text)
497 CODE:
498{ 1620{
499 wchar_t *wtext = sv2wcs (text); 1621 wchar_t *wstr = sv2wcs (string);
500 THIS->scr_overlay_set (x, y, wtext); 1622 THIS->scr_add_lines (wstr, wcslen (wstr));
501 free (wtext); 1623 free (wstr);
502} 1624}
503 1625
504void 1626void
505rxvt_term::tt_write (SV *octets) 1627rxvt_term::tt_write (SV *octets)
506 INIT: 1628 INIT:
507 STRLEN len; 1629 STRLEN len;
508 char *str = SvPVbyte (octets, len); 1630 char *str = SvPVbyte (octets, len);
509 C_ARGS: 1631 C_ARGS:
510 (unsigned char *)str, len 1632 str, len
1633
1634void
1635rxvt_term::cmd_parse (SV *octets)
1636 CODE:
1637{
1638 STRLEN len;
1639 char *str = SvPVbyte (octets, len);
1640
1641 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1642 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1643
1644 THIS->cmdbuf_ptr = str;
1645 THIS->cmdbuf_endp = str + len;
1646
1647 rxvt_push_locale (THIS->locale);
1648 THIS->cmd_parse ();
1649 rxvt_pop_locale ();
1650
1651 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1652 THIS->cmdbuf_endp = old_cmdbuf_endp;
1653}
1654
1655SV *
1656rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
1657 CODE:
1658{
1659 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
1660 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
1661 o->self = (HV *)SvRV (RETVAL);
1662}
1663 OUTPUT:
1664 RETVAL
1665
1666MODULE = urxvt PACKAGE = urxvt::overlay
1667
1668void
1669overlay::set (int x, int y, SV *text, SV *rend = 0)
1670
1671void
1672overlay::show ()
1673
1674void
1675overlay::hide ()
1676
1677void
1678overlay::DESTROY ()
511 1679
512MODULE = urxvt PACKAGE = urxvt::timer 1680MODULE = urxvt PACKAGE = urxvt::timer
513 1681
514SV * 1682SV *
515timer::new () 1683timer::new ()
516 CODE: 1684 CODE:
517 timer *w = new timer; 1685 timer *w = new timer;
1686 w->start (NOW);
518 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1687 RETVAL = newSVptr ((void *)w, "urxvt::timer");
519 w->self = (HV *)SvRV (RETVAL); 1688 w->self = (HV *)SvRV (RETVAL);
520 OUTPUT: 1689 OUTPUT:
521 RETVAL 1690 RETVAL
522 1691
530 1699
531NV 1700NV
532timer::at () 1701timer::at ()
533 CODE: 1702 CODE:
534 RETVAL = THIS->at; 1703 RETVAL = THIS->at;
1704 OUTPUT:
1705 RETVAL
1706
1707timer *
1708timer::interval (NV interval)
1709 CODE:
1710 THIS->interval = interval;
1711 RETVAL = THIS;
535 OUTPUT: 1712 OUTPUT:
536 RETVAL 1713 RETVAL
537 1714
538timer * 1715timer *
539timer::set (NV tstamp) 1716timer::set (NV tstamp)
550 RETVAL = THIS; 1727 RETVAL = THIS;
551 OUTPUT: 1728 OUTPUT:
552 RETVAL 1729 RETVAL
553 1730
554timer * 1731timer *
1732timer::after (NV delay)
1733 CODE:
1734 THIS->start (NOW + delay);
1735 RETVAL = THIS;
1736 OUTPUT:
1737 RETVAL
1738
1739timer *
555timer::stop () 1740timer::stop ()
556 CODE: 1741 CODE:
557 THIS->stop (); 1742 THIS->stop ();
558 RETVAL = THIS; 1743 RETVAL = THIS;
559 OUTPUT: 1744 OUTPUT:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines