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.74 by root, Wed Jan 18 10:31:37 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines