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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines