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