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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines