… | |
… | |
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); |
… | |
… | |
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 | |
481 | ptytty::init (); |
487 | ptytty::init (); |
482 | |
488 | |
483 | if (!ev_default_loop (0)) |
489 | if (!ev_default_loop (0)) |
484 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
490 | rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); |
485 | |
491 | |
… | |
… | |
488 | signal (SIGHUP, SIG_IGN); |
494 | signal (SIGHUP, SIG_IGN); |
489 | signal (SIGPIPE, SIG_IGN); |
495 | signal (SIGPIPE, SIG_IGN); |
490 | |
496 | |
491 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
497 | sig_handlers.sw_term.start (SIGTERM); ev_unref (); |
492 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
498 | sig_handlers.sw_int.start (SIGINT); ev_unref (); |
493 | |
|
|
494 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
495 | /* signal (SIGURG, SIG_DFL); */ |
|
|
496 | |
499 | |
497 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
500 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
498 | // TODO: handle this with exceptions and tolerate the memory loss |
501 | // TODO: handle this with exceptions and tolerate the memory loss |
499 | XSetIOErrorHandler (rxvt_xioerror_handler); |
502 | XSetIOErrorHandler (rxvt_xioerror_handler); |
500 | |
503 | |
… | |
… | |
646 | |
649 | |
647 | ws.ws_col = ncol; |
650 | ws.ws_col = ncol; |
648 | ws.ws_row = nrow; |
651 | ws.ws_row = nrow; |
649 | ws.ws_xpixel = width; |
652 | ws.ws_xpixel = width; |
650 | ws.ws_ypixel = height; |
653 | ws.ws_ypixel = height; |
651 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
654 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
652 | |
655 | |
653 | #if 0 |
656 | #if 0 |
654 | // TIOCSWINSZ is supposed to do this automatically and correctly |
657 | // TIOCSWINSZ is supposed to do this automatically and correctly |
655 | if (cmd_pid) /* force through to the command */ |
658 | if (cmd_pid) /* force through to the command */ |
656 | kill (-cmd_pid, SIGWINCH); |
659 | kill (-cmd_pid, SIGWINCH); |
… | |
… | |
686 | #endif |
689 | #endif |
687 | |
690 | |
688 | delete fontset[0]; |
691 | delete fontset[0]; |
689 | fontset[0] = fs; |
692 | fontset[0] = fs; |
690 | |
693 | |
691 | prop = (*fs)[1]->properties (); |
694 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
692 | prop.height += lineSpace; |
695 | prop.height += lineSpace; |
|
|
696 | prop.width += letterSpace; |
693 | |
697 | |
694 | fs->set_prop (prop, false); |
698 | fs->set_prop (prop, false); |
695 | |
699 | |
696 | fwidth = prop.width; |
700 | fwidth = prop.width; |
697 | fheight = prop.height; |
701 | fheight = prop.height; |
… | |
… | |
747 | prop, XA_STRING, 8, PropModeReplace, |
751 | prop, XA_STRING, 8, PropModeReplace, |
748 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
752 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
749 | } |
753 | } |
750 | |
754 | |
751 | 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 |
752 | 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) |
753 | { |
769 | { |
754 | wchar_t *ws = rxvt_mbstowcs (str, len); |
770 | wchar_t *ws = rxvt_mbstowcs (str, len); |
755 | char *s = rxvt_wcstoutf8 (ws); |
771 | char *s = rxvt_wcstoutf8 (ws); |
756 | |
772 | |
… | |
… | |
766 | /*----------------------------------------------------------------------*/ |
782 | /*----------------------------------------------------------------------*/ |
767 | /* xterm sequences - title, iconName, color (exptl) */ |
783 | /* xterm sequences - title, iconName, color (exptl) */ |
768 | void |
784 | void |
769 | rxvt_term::set_title (const char *str) |
785 | rxvt_term::set_title (const char *str) |
770 | { |
786 | { |
771 | set_string_property (XA_WM_NAME, str); |
787 | set_mbstring_property (XA_WM_NAME, str); |
772 | #if ENABLE_EWMH |
788 | #if ENABLE_EWMH |
773 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
789 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
774 | #endif |
790 | #endif |
775 | } |
791 | } |
776 | |
792 | |
777 | void |
793 | void |
778 | rxvt_term::set_icon_name (const char *str) |
794 | rxvt_term::set_icon_name (const char *str) |
779 | { |
795 | { |
780 | set_string_property (XA_WM_ICON_NAME, str); |
796 | set_mbstring_property (XA_WM_ICON_NAME, str); |
781 | #if ENABLE_EWMH |
797 | #if ENABLE_EWMH |
782 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
798 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
783 | #endif |
799 | #endif |
784 | } |
800 | } |
785 | |
801 | |
… | |
… | |
913 | |
929 | |
914 | window_calc (newwidth, newheight); |
930 | window_calc (newwidth, newheight); |
915 | |
931 | |
916 | bool set_hint = !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)); |
917 | |
933 | |
|
|
934 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
918 | if (set_hint) |
935 | if (set_hint) |
919 | { |
936 | { |
920 | szHint.flags &= ~(PBaseSize | PResizeInc); |
937 | szHint.flags &= ~(PBaseSize | PResizeInc); |
921 | XSetWMNormalHints (dpy, parent[0], &szHint); |
938 | XSetWMNormalHints (dpy, parent[0], &szHint); |
922 | szHint.flags |= PBaseSize | PResizeInc; |
939 | szHint.flags |= PBaseSize | PResizeInc; |
… | |
… | |
968 | #else |
985 | #else |
969 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
986 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
970 | #endif |
987 | #endif |
971 | } |
988 | } |
972 | |
989 | |
|
|
990 | if (set_hint) |
|
|
991 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
992 | |
973 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
993 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
974 | |
994 | |
975 | if (fix_screen || newwidth != old_width || newheight != old_height) |
995 | if (fix_screen || newwidth != old_width || newheight != old_height) |
976 | { |
996 | { |
977 | if (scrollBar.state) |
997 | if (scrollBar.state) |
… | |
… | |
983 | |
1003 | |
984 | #ifdef HAVE_BG_PIXMAP |
1004 | #ifdef HAVE_BG_PIXMAP |
985 | if (bgPixmap.window_size_sensitive ()) |
1005 | if (bgPixmap.window_size_sensitive ()) |
986 | update_background (); |
1006 | update_background (); |
987 | #endif |
1007 | #endif |
988 | |
|
|
989 | scr_clear (); |
|
|
990 | } |
1008 | } |
991 | |
|
|
992 | if (set_hint) |
|
|
993 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
994 | |
1009 | |
995 | if (fix_screen || old_height == 0) |
1010 | if (fix_screen || old_height == 0) |
996 | scr_reset (); |
1011 | scr_reset (); |
997 | |
|
|
998 | // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version |
|
|
999 | //scr_touch (false); |
|
|
1000 | |
1012 | |
1001 | #ifdef HAVE_BG_PIXMAP |
1013 | #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 ? |
1014 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1003 | // if (bgPixmap.pixmap) |
1015 | // if (bgPixmap.pixmap) |
1004 | // scr_touch (false); |
1016 | // scr_touch (false); |
… | |
… | |
1076 | |
1088 | |
1077 | /* Checking whether input method is running. */ |
1089 | /* Checking whether input method is running. */ |
1078 | bool |
1090 | bool |
1079 | rxvt_term::IMisRunning () |
1091 | rxvt_term::IMisRunning () |
1080 | { |
1092 | { |
1081 | char *p; |
|
|
1082 | Atom atom; |
1093 | Atom atom; |
1083 | Window win; |
1094 | Window win; |
1084 | char server[IMBUFSIZ]; |
1095 | char server[IMBUFSIZ]; |
1085 | |
1096 | |
1086 | /* get current locale modifier */ |
1097 | /* get current locale modifier */ |
1087 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1098 | if (char *p = XSetLocaleModifiers (0)) |
1088 | { |
1099 | { |
1089 | strcpy (server, "@server="); |
1100 | strcpy (server, "@server="); |
1090 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1101 | strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */ |
1091 | |
1102 | |
1092 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1103 | if (p = strchr (server + 1, '@')) /* first one only */ |
1093 | *p = '\0'; |
1104 | *p = '\0'; |
1094 | |
1105 | |
1095 | atom = XInternAtom (dpy, server, False); |
1106 | atom = XInternAtom (dpy, server, False); |
1096 | win = XGetSelectionOwner (dpy, atom); |
1107 | win = XGetSelectionOwner (dpy, atom); |
1097 | |
1108 | |
… | |
… | |
1164 | |
1175 | |
1165 | term->make_current (); |
1176 | term->make_current (); |
1166 | |
1177 | |
1167 | if (text) |
1178 | if (text) |
1168 | { |
1179 | { |
1169 | void *str; |
1180 | wchar_t *str; |
1170 | |
1181 | |
1171 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1182 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1172 | { |
1183 | { |
1173 | // of course, X makes it ugly again |
1184 | // of course, X makes it ugly again |
1174 | if (term->rs[Rs_imLocale]) |
1185 | if (term->rs[Rs_imLocale]) |
1175 | SET_LOCALE (term->rs[Rs_imLocale]); |
1186 | SET_LOCALE (term->rs[Rs_imLocale]); |
1176 | |
1187 | |
1177 | str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); |
1188 | str = rxvt_temp_buf<wchar_t> (text->length + 1); |
1178 | mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); |
1189 | mbstowcs (str, text->string.multi_byte, text->length + 1); |
1179 | |
1190 | |
1180 | if (term->rs[Rs_imLocale]) |
1191 | if (term->rs[Rs_imLocale]) |
1181 | SET_LOCALE (term->locale); |
1192 | SET_LOCALE (term->locale); |
1182 | } |
1193 | } |
1183 | else |
1194 | else |
1184 | str = (void *)text->string.wide_char; |
1195 | str = text->string.wide_char; |
1185 | |
1196 | |
1186 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1197 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1187 | DT_INT, call_data->caret, |
1198 | DT_INT, call_data->caret, |
1188 | DT_INT, call_data->chg_first, |
1199 | DT_INT, call_data->chg_first, |
1189 | DT_INT, call_data->chg_length, |
1200 | DT_INT, call_data->chg_length, |