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