… | |
… | |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | *---------------------------------------------------------------------*/ |
31 | *---------------------------------------------------------------------*/ |
32 | |
32 | |
33 | #include "../config.h" /* NECESSARY */ |
33 | #include "../config.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
|
|
35 | #include "init.h" |
35 | #include "keyboard.h" |
36 | #include "keyboard.h" |
36 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
37 | |
38 | |
38 | #include <limits> |
39 | #include <limits> |
39 | |
40 | |
|
|
41 | #include <cassert> |
40 | #include <csignal> |
42 | #include <csignal> |
41 | #include <cstring> |
43 | #include <cstring> |
42 | |
44 | |
43 | #include <termios.h> |
45 | #include <termios.h> |
44 | |
46 | |
… | |
… | |
49 | # ifdef HAVE_SETLOCALE |
51 | # ifdef HAVE_SETLOCALE |
50 | # include <clocale> |
52 | # include <clocale> |
51 | # endif |
53 | # endif |
52 | #endif |
54 | #endif |
53 | |
55 | |
|
|
56 | struct termios rxvt_term::def_tio; |
54 | vector<rxvt_term *> rxvt_term::termlist; |
57 | vector<rxvt_term *> rxvt_term::termlist; |
55 | |
58 | |
56 | // used to tell global functions which terminal instance is "active" |
59 | // used to tell global functions which terminal instance is "active" |
57 | rxvt_t rxvt_current_term; |
60 | rxvt_t rxvt_current_term; |
58 | |
61 | |
… | |
… | |
101 | { |
104 | { |
102 | if (cc->c2 == c2) return c1; |
105 | if (cc->c2 == c2) return c1; |
103 | cc = (*this)[cc->c1]; |
106 | cc = (*this)[cc->c1]; |
104 | } |
107 | } |
105 | |
108 | |
106 | // check to see wether this combination already exists otherwise |
109 | // check to see whether this combination already exists otherwise |
107 | for (cc = v.end (); cc-- > v.begin (); ) |
110 | for (cc = v.end (); cc-- > v.begin (); ) |
108 | { |
111 | { |
109 | if (cc->c1 == c1 && cc->c2 == c2) |
112 | if (cc->c1 == c1 && cc->c2 == c2) |
110 | return COMPOSE_LO + (cc - v.begin ()); |
113 | return COMPOSE_LO + (cc - v.begin ()); |
111 | } |
114 | } |
… | |
… | |
237 | #endif |
240 | #endif |
238 | |
241 | |
239 | if (display) |
242 | if (display) |
240 | { |
243 | { |
241 | selection_clear (); |
244 | selection_clear (); |
|
|
245 | selection_clear (true); |
242 | |
246 | |
243 | #ifdef USE_XIM |
247 | #ifdef USE_XIM |
244 | im_destroy (); |
248 | im_destroy (); |
245 | #endif |
249 | #endif |
246 | scrollBar.destroy (); |
250 | scrollBar.destroy (); |
… | |
… | |
271 | /* clear all resources */ |
275 | /* clear all resources */ |
272 | for (int i = 0; i < allocated.size (); i++) |
276 | for (int i = 0; i < allocated.size (); i++) |
273 | free (allocated [i]); |
277 | free (allocated [i]); |
274 | |
278 | |
275 | free (selection.text); |
279 | free (selection.text); |
|
|
280 | free (selection.clip_text); |
276 | // TODO: manage env vars in child only(!) |
281 | // TODO: manage env vars in child only(!) |
277 | free (env_display); |
282 | free (env_display); |
278 | free (env_term); |
283 | free (env_term); |
279 | free (locale); |
284 | free (locale); |
280 | free (v_buffer); |
285 | free (v_buffer); |
… | |
… | |
380 | char mesg[BUFSIZ]; |
385 | char mesg[BUFSIZ]; |
381 | char number[32]; |
386 | char number[32]; |
382 | char *mtype = "XlibMessage"; |
387 | char *mtype = "XlibMessage"; |
383 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
388 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
384 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
389 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
385 | rxvt_warn ("An X Error occured, trying to continue after report.\n"); |
390 | rxvt_warn ("An X Error occurred, trying to continue after report.\n"); |
386 | rxvt_warn ("%s: %s\n", mesg, buffer); |
391 | rxvt_warn ("%s: %s\n", mesg, buffer); |
387 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
392 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
388 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
393 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
389 | sprintf(number, "%d", event->request_code); |
394 | sprintf(number, "%d", event->request_code); |
390 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
395 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
391 | rxvt_warn ("(which is %s)\n", buffer); |
396 | rxvt_warn ("(which is %s)\n", buffer); |
392 | if (event->request_code >= 128) { |
397 | if (event->request_code >= 128) { |
393 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
398 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
394 | mesg, BUFSIZ); |
399 | mesg, BUFSIZ); |
395 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
400 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
396 | } |
401 | } |
397 | if ((event->error_code == BadWindow) || |
402 | if ((event->error_code == BadWindow) || |
398 | (event->error_code == BadPixmap) || |
403 | (event->error_code == BadPixmap) || |
399 | (event->error_code == BadCursor) || |
404 | (event->error_code == BadCursor) || |
400 | (event->error_code == BadFont) || |
405 | (event->error_code == BadFont) || |
401 | (event->error_code == BadDrawable) || |
406 | (event->error_code == BadDrawable) || |
402 | (event->error_code == BadColor) || |
407 | (event->error_code == BadColor) || |
403 | (event->error_code == BadGC) || |
408 | (event->error_code == BadGC) || |
404 | (event->error_code == BadIDChoice) || |
409 | (event->error_code == BadIDChoice) || |
405 | (event->error_code == BadValue) || |
410 | (event->error_code == BadValue) || |
406 | (event->error_code == BadAtom)) { |
411 | (event->error_code == BadAtom)) { |
407 | if (event->error_code == BadValue) |
412 | if (event->error_code == BadValue) |
408 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
413 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
409 | mesg, BUFSIZ); |
414 | mesg, BUFSIZ); |
410 | else if (event->error_code == BadAtom) |
415 | else if (event->error_code == BadAtom) |
411 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
416 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
412 | mesg, BUFSIZ); |
417 | mesg, BUFSIZ); |
413 | else |
418 | else |
414 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
419 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
415 | mesg, BUFSIZ); |
420 | mesg, BUFSIZ); |
416 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
421 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
417 | } |
422 | } |
418 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
423 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
419 | mesg, BUFSIZ); |
424 | mesg, BUFSIZ); |
420 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
425 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
421 | } |
426 | } |
422 | #endif |
427 | #endif |
423 | |
428 | |
424 | int |
429 | int |
… | |
… | |
471 | rxvt_emergency_cleanup (); |
476 | rxvt_emergency_cleanup (); |
472 | w.stop (); |
477 | w.stop (); |
473 | kill (getpid (), w.signum); |
478 | kill (getpid (), w.signum); |
474 | } |
479 | } |
475 | |
480 | |
|
|
481 | static void |
|
|
482 | rxvt_get_ttymode (struct termios *tio) |
|
|
483 | { |
|
|
484 | if (tcgetattr (STDIN_FILENO, tio) < 0) |
|
|
485 | memset (tio, 0, sizeof (struct termios)); |
|
|
486 | |
|
|
487 | for (int i = 0; i < NCCS; i++) |
|
|
488 | tio->c_cc[i] = VDISABLE; |
|
|
489 | |
|
|
490 | tio->c_cc[VINTR] = CINTR; |
|
|
491 | tio->c_cc[VQUIT] = CQUIT; |
|
|
492 | tio->c_cc[VERASE] = CERASE; |
|
|
493 | #ifdef VERASE2 |
|
|
494 | tio->c_cc[VERASE2] = CERASE2; |
|
|
495 | #endif |
|
|
496 | tio->c_cc[VKILL] = CKILL; |
|
|
497 | tio->c_cc[VEOF] = CEOF; |
|
|
498 | tio->c_cc[VSTART] = CSTART; |
|
|
499 | tio->c_cc[VSTOP] = CSTOP; |
|
|
500 | tio->c_cc[VSUSP] = CSUSP; |
|
|
501 | # ifdef VDSUSP |
|
|
502 | tio->c_cc[VDSUSP] = CDSUSP; |
|
|
503 | # endif |
|
|
504 | # ifdef VREPRINT |
|
|
505 | tio->c_cc[VREPRINT] = CRPRNT; |
|
|
506 | # endif |
|
|
507 | # ifdef VDISCRD |
|
|
508 | tio->c_cc[VDISCRD] = CFLUSH; |
|
|
509 | # endif |
|
|
510 | # ifdef VWERSE |
|
|
511 | tio->c_cc[VWERSE] = CWERASE; |
|
|
512 | # endif |
|
|
513 | # ifdef VLNEXT |
|
|
514 | tio->c_cc[VLNEXT] = CLNEXT; |
|
|
515 | # endif |
|
|
516 | |
|
|
517 | # if VMIN != VEOF |
|
|
518 | tio->c_cc[VMIN] = 1; |
|
|
519 | # endif |
|
|
520 | # if VTIME != VEOL |
|
|
521 | tio->c_cc[VTIME] = 0; |
|
|
522 | # endif |
|
|
523 | |
|
|
524 | /* input modes */ |
|
|
525 | tio->c_iflag = (BRKINT | IGNPAR | ICRNL |
|
|
526 | # ifdef IMAXBEL |
|
|
527 | | IMAXBEL |
|
|
528 | # endif |
|
|
529 | | IXON); |
|
|
530 | |
|
|
531 | /* output modes */ |
|
|
532 | tio->c_oflag = (OPOST | ONLCR); |
|
|
533 | |
|
|
534 | /* control modes */ |
|
|
535 | tio->c_cflag = (CS8 | CREAD); |
|
|
536 | |
|
|
537 | /* local modes */ |
|
|
538 | tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO |
|
|
539 | # if defined (ECHOCTL) && defined (ECHOKE) |
|
|
540 | | ECHOCTL | ECHOKE |
|
|
541 | # endif |
|
|
542 | | ECHOE | ECHOK); |
|
|
543 | } |
|
|
544 | |
476 | char **rxvt_environ; // startup environment |
545 | char **rxvt_environ; // startup environment |
477 | |
546 | |
478 | void |
547 | void |
479 | rxvt_init () |
548 | rxvt_init () |
480 | { |
549 | { |
481 | ptytty::init (); |
550 | assert (("fontMask must not overlap other RS masks", |
|
|
551 | 0 == (RS_fontMask & (RS_Sel | RS_baseattrMask | RS_customMask | RS_bgMask | RS_fgMask)))); |
482 | |
552 | |
|
|
553 | rxvt_get_ttymode (&rxvt_term::def_tio); |
|
|
554 | |
|
|
555 | // get rid of stdin/stdout as we don't need them, to free resources |
|
|
556 | dup2 (STDERR_FILENO, STDIN_FILENO); |
|
|
557 | dup2 (STDERR_FILENO, STDOUT_FILENO); |
|
|
558 | |
483 | if (!ev_default_loop (0)) |
559 | if (!ev_default_loop ()) |
484 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
560 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
485 | |
561 | |
486 | rxvt_environ = environ; |
562 | rxvt_environ = environ; |
487 | |
563 | |
488 | signal (SIGHUP, SIG_IGN); |
564 | signal (SIGHUP, SIG_IGN); |
489 | signal (SIGPIPE, SIG_IGN); |
565 | signal (SIGPIPE, SIG_IGN); |
490 | |
566 | |
491 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
567 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
492 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
568 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
493 | |
|
|
494 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
495 | /* signal (SIGURG, SIG_DFL); */ |
|
|
496 | |
569 | |
497 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
570 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
498 | // TODO: handle this with exceptions and tolerate the memory loss |
571 | // TODO: handle this with exceptions and tolerate the memory loss |
499 | XSetIOErrorHandler (rxvt_xioerror_handler); |
572 | XSetIOErrorHandler (rxvt_xioerror_handler); |
500 | |
573 | |
… | |
… | |
686 | #endif |
759 | #endif |
687 | |
760 | |
688 | delete fontset[0]; |
761 | delete fontset[0]; |
689 | fontset[0] = fs; |
762 | fontset[0] = fs; |
690 | |
763 | |
691 | prop = (*fs)[1]->properties (); |
764 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
692 | prop.height += lineSpace; |
765 | prop.height += lineSpace; |
693 | prop.width += letterSpace; |
766 | prop.width += letterSpace; |
694 | |
767 | |
695 | fs->set_prop (prop, false); |
768 | fs->set_prop (prop, false); |
696 | |
769 | |
… | |
… | |
748 | prop, XA_STRING, 8, PropModeReplace, |
821 | prop, XA_STRING, 8, PropModeReplace, |
749 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
822 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
750 | } |
823 | } |
751 | |
824 | |
752 | void |
825 | void |
|
|
826 | rxvt_term::set_mbstring_property (Atom prop, const char *str, int len) |
|
|
827 | { |
|
|
828 | XTextProperty ct; |
|
|
829 | |
|
|
830 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
|
|
831 | { |
|
|
832 | XSetTextProperty (dpy, parent[0], &ct, prop); |
|
|
833 | XFree (ct.value); |
|
|
834 | } |
|
|
835 | } |
|
|
836 | |
|
|
837 | void |
753 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
838 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
754 | { |
839 | { |
755 | wchar_t *ws = rxvt_mbstowcs (str, len); |
840 | wchar_t *ws = rxvt_mbstowcs (str, len); |
756 | char *s = rxvt_wcstoutf8 (ws); |
841 | char *s = rxvt_wcstoutf8 (ws); |
757 | |
842 | |
… | |
… | |
767 | /*----------------------------------------------------------------------*/ |
852 | /*----------------------------------------------------------------------*/ |
768 | /* xterm sequences - title, iconName, color (exptl) */ |
853 | /* xterm sequences - title, iconName, color (exptl) */ |
769 | void |
854 | void |
770 | rxvt_term::set_title (const char *str) |
855 | rxvt_term::set_title (const char *str) |
771 | { |
856 | { |
772 | set_string_property (XA_WM_NAME, str); |
857 | set_mbstring_property (XA_WM_NAME, str); |
773 | #if ENABLE_EWMH |
858 | #if ENABLE_EWMH |
774 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
859 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
775 | #endif |
860 | #endif |
776 | } |
861 | } |
777 | |
862 | |
778 | void |
863 | void |
779 | rxvt_term::set_icon_name (const char *str) |
864 | rxvt_term::set_icon_name (const char *str) |
780 | { |
865 | { |
781 | set_string_property (XA_WM_ICON_NAME, str); |
866 | set_mbstring_property (XA_WM_ICON_NAME, str); |
782 | #if ENABLE_EWMH |
867 | #if ENABLE_EWMH |
783 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
868 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
784 | #endif |
869 | #endif |
785 | } |
870 | } |
786 | |
871 | |
… | |
… | |
993 | } |
1078 | } |
994 | |
1079 | |
995 | if (fix_screen || old_height == 0) |
1080 | if (fix_screen || old_height == 0) |
996 | scr_reset (); |
1081 | scr_reset (); |
997 | |
1082 | |
998 | // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version |
|
|
999 | //scr_touch (false); |
|
|
1000 | |
|
|
1001 | #ifdef HAVE_BG_PIXMAP |
1083 | #ifdef HAVE_BG_PIXMAP |
1002 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1084 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1003 | // if (bgPixmap.pixmap) |
1085 | // if (bgPixmap.pixmap) |
1004 | // scr_touch (false); |
1086 | // scr_touch (false); |
1005 | #endif |
1087 | #endif |
… | |
… | |
1163 | |
1245 | |
1164 | term->make_current (); |
1246 | term->make_current (); |
1165 | |
1247 | |
1166 | if (text) |
1248 | if (text) |
1167 | { |
1249 | { |
1168 | void *str; |
1250 | wchar_t *str; |
1169 | |
1251 | |
1170 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1252 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1171 | { |
1253 | { |
1172 | // of course, X makes it ugly again |
1254 | // of course, X makes it ugly again |
1173 | if (term->rs[Rs_imLocale]) |
1255 | if (term->rs[Rs_imLocale]) |
1174 | SET_LOCALE (term->rs[Rs_imLocale]); |
1256 | SET_LOCALE (term->rs[Rs_imLocale]); |
1175 | |
1257 | |
1176 | str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); |
1258 | str = rxvt_temp_buf<wchar_t> (text->length + 1); |
1177 | mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); |
1259 | mbstowcs (str, text->string.multi_byte, text->length + 1); |
1178 | |
1260 | |
1179 | if (term->rs[Rs_imLocale]) |
1261 | if (term->rs[Rs_imLocale]) |
1180 | SET_LOCALE (term->locale); |
1262 | SET_LOCALE (term->locale); |
1181 | } |
1263 | } |
1182 | else |
1264 | else |
1183 | str = (void *)text->string.wide_char; |
1265 | str = text->string.wide_char; |
1184 | |
1266 | |
1185 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1267 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1186 | DT_INT, call_data->caret, |
1268 | DT_INT, call_data->caret, |
1187 | DT_INT, call_data->chg_first, |
1269 | DT_INT, call_data->chg_first, |
1188 | DT_INT, call_data->chg_length, |
1270 | DT_INT, call_data->chg_length, |
… | |
… | |
1542 | void |
1624 | void |
1543 | rxvt_term::get_window_origin (int &x, int &y) |
1625 | rxvt_term::get_window_origin (int &x, int &y) |
1544 | { |
1626 | { |
1545 | Window cr; |
1627 | Window cr; |
1546 | XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); |
1628 | XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); |
1547 | /* fprintf (stderr, "origin is %+d%+d\n", x, y);*/ |
|
|
1548 | } |
1629 | } |
1549 | |
1630 | |
1550 | Pixmap |
1631 | Pixmap |
1551 | rxvt_term::get_pixmap_property (int prop_id) |
1632 | rxvt_term::get_pixmap_property (int prop_id) |
1552 | { |
1633 | { |
… | |
… | |
1566 | |
1647 | |
1567 | return None; |
1648 | return None; |
1568 | } |
1649 | } |
1569 | |
1650 | |
1570 | #ifdef HAVE_BG_PIXMAP |
1651 | #ifdef HAVE_BG_PIXMAP |
1571 | # if TRACE_PIXMAPS |
|
|
1572 | # undef update_background |
|
|
1573 | void |
|
|
1574 | rxvt_term::trace_update_background (const char *file, int line) |
|
|
1575 | { |
|
|
1576 | fprintf (stderr, "%s:%d:update_background()\n", file, line); |
|
|
1577 | update_background (); |
|
|
1578 | } |
|
|
1579 | # endif |
|
|
1580 | |
1652 | |
1581 | void |
1653 | void |
1582 | rxvt_term::update_background () |
1654 | rxvt_term::update_background () |
1583 | { |
1655 | { |
1584 | if (update_background_ev.is_active ()) |
1656 | if (update_background_ev.is_active ()) |