… | |
… | |
36 | #include "keyboard.h" |
36 | #include "keyboard.h" |
37 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
38 | |
38 | |
39 | #include <limits> |
39 | #include <limits> |
40 | |
40 | |
41 | #include <cassert> |
41 | #include <assert.h> |
42 | #include <csignal> |
42 | #include <signal.h> |
43 | #include <cstring> |
43 | #include <string.h> |
44 | |
44 | |
45 | #include <termios.h> |
45 | #include <termios.h> |
46 | |
46 | |
47 | #ifdef HAVE_XSETLOCALE |
47 | #ifdef HAVE_XSETLOCALE |
48 | # define X_LOCALE |
48 | # define X_LOCALE |
49 | # include <X11/Xlocale.h> |
49 | # include <X11/Xlocale.h> |
50 | #else |
50 | #else |
51 | # ifdef HAVE_SETLOCALE |
|
|
52 | # include <clocale> |
51 | # include <locale.h> |
53 | # endif |
|
|
54 | #endif |
52 | #endif |
55 | |
53 | |
56 | struct termios rxvt_term::def_tio; |
54 | struct termios rxvt_term::def_tio; |
57 | vector<rxvt_term *> rxvt_term::termlist; |
55 | vector<rxvt_term *> rxvt_term::termlist; |
58 | |
56 | |
… | |
… | |
174 | #endif |
172 | #endif |
175 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
173 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
176 | rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), |
174 | rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), |
177 | #endif |
175 | #endif |
178 | scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), |
176 | scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), |
179 | #ifdef USE_XIM |
177 | #if USE_XIM |
180 | im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), |
178 | im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), |
181 | #endif |
179 | #endif |
182 | #ifdef POINTER_BLANK |
180 | #ifdef POINTER_BLANK |
183 | pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this); |
181 | pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this); |
184 | #endif |
182 | #endif |
… | |
… | |
197 | termlist.push_back (this); |
195 | termlist.push_back (this); |
198 | |
196 | |
199 | #ifdef KEYSYM_RESOURCE |
197 | #ifdef KEYSYM_RESOURCE |
200 | keyboard = new keyboard_manager; |
198 | keyboard = new keyboard_manager; |
201 | #endif |
199 | #endif |
202 | |
|
|
203 | // this->envv = 0; |
|
|
204 | } |
200 | } |
205 | |
201 | |
206 | // clean up the most important stuff, do *not* call x or free mem etc. |
202 | // clean up the most important stuff, do *not* call x or free mem etc. |
207 | // for use before an emergency exit |
203 | // for use before an emergency exit |
208 | void |
204 | void |
… | |
… | |
235 | if (display) |
231 | if (display) |
236 | { |
232 | { |
237 | selection_clear (); |
233 | selection_clear (); |
238 | selection_clear (true); |
234 | selection_clear (true); |
239 | |
235 | |
240 | #ifdef USE_XIM |
236 | #if USE_XIM |
241 | im_destroy (); |
237 | im_destroy (); |
242 | #endif |
238 | #endif |
243 | scrollBar.destroy (); |
239 | scrollBar.destroy (); |
244 | if (gc) XFreeGC (dpy, gc); |
240 | if (gc) XFreeGC (dpy, gc); |
245 | |
241 | |
… | |
… | |
269 | for (int i = 0; i < allocated.size (); i++) |
265 | for (int i = 0; i < allocated.size (); i++) |
270 | free (allocated [i]); |
266 | free (allocated [i]); |
271 | |
267 | |
272 | free (selection.text); |
268 | free (selection.text); |
273 | free (selection.clip_text); |
269 | free (selection.clip_text); |
274 | // TODO: manage env vars in child only(!) |
|
|
275 | free (env_display); |
|
|
276 | free (env_term); |
|
|
277 | free (locale); |
270 | free (locale); |
278 | free (v_buffer); |
271 | free (v_buffer); |
279 | |
272 | |
280 | delete selection_req; |
273 | delete selection_req; |
281 | |
274 | |
… | |
… | |
355 | |
348 | |
356 | delete this; |
349 | delete this; |
357 | } |
350 | } |
358 | |
351 | |
359 | void |
352 | void |
360 | rxvt_term::set_option (uint8_t opt, bool set) |
353 | rxvt_term::set_option (uint8_t opt, bool set) NOTHROW |
361 | { |
354 | { |
362 | if (!opt) |
355 | if (!opt) |
363 | return; |
356 | return; |
364 | |
357 | |
365 | uint8_t mask = 1 << (opt & 7); |
358 | uint8_t mask = 1 << (opt & 7); |
… | |
… | |
381 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
374 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
382 | (*t)->emergency_cleanup (); |
375 | (*t)->emergency_cleanup (); |
383 | } |
376 | } |
384 | |
377 | |
385 | #if !ENABLE_MINIMAL |
378 | #if !ENABLE_MINIMAL |
386 | static void |
379 | static void ecb_cold |
387 | print_x_error (Display *dpy, XErrorEvent *event) |
380 | print_x_error (Display *dpy, XErrorEvent *event) |
388 | { |
381 | { |
389 | char buffer[BUFSIZ]; |
382 | char buffer[BUFSIZ]; |
390 | char mesg[BUFSIZ]; |
383 | char mesg[BUFSIZ]; |
391 | char number[32]; |
384 | char number[32]; |
… | |
… | |
429 | mesg, BUFSIZ); |
422 | mesg, BUFSIZ); |
430 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
423 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
431 | } |
424 | } |
432 | #endif |
425 | #endif |
433 | |
426 | |
434 | int |
427 | int ecb_cold |
435 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
428 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
436 | { |
429 | { |
437 | if (GET_R->allowedxerror == -1) |
430 | if (GET_R->allowedxerror == -1) |
438 | GET_R->allowedxerror = event->error_code; |
431 | GET_R->allowedxerror = event->error_code; |
439 | else |
432 | else |
… | |
… | |
448 | } |
441 | } |
449 | |
442 | |
450 | return 0; |
443 | return 0; |
451 | } |
444 | } |
452 | |
445 | |
453 | int |
446 | int ecb_cold |
454 | rxvt_xioerror_handler (Display *display) |
447 | rxvt_xioerror_handler (Display *display) |
455 | { |
448 | { |
456 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
449 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
457 | DisplayString (display)); |
450 | DisplayString (display)); |
458 | rxvt_emergency_cleanup (); |
451 | rxvt_emergency_cleanup (); |
… | |
… | |
578 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
571 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
579 | // TODO: handle this with exceptions and tolerate the memory loss |
572 | // TODO: handle this with exceptions and tolerate the memory loss |
580 | XSetIOErrorHandler (rxvt_xioerror_handler); |
573 | XSetIOErrorHandler (rxvt_xioerror_handler); |
581 | |
574 | |
582 | XrmInitialize (); |
575 | XrmInitialize (); |
|
|
576 | |
|
|
577 | #if HAVE_PIXBUF |
|
|
578 | g_type_init (); |
|
|
579 | #endif |
583 | } |
580 | } |
584 | |
581 | |
585 | /*----------------------------------------------------------------------*/ |
582 | /*----------------------------------------------------------------------*/ |
586 | /* |
583 | /* |
587 | * window size/position calculations for XSizeHint and other storage. |
584 | * window size/position calculations for XSizeHint and other storage. |
… | |
… | |
715 | // size, i.e., when the wm does not honour our size hints, there are |
712 | // size, i.e., when the wm does not honour our size hints, there are |
716 | // extra areas not covered by the terminal screen. Such gaps, when a |
713 | // extra areas not covered by the terminal screen. Such gaps, when a |
717 | // bg pixmap is set, would have to be cleared manually to properly |
714 | // bg pixmap is set, would have to be cleared manually to properly |
718 | // refresh the background. We take the simpler route and shrink the |
715 | // refresh the background. We take the simpler route and shrink the |
719 | // vt window so as to avoid creating gaps. |
716 | // vt window so as to avoid creating gaps. |
720 | width = ncol * fwidth; |
717 | vt_width = ncol * fwidth; |
721 | height = nrow * fheight; |
718 | vt_height = nrow * fheight; |
722 | } |
719 | } |
723 | |
720 | |
724 | /*----------------------------------------------------------------------*/ |
721 | /*----------------------------------------------------------------------*/ |
725 | /* |
722 | /* |
726 | * Tell the teletype handler what size the window is. |
723 | * Tell the teletype handler what size the window is. |
… | |
… | |
734 | |
731 | |
735 | struct winsize ws; |
732 | struct winsize ws; |
736 | |
733 | |
737 | ws.ws_col = ncol; |
734 | ws.ws_col = ncol; |
738 | ws.ws_row = nrow; |
735 | ws.ws_row = nrow; |
739 | ws.ws_xpixel = width; |
736 | ws.ws_xpixel = vt_width; |
740 | ws.ws_ypixel = height; |
737 | ws.ws_ypixel = vt_height; |
741 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
738 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
742 | |
739 | |
743 | #if 0 |
740 | #if 0 |
744 | // TIOCSWINSZ is supposed to do this automatically and correctly |
741 | // TIOCSWINSZ is supposed to do this automatically and correctly |
745 | if (cmd_pid) /* force through to the command */ |
742 | if (cmd_pid) /* force through to the command */ |
… | |
… | |
771 | |
768 | |
772 | delete fontset[0]; |
769 | delete fontset[0]; |
773 | fontset[0] = fs; |
770 | fontset[0] = fs; |
774 | |
771 | |
775 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
772 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
776 | prop.height += lineSpace; |
|
|
777 | prop.width += letterSpace; |
773 | prop.width += letterSpace; |
778 | |
774 | |
779 | fs->set_prop (prop, false); |
775 | fs->set_prop (prop, false); |
780 | |
776 | |
781 | fwidth = prop.width; |
777 | fwidth = prop.width; |
782 | fheight = prop.height; |
778 | fheight = prop.height + lineSpace; |
783 | fbase = prop.ascent; |
779 | fbase = prop.ascent; |
784 | |
780 | |
785 | for (int style = 1; style < 4; style++) |
781 | for (int style = 1; style < 4; style++) |
786 | { |
782 | { |
787 | #if ENABLE_STYLES |
783 | #if ENABLE_STYLES |
… | |
… | |
949 | |
945 | |
950 | /*----------------------------------------------------------------------*/ |
946 | /*----------------------------------------------------------------------*/ |
951 | /* |
947 | /* |
952 | * find if fg/bg matches any of the normal (low-intensity) colors |
948 | * find if fg/bg matches any of the normal (low-intensity) colors |
953 | */ |
949 | */ |
954 | void |
950 | char * |
955 | rxvt_term::set_colorfgbg () |
951 | rxvt_term::get_colorfgbg () |
956 | { |
952 | { |
957 | unsigned int i; |
953 | unsigned int i; |
958 | const char *xpmb = ""; |
954 | const char *xpmb = ""; |
959 | char fstr[] = "default"; |
955 | char fstr[] = "default"; |
960 | char bstr[] = "default"; |
956 | char bstr[] = "default"; |
|
|
957 | char *env_colorfgbg; |
961 | |
958 | |
962 | for (i = Color_Black; i <= Color_White; i++) |
959 | for (i = Color_Black; i <= Color_White; i++) |
963 | if (pix_colors[Color_fg] == pix_colors[i]) |
960 | if (pix_colors[Color_fg] == pix_colors[i]) |
964 | { |
961 | { |
965 | sprintf (fstr, "%d", i - Color_Black); |
962 | sprintf (fstr, "%d", i - Color_Black); |
… | |
… | |
968 | |
965 | |
969 | for (i = Color_Black; i <= Color_White; i++) |
966 | for (i = Color_Black; i <= Color_White; i++) |
970 | if (pix_colors[Color_bg] == pix_colors[i]) |
967 | if (pix_colors[Color_bg] == pix_colors[i]) |
971 | { |
968 | { |
972 | sprintf (bstr, "%d", i - Color_Black); |
969 | sprintf (bstr, "%d", i - Color_Black); |
973 | #ifdef BG_IMAGE_FROM_FILE |
970 | #if BG_IMAGE_FROM_FILE |
974 | xpmb = "default;"; |
971 | xpmb = "default;"; |
975 | #endif |
972 | #endif |
976 | break; |
973 | break; |
977 | } |
974 | } |
978 | |
975 | |
|
|
976 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg")); |
979 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
977 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
|
|
978 | return env_colorfgbg; |
980 | } |
979 | } |
981 | |
980 | |
982 | /*----------------------------------------------------------------------*/ |
981 | /*----------------------------------------------------------------------*/ |
983 | |
982 | |
984 | bool |
983 | bool |
… | |
… | |
1077 | if (scrollBar.state) |
1076 | if (scrollBar.state) |
1078 | scrollBar.resize (); |
1077 | scrollBar.resize (); |
1079 | |
1078 | |
1080 | XMoveResizeWindow (dpy, vt, |
1079 | XMoveResizeWindow (dpy, vt, |
1081 | window_vt_x, window_vt_y, |
1080 | window_vt_x, window_vt_y, |
1082 | width, height); |
1081 | vt_width, vt_height); |
1083 | |
1082 | |
1084 | #ifdef HAVE_BG_PIXMAP |
1083 | #ifdef HAVE_BG_PIXMAP |
1085 | if (bg_window_size_sensitive ()) |
1084 | if (bg_window_size_sensitive ()) |
1086 | update_background (); |
1085 | update_background (); |
1087 | #endif |
1086 | #endif |
1088 | } |
1087 | } |
1089 | |
1088 | |
1090 | if (fix_screen || old_height == 0) |
1089 | if (fix_screen || old_height == 0) |
1091 | scr_reset (); |
1090 | scr_reset (); |
1092 | |
1091 | |
1093 | #ifdef USE_XIM |
1092 | #if USE_XIM |
1094 | im_set_position (); |
1093 | im_set_position (); |
1095 | #endif |
1094 | #endif |
1096 | } |
1095 | } |
1097 | |
1096 | |
1098 | /* |
1097 | /* |
… | |
… | |
1112 | newwidth = wattr.width - szHint.base_width; |
1111 | newwidth = wattr.width - szHint.base_width; |
1113 | if (newheight == 0) |
1112 | if (newheight == 0) |
1114 | newheight = wattr.height - szHint.base_height; |
1113 | newheight = wattr.height - szHint.base_height; |
1115 | } |
1114 | } |
1116 | |
1115 | |
1117 | if (newwidth != width || newheight != height) |
1116 | if (newwidth != vt_width || newheight != vt_height) |
1118 | { |
1117 | { |
1119 | newwidth += szHint.base_width; |
1118 | newwidth += szHint.base_width; |
1120 | newheight += szHint.base_height; |
1119 | newheight += szHint.base_height; |
1121 | resize_all_windows (newwidth, newheight, 0); |
1120 | resize_all_windows (newwidth, newheight, 0); |
1122 | } |
1121 | } |
1123 | } |
1122 | } |
1124 | |
1123 | |
1125 | /* -------------------------------------------------------------------- * |
1124 | /* -------------------------------------------------------------------- * |
1126 | * - X INPUT METHOD ROUTINES - * |
1125 | * - X INPUT METHOD ROUTINES - * |
1127 | * -------------------------------------------------------------------- */ |
1126 | * -------------------------------------------------------------------- */ |
1128 | #ifdef USE_XIM |
1127 | #if USE_XIM |
1129 | |
1128 | |
1130 | void |
1129 | void |
1131 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1130 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1132 | { |
1131 | { |
1133 | fg = pix_colors [Color_fg]; |
1132 | fg = pix_colors [Color_fg]; |
… | |
… | |
1530 | im_destroy (); |
1529 | im_destroy (); |
1531 | |
1530 | |
1532 | if (Input_Context) |
1531 | if (Input_Context) |
1533 | return; |
1532 | return; |
1534 | |
1533 | |
1535 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1536 | if (rs[Rs_imLocale]) |
1534 | if (rs[Rs_imLocale]) |
1537 | SET_LOCALE (rs[Rs_imLocale]); |
1535 | SET_LOCALE (rs[Rs_imLocale]); |
1538 | #endif |
|
|
1539 | |
1536 | |
1540 | p = rs[Rs_inputMethod]; |
1537 | p = rs[Rs_inputMethod]; |
1541 | if (p && *p) |
1538 | if (p && *p) |
1542 | { |
1539 | { |
1543 | bool found = false; |
1540 | bool found = false; |
… | |
… | |
1571 | /* try with no modifiers base IF the user didn't specify an IM */ |
1568 | /* try with no modifiers base IF the user didn't specify an IM */ |
1572 | if (im_get_ic ("@im=none")) |
1569 | if (im_get_ic ("@im=none")) |
1573 | goto done; |
1570 | goto done; |
1574 | |
1571 | |
1575 | done: |
1572 | done: |
1576 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1577 | if (rs[Rs_imLocale]) |
1573 | if (rs[Rs_imLocale]) |
1578 | SET_LOCALE (locale); |
1574 | SET_LOCALE (locale); |
1579 | #endif |
|
|
1580 | } |
1575 | } |
1581 | |
1576 | |
1582 | void |
1577 | void |
1583 | rxvt_term::im_set_position () |
1578 | rxvt_term::im_set_position () |
1584 | { |
1579 | { |
… | |
… | |
1629 | { |
1624 | { |
1630 | Window cr; |
1625 | Window cr; |
1631 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1626 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1632 | } |
1627 | } |
1633 | |
1628 | |
1634 | Pixmap |
|
|
1635 | rxvt_term::get_pixmap_property (Atom property) |
|
|
1636 | { |
|
|
1637 | Pixmap pixmap = None; |
|
|
1638 | |
|
|
1639 | int aformat; |
|
|
1640 | unsigned long nitems, bytes_after; |
|
|
1641 | Atom atype; |
|
|
1642 | unsigned char *prop; |
|
|
1643 | int result = XGetWindowProperty (dpy, display->root, property, |
|
|
1644 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
1645 | &nitems, &bytes_after, &prop); |
|
|
1646 | if (result == Success) |
|
|
1647 | { |
|
|
1648 | if (atype == XA_PIXMAP) |
|
|
1649 | pixmap = *(Pixmap *)prop; |
|
|
1650 | XFree (prop); |
|
|
1651 | } |
|
|
1652 | |
|
|
1653 | return pixmap; |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | #ifdef HAVE_BG_PIXMAP |
1629 | #ifdef HAVE_BG_PIXMAP |
1657 | |
1630 | |
1658 | void |
1631 | void |
1659 | rxvt_term::update_background () |
1632 | rxvt_term::update_background () |
1660 | { |
1633 | { |