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.8 by root, Tue Jan 3 00:06:57 2006 UTC vs.
Revision 1.17 by root, Tue Jan 3 18:11:34 2006 UTC

139#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 139#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
140#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 140#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
141 141
142struct timer : time_watcher, perl_watcher 142struct timer : time_watcher, perl_watcher
143{ 143{
144 tstamp interval;
145
144 timer () 146 timer ()
145 : time_watcher (this, &timer::execute) 147 : time_watcher (this, &timer::execute)
146 { 148 {
147 } 149 }
148 150
149 void execute (time_watcher &w) 151 void execute (time_watcher &w)
150 { 152 {
153 if (interval)
154 start (at + interval);
155
151 invoke ("urxvt::timer", newSVtimer (this)); 156 invoke ("urxvt::timer", newSVtimer (this));
152 } 157 }
153}; 158};
154 159
155#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 160#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
165 void execute (io_watcher &w, short revents) 170 void execute (io_watcher &w, short revents)
166 { 171 {
167 invoke ("urxvt::iow", newSViow (this), revents); 172 invoke ("urxvt::iow", newSViow (this), revents);
168 } 173 }
169}; 174};
175
176/////////////////////////////////////////////////////////////////////////////
177
178#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
179
180struct overlay {
181 HV *self;
182 rxvt_term *THIS;
183 int x, y, w, h;
184 int border;
185 text_t **text;
186 rend_t **rend;
187
188 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
189 ~overlay ();
190
191 void swap ();
192
193 void set (int x, int y, SV *str, SV *rend);
194};
195
196overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
197: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
198{
199 if (border == 2)
200 {
201 w += 2;
202 h += 2;
203 }
204
205 text = new text_t *[h];
206 rend = new rend_t *[h];
207
208 for (int y = 0; y < h; y++)
209 {
210 text_t *tp = text[y] = new text_t[w];
211 rend_t *rp = rend[y] = new rend_t[w];
212
213 text_t t0, t1, t2;
214 rend_t r = rstyle;
215
216 if (border == 2)
217 {
218 if (y == 0)
219 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
220 else if (y < h - 1)
221 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
222 else
223 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
224
225 *tp++ = t0;
226 *rp++ = r;
227
228 for (int x = w - 2; x-- > 0; )
229 {
230 *tp++ = t1;
231 *rp++ = r;
232 }
233
234 *tp = t2;
235 *rp = r;
236 }
237 else
238 for (int x = w; x-- > 0; )
239 {
240 *tp++ = 0x0020;
241 *rp++ = r;
242 }
243 }
244
245 THIS->want_refresh = 1;
246}
247
248overlay::~overlay ()
249{
250 for (int y = h; y--; )
251 {
252 delete [] text[y];
253 delete [] rend[y];
254 }
255
256 delete [] text;
257 delete [] rend;
258
259 THIS->want_refresh = 1;
260}
261
262void overlay::swap ()
263{
264 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
265 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
266
267 int ov_w = min (w, THIS->ncol - ov_x);
268 int ov_h = min (h, THIS->nrow - ov_y);
269
270 for (int y = ov_h; y--; )
271 {
272 text_t *t1 = text [y];
273 rend_t *r1 = rend [y];
274
275 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
276 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
277
278 for (int x = ov_w; x--; )
279 {
280 text_t t = *t1; *t1++ = *t2; *t2++ = t;
281 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
282 }
283 }
284
285}
286
287void overlay::set (int x, int y, SV *text, SV *rend)
288{
289 x += border;
290 y += border;
291
292 if (!IN_RANGE_EXC (y, 0, h - border))
293 return;
294
295 wchar_t *wtext = sv2wcs (text);
296
297 for (int col = min (wcslen (wtext), w - x - border); col--; )
298 this->text [y][x + col] = wtext [col];
299
300 free (wtext);
301
302 if (rend)
303 {
304 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
305 croak ("rend must be arrayref");
306
307 AV *av = (AV *)SvRV (rend);
308
309 for (int col = min (av_len (av) + 1, w - x - border); col--; )
310 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
311 }
312
313 THIS->want_refresh = 1;
314}
315
170 316
171///////////////////////////////////////////////////////////////////////////// 317/////////////////////////////////////////////////////////////////////////////
172 318
173struct rxvt_perl_interp rxvt_perl; 319struct rxvt_perl_interp rxvt_perl;
174 320
213} 359}
214 360
215bool 361bool
216rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 362rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
217{ 363{
218 if (!perl 364 if (!perl)
219 || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY))
220 return false; 365 return false;
221 366
222 if (htype == HOOK_INIT) // first hook ever called 367 if (htype == HOOK_INIT) // first hook ever called
368 {
223 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 369 term->self = (void *)newSVptr ((void *)term, "urxvt::term");
370 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
371 }
372 else if (!term->self)
373 return false; // perl not initialized for this instance
374 else if (htype == HOOK_DESTROY)
375 {
376 // handled later
377 }
378 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
379 {
380 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0));
381
382 if (HvKEYS (hv))
383 {
384 hv_iterinit (hv);
385
386 while (HE *he = hv_iternext (hv))
387 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
388 }
389 }
390 else if (!should_invoke [htype])
391 return false;
224 392
225 dSP; 393 dSP;
226 va_list ap; 394 va_list ap;
227 395
228 va_start (ap, htype); 396 va_start (ap, htype);
296PROTOTYPES: ENABLE 464PROTOTYPES: ENABLE
297 465
298BOOT: 466BOOT:
299{ 467{
300# define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) 468# define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0))
469# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name));
301 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 470 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
302 set_hookname (INIT); 471 set_hookname (INIT);
303 set_hookname (RESET); 472 set_hookname (RESET);
304 set_hookname (START); 473 set_hookname (START);
305 set_hookname (DESTROY); 474 set_hookname (DESTROY);
314 set_hookname (TTY_ACTIVITY); 483 set_hookname (TTY_ACTIVITY);
315 set_hookname (REFRESH_BEGIN); 484 set_hookname (REFRESH_BEGIN);
316 set_hookname (REFRESH_END); 485 set_hookname (REFRESH_END);
317 set_hookname (KEYBOARD_COMMAND); 486 set_hookname (KEYBOARD_COMMAND);
318 487
488 export_const (DEFAULT_RSTYLE);
489 export_const (OVERLAY_RSTYLE);
490 export_const (RS_Bold);
491 export_const (RS_Italic);
492 export_const (RS_Blink);
493 export_const (RS_RVid);
494 export_const (RS_Uline);
495
319 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 496 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR);
320} 497}
321 498
322void 499void
323set_should_invoke (int htype, int value) 500set_should_invoke (int htype, int value)
337NV 514NV
338NOW () 515NOW ()
339 CODE: 516 CODE:
340 RETVAL = NOW; 517 RETVAL = NOW;
341 OUTPUT: 518 OUTPUT:
519 RETVAL
520
521int
522GET_BASEFG (int rend)
523 CODE:
524 RETVAL = GET_BASEFG (rend);
525 OUTPUT:
526 RETVAL
527
528int
529GET_BASEBG (int rend)
530 CODE:
531 RETVAL = GET_BASEBG (rend);
532 OUTPUT:
533 RETVAL
534
535int
536SET_FGCOLOR (int rend, int new_color)
537 CODE:
538 RETVAL = SET_FGCOLOR (rend, new_color);
539 OUTPUT:
540 RETVAL
541
542int
543SET_BGCOLOR (int rend, int new_color)
544 CODE:
545 RETVAL = SET_BGCOLOR (rend, new_color);
546 OUTPUT:
547 RETVAL
548
549int
550GET_CUSTOM (int rend)
551 CODE:
552 RETVAL = (rend && RS_customMask) >> RS_customShift;
553 OUTPUT:
554 RETVAL
555
556int
557SET_CUSTOM (int rend, int new_value)
558 CODE:
559{
560 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
561 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
562
563 RETVAL = (rend & ~RS_customMask)
564 | ((new_value << RS_customShift) & RS_customMask);
565}
566 OUTPUT:
342 RETVAL 567 RETVAL
343 568
344MODULE = urxvt PACKAGE = urxvt::term 569MODULE = urxvt PACKAGE = urxvt::term
345 570
346int 571int
430rxvt_term::ncol () 655rxvt_term::ncol ()
431 CODE: 656 CODE:
432 RETVAL = THIS->ncol; 657 RETVAL = THIS->ncol;
433 OUTPUT: 658 OUTPUT:
434 RETVAL 659 RETVAL
660
661void
662rxvt_term::want_refresh ()
663 CODE:
664 THIS->want_refresh = 1;
435 665
436void 666void
437rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 667rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0)
438 PPCODE: 668 PPCODE:
439{ 669{
458 free (str); 688 free (str);
459 } 689 }
460 690
461 if (new_text) 691 if (new_text)
462 { 692 {
463 STRLEN slen;
464 char *str = SvPVutf8 (new_text, slen); 693 wchar_t *wstr = sv2wcs (new_text);
465 wchar_t *wstr = rxvt_utf8towcs (str, slen);
466 694
467 int len = wcslen (wstr); 695 int len = wcslen (wstr);
468 696
469 if (start_col + len > THIS->ncol) 697 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
470 { 698 {
471 free (wstr); 699 free (wstr);
472 croak ("new_text extends beyond right margin"); 700 croak ("new_text extends beyond horizontal margins");
473 } 701 }
474 702
475 for (int col = start_col; col < start_col + len; col++) 703 for (int col = start_col; col < start_col + len; col++)
476 { 704 {
477 l.t [col] = wstr [col]; 705 l.t [col] = wstr [col - start_col];
478 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 706 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
479 } 707 }
708
709 free (wstr);
480 } 710 }
481} 711}
482 712
483void 713void
484rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 714rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0)
506 croak ("new_rend must be arrayref"); 736 croak ("new_rend must be arrayref");
507 737
508 AV *av = (AV *)SvRV (new_rend); 738 AV *av = (AV *)SvRV (new_rend);
509 int len = av_len (av) + 1; 739 int len = av_len (av) + 1;
510 740
511 if (start_col + len > THIS->ncol) 741 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
512 croak ("new_rend array extends beyond right margin"); 742 croak ("new_rend array extends beyond horizontal margins");
513 743
514 for (int col = start_col; col < start_col + len; col++) 744 for (int col = start_col; col < start_col + len; col++)
515 { 745 {
516 rend_t r = SvIV (*av_fetch (av, col, 1)) & ~RS_fontMask; 746 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask;
517 747
518 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 748 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
519 } 749 }
520 } 750 }
521} 751}
614 THIS->want_refresh = 1; 844 THIS->want_refresh = 1;
615 } 845 }
616} 846}
617 847
618int 848int
619rxvt_term::selection_grab (int eventtime) 849rxvt_term::selection_grab (int eventtime = CurrentTime)
620 850
621void 851void
622rxvt_term::selection (SV *newtext = 0) 852rxvt_term::selection (SV *newtext = 0)
623 PPCODE: 853 PPCODE:
624{ 854{
638 THIS->selection.text = sv2wcs (newtext); 868 THIS->selection.text = sv2wcs (newtext);
639 THIS->selection.len = wcslen (THIS->selection.text); 869 THIS->selection.len = wcslen (THIS->selection.text);
640 } 870 }
641} 871}
642 872
643void
644rxvt_term::scr_overlay_new (int x, int y, int w, int h)
645
646void
647rxvt_term::scr_overlay_off ()
648
649void
650rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE)
651 CODE:
652 THIS->scr_overlay_set (x, y, text, rend);
653
654void
655rxvt_term::scr_overlay_set (int x, int y, SV *text)
656 CODE:
657{
658 wchar_t *wtext = sv2wcs (text);
659 THIS->scr_overlay_set (x, y, wtext);
660 free (wtext);
661}
662
663void 873void
664rxvt_term::tt_write (SV *octets) 874rxvt_term::tt_write (SV *octets)
665 INIT: 875 INIT:
666 STRLEN len; 876 STRLEN len;
667 char *str = SvPVbyte (octets, len); 877 char *str = SvPVbyte (octets, len);
668 C_ARGS: 878 C_ARGS:
669 (unsigned char *)str, len 879 (unsigned char *)str, len
670 880
881SV *
882rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
883 CODE:
884{
885 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
886 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
887 o->self = (HV *)SvRV (RETVAL);
888
889 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0));
890 char key[33]; sprintf (key, "%32lx", (long)o);
891 hv_store (hv, key, 32, newSViv ((long)o), 0);
892}
893 OUTPUT:
894 RETVAL
895
896MODULE = urxvt PACKAGE = urxvt::overlay
897
898void
899overlay::set (int x, int y, SV *text, SV *rend = 0)
900
901void
902overlay::DESTROY ()
903 CODE:
904{
905 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0);
906 if (ovs)
907 {
908 HV *hv = (HV *)SvRV (*ovs);
909 char key[33]; sprintf (key, "%32lx", (long)THIS);
910 hv_delete (hv, key, 32, G_DISCARD);
911 }
912
913 delete THIS;
914}
915
671MODULE = urxvt PACKAGE = urxvt::timer 916MODULE = urxvt PACKAGE = urxvt::timer
672 917
673SV * 918SV *
674timer::new () 919timer::new ()
675 CODE: 920 CODE:
676 timer *w = new timer; 921 timer *w = new timer;
922 w->start (NOW);
677 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 923 RETVAL = newSVptr ((void *)w, "urxvt::timer");
678 w->self = (HV *)SvRV (RETVAL); 924 w->self = (HV *)SvRV (RETVAL);
679 OUTPUT: 925 OUTPUT:
680 RETVAL 926 RETVAL
681 927
689 935
690NV 936NV
691timer::at () 937timer::at ()
692 CODE: 938 CODE:
693 RETVAL = THIS->at; 939 RETVAL = THIS->at;
940 OUTPUT:
941 RETVAL
942
943timer *
944timer::interval (NV interval)
945 CODE:
946 THIS->interval = interval;
947 RETVAL = THIS;
694 OUTPUT: 948 OUTPUT:
695 RETVAL 949 RETVAL
696 950
697timer * 951timer *
698timer::set (NV tstamp) 952timer::set (NV tstamp)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines