… | |
… | |
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 | } |
… | |
… | |
227 | delete fontset[0]; |
228 | delete fontset[0]; |
228 | |
229 | |
229 | #ifdef HAVE_BG_PIXMAP |
230 | #ifdef HAVE_BG_PIXMAP |
230 | bgPixmap.destroy (); |
231 | bgPixmap.destroy (); |
231 | #endif |
232 | #endif |
|
|
233 | #ifdef HAVE_AFTERIMAGE |
|
|
234 | if (asv) |
|
|
235 | destroy_asvisual (asv, 0); |
|
|
236 | if (asimman) |
|
|
237 | destroy_image_manager (asimman, 0); |
|
|
238 | #endif |
232 | |
239 | |
233 | if (display) |
240 | if (display) |
234 | { |
241 | { |
235 | selection_clear (); |
242 | selection_clear (); |
|
|
243 | selection_clear (true); |
236 | |
244 | |
237 | #ifdef USE_XIM |
245 | #ifdef USE_XIM |
238 | im_destroy (); |
246 | im_destroy (); |
239 | #endif |
247 | #endif |
240 | scrollBar.destroy (); |
248 | scrollBar.destroy (); |
… | |
… | |
265 | /* clear all resources */ |
273 | /* clear all resources */ |
266 | for (int i = 0; i < allocated.size (); i++) |
274 | for (int i = 0; i < allocated.size (); i++) |
267 | free (allocated [i]); |
275 | free (allocated [i]); |
268 | |
276 | |
269 | free (selection.text); |
277 | free (selection.text); |
|
|
278 | free (selection.clip_text); |
270 | // TODO: manage env vars in child only(!) |
279 | // TODO: manage env vars in child only(!) |
271 | free (env_display); |
280 | free (env_display); |
272 | free (env_term); |
281 | free (env_term); |
273 | free (locale); |
282 | free (locale); |
274 | free (v_buffer); |
283 | free (v_buffer); |
… | |
… | |
382 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
391 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
383 | sprintf(number, "%d", event->request_code); |
392 | sprintf(number, "%d", event->request_code); |
384 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
393 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
385 | rxvt_warn ("(which is %s)\n", buffer); |
394 | rxvt_warn ("(which is %s)\n", buffer); |
386 | if (event->request_code >= 128) { |
395 | if (event->request_code >= 128) { |
387 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
396 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
388 | mesg, BUFSIZ); |
397 | mesg, BUFSIZ); |
389 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
398 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
390 | } |
399 | } |
391 | if ((event->error_code == BadWindow) || |
400 | if ((event->error_code == BadWindow) || |
392 | (event->error_code == BadPixmap) || |
401 | (event->error_code == BadPixmap) || |
393 | (event->error_code == BadCursor) || |
402 | (event->error_code == BadCursor) || |
394 | (event->error_code == BadFont) || |
403 | (event->error_code == BadFont) || |
395 | (event->error_code == BadDrawable) || |
404 | (event->error_code == BadDrawable) || |
396 | (event->error_code == BadColor) || |
405 | (event->error_code == BadColor) || |
397 | (event->error_code == BadGC) || |
406 | (event->error_code == BadGC) || |
398 | (event->error_code == BadIDChoice) || |
407 | (event->error_code == BadIDChoice) || |
399 | (event->error_code == BadValue) || |
408 | (event->error_code == BadValue) || |
400 | (event->error_code == BadAtom)) { |
409 | (event->error_code == BadAtom)) { |
401 | if (event->error_code == BadValue) |
410 | if (event->error_code == BadValue) |
402 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
411 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
403 | mesg, BUFSIZ); |
412 | mesg, BUFSIZ); |
404 | else if (event->error_code == BadAtom) |
413 | else if (event->error_code == BadAtom) |
405 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
414 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
406 | mesg, BUFSIZ); |
415 | mesg, BUFSIZ); |
407 | else |
416 | else |
408 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
417 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
409 | mesg, BUFSIZ); |
418 | mesg, BUFSIZ); |
410 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
419 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
411 | } |
420 | } |
412 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
421 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
413 | mesg, BUFSIZ); |
422 | mesg, BUFSIZ); |
414 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
423 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
415 | } |
424 | } |
416 | #endif |
425 | #endif |
417 | |
426 | |
418 | int |
427 | int |
… | |
… | |
470 | char **rxvt_environ; // startup environment |
479 | char **rxvt_environ; // startup environment |
471 | |
480 | |
472 | void |
481 | void |
473 | rxvt_init () |
482 | rxvt_init () |
474 | { |
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 | |
475 | ptytty::init (); |
487 | ptytty::init (); |
476 | |
488 | |
477 | if (!ev_default_loop (0)) |
489 | if (!ev_default_loop (0)) |
478 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
490 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
479 | |
491 | |
… | |
… | |
482 | signal (SIGHUP, SIG_IGN); |
494 | signal (SIGHUP, SIG_IGN); |
483 | signal (SIGPIPE, SIG_IGN); |
495 | signal (SIGPIPE, SIG_IGN); |
484 | |
496 | |
485 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
497 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
486 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
498 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
487 | |
|
|
488 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
489 | /* signal (SIGURG, SIG_DFL); */ |
|
|
490 | |
499 | |
491 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
500 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
492 | // TODO: handle this with exceptions and tolerate the memory loss |
501 | // TODO: handle this with exceptions and tolerate the memory loss |
493 | XSetIOErrorHandler (rxvt_xioerror_handler); |
502 | XSetIOErrorHandler (rxvt_xioerror_handler); |
494 | |
503 | |
… | |
… | |
522 | if (rs[Rs_geometry]) |
531 | if (rs[Rs_geometry]) |
523 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
532 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
524 | |
533 | |
525 | if (flags & WidthValue) |
534 | if (flags & WidthValue) |
526 | { |
535 | { |
|
|
536 | if (!w) |
|
|
537 | rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); |
|
|
538 | |
527 | ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ()); |
539 | ncol = clamp (w, 1, std::numeric_limits<int16_t>::max ()); |
528 | szHint.flags |= USSize; |
540 | szHint.flags |= USSize; |
529 | } |
541 | } |
530 | |
542 | |
531 | if (flags & HeightValue) |
543 | if (flags & HeightValue) |
532 | { |
544 | { |
|
|
545 | if (!h) |
|
|
546 | rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); |
|
|
547 | |
533 | nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ()); |
548 | nrow = clamp (h, 1, std::numeric_limits<int16_t>::max ()); |
534 | szHint.flags |= USSize; |
549 | szHint.flags |= USSize; |
535 | } |
550 | } |
536 | |
551 | |
537 | if (flags & XValue) |
552 | if (flags & XValue) |
538 | { |
553 | { |
… | |
… | |
613 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
628 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
614 | |
629 | |
615 | if (recalc_y) |
630 | if (recalc_y) |
616 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
631 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
617 | |
632 | |
618 | ncol = width / fwidth; |
633 | ncol = width / fwidth; |
619 | nrow = height / fheight; |
634 | nrow = height / fheight; |
620 | } |
635 | } |
621 | |
636 | |
622 | /*----------------------------------------------------------------------*/ |
637 | /*----------------------------------------------------------------------*/ |
623 | /* |
638 | /* |
… | |
… | |
634 | |
649 | |
635 | ws.ws_col = ncol; |
650 | ws.ws_col = ncol; |
636 | ws.ws_row = nrow; |
651 | ws.ws_row = nrow; |
637 | ws.ws_xpixel = width; |
652 | ws.ws_xpixel = width; |
638 | ws.ws_ypixel = height; |
653 | ws.ws_ypixel = height; |
639 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
654 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
640 | |
655 | |
641 | #if 0 |
656 | #if 0 |
642 | // TIOCSWINSZ is supposed to do this automatically and correctly |
657 | // TIOCSWINSZ is supposed to do this automatically and correctly |
643 | if (cmd_pid) /* force through to the command */ |
658 | if (cmd_pid) /* force through to the command */ |
644 | kill (-cmd_pid, SIGWINCH); |
659 | kill (-cmd_pid, SIGWINCH); |
… | |
… | |
674 | #endif |
689 | #endif |
675 | |
690 | |
676 | delete fontset[0]; |
691 | delete fontset[0]; |
677 | fontset[0] = fs; |
692 | fontset[0] = fs; |
678 | |
693 | |
679 | prop = (*fs)[1]->properties (); |
694 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
680 | prop.height += lineSpace; |
695 | prop.height += lineSpace; |
|
|
696 | prop.width += letterSpace; |
681 | |
697 | |
682 | fs->set_prop (prop, false); |
698 | fs->set_prop (prop, false); |
683 | |
699 | |
684 | fwidth = prop.width; |
700 | fwidth = prop.width; |
685 | fheight = prop.height; |
701 | fheight = prop.height; |
… | |
… | |
735 | prop, XA_STRING, 8, PropModeReplace, |
751 | prop, XA_STRING, 8, PropModeReplace, |
736 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
752 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
737 | } |
753 | } |
738 | |
754 | |
739 | void |
755 | void |
|
|
756 | rxvt_term::set_mbstring_property (Atom prop, const char *str, int len) |
|
|
757 | { |
|
|
758 | XTextProperty ct; |
|
|
759 | |
|
|
760 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
|
|
761 | { |
|
|
762 | XSetTextProperty (dpy, parent[0], &ct, prop); |
|
|
763 | XFree (ct.value); |
|
|
764 | } |
|
|
765 | } |
|
|
766 | |
|
|
767 | void |
740 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
768 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
741 | { |
769 | { |
742 | wchar_t *ws = rxvt_mbstowcs (str, len); |
770 | wchar_t *ws = rxvt_mbstowcs (str, len); |
743 | char *s = rxvt_wcstoutf8 (ws); |
771 | char *s = rxvt_wcstoutf8 (ws); |
744 | |
772 | |
… | |
… | |
754 | /*----------------------------------------------------------------------*/ |
782 | /*----------------------------------------------------------------------*/ |
755 | /* xterm sequences - title, iconName, color (exptl) */ |
783 | /* xterm sequences - title, iconName, color (exptl) */ |
756 | void |
784 | void |
757 | rxvt_term::set_title (const char *str) |
785 | rxvt_term::set_title (const char *str) |
758 | { |
786 | { |
759 | set_string_property (XA_WM_NAME, str); |
787 | set_mbstring_property (XA_WM_NAME, str); |
760 | #if ENABLE_EWMH |
788 | #if ENABLE_EWMH |
761 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
789 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
762 | #endif |
790 | #endif |
763 | } |
791 | } |
764 | |
792 | |
765 | void |
793 | void |
766 | rxvt_term::set_icon_name (const char *str) |
794 | rxvt_term::set_icon_name (const char *str) |
767 | { |
795 | { |
768 | set_string_property (XA_WM_ICON_NAME, str); |
796 | set_mbstring_property (XA_WM_ICON_NAME, str); |
769 | #if ENABLE_EWMH |
797 | #if ENABLE_EWMH |
770 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
798 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
771 | #endif |
799 | #endif |
772 | } |
800 | } |
773 | |
801 | |
… | |
… | |
899 | int old_width = szHint.width; |
927 | int old_width = szHint.width; |
900 | int old_height = szHint.height; |
928 | int old_height = szHint.height; |
901 | |
929 | |
902 | window_calc (newwidth, newheight); |
930 | window_calc (newwidth, newheight); |
903 | |
931 | |
904 | if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END))) |
932 | bool set_hint = !HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END)); |
|
|
933 | |
|
|
934 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
|
|
935 | if (set_hint) |
|
|
936 | { |
|
|
937 | szHint.flags &= ~(PBaseSize | PResizeInc); |
905 | XSetWMNormalHints (dpy, parent[0], &szHint); |
938 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
939 | szHint.flags |= PBaseSize | PResizeInc; |
|
|
940 | } |
906 | |
941 | |
907 | if (!ignoreparent) |
942 | if (!ignoreparent) |
908 | { |
943 | { |
909 | #ifdef SMART_RESIZE |
944 | #ifdef SMART_RESIZE |
910 | /* |
945 | /* |
… | |
… | |
950 | #else |
985 | #else |
951 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
986 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
952 | #endif |
987 | #endif |
953 | } |
988 | } |
954 | |
989 | |
|
|
990 | if (set_hint) |
|
|
991 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
992 | |
955 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
993 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
956 | |
994 | |
957 | if (fix_screen || newwidth != old_width || newheight != old_height) |
995 | if (fix_screen || newwidth != old_width || newheight != old_height) |
958 | { |
996 | { |
959 | if (scrollBar.state) |
997 | if (scrollBar.state) |
… | |
… | |
965 | |
1003 | |
966 | #ifdef HAVE_BG_PIXMAP |
1004 | #ifdef HAVE_BG_PIXMAP |
967 | if (bgPixmap.window_size_sensitive ()) |
1005 | if (bgPixmap.window_size_sensitive ()) |
968 | update_background (); |
1006 | update_background (); |
969 | #endif |
1007 | #endif |
970 | |
|
|
971 | scr_clear (); |
|
|
972 | } |
1008 | } |
973 | |
1009 | |
974 | if (fix_screen || old_height == 0) |
1010 | if (fix_screen || old_height == 0) |
975 | scr_reset (); |
1011 | scr_reset (); |
976 | |
|
|
977 | // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version |
|
|
978 | //scr_touch (false); |
|
|
979 | |
1012 | |
980 | #ifdef HAVE_BG_PIXMAP |
1013 | #ifdef HAVE_BG_PIXMAP |
981 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1014 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
982 | // if (bgPixmap.pixmap) |
1015 | // if (bgPixmap.pixmap) |
983 | // scr_touch (false); |
1016 | // scr_touch (false); |
… | |
… | |
1055 | |
1088 | |
1056 | /* Checking whether input method is running. */ |
1089 | /* Checking whether input method is running. */ |
1057 | bool |
1090 | bool |
1058 | rxvt_term::IMisRunning () |
1091 | rxvt_term::IMisRunning () |
1059 | { |
1092 | { |
1060 | char *p; |
|
|
1061 | Atom atom; |
1093 | Atom atom; |
1062 | Window win; |
1094 | Window win; |
1063 | char server[IMBUFSIZ]; |
1095 | char server[IMBUFSIZ]; |
1064 | |
1096 | |
1065 | /* get current locale modifier */ |
1097 | /* get current locale modifier */ |
1066 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1098 | if (char *p = XSetLocaleModifiers (0)) |
1067 | { |
1099 | { |
1068 | strcpy (server, "@server="); |
1100 | strcpy (server, "@server="); |
1069 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1101 | strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */ |
1070 | |
1102 | |
1071 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1103 | if (p = strchr (server + 1, '@')) /* first one only */ |
1072 | *p = '\0'; |
1104 | *p = '\0'; |
1073 | |
1105 | |
1074 | atom = XInternAtom (dpy, server, False); |
1106 | atom = XInternAtom (dpy, server, False); |
1075 | win = XGetSelectionOwner (dpy, atom); |
1107 | win = XGetSelectionOwner (dpy, atom); |
1076 | |
1108 | |
… | |
… | |
1143 | |
1175 | |
1144 | term->make_current (); |
1176 | term->make_current (); |
1145 | |
1177 | |
1146 | if (text) |
1178 | if (text) |
1147 | { |
1179 | { |
1148 | void *str; |
1180 | wchar_t *str; |
1149 | |
1181 | |
1150 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1182 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1151 | { |
1183 | { |
1152 | // of course, X makes it ugly again |
1184 | // of course, X makes it ugly again |
1153 | if (term->rs[Rs_imLocale]) |
1185 | if (term->rs[Rs_imLocale]) |
1154 | SET_LOCALE (term->rs[Rs_imLocale]); |
1186 | SET_LOCALE (term->rs[Rs_imLocale]); |
1155 | |
1187 | |
1156 | str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); |
1188 | str = rxvt_temp_buf<wchar_t> (text->length + 1); |
1157 | mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); |
1189 | mbstowcs (str, text->string.multi_byte, text->length + 1); |
1158 | |
1190 | |
1159 | if (term->rs[Rs_imLocale]) |
1191 | if (term->rs[Rs_imLocale]) |
1160 | SET_LOCALE (term->locale); |
1192 | SET_LOCALE (term->locale); |
1161 | } |
1193 | } |
1162 | else |
1194 | else |
1163 | str = (void *)text->string.wide_char; |
1195 | str = text->string.wide_char; |
1164 | |
1196 | |
1165 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1197 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1166 | DT_INT, call_data->caret, |
1198 | DT_INT, call_data->caret, |
1167 | DT_INT, call_data->chg_first, |
1199 | DT_INT, call_data->chg_first, |
1168 | DT_INT, call_data->chg_length, |
1200 | DT_INT, call_data->chg_length, |