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.3 by root, Mon Jan 2 18:20:23 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
47#undef LINENO
48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
49#undef ROW
50#define ROW(n) THIS->row_buf [LINENO (n)]
51
40///////////////////////////////////////////////////////////////////////////// 52/////////////////////////////////////////////////////////////////////////////
41 53
42static wchar_t * 54static wchar_t *
43sv2wcs (SV *sv) 55sv2wcs (SV *sv)
44{ 56{
46 char *str = SvPVutf8 (sv, len); 58 char *str = SvPVutf8 (sv, len);
47 return rxvt_utf8towcs (str, len); 59 return rxvt_utf8towcs (str, len);
48} 60}
49 61
50static 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 *
51new_ref (HV *hv, const char *klass) 75new_ref (HV *hv, const char *klass)
52{ 76{
53 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 77 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
54} 78}
55 79
56//TODO: use magic 80//TODO: use magic
57static SV * 81static SV *
58newSVptr (void *ptr, const char *klass) 82newSVptr (void *ptr, const char *klass)
59{ 83{
60 HV *hv = newHV (); 84 HV *hv = newHV ();
61 hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); 85 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
62 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);
63} 97}
64 98
65static long 99static long
66SvPTR (SV *sv, const char *klass) 100SvPTR (SV *sv, const char *klass)
67{ 101{
68 if (!sv_derived_from (sv, klass)) 102 if (!sv_derived_from (sv, klass))
69 croak ("object of type %s expected", klass); 103 croak ("object of type %s expected", klass);
70 104
71 IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); 105 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
72 106
73 if (!iv) 107 if (!mg)
74 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);
75 109
76 return (long)iv; 110 return (long)mg->mg_ptr;
77} 111}
78 112
79#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 113#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
80#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 114#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
81 115
82///////////////////////////////////////////////////////////////////////////// 116/////////////////////////////////////////////////////////////////////////////
83 117
84struct perl_watcher 118struct perl_watcher
134#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 168#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
135#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 169#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
136 170
137struct timer : time_watcher, perl_watcher 171struct timer : time_watcher, perl_watcher
138{ 172{
173 tstamp interval;
174
139 timer () 175 timer ()
140 : time_watcher (this, &timer::execute) 176 : time_watcher (this, &timer::execute)
141 { 177 {
142 } 178 }
143 179
144 void execute (time_watcher &w) 180 void execute (time_watcher &w)
145 { 181 {
182 if (interval)
183 start (at + interval);
184
146 invoke ("urxvt::timer", newSVtimer (this)); 185 invoke ("urxvt::timer", newSVtimer (this));
147 } 186 }
148}; 187};
149 188
150#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 189#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
160 void execute (io_watcher &w, short revents) 199 void execute (io_watcher &w, short revents)
161 { 200 {
162 invoke ("urxvt::iow", newSViow (this), revents); 201 invoke ("urxvt::iow", newSViow (this), revents);
163 } 202 }
164}; 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
165 374
166///////////////////////////////////////////////////////////////////////////// 375/////////////////////////////////////////////////////////////////////////////
167 376
168struct rxvt_perl_interp rxvt_perl; 377struct rxvt_perl_interp rxvt_perl;
169 378
212{ 421{
213 if (!perl) 422 if (!perl)
214 return false; 423 return false;
215 424
216 if (htype == HOOK_INIT) // first hook ever called 425 if (htype == HOOK_INIT) // first hook ever called
426 {
217 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
218 else if (htype == HOOK_DESTROY) 432 else if (htype == HOOK_DESTROY)
219 { 433 {
220 // TODO: clear magic 434 // handled later
221 hv_clear ((HV *)SvRV ((SV *)term->self));
222 SvREFCNT_dec ((SV *)term->self);
223 } 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));
224 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 }
225 if (!should_invoke [htype]) 448 else if (!should_invoke [htype])
226 return false; 449 return false;
227 450
228 dSP; 451 dSP;
229 va_list ap; 452 va_list ap;
230 453
231 va_start (ap, htype); 454 va_start (ap, htype);
232 455
249 472
250 case DT_LONG: 473 case DT_LONG:
251 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 474 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
252 break; 475 break;
253 476
477 case DT_STR:
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 }
549 break;
550
254 case DT_END: 551 case DT_END:
255 { 552 {
256 va_end (ap); 553 va_end (ap);
257 554
258 PUTBACK; 555 PUTBACK;
270 LEAVE; 567 LEAVE;
271 568
272 if (SvTRUE (ERRSV)) 569 if (SvTRUE (ERRSV))
273 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));
274 571
572 if (htype == HOOK_DESTROY)
573 {
574 clearSVptr ((SV *)term->perl.self);
575 SvREFCNT_dec ((SV *)term->perl.self);
576 }
577
275 return count; 578 return count;
276 } 579 }
277 580
278 default: 581 default:
279 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 582 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
287 590
288PROTOTYPES: ENABLE 591PROTOTYPES: ENABLE
289 592
290BOOT: 593BOOT:
291{ 594{
292# 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));
596
293 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 597 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
294 set_hookname (LOAD); 598# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
295 set_hookname (INIT); 599# include "hookinc.h"
296 set_hookname (RESET); 600# undef def
297 set_hookname (START);
298 set_hookname (DESTROY);
299 set_hookname (SEL_BEGIN);
300 set_hookname (SEL_EXTEND);
301 set_hookname (SEL_MAKE);
302 set_hookname (SEL_GRAB);
303 set_hookname (FOCUS_IN);
304 set_hookname (FOCUS_OUT);
305 set_hookname (VIEW_CHANGE);
306 set_hookname (SCROLL_BACK);
307 set_hookname (TTY_ACTIVITY);
308 set_hookname (REFRESH_BEGIN);
309 set_hookname (REFRESH_END);
310 601
311 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 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));
611 export_const_iv (DEFAULT_RSTYLE);
612 export_const_iv (OVERLAY_RSTYLE);
613 export_const_iv (RS_Bold);
614 export_const_iv (RS_Italic);
615 export_const_iv (RS_Blink);
616 export_const_iv (RS_RVid);
617 export_const_iv (RS_Uline);
618
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);
312} 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
313 665
314void 666void
315set_should_invoke (int htype, int value) 667set_should_invoke (int htype, int value)
316 CODE: 668 CODE:
317 rxvt_perl.should_invoke [htype] = value; 669 rxvt_perl.should_invoke [htype] = value;
331 CODE: 683 CODE:
332 RETVAL = NOW; 684 RETVAL = NOW;
333 OUTPUT: 685 OUTPUT:
334 RETVAL 686 RETVAL
335 687
688int
689GET_BASEFG (int rend)
690 CODE:
691 RETVAL = GET_BASEFG (rend);
692 OUTPUT:
693 RETVAL
694
695int
696GET_BASEBG (int rend)
697 CODE:
698 RETVAL = GET_BASEBG (rend);
699 OUTPUT:
700 RETVAL
701
702int
703SET_FGCOLOR (int rend, int new_color)
704 CODE:
705 RETVAL = SET_FGCOLOR (rend, new_color);
706 OUTPUT:
707 RETVAL
708
709int
710SET_BGCOLOR (int rend, int new_color)
711 CODE:
712 RETVAL = SET_BGCOLOR (rend, new_color);
713 OUTPUT:
714 RETVAL
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
336MODULE = 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);
337 791
338int 792int
339rxvt_term::strwidth (SV *str) 793rxvt_term::strwidth (SV *str)
340 CODE: 794 CODE:
341{ 795{
377 831
378 rxvt_push_locale (THIS->locale); 832 rxvt_push_locale (THIS->locale);
379 wchar_t *wstr = rxvt_mbstowcs (data, len); 833 wchar_t *wstr = rxvt_mbstowcs (data, len);
380 rxvt_pop_locale (); 834 rxvt_pop_locale ();
381 835
382 char *str = rxvt_wcstoutf8 (wstr); 836 RETVAL = wcs2sv (wstr);
383 free (wstr); 837 free (wstr);
838}
839 OUTPUT:
840 RETVAL
384 841
385 RETVAL = newSVpv (str, 0); 842#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
386 SvUTF8_on (RETVAL); 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
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
901rxvt_term::vt ()
902 CODE:
903 RETVAL = (U32)THIS->vt;
904 OUTPUT:
905 RETVAL
906
907U32
908rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
909 CODE:
910{
911 RETVAL = THIS->rstyle;
912 THIS->rstyle = new_rstyle;
913}
914 OUTPUT:
915 RETVAL
916
917int
918rxvt_term::view_start (int newval = -1)
919 CODE:
920{
921 RETVAL = THIS->view_start;
922
923 if (newval >= 0)
924 {
925 THIS->view_start = min (newval, THIS->nsaved);
926 THIS->scr_changeview (RETVAL);
927 }
928}
929 OUTPUT:
930 RETVAL
931
932void
933rxvt_term::want_refresh ()
934 CODE:
935 THIS->want_refresh = 1;
936
937void
938rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
939 PPCODE:
940{
941 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
942 XSRETURN_EMPTY;
943
944 line_t &l = ROW(row_number);
945
946 if (GIMME_V != G_VOID)
947 {
948 wchar_t *wstr = new wchar_t [THIS->ncol];
949
950 for (int col = 0; col < THIS->ncol; col++)
951 wstr [col] = l.t [col];
952
953 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
954
955 delete [] wstr;
956 }
957
958 if (new_text)
959 {
960 wchar_t *wstr = sv2wcs (new_text);
961
962 int len = min (wcslen (wstr) - start_ofs, max_len);
963
964 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
965 {
966 free (wstr);
967 croak ("new_text extends beyond horizontal margins");
968 }
969
970 for (int col = start_col; col < start_col + len; col++)
971 {
972 l.t [col] = wstr [start_ofs + col - start_col];
973 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
974 }
975
387 free (str); 976 free (wstr);
977 }
978}
979
980void
981rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
982 PPCODE:
983{
984 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
985 XSRETURN_EMPTY;
986
987 line_t &l = ROW(row_number);
988
989 if (GIMME_V != G_VOID)
990 {
991 AV *av = newAV ();
992
993 av_extend (av, THIS->ncol - 1);
994 for (int col = 0; col < THIS->ncol; col++)
995 av_store (av, col, newSViv (l.r [col]));
996
997 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
998 }
999
1000 if (new_rend)
1001 {
1002 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1003 croak ("new_rend must be arrayref");
1004
1005 AV *av = (AV *)SvRV (new_rend);
1006 int len = min (av_len (av) + 1 - start_ofs, max_len);
1007
1008 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1009 croak ("new_rend array extends beyond horizontal margins");
1010
1011 for (int col = start_col; col < start_col + len; col++)
1012 {
1013 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1014
1015 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
1016 }
1017 }
1018}
1019
1020int
1021rxvt_term::ROW_l (int row_number, int new_length = -1)
1022 CODE:
1023{
1024 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1025 XSRETURN_EMPTY;
1026
1027 line_t &l = ROW(row_number);
1028 RETVAL = l.l;
1029
1030 if (new_length >= 0)
1031 l.l = new_length;
1032}
1033 OUTPUT:
1034 RETVAL
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
1052SV *
1053rxvt_term::special_encode (SV *string)
1054 CODE:
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
1090
1091SV *
1092rxvt_term::special_decode (SV *text)
1093 CODE:
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;
388} 1123}
389 OUTPUT: 1124 OUTPUT:
390 RETVAL 1125 RETVAL
391 1126
392void 1127void
393rxvt_term::_resource (char *name, int index, SV *newval = 0) 1128rxvt_term::_resource (char *name, int index, SV *newval = 0)
394 PPCODE: 1129 PPCODE:
395{ 1130{
396 struct resval { const char *name; int value; } rslist [] = { 1131 struct resval { const char *name; int value; } rslist [] = {
397# define Rs_def(name) { # name, Rs_ ## name }, 1132# define def(name) { # name, Rs_ ## name },
398# define Rs_reserve(name,count) 1133# define reserve(name,count)
399# include "rsinc.h" 1134# include "rsinc.h"
400# undef Rs_def 1135# undef def
401# undef Rs_reserve 1136# undef reserve
402 }; 1137 };
403 1138
404 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1139 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
405 1140
406 do { 1141 do {
427 else 1162 else
428 THIS->rs [index] = 0; 1163 THIS->rs [index] = 0;
429 } 1164 }
430} 1165}
431 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
432void 1203void
433rxvt_term::selection_mark (...) 1204rxvt_term::cur (...)
434 PROTOTYPE: $;$$ 1205 PROTOTYPE: $;$$
435 ALIAS: 1206 ALIAS:
1207 screen_cur = 0
436 selection_beg = 1 1208 selection_beg = 1
437 selection_end = 2 1209 selection_end = 2
1210 selection_mark = 3
438 PPCODE: 1211 PPCODE:
439{ 1212{
440 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
441 : ix == 2 ? THIS->selection.end 1215 : ix == 2 ? THIS->selection.end
442 : THIS->selection.mark; 1216 : THIS->selection.mark;
443 1217
444 if (GIMME_V != G_VOID) 1218 if (GIMME_V != G_VOID)
445 { 1219 {
446 EXTEND (SP, 2); 1220 EXTEND (SP, 2);
447 PUSHs (sv_2mortal (newSViv (sel.row))); 1221 PUSHs (sv_2mortal (newSViv (rc.row)));
448 PUSHs (sv_2mortal (newSViv (sel.col))); 1222 PUSHs (sv_2mortal (newSViv (rc.col)));
449 } 1223 }
450 1224
451 if (items == 3) 1225 if (items == 3)
452 { 1226 {
453 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1227 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
454 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1228 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
455 1229
456 if (ix) 1230 if (ix)
457 THIS->want_refresh = 1; 1231 THIS->want_refresh = 1;
458 } 1232 }
459} 1233}
460 1234
461int 1235int
462rxvt_term::selection_grab (int eventtime) 1236rxvt_term::selection_grab (U32 eventtime)
463 1237
464void 1238void
465rxvt_term::selection (SV *newtext = 0) 1239rxvt_term::selection (SV *newtext = 0)
466 PPCODE: 1240 PPCODE:
467{ 1241{
468 if (GIMME_V != G_VOID) 1242 if (GIMME_V != G_VOID)
469 { 1243 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)));
470 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len);
471 SV *sv = newSVpv (sel, 0);
472 SvUTF8_on (sv);
473 free (sel);
474 XPUSHs (sv_2mortal (sv));
475 }
476 1244
477 if (newtext) 1245 if (newtext)
478 { 1246 {
479 free (THIS->selection.text); 1247 free (THIS->selection.text);
480 1248
481 THIS->selection.text = sv2wcs (newtext); 1249 THIS->selection.text = sv2wcs (newtext);
482 THIS->selection.len = wcslen (THIS->selection.text); 1250 THIS->selection.len = wcslen (THIS->selection.text);
483 } 1251 }
484} 1252}
485
486void
487rxvt_term::scr_overlay_new (int x, int y, int w, int h)
488 1253
489void 1254void
490rxvt_term::scr_overlay_off () 1255rxvt_term::scr_add_lines (SV *string)
491
492void
493rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE)
494 CODE: 1256 CODE:
495 THIS->scr_overlay_set (x, y, text, rend);
496
497void
498rxvt_term::scr_overlay_set (int x, int y, SV *text)
499 CODE:
500{ 1257{
501 wchar_t *wtext = sv2wcs (text); 1258 wchar_t *wstr = sv2wcs (string);
502 THIS->scr_overlay_set (x, y, wtext); 1259 THIS->scr_add_lines (wstr, wcslen (wstr));
503 free (wtext); 1260 free (wstr);
504} 1261}
505 1262
506void 1263void
507rxvt_term::tt_write (SV *octets) 1264rxvt_term::tt_write (SV *octets)
508 INIT: 1265 INIT:
509 STRLEN len; 1266 STRLEN len;
510 char *str = SvPVbyte (octets, len); 1267 char *str = SvPVbyte (octets, len);
511 C_ARGS: 1268 C_ARGS:
512 (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 ()
513 1316
514MODULE = urxvt PACKAGE = urxvt::timer 1317MODULE = urxvt PACKAGE = urxvt::timer
515 1318
516SV * 1319SV *
517timer::new () 1320timer::new ()
518 CODE: 1321 CODE:
519 timer *w = new timer; 1322 timer *w = new timer;
1323 w->start (NOW);
520 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1324 RETVAL = newSVptr ((void *)w, "urxvt::timer");
521 w->self = (HV *)SvRV (RETVAL); 1325 w->self = (HV *)SvRV (RETVAL);
522 OUTPUT: 1326 OUTPUT:
523 RETVAL 1327 RETVAL
524 1328
532 1336
533NV 1337NV
534timer::at () 1338timer::at ()
535 CODE: 1339 CODE:
536 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;
537 OUTPUT: 1349 OUTPUT:
538 RETVAL 1350 RETVAL
539 1351
540timer * 1352timer *
541timer::set (NV tstamp) 1353timer::set (NV tstamp)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines