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

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.84 by root, Fri Jan 20 18:50:49 2006 UTC vs.
Revision 1.94 by root, Thu Jan 26 00:09:47 2006 UTC

244 244
245///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
246 246
247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
248 248
249struct overlay { 249class overlay {
250 HV *self;
251 bool visible;
252 rxvt_term *THIS; 250 rxvt_term *THIS;
251 AV *overlay_av;
253 int x, y, w, h; 252 int x, y, w, h;
254 int border; 253 int border;
255 text_t **text; 254 text_t **text;
256 rend_t **rend; 255 rend_t **rend;
257 256
257public:
258 HV *self;
259
258 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 260 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
259 ~overlay (); 261 ~overlay ();
260 262
261 void show (); 263 void show ();
262 void hide (); 264 void hide ();
265 267
266 void set (int x, int y, SV *str, SV *rend); 268 void set (int x, int y, SV *str, SV *rend);
267}; 269};
268 270
269overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 271overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
270: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false) 272: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
271{ 273{
272 if (border == 2) 274 if (border == 2)
273 { 275 {
274 w += 2; 276 w += 2;
275 h += 2; 277 h += 2;
314 *rp++ = r; 316 *rp++ = r;
315 } 317 }
316 } 318 }
317 319
318 show (); 320 show ();
319 THIS->want_refresh = 1;
320} 321}
321 322
322overlay::~overlay () 323overlay::~overlay ()
323{ 324{
324 hide (); 325 hide ();
329 delete [] rend[y]; 330 delete [] rend[y];
330 } 331 }
331 332
332 delete [] text; 333 delete [] text;
333 delete [] rend; 334 delete [] rend;
335}
336
337void
338overlay::show ()
339{
340 if (overlay_av)
341 return;
342
343 overlay_av = (AV *)SvREFCNT_inc (SvRV (
344 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
345 ));
346 av_push (overlay_av, newSViv ((long)this));
334 347
335 THIS->want_refresh = 1; 348 THIS->want_refresh = 1;
336} 349}
337 350
338void 351void
339overlay::show () 352overlay::hide ()
340{ 353{
341 if (visible) 354 if (!overlay_av)
342 return; 355 return;
343 356
344 visible = true;
345
346 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
347 av_push (av, newSViv ((long)this));
348}
349
350void
351overlay::hide ()
352{
353 if (!visible)
354 return;
355
356 visible = false;
357
358 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
359
360 int i; 357 int i;
361 358
362 for (i = AvFILL (av); i >= 0; i--) 359 for (i = AvFILL (overlay_av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 360 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
364 { 361 {
365 av_delete (av, i, G_DISCARD); 362 av_delete (overlay_av, i, G_DISCARD);
366 break; 363 break;
367 } 364 }
368 365
369 for (; i < AvFILL (av); i++) 366 for (; i < AvFILL (overlay_av); i++)
370 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); 367 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
371 368
372 av_pop (av); 369 av_pop (overlay_av);
370
371 SvREFCNT_dec (overlay_av);
372 overlay_av = 0;
373
374 THIS->want_refresh = 1;
373} 375}
374 376
375void overlay::swap () 377void overlay::swap ()
376{ 378{
377 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 379 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
554 break; 556 break;
555 557
556 case DT_STR_LEN: 558 case DT_STR_LEN:
557 { 559 {
558 char *str = va_arg (ap, char *); 560 char *str = va_arg (ap, char *);
559 int len = va_arg (ap, int); 561 int len = va_arg (ap, int);
560 562
561 XPUSHs (sv_2mortal (newSVpvn (str, len))); 563 XPUSHs (sv_2mortal (newSVpvn (str, len)));
562 } 564 }
563 break; 565 break;
564 566
565 case DT_WCS_LEN: 567 case DT_WCS_LEN:
566 { 568 {
567 wchar_t *wstr = va_arg (ap, wchar_t *); 569 wchar_t *wstr = va_arg (ap, wchar_t *);
568 int wlen = va_arg (ap, int); 570 int wlen = va_arg (ap, int);
569 571
570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 572 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
573 }
574 break;
575
576 case DT_LCS_LEN:
577 {
578 long *lstr = va_arg (ap, long *);
579 int llen = va_arg (ap, int);
580
581 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
571 } 582 }
572 break; 583 break;
573 584
574 case DT_XEVENT: 585 case DT_XEVENT:
575 { 586 {
576 XEvent *xe = va_arg (ap, XEvent *); 587 XEvent *xe = va_arg (ap, XEvent *);
577 HV *hv = newHV (); 588 HV *hv = newHV ();
578 589
579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 590# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
580# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 591# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
581# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 592# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
582# undef set 593# undef set
583 594
584 setiv (type, xe->type); 595 setiv (type, xe->type);
585 setiv (send_event, xe->xany.send_event); 596 setiv (send_event, xe->xany.send_event);
586 setiv (serial, xe->xany.serial); 597 setiv (serial, xe->xany.serial);
587 598
596 setuv (root, xe->xmotion.root); 607 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow); 608 setuv (subwindow, xe->xmotion.subwindow);
598 setuv (time, xe->xmotion.time); 609 setuv (time, xe->xmotion.time);
599 setiv (x, xe->xmotion.x); 610 setiv (x, xe->xmotion.x);
600 setiv (y, xe->xmotion.y); 611 setiv (y, xe->xmotion.y);
601 setiv (row, xe->xmotion.y / term->fheight); 612 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
602 setiv (col, xe->xmotion.x / term->fwidth); 613 setiv (col, xe->xmotion.x / term->fwidth);
603 setiv (x_root, xe->xmotion.x_root); 614 setiv (x_root, xe->xmotion.x_root);
604 setiv (y_root, xe->xmotion.y_root); 615 setiv (y_root, xe->xmotion.y_root);
605 setuv (state, xe->xmotion.state); 616 setuv (state, xe->xmotion.state);
606 617
716 } 727 }
717 else if (htype == HOOK_DESTROY) 728 else if (htype == HOOK_DESTROY)
718 { 729 {
719 clearSVptr ((SV *)term->perl.self); 730 clearSVptr ((SV *)term->perl.self);
720 SvREFCNT_dec ((SV *)term->perl.self); 731 SvREFCNT_dec ((SV *)term->perl.self);
732
733 // don't allow further calls
734 term->perl.self = 0;
721 } 735 }
722 736
723 swap (perl_environ, environ); 737 swap (perl_environ, environ);
724 738
725 return event_consumed; 739 return event_consumed;
842 const_iv (SelectionRequest), 856 const_iv (SelectionRequest),
843 const_iv (SelectionNotify), 857 const_iv (SelectionNotify),
844 const_iv (ColormapNotify), 858 const_iv (ColormapNotify),
845 const_iv (ClientMessage), 859 const_iv (ClientMessage),
846 const_iv (MappingNotify), 860 const_iv (MappingNotify),
861# if ENABLE_XIM_ONTHESPOT
862 const_iv (XIMReverse),
863 const_iv (XIMUnderline),
864 const_iv (XIMHighlight),
865 const_iv (XIMPrimary),
866 const_iv (XIMSecondary),
867 const_iv (XIMTertiary),
868 const_iv (XIMVisibleToForward),
869 const_iv (XIMVisibleToBackword),
870 const_iv (XIMVisibleToCenter),
871# if 0
872 const_iv (XIMForwardChar),
873 const_iv (XIMBackwardChar),
874 const_iv (XIMForwardWord),
875 const_iv (XIMBackwardWord),
876 const_iv (XIMCaretUp),
877 const_iv (XIMCaretDown),
878 const_iv (XIMNextLine),
879 const_iv (XIMPreviousLine),
880 const_iv (XIMLineStart),
881 const_iv (XIMLineEnd),
882 const_iv (XIMAbsolutePosition),
883 const_iv (XIMDontChange),
884# endif
885# endif
847 }; 886 };
848 887
849 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 888 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
850 civ-- > const_iv; ) 889 civ-- > const_iv; )
851 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 890 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
928 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) 967 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
929 croak ("first argument to urxvt::term->_new must be arrayref"); 968 croak ("first argument to urxvt::term->_new must be arrayref");
930 969
931 rxvt_term *term = new rxvt_term; 970 rxvt_term *term = new rxvt_term;
932 971
933 term->argv = new stringvec; 972 stringvec *argv = new stringvec;
934 term->envv = new stringvec; 973 stringvec *envv = new stringvec;
935 974
936 for (int i = 1; i < items; i++) 975 for (int i = 1; i < items; i++)
937 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 976 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
938 977
939 AV *envv = (AV *)SvRV (ST (0)); 978 AV *env = (AV *)SvRV (ST (0));
940 for (int i = AvFILL (envv) + 1; i--; ) 979 for (int i = AvFILL (env) + 1; i--; )
941 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 980 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
942 981
943 term->envv->push_back (0); 982 envv->push_back (0);
944 983
945 bool success; 984 bool success;
946 985
947 try 986 try
948 { 987 {
949 success = term->init (term->argv->size (), term->argv->begin ()); 988 success = term->init (argv, envv);
950 } 989 }
951 catch (const class rxvt_failure_exception &e) 990 catch (const class rxvt_failure_exception &e)
952 { 991 {
953 success = false; 992 success = false;
954 } 993 }
1117rxvt_term::ModLevel3Mask () 1156rxvt_term::ModLevel3Mask ()
1118 ALIAS: 1157 ALIAS:
1119 ModLevel3Mask = 0 1158 ModLevel3Mask = 0
1120 ModMetaMask = 1 1159 ModMetaMask = 1
1121 ModNumLockMask = 2 1160 ModNumLockMask = 2
1161 current_screen = 3
1162 hidden_cursor = 4
1122 CODE: 1163 CODE:
1123 switch (ix) 1164 switch (ix)
1124 { 1165 {
1125 case 0: RETVAL = THIS->ModLevel3Mask; break; 1166 case 0: RETVAL = THIS->ModLevel3Mask; break;
1126 case 1: RETVAL = THIS->ModMetaMask; break; 1167 case 1: RETVAL = THIS->ModMetaMask; break;
1127 case 2: RETVAL = THIS->ModNumLockMask; break; 1168 case 2: RETVAL = THIS->ModNumLockMask; break;
1169 case 3: RETVAL = THIS->current_screen; break;
1170 case 4: RETVAL = THIS->hidden_cursor; break;
1128 } 1171 }
1129 OUTPUT: 1172 OUTPUT:
1130 RETVAL 1173 RETVAL
1131 1174
1132char * 1175char *
1170 if (events != EVENT_UNDEF) 1213 if (events != EVENT_UNDEF)
1171 THIS->pty_ev.set (events); 1214 THIS->pty_ev.set (events);
1172 OUTPUT: 1215 OUTPUT:
1173 RETVAL 1216 RETVAL
1174 1217
1218int
1219rxvt_term::pty_fd ()
1220 CODE:
1221 RETVAL = THIS->pty->pty;
1222 OUTPUT:
1223 RETVAL
1224
1175Window 1225Window
1176rxvt_term::parent () 1226rxvt_term::parent ()
1177 CODE: 1227 CODE:
1178 RETVAL = THIS->parent [0]; 1228 RETVAL = THIS->parent [0];
1179 OUTPUT: 1229 OUTPUT:
1233 1283
1234 line_t &l = ROW(row_number); 1284 line_t &l = ROW(row_number);
1235 1285
1236 if (GIMME_V != G_VOID) 1286 if (GIMME_V != G_VOID)
1237 { 1287 {
1238 wchar_t *wstr = new wchar_t [THIS->ncol]; 1288 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1239 1289
1240 for (int col = 0; col < THIS->ncol; col++) 1290 for (int col = 0; col < THIS->ncol; col++)
1241 wstr [col] = l.t [col]; 1291 wstr [col] = l.t [col];
1242 1292
1243 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1293 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1244
1245 delete [] wstr;
1246 } 1294 }
1247 1295
1248 if (new_text) 1296 if (new_text)
1249 { 1297 {
1250 wchar_t *wstr = sv2wcs (new_text); 1298 wchar_t *wstr = sv2wcs (new_text);
1343rxvt_term::special_encode (SV *string) 1391rxvt_term::special_encode (SV *string)
1344 CODE: 1392 CODE:
1345{ 1393{
1346 wchar_t *wstr = sv2wcs (string); 1394 wchar_t *wstr = sv2wcs (string);
1347 int wlen = wcslen (wstr); 1395 int wlen = wcslen (wstr);
1348 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1396 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1349 1397
1350 rxvt_push_locale (THIS->locale); 1398 rxvt_push_locale (THIS->locale);
1351 1399
1352 wchar_t *r = rstr; 1400 wchar_t *r = rstr;
1353 for (wchar_t *s = wstr; *s; s++) 1401 for (wchar_t *s = wstr; *s; s++)
1402 {
1403 int w = WCWIDTH (*s);
1404
1354 if (wcwidth (*s) == 0) 1405 if (w == 0)
1355 { 1406 {
1356 if (r == rstr) 1407 if (r == rstr)
1357 croak ("leading combining character unencodable"); 1408 croak ("leading combining character unencodable");
1358 1409
1359 unicode_t n = rxvt_compose (r[-1], *s); 1410 unicode_t n = rxvt_compose (r[-1], *s);
1360 if (n == NOCHAR) 1411 if (n == NOCHAR)
1361 n = rxvt_composite.compose (r[-1], *s); 1412 n = rxvt_composite.compose (r[-1], *s);
1362 1413
1363 r[-1] = n; 1414 r[-1] = n;
1364 } 1415 }
1365#if !UNICODE_3 1416#if !UNICODE_3
1366 else if (*s >= 0x10000) 1417 else if (*s >= 0x10000)
1367 *r++ = rxvt_composite.compose (*s); 1418 *r++ = rxvt_composite.compose (*s);
1368#endif 1419#endif
1369 else 1420 else
1370 *r++ = *s; 1421 *r++ = *s;
1422
1423 // the *2 above only allows wcwidth <= 2
1424 if (w > 1)
1425 *r++ = NOCHAR;
1426 }
1371 1427
1372 rxvt_pop_locale (); 1428 rxvt_pop_locale ();
1373 1429
1374 RETVAL = wcs2sv (rstr, r - rstr); 1430 RETVAL = wcs2sv (rstr, r - rstr);
1375
1376 delete [] rstr;
1377} 1431}
1378 OUTPUT: 1432 OUTPUT:
1379 RETVAL 1433 RETVAL
1380 1434
1381SV * 1435SV *
1393 else if (IS_COMPOSE (*s)) 1447 else if (IS_COMPOSE (*s))
1394 dlen += rxvt_composite.expand (*s, 0); 1448 dlen += rxvt_composite.expand (*s, 0);
1395 else 1449 else
1396 dlen++; 1450 dlen++;
1397 1451
1398 wchar_t *rstr = new wchar_t [dlen]; 1452 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1399 1453
1400 // decode 1454 // decode
1401 wchar_t *r = rstr; 1455 wchar_t *r = rstr;
1402 for (wchar_t *s = wstr; *s; s++) 1456 for (wchar_t *s = wstr; *s; s++)
1403 if (*s == NOCHAR) 1457 if (*s == NOCHAR)
1406 r += rxvt_composite.expand (*s, r); 1460 r += rxvt_composite.expand (*s, r);
1407 else 1461 else
1408 *r++ = *s; 1462 *r++ = *s;
1409 1463
1410 RETVAL = wcs2sv (rstr, r - rstr); 1464 RETVAL = wcs2sv (rstr, r - rstr);
1411
1412 delete [] rstr;
1413} 1465}
1414 OUTPUT: 1466 OUTPUT:
1415 RETVAL 1467 RETVAL
1416 1468
1417void 1469void
1527 if (items == 3) 1579 if (items == 3)
1528 { 1580 {
1529 rc.row = SvIV (ST (1)); 1581 rc.row = SvIV (ST (1));
1530 rc.col = SvIV (ST (2)); 1582 rc.col = SvIV (ST (2));
1531 1583
1532 if (ix == 2 && rc.col == 0) 1584 if (ix == 2)
1533 { 1585 {
1586 if (rc.col == 0)
1587 {
1588 // col == 0 means end of previous line
1534 rc.row--; 1589 rc.row--;
1535 rc.col = THIS->ncol; 1590 rc.col = THIS->ncol;
1591 }
1592 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1593 && rc.col > ROW(rc.row).l)
1594 {
1595 // col >= length means while line and add newline
1596 rc.col = THIS->ncol;
1597 }
1536 } 1598 }
1537 1599
1538 clamp_it (rc.col, 0, THIS->ncol); 1600 clamp_it (rc.col, 0, THIS->ncol);
1539 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1601 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1540 1602
1548 CODE: 1610 CODE:
1549 RETVAL = THIS->charsets [THIS->screen.charset]; 1611 RETVAL = THIS->charsets [THIS->screen.charset];
1550 OUTPUT: 1612 OUTPUT:
1551 RETVAL 1613 RETVAL
1552 1614
1553#void 1615void
1554#rxvt_term::selection_clear () 1616rxvt_term::selection_clear ()
1555 1617
1556void 1618void
1557rxvt_term::selection_make (Time eventtime, bool rect = false) 1619rxvt_term::selection_make (Time eventtime, bool rect = false)
1558 CODE: 1620 CODE:
1559 THIS->selection.op = SELECTION_CONT; 1621 THIS->selection.op = SELECTION_CONT;
1587void 1649void
1588rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1650rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1589 1651
1590void 1652void
1591rxvt_term::scr_bell () 1653rxvt_term::scr_bell ()
1654
1655void
1656rxvt_term::scr_change_screen (int screen)
1592 1657
1593void 1658void
1594rxvt_term::scr_add_lines (SV *string) 1659rxvt_term::scr_add_lines (SV *string)
1595 CODE: 1660 CODE:
1596{ 1661{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines