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.11 by root, Tue Jan 3 02:01:27 2006 UTC vs.
Revision 1.41 by root, Sun Jan 8 03:07:05 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
33#include "rxvt.h" 34#include "rxvt.h"
34#include "iom.h" 35#include "iom.h"
35#include "rxvtutil.h" 36#include "rxvtutil.h"
36#include "rxvtperl.h" 37#include "rxvtperl.h"
37 38
38#include "perlxsi.c" 39#include "perlxsi.c"
39 40
41#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
42# define GRAB_CURSOR THIS->leftptr_cursor
43#else
44# define GRAB_CURSOR None
45#endif
46
40#undef LINENO 47#undef LINENO
41#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)
42#undef ROW 49#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
44 51
51 char *str = SvPVutf8 (sv, len); 58 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 59 return rxvt_utf8towcs (str, len);
53} 60}
54 61
55static SV * 62static SV *
63wcs2sv (wchar_t *wstr, int len = -1)
64{
65 char *str = rxvt_wcstoutf8 (wstr, len);
66
67 SV *sv = newSVpv (str, 0);
68 SvUTF8_on (sv);
69 free (str);
70
71 return sv;
72}
73
74static SV *
56new_ref (HV *hv, const char *klass) 75new_ref (HV *hv, const char *klass)
57{ 76{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 77 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 78}
60 79
61//TODO: use magic 80//TODO: use magic
62static SV * 81static SV *
63newSVptr (void *ptr, const char *klass) 82newSVptr (void *ptr, const char *klass)
64{ 83{
65 HV *hv = newHV (); 84 HV *hv = newHV ();
66 hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); 85 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
67 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 86 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
87}
88
89static void
90clearSVptr (SV *sv)
91{
92 if (SvROK (sv))
93 sv = SvRV (sv);
94
95 hv_clear ((HV *)sv);
96 sv_unmagic (sv, PERL_MAGIC_ext);
68} 97}
69 98
70static long 99static long
71SvPTR (SV *sv, const char *klass) 100SvPTR (SV *sv, const char *klass)
72{ 101{
73 if (!sv_derived_from (sv, klass)) 102 if (!sv_derived_from (sv, klass))
74 croak ("object of type %s expected", klass); 103 croak ("object of type %s expected", klass);
75 104
76 IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); 105 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
77 106
78 if (!iv) 107 if (!mg)
79 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 108 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
80 109
81 return (long)iv; 110 return (long)mg->mg_ptr;
82} 111}
83 112
84#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 113#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
85#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 114#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
86 115
87///////////////////////////////////////////////////////////////////////////// 116/////////////////////////////////////////////////////////////////////////////
88 117
89struct perl_watcher 118struct perl_watcher
139#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 168#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
140#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 169#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
141 170
142struct timer : time_watcher, perl_watcher 171struct timer : time_watcher, perl_watcher
143{ 172{
173 tstamp interval;
174
144 timer () 175 timer ()
145 : time_watcher (this, &timer::execute) 176 : time_watcher (this, &timer::execute)
146 { 177 {
147 } 178 }
148 179
149 void execute (time_watcher &w) 180 void execute (time_watcher &w)
150 { 181 {
182 if (interval)
183 start (at + interval);
184
151 invoke ("urxvt::timer", newSVtimer (this)); 185 invoke ("urxvt::timer", newSVtimer (this));
152 } 186 }
153}; 187};
154 188
155#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 189#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
165 void execute (io_watcher &w, short revents) 199 void execute (io_watcher &w, short revents)
166 { 200 {
167 invoke ("urxvt::iow", newSViow (this), revents); 201 invoke ("urxvt::iow", newSViow (this), revents);
168 } 202 }
169}; 203};
204
205/////////////////////////////////////////////////////////////////////////////
206
207#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
208
209struct overlay {
210 HV *self;
211 rxvt_term *THIS;
212 int x, y, w, h;
213 int border;
214 text_t **text;
215 rend_t **rend;
216
217 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
218 ~overlay ();
219
220 void show ();
221 void hide ();
222
223 void swap ();
224
225 void set (int x, int y, SV *str, SV *rend);
226};
227
228overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
229: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
230{
231 if (border == 2)
232 {
233 w += 2;
234 h += 2;
235 }
236
237 text = new text_t *[h];
238 rend = new rend_t *[h];
239
240 for (int y = 0; y < h; y++)
241 {
242 text_t *tp = text[y] = new text_t[w];
243 rend_t *rp = rend[y] = new rend_t[w];
244
245 text_t t0, t1, t2;
246 rend_t r = rstyle;
247
248 if (border == 2)
249 {
250 if (y == 0)
251 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
252 else if (y < h - 1)
253 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
254 else
255 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
256
257 *tp++ = t0;
258 *rp++ = r;
259
260 for (int x = w - 2; x-- > 0; )
261 {
262 *tp++ = t1;
263 *rp++ = r;
264 }
265
266 *tp = t2;
267 *rp = r;
268 }
269 else
270 for (int x = w; x-- > 0; )
271 {
272 *tp++ = 0x0020;
273 *rp++ = r;
274 }
275 }
276
277 show ();
278 THIS->want_refresh = 1;
279}
280
281overlay::~overlay ()
282{
283 hide ();
284
285 for (int y = h; y--; )
286 {
287 delete [] text[y];
288 delete [] rend[y];
289 }
290
291 delete [] text;
292 delete [] rend;
293
294 THIS->want_refresh = 1;
295}
296
297void
298overlay::show ()
299{
300 char key[33]; sprintf (key, "%32lx", (long)this);
301
302 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
303 hv_store (hv, key, 32, newSViv ((long)this), 0);
304}
305
306void
307overlay::hide ()
308{
309 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
310
311 if (ovs)
312 {
313 char key[33]; sprintf (key, "%32lx", (long)this);
314
315 HV *hv = (HV *)SvRV (*ovs);
316 hv_delete (hv, key, 32, G_DISCARD);
317 }
318}
319
320void overlay::swap ()
321{
322 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
323 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
324
325 int ov_w = min (w, THIS->ncol - ov_x);
326 int ov_h = min (h, THIS->nrow - ov_y);
327
328 for (int y = ov_h; y--; )
329 {
330 text_t *t1 = text [y];
331 rend_t *r1 = rend [y];
332
333 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
334 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
335
336 for (int x = ov_w; x--; )
337 {
338 text_t t = *t1; *t1++ = *t2; *t2++ = t;
339 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
340 }
341 }
342
343}
344
345void overlay::set (int x, int y, SV *text, SV *rend)
346{
347 x += border;
348 y += border;
349
350 if (!IN_RANGE_EXC (y, 0, h - border))
351 return;
352
353 wchar_t *wtext = sv2wcs (text);
354
355 for (int col = min (wcslen (wtext), w - x - border); col--; )
356 this->text [y][x + col] = wtext [col];
357
358 free (wtext);
359
360 if (rend)
361 {
362 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
363 croak ("rend must be arrayref");
364
365 AV *av = (AV *)SvRV (rend);
366
367 for (int col = min (av_len (av) + 1, w - x - border); col--; )
368 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
369 }
370
371 THIS->want_refresh = 1;
372}
373
170 374
171///////////////////////////////////////////////////////////////////////////// 375/////////////////////////////////////////////////////////////////////////////
172 376
173struct rxvt_perl_interp rxvt_perl; 377struct rxvt_perl_interp rxvt_perl;
174 378
213} 417}
214 418
215bool 419bool
216rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 420rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
217{ 421{
218 if (!perl 422 if (!perl)
219 || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY))
220 return false; 423 return false;
221 424
222 if (htype == HOOK_INIT) // first hook ever called 425 if (htype == HOOK_INIT) // first hook ever called
426 {
223 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 427 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
428 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
429 }
430 else if (!term->perl.self)
431 return false; // perl not initialized for this instance
432 else if (htype == HOOK_DESTROY)
433 {
434 // handled later
435 }
436 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
437 {
438 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
439
440 if (HvKEYS (hv))
441 {
442 hv_iterinit (hv);
443
444 while (HE *he = hv_iternext (hv))
445 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
446 }
447 }
448 else if (!should_invoke [htype])
449 return false;
224 450
225 dSP; 451 dSP;
226 va_list ap; 452 va_list ap;
227 453
228 va_start (ap, htype); 454 va_start (ap, htype);
246 472
247 case DT_LONG: 473 case DT_LONG:
248 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 474 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
249 break; 475 break;
250 476
251 case DT_STRING: 477 case DT_STR:
252 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 478 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
479 break;
480
481 case DT_STR_LEN:
482 {
483 char *str = va_arg (ap, char *);
484 int len = va_arg (ap, int);
485
486 XPUSHs (sv_2mortal (newSVpvn (str, len)));
487 }
488 break;
489
490 case DT_WCS_LEN:
491 {
492 wchar_t *wstr = va_arg (ap, wchar_t *);
493 int wlen = va_arg (ap, int);
494
495 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
496 }
497 break;
498
499 case DT_XEVENT:
500 {
501 XEvent *xe = va_arg (ap, XEvent *);
502 HV *hv = newHV ();
503
504# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
505# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
506# undef set
507
508 setiv (type, xe->type);
509 setiv (send_event, xe->xany.send_event);
510 setiv (serial, xe->xany.serial);
511
512 switch (xe->type)
513 {
514 case KeyPress:
515 case KeyRelease:
516 case ButtonPress:
517 case ButtonRelease:
518 case MotionNotify:
519 setiv (time, xe->xmotion.time);
520 setiv (x, xe->xmotion.x);
521 setiv (y, xe->xmotion.y);
522 setiv (row, xe->xmotion.y / term->fheight);
523 setiv (col, xe->xmotion.x / term->fwidth);
524 setiv (x_root, xe->xmotion.x_root);
525 setiv (y_root, xe->xmotion.y_root);
526 setiv (state, xe->xmotion.state);
527 break;
528 }
529
530 switch (xe->type)
531 {
532 case KeyPress:
533 case KeyRelease:
534 setiv (keycode, xe->xkey.keycode);
535 break;
536
537 case ButtonPress:
538 case ButtonRelease:
539 setiv (button, xe->xbutton.button);
540 break;
541
542 case MotionNotify:
543 setiv (is_hint, xe->xmotion.is_hint);
544 break;
545 }
546
547 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
548 }
253 break; 549 break;
254 550
255 case DT_END: 551 case DT_END:
256 { 552 {
257 va_end (ap); 553 va_end (ap);
273 if (SvTRUE (ERRSV)) 569 if (SvTRUE (ERRSV))
274 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 570 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
275 571
276 if (htype == HOOK_DESTROY) 572 if (htype == HOOK_DESTROY)
277 { 573 {
278 // TODO: clear magic
279 hv_clear ((HV *)SvRV ((SV *)term->self)); 574 clearSVptr ((SV *)term->perl.self);
280 SvREFCNT_dec ((SV *)term->self); 575 SvREFCNT_dec ((SV *)term->perl.self);
281 } 576 }
282 577
283 return count; 578 return count;
284 } 579 }
285 580
295 590
296PROTOTYPES: ENABLE 591PROTOTYPES: ENABLE
297 592
298BOOT: 593BOOT:
299{ 594{
300# define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) 595 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
301# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); 596
302 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 597 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
303 set_hookname (INIT); 598# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
304 set_hookname (RESET); 599# include "hookinc.h"
305 set_hookname (START); 600# undef def
306 set_hookname (DESTROY);
307 set_hookname (SEL_BEGIN);
308 set_hookname (SEL_EXTEND);
309 set_hookname (SEL_MAKE);
310 set_hookname (SEL_GRAB);
311 set_hookname (FOCUS_IN);
312 set_hookname (FOCUS_OUT);
313 set_hookname (VIEW_CHANGE);
314 set_hookname (SCROLL_BACK);
315 set_hookname (TTY_ACTIVITY);
316 set_hookname (REFRESH_BEGIN);
317 set_hookname (REFRESH_END);
318 set_hookname (KEYBOARD_COMMAND);
319 601
602 HV *option = get_hv ("urxvt::OPTION", 1);
603# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
604# define nodef(name)
605# include "optinc.h"
606# undef nodef
607# undef def
608
609 HV *stash = gv_stashpv ("urxvt", 1);
610# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
320 export_const (DEFAULT_RSTYLE); 611 export_const_iv (DEFAULT_RSTYLE);
321 export_const (OVERLAY_RSTYLE); 612 export_const_iv (OVERLAY_RSTYLE);
322 export_const (RS_Bold); 613 export_const_iv (RS_Bold);
323 export_const (RS_Italic); 614 export_const_iv (RS_Italic);
324 export_const (RS_Blink); 615 export_const_iv (RS_Blink);
325 export_const (RS_RVid); 616 export_const_iv (RS_RVid);
326 export_const (RS_Uline); 617 export_const_iv (RS_Uline);
327 618
328 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 619 export_const_iv (CurrentTime);
620 export_const_iv (ShiftMask);
621 export_const_iv (LockMask);
622 export_const_iv (ControlMask);
623 export_const_iv (Mod1Mask);
624 export_const_iv (Mod2Mask);
625 export_const_iv (Mod3Mask);
626 export_const_iv (Mod4Mask);
627 export_const_iv (Mod5Mask);
628 export_const_iv (Button1Mask);
629 export_const_iv (Button2Mask);
630 export_const_iv (Button3Mask);
631 export_const_iv (Button4Mask);
632 export_const_iv (Button5Mask);
633 export_const_iv (AnyModifier);
329} 634}
635
636SV *
637new (...)
638 CODE:
639{
640 stringvec *argv = new stringvec;
641 bool success;
642
643 for (int i = 0; i < items ;i++)
644 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
645
646 rxvt_term *term = new rxvt_term;
647
648 term->argv = argv;
649
650 try
651 {
652 if (!term->init (argv->size (), argv->begin ()))
653 term = 0;
654 }
655 catch (const class rxvt_failure_exception &e)
656 {
657 term->destroy ();
658 croak ("exception caught while initializing new terminal instance");
659 }
660
661 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
662}
663 OUTPUT:
664 RETVAL
330 665
331void 666void
332set_should_invoke (int htype, int value) 667set_should_invoke (int htype, int value)
333 CODE: 668 CODE:
334 rxvt_perl.should_invoke [htype] = value; 669 rxvt_perl.should_invoke [htype] = value;
363 RETVAL = GET_BASEBG (rend); 698 RETVAL = GET_BASEBG (rend);
364 OUTPUT: 699 OUTPUT:
365 RETVAL 700 RETVAL
366 701
367int 702int
368SET_FGCOLOR (int rend, int color) 703SET_FGCOLOR (int rend, int new_color)
369 CODE: 704 CODE:
370 RETVAL = SET_FGCOLOR (rend, color); 705 RETVAL = SET_FGCOLOR (rend, new_color);
371 OUTPUT: 706 OUTPUT:
372 RETVAL 707 RETVAL
373 708
374int 709int
375SET_BGCOLOR (int rend, int color) 710SET_BGCOLOR (int rend, int new_color)
376 CODE: 711 CODE:
377 RETVAL = SET_BGCOLOR (rend, color); 712 RETVAL = SET_BGCOLOR (rend, new_color);
378 OUTPUT: 713 OUTPUT:
379 RETVAL 714 RETVAL
380 715
716int
717GET_CUSTOM (int rend)
718 CODE:
719 RETVAL = (rend && RS_customMask) >> RS_customShift;
720 OUTPUT:
721 RETVAL
722
723int
724SET_CUSTOM (int rend, int new_value)
725 CODE:
726{
727 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
728 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
729
730 RETVAL = (rend & ~RS_customMask)
731 | ((new_value << RS_customShift) & RS_customMask);
732}
733 OUTPUT:
734 RETVAL
735
381MODULE = urxvt PACKAGE = urxvt::term 736MODULE = urxvt PACKAGE = urxvt::term
737
738void
739rxvt_term::destroy ()
740
741void
742rxvt_term::grab_button (int button, U32 modifiers)
743 CODE:
744 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
745 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
746 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
747
748bool
749rxvt_term::grab (U32 eventtime, int sync = 0)
750 CODE:
751{
752 int mode = sync ? GrabModeSync : GrabModeAsync;
753
754 THIS->perl.grabtime = 0;
755
756 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
757 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
758 mode, mode, None, GRAB_CURSOR, eventtime))
759 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
760 THIS->perl.grabtime = eventtime;
761 else
762 XUngrabPointer (THIS->display->display, eventtime);
763
764 RETVAL = !!THIS->perl.grabtime;
765}
766 OUTPUT:
767 RETVAL
768
769void
770rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
771 CODE:
772 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
773
774void
775rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
776 CODE:
777 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
778
779void
780rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
781 CODE:
782 XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
783 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
784
785void
786rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
787 CODE:
788 THIS->perl.grabtime = 0;
789 XUngrabKeyboard (THIS->display->display, eventtime);
790 XUngrabPointer (THIS->display->display, eventtime);
382 791
383int 792int
384rxvt_term::strwidth (SV *str) 793rxvt_term::strwidth (SV *str)
385 CODE: 794 CODE:
386{ 795{
422 831
423 rxvt_push_locale (THIS->locale); 832 rxvt_push_locale (THIS->locale);
424 wchar_t *wstr = rxvt_mbstowcs (data, len); 833 wchar_t *wstr = rxvt_mbstowcs (data, len);
425 rxvt_pop_locale (); 834 rxvt_pop_locale ();
426 835
427 char *str = rxvt_wcstoutf8 (wstr); 836 RETVAL = wcs2sv (wstr);
428 free (wstr); 837 free (wstr);
429
430 RETVAL = newSVpv (str, 0);
431 SvUTF8_on (RETVAL);
432 free (str);
433} 838}
434 OUTPUT: 839 OUTPUT:
435 RETVAL 840 RETVAL
436 841
842#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
843
844#define TERM_OFFSET_width TERM_OFFSET(width)
845#define TERM_OFFSET_height TERM_OFFSET(height)
846#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
847#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
848#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
849#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
850#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
851#define TERM_OFFSET_focus TERM_OFFSET(focus)
852#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
853#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
854#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
855#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved)
856
437int 857int
858rxvt_term::width ()
859 ALIAS:
860 width = TERM_OFFSET_width
861 height = TERM_OFFSET_height
862 fwidth = TERM_OFFSET_fwidth
863 fheight = TERM_OFFSET_fheight
864 fbase = TERM_OFFSET_fbase
865 nrow = TERM_OFFSET_nrow
866 ncol = TERM_OFFSET_ncol
867 focus = TERM_OFFSET_focus
868 mapped = TERM_OFFSET_mapped
869 saveLines = TERM_OFFSET_saveLines
870 total_rows = TERM_OFFSET_total_rows
871 nsaved = TERM_OFFSET_nsaved
872 CODE:
873 RETVAL = *(int *)((char *)THIS + ix);
874 OUTPUT:
875 RETVAL
876
877unsigned int
878rxvt_term::ModLevel3Mask ()
879 ALIAS:
880 ModLevel3Mask = 0
881 ModMetaMask = 1
882 ModNumLockMask = 2
883 CODE:
884 switch (ix)
885 {
886 case 0: RETVAL = THIS->ModLevel3Mask; break;
887 case 1: RETVAL = THIS->ModMetaMask; break;
888 case 2: RETVAL = THIS->ModNumLockMask; break;
889 }
890 OUTPUT:
891 RETVAL
892
893U32
894rxvt_term::parent ()
895 CODE:
896 RETVAL = (U32)THIS->parent [0];
897 OUTPUT:
898 RETVAL
899
900U32
438rxvt_term::nsaved () 901rxvt_term::vt ()
439 CODE: 902 CODE:
903 RETVAL = (U32)THIS->vt;
904 OUTPUT:
905 RETVAL
906
907U32
908rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
909 CODE:
910{
440 RETVAL = THIS->nsaved; 911 RETVAL = THIS->rstyle;
912 THIS->rstyle = new_rstyle;
913}
441 OUTPUT: 914 OUTPUT:
442 RETVAL 915 RETVAL
443 916
444int 917int
445rxvt_term::view_start (int newval = -1) 918rxvt_term::view_start (int newval = -1)
446 CODE: 919 CODE:
447{ 920{
454 } 927 }
455} 928}
456 OUTPUT: 929 OUTPUT:
457 RETVAL 930 RETVAL
458 931
459int
460rxvt_term::nrow ()
461 CODE:
462 RETVAL = THIS->nrow;
463 OUTPUT:
464 RETVAL
465
466int
467rxvt_term::ncol ()
468 CODE:
469 RETVAL = THIS->ncol;
470 OUTPUT:
471 RETVAL
472
473void 932void
474rxvt_term::want_refresh () 933rxvt_term::want_refresh ()
475 CODE: 934 CODE:
476 THIS->want_refresh = 1; 935 THIS->want_refresh = 1;
477 936
478void 937void
479rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 938rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
480 PPCODE: 939 PPCODE:
481{ 940{
482 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 941 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
483 croak ("row_number number of out range"); 942 XSRETURN_EMPTY;
484 943
485 line_t &l = ROW(row_number); 944 line_t &l = ROW(row_number);
486 945
487 if (GIMME_V != G_VOID) 946 if (GIMME_V != G_VOID)
488 { 947 {
489 wchar_t *wstr = new wchar_t [THIS->ncol]; 948 wchar_t *wstr = new wchar_t [THIS->ncol];
490 949
491 for (int col = 0; col <THIS->ncol; col++) 950 for (int col = 0; col < THIS->ncol; col++)
492 wstr [col] = l.t [col]; 951 wstr [col] = l.t [col];
493 952
494 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol);
495 free (wstr);
496
497 SV *sv = newSVpv (str, 0);
498 SvUTF8_on (sv);
499 XPUSHs (sv_2mortal (sv)); 953 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
500 free (str); 954
955 delete [] wstr;
501 } 956 }
502 957
503 if (new_text) 958 if (new_text)
504 { 959 {
505 STRLEN slen;
506 char *str = SvPVutf8 (new_text, slen); 960 wchar_t *wstr = sv2wcs (new_text);
507 wchar_t *wstr = rxvt_utf8towcs (str, slen);
508 961
509 int len = wcslen (wstr); 962 int len = min (wcslen (wstr) - start_ofs, max_len);
510 963
511 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 964 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
512 { 965 {
513 free (wstr); 966 free (wstr);
514 croak ("new_text extends beyond horizontal margins"); 967 croak ("new_text extends beyond horizontal margins");
515 } 968 }
516 969
517 for (int col = start_col; col < start_col + len; col++) 970 for (int col = start_col; col < start_col + len; col++)
518 { 971 {
519 l.t [col] = wstr [col - start_col]; 972 l.t [col] = wstr [start_ofs + col - start_col];
520 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 973 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
521 } 974 }
522 975
523 free (wstr); 976 free (wstr);
524 } 977 }
525} 978}
526 979
527void 980void
528rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 981rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
529 PPCODE: 982 PPCODE:
530{ 983{
531 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 984 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
532 croak ("row_number number of out range"); 985 XSRETURN_EMPTY;
533 986
534 line_t &l = ROW(row_number); 987 line_t &l = ROW(row_number);
535 988
536 if (GIMME_V != G_VOID) 989 if (GIMME_V != G_VOID)
537 { 990 {
548 { 1001 {
549 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1002 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
550 croak ("new_rend must be arrayref"); 1003 croak ("new_rend must be arrayref");
551 1004
552 AV *av = (AV *)SvRV (new_rend); 1005 AV *av = (AV *)SvRV (new_rend);
553 int len = av_len (av) + 1; 1006 int len = min (av_len (av) + 1 - start_ofs, max_len);
554 1007
555 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1008 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
556 croak ("new_rend array extends beyond horizontal margins"); 1009 croak ("new_rend array extends beyond horizontal margins");
557 1010
558 for (int col = start_col; col < start_col + len; col++) 1011 for (int col = start_col; col < start_col + len; col++)
559 { 1012 {
560 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1013 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
561 1014
562 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1015 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
563 } 1016 }
564 } 1017 }
565} 1018}
566 1019
567int 1020int
568rxvt_term::ROW_l (int row_number, int new_length = -2) 1021rxvt_term::ROW_l (int row_number, int new_length = -1)
569 CODE: 1022 CODE:
570{ 1023{
571 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1024 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
572 croak ("row_number number of out range"); 1025 XSRETURN_EMPTY;
573 1026
574 line_t &l = ROW(row_number); 1027 line_t &l = ROW(row_number);
575 RETVAL = l.l; 1028 RETVAL = l.l;
576 1029
577 if (new_length >= -1) 1030 if (new_length >= 0)
578 l.l = new_length; 1031 l.l = new_length;
579} 1032}
580 OUTPUT: 1033 OUTPUT:
581 RETVAL 1034 RETVAL
582 1035
1036bool
1037rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1038 CODE:
1039{
1040 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1041 XSRETURN_EMPTY;
1042
1043 line_t &l = ROW(row_number);
1044 RETVAL = l.is_longer ();
1045
1046 if (new_is_longer >= 0)
1047 l.is_longer (new_is_longer);
1048}
1049 OUTPUT:
1050 RETVAL
1051
583SV * 1052SV *
584rxvt_term::special_encode (SV *str) 1053rxvt_term::special_encode (SV *string)
585 CODE: 1054 CODE:
586 abort ();//TODO 1055{
1056 wchar_t *wstr = sv2wcs (string);
1057 int wlen = wcslen (wstr);
1058 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1059
1060 rxvt_push_locale (THIS->locale);
1061
1062 wchar_t *r = rstr;
1063 for (wchar_t *s = wstr; *s; s++)
1064 if (wcwidth (*s) == 0)
1065 {
1066 if (r == rstr)
1067 croak ("leading combining character unencodable");
1068
1069 unicode_t n = rxvt_compose (r[-1], *s);
1070 if (n == NOCHAR)
1071 n = rxvt_composite.compose (r[-1], *s);
1072
1073 r[-1] = n;
1074 }
1075#if !UNICODE_3
1076 else if (*s >= 0x10000)
1077 *r++ = rxvt_composite.compose (*s);
1078#endif
1079 else
1080 *r++ = *s;
1081
1082 rxvt_pop_locale ();
1083
1084 RETVAL = wcs2sv (rstr, r - rstr);
1085
1086 delete [] rstr;
1087}
1088 OUTPUT:
1089 RETVAL
587 1090
588SV * 1091SV *
589rxvt_term::special_decode (SV *str) 1092rxvt_term::special_decode (SV *text)
590 CODE: 1093 CODE:
591 abort ();//TODO 1094{
1095 wchar_t *wstr = sv2wcs (text);
1096 int wlen = wcslen (wstr);
1097 int dlen = 0;
1098
1099 // find length
1100 for (wchar_t *s = wstr; *s; s++)
1101 if (*s == NOCHAR)
1102 ;
1103 else if (IS_COMPOSE (*s))
1104 dlen += rxvt_composite.expand (*s, 0);
1105 else
1106 dlen++;
1107
1108 wchar_t *rstr = new wchar_t [dlen];
1109
1110 // decode
1111 wchar_t *r = rstr;
1112 for (wchar_t *s = wstr; *s; s++)
1113 if (*s == NOCHAR)
1114 ;
1115 else if (IS_COMPOSE (*s))
1116 r += rxvt_composite.expand (*s, r);
1117 else
1118 *r++ = *s;
1119
1120 RETVAL = wcs2sv (rstr, r - rstr);
1121
1122 delete [] rstr;
1123}
1124 OUTPUT:
1125 RETVAL
592 1126
593void 1127void
594rxvt_term::_resource (char *name, int index, SV *newval = 0) 1128rxvt_term::_resource (char *name, int index, SV *newval = 0)
595 PPCODE: 1129 PPCODE:
596{ 1130{
597 struct resval { const char *name; int value; } rslist [] = { 1131 struct resval { const char *name; int value; } rslist [] = {
598# define Rs_def(name) { # name, Rs_ ## name }, 1132# define def(name) { # name, Rs_ ## name },
599# define Rs_reserve(name,count) 1133# define reserve(name,count)
600# include "rsinc.h" 1134# include "rsinc.h"
601# undef Rs_def 1135# undef def
602# undef Rs_reserve 1136# undef reserve
603 }; 1137 };
604 1138
605 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1139 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
606 1140
607 do { 1141 do {
628 else 1162 else
629 THIS->rs [index] = 0; 1163 THIS->rs [index] = 0;
630 } 1164 }
631} 1165}
632 1166
1167bool
1168rxvt_term::option (U32 optval, int set = -1)
1169 CODE:
1170{
1171 RETVAL = THIS->options & optval;
1172
1173 if (set >= 0)
1174 {
1175 if (set)
1176 THIS->options |= optval;
1177 else
1178 THIS->options &= ~optval;
1179
1180 switch (optval)
1181 {
1182 case Opt_skipBuiltinGlyphs:
1183 THIS->set_fonts ();
1184 THIS->scr_remap_chars ();
1185 THIS->scr_touch (true);
1186 THIS->want_refresh = 1;
1187 break;
1188
1189 case Opt_cursorUnderline:
1190 THIS->want_refresh = 1;
1191 break;
1192
1193# case Opt_scrollBar_floating:
1194# case Opt_scrollBar_right:
1195# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1196# break;
1197 }
1198 }
1199}
1200 OUTPUT:
1201 RETVAL
1202
633void 1203void
634rxvt_term::selection_mark (...) 1204rxvt_term::cur (...)
635 PROTOTYPE: $;$$ 1205 PROTOTYPE: $;$$
636 ALIAS: 1206 ALIAS:
1207 screen_cur = 0
637 selection_beg = 1 1208 selection_beg = 1
638 selection_end = 2 1209 selection_end = 2
1210 selection_mark = 3
639 PPCODE: 1211 PPCODE:
640{ 1212{
641 row_col_t &sel = ix == 1 ? THIS->selection.beg 1213 row_col_t &rc = ix == 0 ? THIS->screen.cur
1214 : ix == 1 ? THIS->selection.beg
642 : ix == 2 ? THIS->selection.end 1215 : ix == 2 ? THIS->selection.end
643 : THIS->selection.mark; 1216 : THIS->selection.mark;
644 1217
645 if (GIMME_V != G_VOID) 1218 if (GIMME_V != G_VOID)
646 { 1219 {
647 EXTEND (SP, 2); 1220 EXTEND (SP, 2);
648 PUSHs (sv_2mortal (newSViv (sel.row))); 1221 PUSHs (sv_2mortal (newSViv (rc.row)));
649 PUSHs (sv_2mortal (newSViv (sel.col))); 1222 PUSHs (sv_2mortal (newSViv (rc.col)));
650 } 1223 }
651 1224
652 if (items == 3) 1225 if (items == 3)
653 { 1226 {
654 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1227 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
655 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1228 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
656 1229
657 if (ix) 1230 if (ix)
658 THIS->want_refresh = 1; 1231 THIS->want_refresh = 1;
659 } 1232 }
660} 1233}
661 1234
662int 1235int
663rxvt_term::selection_grab (int eventtime) 1236rxvt_term::selection_grab (U32 eventtime)
664 1237
665void 1238void
666rxvt_term::selection (SV *newtext = 0) 1239rxvt_term::selection (SV *newtext = 0)
667 PPCODE: 1240 PPCODE:
668{ 1241{
669 if (GIMME_V != G_VOID) 1242 if (GIMME_V != G_VOID)
670 { 1243 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)));
671 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len);
672 SV *sv = newSVpv (sel, 0);
673 SvUTF8_on (sv);
674 free (sel);
675 XPUSHs (sv_2mortal (sv));
676 }
677 1244
678 if (newtext) 1245 if (newtext)
679 { 1246 {
680 free (THIS->selection.text); 1247 free (THIS->selection.text);
681 1248
682 THIS->selection.text = sv2wcs (newtext); 1249 THIS->selection.text = sv2wcs (newtext);
683 THIS->selection.len = wcslen (THIS->selection.text); 1250 THIS->selection.len = wcslen (THIS->selection.text);
684 } 1251 }
685} 1252}
686
687void
688rxvt_term::scr_overlay_new (int x, int y, int w, int h)
689 1253
690void 1254void
691rxvt_term::scr_overlay_off () 1255rxvt_term::scr_add_lines (SV *string)
692
693void
694rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE)
695 CODE: 1256 CODE:
696 THIS->scr_overlay_set (x, y, text, rend);
697
698void
699rxvt_term::scr_overlay_set (int x, int y, SV *text)
700 CODE:
701{ 1257{
702 wchar_t *wtext = sv2wcs (text); 1258 wchar_t *wstr = sv2wcs (string);
703 THIS->scr_overlay_set (x, y, wtext); 1259 THIS->scr_add_lines (wstr, wcslen (wstr));
704 free (wtext); 1260 free (wstr);
705} 1261}
706 1262
707void 1263void
708rxvt_term::tt_write (SV *octets) 1264rxvt_term::tt_write (SV *octets)
709 INIT: 1265 INIT:
710 STRLEN len; 1266 STRLEN len;
711 char *str = SvPVbyte (octets, len); 1267 char *str = SvPVbyte (octets, len);
712 C_ARGS: 1268 C_ARGS:
713 (unsigned char *)str, len 1269 str, len
1270
1271void
1272rxvt_term::cmd_parse (SV *octets)
1273 CODE:
1274{
1275 STRLEN len;
1276 char *str = SvPVbyte (octets, len);
1277
1278 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1279 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1280
1281 THIS->cmdbuf_ptr = str;
1282 THIS->cmdbuf_endp = str + len;
1283
1284 rxvt_push_locale (THIS->locale);
1285 THIS->cmd_parse ();
1286 rxvt_pop_locale ();
1287
1288 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1289 THIS->cmdbuf_endp = old_cmdbuf_endp;
1290}
1291
1292SV *
1293rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
1294 CODE:
1295{
1296 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
1297 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
1298 o->self = (HV *)SvRV (RETVAL);
1299}
1300 OUTPUT:
1301 RETVAL
1302
1303MODULE = urxvt PACKAGE = urxvt::overlay
1304
1305void
1306overlay::set (int x, int y, SV *text, SV *rend = 0)
1307
1308void
1309overlay::show ()
1310
1311void
1312overlay::hide ()
1313
1314void
1315overlay::DESTROY ()
714 1316
715MODULE = urxvt PACKAGE = urxvt::timer 1317MODULE = urxvt PACKAGE = urxvt::timer
716 1318
717SV * 1319SV *
718timer::new () 1320timer::new ()
719 CODE: 1321 CODE:
720 timer *w = new timer; 1322 timer *w = new timer;
1323 w->start (NOW);
721 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1324 RETVAL = newSVptr ((void *)w, "urxvt::timer");
722 w->self = (HV *)SvRV (RETVAL); 1325 w->self = (HV *)SvRV (RETVAL);
723 OUTPUT: 1326 OUTPUT:
724 RETVAL 1327 RETVAL
725 1328
733 1336
734NV 1337NV
735timer::at () 1338timer::at ()
736 CODE: 1339 CODE:
737 RETVAL = THIS->at; 1340 RETVAL = THIS->at;
1341 OUTPUT:
1342 RETVAL
1343
1344timer *
1345timer::interval (NV interval)
1346 CODE:
1347 THIS->interval = interval;
1348 RETVAL = THIS;
738 OUTPUT: 1349 OUTPUT:
739 RETVAL 1350 RETVAL
740 1351
741timer * 1352timer *
742timer::set (NV tstamp) 1353timer::set (NV tstamp)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines