… | |
… | |
35 | #include "keyboard.h" |
35 | #include "keyboard.h" |
36 | #include "rxvtperl.h" |
36 | #include "rxvtperl.h" |
37 | |
37 | |
38 | #include <limits> |
38 | #include <limits> |
39 | |
39 | |
|
|
40 | #include <cassert> |
40 | #include <csignal> |
41 | #include <csignal> |
41 | #include <cstring> |
42 | #include <cstring> |
42 | |
43 | |
43 | #include <termios.h> |
44 | #include <termios.h> |
44 | |
45 | |
… | |
… | |
101 | { |
102 | { |
102 | if (cc->c2 == c2) return c1; |
103 | if (cc->c2 == c2) return c1; |
103 | cc = (*this)[cc->c1]; |
104 | cc = (*this)[cc->c1]; |
104 | } |
105 | } |
105 | |
106 | |
106 | // check to see wether this combination already exists otherwise |
107 | // check to see whether this combination already exists otherwise |
107 | for (cc = v.end (); cc-- > v.begin (); ) |
108 | for (cc = v.end (); cc-- > v.begin (); ) |
108 | { |
109 | { |
109 | if (cc->c1 == c1 && cc->c2 == c2) |
110 | if (cc->c1 == c1 && cc->c2 == c2) |
110 | return COMPOSE_LO + (cc - v.begin ()); |
111 | return COMPOSE_LO + (cc - v.begin ()); |
111 | } |
112 | } |
… | |
… | |
237 | #endif |
238 | #endif |
238 | |
239 | |
239 | if (display) |
240 | if (display) |
240 | { |
241 | { |
241 | selection_clear (); |
242 | selection_clear (); |
|
|
243 | selection_clear (true); |
242 | |
244 | |
243 | #ifdef USE_XIM |
245 | #ifdef USE_XIM |
244 | im_destroy (); |
246 | im_destroy (); |
245 | #endif |
247 | #endif |
246 | scrollBar.destroy (); |
248 | scrollBar.destroy (); |
… | |
… | |
271 | /* clear all resources */ |
273 | /* clear all resources */ |
272 | for (int i = 0; i < allocated.size (); i++) |
274 | for (int i = 0; i < allocated.size (); i++) |
273 | free (allocated [i]); |
275 | free (allocated [i]); |
274 | |
276 | |
275 | free (selection.text); |
277 | free (selection.text); |
|
|
278 | free (selection.clip_text); |
276 | // TODO: manage env vars in child only(!) |
279 | // TODO: manage env vars in child only(!) |
277 | free (env_display); |
280 | free (env_display); |
278 | free (env_term); |
281 | free (env_term); |
279 | free (locale); |
282 | free (locale); |
280 | free (v_buffer); |
283 | free (v_buffer); |
… | |
… | |
380 | char mesg[BUFSIZ]; |
383 | char mesg[BUFSIZ]; |
381 | char number[32]; |
384 | char number[32]; |
382 | char *mtype = "XlibMessage"; |
385 | char *mtype = "XlibMessage"; |
383 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
386 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
384 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
387 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
385 | rxvt_warn ("An X Error occured, trying to continue after report.\n"); |
388 | rxvt_warn ("An X Error occurred, trying to continue after report.\n"); |
386 | rxvt_warn ("%s: %s\n", mesg, buffer); |
389 | rxvt_warn ("%s: %s\n", mesg, buffer); |
387 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
390 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
388 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
391 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
389 | sprintf(number, "%d", event->request_code); |
392 | sprintf(number, "%d", event->request_code); |
390 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
393 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
391 | rxvt_warn ("(which is %s)\n", buffer); |
394 | rxvt_warn ("(which is %s)\n", buffer); |
392 | if (event->request_code >= 128) { |
395 | if (event->request_code >= 128) { |
393 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
396 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
394 | mesg, BUFSIZ); |
397 | mesg, BUFSIZ); |
395 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
398 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
396 | } |
399 | } |
397 | if ((event->error_code == BadWindow) || |
400 | if ((event->error_code == BadWindow) || |
398 | (event->error_code == BadPixmap) || |
401 | (event->error_code == BadPixmap) || |
399 | (event->error_code == BadCursor) || |
402 | (event->error_code == BadCursor) || |
400 | (event->error_code == BadFont) || |
403 | (event->error_code == BadFont) || |
401 | (event->error_code == BadDrawable) || |
404 | (event->error_code == BadDrawable) || |
402 | (event->error_code == BadColor) || |
405 | (event->error_code == BadColor) || |
403 | (event->error_code == BadGC) || |
406 | (event->error_code == BadGC) || |
404 | (event->error_code == BadIDChoice) || |
407 | (event->error_code == BadIDChoice) || |
405 | (event->error_code == BadValue) || |
408 | (event->error_code == BadValue) || |
406 | (event->error_code == BadAtom)) { |
409 | (event->error_code == BadAtom)) { |
407 | if (event->error_code == BadValue) |
410 | if (event->error_code == BadValue) |
408 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
411 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
409 | mesg, BUFSIZ); |
412 | mesg, BUFSIZ); |
410 | else if (event->error_code == BadAtom) |
413 | else if (event->error_code == BadAtom) |
411 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
414 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
412 | mesg, BUFSIZ); |
415 | mesg, BUFSIZ); |
413 | else |
416 | else |
414 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
417 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
415 | mesg, BUFSIZ); |
418 | mesg, BUFSIZ); |
416 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
419 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
417 | } |
420 | } |
418 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
421 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
419 | mesg, BUFSIZ); |
422 | mesg, BUFSIZ); |
420 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
423 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
421 | } |
424 | } |
422 | #endif |
425 | #endif |
423 | |
426 | |
424 | int |
427 | int |
… | |
… | |
476 | char **rxvt_environ; // startup environment |
479 | char **rxvt_environ; // startup environment |
477 | |
480 | |
478 | void |
481 | void |
479 | rxvt_init () |
482 | rxvt_init () |
480 | { |
483 | { |
|
|
484 | assert (("fontMask must not overlap other RS masks", |
|
|
485 | 0 == (RS_fontMask & (RS_Sel | RS_baseattrMask | RS_customMask | RS_bgMask | RS_fgMask)))); |
|
|
486 | |
|
|
487 | // get rid of stdin/stdout as we don't need them, to free resources |
|
|
488 | dup2 (STDERR_FILENO, STDIN_FILENO); |
|
|
489 | dup2 (STDERR_FILENO, STDOUT_FILENO); |
|
|
490 | |
481 | ptytty::init (); |
491 | ptytty::init (); |
482 | |
492 | |
483 | if (!ev_default_loop (0)) |
493 | if (!ev_default_loop (0)) |
484 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
494 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
485 | |
495 | |
… | |
… | |
488 | signal (SIGHUP, SIG_IGN); |
498 | signal (SIGHUP, SIG_IGN); |
489 | signal (SIGPIPE, SIG_IGN); |
499 | signal (SIGPIPE, SIG_IGN); |
490 | |
500 | |
491 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
501 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
492 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
502 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
493 | |
|
|
494 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
495 | /* signal (SIGURG, SIG_DFL); */ |
|
|
496 | |
503 | |
497 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
504 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
498 | // TODO: handle this with exceptions and tolerate the memory loss |
505 | // TODO: handle this with exceptions and tolerate the memory loss |
499 | XSetIOErrorHandler (rxvt_xioerror_handler); |
506 | XSetIOErrorHandler (rxvt_xioerror_handler); |
500 | |
507 | |
… | |
… | |
625 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
632 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
626 | |
633 | |
627 | if (recalc_y) |
634 | if (recalc_y) |
628 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
635 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
629 | |
636 | |
630 | ncol = width / fwidth; |
637 | ncol = width / fwidth; |
631 | nrow = height / fheight; |
638 | nrow = height / fheight; |
632 | } |
639 | } |
633 | |
640 | |
634 | /*----------------------------------------------------------------------*/ |
641 | /*----------------------------------------------------------------------*/ |
635 | /* |
642 | /* |
… | |
… | |
646 | |
653 | |
647 | ws.ws_col = ncol; |
654 | ws.ws_col = ncol; |
648 | ws.ws_row = nrow; |
655 | ws.ws_row = nrow; |
649 | ws.ws_xpixel = width; |
656 | ws.ws_xpixel = width; |
650 | ws.ws_ypixel = height; |
657 | ws.ws_ypixel = height; |
651 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
658 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
652 | |
659 | |
653 | #if 0 |
660 | #if 0 |
654 | // TIOCSWINSZ is supposed to do this automatically and correctly |
661 | // TIOCSWINSZ is supposed to do this automatically and correctly |
655 | if (cmd_pid) /* force through to the command */ |
662 | if (cmd_pid) /* force through to the command */ |
656 | kill (-cmd_pid, SIGWINCH); |
663 | kill (-cmd_pid, SIGWINCH); |
… | |
… | |
686 | #endif |
693 | #endif |
687 | |
694 | |
688 | delete fontset[0]; |
695 | delete fontset[0]; |
689 | fontset[0] = fs; |
696 | fontset[0] = fs; |
690 | |
697 | |
691 | prop = (*fs)[1]->properties (); |
698 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
692 | prop.height += lineSpace; |
699 | prop.height += lineSpace; |
|
|
700 | prop.width += letterSpace; |
693 | |
701 | |
694 | fs->set_prop (prop, false); |
702 | fs->set_prop (prop, false); |
695 | |
703 | |
696 | fwidth = prop.width; |
704 | fwidth = prop.width; |
697 | fheight = prop.height; |
705 | fheight = prop.height; |
… | |
… | |
747 | prop, XA_STRING, 8, PropModeReplace, |
755 | prop, XA_STRING, 8, PropModeReplace, |
748 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
756 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
749 | } |
757 | } |
750 | |
758 | |
751 | void |
759 | void |
|
|
760 | rxvt_term::set_mbstring_property (Atom prop, const char *str, int len) |
|
|
761 | { |
|
|
762 | XTextProperty ct; |
|
|
763 | |
|
|
764 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
|
|
765 | { |
|
|
766 | XSetTextProperty (dpy, parent[0], &ct, prop); |
|
|
767 | XFree (ct.value); |
|
|
768 | } |
|
|
769 | } |
|
|
770 | |
|
|
771 | void |
752 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
772 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
753 | { |
773 | { |
754 | wchar_t *ws = rxvt_mbstowcs (str, len); |
774 | wchar_t *ws = rxvt_mbstowcs (str, len); |
755 | char *s = rxvt_wcstoutf8 (ws); |
775 | char *s = rxvt_wcstoutf8 (ws); |
756 | |
776 | |
… | |
… | |
766 | /*----------------------------------------------------------------------*/ |
786 | /*----------------------------------------------------------------------*/ |
767 | /* xterm sequences - title, iconName, color (exptl) */ |
787 | /* xterm sequences - title, iconName, color (exptl) */ |
768 | void |
788 | void |
769 | rxvt_term::set_title (const char *str) |
789 | rxvt_term::set_title (const char *str) |
770 | { |
790 | { |
771 | set_string_property (XA_WM_NAME, str); |
791 | set_mbstring_property (XA_WM_NAME, str); |
772 | #if ENABLE_EWMH |
792 | #if ENABLE_EWMH |
773 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
793 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
774 | #endif |
794 | #endif |
775 | } |
795 | } |
776 | |
796 | |
777 | void |
797 | void |
778 | rxvt_term::set_icon_name (const char *str) |
798 | rxvt_term::set_icon_name (const char *str) |
779 | { |
799 | { |
780 | set_string_property (XA_WM_ICON_NAME, str); |
800 | set_mbstring_property (XA_WM_ICON_NAME, str); |
781 | #if ENABLE_EWMH |
801 | #if ENABLE_EWMH |
782 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
802 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
783 | #endif |
803 | #endif |
784 | } |
804 | } |
785 | |
805 | |
… | |
… | |
911 | int old_width = szHint.width; |
931 | int old_width = szHint.width; |
912 | int old_height = szHint.height; |
932 | int old_height = szHint.height; |
913 | |
933 | |
914 | window_calc (newwidth, newheight); |
934 | window_calc (newwidth, newheight); |
915 | |
935 | |
916 | if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END))) |
936 | bool set_hint = !HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END)); |
|
|
937 | |
|
|
938 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
|
|
939 | if (set_hint) |
|
|
940 | { |
|
|
941 | szHint.flags &= ~(PBaseSize | PResizeInc); |
917 | XSetWMNormalHints (dpy, parent[0], &szHint); |
942 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
943 | szHint.flags |= PBaseSize | PResizeInc; |
|
|
944 | } |
918 | |
945 | |
919 | if (!ignoreparent) |
946 | if (!ignoreparent) |
920 | { |
947 | { |
921 | #ifdef SMART_RESIZE |
948 | #ifdef SMART_RESIZE |
922 | /* |
949 | /* |
… | |
… | |
962 | #else |
989 | #else |
963 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
990 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
964 | #endif |
991 | #endif |
965 | } |
992 | } |
966 | |
993 | |
|
|
994 | if (set_hint) |
|
|
995 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
996 | |
967 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
997 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
968 | |
998 | |
969 | if (fix_screen || newwidth != old_width || newheight != old_height) |
999 | if (fix_screen || newwidth != old_width || newheight != old_height) |
970 | { |
1000 | { |
971 | if (scrollBar.state) |
1001 | if (scrollBar.state) |
… | |
… | |
977 | |
1007 | |
978 | #ifdef HAVE_BG_PIXMAP |
1008 | #ifdef HAVE_BG_PIXMAP |
979 | if (bgPixmap.window_size_sensitive ()) |
1009 | if (bgPixmap.window_size_sensitive ()) |
980 | update_background (); |
1010 | update_background (); |
981 | #endif |
1011 | #endif |
982 | |
|
|
983 | scr_clear (); |
|
|
984 | } |
1012 | } |
985 | |
1013 | |
986 | if (fix_screen || old_height == 0) |
1014 | if (fix_screen || old_height == 0) |
987 | scr_reset (); |
1015 | scr_reset (); |
988 | |
|
|
989 | // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version |
|
|
990 | //scr_touch (false); |
|
|
991 | |
1016 | |
992 | #ifdef HAVE_BG_PIXMAP |
1017 | #ifdef HAVE_BG_PIXMAP |
993 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1018 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
994 | // if (bgPixmap.pixmap) |
1019 | // if (bgPixmap.pixmap) |
995 | // scr_touch (false); |
1020 | // scr_touch (false); |
… | |
… | |
1067 | |
1092 | |
1068 | /* Checking whether input method is running. */ |
1093 | /* Checking whether input method is running. */ |
1069 | bool |
1094 | bool |
1070 | rxvt_term::IMisRunning () |
1095 | rxvt_term::IMisRunning () |
1071 | { |
1096 | { |
1072 | char *p; |
|
|
1073 | Atom atom; |
1097 | Atom atom; |
1074 | Window win; |
1098 | Window win; |
1075 | char server[IMBUFSIZ]; |
1099 | char server[IMBUFSIZ]; |
1076 | |
1100 | |
1077 | /* get current locale modifier */ |
1101 | /* get current locale modifier */ |
1078 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1102 | if (char *p = XSetLocaleModifiers (0)) |
1079 | { |
1103 | { |
1080 | strcpy (server, "@server="); |
1104 | strcpy (server, "@server="); |
1081 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1105 | strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */ |
1082 | |
1106 | |
1083 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1107 | if (p = strchr (server + 1, '@')) /* first one only */ |
1084 | *p = '\0'; |
1108 | *p = '\0'; |
1085 | |
1109 | |
1086 | atom = XInternAtom (dpy, server, False); |
1110 | atom = XInternAtom (dpy, server, False); |
1087 | win = XGetSelectionOwner (dpy, atom); |
1111 | win = XGetSelectionOwner (dpy, atom); |
1088 | |
1112 | |
… | |
… | |
1155 | |
1179 | |
1156 | term->make_current (); |
1180 | term->make_current (); |
1157 | |
1181 | |
1158 | if (text) |
1182 | if (text) |
1159 | { |
1183 | { |
1160 | void *str; |
1184 | wchar_t *str; |
1161 | |
1185 | |
1162 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1186 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1163 | { |
1187 | { |
1164 | // of course, X makes it ugly again |
1188 | // of course, X makes it ugly again |
1165 | if (term->rs[Rs_imLocale]) |
1189 | if (term->rs[Rs_imLocale]) |
1166 | SET_LOCALE (term->rs[Rs_imLocale]); |
1190 | SET_LOCALE (term->rs[Rs_imLocale]); |
1167 | |
1191 | |
1168 | str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); |
1192 | str = rxvt_temp_buf<wchar_t> (text->length + 1); |
1169 | mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); |
1193 | mbstowcs (str, text->string.multi_byte, text->length + 1); |
1170 | |
1194 | |
1171 | if (term->rs[Rs_imLocale]) |
1195 | if (term->rs[Rs_imLocale]) |
1172 | SET_LOCALE (term->locale); |
1196 | SET_LOCALE (term->locale); |
1173 | } |
1197 | } |
1174 | else |
1198 | else |
1175 | str = (void *)text->string.wide_char; |
1199 | str = text->string.wide_char; |
1176 | |
1200 | |
1177 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1201 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1178 | DT_INT, call_data->caret, |
1202 | DT_INT, call_data->caret, |
1179 | DT_INT, call_data->chg_first, |
1203 | DT_INT, call_data->chg_first, |
1180 | DT_INT, call_data->chg_length, |
1204 | DT_INT, call_data->chg_length, |