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.93 by root, Wed Jan 25 15:02: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
563 printf ("pushing str %p:%d\n", str,len);//D
561 XPUSHs (sv_2mortal (newSVpvn (str, len))); 564 XPUSHs (sv_2mortal (newSVpvn (str, len)));
562 } 565 }
563 break; 566 break;
564 567
565 case DT_WCS_LEN: 568 case DT_WCS_LEN:
566 { 569 {
567 wchar_t *wstr = va_arg (ap, wchar_t *); 570 wchar_t *wstr = va_arg (ap, wchar_t *);
568 int wlen = va_arg (ap, int); 571 int wlen = va_arg (ap, int);
569 572
570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 573 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
574 }
575 break;
576
577 case DT_LCS_LEN:
578 {
579 long *lstr = va_arg (ap, long *);
580 int llen = va_arg (ap, int);
581
582 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
571 } 583 }
572 break; 584 break;
573 585
574 case DT_XEVENT: 586 case DT_XEVENT:
575 { 587 {
576 XEvent *xe = va_arg (ap, XEvent *); 588 XEvent *xe = va_arg (ap, XEvent *);
577 HV *hv = newHV (); 589 HV *hv = newHV ();
578 590
579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 591# 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) 592# 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) 593# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
582# undef set 594# undef set
583 595
584 setiv (type, xe->type); 596 setiv (type, xe->type);
585 setiv (send_event, xe->xany.send_event); 597 setiv (send_event, xe->xany.send_event);
586 setiv (serial, xe->xany.serial); 598 setiv (serial, xe->xany.serial);
587 599
596 setuv (root, xe->xmotion.root); 608 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow); 609 setuv (subwindow, xe->xmotion.subwindow);
598 setuv (time, xe->xmotion.time); 610 setuv (time, xe->xmotion.time);
599 setiv (x, xe->xmotion.x); 611 setiv (x, xe->xmotion.x);
600 setiv (y, xe->xmotion.y); 612 setiv (y, xe->xmotion.y);
601 setiv (row, xe->xmotion.y / term->fheight); 613 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
602 setiv (col, xe->xmotion.x / term->fwidth); 614 setiv (col, xe->xmotion.x / term->fwidth);
603 setiv (x_root, xe->xmotion.x_root); 615 setiv (x_root, xe->xmotion.x_root);
604 setiv (y_root, xe->xmotion.y_root); 616 setiv (y_root, xe->xmotion.y_root);
605 setuv (state, xe->xmotion.state); 617 setuv (state, xe->xmotion.state);
606 618
716 } 728 }
717 else if (htype == HOOK_DESTROY) 729 else if (htype == HOOK_DESTROY)
718 { 730 {
719 clearSVptr ((SV *)term->perl.self); 731 clearSVptr ((SV *)term->perl.self);
720 SvREFCNT_dec ((SV *)term->perl.self); 732 SvREFCNT_dec ((SV *)term->perl.self);
733
734 // don't allow further calls
735 term->perl.self = 0;
721 } 736 }
722 737
723 swap (perl_environ, environ); 738 swap (perl_environ, environ);
724 739
725 return event_consumed; 740 return event_consumed;
842 const_iv (SelectionRequest), 857 const_iv (SelectionRequest),
843 const_iv (SelectionNotify), 858 const_iv (SelectionNotify),
844 const_iv (ColormapNotify), 859 const_iv (ColormapNotify),
845 const_iv (ClientMessage), 860 const_iv (ClientMessage),
846 const_iv (MappingNotify), 861 const_iv (MappingNotify),
862# if ENABLE_XIM_ONTHESPOT
863 const_iv (XIMReverse),
864 const_iv (XIMUnderline),
865 const_iv (XIMHighlight),
866 const_iv (XIMPrimary),
867 const_iv (XIMSecondary),
868 const_iv (XIMTertiary),
869 const_iv (XIMVisibleToForward),
870 const_iv (XIMVisibleToBackword),
871 const_iv (XIMVisibleToCenter),
872# if 0
873 const_iv (XIMForwardChar),
874 const_iv (XIMBackwardChar),
875 const_iv (XIMForwardWord),
876 const_iv (XIMBackwardWord),
877 const_iv (XIMCaretUp),
878 const_iv (XIMCaretDown),
879 const_iv (XIMNextLine),
880 const_iv (XIMPreviousLine),
881 const_iv (XIMLineStart),
882 const_iv (XIMLineEnd),
883 const_iv (XIMAbsolutePosition),
884 const_iv (XIMDontChange),
885# endif
886# endif
847 }; 887 };
848 888
849 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 889 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
850 civ-- > const_iv; ) 890 civ-- > const_iv; )
851 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 891 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
928 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) 968 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
929 croak ("first argument to urxvt::term->_new must be arrayref"); 969 croak ("first argument to urxvt::term->_new must be arrayref");
930 970
931 rxvt_term *term = new rxvt_term; 971 rxvt_term *term = new rxvt_term;
932 972
933 term->argv = new stringvec; 973 stringvec *argv = new stringvec;
934 term->envv = new stringvec; 974 stringvec *envv = new stringvec;
935 975
936 for (int i = 1; i < items; i++) 976 for (int i = 1; i < items; i++)
937 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 977 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
938 978
939 AV *envv = (AV *)SvRV (ST (0)); 979 AV *env = (AV *)SvRV (ST (0));
940 for (int i = AvFILL (envv) + 1; i--; ) 980 for (int i = AvFILL (env) + 1; i--; )
941 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 981 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
942 982
943 term->envv->push_back (0); 983 envv->push_back (0);
944 984
945 bool success; 985 bool success;
946 986
947 try 987 try
948 { 988 {
949 success = term->init (term->argv->size (), term->argv->begin ()); 989 success = term->init (argv, envv);
950 } 990 }
951 catch (const class rxvt_failure_exception &e) 991 catch (const class rxvt_failure_exception &e)
952 { 992 {
953 success = false; 993 success = false;
954 } 994 }
1117rxvt_term::ModLevel3Mask () 1157rxvt_term::ModLevel3Mask ()
1118 ALIAS: 1158 ALIAS:
1119 ModLevel3Mask = 0 1159 ModLevel3Mask = 0
1120 ModMetaMask = 1 1160 ModMetaMask = 1
1121 ModNumLockMask = 2 1161 ModNumLockMask = 2
1162 current_screen = 3
1163 hidden_cursor = 4
1122 CODE: 1164 CODE:
1123 switch (ix) 1165 switch (ix)
1124 { 1166 {
1125 case 0: RETVAL = THIS->ModLevel3Mask; break; 1167 case 0: RETVAL = THIS->ModLevel3Mask; break;
1126 case 1: RETVAL = THIS->ModMetaMask; break; 1168 case 1: RETVAL = THIS->ModMetaMask; break;
1127 case 2: RETVAL = THIS->ModNumLockMask; break; 1169 case 2: RETVAL = THIS->ModNumLockMask; break;
1170 case 3: RETVAL = THIS->current_screen; break;
1171 case 4: RETVAL = THIS->hidden_cursor; break;
1128 } 1172 }
1129 OUTPUT: 1173 OUTPUT:
1130 RETVAL 1174 RETVAL
1131 1175
1132char * 1176char *
1170 if (events != EVENT_UNDEF) 1214 if (events != EVENT_UNDEF)
1171 THIS->pty_ev.set (events); 1215 THIS->pty_ev.set (events);
1172 OUTPUT: 1216 OUTPUT:
1173 RETVAL 1217 RETVAL
1174 1218
1219int
1220rxvt_term::pty_fd ()
1221 CODE:
1222 RETVAL = THIS->pty->pty;
1223 OUTPUT:
1224 RETVAL
1225
1175Window 1226Window
1176rxvt_term::parent () 1227rxvt_term::parent ()
1177 CODE: 1228 CODE:
1178 RETVAL = THIS->parent [0]; 1229 RETVAL = THIS->parent [0];
1179 OUTPUT: 1230 OUTPUT:
1233 1284
1234 line_t &l = ROW(row_number); 1285 line_t &l = ROW(row_number);
1235 1286
1236 if (GIMME_V != G_VOID) 1287 if (GIMME_V != G_VOID)
1237 { 1288 {
1238 wchar_t *wstr = new wchar_t [THIS->ncol]; 1289 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1239 1290
1240 for (int col = 0; col < THIS->ncol; col++) 1291 for (int col = 0; col < THIS->ncol; col++)
1241 wstr [col] = l.t [col]; 1292 wstr [col] = l.t [col];
1242 1293
1243 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1294 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1244
1245 delete [] wstr;
1246 } 1295 }
1247 1296
1248 if (new_text) 1297 if (new_text)
1249 { 1298 {
1250 wchar_t *wstr = sv2wcs (new_text); 1299 wchar_t *wstr = sv2wcs (new_text);
1343rxvt_term::special_encode (SV *string) 1392rxvt_term::special_encode (SV *string)
1344 CODE: 1393 CODE:
1345{ 1394{
1346 wchar_t *wstr = sv2wcs (string); 1395 wchar_t *wstr = sv2wcs (string);
1347 int wlen = wcslen (wstr); 1396 int wlen = wcslen (wstr);
1348 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1397 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1349 1398
1350 rxvt_push_locale (THIS->locale); 1399 rxvt_push_locale (THIS->locale);
1351 1400
1352 wchar_t *r = rstr; 1401 wchar_t *r = rstr;
1353 for (wchar_t *s = wstr; *s; s++) 1402 for (wchar_t *s = wstr; *s; s++)
1403 {
1404 int w = WCWIDTH (*s);
1405
1354 if (wcwidth (*s) == 0) 1406 if (w == 0)
1355 { 1407 {
1356 if (r == rstr) 1408 if (r == rstr)
1357 croak ("leading combining character unencodable"); 1409 croak ("leading combining character unencodable");
1358 1410
1359 unicode_t n = rxvt_compose (r[-1], *s); 1411 unicode_t n = rxvt_compose (r[-1], *s);
1360 if (n == NOCHAR) 1412 if (n == NOCHAR)
1361 n = rxvt_composite.compose (r[-1], *s); 1413 n = rxvt_composite.compose (r[-1], *s);
1362 1414
1363 r[-1] = n; 1415 r[-1] = n;
1364 } 1416 }
1365#if !UNICODE_3 1417#if !UNICODE_3
1366 else if (*s >= 0x10000) 1418 else if (*s >= 0x10000)
1367 *r++ = rxvt_composite.compose (*s); 1419 *r++ = rxvt_composite.compose (*s);
1368#endif 1420#endif
1369 else 1421 else
1370 *r++ = *s; 1422 *r++ = *s;
1423
1424 // the *2 above only allows wcwidth <= 2
1425 if (w > 1)
1426 *r++ = NOCHAR;
1427 }
1371 1428
1372 rxvt_pop_locale (); 1429 rxvt_pop_locale ();
1373 1430
1374 RETVAL = wcs2sv (rstr, r - rstr); 1431 RETVAL = wcs2sv (rstr, r - rstr);
1375
1376 delete [] rstr;
1377} 1432}
1378 OUTPUT: 1433 OUTPUT:
1379 RETVAL 1434 RETVAL
1380 1435
1381SV * 1436SV *
1393 else if (IS_COMPOSE (*s)) 1448 else if (IS_COMPOSE (*s))
1394 dlen += rxvt_composite.expand (*s, 0); 1449 dlen += rxvt_composite.expand (*s, 0);
1395 else 1450 else
1396 dlen++; 1451 dlen++;
1397 1452
1398 wchar_t *rstr = new wchar_t [dlen]; 1453 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1399 1454
1400 // decode 1455 // decode
1401 wchar_t *r = rstr; 1456 wchar_t *r = rstr;
1402 for (wchar_t *s = wstr; *s; s++) 1457 for (wchar_t *s = wstr; *s; s++)
1403 if (*s == NOCHAR) 1458 if (*s == NOCHAR)
1406 r += rxvt_composite.expand (*s, r); 1461 r += rxvt_composite.expand (*s, r);
1407 else 1462 else
1408 *r++ = *s; 1463 *r++ = *s;
1409 1464
1410 RETVAL = wcs2sv (rstr, r - rstr); 1465 RETVAL = wcs2sv (rstr, r - rstr);
1411
1412 delete [] rstr;
1413} 1466}
1414 OUTPUT: 1467 OUTPUT:
1415 RETVAL 1468 RETVAL
1416 1469
1417void 1470void
1527 if (items == 3) 1580 if (items == 3)
1528 { 1581 {
1529 rc.row = SvIV (ST (1)); 1582 rc.row = SvIV (ST (1));
1530 rc.col = SvIV (ST (2)); 1583 rc.col = SvIV (ST (2));
1531 1584
1532 if (ix == 2 && rc.col == 0) 1585 if (ix == 2)
1533 { 1586 {
1587 if (rc.col == 0)
1588 {
1589 // col == 0 means end of previous line
1534 rc.row--; 1590 rc.row--;
1535 rc.col = THIS->ncol; 1591 rc.col = THIS->ncol;
1592 }
1593 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1594 && rc.col > ROW(rc.row).l)
1595 {
1596 // col >= length means while line and add newline
1597 rc.col = THIS->ncol;
1598 }
1536 } 1599 }
1537 1600
1538 clamp_it (rc.col, 0, THIS->ncol); 1601 clamp_it (rc.col, 0, THIS->ncol);
1539 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1602 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1540 1603
1548 CODE: 1611 CODE:
1549 RETVAL = THIS->charsets [THIS->screen.charset]; 1612 RETVAL = THIS->charsets [THIS->screen.charset];
1550 OUTPUT: 1613 OUTPUT:
1551 RETVAL 1614 RETVAL
1552 1615
1553#void 1616void
1554#rxvt_term::selection_clear () 1617rxvt_term::selection_clear ()
1555 1618
1556void 1619void
1557rxvt_term::selection_make (Time eventtime, bool rect = false) 1620rxvt_term::selection_make (Time eventtime, bool rect = false)
1558 CODE: 1621 CODE:
1559 THIS->selection.op = SELECTION_CONT; 1622 THIS->selection.op = SELECTION_CONT;
1587void 1650void
1588rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1651rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1589 1652
1590void 1653void
1591rxvt_term::scr_bell () 1654rxvt_term::scr_bell ()
1655
1656void
1657rxvt_term::scr_change_screen (int screen)
1592 1658
1593void 1659void
1594rxvt_term::scr_add_lines (SV *string) 1660rxvt_term::scr_add_lines (SV *string)
1595 CODE: 1661 CODE:
1596{ 1662{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines